﻿function ClearField(obj, clear_value, color_class)
{
	
	if (obj.value==clear_value) { obj.value = ""; obj.className = color_class;}
}

function UnClearField(obj, clear_value, gray_class)
{
	
	if (obj.value=="")
	{ obj.value = clear_value;obj.className = gray_class;}
}

function ColorField(obj, gray_class, color_class)
{
	if (obj.value=="") obj.className = gray_class;
	else obj.className = color_class;
}

function ValidateForm(whichFormId) 
{
	var root = document.getElementById(whichFormId);
    var f_el = root.getElementsByTagName("input");


    var spn;
    var bRet = true;
    for (var i = 0; i < f_el.length; i++) {
        spn = document.getElementById("spn" + f_el[i].id)
        if (spn) //is mandatory?
            if (f_el[i].value.replace(/^\s+|\s+$/g, '') == "") 
			{
				if (!document.getElementById("Old" + f_el[i].id))
				{
                  bRet = false;				 
                  spn.style.visibility = "visible";
				}
        }
        else
            spn.style.visibility = "hidden";

    }
    f_el = document.getElementById(whichFormId).getElementsByTagName("select")
    for (var i = 0; i < f_el.length; i++) {
        spn = document.getElementById("spn" + f_el[i].id)
        if (spn) //is mandatory?
            if (f_el[i].value == "0") {
            bRet = false;		
            spn.style.visibility = "visible";
        }
        else
            spn.style.visibility = "hidden";

    }  	
	
    return bRet;
}

function validateAndSubmit(whichFormId) 
{
  if (validateForm(whichFormId)) document.getElementById(whichFormId).submit();  
}

function ValidateSignOn()
{	
	document.getElementById('spnemailbad').style.display="none";        	
	if (ValidateForm('frmSignOn'))
	{
		b = true; //stop clock on ticking pages
		
		em_str = document.getElementById('email').value
		if (em_str.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/))
			return em_str;
        else document.getElementById('spnemailbad').style.display="";
	}
	return "";
}

function ValidateContact()
{
	var bf = false, be = false, msg_on = false;
    document.getElementById('spnContactError').style.visibility ="hidden";
	document.getElementById('spnEmailError').style.display="none";
	document.getElementById('spnPhoneError').style.display="none";
	
	var e = document.getElementById('e').value ;
	var p = document.getElementById('p').value ;
	
	  if (e.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/))
	   {
		  
		  be = true;		  		  
	   }
	   else
	   { 
		   be = false;
		   if (e != "")
		   {
	  		   document.getElementById('spnEmailError').style.display="";		 
			   msg_on = true;
		   }		  		  
	   }
	 
	  if ( p.match(/0(2|3|4|8|9)-{0,1}\d{7,7}$/) ||
           p.match(/077-{0,1}\d{7,7}$/) ||
		   p.match(/05(0|2|4|7|8)-{0,1}\d{7,7}$/))		   		   
	   {
		  document.getElementById('spnPhoneError').style.display="none";
		  bf = (!msg_on) && true;		  
	   }
	   else
	   {
		  bf = false; 
		  if ( p != "" ) 
		  {
	        document.getElementById('spnPhoneError').style.display="";		 		 
		    msg_on = true;	
	      }
	   }
//alert("bf="+bf+"msg="+msg_on);
	if (bf || be)
	{
	  var f = document.getElementById('frmContact');	
	  //ClearContact(f);	
	  f.submit();
	}
	else
      if (!msg_on) document.getElementById('spnContactError').style.visibility ="visible";
}

function  ClearContact()
{
      document.getElementById('frmContact').reset();
      document.getElementById('spnContactError').style.visibility ="hidden";
      document.getElementById('spnEmailError').style.display="none";
      document.getElementById('spnPhoneError').style.display="none";
	
}

function ValidateNewsletter()
{	
	var en = document.getElementById("nlname"); 
    var em = document.getElementById("nlmail");
	if (en.value=='שם') en.value = "";	
    if(em.value=='אימייל') em.value="";	
	if (ValidateForm('frmNL'))
		if (!em.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/))
	    {
           document.getElementById('spnNlEmailError').style.visibility ="visible"; 		   
		   return false;
		}
		else
			return true;
    else
		return false;
}
