// JScript File

/* Browser Detection */
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('msie')){browser = "Internet Explorer";}

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
/* End of Browser Detection */

function createRequestObject() {
var ro;
if(browser == "Internet Explorer"){
	ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
	ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

/*-------------------------------------------------------------
	Function openLogin
	Toggle visible the login popin
---------------------------------------------------------------*/

function openLogin(){
	positionneDiv("div_login", 220, 110);
	document.getElementById("div_login").style.display="block";
}



/*-------------------------------------------------------------
	Function closeLogin
	Toggle invisible the login popin
---------------------------------------------------------------*/


function closeLogin(){
	document.getElementById("div_login").style.display="none";
}



/*-------------------------------------------------------------
	Function openDiv
	Toggle visible the defined div (theId)
---------------------------------------------------------------*/


function openDiv(theId) {
	positionneDiv(theId, 220, 110);
	document.getElementById(theId).style.display="block";
}


/*-------------------------------------------------------------
	Function closeDiv
	Toggle invisible the defined div (theId)
---------------------------------------------------------------*/


function closeDiv(theId) {
	document.getElementById(theId).style.display="none";

}







function validateLogin(){		
		login_username = document.getElementById("login_username").value;
		login_password = document.getElementById("login_password").value;
        http.open('post', 'http://www.go6.dev/4105/db_login.asp');
        http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        http.onreadystatechange = handleLogin;
        http.send('login_username='+login_username+'&login_password='+login_password);		
}


function logout(){		
        http.open('get', 'http://www.go6.dev/4105/db_logout.asp');
         http.onreadystatechange = handleLogout;
         http.send(null);		
			
}

function handleLogin() {
	if(http.readyState == 4){
		var myVars = http.responseText;
		if(myVars.indexOf('invalid') != -1)
		{
		   document.getElementById('error_login').style.display = "block";
		}
		else
		{
		    alert('Welcome! ' + myVars);
		    document.getElementById('m_login').src = "/4105/images/m_login_active.gif"
		    closeLogin();
		}
	}
}

function handleLogout() {
	if(http.readyState == 4){
		var myVars = http.responseText;
	    alert(myVars);
	    document.getElementById('m_login').src = "/4105/images/m_login.gif"
	    closeLogin();	    
	}
}