﻿// JScript File
 // canada postal code
	function fValidatePostalCode(objPostalCode, objPCtext) //a1a 1s1
	{
		var digits = "0123456789"
		var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		var strPostalCode;
		var strPostalCode2;

		strPostalCode = trimAll(objPostalCode).toUpperCase();
		objPostalCode.value = strPostalCode; //A1A 1S1
		
		if (strPostalCode.length == 7)
		{
			strFourthChar = strPostalCode.substr(3,1);
			if ((strFourthChar != " ") && (strFourthChar != "-"))
			{
    			return false;
			}
			else
			{
				if (strFourthChar == " ")
				{
					strPostalCode2= strPostalCode.replace(" ", "");
				}
				else 
				{
					strPostalCode2 = strPostalCode.replace("-", "");
				}
		    	strPostalCode = strPostalCode2;
			}
		}

		if(strPostalCode.length != 6 )
		{
			return false;
		}

		if((letters.indexOf(strPostalCode.charAt(0)) < 0) || (letters.indexOf(strPostalCode.charAt(2)) < 0) || (letters.indexOf(strPostalCode.charAt(4)) < 0) )
		{
			return false;
		}
		else if((digits.indexOf(strPostalCode.charAt(1)) < 0) || (digits.indexOf(strPostalCode.charAt(3)) < 0) || (digits.indexOf(strPostalCode.charAt(5)) < 0) )
		{
			return false;
		}

	 return true;
	}
	
	//ddlmiles
	function zipcodetoradius(ddlcountry, txtzip, txtpostal, ddlradius)
    {
    if(document.getElementById(ddlcountry).value=="1")
    {
        if(document.getElementById(txtzip).value.length=="5")
        {
             document.getElementById(ddlradius).value="20";
        }
        else
        {
             document.getElementById(ddlradius).value="0";
        }
    }
    else
    {
          document.getElementById(ddlradius).value="0";
    }
    }
  
  //span
  
  function DisplayState(spnzip,spnpostal,spnstate,spnprovince,ddlstate,ddlprovince,txtzip,txtpostal,pgtype,spncounty,ddlcounty,ddlradius,radius,spn_statefirst)
 {

    var countryid= document.form1.ddlcountry.value;
 
 
 if(countryid=="1")
 {
     if(pgtype=="Register")
     {
     // document.getElementById(spncounty).style.display="block";
      //document.getElementById(ddlcounty).style.display="block";      
      //document.getElementById(spn_statefirst).style.display="block";
       document.getElementById(spnstate).style.display="block";
     document.getElementById(ddlstate).style.display="block";
      document.getElementById(spnprovince).style.display="none";
     document.getElementById(ddlprovince).style.display="none";
     document.getElementById(ddlprovince).value="1";
     document.getElementById(ddlstate).value="1";
     }
 
     document.getElementById(spnzip).style.display="block";
     document.getElementById(txtzip).style.display="block";
    
     
     document.getElementById(spnpostal).style.display="none";
     document.getElementById(txtpostal).style.display="none";
    
     document.getElementById(txtpostal).value="";
     
  document.getElementById(txtzip).value="";
    
  if(radius=="yes")
  {
  document.getElementById(ddlradius).value="0";
  }
  
 }
 else if(countryid=="2")
 { 
 
  if(pgtype=="Register")
 {
 
// document.getElementById(spncounty).style.display="none";
// document.getElementById(ddlcounty).style.display="none";
// document.getElementById(spn_statefirst).style.display="none";
     document.getElementById(spnstate).style.display="none";
     document.getElementById(ddlstate).style.display="none";
     document.getElementById(spnprovince).style.display="block";
     document.getElementById(ddlprovince).style.display="block";
     document.getElementById(ddlstate).value="1";
     document.getElementById(ddlprovince).value="1";
 }
     
     document.getElementById(txtzip).value="";
     
     document.getElementById(txtpostal).value="";
     document.getElementById(spnzip).style.display="none";
     document.getElementById(txtzip).style.display="none";
     
         
     document.getElementById(spnpostal).style.display="block";
     document.getElementById(txtpostal).style.display="block";
     
      if(radius=="yes")
  {

  document.getElementById(ddlradius).value="0";
  }
  
 }
}
 
 
 
 
 function checkUrl(theUrl)
    {    
      var incomingvalue="http://"+theUrl.value.replace("http://","");             
      if(incomingvalue.match(/^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i) ||
         incomingvalue.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i))
         {
        return true;
        }
        else
         {
         return false;
        }
    }
