function submitBasicSearch() {

    if( document.basicsearch.sc.value.length == 0 ) {

        alert( "Please enter search text before clicking the search button." );

    } else {

        document.basicsearch.submit();

    }

}

function notLoggedIn(reason) {

    if( reason=="wishlist" ) {

        alert( "Please Log-in to add items to your wishlist." );

    } else {

       alert( "You must be logged in to perform this operation." );

    }

}

function submitAdvancedSearch() {

	var isOK = false;
	
	if (document.advancedsearch.as_bid.value < 0) {

        alert( "The are no brands containing products in the chosen subcategory. Please make another selection." );

    } else if (document.advancedsearch.as_cid.value <= 0 || document.advancedsearch.as_scid.value <= 0) {

        alert( "Please make a category and subcategory selection before clicking the search button." );

    } else if( document.advancedsearch.sc.value.length == 0 ) {

        alert( "Please enter the search keywords before clicking the search button." );

    } else {
    
		isOK = true;
    }
    
    if (isOK) {
    
		//alert( "All Good." );
		document.advancedsearch.changedselect.value = "doadvancedsearch";
		document.advancedsearch.submit();
		
	}
}

function updateSearchForm( theSelect ) {

	    document.advancedsearch.changedselect.value = theSelect;

        //alert( "Search Form Update. Hidden Field: " + document.advancedsearch.changedselect.value )
        
        document.advancedsearch.submit();

}


function submitAddToCart() {

	if (document.cartform.cart_notes.value.length > 50){
	
		alert( "Item notes are too long. Please shorten your message." );
	
	}else{
        
        document.cartform.submit();
	
	}
}


function submitAddToCart_Wishlist(theform) {

	if (document.forms[theform].cart_notes.value.length > 50){
	
		alert( "Item notes are too long. Please shorten your message." );
	
	}else{
        //alert( "Wishlist form: " + theform );
        document.forms[theform].submit();
	
	}
}
    
function submitUpdateQuantity(theform) {

	//alert(" Cart Hidden Field: " + document.cartquantityform.cart_pid.value )
	
	//alert(document.forms[theform].cartproduct_quantity.value);

	if (document.forms[theform].cartproduct_quantity.value.length > 2) {	
	
		alert( "Invalid quantity." );

	}else if (document.forms[theform].cartproduct_quantity.value > 99){
	
		alert( "Invalid quantity." );
		
	}else if (document.forms[theform].cartproduct_quantity.value < 0){
	
		alert( "Invalid quantity." );
	
	}else{

       document.forms[theform].submit();
    }

}

function submitLogin() {

	if (document.loginform.acct_email.value.length > 50){
	
		alert( "Email Address is too long." );

	}else if (document.loginform.acct_email.value.length == 0){
	
		alert( "Please enter your email address." );
	
	}else if (emailCheck(document.loginform.acct_email.value) == false){
		
		alert( "Invalid Email Addresss." );
		
	}else if (document.loginform.acct_password.value.length > 20){
	
		alert( "Password is too long." );
		
	}else if (document.loginform.acct_password.value.length == 0){
	
		alert( "Please enter your password." );
		
	}else if (document.loginform.acct_password.value.length < 6){
	
		alert( "Password is too short. Passwords must be at least 6 characters." );
	
	}else{
        
        //alert( "Login Form is good." );
        document.loginform.submit();
	
	}

}

function submitRetrievePassword() {

	if (document.retrievepasswordform.acct_email.value.length > 50){
	
		alert( "Email Address is too long." );

	}else if (document.retrievepasswordform.acct_email.value.length == 0){
	
		alert( "Please enter your email address." );
	
	}else if (emailCheck(document.retrievepasswordform.acct_email.value) == false){
		
		alert( "Invalid Email Addresss." );
	
	}else{
        
        //alert( "Login Form is good." );
        document.retrievepasswordform.submit();
	
	}

}

