function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function validateEmail()
{
	if (document.emailForm.toemail.selectedIndex==0)
	{
		alert("Please tell us where to direct your email.");
		document.emailForm.toemail.focus();
		return false;
	}
	if (document.emailForm.name.value=="")
	{
		alert("Please enter your name.");
		document.emailForm.name.focus();
		return false;
	}
	if (checkEmail(document.emailForm.email.value))
	{
		alert("Please enter a valid email address.");
		document.emailForm.email.focus();
		return false;
	}
	if (document.emailForm.msg.value=="")
	{
		alert("Please enter a message.");
		document.emailForm.msg.focus();
		return false;
	}
	return true;
}

function checkEmail(emailAddress) 
{
	emailReg=/(\w+[\w|\.]*\w+)(@\w+[\w|\.]*\w+\.\w{2,3})/;
	var valid = emailAddress.search(emailReg);
	if (valid != 0) 
	{
		return true;
	}
	else 
	{
		return false;
	}
}

function validateSubscribe()
{
	if (checkEmail(document.talkSubscribe.email1.value))
	{
		alert("Please enter a valid email address.");
		document.talkSubscribe.email1.focus();
		return false;
	}
	if (checkEmail(document.talkSubscribe.email2.value))
	{
		alert("Please enter a valid email address.");
		document.talkSubscribe.email2.focus();
		return false;
	}
	if (document.talkSubscribe.email1.value!=document.talkSubscribe.email2.value) {
		alert("Please make sure that you have entered the same email twice.");
		document.talkSubscribe.email1.focus();
		return false;
	}
	return true;
}

function validateSearch() {
	if (document.simpleSearch.criteria.value=='') {
		alert('Please enter something to search for.');
		document.simpleSearch.criteria.focus();
		return false;
	}
	return true;
}

function validatePayShipInfo() {
	theForm=document.payShipInfo;
	//START BILLING INFO VALIDATION
	//put in credit card validation here
	if (theForm.cc_type.selectedIndex==0) {
		alert('Billing Information: Please enter the type of credit card you are paying with.');
		theForm.cc_type.focus();
		return false;
	}
	if (theForm.cc_number.value=='') {
		alert('Billing Information: Please enter a credit card number.');
		theForm.cc_number.focus();
		return false;
	}
	if (!checkCreditCard(theForm.cc_number.value,theForm.cc_type.value)) {
		theForm.cc_type.focus();
		return false;
	}
	if (theForm.cc_ccv.value=='' || isNaN(theForm.cc_ccv.value)) {
		alert('Billing Information: Please enter a valid credit card verification number.');
		theForm.cc_ccv.focus();
		return false;
	}
	if (theForm.cc_exp_month.selectedIndex==0 || theForm.cc_exp_year.selectedIndex==0) {
		alert('Billing Information: Please enter a valid credit card expiration date.');
		theForm.cc_exp_month.focus();
		return false;
	}
	if (theForm.bill_firstname.value=='') {
		alert('Billing Information: Please enter first name.');
		theForm.bill_firstname.focus();
		return false;
	}
	if (theForm.bill_lastname.value=='') {
		alert('Billing Information: Please enter last name.');
		theForm.bill_lastname.focus();
		return false;
	}
	if (theForm.bill_address1.value=='') {
		alert('Billing Information: Please enter address.');
		theForm.bill_address1.focus();
		return false;
	}
	if (theForm.bill_city.value=='') {
		alert('Billing Information: Please enter the city.');
		theForm.bill_city.focus();
		return false;
	}
	if (theForm.bill_state.selectedIndex==0) {
		alert('Billing Information: Please enter the state.');
		theForm.bill_state.focus();
		return false;
	}
	if (theForm.bill_zip.value=='') {
		alert('Billing Information: Please enter the zip code.');
		theForm.bill_zip.focus();
		return false;
	}
	if (theForm.bill_dayphone.value=='' && theForm.bill_eveningphone.value=='') {
		alert('Billing Information: Please enter at least one phone number.');
		theForm.bill_dayphone.focus();
		return false;
	}
	if (theForm.bill_email1.value=='' || theForm.bill_email2.value=='' || (theForm.bill_email1.value!=theForm.bill_email2.value)) {
		alert('Billing Information: Please make sure both email fields are complete and match.');
		theForm.bill_email1.focus();
		return false;
	}
	//put in email syntax validation here
	//END BILLING INFO VALIDATION
	//START SHIPPING INFO VALIDATION
	if (theForm.ship_firstname.value=='') {
		alert('Shipping Information: Please enter first name.');
		theForm.ship_firstname.focus();
		return false;
	}
	if (theForm.ship_lastname.value=='') {
		alert('Shipping Information: Please enter last name.');
		theForm.ship_lastname.focus();
		return false;
	}
	if (theForm.ship_address1.value=='') {
		alert('Shipping Information: Please enter address.');
		theForm.ship_address1.focus();
		return false;
	}
	if (theForm.ship_city.value=='') {
		alert('Shipping Information: Please enter the city.');
		theForm.ship_city.focus();
		return false;
	}
	if (theForm.ship_state.selectedIndex==0) {
		alert('Shipping Information: Please enter the state.');
		theForm.ship_state.focus();
		return false;
	}
	if (theForm.ship_zip.value=='') {
		alert('Shipping Information: Please enter the zip code.');
		theForm.ship_zip.focus();
		return false;
	}
	if (theForm.ship_dayphone.value=='' && theForm.ship_eveningphone.value=='') {
		alert('Shipping Information: Please enter at least one phone number.');
		theForm.ship_dayphone.focus();
		return false;
	}
	//if email is not blank do syntax validation
	//END SHIPPING INFO VALIDATION
	return true;
}
function sameInfo() {
	theForm=document.payShipInfo;
	if (theForm.infoSame.checked==true) {
		theForm.ship_firstname.value=theForm.bill_firstname.value;
		theForm.ship_lastname.value=theForm.bill_lastname.value;
		theForm.ship_address1.value=theForm.bill_address1.value;
		theForm.ship_address2.value=theForm.bill_address2.value;
		theForm.ship_city.value=theForm.bill_city.value;
		theForm.ship_state.selectedIndex=theForm.bill_state.selectedIndex;
		theForm.ship_zip.value=theForm.bill_zip.value;
		theForm.ship_dayphone.value=theForm.bill_dayphone.value;
		theForm.ship_eveningphone.value=theForm.bill_eveningphone.value;
		theForm.ship_email.value=theForm.bill_email1.value;
	} else {
		theForm.ship_firstname.value='';
		theForm.ship_lastname.value='';
		theForm.ship_address1.value='';
		theForm.ship_address2.value='';
		theForm.ship_city.value='';
		theForm.ship_state.selectedIndex='';
		theForm.ship_zip.value='';
		theForm.ship_dayphone.value='';
		theForm.ship_eveningphone.value='';
		theForm.ship_email.value='';
	}
}

