function validateForm(obj){
    
	var formObj = obj;
    var valid = true;
	var objId="";
    var objValue="";
    
    for(var i =0;i<formObj.length;i++){
   		
		objId = formObj.elements[i].id;
		objValue = formObj.elements[i].value;
		
		switch (objId) {
			case "name":
				if(objValue ==""){
					document.getElementById(objId+"1").className="notValid";
					return false;
				}
				else{
					document.getElementById(objId+"1").className="valid";
					valid=true;
				}
				
			break;
			
			case "email":
				if(objValue ==""){
					document.getElementById(objId+"1").className="notValid";
					 return false;
				}
				else{
					if (echeck(objValue)==false){
						document.getElementById(objId).value="";
						document.getElementById(objId+"1").className="notValid";
						document.getElementById(objId).focus();
						return false;
					}
					else{
						document.getElementById(objId+"1").className="valid";
						valid=true;
					}
				}
			break;
			
			case "message":
				if(objValue ==""){
					document.getElementById(objId+"1").className="notValid";
					return false;
				}
				else{
					document.getElementById(objId+"1").className="valid";
					valid=true;
				}
			break;

		}
    }
  
    return valid;
}



function fieldValidation(field){
	
	with (field)
	{
	  if (field.value==null||field.value=="")
	  {
		document.getElementById(field.id+"1").className="notValid";
	  }
	  else
	  {
		document.getElementById(field.id+"1").className="Valid";
	  }
	}
	
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("כתובת מייל לא תקינה, אנא הכנס כתובת תקינה")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("כתובת מייל לא תקינה, אנא הכנס כתובת תקינה")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   //alert("כתובת מייל לא תקינה, אנא הכנס כתובת תקינה")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("כתובת מייל לא תקינה, אנא הכנס כתובת תקינה")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("כתובת מייל לא תקינה, אנא הכנס כתובת תקינה")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("כתובת מייל לא תקינה, אנא הכנס כתובת תקינה")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("כתובת מייל לא תקינה, אנא הכנס כתובת תקינה")
		    return false
		 }

 		 return true					
	}


