var xmlhttp
var xmldata

function loadLoginPreference()
{
	var sAccountNumber = new String(document.getElementById("vAccountNumber").value);
	if (sAccountNumber.length >=1) {
		var sProtocolCheck = new String(window.location).substr(0,5).toLowerCase();
		if ("https" != sProtocolCheck) {

			xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
			{
				alert ("Your browser does not support AJAX!");
				return;
			}
			var url="/mw08/oqLoginPreferenceServer.asp";
			url=url+"?AccNo="+sAccountNumber;
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=stateChanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		}

	}
}

function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		//alert("readyState changed to 4. status is: " + xmlhttp.status);
		if (xmlhttp.status ==200)
		{
			//alert("Response text is : " + xmlhttp.responseText) ;
			var xmlDoc=xmlhttp.responseXML.documentElement;
			if (xmlDoc != null) {
				xmldata = xmlDoc.getElementsByTagName("AccountDetail");
				if (xmldata.length >= 1) {
					var nForceSecureLogin=xmldata[0].getElementsByTagName("iForceSecureLogin")[0].childNodes[0].nodeValue;
					if (1 == nForceSecureLogin) {						
						var sAccountNumber=xmldata[0].getElementsByTagName("AccountNumber")[0].childNodes[0].nodeValue;
						//alert("Force Secure Login is true for account " + sAccountNumber ) ;
						disableFields();
						var sNewLoc = new String(window.location).toLowerCase();
						sNewLoc = sNewLoc.replace("http:", "https:");
						alert("You are being redirected to the secure login page...");
						window.location = sNewLoc;
					}
				}
			}
			else {
				//alert("xmlDoc is null.");
			}
		}
	}
}

function GetXmlHttpObject()
{
	//alert("in getXmlHttpObject") ;
	if (window.XMLHttpRequest)
	{
		//alert("code for IE7+, Firefox, Chrome, Opera, Safari") ;
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		//alert("code for IE6, IE5");
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function disableFields()
{
	document.getElementById("vAccountNumber").disabled = true;
	document.getElementById("vLoginName").disabled = true;
	document.getElementById("vPassword").disabled = true;
	document.getElementById("B1").disabled = true;
	
	return null;
}

function setFocus()
{
	document.getElementById("vAccountNumber").focus();
}
