function IsEmailValid(checkThisEmail)
{
	var myEMailIsValid = true;
	var myAtSymbolAt = checkThisEmail.indexOf('@');
	var myLastDotAt = checkThisEmail.lastIndexOf('.');
	var mySpaceAt = checkThisEmail.indexOf(' ');
	var myLength = checkThisEmail.length;
	
	if (myAtSymbolAt < 1 )
	 {myEMailIsValid = false}
	
	if (myLastDotAt < myAtSymbolAt)
	 {myEMailIsValid = false}
	
	if (myLength - myLastDotAt <= 2)
	 {myEMailIsValid = false}
	
	if (mySpaceAt != -1)
	 {myEMailIsValid = false}
	
	return myEMailIsValid
}

function link_hover(field,pic)
{
	document.getElementById(field).src = "gfx/" + pic;
}

function change_pic(field,pic)
{
	document.all(field).src = "gfx/" + pic;
}

function send_mail()
{
	TheForm = document.contact;
	
	if (TheForm.contact_name.value == '')
	{
		alert("Please fill the contact name");
		TheForm.contact_name.focus()
		return;
	}
	if (TheForm.phone.value == '')
	{
		alert("Please fill your phone number");
		TheForm.phone.focus()
		return;
	}
	if (!IsEmailValid(TheForm.email.value))
	{
		alert("Please fill your Email address");
		TheForm.email.focus()
		return;
	}
	
	TheForm.action = sitePath + "contact/?cmd=send";
	TheForm.submit();
}

function check_contact_info()
{
	TheForm = document.contact;
	if (TheForm.info.value == 'אחר')
	{
		document.all("other1").style.display = "block";
	}
	else
	{
		document.all("other1").style.display = "none";
	}
}

function check_key(nextfield)
{
	var EnterKey = 13;
	if (window.event.keyCode == EnterKey)
	{
		document.getElementById(nextfield).focus();
	}
}

function fn_login()
{
	TheForm = document.frm_login;
	
	if (!IsEmailValid(TheForm.username.value))
	{
		alert("Please fill the email field currectly");
		TheForm.username.focus();
		return;
	}
	if (TheForm.password.value == '')
	{
		alert("Please fill the password field");
		TheForm.password.focus();
		return;
	}
	
	TheForm.action = sitePath + "business/operators/login/?cmd=login";
	TheForm.submit();
}

function fn_retreive_password()
{
	TheForm = document.retreive_password;
	
	if (!IsEmailValid(TheForm.user_email.value))
	{
		alert("Please fill the email field currectly");
		TheForm.user_email.focus();
		return;
	}
	
	TheForm.action = sitePath + "business/operators/retrieve/password/?cmd=send";
	TheForm.submit();
}

function fn_register()
{
	TheForm = document.register;
	
	if (TheForm.user_first_name.value == '')
	{
		alert("Please insert your first name");
		TheForm.user_first_name.focus();
		return;
	}
	if (TheForm.user_last_name.value == '')
	{
		alert("Please insert your last name");
		TheForm.user_last_name.focus();
		return;
	}
	if (TheForm.user_phone.value == '')
	{
		alert("Please insert your phone number");
		TheForm.user_phone.focus();
		return;
	}
	if (!IsEmailValid(TheForm.user_email.value))
	{
		alert("Please insert your valid email address");
		TheForm.user_email.focus();
		return;
	}
	if (TheForm.user_password.value == '')
	{
		alert("Please choose a password");
		TheForm.user_password.focus();
		return;
	}
	if (!TheForm.user_agree.checked)
	{
		alert("You must agree to the privacy statement");
		TheForm.user_agree.focus();
		return;
	}
	
	TheForm.action = sitePath + "business/operators/register/?cmd=add";
	TheForm.submit();
}
