// JavaScript Document
function getCookie(c_name)
{
	if(document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name+"=")
		if(c_start!=-1)
		{
			c_start=c_start+c_name.length+1
			c_end=document.cookie.indexOf(";",c_start)
			if(c_end==-1)
				c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		}
	}
	return""
}
function login(type,frm,divErr,labU,labP){
	var docfrm = eval("document."+frm);
	var username= docfrm.username.value;
	var password= docfrm.password.value;
	if(username==""){
        //document.getElementById("usernameErr").innerHTML="Username is not Empty"; 
		document.getElementById(divErr).style.display="";
		document.getElementById(divErr).innerHTML="Username is not Empty";
		document.getElementById(labU).style.color="#FF0000" ;
		//alert("กรุณากรอกUserNameด้วยนะครับ");
		docfrm.username.focus(); 
         return false;
	}else if(password==""){
		//alert("กรุณากรอกPasswordด้วยนะครับ");
		//document.getElementById("passwordErr").innerHTML="Password is not Empty";
		document.getElementById(divErr).style.display="";
		document.getElementById(divErr).innerHTML="Password is not Empty";
		document.getElementById(labP).style.color="#FF0000" ;
		document.getElementById(labU).style.color="" ;
		docfrm.password.focus(); 
         return false;
	}
	else{
		document.getElementById(divErr).innerHTML="";
		document.getElementById(labP).style.color="" ;
		var req;
		/*if(window.XMLHttpRequest) req=new XMLHttpRequest();
		else if(window.ActiveObject) req=new ActiveObject("Microsoft.XMLHTTP");
	else{
		alert("Browser not support");return false;
	}*/
	if (window.XMLHttpRequest)
				req=new XMLHttpRequest();
			else if (window.ActiveXObject)
				req=new ActiveXObject("Microsoft.XMLHTTP");
			else{
				alert("Browser not support");
				return false;
			}
	req.onreadystatechange=function()
		{
			if(req.readyState==4){
				//alert(req.responseText);
				if(req.responseText!="1"){
					if (req.responseText.indexOf("password")>1){
						document.getElementById(divErr).style.display="";
						//var arrerror = req.responseText.split("<:XXX:>");
						//alert(arrerror[0]);
						//document.getElementById("usernameErr").innerHTML=arrerror[0];
						//document.getElementById("passwordErr").innerHTML=arrerror[1];
						document.getElementById(labP).style.color="#FF0000" ;
					//}else{
						//document.getElementById("usernameErr").innerHTML=req.responseText;
						//document.getElementById("passwordErr").innerHTML="";
						document.getElementById(labU).style.color="#FF0000" ;
						
					}
					document.getElementById(divErr).innerHTML=req.responseText;
                } 
				else{
				   switch(type){
					case 1:
					    window.location='../admin/index2.php';
		         		break;	
					case 2:
					    window.location='employer.php';
		                break;	
        			case 3:
						window.location='employee.php';
		         		break;	
					case 4:
					    window.location='sendresume.php?jid='+docfrm.jid.value+'&cid='+docfrm.cid.value;
		         		break;		
					}	
				 
				}
			}
		}
		var str=Math.random();
		var querystr="";
		if(type==1){querystr+="login.php";}else{querystr+="admin/login.php";}
		if(type==4){querystr=""; querystr+="../admin/login.php";}
		querystr+="?pop="+str;
		querystr+="&username="+username;
		querystr+="&password="+password;
		querystr+="&type="+type;
	//alert(querystr);	
	req.open("GET",querystr,true);
	req.send(null);
	}
}

function logout(type){
	var req;
			if (window.XMLHttpRequest)
				req=new XMLHttpRequest();
			else if (window.ActiveXObject)
				req=new ActiveXObject("Microsoft.XMLHTTP");
			else{
				alert("Browser not support");
				return false;
			}
req.onreadystatechange=function()
		{
			if(req.readyState==4){
				 switch(type){
					case '1':
					    window.location='../admin/index2.php';
		         		break;	
					case '2':
					    window.location='index.php';
		                break;	
        			case '3':
					    window.location='index.php';
		         		break;	
					}
			}
		}
		var str=Math.random();
		var querystr="";
		if(type==1){querystr+="logout.php";}else{querystr+="admin/logout.php";}
		querystr+="?pop="+str;
	req.open("GET",querystr,true);
	req.send(null);
	}
