YAHOO.namespace("kmbs");

// Declare a variable for testing to see if an "Other" choice is needed in the select
var specialSubCategories = "magicolor|pagepro";

function sweepsForm() {
    subwin = window.open( '/sweeps/sweepsentry.asp', 'sweeps', 'width=800,height=627,left=0,top=0,scrollbars=no,status=yes,toolbar=no,resizeable=no' );
    subwin.focus();
}

function addOther() {
    // Get references to the controls we need to test
    var customer = document.getElementById( "currentCustomerY" );
    var dealer   = document.getElementById( "locationID" );
    var subcat   = document.getElementById( "productSubCategory" );
    
    // Is the user a customer?
    if ( customer.checked ) {
        // Yes, they're a customer.  Has the user made a choice in the productSubCategory field?
        if ( subcat.value == "" ) {
            // They have not.  Does the locationID select control already have an "OTHER" option?
            if ( dealer.options[ dealer.options.length - 1 ].value == "OTHER" ) {
                // It does.  Remove the Other choice from the dealer select control
                dealer.options[dealer.options.length - 1] = null;
                
                // Clear the span
                document.getElementById("workedWithDealerNameDISPLAY").innerHTML = "";
            }
        } else {
            // They have.  Did the user choose "magicolor" or "pagepro" for the product subcategory?
            if ( specialSubCategories.indexOf( subcat.value ) >= 0 ) {
                // They did.  Does the locationID select control already have an "OTHER" option?
                if ( dealer.options[ dealer.options.length - 1 ].value != "OTHER" ) {
                    // It does not.  Add the Other choice to the select control
                    dealer.options[dealer.options.length] = new Option( "Other", "OTHER" );
                }
            } else {
                // They did not.  Does the locationID select control already have an "OTHER" option?
                if ( dealer.options[ dealer.options.length - 1 ].value == "OTHER" ) {
                    // It does.  Remove the Other choice from the select control
                    dealer.options[dealer.options.length - 1] = null;
                    
                    // Clear the span
                    document.getElementById("workedWithDealerNameDISPLAY").innerHTML = "";
                }
            }
        }
    }
}

function doReset() {
    document.getElementById( "workedWithDealerNameDISPLAY" ).innerHTML = "";
    document.getElementById( "locationID" ).selectedIndex = -1;
    document.getElementById( "currentCustomerObjects" ).style.display = "none";
}

function handleOther() {    
    // Get a reference to the locationID select control.
    var dealer = document.getElementById( "locationID" );
    var subcat = document.getElementById( "productSubCategory" );
        
    // Has the user made a choice in the productSubCategory field?
    if ( subcat.value != "" ) {
        // They have.  Did the user choose "magicolor" or "pagepro" for the product subcategory?
        if ( specialSubCategories.indexOf( subcat.value ) >= 0 ) {
            // They did.  Did they choose the "Other" choice?
            if ( dealer.options[dealer.selectedIndex].value == "OTHER") {
                // They did choose "Other".  Add the control for capturing the value for "Other" 
                document.getElementById( "workedWithDealerNameDISPLAY" ).innerHTML = "<i>" + dealer.options[dealer.selectedIndex].text + "</i>&nbsp;&nbsp;&nbsp;<b><span style=\"color:red\">*</span>Enter other sales partner</b>&nbsp;&nbsp;<input type=\"text\" name=\"wherePurchasedOther\" maxlength=\"100\" size=\"30\" />";
            } else {
                // They did not choose "Other".  Clear the span
                document.getElementById( "workedWithDealerNameDISPLAY" ).innerHTML = "";
            }
        } else {
            // They didn't choose "magicolor" or "pagepro".  Clear the span
            document.getElementById("workedWithDealerNameDISPLAY").innerHTML = "";
        }
    }
}

