// JavaScript Document

      var XMLHttpRequestObject = false; 

      if (window.XMLHttpRequest) {
        XMLHttpRequestObject = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
      }

function getData(theDomain) 
      { 
        if(XMLHttpRequestObject) {
		
          var obj = document.getElementById("passwordError");
		  var theUsername = document.getElementById("username").value;
		  var thePassword = document.getElementById("password").value;
		  
		  var dataSource = "login.php";
		  
          XMLHttpRequestObject.open("GET", dataSource + "?un=" + name + "&ps=" + pass + "&dm=" + theDomain, true); 

          XMLHttpRequestObject.onreadystatechange = function() 
          { 
            if (XMLHttpRequestObject.readyState == 4 && 
              XMLHttpRequestObject.status == 200) { 
			  
			  //If the response text from the login.php is "Test Passed" then it will 
			  //forward you to designated website
			  	
				if (XMLHttpRequestObject.responseText == "ops") {
			
					location.href = "core/portal.php?mod=cl05a";
				} else if (XMLHttpRequestObject.responseText == "acc") {
			
					location.href = "core/portal.php?mod=cl05a";
				} else if (XMLHttpRequestObject.responseText == "non") {
			
					//obj.innerHTML = "Access Denied. Please contact your administrator.";
					alert("Access Denied. Please contact your administrator.");
				} else {
			//Any other response from the login.php will produce an error	
                obj.innerHTML = XMLHttpRequestObject.responseText; 
            	}
			} 
          } 

          XMLHttpRequestObject.send(null); 
        }
}






function checkPass(theDomain) { 
        if(XMLHttpRequestObject) {
		var ran_number= Math.random()*5;
		
		  var obj = document.getElementById("passwordError");
		  var theUsername = document.getElementById("username").value;
		  var thePassword = document.getElementById("password").value;
		  
		  	var the_brType = escape(document.getElementById("btp").value);
			var the_brVers = escape(document.getElementById("bvs").value);
			var the_osType = escape(document.getElementById("ost").value);
			var the_osVers = document.getElementById("osv").value;
			var the_userIp = escape(document.getElementById("cip").value);
			var the_scr_x = escape(document.getElementById("scrx").value);
			var the_scr_y = escape(document.getElementById("scry").value);
			var the_wdw_x = escape(document.getElementById("wdwx").value);
			var the_wdw_y = escape(document.getElementById("wdwy").value);
			var the_wdw_d = escape(document.getElementById("wdwd").value);
		  
		  var dataSource = "login.php";
		
	
		
			
		var params = 
		"snd_un=" + theUsername + 
		"&snd_ps=" + thePassword + 
		"&snd_brType=" + the_brType + 
		"&snd_brVers=" + the_brVers + 
		"&snd_osType=" + the_osType + 
		"&snd_osVers=" + the_osVers + 
		"&snd_userIp=" + the_userIp + 
		"&snd_scr_x=" + the_scr_x + 
		"&snd_scr_y=" + the_scr_y + 
		"&snd_wdw_x=" + the_wdw_x + 
		"&snd_wdw_y=" + the_wdw_y + 
		"&snd_wdw_d=" + the_wdw_d + 
		"&snd_dm=" + theDomain;
		
		//alert(params);
		
		XMLHttpRequestObject.open("POST", dataSource, true);
	  
		XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		XMLHttpRequestObject.setRequestHeader("Content-length", params.length);
		XMLHttpRequestObject.setRequestHeader("Connection", "close");
			
		
		XMLHttpRequestObject.onreadystatechange = function() 
          { 
            if (XMLHttpRequestObject.readyState == 4 && 
              XMLHttpRequestObject.status == 200) { 
			
				var theResp = XMLHttpRequestObject.responseText;
				//alert(theResp);
                if (theResp == "1"){
					//alert("Fine to Proceed");
					location.href = "core/portal.php?mod=cl05a";
				} else if (theResp == "2"){
					//obj.innerHTML = XMLHttpRequestObject.responseText; 
					showPassError("Error Code 100, please contact your administrator", 1, 5000);
				} else if (theResp == "8"){
					//alert("Disabled User");
					showPassError("Your account has been disabled, please contact your administrator", 1, 4000);
				} else if (theResp == "9"){
					//alert("Incorrect Username/Password");
					showPassError("Incorrect Username/Password. Please try again.", 1, 3000);
				} else {
					showPassError("Error Code 400, please contact your administrator", 1, 5000);
					//alert(theResp);
				}
				
            } 
          } 

          XMLHttpRequestObject.send(params); 
		  
      }
}


function valPass(theDomain){
	var theUn = document.getElementById("username").value;
	var thePp = document.getElementById("password").value;
	if(theUn == "" && thePp == ""){
		showPassError("Please enter a Username and Password", 1, 3000);
	} else {
		if(theUn == ""){
			showPassError("Please enter a Username", 1, 3000);
		} else if(thePp == ""){
			showPassError("Please enter a Password", 1, 3000);
		} else {
			checkPass(theDomain);
		}
	}
}
	  
	  
	  
function fpass(dir){
	if(dir == 1){
		document.getElementById("logNorm").style.display = "none";
		document.getElementById("logBtnNorm").style.display = "none";
		document.getElementById("logReq").style.display = "block";
		document.getElementById("logBtnReq").style.display = "block";
	} else if (dir == 2){
		document.getElementById("logReq").style.display = "none";
		document.getElementById("logBtnReq").style.display = "none";
		document.getElementById("logNorm").style.display = "block";
		document.getElementById("logBtnNorm").style.display = "block";
	}
}

function cancelReq(){
	
	fpass('2');
}

function showConf(){
	document.getElementById("confirmation").style.display = "block";
}
function hideConf(){
	document.getElementById("confirmation").style.display = "none";
}
function showPassError(msg, type, dur){
	showConf();
	if(type == 1){
		document.getElementById("confirmation").style.color = "#EC1318";
	} else if (type == 2){
		document.getElementById("confirmation").style.color = "#41943F";
	}
	document.getElementById("confirmation").innerHTML = msg;
	setTimeout("hideConf()", dur);
}
