function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}


function checkML(mlForm, emailField)
{
	if(!checkEmail(emailField.value))
	{
		alert (_tpl_emailNotValid);
		emailField.focus();
	} else {
		var url = "xmlJoinML.php?joinML_email="+emailField.value;
		var xml = LoadXML(url);
		if(xml != null)
		{
			var response = xml.getElementsByTagName('rsp_stat')[0].firstChild.data;
			if (response == "yes")
			{
				alert (_tpl_thanksForJoining);
				emailField.value="";
			}
			else
			{
				alert (_tpl_mlJoinError);
				emailField.focus();
			}
		}
	}
	return false;
}

function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}

function showMessage(message, elementID)
{
	document.getElementById(elementID).innerText=message;
}

function clearMessage(elementID)
{
	document.getElementById(elementID).innerText="";
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }


function popupWin(popUrl, width, height)
{
	if (!navigator.appName.indexOf("Microsoft")) width+=20;
	height+=5;
	topVar=((screen.height / 2)-(height/2));
	leftVar=((screen.width / 2)-(width/2));
	window.open(popUrl, "PopUp", "height="+height+", width="+width+", top="+topVar+", left="+leftVar+", scrollbars=yes, status=no, location=no, resize=yes, menubar=no, titlebar=no, toolbar=no");
}

function switchElementDisplay(elementID){
// SWITCH SELECTED ELEMENT DISPLAY: NONE/INLINE
	if (document.getElementById(elementID).style.display=="none")
		document.getElementById(elementID).style.display="inline";
	else
		document.getElementById(elementID).style.display="none";
}

function checkSurvey(cForm)
{
	isChecked = false;
	for (i=0; i<cForm.survey_answer.length; i++)
	{
		if (cForm.survey_answer[i].checked)
			isChecked = true;
	}
	if (!isChecked)
	{
		alert (_survey_noSelection);
		return false;
	}
	else
		return true;
}

function checkContact()
{
	curForm = document.contactForm;
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (curForm[fieldName].value=="")
		{
			cMessage = eval("contAlert_"+fieldName);
			showMessage(cMessage,"pageMessage");
			setTimeout('clearMessage("pageMessage")',2500);
			curForm[fieldName].focus();
			return false;
		 }
		 if (fieldName == "email" && !checkEmail(curForm.email.value))
		{
			showMessage("כתובת המייל שהזנתם אינה תקנית","pageMessage");
			setTimeout('clearMessage("pageMessage")',2500);
			curForm.email.focus();
			return false;
		 }
	}

	return confirm(_confirm_continue);
}