// ******************************************************************
// Check For Mandatory Fields
// ******************************************************************

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					
	}



var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= 9 && s.length < 11);
}


function checkValidity() {
	var returnValue = true;

	if (document.subscribe.lcname.value == "")
	{
		alert("עליך לרשום שם");
		document.subscribe.lcname.focus();
		returnValue = false;
	}
	else if (document.subscribe.lcphone.value == "" && document.subscribe.lccell.value == "")
	{
		alert("עליך לרשום טלפון");
		document.subscribe.lcphone.focus();
		returnValue = false;
	}
	
	var emailID=document.subscribe.lcmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("עליך לרשום דואר אלקטרוני")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		
		emailID.focus()
		return false
	}
	if (document.subscribe.lcphone.value != "") {
		var Phone = document.subscribe.lcphone
		if (checkInternationalPhone(Phone.value) == false) {
			alert("אנא הכנס מספר טלפון תקין")
			
			Phone.focus()
			return false
		}
	}
	if (document.subscribe.lccell.value != "") {
		var Phone2 = document.subscribe.lccell
		if (checkInternationalPhone(Phone2.value) == false) {
			alert("אנא הכנס מספר סלולארי תקין")
			
			Phone.focus()
			return false
		}
	}
return returnValue;
}


function checkValidity2() {
	
	var returnValue = true;

	if (document.stf.Name_To.value == "")
	{
		alert("עליך לרשום שם");
		document.stf.Name_To.focus();
		returnValue = false;
	}
	if (document.stf.msg.value == "")
	{
		alert("תוכן ההודעה לא יכול להיות ריק.");
		document.stf.msg.focus();
		returnValue = false;
	}
	else if (document.stf.Name_From.value == "")
	{
		alert("עליך לרשום שם");
		document.stf.Name_From.focus();
		returnValue = false;
	}
	
	var emailID=document.stf.Email_From
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("עליך לרשום דואר אלקטרוני");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.focus();
		return false;
	}
	
	var emailID=document.stf.Email_To
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("עליך לרשום דואר אלקטרוני");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		
		emailID.focus();
		return false;
	}
	
	
return returnValue;
}