function submitCreateAccount() {

	formComplete = false;

	if (document.createaccountform.acct_firstname.value.length > 20){
	
		alert( "First Name is too long. Please shorten." );
		
	}else if (document.createaccountform.acct_firstname.value.length == 0){
	
		alert( "Please enter your first name." );
		
	}else if (document.createaccountform.acct_lastname.value.length > 20){
	
		alert( "Last Name is too long. Please shorten." );
	
	}else if (document.createaccountform.acct_lastname.value.length == 0){
	
		alert( "Please enter your last name." );
		
	}else if (document.createaccountform.acct_email.value.length > 50){
	
		alert( "Email Address is too long." );
		
	}else if (document.createaccountform.acct_email.value.length == 0){
	
		alert( "Please enter your email address." );
		
	}else if (document.createaccountform.acct_emailretype.value.length > 50){
	
		alert( "Email Address is too long." );
		
	}else if (document.createaccountform.acct_emailretype.value.length == 0){
	
		alert( "Please retype your email address." );
		
	}else if (document.createaccountform.acct_password.value.length > 20){
	
		alert( "Password is too long." );
		
	}else if (document.createaccountform.acct_password.value.length == 0){
	
		alert( "Please enter your password." );
		
	}else if (document.createaccountform.acct_password.value.length < 6){
	
		alert( "Password is too short. Passwords must be at least 6 characters." );
		
	}else if (document.createaccountform.acct_passwordretype.value.length > 20){
	
		alert( "Password is too long." );
		
	}else if (document.createaccountform.acct_passwordretype.value.length == 0){
	
		alert( "Please retype your password." );
		
	}else if (document.createaccountform.acct_email.value != document.createaccountform.acct_emailretype.value){
	
		alert( "Email Addresses do not match. Please enter them again." );
		
	}else if (document.createaccountform.acct_password.value != document.createaccountform.acct_passwordretype.value){
	
		alert( "Passwords do not match. Please enter them again." );
		
	}else if (emailCheck(document.createaccountform.acct_email.value) == false){
		
		alert( "Invalid Email Addresss." );
		
	}else if (document.createaccountform.acct_securityquestion.value.length > 75){
		
		alert( "Your security question is too long. Please shorten." );
		
	}else if (document.createaccountform.acct_securityquestion.value.length == 0){
		
		alert( "Please type in your security question." );
		
	}else if (document.createaccountform.acct_securityquestionanswer.value.length > 75){
		
		alert( "Your security question answer is too long. Please shorten." );
		
	}else if (document.createaccountform.acct_securityquestionanswer.value.length == 0){
		
		alert( "Please type in your security question answer." );
	
	}else{
        
        //alert( "Create Account Form is good." );
        document.createaccountform.submit();
	
	}
	
}

function submitEditAccount() {

	formComplete = false;

	if (document.editaccountform.acct_firstname.value.length > 20){
	
		alert( "First Name is too long. Please shorten." );
		
	}else if (document.editaccountform.acct_firstname.value.length == 0){
	
		alert( "Please enter your first name." );
		
	}else if (document.editaccountform.acct_lastname.value.length > 20){
	
		alert( "Last Name is too long. Please shorten." );
	
	}else if (document.editaccountform.acct_lastname.value.length == 0){
	
		alert( "Please enter your last name." );
		
	}else if (document.editaccountform.acct_email.value.length > 50){
	
		alert( "Email Address is too long." );
		
	}else if (document.editaccountform.acct_email.value.length == 0){
	
		alert( "Please enter your email address." );
		
	}else if (document.editaccountform.acct_emailretype.value.length > 50){
	
		alert( "Email Address is too long." );
		
	}else if (document.editaccountform.acct_emailretype.value.length == 0){
	
		alert( "Please retype your email address." );
		
	}else if (document.editaccountform.acct_password.value.length > 20){
	
		alert( "Password is too long." );
		
	}else if (document.editaccountform.acct_password.value.length == 0){
	
		alert( "Please enter your password." );
		
	}else if (document.editaccountform.acct_password.value.length < 6){
	
		alert( "Password is too short. Passwords must be at least 6 characters." );
		
	}else if (document.editaccountform.acct_passwordretype.value.length > 20){
	
		alert( "Password is too long." );
		
	}else if (document.editaccountform.acct_passwordretype.value.length == 0){
	
		alert( "Please retype your password." );
		
	}else if (document.editaccountform.acct_email.value != document.editaccountform.acct_emailretype.value){
	
		alert( "Email Addresses do not match. Please enter them again." );
		
	}else if (document.editaccountform.acct_password.value != document.editaccountform.acct_passwordretype.value){
	
		alert( "Passwords do not match. Please enter them again." );
		
	}else if (emailCheck(document.editaccountform.acct_email.value) == false){
		
		alert( "Invalid Email Addresss." );
		
	}else if (document.editaccountform.acct_securityquestion.value.length > 75){
		
		alert( "Your security question is too long. Please shorten." );
		
	}else if (document.editaccountform.acct_securityquestion.value.length == 0){
		
		alert( "Please type in your security question." );
		
	}else if (document.editaccountform.acct_securityquestionanswer.value.length > 75){
		
		alert( "Your security question answer is too long. Please shorten." );
		
	}else if (document.editaccountform.acct_securityquestionanswer.value.length == 0){
		
		alert( "Please type in your security question answer." );
	
	}else{
        
       // alert( "edit Account Form is good." );
        document.editaccountform.submit();
	
	}
	
}


