function UradiLogin() {
	if ( (document.getElementById('LOGINEMAIL').value=='') || 
	     (document.getElementById('LOGINSIFRA').value=='') ) {		   
		   PrikaziProzorPoruke('Niste uneli sve potrebne podatke!');		   
	} else {
		var LoginEmail         = document.getElementById('LOGINEMAIL').value;
		var LoginSifra         = document.getElementById('LOGINSIFRA').value;
		var LoginPamcenje      = 0;
		if (document.getElementById('LOGINPAMTI').checked == true) {
			LoginPamcenje      = 1;	
		} 

		xmlHttp_Login=GetXmlHttpObject();
		if (xmlHttp_Login==null) {
		  alert ("Browser does not support HTTP Request");
		  return;
		}

		var url="AJAX-login.php";	
		var parametri = "LOGINEMAIL="+LoginEmail+"&"+"LOGINSIFRA="+LoginSifra+"&"+"LOGINPAMTI="+LoginPamcenje+"&"+"LOGIN=IN";
		
		xmlHttp_Login.onreadystatechange=Login_Changed;
		xmlHttp_Login.open("POST",url,true);
		xmlHttp_Login.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp_Login.setRequestHeader("Content-length", parametri.length);
		xmlHttp_Login.setRequestHeader("Connection", "close");
		xmlHttp_Login.send(parametri);	
	}
}

function Login_Changed() { 
	if (xmlHttp_Login.readyState==1) { 
		document.getElementById('LOGINRADI').style.display="block";	
		document.getElementById('LOGINBOX').style.display="none";							
	} else if (xmlHttp_Login.readyState==4) { 	
		RezultatLogin = new Array();
		RezultatLogin = xmlHttp_Login.responseText.split('$$$');
		
		if (RezultatLogin[0]=='000') {
			document.getElementById('HEDER-LINK-ROLNA').innerHTML = RezultatLogin[1];
		} else {
			PrikaziProzorPoruke(RezultatLogin[1]);
			document.getElementById('LOGINRADI').style.display="none";
			document.getElementById('LOGINBOX').style.display="block";					
		}
	}
}

// *************************************************************************************************************************************

function UradiLogoff() {

	xmlHttp_Logoff=GetXmlHttpObject();
	if (xmlHttp_Logoff==null) {		 
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url="AJAX-login.php";	
	var parametri = "LOGIN=OUT";
		
	xmlHttp_Logoff.onreadystatechange=Logoff_Changed;
	xmlHttp_Logoff.open("POST",url,true);
	xmlHttp_Logoff.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_Logoff.setRequestHeader("Content-length", parametri.length);
	xmlHttp_Logoff.setRequestHeader("Connection", "close");
	xmlHttp_Logoff.send(parametri);	
}

function Logoff_Changed() { 
	
	if (xmlHttp_Logoff.readyState==1) { 
		document.getElementById('LOGINRADI').style.display="block";	
		document.getElementById('LOGINBOX').style.display="none";							
	} else if (xmlHttp_Logoff.readyState==4) { 		
		document.getElementById('HEDER-LINK-ROLNA').innerHTML = xmlHttp_Logoff.responseText;
        window.location='index.php';
	}
}

// *************************************************************************************************************************************

function SubmitEnter(polje,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
		UradiLogin();
	    return false;
	} else {
   		return true;
	}
}

