// JavaScript Document
function login(user, pass, todo){
	var ajaxReq;  // The variable that makes Ajax possible!
//	document.getElementById('imgholder'+imageid).innerHTML="imgholder";
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxReq = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	if (todo==''){
		ajaxReq.onreadystatechange = function(){
			if(ajaxReq.readyState == 1 || ajaxReq.readyState == 2 || ajaxReq.readyState == 3){
				document.getElementById('popupLoginContent').innerHTML="<p class=\"verd11\">Connecting...</p>";
			}
			if(ajaxReq.readyState == 4){
				var ajaxDisplay = document.getElementById('popupLoginContent');
				ajaxDisplay.innerHTML = ajaxReq.responseText;
			}		
		}
		sid=Math.random();
		var str="user="+user+"&pass="+pass+"&todo=login"
		ajaxReq.open("POST","../inc/loginProcess.php", true)
		ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxReq.setRequestHeader("Content-length", str.length);
	    ajaxReq.setRequestHeader("Connection", "close");
		ajaxReq.send(str);
	}
	
	if (todo=='addtofav'){
		ajaxReq.onreadystatechange = function(){
			if(ajaxReq.readyState == 1 || ajaxReq.readyState == 2 || ajaxReq.readyState == 3){
				document.getElementById('popupFavContent').innerHTML="<p class=\"verd11\">Connecting...</p>";
			}
			if(ajaxReq.readyState == 4){
				var ajaxDisplay = document.getElementById('popupFavContent');
				ajaxDisplay.innerHTML = ajaxReq.responseText;
			}		
		}
		sid=Math.random();
		var str="user="+user+"&pass="+pass+"&todo=addtofav&sid="+sid
		ajaxReq.open("POST","../inc/loginProcess.php", true)
		ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxReq.setRequestHeader("Content-length", str.length);
	    ajaxReq.setRequestHeader("Connection", "close");
		ajaxReq.send(str);
	}
}
function keyListenerLogin(e, user, pass,todo){
//	alert (thisval);
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

	//down arror keycode is 40, up arrow is 38,  highlight the correct item when uparrow or downarrow is being pushed
	//if (code == 38)
	// alert("up");
/*	if(code == 40) {
		document.getElementById('sectionlist').focus();
	  document.getElementById('sectionlist').options[0].select();
	  
	}*/
	if(code == 13) {
		login(user, pass,todo);
	}
}