function submitShippingAddress() {

	formComplete = false;

	if (document.shippingaddressform.shipping_firstname.value.length > 20){
	
		alert( "First Name is too long. Please shorten." );
		
	}else if (document.shippingaddressform.shipping_firstname.value.length == 0){
	
		alert( "Please enter your first name." );
		
	}else if (document.shippingaddressform.shipping_lastname.value.length > 20){
	
		alert( "Last Name is too long. Please shorten." );
	
	}else if (document.shippingaddressform.shipping_lastname.value.length == 0){
	
		alert( "Please enter your last name." );
		
	}else if (document.shippingaddressform.shipping_middleinitial.value.length > 1){
	
		alert( "Middle Initial is too long." );
		
	}else if (document.shippingaddressform.shipping_address1.value.length > 75){
	
		alert( "Address1 is too long." );
		
	}else if (document.shippingaddressform.shipping_address1.value.length == 0){
	
		alert( "Please enter your street address." );
		
	}else if (document.shippingaddressform.shipping_address2.value.length > 75){
	
		alert( "Address2 is too long." );
		
	}else if (document.shippingaddressform.shipping_city.value.length > 50){
	
		alert( "City is too long." );
		
	}else if (document.shippingaddressform.shipping_city.value.length == 0){
	
		alert( "Please enter the city." );
		
	}else if (document.shippingaddressform.shipping_state.value.length > 50){
		
		alert( "State/Province is too long." );
		
	}else if (document.shippingaddressform.shipping_state.value.length == 0){
		
		alert( "Please enter the State/Province." );
		
	}else if (document.shippingaddressform.shipping_zip.value.length > 20){
		
		alert( "Zip/Postal code is too long. Please shorten." );
		
	}else if (document.shippingaddressform.shipping_zip.value.length == 0){
		
		alert( "Please enter your zip/postal code." );

	}else if (document.shippingaddressform.shipping_phone.value.length > 20){
		
		alert( "The telephone number is too long. Please shorten." );
		
	}else if (document.shippingaddressform.shipping_phone.value.length == 0){
		
		alert( "Please enter your telephone number." );

	}else if (document.shippingaddressform.shipping_state.value != "Outside U.S."
			&& document.shippingaddressform.shipping_country.value != "United States"){
		
		alert( "Please choose the correct country or state." );
	
	}else if (document.shippingaddressform.shipping_state.value == "Outside U.S."
			&& document.shippingaddressform.shipping_country.value == "United States"){
		
		alert( "Please choose the correct country or state." );
	
	}else{
        
        
        document.shippingaddressform.submit();
	
	}
	
}

