      // MAHE INHOUSE MADE FUNCTIONS
	var xmlhttp;
   	function createXMLHTTPObject()
	{
		xmlhttp=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
	 	}
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch (e) {
				xmlhttp=false;
			}
		}
		if (!xmlhttp && window.createRequest) {
			try {
				xmlhttp = window.createRequest();
			} catch (e) {
				xmlhttp=false;
			}
		}

	}

function lwmCrypt(value_in) 
{
	lwm_out = "";
	if(value_in == "") return "";
	else {
		lwm_in = escape(value_in);
		for(i = 0; i < lwm_in.length; i++) {
			lwm_out += lwm_in.charCodeAt(i) - 23;
		}
		return lwm_out;
   	}
}



   function doTracking()
	{
		var szURL = "http://track.mahe.com/TWMPro/TWM-Track.nsf/WTrackDirect?OpenForm";
		var szQS = "";
		var bContinue = false;
		
		var szCons = document.forms["tracktraceform"].txtCons.value;
		var szBook = document.forms["tracktraceform"].txtBook.value;
		
		if (szCons != "")
		{
			szQS = "&CONS=" + szCons;
			bContinue = true;
		}

		if (szBook != "")
		{
			szQS += "&BOOK=" + szBook;
			bContinue = true;
		}

		if (!bContinue) { return; }

		var xpos = (screen.width - 500) / 2;
		var ypos = (screen.height - 520) / 2;
		var trackWin = window.open(szURL + szQS, 'lwmTracking','left=' + xpos + ',top=' + ypos + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=500');
		trackWin.focus();
	}
	
	function doLWMLogin()
	{
		var szURL = "https://twm.mahe.com/twmpro/lwm-redirect.nsf/GetServerAddress?OpenAgent&user=";
		var szQS = "";
		var bContinue = false;
		var szRedirect = "";
		var xmlDoc;
		
		var szUser = document.forms["lwmloginform"].lwmUser.value;
		var szPwd = document.forms["lwmloginform"].lwmPwd.value;
		
		if (szUser != "" && szPwd != "")
		{
			szURL+=szUser;			
			szQS = "&Username=" + szUser + "&Password=" + szPwd;
			bContinue = true;
		}


		if (!bContinue) { return; }
		bContinue = false;
		
		createXMLHTTPObject();
		xmlhttp.open("POST", szURL,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {				
				//alert(xmlhttp.responseText);
				//alert(xmlhttp.getAllResponseHeaders());
				//alert(xmlhttp.responseXML.xml);
				//return;
				if (xmlhttp.status==200) {
					//szRedirect = xmlhttp.getAllResponseHeaders();
					szRedirect = xmlhttp.responseXML.xml;

					// Load the XML parser
					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async = false;
					xmlDoc.loadXML (szRedirect);
					
					try {
						xmlURLValue = xmlDoc.selectSingleNode("//LWM").text;
						bContinue = true;
					} catch (e) {
						xmlURLValue = xmlDoc.selectSingleNode("//error").text;
					}

					
					if (!bContinue) { 
						alert("An error was reported from the LWM service.\n" + "Message: " + xmlURLValue);
						xmlhttp = null;
						xmlDoc = null;
						return;
					}

					xmlhttp = null;
					xmlDoc = null;
					// Set this value = "" if you want LWM to return the service_denied page
					//xmlURLValue = "";
					window.open("https://twm.mahe.com/TWMPro/LWM-Redirect.nsf/wAuthentication?OpenAgent&address=" + xmlURLValue + "&issuer=" + szUser + "&auth=" + szPwd);
				}				
			}
		}
		xmlhttp.send(null)
	}

	function checkTrackKey()
	{
		if (event.keyCode == 13)
		{
			doTracking(); }
	}
   
	function checkLWMKey()
	{
		if (event.keyCode == 13)
		{
			doLWMLogin(); }
	}

