﻿function checkMobile(mobile){
    var result = false;
    try{
        mobile=mobile.replace(' ','');
        if (mobile.length > 0 )
        {
          if (mobile.substr(0,1) == '+') mobile = mobile.substr(1);
          if (mobile.substr(0,1) == '98') mobile = mobile.substr(2);
          if (mobile.substr(0,1) == '0') mobile = mobile.substr(1);
          if (mobile.length ==10)
          if (!isNaN(mobile)){
              if ((parseInt(mobile.substr(0,2)) == 91) || (parseInt(mobile.substr(0,2)) == 93))
                  result= true;
          }
        }
    }catch(e){}
    return result;
}

function checkShNezam(shNezam){
    var result = false;
    var maxShNezam = 200000;
    var valisPrefices = ';د;آ;م;ك;ک;ع-آ;ت;ب;ف;گ;ك-د;ک-د;ات;';

	var sh = new String()
	sh = shNezam + '';
    try{
        sh = sh.replace(' ','');
        if (sh.length > 0 )
        {
          if (!isNaN(sh)){
          	if (sh>0 && sh < maxShNezam)
          		result = true;
          }
          else
          {
          	var prefix = sh.substr(0,sh.lastIndexOf('-')) + ';';
          	if (valisPrefices.indexOf(prefix)>0){
          		var numericPart = sh.substr(sh.lastIndexOf('-')+1);
          		if (!isNaN(numericPart))
          			result = true;
          	}
          }
        }
    }catch(e){}
    return result;
}


function checkPNC(code){
    try{
        var Ncode = new String();
        Ncode=code;
        if (Ncode.length==10){
            if (Ncode.substr(0,7) == "0000000"){
                //alert ('000000000000');
                return true;
            }
            else
            {
                var n = parseInt(Ncode.substr(0, 1)) * 10 + 
                        parseInt(Ncode.substr(1, 1)) * 9 + 
                        parseInt(Ncode.substr(2, 1)) * 8 + 
                        parseInt(Ncode.substr(3, 1)) * 7 + 
                        parseInt(Ncode.substr(4, 1)) * 6 + 
                        parseInt(Ncode.substr(5, 1)) * 5 + 
                        parseInt(Ncode.substr(6, 1)) * 4 + 
                        parseInt(Ncode.substr(7, 1)) * 3 + 
                        parseInt(Ncode.substr(8, 1)) * 2;
                var c = parseInt(Ncode.substr(9, 1));

                var r =  n % 11;
                if ((r == 0 && c == 0) || (r == 1 && c == 1) || (r + c == 11))
                    return true;
            }
        }
    }
    catch(e){}
   return false;
}

function ConfirmDel(){
var e = event.srcElement;
    if (e.innerText == 'حذف'){
        if (!confirm("آدرس مورد نظر حذف خواهد شد. آیا مطمئنید؟")){
            event.cancelBubble= true;
            return false;
        }
    }
}

function EmailCheck(txtEmail)
{
    var x = document.getElementById(txtEmail).value;
	if(x.length!=0){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(x))
	{
	alert('ادرس  پست الکترونيکی صحيح نمی باشد');
	document.getElementById(txtEmail).value='';
	document.getElementById(EnglishType).focus();
	}
	}
}
function TelCheck(txtTel){
var y = document.getElementById(txtTel).value;
if(y.length!=0){
var filter  = /^09[1,3]\d{8}$/;
	if (!filter.test(y)){
	alert('شماره تلفن همراه راصحيح نمی باشد');
	document.getElementById(txtTel).value='';
	document.getElementById(EnglishType).focus();
	}
}
}
function EnglishTypeCheck(EnglishType)
{
    var x = document.getElementById(EnglishType).value;
	if(x.length!=0){
	var filter  = /^([a-zA-Z0-9_ \.\-\@\&\$\#\!])+$/;
	if (!filter.test(x))
	{
	alert('لطفاًازحروف انگليسی وکاراکترهای معتبراستفاده نماييد');
	document.getElementById(EnglishType).value='';
	document.getElementById(EnglishType).focus();
	}
	}
}
function OnlyNumber(EnglishType)
{
    var x = document.getElementById(EnglishType).value;
	if(x.length!=0){
	var filter  = /^([0-9_ \.\/])+$/;
	if (!filter.test(x))
	{
	alert('لطفاًفقط ازاعداداستفاده نماييد');
	document.getElementById(EnglishType).value='';
	document.getElementById(EnglishType).focus();
	}
	}
}


