var postalcode,pobox;
var good="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var bad="!#$%^&*()-_+/|\.<>';,:+،؛=?!";
var badname="!#$%^&*()_+/|\.<>';,:+،؛=?!";
var cctype;
function Trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
   //alert("number is: v"+str+ "v");
  return str;
 
}
function DHLStringValidate1(src,args)
{  var string=args.Value;
	string=Trim(string);
	if (string=="")
		args.IsValid=false; 
		
	else if (string.length>35)
	    args.IsValid=false; 
	else
	{
		for (var i = 0; i < string.length; i++) 
		{
			if (good.indexOf(string.charAt(i)) == -1 && string.charAt(i)!=" ") 
			{	args.IsValid=false;
				break;
			}
			else  
				args.IsValid=true;
		}  
	}	
}
function DHLStringValidate(src,args)
{  var string=args.Value;
	string=Trim(string);
	if (string=="")
		args.IsValid=false; 
		
	else if (string.length>35)
	    args.IsValid=false; 
	else
	{
		for (var i = 0; i < string.length; i++) 
		{
			if (bad.indexOf(string.charAt(i)) == -1) 
				args.IsValid=true;					
			else{  
				args.IsValid=false; 
				//alert("إلزامي. فقط أحرف و أرقام. العدد الأقصى 35");
				break;}
		}  
	}	
}
function DHLNameValidate(src,args)
{  var string=args.Value;
	string=Trim(string);
	if (string=="")
		args.IsValid=false; 
		
	else if (string.length>35)
	    args.IsValid=false; 
	else
	{
		for (var i = 0; i < string.length; i++) 
		{
			if (badname.indexOf(string.charAt(i)) == -1) 
				args.IsValid=true;					
			else{  
				args.IsValid=false; 
				//alert("إلزامي. فقط أحرف و أرقام. العدد الأقصى 35");
				break;}
		}  
	}	
}
function DHLNumberValidate(src,args)
{  var string=args.Value;
   var goodnumber=good.substring(0,10);
    string=Trim(string);
	if (string=="")
		args.IsValid=false; 
	else if (string.length>25)
	    args.IsValid=false; 
	else
	{
		for (var i = 0; i < string.length; i++) 
		{
			if (goodnumber.indexOf(string.charAt(i)) == -1  && string.charAt(i)!=" ") 
			{	args.IsValid=false;
				//alert("إلزامي. فقط أرقام. العدد الأقصى 25");
				break;
			}
			else  
				args.IsValid=true;
		}  
	}	
}

function DHLAddressValidate(src,args)
{
	var string=args.Value;
	string=Trim(string);
    if (string=="" || string.indexOf("'")>0)
		args.IsValid=false; 
	else if (string.length>60)
	    args.IsValid=false; 
	else{
		args.IsValid=true;
	}
			
}
function validatePOBox(oSrc, args) { 
var string=args.Value;
string=Trim(string); 
if(string=="") 
{   
    if (document.getElementById("AddressPayment1_tdistrict")!=null)
		postalcode=document.getElementById("AddressPayment1_tdistrict").value;
	else
		postalcode=document.getElementById("tdistrict").value;
	postalcode=Trim(postalcode);
	if (postalcode=="")
		args.IsValid=false;
	else
		args.IsValid=true;
		
}
	else
		args.IsValid=true;
		
			 			
}
function validatePostal(oSrc, args) {  
var string=args.Value;
if(string=="") 
{   
	if (document.getElementById("AddressPayment1_tpobox")!=null)
		pobox=Trim(document.getElementById("AddressPayment1_tpobox").value);
	else
		pobox=Trim(document.getElementById("tpobox").value);
	if (pobox=="")
		args.IsValid=false;
	else
		args.IsValid=true;
}
	else
		args.IsValid=true;			 			 
}

function fun_pmethod(fieldobject) 
{
cctype=fieldobject.value;
}
function validateNumber(oSrc, args) {    
	if ((cctype=="13" || cctype=="12" || cctype=="11") && args.Value== "")  		 
        args.IsValid=false;
	else if (cctype=="12" && ((args.Value.length!=16) || (args.Value.charAt(0)!=5)))
		args.IsValid=false;
	else if (cctype=="11" && (((args.Value.length!=16) && (args.Value.length!=13)) || (args.Value.charAt(0)!=4)))
			args.IsValid=false;		
else if (cctype=="13" && ((args.Value.length!=15) || (args.Value.substring(0,2)!=37)))
	args.IsValid=false;		
else
 args.IsValid=true;			 
}
function validateName( oSrc,args) {       			
	if ((cctype=="13" || cctype=="12" || cctype=="11") && args.Value=="")
					args.IsValid=false;
else
		args.IsValid=true;	
}
