// JavaScript Document

function AjaxEmailTest(ASPscriptSourcePath)
{	EmailValue=document.getElementById("email").value;
	PasswordValue=document.getElementById("password").value;
	parameters='Email='+EmailValue+'&Password='+PasswordValue;
	ajaxFunction (ASPscriptSourcePath+'CheckRegistration.asp',parameters,AjaxReturneDataToLoginFailedLabel,false);
	if (document.getElementById("LoginFailedLabel").innerHTML=='Welcome') {return true;}
	else {return false;}
}

function AjaxReturneDataToLoginFailedLabel(text)
{
	document.getElementById("LoginFailedLabel").style.display = "";
	document.getElementById("LoginFailedLabel").innerHTML=text;
}

function AjaxSendPassword(ASPscriptSourcePath)
{	
	var message; //contain the message to user
	var EmailValue;
	
	EmailValue=document.getElementById("email").value;
	
	//if the user didn't eneter email addres yet or Email address not in right form
	if (EmailValue=='' || EmailValue == null || (!checkEmail(EmailValue))) 
	{	
		message='כתובת דואר אלקטרוני לא תקנית.<br>';
		message=message+'סיסמתך תישלח אליך לדוא"ל איתו<br> נרשמת, אנא הקלד אותו בשדה<br> המתאים\n<a href="javascript:void(0);" onclick="AjaxSendPassword(\''+ASPscriptSourcePath+'\');">ולחץ כאן</a> להמשך.'
		document.getElementById("LoginFailedLabel").style.display = "";
		document.getElementById("LoginFailedLabel").innerHTML=message;
		return false;
	}
	
	
	
	parameters='Email='+EmailValue;
	ajaxFunction (ASPscriptSourcePath+'PasswordReminder.asp',parameters,AjaxReturneDataToLoginFailedLabel,true);
	//ajaxFunction (ASPscriptSourcePath+'test.asp',parameters,AjaxReturneDataToLoginFailedLabel);
}


//Checks Email By RegExp
function checkEmail(EmailText)
{

	var email = EmailText;
	var rExpEmail = new RegExp(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i);
	if(!rExpEmail.test(email))
	{
		return false; //email not valid
	}
	return true; //the Email Valid!
}



function ajaxFunction(URL,parameters,UseFunctionName,aSynchronicMethod)
			{   
			var thisdate = new Date()
			var xmlHttp;
			

			try
			  {
			  // Firefox, Opera 8.0+, Safari
			  xmlHttp=new XMLHttpRequest();
			  }
			catch (e)
			  {
			  // Internet Explorer
			  try
				{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
			  catch (e)
				{
				try
				  {
				  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				  }
				catch (e)
				  {
				  alert("Your browser does not support AJAX!");
				  return false;
				  }
				}
			  }
			  
			  //pay Attention!!
			  //Firefox  not proccessing this methos on synchronize ajax!!!
			  //so I had inserted this if clause
			  //for synchronized method look ahead!!
			 if (aSynchronicMethod==true) 
			 {
			   xmlHttp.onreadystatechange=function()
				  {
				  if(xmlHttp.readyState==4)
					{
						UseFunctionName(xmlHttp.responseText);
					}
				  };
			 }
			//prompt (xmlHttp,URL+'?Junk='+thisdate.getTime()+'&'+parameters);
			
					//asynchronic method
			xmlHttp.open("GET",URL+'?Junk='+thisdate.getTime()+'&'+parameters,aSynchronicMethod);
			xmlHttp.send('');  
			
			//synchronic AJAX
			if (aSynchronicMethod==false)
			{
				UseFunctionName(xmlHttp.responseText);
			}
			};



function showhide(id)
{ 
	if (document.getElementById)
	{ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none")
		{ 
			obj.style.display = ""; 
		} 
		else 
		{ 
		obj.style.display = "none"; 
		} 
	} 
	else
	{
		alert ('browser incompability!');
	}

}