
var g_xmlContactSignInHttpRequest=null;
var g_xmlAceeptFAHttpRequest=null;
var g_sAWPLogin="";
var g_sAWPPwd="";
var g_fnCallBackSuccessfulLogin=NavigateToPCV;
var DOCUMENT_DOMAIN=document.domain;
function NavigateToPCV()
{
document.location.href="http://"+DOCUMENT_DOMAIN+"/?Page=-1";
}
function OnKeyPressSignIn(evt)
{
try
{
var charCode=(evt.which)?evt.which:event.keyCode;
if(charCode==13)
{
OnAWPSignIn();
}
}
catch(e)
{
}
}
function OnAWPSignIn()
{
g_sAWPLogin=$("txtAWPLogin").value;
g_sAWPPwd=$("txtAWPPwd").value;
if(g_sAWPLogin==""||g_sAWPPwd=="")
{
alert("Please enter your User ID and Password, then click Login.");
return;
}
try
{
DisableLogin();
StartContactAuthentication(g_sAWPLogin);
}
catch(e)
{
EnableLogin();
DisplayErrorDialog("Unable to authenticate user",e,"AWPClientLogin.js","OnAWPSignIn");
}
}
function StartContactAuthentication(p_sAWPLogin)
{
try
{
var sPost="contactLogin="+p_sAWPLogin;
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/StartContactSession.ashx";
g_xmlContactSignInHttpRequest=new XmlHttp();
g_xmlContactSignInHttpRequest.open("POST",sURL,true);
g_xmlContactSignInHttpRequest.onreadystatechange=RSCStartContactAuthentication;
g_xmlContactSignInHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
g_xmlContactSignInHttpRequest.send(sPost);
}
catch(e)
{
EnableLogin();
DisplayErrorDialog("Cannot start a new session.",e,"AWPClientLogin.js","StartContactAuthentication");
}
}
function RSCStartContactAuthentication()
{
if(isXMLHttpReady(g_xmlContactSignInHttpRequest))
{
try
{
g_xmlContactSignInHttpRequest.onreadystatechange=new Function();
if(g_xmlContactSignInHttpRequest.status!=200)
{
var oErr=new Error(g_xmlContactSignInHttpRequest.status,"Unexpected HTTP status code returned.");
throw(oErr);
}
var xmlResponse=g_xmlContactSignInHttpRequest.responseXML;
var nodeReturn=SelectSingleNode(xmlResponse,"UNIQUEKEY");
if(null==nodeReturn)
{
var oErr=new Error(0,"Unexpected response.");
throw(oErr);
}
var sKey=nodeReturn.getAttribute("guid");
if(""==sKey||null==sKey)
{
var oErr=new Error(0,"Unexpected response.");
throw(oErr);
}
var sMD5Pwd=GetMD5Password(g_sAWPPwd,sKey,g_sAWPLogin);
if(""==sMD5Pwd)
{
var oErr=new Error(ERROR_GENERAL_ERROR,"Unable to generate valid MD5 password.");
throw(oErr);
}
AuthenticateContact(sMD5Pwd);
}
catch(e)
{
EnableLogin();
DisplayErrorDialog("Unexpected error occurred when starting to authenticate user.",e,
"AWPClientLogin.js","RSCStartContactAuthentication");
}
}
}
function AuthenticateContact(p_sPwd)
{
try
{
var sPost="contactLogin="+g_sAWPLogin+"&md5HashedPwd="+p_sPwd;
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/AuthenticateContact.ashx";
g_xmlContactSignInHttpRequest=new XmlHttp();
g_xmlContactSignInHttpRequest.open("POST",sURL,true);
g_xmlContactSignInHttpRequest.onreadystatechange=RSCAuthenticateContact;
g_xmlContactSignInHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
g_xmlContactSignInHttpRequest.send(sPost);
}
catch(e)
{
EnableLogin();
DisplayErrorDialog("Cannot start authentication",e,"AWPClientLogin.js","AuthenticateContact");
}
}
function RSCAuthenticateContact()
{
if(isXMLHttpReady(g_xmlContactSignInHttpRequest))
{
try
{
g_xmlContactSignInHttpRequest.onreadystatechange=new Function();
if(g_xmlContactSignInHttpRequest.status!=200)
{
var oErr=new Error(g_xmlContactSignInHttpRequest.status,"Unexpected HTTP status code returned.");
throw(oErr);
}
var xmlResponse=g_xmlContactSignInHttpRequest.responseXML;
var nodeReturn=SelectSingleNode(xmlResponse,"RESULTS");
if(null==nodeReturn)
{
var oErr=new Error(0,"Unexpected response.");
throw(oErr);
}
var iRetCode=parseInt(nodeReturn.getAttribute("retcode"),10);
if(isNaN(iRetCode))
{
var oErr=new Error(0,"Unexpected response. Invalid return code.");
throw(oErr);
}
if(iRetCode==0)
{
document.location.href="http://"+DOCUMENT_DOMAIN+"/?Page=-1";
}
else if(iRetCode==1)
{
var sSecureServerName=nodeReturn.getAttribute("infranet");
var sContactLogin=nodeReturn.getAttribute("login");
var iContactID=nodeReturn.getAttribute("contactid");
var sSiteCode=nodeReturn.getAttribute("site");
var sSessionID=nodeReturn.getAttribute("session");
var sURL="https://"+sSecureServerName+"/1_4/Settings/AWPChangePassword.asp";
var nodePwdQuestion=SelectSingleNode(xmlResponse,"RESULTS/VALIDQUESTIONS");
var xmlPwdQuestion=GetSerializedXml(nodePwdQuestion);
document.frmAWPChangePwd.action=sURL;
document.frmAWPChangePwd.SiteCode.value=sSiteCode;
document.frmAWPChangePwd.ReturnURL.value="/";
document.frmAWPChangePwd.ContactID.value=iContactID;
document.frmAWPChangePwd.ContactLogin.value=sContactLogin;
document.frmAWPChangePwd.PwdQuestions.value=URLEncodeQueryStringParm(xmlPwdQuestion);
document.frmAWPChangePwd.Session.value=URLEncodeQueryStringParm(sSessionID);
document.frmAWPChangePwd.submit();
}
else
{
EnableLogin();
sErrorMsg="Invalid User ID and/or Password.  Please try again.";
alert(sErrorMsg);
}
}
catch(e)
{
EnableLogin();
DisplayErrorDialog("Unable to authenticate user.",e,"AWPClientLogin.js","RSCAuthenticateContact");
}
}
}
function OnLogout()
{
try
{
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/CloseSession.ashx";
document.frmLogout.action=sURL;
document.frmLogout.submit();
}
catch(e)
{
DisplayErrorDialog("Unable to logout",e,"AWPClientLogin.js","OnLogout");
}
}
function OnAcceptEula()
{
try
{
var sMsg="A confirmation email has been sent to you. Use the link in this email \n";
sMsg+="to access additional information your Realtor intended you to see. \n";
sMsg+="Your access will be limited until you have verified.";
alert(sMsg);
var sCurrentURL=document.location.href;
var regxPagePattStr=/Page=-1/g;
if(sCurrentURL.match(regxPagePattStr))
{
sCurrentURL=sCurrentURL.replace(regxPagePattStr,"Login=-1");
}
var sPostString="currentURL="+URLEncodeQueryStringParm(sCurrentURL);
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/AcceptAgreement.ashx";
document.frmEULA.action=sURL;
document.frmEULA.returnURL.value=sCurrentURL;
document.frmEULA.submit();
}
catch(e)
{
DisplayErrorDialog("Unable to accept EULA",e,"AWPClientLogin.js","OnAcceptEula");
}
}
function OnRejectEula()
{
try
{
var sMsg="By not agreeing to Terms of Use, additional information \n";
sMsg+="your Realtor intended you to see will not be available to you.";
alert(sMsg);
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/RejectAgreement.ashx";
document.frmEULA.action=sURL;
document.frmEULA.submit();
}
catch(e)
{
DisplayErrorDialog("Unable to accept EULA",e,"AWPClientLogin.js","OnRejectEula");
}
}
function GetMD5Password(p_sPwd,p_sAuthKey,p_sLogin)
{
var sResult="";
try
{
var sUserPwdUpperCase=new String(p_sPwd);
sUserPwdUpperCase=sUserPwdUpperCase.toUpperCase();
var sPwd=sUserPwdUpperCase+p_sAuthKey;
sResult=hex_md5(sPwd);
}
catch(e)
{
e.description="AWPClientLogin.js - GetMD5Password exception: "+e.description;
throw e;
}
return sResult;
}
function DisableLogin()
{
try
{
$("btnAWPLoginBtn").style.display='none';
$("divImageLoading").style.display='block';
}
catch(e)
{
DisplayErrorDialog("Object undefined",e,"AWPClientLogin.js","DisableLogin");
}
}
function EnableLogin()
{
try
{
$("btnAWPLoginBtn").style.display='block';
$("divImageLoading").style.display='none';
}
catch(e)
{
DisplayErrorDialog("Object undefined",e,"AWPClientLogin.js","EnableLogin");
}
}
function OnAcceptFA()
{
try
{
var sEmailAddress=$("txtEmailAddress").value;
if((sEmailAddress==null)||(sEmailAddress==""))
{
alert("Please enter your email address to confirm that you have read \nand understand the above financial agreement.");
return;
}
var sPostString="emailAddress="+URLEncodeQueryStringParm(sEmailAddress);
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/AcceptFinAgreement.ashx";
g_xmlAceeptFAHttpRequest=new XmlHttp();
g_xmlAceeptFAHttpRequest.open("POST",sURL,true);
g_xmlAceeptFAHttpRequest.onreadystatechange=RSCAcceptFA;
g_xmlAceeptFAHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
g_xmlAceeptFAHttpRequest.send(sPostString);
}
catch(e)
{
DisplayErrorDialog("Unable to accept FA",e,"AWPClientLogin.js","OnAcceptFA");
}
}
function RSCAcceptFA()
{
if(isXMLHttpReady(g_xmlAceeptFAHttpRequest))
{
try
{
g_xmlAceeptFAHttpRequest.onreadystatechange=new Function();
if(g_xmlAceeptFAHttpRequest.status!=200)
{
var oErr=new Error(g_xmlAceeptFAHttpRequest.status,"Unexpected HTTP status code returned.");
throw(oErr);
}
var xmlResponse=g_xmlAceeptFAHttpRequest.responseXML;
var nodeReturn=SelectSingleNode(xmlResponse,"RESULTS");
if(null==nodeReturn)
{
var oErr=new Error(0,"Unexpected response.");
throw(oErr);
}
var iRetCode=parseInt(nodeReturn.getAttribute("retcode"),10);
if(isNaN(iRetCode))
{
var oErr=new Error(0,"Unexpected response. Invalid return code.");
throw(oErr);
}
if(iRetCode==0)
{
document.location.href="http://"+DOCUMENT_DOMAIN+"/?Page=-1";
}
else
{
sErrorMsg="The email address entered does not match the email address of file. Please re-enter.";
alert(sErrorMsg);
}
}
catch(e)
{
DisplayErrorDialog("Unable to authenticate user.",e,"AWPClientLogin.js","RSCAuthenticateContact");
}
}
}
function OnRejectFA()
{
try
{
var sMsg="By not agreeing to the financial agreement, additional information \n";
sMsg+="your Realtor intended you to see will not be available to you.";
alert(sMsg);
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/RejectFinAgreement.ashx";
document.frmFA.action=sURL;
document.frmFA.submit();
}
catch(e)
{
DisplayErrorDialog("Unable to accept FA",e,"AWPClientLogin.js","OnRejectFA");
}
}
function OnKeyPressFASubmit(evt)
{
try
{
var charCode=(evt.which)?evt.which:event.keyCode;
if(charCode==13)
{
OnAcceptFA();
}
}
catch(e)
{
DisplayErrorDialog("Error invoking FA acceptance",e,"AWPClientLogin.js","OnKeyPressFASubmit");
}
}

