
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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);



function callNewWindow(name)
         {                 
     window.open(name,"enlarge","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=800,height=600");
             }

function callNewWindow2(name)
         {                 
     window.open(name,"enlarge","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=800,height=800");
             }

function callNewWindow3(name)
         {                 
     window.open(name,"enlarge","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=778,height=519");
             }

function callNewWindow4(name)
         {                 
     window.open(name,"enlarge","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=860,height=450");
             }


function callNewWindow5(name)
         {                 
     window.open(name,"enlarge","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=1224,height=792");
             }


//== Custom trim functions for String objects
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

function strltrim() {
    return this.replace(/^\s+/,'');
}

function strrtrim() {
    return this.replace(/\s+$/,'');
}
function strtrim() {
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
}


function validate(f) {
    var isValid = true;
    var fnameLabel = document.getElementById("fname");
    var lnameLabel = document.getElementById("lname");
    var besttimeLabel = document.getElementById("besttime");
    var phoneLabel = document.getElementById("phone");
    var emailLabel = document.getElementById("email");
    var emailcompareLabel = document.getElementById("emailcompare");
    var instruxLabel = document.getElementById("instrux");
    
    var address = f.txtAddress.value.trim();
    var city = f.txtCity.value.trim();
    var state = f.selState.options[f.selState.selectedIndex].value;
    var zip = f.txtZip.value.trim();
    var phone = f.txtPhoneNumber.value.trim();
    var email = f.txtEmail.value.trim();
    var emailcompare = f.txtEmailCompare.value.trim();
    
    var addressIsValid = false;
    var phoneIsValid = false;
    var emailIsValid = false;
    
    fnameLabel.style.color="black";
    lnameLabel.style.color="black";
    besttimeLabel.style.color="black";
    phoneLabel.style.color="black";
    emailLabel.style.color="black";
    emailcompareLabel.style.color="black";
    instruxLabel.style.color="black";
    
    if (f.txtFirstName.value.trim() == '') {
        fnameLabel.style.color="red";
        isValid = false;
    }
    
    if (f.txtLastName.value.trim() == '') {
        lnameLabel.style.color="red";
        isValid = false;
    }
    
    if (f.selBestTime.options[f.selBestTime.selectedIndex].value == 'None') {
        besttimeLabel.style.color="red";
        isValid = false;
    }
    
    
    if (+address == 0 || +city == 0 || +state == 0 || +zip == 0) {
        addressIsValid = false;
    } else {
        addressIsValid = true;
    }
    
    
    if (+phone != 0) {
        if (isValidPhone(phone)) {
            phoneIsValid = true;
        } else {
            phoneLabel.style.color="red";
            return false;
        }
    }
    
    
    if (+email != 0) {
        //validate email
        if (isValidEmail(email)) {
            if (email == emailcompare){
                emailIsValid = true;
            } else {
                emailcompareLabel.style.color="red";
                return false;
            }
        } else {
            emailLabel.style.color="red";
            return false;
        }
    }
    

    if (isValid == true) {
        if (+addressIsValid + +phoneIsValid + +emailIsValid == 0) {
            instruxLabel.style.color="red";
            return false;
        }
    } else {
        return false;
    }
}


function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


function isValidPhone(str) {
    var stripped = str.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) return false;
    if (stripped.length < 10) {
        return false;
    } else {
        return true;
    }
}