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)
	{
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false;
	}
	if (str.indexOf(" ")!=-1)
	{
		return false;
	}
	return true;				
}

function ValidateForm()
{
	var address = document.F1.address;
	if ((address.value==null)||(address.value==""))
	{
		alert("آدرس وارد نشده است");
		address.focus();
		return false;
	}
	var postal_code = document.F1.zipcode;
	var postal_codeValue = F1.zipcode.value;
	if ((postal_codeValue==null)||(postal_codeValue==""))
	{
		alert("کد پستی وارد نشده است");
		postal_code.focus();
		return false;
	}
	if (!/^[0-9]+$/.test(postal_codeValue))
	{
        alert("کد پستی باید عدد باشد");
		postal_codeValue="";
		postal_code.focus();
		return false;
	}
	if (postal_codeValue.length > 10 || postal_codeValue.length < 5)
	{
		alert("کد پستی باید 5 و یا 10 رقم باشد");
		postal_code.focus()
		return false;
	}
	
	var myRegExp = /0/;
	var matchPos1 = postal_codeValue.search(myRegExp);
	if(matchPos1 != -1)
	{
		alert("کد پستی نمیتواند شامل عدد صفر باشد");
		postal_code.value = "";
		postal_code.focus();
		return false;
	}
	var myRegExp = /2/;
	var matchPos1 = postal_codeValue.search(myRegExp);
	if(matchPos1 != -1)
	{
		alert("کد پستی نمیتواند شامل عدد 2 باشد");
		postal_code.value = "";
		postal_code.focus();
		return false;
	}
	var first_name = document.F1.name;
	if ((first_name.value==null)||(first_name.value==""))
	{
		alert("نام وارد نشده است");
		first_name.focus();
		return false;
	}
	
	var last_name = document.F1.l_name;
	if ((last_name.value==null)||(last_name.value==""))
	{
		alert("نام خانوادگی وارد نشده است");
		last_name.focus();
		return false;
	}
	var email = document.F1.email;
	if (echeck(email.value)==false)
	{
		email.value="";
	}
	var phone = document.F1.tel_home;
	var work = document.F1.tel_job;
	var cell = document.F1.tel_mobile;
	if ((phone.value != "")||(work.value != "")||(cell.value != ""))
	{
		var phoneValue = F1.phone.value;
		var workValue = F1.work.value;
		var cellValue = F1.cell.value;
		if((!/^[0-9]+$/.test(phoneValue))||phoneValue.length<5||phoneValue.length>18||(!/^[0-9]+$/.test(workValue))||workValue.length<5||workValue.length>18||(!/^[0-9]+$/.test(cellValue))||cellValue.length<5||cellValue.length>18)
		{
			alert("شماره تماس باید بصورت عدد وارد شود");
			phone.value="";
			phone.focus();
			return false;
		}
	} else {
		alert("یک شماره تماس وارد نمایید");
		phone.focus();
		return false;
	}
	return true
}

var numbers='1234567890'
function alpha(e,allow)
{
     var k;
     k=document.all?parseInt(e.keyCode): parseInt(e.which);
     return (allow.indexOf(String.fromCharCode(k))!=-1);
}

var code='13456789'
function postalcode(e,allow)
{
     var k;
     k=document.all?parseInt(e.keyCode): parseInt(e.which);
     return (allow.indexOf(String.fromCharCode(k))!=-1);
}

var farsi = true ;
var s = new Array(32,33,34,35,36,37,1548,1711,41,40,215,43,
                  1608,45,46,47,48,49,50,51,52,53,54,55,56,
                  57,58,1603,44,61,46,1567,64,1616,1584,125,
                  1609,1615,1609,1604,1570,247,1600,1548,47,
                  8217,1583,215,1563,1614,1569,1613,1601,
                  8216,123,1611,1618,1573,126,1580,1688,
                  1670,94,95,1662,1588,1584,1586,1610,1579,
                  1576,1604,1575,1607,1578,1606,1605,1574,
                  1583,1582,1581,1590,1602,1587,1601,1593,
                  1585,1589,1591,1594,1592,60,124,62,1617);
var b = navigator.userAgent.toLowerCase();
var msie  = (b.indexOf('msie')>-1)  ? true : false ;
var gecko = (b.indexOf('gecko')>-1) ? true : false ;
var opera = (b.indexOf('opera')>-1) ? true : false ;

function convert(fld,e)
{
	k =(msie) ? event.keyCode : e.which ;
	if (farsi)
	{
		if (msie && k>32 && k<128) event.keyCode = s[k-32];
		else if (gecko && k>32 && k<128)
		{
			var EVT = document.createEvent("KeyEvents");
			EVT.initKeyEvent("keypress", true, true, document.defaultView, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0, String.fromCharCode(s[k-32]).charCodeAt(0)) ;
			e.preventDefault();
			e.target.dispatchEvent(EVT);
		} else if (opera && k>31 && k<128) {
			fld.value  = fld.value + String.fromCharCode(s[k-32]);
			return false;
		}
	}
}

function LangFar (myobj)
{
       myobj.style.textAlign = "right";
       myobj.style.direction = "rtl";
       myobj.focus();
}


function LangEng (myobj)
{
       myobj.style.textAlign = "left";
       myobj.style.direction = "ltr";
       myobj.focus();
}

function change(obj){
	farsi = !fasi;
	obj.focus();
}
