
var g_xmlHttpRequest=null;
var DOCUMENT_DOMAIN=document.domain;
function OnKeyPressCreateAccount(evt)
{
try
{
var charCode=(evt.which)?evt.which:event.keyCode;
if(charCode==13)
{
OnAWPCreateAccount();
}
}
catch(e)
{
}
}
function OnAWPCreateAccount()
{
try
{
var sAccountEmail=$("txtAccountEmail").value;
if(sAccountEmail=="")
{
alert("Please enter your email address, then click Create Account.");
return;
}
document.frmAWPCreateAccount.submit();
}
catch(e)
{
DisplayErrorDialog("Cannot create account",e,"AWPAccountManagement.js","OnAWPCreateAccount");
}
}
function OnSendInstruction()
{
try
{
var sAccountEmail=$("ContactInfo").value;
var sFirstName=$("txtFirstName").value;
var sLastName=$("txtLastName").value;
var sCaptchaConfirmCode=$("txtPicCode").value;
var bAgreeToTOU=($("ckAgreeToTOU")!=null)?$("ckAgreeToTOU").checked:false;
if(sAccountEmail==""||sFirstName==""||sLastName=="")
{
alert("Please fill in all required fields.");
return;
}
var sContactInfo=CreateNewClientXML(sAccountEmail,sFirstName,sLastName);
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/RegisterContact.ashx";
var sPostString="contactInfo="+sContactInfo+"&"+
"captchaConfirmCode="+sCaptchaConfirmCode+"&"+
"agreeToTOU="+(bAgreeToTOU?"1":"0");
g_xmlHttpRequest=new XmlHttp();
g_xmlHttpRequest.open("POST",sURL,true);
g_xmlHttpRequest.onreadystatechange=RSCSendInstruction;
g_xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
g_xmlHttpRequest.send(sPostString);
}
catch(e)
{
DisplayErrorDialog("Cannot send email to user",e,"AWPAccountManagement.js","OnSendInstruction");
}
}
function RSCSendInstruction()
{
if(isXMLHttpReady(g_xmlHttpRequest))
{
try
{
g_xmlHttpRequest.onreadystatechange=new Function();
if(g_xmlHttpRequest.status!=200)
{
var oErr=new Error(g_xmlHttpRequest.status,"Unexpected HTTP status code returned.");
throw(oErr);
}
var xmlResponse=g_xmlHttpRequest.responseXML;
var nodeReturn=SelectSingleNode(xmlResponse,"RETURN");
if(null==nodeReturn)
{
var oErr=new Error(0,"Unexpected response.");
throw(oErr);
}
var iRetCode=parseInt(nodeReturn.getAttribute("rc"),10);
if(isNaN(iRetCode))
{
var oErr=new Error(0,"Unexpected response. Invalid return code.");
throw(oErr);
}
if(iRetCode==0)
{
alert("Temporary password has been sent to your email, please login and change your password");
document.location.href="http://"+DOCUMENT_DOMAIN+"/?Login";
}
else if(iRetCode==1)
{
alert("You've already got an account");
document.location.href="http://"+DOCUMENT_DOMAIN;
}
else if(iRetCode==2)
{
alert("Incorrect code entered. Please try again.");
}
}
catch(e)
{
DisplayErrorDialog("Unable to create new account",e,"AWPAccountManagement.js","RSCSendInstruction");
}
}
}
function OnRemindPassword(p_sAccountEmail)
{
try
{
var sAccountEmail=$("txtReminderEmail").value;
var sPwdQuestionID=$("selReminderQuestion").value;
var sReminderAnswer=$("txtReminderAnswer").value;
var sCaptchaConfirmCode=$("txtPicCode").value;
var bAgreeToTOU=$("ckAgreeToTOU").checked;
var sMD5QuestionAnswer=GetMD5SecretQuestionAndAnswer(sPwdQuestionID,sReminderAnswer);
var sURL="http://"+DOCUMENT_DOMAIN+"/DotNET/AWPContact/RemindPassword.ashx";
var sPostString="contactLogin="+sAccountEmail+"&"+
"md5HashedQuestionAnswer="+sMD5QuestionAnswer+"&"+
"captchaConfirmCode="+sCaptchaConfirmCode+"&"+
"agreeToTOU="+(bAgreeToTOU?"1":"0");
g_xmlHttpRequest=new XmlHttp();
g_xmlHttpRequest.open("POST",sURL,true);
g_xmlHttpRequest.onreadystatechange=RSCOnRemindPassword;
g_xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
g_xmlHttpRequest.send(sPostString);
}
catch(e)
{
DisplayErrorDialog("Cannot start password reset process",e,"AWPAccountManagement.js","OnRemindPassword");
}
}
function RSCOnRemindPassword()
{
if(isXMLHttpReady(g_xmlHttpRequest))
{
try
{
g_xmlHttpRequest.onreadystatechange=new Function();
if(g_xmlHttpRequest.status!=200)
{
var oErr=new Error(g_xmlHttpRequest.status,"Unexpected HTTP status code returned.");
throw(oErr);
}
var xmlResponse=g_xmlHttpRequest.responseXML;
var nodeReturn=SelectSingleNode(xmlResponse,"SUCCESS");
if(null==nodeReturn)
{
var oErr=new Error(0,"Unexpected response.");
throw(oErr);
}
else
{
alert("Temporary password has been reset and sent to your email, please login and change your password");
document.location.href="http://"+DOCUMENT_DOMAIN+"/?Login";
}
}
catch(e)
{
DisplayErrorDialog("Unable to reset password",e,"AWPAccountManagement.js","RSCOnRemindPassword");
}
}
}
function CreateNewClientXML(p_sAccountEmail,p_sFirstName,p_sLastName)
{
var sXML="<HasPCVAccess>1</HasPCVAccess>"+
"<FirstName>"+p_sFirstName+"</FirstName>"+
"<LastName>"+p_sLastName+"</LastName>"+
AddContactType()+
"<Email>"+p_sAccountEmail+"</Email>"+
"<Email2></Email2>"+
"<Email3></Email3>"+
"<Email4></Email4>";
return('<Contact applevel="3">'+sXML+'</Contact>');
}
function AddContactType()
{
var sRes="";
for(var i=0;i<8;i++)
{
sIndex=i+1;
sRes+="<ContactType"+sIndex+"></ContactType"+sIndex+">";
}
return sRes;
}
function GetMD5SecretQuestionAndAnswer(p_sQuestionID,p_sQuestionAnswer)
{
var sResult="";
try
{
var sAnswerUpperCase=new String(p_sQuestionAnswer);
sAnswerUpperCase=sAnswerUpperCase.toUpperCase();
var sQuestionAndAnswer=p_sQuestionID+sAnswerUpperCase;
sResult=hex_md5(sQuestionAndAnswer);
}
catch(e)
{
e.description="AWPAccountManager.js - GetMD5SecretQuestionAndAnswer exception: "+e.description;
throw e;
}
return(sResult);
}


