//CLOSE THE CURRENT WINDOW
function closeWin() {
        this.window.close();
} 

function formatPhone(frm,field,phoneNbr) {
        re = /\D/;
        phoneNbr = phoneNbr.replace(re, "");
        if (phoneNbr.length > 10) {
                re = /^1/;
                phoneNbr = phoneNbr.replace(re, "");
        }
        document.frm.field.value = phoneNbr;
}

//SELECT LIST NAVIGATION
function linkMenu(form) {
        var myindex=form.dest.selectedIndex
        window.open(form.dest.options[myindex].value, target="_parent", "toolbar=yes,scrollbars=yes,location=yes"); 
}

                
function productView(img, product) {
        prodImage = new Image();
        prodImage.src=img;
        if (prodImage.width < 500) {
                prodImageWidth = prodImage.width + 120;
        } else {
                prodImageWidth = 700;
        }
        if (prodImage.height < 320) {
                prodImageHeight = prodImage.height + 120;
        } else {
                prodImageHeight = 700;
        }
        thisWindow=window.open("", "productWindow", "width=" + prodImageWidth + ", height=" + prodImageHeight + ", resizable, scrollbars=1");
        thisWindow.document.write("<HTML><HEAD><TITLE>PRODUCT VIEWER: " + product + "</TITLE></HEAD>");
                        
        thisWindow.document.write("<BODY BGCOLOR=FFFFFF><center><font face=Verdana size=2><b>" + product + "</b></font><br>");
                        
        thisWindow.document.write("<img src=" + prodImage.src + "><BR><A HREF=JAVASCRIPT:window.close()>CLOSE</a></center></BODY></HTML>");
                        
} 

function returnRequest(f, s) {
        if (s == 1) {
                if (f.rr_company.value == "" && f.rr_name.value == "") {
                        alert("Please enter a company name or your first and last name!");
                        f.rr_name.focus();
                        return false;
                }
                
                if (f.rr_email.value == "") {
                        alert("Please enter your email address!");
                        f.rr_email.focus();
                        return false;
                } 
                
                if (f.inv_no.value == "") {
                        alert("Please enter your eDirectHardware order number!");
                        f.inv_no.focus();
                        return false;
                } 
                
                if (f.rr_reason.value == "") {
                        alert("Please enter your reason for return!");
                        f.rr_reason.focus();
                        return false;
                }       
                        
                f.method = "post";
                f.action = "https://secure.edirecthardware.com/cgi-bin/edhcare.pl";
                f.submit();
                return true;
        
        } 
        
/*      else {
                if (confirm("Is everything correct on your return request?")) {
                        f.method = "post";
                        f.action = "https://secure.edirecthardware.com/cgi-bin/edhcare.pl";
                        f.submit();     
                } else {
                        return false;
                }
        }
*/      
}
                        
                                
function secureAlert() {
        alert("You are entering secure mode...");
        return true;
}

function validateBilling(frm, loc) {
        var valid = true;
        if (frm.cust_bfname.value == "") {
                alert("Please enter the first name!");
                frm.cust_bfname.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_blname.value == "") {
                alert("Please enter the last name!");
                frm.cust_blname.focus();
                valid = false;
                return valid;
        }                       
        if (frm.cust_badd1.value == "") {
                alert("Please enter the address!");
                frm.cust_badd1.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_bcity.value == "") {
                alert("Please enter the city!");
                frm.cust_bcity.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_bstate.value == "XX") {
                alert("Please select a state!");
                frm.cust_bstate.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_bzip.value == "") {
                alert("Please enter a zip code!");
                frm.cust_bzip.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_bphone.value == "") {
                alert("Please enter your phone number!");
                frm.cust_bphone.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_email.value == "") {
                alert("Please enter your email address!");
                frm.cust_email.focus();
                valid = false;
                return valid;
        }
        if (frm == "billForm2") {       
                if (frm.cust_uid.value != "") {
                        if (frm.cust_pwd.value == "") {
                                alert("Please enter a password!");
                                frm.cust_pwd.focus();
                                valid = false;
                                return valid;
                        }
                        if (frm.cust_pwd2.value == "") {
                                alert("Please re-enter your password for validation!");
                                frm.cust_pwd2.focus();
                                valid = false;
                                return valid;
                        }
                }
        }       
        
        return valid;
                                                                                                                        
}