/*============================================================================*/

/*

This routine checks the credit card number. The following checks are made:

1. A number has been provided
2. The number is a right length for the card
3. The number has an appropriate prefix for the card
4. The number has a valid modulus 10 number check digit if required

If the validation fails an error is reported.

The structure of credit card formats was gleaned from a variety of sources on 
the web.

Parameters:
            cardnumber           number on the card
            cardname             name of card as defined in the card list below

Author:     John Gardner
Date:       1st November 2003
Updated:    26th Feb. 2005      Additional cards added by request

*/

/*
   If a credit card number is invalid, an error reason is loaded into the 
   global ccErrorNo variable. This can be be used to index into the global error  
   string array to report the reason to the user if required:
   
   e.g. if (!checkCreditCard (number, name) alert (ccErrors(ccErrorNo);
*/

function checkCreditCard(cardnumber, cardname) {
	var ccErrorNo = 0;
	var ccErrors = new Array ()
	
	ccErrors [0] = "Unknown card type";
	ccErrors [1] = "Please provide a credit card number";
	ccErrors [2] = "Please enter a valid credit card number";
	ccErrors [3] = "Please enter a valid credit card number";
	ccErrors [4] = "Please enter a valid credit card number";
     
  	// Array to hold the permitted card characteristics
  	var cards = new Array();

  	// Define the cards we support. You may add addtional card types.
  	
  	//  Name:      As in the selection box of the form - must be same as user's
  	//  Length:    List of possible valid lengths of the card number for the card
  	//  prefixes:  List of possible prefixes for the card
  	//  checkdigit Boolean to say whether there is a check digit
  
  	cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  	cards [1] = {name: "Mastercard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  	cards [2] = {name: "American Express", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  	cards [3] = {name: "Discover", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
               
  	// Establish card type
  	var cardType = -1;
  	for (var i=0; i<cards.length; i++) {
    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
   	 alert(ccErrors[0])
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
      alert(ccErrors[1]);
     return false; 
  }
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
      alert(ccErrors[2])
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
      alert(ccErrors[3]);
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
      alert(ccErrors[3]);
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
      alert(ccErrors[4]);
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}

/*============================================================================*/