function dealerLookup() {
    // Did the user enter a zip code?
    if ( document.dataCapture.zip.value == "" ) {
        // They did not.  Display an error message
        alert( "Please enter your zip code so we can locate your nearest KMBS representative" );
        
        // Clear out the "Yes" Radio button
        document.dataCapture.currentCustomer[0].checked = false;
        
        // Delete the HTML in the workedWithDealerNameDisplay div
        document.getElementById( "workedWithDealerNameDISPLAY" ).innerHTML = "";
        
        // return false
        return false;
    
    // There is a Zip code.  Did the user indicate they're a customer?
    } else if ( document.dataCapture.currentCustomer[0].checked ) {
        // Yes, they're a customer.  Get a reference to the locationID field
        var dealer = document.getElementById( "locationID" );
        
        // Remove all options from the Dealer List field
        for ( var count = dealer.options.length - 1; count > 0; count-- ) {
            dealer.options[count] = null;
        }
        dealer.selectedIndex = 0;
        
         nlCookie = "";
         nlCookie = getCookie( "nlsource" );

         if ( nlCookie != "dc" && nlCookie != "wbkmpf0percentdc" && nlCookie != "c200kmpfpromodc" && nlCookie != "wbc35dc" && nlCookie != "wbverticaldc" ) {

             // Populate the dealer list.
             populateDealerList( dealer );
         }
        
        // return true
        return true;        
    }
}

function getNodeValue( obj, tag ) {
    return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}

