// ingenium JAVASCRIPT for homepage
var objEmail;
var objPass;
var fExm;
var tagit;
var yn;

// global function for elements
function $(id)
{
	return document.getElementById(id);
}

function doSignIn(formtype,fromwhere,exposeid,yn,userid){
	//alert("fromwhere: "+fromwhere);
	objEmail = $('username_'+formtype);
	objPass  = $('pass_'+formtype);
	if (IsEmail(objEmail.value)){
		if (objPass.value != ''){
		saverequest(formtype,fromwhere,exposeid,yn,userid); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   the AJAX call 
		}else{
		alert("יש להזין סיסמא");
		objPass.focus();			
		}
	}else{
		alert("יש להזין כתובת מייל תקינה");
		objEmail.focus();
	}
}

function forgotPass(formtype){
	
	objPassDiv  = $('pass_div_'+formtype);
	objPassDiv.style.display = 'none';
	$('bottom_links_'+formtype).innerHTML = 'הזן את כתובת האימייל שלך. סיסמא חדשה תשלח לך במייל.<br><center><span style="color:#40c5d8;cursor:pointer" onclick="backFromGorgotPass(\''+formtype+'\')">חזרה</span></center>';
	$('arrow_'+formtype).innerHTML = '<a href="javascript:doPASSWORD(\''+formtype+'\')" title="שחזר סיסמא"><img src="/img/blue_arrow.gif" border="0" alt="שחזר סיסמא"></a>';
	
	
}

function doPASSWORD (formtype) {
	
	objEmail = $('username_'+formtype);
	if (IsEmail(objEmail.value)){
		recoverpass(formtype); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   the AJAX call		
		}else{
			alert("נא להזין כתובת אימייל");
			$('username_'+formtype).focus();
		}
}

function backFromGorgotPass(formtype) {
	objPassDiv  = $('pass_div_'+formtype);
	objPassDiv.style.display = 'block';	
	$('bottom_links_'+formtype).innerHTML = '<span onclick="forgotPass(\''+formtype+'\')" style="cursor:pointer">שכחתי סיסמא</span> | <a href="#">מועמד חדש?</a>';
	if (formtype=='user'){
	$('arrow_'+formtype).innerHTML = '<a href="javascript:doSignIn(\''+formtype+'\')" title="שלח"><img src="/img/blue_arrow.gif" border="0" alt="שלח"></a>';
	}else{
		$('arrow_'+formtype).innerHTML = '<a href="javascript:doSignIn(\''+formtype+'\', \''+fExm+'\' , \''+tagit+'\' , \''+yn+'\')" title="שלח"><img src="/img/blue_arrow.gif" border="0" alt="שלח"></a>';	
	}
	
}

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 openContent(id)
{
	var mwas = $('mwas').value;
	$(mwas).className='ContentMenuSubTitle';
	$('mwas').value=id;
	$(id).className='ContentMenuSelected';
	doAjax("content.load.ajax.php",doContent,"id="+id);	
}

function doContent(data)
{
	//alert(data);
	
	$("MainContent").innerHTML = data;
}

// CV stuff------------------------------------------------------------------
function openCVDiv(){

	$('floatingCVDiv').style.display = "block";
}

function closeCVDiv(){
	
	$('floatingCVDiv').style.display = "none";
}

function sendCV(){

	if ($('cvfile').value == '') {
		alert('נא לבחור קובץ קורות חיים מהמחשב')
	}else{
		$('floatCVSave').innerHTML = '';
		$('CVloader').style.display = "block";
		$('cvFrm').submit();
	}
	
}

// Contact page--------------------------------------------------------------
function doContact()
	{
		if (document.contact.fullname.value != ""){
			if(IsEmail(document.contact.email.value)==true){
					document.contact.submit();
			} else{ 
				alert("נא לרשום כתובת דואר אלקטרוני חוקית");
				document.contact.email.focus();
			}
		} else{ 
			alert("נא לרשום שם");
			document.contact.fullname.focus();
		}
}

function newUserWin (uid , is_approved , i){ // userid, exposed? , location on page
window.open ('../userpage.php?id='+uid+'&is_approved='+is_approved+"&i="+i, 'nw'+uid, config='height=440,width=590, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no');

}

function Help(id)
{
	window.open ('help.php?id='+id, 'help','height=420,width=590, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no');
}