

//***************** Check the form elements and submit if valid****************//


function CheckAndSubmit()
{
// check the required fields
var flagAst,flag,lblMsg

flagAst=0;


if (document.getElementById("txtName").value=="")
{
 	if (flagAst==0)
	{
		alert("שם פרטי חובה");
		document.getElementById("txtName").focus();
	}
	flagAst=1;
}
 



if (document.getElementById("txtEmail").value=="")
{
 	if (flagAst==0)
	{
		alert("דוא''ל חובה");
		document.getElementById("txtEmail").focus();
	}
	flagAst=1;
}

if (document.getElementById("txtRCName").value=="")
{
 	if (flagAst==0)
	{
		alert("שם המתכון חובה");
		document.getElementById("txtRCName").focus();
	}
	flagAst=1;
}


 
if (document.getElementById("txtDesc1").value=="")
{
 	if (flagAst==0)
	{
		alert("מצרכים חובה");
		document.getElementById("txtDesc1").focus();
	}
	flagAst=1;
}



if (document.getElementById("txtDesc2").value=="")
{
 	if (flagAst==0)
	{
		alert("אופן ההכנה חובה");
		document.getElementById("txtDesc2").focus();
	}
	flagAst=1;
}





lblMsg="";

if (flagAst==0)
{

	if  (checkLettters(document.frm.txtName.value)==true)
	{
		if (lblMsg!="")
			lblMsg+="\n"
		else
		{
			document.frm.txtName.focus();
			document.frm.txtName.select();
		}
		lblMsg+="שם לא תקין";
	}


	if (ValidateMail(document.frm.txtEmail.value)==false)
	{
		if (lblMsg!="")
			lblMsg+="\n"
		else
		{
			document.frm.txtEmail.focus();
			document.frm.txtEmail.select();
		}
		lblMsg+="דוא''ל לא תקין";
	}



	if (lblMsg=="")
	{
		document.frm.btn.disabled= true;
		document.frm.submit();
	}
	else
		alert(lblMsg);

}
}

function checkNum(num){
var i,c, wrong;
for (i=0 ; i < num.length ; i++)
{
	c = num.charAt(i)
	if ( ( (c<'0') || (c>'9') ))
		return false
}
return true
}


function checkLettters(check){
var i,c, wrong;
for (i=0 ; i < check.length ; i++)
{
c = check.charAt(i)
//        -
if ( ( (c<'a') || (c>'z') ) && ((c<'A') || (c>'Z')) && ((c<'א') || (c>'ת')) && c!=' ')
wrong=1;
}
if (wrong==1)
return true
return false
}

function ValidateMail(WhatToCheck) {
    var ValidCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.@"
	var state;
    for (i=0; i < WhatToCheck.length; i++)
    {
        if (ValidCharacters.indexOf(WhatToCheck.substring(i,i+1).toUpperCase()) == -1)
        {
           state=1;
        }
    }
      if (state==1)
			return false
	  else
	  {
			return checkmail(WhatToCheck);
	}
}

function checkmail(txt){
var i,c, state,s,d;
s=0;

   for (i=0 ; i < txt.length ; i++) {
                c = txt.charAt(i)

                if ( ( (c<'a') || (c>'z') ) && ((c<'A') || (c>'Z') ) )
                {
			     	if((i==0) || (i==txt.length-1))
			     	state=1;
				}
				if (c=='@')
					s++;
		}


		if (s!=1)
			state=1;
		else
		if ( txt.indexOf('.') == -1 )
			state=1;

        else if (txt.indexOf('@.') > -1)
			state=1;
        else if ( txt.indexOf('.@') > -1)
         state=1;

	if (state==1)
			return false

	return true


}

