// JavaScript Document


/************************************************
 bool ValidateEmail(string input)
 Return true or false
 if the email is valid or not.
 checks for @ and .
**************************************************/
function ValidateEmail(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0);
 if(s.indexOf)
 {
  at_character=s.indexOf('@');
  if(at_character<=0 || at_character+4>s.length)
   return false;
 }
 if(s.length<6)
  return false;
 else
  return true;
}
 
/************************************************
 bool ValidatePhone(string input)
 Return true or false
 if the phone number is valid or not.
 acepts - and + symbols
**************************************************/
function ValidatePhone(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("[-+0-9]+","gi"))>=0);
 if(s.length<5)
  return false;
 else
  return true;
}

/************************************************
 bool ValidateZip(string input)
 Return true or false
 if the zip is valid or not.
 acepts leters and numbers
**************************************************/
function ValidateZip(theinput)
{
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("[a-zA-Z0-9]+","gi"))>=0);
 if(s.length<3)
  return false;
 else
  return true;
}
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}

function CheckAddDrForm(){
	var error="";
	if(document.frmAddDr.fname.value=="" || document.frmAddDr.fname.value.lenght<3)
		error="\tYou must supply a First Name\n";
	if(document.frmAddDr.lname.value=="" || document.frmAddDr.lname.value.lenght<3)
		error+="\tYou must supply a Last Name\n";	
	if(document.frmAddDr.address1.value=="" || document.frmAddDr.address1.value.lenght<10)
		error+="\tYou must supply a Street Address\n";
	if(document.frmAddDr.city.value=="" || document.frmAddDr.city.value.lenght<5)
		error+="\tYou must supply a City\n";
	if(document.frmAddDr.state.value==-1)
		error+="\tYou must supply a State\n";
	if(!ValidateZip(document.frmAddDr.zip.value))
		error+="\tYou must supply a Postal Code\n";		
	if(!ValidatePhone(document.frmAddDr.phone.value))
		error+="\tYou must supply a Phone\n";			
	if(!ValidateEmail(document.frmAddDr.email.value))
		error+="\tYou must supply a Email\n";			
	if(hex_md5(document.frmAddDr.captcha.value.toUpperCase())!=document.frmAddDr.hidecaptcha.value)
		error+="   *  You must supply the correct code\n";
	if(error!="")
		alert("We need the following information:\n"+error);
	else {
		document.frmAddDr.submit();
	}
	return;
}

function checkMLForm(form){
	var error ="";
	if(form.fname.value.length<2 || form.lname.value.length<2)
		error+="   *  You must supply a First Name and Last Name\n";
	if(!ValidateEmail(form.email.value))
		error+="   *  You must supply an Email Address\n";
	if(hex_md5(form.captcha.value.toUpperCase())!=form.hidecaptcha.value)
		error+="   *  You must supply the correct code\n";
	
	if(error!="")
		alert("Please Make the Following Changes:\n\n"+error);
	else
		form.submit();
		
}

function showHideStates(){
        if((document.getElementById('country').value==231)||(document.getElementById('country').value==39)){
            document.getElementById('stateTD').style.visibility = 'visible';
        } else {
            document.getElementById('stateTD').style.visibility = 'hidden';
        }

}
