
    function CheckSerial(Serial)
    {  
        var regularexpression =/^\d{2}[2Aa][EePpRrTt17MmNnVvYyLlZzJj]\d[08Uu][0-9AFaf]\d{7}$/;
        var checkStr=new String(""); 
        var SANotValid=true; 
        var HRNotValid=true;
        checkStr = Serial;
        SANotValid = !isValid(regularexpression,checkStr);

        if (SANotValid) 
        {
            regularexpression =/^\d{7}$/;
            HRNotValid = !isValid(regularexpression,checkStr);
            if (HRNotValid)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            return true;
        }
        
    }

	function isValid(pattern, str)
	{
		return pattern.test(str);
	}
		
	function SwitchInt(mode)	
	{
		document.addform.mode.value=mode;	
		document.addform.submit();
	}    
	function stripChars(pattern, str)	
	{
		return (str.replace(pattern,""));
	}

	function jsTrim(strInput)
	{
		var strResult;
		var objRegex = new RegExp("(^\\s+)");
		strResult = strInput.replace(objRegex, "");
		objRegex = new RegExp("(\\s+$)");
		strResult = strResult.replace(objRegex, "");
		return(strResult);
	}

	function validEmailN(TheirEmail) 
	{
		var invalidChars = " /:,;"
		if (TheirEmail == "") return false;

		for (i=0; i<invalidChars.length; i++) 
		{ // does it contain any invalid characters?
			badChar = invalidChars.charAt(i);
			if (TheirEmail.indexOf(badChar,0) > -1) 
			{
			return false;
			}
		}
		var atPos = TheirEmail.indexOf("@",1); // there must be one "@" symbol
		if (atPos == -1) return false;
		
		if (TheirEmail.indexOf("@",atPos+1) != -1) return false;
		
		var periodPos = TheirEmail.indexOf(".",atPos);
		if (periodPos == -1) return false;
		
		if (periodPos+3 > TheirEmail.length) return false;
		
		return true;
	}

	function CheckPhone(Phone)	
	{
	   var regularexpression =/[^0-9()\-xX\s\+]/i;
	   var checkStr=new String("");  
	   checkStr = Phone;
	   if (checkStr.search(regularexpression)!=-1) return false;
	   return true;
	}

	function CheckFax(Phone)	
	{
	   var regularexpression =/[^0-9()\-\s\+]/i;
	   var checkStr=new String("");  
	   checkStr = Phone;
	   if (checkStr.search(regularexpression)!=-1) return false;
	   return true;
	}

	function CheckPhoneNA(Phone)	
	{
	  //old	var regularexpression =/^\(\d{3}\)\s?\d{3}\-\d{4}\s?[Xx]?\s?\d{0,4}$/;
	   var regularexpression =/^\(?\d{3}\)?\s?\-?\d{3}\-?\s?\d{4}\s?[Xx]?\s?\d{0,4}$/;
	   var notvalid=true; 
	   notvalid = !isValid(regularexpression,Phone);
	   if (notvalid) 
	   {
		return false;
	   }
	   return true;
	}

	function CheckFaxNA(Phone)	
	{
	   var regularexpression =/^\(?\d{3}\)?\s?\-?\d{3}\-?\s?\d{4}$/;
	   var notvalid=true; 
	   notvalid = !isValid(regularexpression,Phone);
	   if (notvalid) 
	   {
		return false;
	   }
	   return true;
	}

	function CheckZipCAN(Zip)	
	{
	   var regularexpression =/^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/;
	   var notvalid=true; 
	   notvalid = !isValid(regularexpression,Zip);
	   if (notvalid) 
	   {
		return false;
	   }
	   return true;
	}
	function CheckZipUSA(Zip)	
	{
	   var regularexpression =/^\d{5}$|^\d{9}$/;
	   var notvalid=true; 
	   notvalid = !isValid(regularexpression,Zip);
	   if (notvalid) 
	   {
		return false;
	   }
	   return true;
	}
	function CheckCompany(Company)	
	{
	   var regularexpression =/[^0-9A-Za-zÉéÈèÀàÊêÔôËëÇçÂâÙùÛûÎîáéíóúüÁÉÍÓÚÜñÑ¿¡°\.,&\s\?!\-@']/i;
	   var checkStr=new String("");  
	   checkStr = Company;
	   if (checkStr.search(regularexpression)!=-1) return false;
	   return true;
	}
	
//weblisting functions		
function deleteRequest()
{
	if(confirm("Are you sure to delete the pre-approval profile?\n\nClick Ok to confirm.\nClick Cancel to delete it later.")){
		document.location.href = "Delete_act.asp"
	}
}
function IsUSZip(str){
	var regularexpression = /^\d{5}\b/;
	var checkStr=new String("");  
	checkStr = str;
	if (checkStr.search(regularexpression)==-1) return false;
	return true;
}

function IsCanadaPostal(str){
	var regularexpression = /^([A-Z]\d){3}\b/;
	var checkStr=new String("");  
	checkStr = str;
	checkStr = checkStr.toUpperCase();
	if (checkStr.search(regularexpression)==-1) return false;
	return true;
}


function submitEditContactForm(){
	if(checkFormWebListing()){
		document.ProfileForm.submit();
	}
}

function checkFormWebListing(){

	var txt;
	
	txt = stripChars(/\s/g,document.ProfileForm.ContactName.value);
	if(txt.length==0){
		alert("Please enter contact name.");
		document.ProfileForm.ContactName.focus();
		return false;
	} 

	txt = stripChars(/\s/g,document.ProfileForm.ContactPhone.value);
	if(txt.length==0){
		alert("Please enter telephone number.");
		document.ProfileForm.ContactPhone.focus();
		return false;
	}else{
		if(!CheckPhoneWebListing(txt)){
			alert("Please check your telephone number.");
			document.ProfileForm.ContactPhone.focus();
			return false;
		}
	} 
	
	txt = stripChars(/\s/g,document.ProfileForm.ContactEmail.value);
	if(txt.length==0){
		alert("Please enter email address.");
		document.ProfileForm.ContactEmail.focus();
		return false;
	}else{
		if(!validEmailNWebListing(txt)){
			alert("Please enter a valid e-mail address.");
			document.ProfileForm.ContactEmail.focus();
			return false;
		}
	} 
	
	return true;
}



function validEmailNWebListing(TheirEmail) 
{
	var invalidChars = " /:,;"
	if (TheirEmail == "") return false;

	for (i=0; i<invalidChars.length; i++) 
	{ // does it contain any invalid characters?
		badChar = invalidChars.charAt(i);
		if (TheirEmail.indexOf(badChar,0) > -1) 
		{
		return false;
		}
	}
	var atPos = TheirEmail.indexOf("@",1); // there must be one "@" symbol
	if (atPos == -1) return false;
	
	if (TheirEmail.indexOf("@",atPos+1) != -1) return false;
	
	var periodPos = TheirEmail.indexOf(".",atPos);
	if (periodPos == -1) return false;
	
	if (periodPos+3 > TheirEmail.length) return false;
	
	return true;
}

function CheckPhoneWebListing(Phone)	
{
   var regularexpression =/[^0-9()\-xX\s\+]/i;
   var checkStr=new String("");  
   checkStr = Phone;
   if (checkStr.search(regularexpression)!=-1) return false;
   return true;
}


function submitFormEditProfile(){
	if(checkFormEditProfile()){
		document.ProfileForm.submit();
	}
}