function textCounter(field,counter,maxlimit,prbar)
    {
    
  //  alert(prbar);
	// text width//
	    var fieldWidth =  parseInt(field.offsetWidth);
	    var charcnt = field.value.length;        

	    // trim the extra text
	    if (charcnt > maxlimit)
	     { 
		    field.value = field.value.substring(0, maxlimit);
	    }

	    else
    	
	     { 
	   
	     
	    if(prbar == "yes")
	    {
	   
	   // progress bar percentage
	    var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	    document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	    document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	   // color correction on style from CCFFF -> CC0000
	     setcolor(document.getElementById(counter),percentage,"background-color");
	    }
	    
	    }
}


function setcolor(obj,percentage,prop)
{
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
 function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   } 
   function isValidURL(url){ 
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 
    if(RegExp.test(url)){ 
        return true; 
    }else{ 
        return false; 
    } 
} 
 function opencal(field)
{
window.open('../Common/frmcalendar.aspx?cname='+ field,'Calendar','menubar=0,height=215,width=215');
} 

 function phonefn(prev,next)
    {
     var prevControl=prev;
     if (prevControl.value.length >=3)
     {
      next.focus();
     }
    } 

function CheckAll(spanChk) 
{
	  var oItem = spanChk.children;
var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
xState=theBox.checked;

elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
//elm[i].click();
if(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;
}
 }



 
  function validateEmail(str)
 {
	if(str != '')
	{
	    var strexp=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (strexp.test(str))
		{
			return 1;
		}
		else
			
		{
		
			return 0;
		}
	}
	
}
 
 
 
  function trimAll(sString) 
  {
        while (sString.substring(0,1) == ' ')
        {
            sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length-1, sString.length) == ' ')
        {
            sString = sString.substring(0,sString.length-1);
        }
    
        return sString;
    }
    
    
    
    
    function valuecheck(th)
    {
                
        if(th.value.length == 3)
        {
           if(th.id=="txtph11")
            {
              document.form1.txtph12.focus();              
            }
            if(th.id=="txtph12")
            {    
               document.form1.txtph13.focus();
            }       
          
          
       
           if(th.id=="txtph21")
            {
              document.form1.txtph22.focus();              
            }
            if(th.id=="txtph22")
            {    
               document.form1.txtph23.focus();
            }       
         }
    }
    
    
    
    
    
      function isDate(dateStr)
	{
    	var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
	    var matchArray = dateStr.match(datePat); // is the format ok?
    	if(dateStr.length==0)
	    {
    	    return true;
	    }
    
    	if(dateStr.length!=10)
	    {
    	    return false;
	    }
	
    	if (matchArray == null)
	    {
    	    return false;
	    }

    	month = matchArray[1]; // parse date into variables
	    day = matchArray[3];
	    year = matchArray[5];

    	if (month < 1 || month > 12) // check month range
	    {
    	    return false;
	    }

    	if (day < 1 || day > 31)
	    {
    	    return false;
	    }

    	if ((month==4 || month==6 || month==9 || month==11) && day==31)
	    {
    	    return false;
	    }

    	if (month == 2) // check for february 29th
	    {
    	    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        	if (day > 29 || (day==29 && !isleap))
	        {
    	         return false;
        	}
	    }

    	return true; // date is valid
	}
	 
 
 function checkdate(dateString)
 {
  var now = new Date();
  
	   	var today = new Date(now.getYear(),now.getMonth(),now.getDate());
	    
		var testdate = new Date(dateString.substring(6,10), dateString.substring(0,2)-1, dateString.substring(3,5));
	      
		
		if(testdate < now)
		{
	//	alert(now.getDate());
	//	alert("t" + testdate.getDate());
		//msg = msg + "<li> Date should be greater than today's date \n ";
		return 0;
		}
		
		else
		
		{
		    return 1;
		}	
 }
   function checkdates(fromdateStr,todateStr)
 {
  //var now = new Date();
  
	   	//var today = new Date(now.getYear(),now.getMonth(),now.getDate());
	    var testfrmdate = new Date(fromdateStr.substring(6,10), fromdateStr.substring(0,2)-1, fromdateStr.substring(3,5));
		var testtodate = new Date(todateStr.substring(6,10), todateStr.substring(0,2)-1, todateStr.substring(3,5));
	      
		
		if(testfrmdate <= testtodate)
		{
	//	alert(now.getDate());
	//	alert("t" + testdate.getDate());
		//msg = msg + "<li> Date should be greater than today's date \n ";
		return 0;
		}
		
		else
		
		{
		    return 1;
		}	
 }