function submitBillingAddress() {

	formComplete = false;

	if (document.billingaddressform.billing_firstname.value.length > 20){
	
		alert( "First Name is too long. Please shorten." );
		
	}else if (document.billingaddressform.billing_firstname.value.length == 0){
	
		alert( "Please enter your first name." );
		
	}else if (document.billingaddressform.billing_lastname.value.length > 20){
	
		alert( "Last Name is too long. Please shorten." );
	
	}else if (document.billingaddressform.billing_lastname.value.length == 0){
	
		alert( "Please enter your last name." );
		
	}else if (document.billingaddressform.billing_middleinitial.value.length > 1){
	
		alert( "Middle Initial is too long." );
		
	}else if (document.billingaddressform.billing_address1.value.length > 75){
	
		alert( "Address1 is too long." );
		
	}else if (document.billingaddressform.billing_address1.value.length == 0){
	
		alert( "Please enter your street address." );
		
	}else if (document.billingaddressform.billing_address2.value.length > 75){
	
		alert( "Address2 is too long." );
		
	}else if (document.billingaddressform.billing_city.value.length > 50){
	
		alert( "City is too long." );
		
	}else if (document.billingaddressform.billing_city.value.length == 0){
	
		alert( "Please enter the city." );
		
	}else if (document.billingaddressform.billing_state.value.length > 50){
		
		alert( "State/Province is too long." );
		
	}else if (document.billingaddressform.billing_state.value.length == 0){
		
		alert( "Please enter the State/Province." );
		
	}else if (document.billingaddressform.billing_zip.value.length > 20){
		
		alert( "Zip/Postal code is too long. Please shorten." );
		
	}else if (document.billingaddressform.billing_zip.value.length == 0){
		
		alert( "Please enter your zip/postal code." );

	}else if (document.billingaddressform.billing_phone.value.length > 20){
		
		alert( "The telephone number is too long. Please shorten." );
		
	}else if (document.billingaddressform.billing_phone.value.length == 0){
		
		alert( "Please enter your telephone number." );

	}else if (document.billingaddressform.billing_state.value != "Outside U.S."
			&& document.billingaddressform.billing_country.value != "United States"){
		
		alert( "Please choose the correct country or state." );
	
	}else if (document.billingaddressform.billing_state.value == "Outside U.S."
			&& document.billingaddressform.billing_country.value == "United States"){
		
		alert( "Please choose the correct country or state." );
	
	}else{
        
        
        document.billingaddressform.submit();
	
	}
	
}


function submitCoupon() {

	if (document.couponform.coupon_code.value.length > 20){
	
		alert( "Invalid Coupon Length." );
	
	}else{
        
        document.couponform.submit();
	
	}
	
}

function submitOrder() {

	if (document.orderform.card_type.value.length > 16){
	
		alert( "Invalid Card Type" );
		
	}else if (document.orderform.card_type.value.length == 0){
	
		alert( "Invalid Card Type" );

	}else if (validateDigits(document.orderform.card_num.value, 15, 16) == false){
	
		alert( "Invalid Card Number" );
	
	}else if(document.orderform.exp_month.value.length > 2){
		
		alert( "Invalid Expiration Date" );

	}else if(document.orderform.exp_month.value.length == 0){
		
		alert( "Invalid Expiration Date" );

	}else if(document.orderform.exp_year.value.length > 4){
		
		alert( "Invalid Expiration Date" );

	}else if(document.orderform.exp_year.value.length == 0){
		
		alert( "Invalid Expiration Date" );

	}else if(validateDigits(document.orderform.card_cvv2.value,3,4) == false){
		
		alert( "Invalid CVV2 Code" );

	}else{

		//alert("Order Form is good");
		document.orderform.submit();

	}



}

function validateDigits(num, lower, upper) {
	var orignumber = new String(num);
	var regexp = /[^0123456789]/gi;
	var fixednumber = orignumber.replace(regexp,"");
	if (fixednumber.length > upper){
	   return(false);
	}else if (fixednumber.length < lower){
	   return(false);
	}else{
	   return(true);
	}
}


function emailCheck (emailStr) {

/*
This script and many more are available free online at -->
The JavaScript Source!! http://javascript.internet.com -->

V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
Changes:
 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original  */

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

