
function changeClass(id, cname){
	$(id).className=cname;
}

function IsEmail(sText) {
	var at="@"
	var dot="."
	var lat=sText.indexOf(at)
	var lstr=sText.length
	var ldot=sText.indexOf(dot)
	if (sText=="" || sText==null){ return false }
	if (sText.indexOf(at)==-1 || sText.indexOf(at)==0 || sText.indexOf(at)==lstr){ return false }
	if (sText.indexOf(dot)==-1 || sText.indexOf(dot)==0 || sText.indexOf(dot)==lstr){ return false }
	if (sText.indexOf(at,(lat+1))!=-1){ return false }
	if (sText.substring(lat-1,lat)==dot || sText.substring(lat+1,lat+2)==dot){ return false }
	if (sText.indexOf(dot,(lat+2))==-1){ return false }
	if (sText.indexOf(" ")!=-1){ return false }
 	return true					
}
function switchDisplay(id){
	if(typeof id=='object'){
		id.style.display = id.style.display == '' ? 'none' : '';
	}else{
		$(id).style.display = $(id).style.display == '' ? 'none' : '';
		if ($('username') && $(id).style.display == ''){
			$('username').focus();
		}
	}
}
function $(id){
	return document.getElementById(id);
}
function doLogin(){
	//alert("fromwhere: "+fromwhere);
	objUsername = $('username');
	objPass  = $('password');
	if (objUsername.value){
		if (objPass.value != ''){
		saverequest(); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   the AJAX call 
		}else{
		alert("יש להזין סיסמא");
		objPass.focus();			
		}
	}else{
		alert("יש להזין שם משתמש");
		objUsername.focus();
	}
}

function saverequest(){
	doAjax("login.enter.ajax.php",loginData,"username="+objUsername.value+"&pass="+objPass.value);
}

function loginData(data){
	if (data == "<user - ok/>"){
		setTimeout(function(){
			//alert(data);
			document.location.href = "/employees.php";
		},1000);
	}else{
		alert(data);	
	}

}