  /************************************************************/
  /*IS NUMBER FUNCTIONS                                       */
  /************************************************************/ 
  function isNumberKey(evt)
  {
  	var charCode = (evt.which) ? evt.which : event.keyCode
	if ((charCode >= 48) && (charCode <= 57)) //0 thru 9 
		return true;
	if (charCode == 8) //backspace
		return true;
		
	return false;
  }
  function isNumber(charCode)
  {
    if (charCode > 31 && (charCode < 48 || charCode > 57) && 
      (charCode < 96 || charCode > 105) && charCode != 46 && (charCode < 37 || charCode > 40))
        return false;
    return true;
  }  
  function isNumberKey_Phone(evt, txtPhone)
  {
     var charCode = (evt.which) ? evt.which : event.keyCode
     if (isNumber(charCode) == false)
        return false;
     else
     {
        if (charCode != 8) //Allow backspace
          ValidatePhone(txtPhone);
        return true;
     }
  }
  
  //PHONE VALIDATION FUNCTIONS
  function ValidatePhone(txtPhone)
  {
    //<!-- This script and many more are available free online at -->
    //<!-- The JavaScript Source!! http://javascript.internet.com -->
    //<!-- Original:  Roman Feldblum (web.developer@programmer.net) -->
    if (typeof txtPhone != 'undefined')
    {
      var phonenum = txtPhone.value;
      var d1 = phonenum.indexOf('(')
	    var d2 = phonenum.indexOf(')')
	    	    
      if(phonenum.length>5){
        if (d1 == -1)
	        phonenum = AddLeftParantheses(phonenum)
	      if (d2 == -1)
	        phonenum = AddRightParantheses(phonenum,phonenum.length)
	      d1 = phonenum.indexOf('(')
	      d2 = phonenum.indexOf(')')
	      p11=phonenum.substring(d1+1,d2);
	      if(p11.length>3){
	        p12=p11;
	        l12=p12.length;
	        l15=phonenum.length
	        //l12=l12-3
	        p13=p11.substring(0,3);
	        p14=p11.substring(3,l12);
	        p15=phonenum.substring(d2+1,l15);
	        phonenum="("+p13+")"+p14+p15;
	      }
	      l16=phonenum.length;
	      p16=phonenum.substring(d2+1,l16);
	      l17=p16.length;
	      if(l17 >= 3 && p16.indexOf('-') == -1){
		      p17=phonenum.substring(d2+1,d2+4);
		      p18=phonenum.substring(d2+4,l16);
		      p19=phonenum.substring(0,d2+1);
		      phonenum=p19+p17+"-"+p18;
	      }
      }
      else if(phonenum.length>3){
	      if (d1 == -1)
	        phonenum = AddLeftParantheses(phonenum)
	      if (d2 == -1)
	        phonenum = AddRightParantheses(phonenum,phonenum.length)
      } 
      else if(phonenum.length==3)
      {
	      if (d1 == -1)
	        phonenum = AddLeftParantheses(phonenum)
	      if (d2 == -1)
	        phonenum = AddRightParantheses(phonenum,phonenum.length)
      }
      txtPhone.value = phonenum
      setTimeout(ValidatePhone,100)
    }
  }
  
  function AddLeftParantheses(phonenum)
  {
    return ('(' + phonenum);
  }
  
  function AddRightParantheses(phonenum,len)
  {
    var tempphone = phonenum;
    if (len == 3)
      return (phonenum + ')');
    else
      return (phonenum.substring(0,4) + ")" + phonenum.substring(4));  
  }
  
  //Validate Mail List Entries
  function  validateForm()
  {
	var msg = ""
	if (document.getElementById('ContactName').value == "")
		msg = "Please enter a contact name." + '\n';
	if (document.getElementById('AgencyName').value == "")
		msg = msg + "Please enter an agency name." + '\n';
	if (document.getElementById('Addr1').value == "")
		msg = msg + "Please enter an address." + '\n';
	if (document.getElementById('City').value == "")
		msg = msg + "Please enter a city." + '\n';
	if (document.getElementById('State').value == "")
		msg = msg + "Please enter a state." + '\n';
	if (document.getElementById('Zip').value == "")
		msg = msg + "Please enter a zip code." + '\n';
	else
	{
		if (document.getElementById('Zip').value.length < 5)
			msg = msg + "Please enter a valid zip code." + '\n';
	}
	if (document.getElementById('Phone').value == "")
		msg = msg + "Please enter a phone number." + '\n';
	else
	{
		if (document.getElementById('Phone').value.length < 13)
			msg = msg + "Please enter a valid phone number." + '\n';
	}
	if ((document.getElementById('Fax').value.length < 13) && (document.getElementById('Fax').value.length > 0))
		msg = msg + "Please enter a valid fax number." + '\n';
	if (document.getElementById('Email').value == "")
		msg = msg + "Please enter an email address." + '\n';
	else
	{
		var str = document.getElementById('Email').value;
		if ((str.indexOf("@") == -1) || (str.indexOf(".") == -1)) 
			msg = msg + "Please enter a valid email address." + '\n';
	}
	if (msg == "")
		return true;
	else
	{
		alert(msg);
		return false;
	}
  }
  
  //Pop Up Window Emailing
  function popUpWindow(URLStr)
  {
	popUp = open(URLStr, 'mailform', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=no,copyhistory=yes,width=375,height=460,left=0,top=0,screenX=20,screenY=20');
	popUp.focus()
  }
		


 