// VALIDATE CREDIT CARD INFORMATION ON ORDER SUBMISSION
function validateCC(frm, loc) {
        if (frm.cust_ccnum.value == "") {
                alert("Please enter your " + frm.ord_pay_method.value + " card number!");
                frm.cust_ccnum.focus();
                return false;
        }
    if (frm.ord_pay_method.value == "AMEX") {
        if (frm.cust_cccode.value == "" || 
                        frm.cust_cccode.value.length < 4) {
                alert("Please enter the 4 digit CCV code located\n on the front of your American Express card!");
                frm.cust_cccode.focus();
                return false;
        }
    } else {
        if (frm.cust_cccode.value == "" || 
                        frm.cust_cccode.value.length < 3) {
                alert("Please enter the 3 digit CCV code\n located on the back of your credit card!");
                frm.cust_cccode.focus();
                return false;
        }
    }
        
    if (frm.cust_ccmo.selectedIndex == 0) {
        alert("Please enter a valid\n card expiration month!");
        frm.cust_ccmo.focus();
        return false;
    }
    
    if (frm.cust_ccyear.selectedIndex == 0) {
        alert("Please enter a valid\n card expiration year!");
        frm.cust_ccyear.focus();
        return false;
    }   
        
        return true;
}

function validateEmail(efield, email) {
        regExp = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

        if (!regExp.test(email)) {
                alert("Please enter a valid email address!");
                efield.focus();
                return false;
        }
        return true;
}

function validatePwd(frm) {
        var valid;
                
        if (frm.cust_pwd.value == frm.cust_pwd2.value) {
                valid = true;
        } else {
                alert("Please retype your passwords, they do not match!");
                frm.cust_pwd.focus();
                frm.cust_pwd.select();
                valid = false;
        }
                        
        return valid;
}       

function validateQuoteForm(frm) {
        var valid = true;
        if (frm.cust_bfname.value == "") {
                alert("Please enter the first name!");
                frm.cust_bfname.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_blname.value == "") {
                alert("Please enter the last name!");
                frm.cust_blname.focus();
                valid = false;
                return valid;
        }                       
        if (frm.cust_badd1.value == "") {
                alert("Please enter the address!");
                frm.cust_badd1.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_bcity.value == "") {
                alert("Please enter the city!");
                frm.cust_bcity.focus();
                valid = false;
                return valid;
        }       
        
        if (frm.cust_bctry.value == 'us') {
                if (frm.cust_bstate.value == "XX") {
                        alert("Please select a state!");
                        frm.cust_bstate.focus();
                        valid = false;
                        return valid;
                }       
        } else {
                frm.cust_bstate.value == 'XX';
        }
        if (frm.cust_bzip.value == "") {
                alert("Please enter a zip code!");
                frm.cust_bzip.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_bphone.value == "") {
                alert("Please enter your phone number!");
                frm.cust_bphone.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_email.value == "") {
                alert("Please enter your email address!");
                frm.cust_email.focus();
                valid = false;
                return valid;
        }
        if (frm.ship_same.value != 'Y') {
        if (frm.cust_sfname.value == "") {
                alert("Please enter the first name!");
                frm.cust_sfname.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_slname.value == "") {
                alert("Please enter the last name!");
                frm.cust_slname.focus();
                valid = false;
                return valid;
        }                       
        if (frm.cust_sadd1.value == "") {
                alert("Please enter the address!");
                frm.cust_sadd1.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_scity.value == "") {
                alert("Please enter the city!");
                frm.cust_scity.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_sstate.value == "XX") {
                alert("Please select a state!");
                frm.cust_sstate.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_szip.value == "") {
                alert("Please enter a zip code!");
                frm.cust_szip.focus();
                valid = false;
                return valid;
        }       
                if (frm.cust_sctry.value == 'us') {
                        if (frm.cust_sstate.value == "XX") {
                                alert("Please select a state!");
                                frm.cust_sstate.focus();
                                valid = false;
                                return valid;
                        }       
                } else {
                        frm.cust_sstate.value == 'XX';
                }
        }       
        
        return valid;
                                                                                                                        
}

function validateShipping(frm, loc) {
        var valid = true;
        if (frm.cust_sfname.value == "") {
                alert("Please enter the first name!");
                frm.cust_sfname.focus();
                valid = false;
                return valid;
        }               
        if (frm.cust_slname.value == "") {
                alert("Please enter the last name!");
                frm.cust_slname.focus();
                valid = false;
                return valid;
        }                       
        if (frm.cust_sadd1.value == "") {
                alert("Please enter the address!");
                frm.cust_sadd1.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_scity.value == "") {
                alert("Please enter the city!");
                frm.cust_scity.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_sstate.value == "XX") {
                alert("Please select a state!");
                frm.cust_sstate.focus();
                valid = false;
                return valid;
        }       
        if (frm.cust_szip.value == "") {
                alert("Please enter a zip code!");
                frm.cust_szip.focus();
                valid = false;
                return valid;
        }               


        return valid;
                                                                                                                        
}

function validateState() {
        var valid = true;
                
        if (document.hfForm.cust_bstate.value == 'XX' && document.hfForm.cust_bctry.value == 'us') {
                valid = false;
        } 

        if (valid == false) {
                alert("Please select your state");
                document.hfForm.cust_bstate.focus();
                valid = false;
        }
                        
        return valid;
}

function verifyEmail(email, email2) {
        if (email.value != email2.value) {
                alert("Your email addresses do not match, please re-enter!");
                email.focus();
                return false;
        }
        return true;
}       