function populateDealerList( dealer ) {
    // Is the user a current customer?
    if ( document.dataCapture.currentCustomer[0].checked ) {
        // They are a customer.  Show the current customer objects
        document.getElementById( "currentCustomerObjects" ).style.display = "";
    } else {
        // They are not a customer.  Hide the current customer objects
        document.getElementById( "currentCustomerObjects" ).style.display = "none";
    }
    
    // Do a look-up to determine who are the dealers for the zip code
    var url = "/content/rfq/dealer_lookup.html" + 
              "?zip="    + document.getElementById("zip").value +
              "&subcat=" + document.getElementById("productSubCategory").value;
    var vars = null;

    // Build the request
    var req =  new XMLHttpRequest();
    req.open("GET", url, true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    // Define the call back function for the request
    req.onreadystatechange = function() {
        // Was the request successful?
        if ( req.readyState != 4 || req.status != 200 )
            // It was not.  Exit now
            return;
        
        // Did we get any data back from the request?
        if (req.status == 200) {
            // We did.  Get the response XML
            var xmldoc = req.responseXML;
            
            // Get all of the "item" elements in the response XML
            var elements = xmldoc.getElementsByTagName("item");
            
            // Add the "Please select . . ." option to the select control.
            dealer.options[0] = new Option("-- Please select a Sales Partner --", "");
            
            // Add all of the values returned as item elements to the select control's options
            for (var i = 0; i < elements.length; i++) {
                var value = getNodeValue(elements[i], 'value');
                var text  = getNodeValue(elements[i], 'label');
                dealer.options[i + 1] = new Option(text, value);
            }
        }

        // Did the request finish?
        if ( req.readyState == 4 ) {
            // Yes, it did.  Add the "Other" option to the list, if needed
            addOther( dealer );
        }
    };

    // Send the request & process its response.
    req.send(vars);
}

function showRfqForm( cat, subcat, model, nl ) {
     document.getElementById( "rfqTable" ).className = "dataTableNoBorder";
     document.getElementById( "submitNoRfq" ).innerHTML = "<h2 class=\"headingTypeB01\">Please enter the information below to complete your request for a quote.</h2>";
     document.getElementById( "submitWithRfq" ).style.visibility = "visible";             
                       
    if ( cat != '' && subcat == '' ) {
        PopulateSubCats( document.dataCapture.productCategory, document.dataCapture.productSubCategory,document.dataCapture.productModel,cat );
    }

    if ( cat != '' && subcat != '' ) {
        PopulateSubCats  ( document.dataCapture.productCategory, document.dataCapture.productSubCategory,document.dataCapture.productModel, subcat );
        PopulateRfqModels( document.dataCapture.productCategory, document.dataCapture.productSubCategory,document.dataCapture.productModel, model );
    }

    nlCookie = "";
    nlCookie = getCookie( "nlsource" );

    if(nlCookie == "" || nlCookie == null) {
         nlCookie = nl;
    }

    if ( nlCookie == "dc" || nlCookie == "wbkmpf0percentdc" || nlCookie == "c200kmpfpromodc" || nlCookie == "wbc35dc" || nlCookie == "wbverticaldc" ) {
        document.dataCapture.currentCustomer[0].checked = true;
        document.getElementById( "existingCustomer" ).className = "invisible";
    }
}

function hideRfqForm( cat, subcat, model, nl ) {
    document.getElementById( "rfqTable" ).className = "dataTableInvisible";
    document.getElementById( "submitNoRfq" ).innerHTML = "<div align = \"center\"><input TYPE = \"image\" src = \"/img/buttons/submit.gif\" ID = \"btnSubmit\" NAME = \"btnSubmit\"  alt = \"Submit Request\"></div>";
    document.getElementById( "submitWithRfq" ).style.visibility = "hidden";
}

function validateForm() {
    if ( document.dataCapture.firstName.value == "" ) {
        document.dataCapture.firstName.focus();
        window.alert( "Please enter a First Name." );
        return false; 
    } else {
        if ( !isProper( document.dataCapture.firstName ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for First Name. No special characters allowed." );
            return false;       
        }      
    }
    
    if ( document.dataCapture.lastName.value == "" ) {
        document.dataCapture.lastName.focus();
        window.alert( "Please enter a Last Name." );
        return false; 
    } else {
        if ( !isProper( document.dataCapture.lastName ) ) {
            document.dataCapture.lastName.focus();
            window.alert( "Please enter a proper value for Last Name. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.email.value == ""  ) {
        document.dataCapture.email.focus();
        window.alert( "Please enter an Email Address." );
        return false; 
    }
    
    if ( ( document.dataCapture.email.value.indexOf( "@" ) < 0 ) || ( document.dataCapture.email.value.indexOf( "." ) < 0 ) ) {
        document.dataCapture.email.focus();
        window.alert( "Please enter an valid Email Address." );
        return false; 
    }
    
    if ( document.dataCapture.companyName.value == "" ) {
        document.dataCapture.companyName.focus();
        window.alert( "Please enter a Business Name." );
        return false; 
    }
    
    if ( document.dataCapture.address1.value == "" ) {
        document.dataCapture.address1.focus();
        window.alert( "Please enter a Business Address 1 value." );
        return false; 
    } else {
        if ( !isProper( document.dataCapture.address1 ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for Business Address 1. No special characters allowed." );
            return false;
        }
    }
  
    if ( document.dataCapture.address2.value != "" ) {      
        if ( !isProper( document.dataCapture.address2 ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for Business Address 2. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.city.value == "" ) {
        document.dataCapture.city.focus();
        window.alert( "Please enter a City." );
        return false;
    } else {
        if ( !isProper( document.dataCapture.city ) ) {
            document.dataCapture.city.focus();
            window.alert( "Please enter a proper value for City. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.state.value == "" ) {
        document.dataCapture.state.focus();
        window.alert( "Please select a State." );
        return false; 
    }
    
    if ( document.dataCapture.zip.value == "" ) {
        document.dataCapture.zip.focus();
        window.alert( "Please enter a Zip Code." );
        return false;
    } else {
        if ( !( /^\d{5}$/.test( document.dataCapture.zip.value ) ) ) {
            document.dataCapture.zip.focus();
            window.alert( "Please enter a valid 5-digit Zip Code." );
            return false;
        }
    }
    
    if ( document.dataCapture.telephoneArea.value == "" ) {
        document.dataCapture.telephoneArea.focus();
        window.alert( "Please enter an Area Code." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephoneArea.value ) ) {
        document.dataCapture.telephoneArea.focus();
        window.alert( "Please enter a valid Area Code." );
        return false;
    }
    
    if ( document.dataCapture.telephonePrefix.value == "" ) {
        document.dataCapture.telephonePrefix.focus();
        window.alert( "Please enter a Business Phone Number." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephonePrefix.value ) ) {
        document.dataCapture.telephonePrefix.focus();
        window.alert( "Please enter a valid Business Phone Number." );
        return false;
    }
    if ( document.dataCapture.telephoneNumber.value == "" ) {
        document.dataCapture.telephoneNumber.focus();
        window.alert( "Please enter a Business Phone Number." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephoneNumber.value ) ) {
        document.dataCapture.telephoneNumber.focus();
        window.alert( "Please enter a valid Business Phone Number." );
        return false;
    }
    
    if ( document.dataCapture.industry.value == "" ) {
        document.dataCapture.industry.focus();
        window.alert( "Please select an Industry." );
        return false;
    }
    
    if ( document.dataCapture.requestQuote[0].checked == false && document.dataCapture.requestQuote[1].checked == false ) {        
        document.dataCapture.requestQuote[0].focus();
        window.alert( "Please select if you would like to Request a Quote." );
        return false;     
    }      
    
    if ( document.dataCapture.requestQuote[0].checked == true ) {    
        nlCookie = getCookie( "nlsource" );        

        if ( nlCookie != "dc" && nlCookie != "wbkmpf0percentdc" && nlCookie != "c200kmpfpromodc" && nlCookie != "wbc35dc" && nlCookie != "wbverticaldc" ) {
            if ( document.dataCapture.currentCustomer[0].checked == false && document.dataCapture.currentCustomer[1].checked == false ) {        
                document.dataCapture.currentCustomer[0].focus();
                window.alert( "Please select if you are a current customer." );
                return false;     
            }              
              
            if ( document.dataCapture.currentCustomer[0].checked == true && document.dataCapture.locationID.value == "" ) {
                document.dataCapture.currentCustomer[0].focus();
                window.alert( "Please select your sales location." );
                dealerLookup();
                return false;
            } else if ( document.dataCapture.locationID.options[document.dataCapture.locationID.selectedIndex].value == "OTHER" ) {
                if ( document.dataCapture.wherePurchasedOther.value == "" ) {
                    document.dataCapture.wherePurchasedOther.focus();
                    window.alert( "Please enter your sales partner." );
                    return false;
                }
            }
        }

        if ( document.dataCapture.productSubCategory.value == "pagepro" || document.dataCapture.productSubCategory.value == "magicolor" ) {
            if ( nlCookie != "dc" ) {
                if ( document.dataCapture.currentCustomer[0].checked == true && document.dataCapture.locationID.value == "Other" ) {
                    if ( document.dataCapture.wherePurchasedOther.value == "" ) {
                        document.dataCapture.wherePurchasedOther.focus();
                        window.alert( "Please enter where you purchased your equipment." );
                        return false; 
                    }
                }
            }        
  
            if ( ( document.dataCapture.printerPurchase[0].checked == false ) && ( document.dataCapture.printerPurchase[1].checked == false ) ) {
                document.dataCapture.printerPurchase[0].focus();
                window.alert( "Please select how many printers you are looking to purchase." );
                return false; 
            }
        }
    } // END REQUEST A QUOTE selectED        
     
    return true;
}

function validateSTPForm() {
    if ( document.dataCapture.firstName.value == "" ) {
        document.dataCapture.firstName.focus();
        window.alert( "Please enter a First Name." );
        return false; 
    } else {
        if ( !isProper( document.dataCapture.firstName ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for First Name. No special characters allowed." );
            return false;       
        }      
    }
    
    if ( document.dataCapture.lastName.value == "" ) {
        document.dataCapture.lastName.focus();
        window.alert( "Please enter a Last Name." );
        return false; 
    } else {
        if ( !isProper( document.dataCapture.lastName ) ) {
            document.dataCapture.lastName.focus();
            window.alert( "Please enter a proper value for Last Name. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.email.value == ""  ) {
        document.dataCapture.email.focus();
        window.alert( "Please enter an Email Address." );
        return false; 
    }
    
    if ( ( document.dataCapture.email.value.indexOf( "@" ) < 0 ) || ( document.dataCapture.email.value.indexOf( "." ) < 0 ) ) {
        document.dataCapture.email.focus();
        window.alert( "Please enter an valid Email Address." );
        return false; 
    }
    
    if ( document.dataCapture.companyName.value == "" ) {
        document.dataCapture.companyName.focus();
        window.alert( "Please enter a Business Name." );
        return false; 
    }
    
    if ( document.dataCapture.address1.value == "" ) {
        document.dataCapture.address1.focus();
        window.alert( "Please enter a Business Address 1 value." );
        return false; 
    } else {
        if ( !isProper( document.dataCapture.address1 ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for Business Address 1. No special characters allowed." );
            return false;
        }
    }
  
    if ( document.dataCapture.address2.value != "" ) {      
        if ( !isProper( document.dataCapture.address2 ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for Business Address 2. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.city.value == "" ) {
        document.dataCapture.city.focus();
        window.alert( "Please enter a City." );
        return false;
    } else {
        if ( !isProper( document.dataCapture.city ) ) {
            document.dataCapture.city.focus();
            window.alert( "Please enter a proper value for City. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.state.value == "" ) {
        document.dataCapture.state.focus();
        window.alert( "Please select a State." );
        return false; 
    }
    
    if ( document.dataCapture.zip.value == "" ) {
        document.dataCapture.zip.focus();
        window.alert( "Please enter a Zip Code." );
        return false;
    } else {
        if ( !( /^\d{5}$/.test( document.dataCapture.zip.value ) ) ) {
            document.dataCapture.zip.focus();
            window.alert( "Please enter a valid 5-digit Zip Code." );
            return false;
        }
    }
    
    if ( document.dataCapture.telephoneArea.value == "" ) {
        document.dataCapture.telephoneArea.focus();
        window.alert( "Please enter an Area Code." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephoneArea.value ) ) {
        document.dataCapture.telephoneArea.focus();
        window.alert( "Please enter a valid Area Code." );
        return false;
    }
    
    if ( document.dataCapture.telephonePrefix.value == "" ) {
        document.dataCapture.telephonePrefix.focus();
        window.alert( "Please enter a Business Phone Number." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephonePrefix.value ) ) {
        document.dataCapture.telephonePrefix.focus();
        window.alert( "Please enter a valid Business Phone Number." );
        return false;
    }
    if ( document.dataCapture.telephoneNumber.value == "" ) {
        document.dataCapture.telephoneNumber.focus();
        window.alert( "Please enter a Business Phone Number." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephoneNumber.value ) ) {
        document.dataCapture.telephoneNumber.focus();
        window.alert( "Please enter a valid Business Phone Number." );
        return false;
    }
    
    if ( document.dataCapture.industry.value == "" ) {
        document.dataCapture.industry.focus();
        window.alert( "Please select an Industry." );
        return false;
    }
    
    if ( document.dataCapture.currentCustomer[0].checked == false && document.dataCapture.currentCustomer[1].checked == false ) {        
         document.dataCapture.currentCustomer[0].focus();
         window.alert( "Please select if you are a current customer." );
         return false;     
    }              
              
   if ( document.dataCapture.currentCustomer[0].checked == true && document.dataCapture.locationID.value == "" ) {
                document.dataCapture.currentCustomer[0].focus();
                window.alert( "Please select your sales location." );
                dealerLookup();
                return false;
   }
     
    return true;
}

function validateFormByModel() {
    if ( document.dataCapture.firstName.value == "" ) {
        document.dataCapture.firstName.focus();
        window.alert( "Please enter a First Name." );
        return false;
    } else {
        if ( !isProper( document.dataCapture.firstName ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for First Name. No special characters allowed." );
            return false;        
        }      
    }
    
    if ( document.dataCapture.lastName.value == "" ) {
        document.dataCapture.lastName.focus();
        window.alert( "Please enter a Last Name." );
        return false;
    } else {
        if ( !isProper( document.dataCapture.lastName ) ) {
            document.dataCapture.lastName.focus();
            window.alert( "Please enter a proper value for Last Name. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.email.value == ""  ) {
        document.dataCapture.email.focus();
        window.alert( "Please enter an Email Address." );
        return false;
    }

    if ( ( document.dataCapture.email.value.indexOf( "@" ) < 0 ) || ( document.dataCapture.email.value.indexOf( "." ) < 0 ) ) {
        document.dataCapture.email.focus();
        window.alert( "Please enter an valid Email Address." );
        return false;
    }
    
    if ( document.dataCapture.zip.value == "" ) {
        document.dataCapture.zip.focus();
        window.alert( "Please enter a Zip Code." );
        return false;
    }
    
    if ( document.dataCapture.companyName.value == "" ) {
        document.dataCapture.companyName.focus();
        window.alert( "Please enter a Company value." );
        return false;
    }
    
    if ( document.dataCapture.address1.value == "" ) {
        document.dataCapture.address1.focus();
        window.alert( "Please enter an Address 1 value." );
        return false;
    } else {
        if ( !isProper( document.dataCapture.address1 ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for Business Address 1. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.address2.value != "" ) {      
        if ( !isProper( document.dataCapture.address2 ) ) {
            document.dataCapture.firstName.focus();
            window.alert( "Please enter a proper value for Business Address 2. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.city.value == "" ) {
        document.dataCapture.city.focus();
        window.alert( "Please enter a City." );
        return false;
    } else {
        if ( !isProper( document.dataCapture.city ) ) {
            document.dataCapture.city.focus();
            window.alert( "Please enter a proper value for City. No special characters allowed." );
            return false;        
        }
    }
    
    if ( document.dataCapture.state.value == "" ) {
        document.dataCapture.state.focus();
        window.alert( "Please select a State." );
        return false;
    }
    
    if ( document.dataCapture.telephoneArea.value == "" ) {
        document.dataCapture.telephoneArea.focus();
        window.alert( "Please enter an Area Code." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephoneArea.value ) ) {
        document.dataCapture.telephoneArea.focus();
        window.alert( "Please enter a valid Area Code." );
        return false;
    } 
    
    if ( document.dataCapture.telephonePrefix.value == "" ) {
        document.dataCapture.telephonePrefix.focus();
        window.alert( "Please enter a Phone Number." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephonePrefix.value ) ) {
        document.dataCapture.telephonePrefix.focus();
        window.alert( "Please enter a valid Phone Number." );
        return false;
    }
    
    if ( document.dataCapture.telephoneNumber.value == "" ) {
        document.dataCapture.telephoneNumber.focus();
        window.alert( "Please enter a Phone Number." );
        return false;
    }
    
    if ( !IsNumeric( document.dataCapture.telephoneNumber.value ) ) {
        document.dataCapture.telephoneNumber.focus();
        window.alert( "Please enter a valid Phone Number." );
        return false;
    }
    
    if ( document.dataCapture.industry.value == "" ) {
        document.dataCapture.industry.focus();
        window.alert( "Please select an Industry." );
        return false;
    }
    
    if ( document.dataCapture.currentCustomer[0].checked == false && document.dataCapture.currentCustomer[1].checked == false ) {        
        document.dataCapture.currentCustomer[0].focus();
        window.alert( "Please select if you are a current customer." );
        return false;     
    }              
    
    if ( document.dataCapture.currentCustomer[0].checked == true && document.dataCapture.locationID.value == "" ) {
        document.dataCapture.currentCustomer[0].focus();
        window.alert( "Please select your current company." );
        dealerLookup();
        return false;     
    }
    
    if ( document.dataCapture.locationID.options[document.dataCapture.locationID.selectedIndex].value == "OTHER" ) {
        if ( document.dataCapture.wherePurchasedOther.value == "" ) {
            document.dataCapture.wherePurchasedOther.focus();
            window.alert( "Please enter your sales partner." );
            return false;
        }
    }
    
    return true;
}
   
var phone_field_length = 0;

function TabNext( obj,event,len,next_field ) {
    if ( event == "down" ) {
        phone_field_length = obj.value.length;
    } else if ( event == "up" ) {
        if ( obj.value.length != phone_field_length ) {
            phone_field_length = obj.value.length;
            if ( phone_field_length == len ) {
                next_field.focus();
            }
        }
    }
}
    
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 setFocus() {
    document.dataCapture.firstName.focus();
}

function getCookie( NameOfCookie ) {
     if ( document.cookie.length > 0 ) {

        begin = document.cookie.indexOf( NameOfCookie + "=" );
        
        if ( begin != -1 ) {      // Note: != means "is not equal to"
            begin += NameOfCookie.length + 1; 
            end = document.cookie.indexOf( ";", begin );
            
            if ( end == -1 )
                end = document.cookie.length;
            
            return unescape( document.cookie.substring( begin, end ) ); 
        }
    }
    
    return null;
}

function dealerLookupWTB() {    
    if ( document.dataCapture.zip.value == "" ) {
          alert( "Please enter your zip code so we can locate your nearest KMBS representative" );
          document.dataCapture.currentCustomer[0].checked = false;
        document.getElementById( 'workedWithDealerNameDISPLAY' ).innerHTML = "";
          return false;
    } else {      
            subwin = window.open("/content/rfq/dealer_lookup_wtb.html?zip=" + document.dataCapture.zip.value + "&cat=" + document.dataCapture.productCategory.value, 'popup', 'width=450,height=150,scrollbars=no,status=no,menubar=no,toolbar=no')
            subwin.focus();
    }
}

function isProper( formField ) {
    var string = formField.value;
    var iChars = "~^+=!*|,\":<>[]{}`\;()@&$#%";
	
    for ( var i = 0; i < string.length; i++ ) {
        if ( iChars.indexOf( string.charAt( i ) ) != -1 )
            return false;
    }
    return true;
}
