var tempData = "";
function startProcess(input1, input2)
{
    if (input1.length==0 || input2.length==0)    
    { 
        document.getElementById("message").innerHTML="Enter ID and Password!";
        document.getElementById("message").style.color="red";
        document.getElementById("submit").style.display="block";
        document.getElementById("loginId").focus();
        tempData = "";
	return;
    }
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="../includeFiles/checkLogin.asp";
    url=url+"?id="+input1+"&password="+input2+"&time="+Date();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    setTimeout("display()", 100);
}
var count = 0;
function display()
{   
    if (tempData != "")
    {
        if (tempData =="PASS0" || tempData == "PASS1" || tempData == "PASS2" || tempData == "PASS3" || tempData == "PASS4")
        {
            document.getElementById("message").innerHTML="";
            document.getElementById("theButton").style.display="none";
            document.getElementById("message").style.color="black";
           
	makeRedirect();
	tempData="";
        }
        else
        {            
            document.getElementById("message").style.display="block";
            document.getElementById("message").innerHTML="ID and Password are incorrect<br><br><font face=arial size=1 color=black>Forget password, click </font><a href=/mics/forgetPassword.asp><font color=blue>HERE</font></a>";
            document.getElementById("theButton").style.display="block";
            document.getElementById("message").style.color="red";
        }
	
        tempData = "";
                
    }
    else if (count <= 5)
    {
        count ++;
        setTimeout("display()", 300);
    }
    else
    {
			//makeRedirect();
        document.getElementById("message").innerHTML="The Server is too busy.";
        document.getElementById("theButton").style.display="block";
        document.getElementById("message").style.color="red";
        tempData = "";
        count = 0;
    }        
}

function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    { 
        tempData = xmlHttp.responseText;
    }
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function makeRedirect()
{
if (tempData == "PASS0")
{
	location.href="../main/video/setVideo.asp" 
}
if (tempData == "PASS1")
	location.href="../main/loadDocument/loadStep.asp" 
else if (tempData == "PASS2")
	location.href="../main/search/documents/searchDocument.asp" 
else if (tempData == "PASS3")
	location.href="../main/loadDocument/loadStep.asp"
else if (tempData == "PASS4")
{
	location.href="../main/search/documents/searchDocument.asp"
}
}
