var xmlHttp
var resultvalue
var MEMBER_STATUS_MSG1 = "We have successfully matched the details you provided with an eligible Australian Unity member. They will soon receive the Member-Get-Member benefit."
var MEMBER_STATUS_MSG2 = "Unfortunately the member you have nominated is not eligible to receive a Member-Get-Member benefit at this time. Please click Continue to proceed with your application."
var MEMBER_STATUS_MSG3 = "The membership name you have entered belongs to more than one member. Please re-enter the correct membership number or leave blank and click Continue to proceed with your application.<br><br>We will contact you to validate your referring member’s details."
var MEMBER_STATUS_MSG4 = "Unfortunately we cannot find the referring member because you have not told us the member’s name or number.  Please enter the details or click Continue to proceed with your application.<br><br>We will contact you to validate your referring member’s details."
var MEMBER_STATUS_MSG5 = "Unfortunately the membership details you have entered are incorrect.  Please re-enter the correct membership details or leave blank and click Continue to proceed with your application.<br><br>We will contact you to validate your referring member’s details."
var MEMBER_STATUS_MSG6 = "System Error.Please try again later"


function validateMemberRecord(strFName,strSName,strCustomerCD)
{
//moved check to validating page to set validationstatus to 4 - no details provided
/*if (strFName.length==0 && strSName.length == 0 && strCustomerCD.length ==0)
{ 
	resultvalue = "";
	return
}*/

window.status = "Checking Australian Unity Membership Details:"
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 

var url="validateReferringMember.asp"
url=url+"?fname="+escape(strFName)
url=url+"&sname="+escape(strSName)
url=url+"&CustomerCD="+strCustomerCD
//alert(url);
//url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

} 
//prospecting model functions start
function getBuyonlineFormData(strFName,strSName,strGender,strTitle,strDOB,strEmail,strPhone,pageurl, width, height)
{
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	
	var url = "updateProspectingModelData.asp"
	url = url +"?fname="+escape(strFName)
	url = url +"&sname="+escape(strSName)
	url = url +"&gender="+escape(strGender)
	url = url +"&title="+escape(strTitle)
	url = url +"&dob="+escape(strDOB)
	url = url +"&email="+escape(strEmail)
	url = url +"&phone="+escape(strPhone)
	
	xmlHttp.onreadystatechange = PM_stateChanged
	xmlHttp.open("GET",url,false)
	xmlHttp.send(null)
	PopupHelps(pageurl+"&"+xmlHttp.responseText, width, height);
}

function PM_stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
		window.status = 'Done';
	} 
	
} 

//prospecting model functions end
function stateChanged() 
{ 
resultvalue = null;
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
	//document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
	resultvalue = xmlHttp.responseText
	//alert(resultvalue);
	evaluateResult(resultvalue);
	//window.status = 'Done';
} 
} 

function evaluateResult(resultvalue)
{
		var msg = "";
		var match = resultvalue.substr(0,resultvalue.indexOf(':'));
		var eligibility = resultvalue.substr(resultvalue.indexOf(':')+1,resultvalue.length-1);
		
		document.getElementById("divErrRefer").style.color="red";
		
		//alert(resultvalue);
		
		//alert(eligibility);
		if(match == "M-1")
		{
			msg = MEMBER_STATUS_MSG5;
		}
		else if(match == "M-0")
		{
			msg = MEMBER_STATUS_MSG6;			// system error
		}
		else if(match == "M-2")
		{
			msg = MEMBER_STATUS_MSG3;
		}
		else if(match == "M-3")
		{
			msg = MEMBER_STATUS_MSG2;
		
		}
		else if(match== "")
		{
			msg = MEMBER_STATUS_MSG4;
		}
		else
		{
				if (match == "M1")
				{
					if (eligibility == "E1")
					{
						msg = MEMBER_STATUS_MSG1;
						document.getElementById("divErrRefer").style.color="#000000";
					}
					
					else
					{
						msg = MEMBER_STATUS_MSG2;
					}
				}
		}
			
				afwcShowDiv("divErrRefer");
				document.getElementById("divErrRefer").innerHTML = msg;
				//afwcChangeDivHtml(document.getElementById("divErrRefer"),msg);
				document.getElementById("divErrRefer").scrollIntoView();
				document.appForm.RefMemberSName.value = document.appForm.RefMemberSName.value + " ";
				window.status = "Done";			
}

function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 

