	String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
	};
	
	function LogIn() {
		//test
		//validate the text fields...
		var strUser = document.frmMCW.HBUSERNAME.value.trim();
		var strPass = document.frmMCW.PASSWORD.value.trim();

		//writeLog(strUser);
		
		if (strUser.length < 5 || strUser.length > 20) {
			document.frmMCW.HBUSERNAME.value = strUser;
			document.frmMCW.PASSWORD.value = strPass;
	
			alert("Please enter your username and try again.");
			document.frmMCW.HBUSERNAME.focus();
			document.frmMCW.HBUSERNAME.select();
			return;
		}
		if (strUser.charAt(0) >= "0" && strUser.charAt(0) <= "9") {
			//they must not have a username yet - send them into MCW
			document.frmMCW.HBUSERNAME.value = "";
			document.frmMCW.PASSWORD.value = "";		
			
			document.frmMCW.action = "https://hb.hcu.coop/cgi-bin/mcw000.cgi?MCWSTARTUSERNAMEREG";
			document.frmMCW.submit();
			return;
		}
		if (strPass.length < 6 || strPass.length > 20) {
			document.frmMCW.HBUSERNAME.value = strUser;
			document.frmMCW.PASSWORD.value = "";
	
			alert("Please enter your password and try again.  Your password must be between 6 and 20 characters in length.");
			clearPassword();
			document.frmMCW.PASSWORD.focus();
			return;		
		}
		if (document.frmMCW.btnLI.value == "Please Wait...") {
			return;		//we've already submitted - just exit
		}
		document.frmMCW.btnLI.value = "Please Wait...";
		document.frmMCW.btnLI.disabled = true;
		if (xhr == null) {
			//we couldn't instantiate an XML Requestor
			logInLegacy();
		} else {
			getMCWVars();
		}
	
		return;
	}
	
//	function writeLog(strUser)
//	{
//		var strParams = "username=" + strUser;
//		xhr2.open("POST", "/modules/mod_mcwtether_log.php", true);					// true = asynch
//		xhr2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//		xhr2.setRequestHeader("Content-length", strParams.length);
//		xhr2.setRequestHeader("Connection", "close");
//		xhr2.onreadystatechange = new function() { };
//		xhr2.send(strParams);
//		return;
//	}
	
	function logInLegacy() {
		document.frmMCW.C.value = "HTML";
		document.frmMCW.action = "https://www.hcu.coop/modules/mod_mcwtether/mod_mcwtether_xml.php";
		document.frmMCW.submit();
		
	}
	function clearUsername() {
		if (document.frmMCW.HBUSERNAME.value == "Username") {
			document.frmMCW.HBUSERNAME.style.color="#000000";
			document.frmMCW.HBUSERNAME.value="";
		}
		return;	
	}
	function clearPassword() {
		if (document.frmMCW.PASSWORD.value == "***" || document.frmMCW.PASSWORD.value == "") {
			document.frmMCW.PASSWORD.style.color="#000000";
			document.frmMCW.PASSWORD.value="";
		}
		return;	
	}
	function setUsername() {
		if (document.frmMCW.HBUSERNAME.value == "") {
			document.frmMCW.HBUSERNAME.style.color="#919191";
			document.frmMCW.HBUSERNAME.value="Username";
		}
		return;	
	}
	function setPassword() {
		if (document.frmMCW.PASSWORD.value == "") {
			document.frmMCW.PASSWORD.style.color="#919191";
			document.frmMCW.PASSWORD.value="***";
		}
		return;	
	}
	function getXMLHttpRequest()	// There are 3 different methods to use depending on browser and browser version
	{





   if (window.XMLHttpRequest) {
			/*
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
			netscape.security.PrivilegeManager.enablePrivilege("CapabilityPreferencesAccess ");  
			 */
			 
      return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
      try {
      	return new ActiveXObject("Msxml2.XMLHTTP");
      } catch(err) {
      	try {
      		return new ActiveXObject("Microsoft.XMLHTTP");
      	} catch (err) {
      		//do nothing
      	}
      }
		}
		return null;

		
		
		
		
		
/*
		try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {};
		try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {};
		try { return new XMLHttpRequest(); } catch(e) {};
		return null;		// If none of the 3 worked, return null;
*/
	}
	function getMCWVars()
	{
		//xhr.open("POST", "<?php echo $strMosSiteLiveHTTPS; ?>/modules/mod_mcwtether_xml.php", true);					// true = asynchronous (don't wait for response before going on)
		xhr.open("POST", "modules/mod_mcwtether/mod_mcwtether_xml.php", true);					// true = asynchronous (don't wait for response before going on)
		xhr.onreadystatechange = processResponse;	// tell it to run this function when it gets a response back
		xhr.send(null);
		return;
	}
	function processResponse() {
		
		var oXML;
		if (xhr.readyState == 4) {		//we have a complete request and response
			if (xhr.status == 200) {
			 	//we have a valid response - lets process it
				oXML = xhr.responseXML;
				
				var strExpiration = getStringData(oXML.getElementsByTagName("mcw")[0].getElementsByTagName("MCWExpiration")[0]);
				if (!isHex(strExpiration) || strExpiration.length != 48) {
					logInLegacy();
					return;
				}
				
				var strSlot = getStringData(oXML.getElementsByTagName("mcw")[0].getElementsByTagName("MCWAssignedSlot")[0]);
				if (!isHex(strSlot) || strSlot.length != 64) {
					logInLegacy();
					return;
				}
				
				var strSymDir = getStringData(oXML.getElementsByTagName("mcw")[0].getElementsByTagName("MCWSymDir")[0]);
				if (!isHex(strSymDir) || strSymDir.length != 16) {
					logInLegacy();
					return;
				}
				
				document.frmMCW.MCWEXPIRATION.value = strExpiration;
				document.frmMCW.MCWASSIGNEDSLOT.value = strSlot;
				document.frmMCW.MCWSYMDIR.value = strSymDir;
				document.frmMCW.MCWTRANTYPE.value = "MCWLOGONFORM";
				
				document.frmMCW.submit();
			} else {
				//we got a response, but it wasn't good - lets fail back to the old style
				logInLegacy();
				return;
			}
		}
		return;
	}
	function isHex(str) {
		for (var i=0; i<str.length; i++) {
			if (str.charAt(i) < "0" || str.charAt(i) > "F" || (str.charAt(i) > "9" && str.charAt(i) < "A")) {
				//we have invalid Hex code
				return false;
			}
		}
		return true;		//must be true if here.
	}
	function getStringData(oElement)
	{
	   //must use this function to avoid error if the element has no data
	   if (oElement.firstChild)    //make sure it has data before reading it.
	      return oElement.firstChild.data;
	   return "";		//return a "" if there's no data   
	}
	
	//action='https://hb.hcu.coop/cgi-bin/mcw000.cgi' method='post'
	
	var xhr = getXMLHttpRequest();
	//var xhr2 = getXMLHttpRequest();

