function addToCart( productToAdd ) {
 var lame = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "w","x","y","z","!","@","#","$","%","^","&","*","(",")","-","_","+","=","[","{","}","]",":",";","\"","'",",","<",">","/","?","|","\\"];

 if ( productToAdd.amountAdded.value == "" ) {
  alert( "Enter an Add to Cart Amount" );
  productToAdd.amountAdded.focus();
  return false;
 } 
 
 if ( productToAdd.amountAdded.value != "" ) {
  var amount = productToAdd.amountAdded.value;
  for (i=0; i<productToAdd.amountAdded.value.length; i++) {
   for (x=0; x<lame.length; x++) {
    if (amount.charAt(i).toLowerCase() == lame[x]) {
     alert( "Enter a Valid Add to Cart Amount" );
     productToAdd.amountAdded.focus();
     return false;
    }
   }
  }
 }
 return true;
}


function customerInfo( customerInformation ) {
 var zip_lame = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "w","x","y","z","!","@","#","$","%","^","&","*","(",")","_","+","=","[","{","}","]",":",";","\"","'",",","<",">","/","?","|","\\"];
 
 if ( customerInformation.firstName.value == "" ) {
  alert( "Please Enter Your Billing First Name" );
  customerInformation.firstName.focus();
  return false;
 }
 if ( customerInformation.lastName.value == "" ) {
  alert( "Please Enter Your Billing Last Name" );
  customerInformation.lastName.focus();
  return false;
 } 
 if ( customerInformation.address1.value == "" ) {
  alert( "Please Enter Your Billing Street Address" );
  customerInformation.address1.focus();
  return false;
 }  
 if ( customerInformation.city.value == "" ) {
  alert( "Please Enter Your Billing City" );
  customerInformation.city.focus();
  return false;
 }  
 if ( customerInformation.state.value == "" ) {
  alert( "Please Enter Your Billing State" );
  customerInformation.state.focus();
  return false;
 } 
 if ( customerInformation.zipCode.value == "" ) {
  alert( "Please Enter Your Billing Zip Code" );
  customerInformation.zipCode.focus();
  return false;
 }  
 if ( customerInformation.zipCode.value != "" ) {
  var _zip_amount = customerInformation.zipCode.value;
  
  if (customerInformation.zipCode.value.length < 5 ) {
   alert( "Please Enter A Valid Billing Zip Code" );
   customerInformation.zipCode.focus();
   return false;  
  } 
  else {
   for (i=0; i<customerInformation.zipCode.value.length; i++) {
    for (x=0; x<zip_lame.length; x++) {
     if (_zip_amount.charAt(i).toLowerCase() == zip_lame[x]) {
      alert( "Please Enter A Valid Billing Zip Code" );
      customerInformation.zipCode.focus();
      return false;
     }
    }
   }
  }
 } 
 if ( customerInformation.country.value == "" ) {
  alert( "Please Enter Your Billing Country" );
  customerInformation.country.focus();
  return false;
 }  
 if ( customerInformation.email.value == "" ) {
  alert( "Please Enter Your E-Mail Address" );
  customerInformation.email.focus();
  return false;
 } 
 var same = -1;
 for ( x=0; x<customerInformation.shippingSame.length; x++ ) {
  if ( customerInformation.shippingSame[x].checked ) {
   same = x;
  }
 } 
 if( same == 1) {
  if ( customerInformation.shipping_firstName.value == "" ) {
   alert( "Please Enter Your Shipping First Name" );
   customerInformation.shipping_firstName.focus();
   return false;
  }
  if ( customerInformation.shipping_lastName.value == "" ) {
   alert( "Please Enter Your Shipping Last Name" );
   customerInformation.shipping_lastName.focus();
   return false;
  } 
  if ( customerInformation.shipping_address1.value == "" ) {
   alert( "Please Enter Your Shipping Street Address" );
   customerInformation.shipping_address1.focus();
   return false;
  }  
  if ( customerInformation.shipping_city.value == "" ) {
   alert( "Please Enter Your Shipping City" );
   customerInformation.shipping_city.focus();
   return false;
  }  
  if ( customerInformation.shipping_state.value == "" ) {
   alert( "Please Enter Your Shipping State" );
   customerInformation.shipping_state.focus();
   return false;
  } 
  if ( customerInformation.shipping_zipCode.value != "" ) {
   var zip_amount = customerInformation.shipping_zipCode.value;
   if (customerInformation.shipping_zipCode.value.length < 5 ) {
    alert( "Please Enter A Valid Shipping Zip Code" );
    customerInformation.shipping_zipCode.focus();
    return false;  
   }    
   for (i=0; i<customerInformation.shipping_zipCode.value.length; i++) {
    for (x=0; x<zip_lame.length; x++) {
     if (zip_amount.charAt(i).toLowerCase() == zip_lame[x]) {
      alert( "Please Enter A Valid Shipping Zip Code" );
      customerInformation.shipping_zipCode.focus();
      return false;
     }
    }
   }
  }  
  if ( customerInformation.shipping_country.value == "" ) {
   alert( "Please Enter Your Shipping Country" );
   customerInformation.shipping_country.focus();
   return false;
  }  
 } 
}

function checkCreditCard (placeOrder) {
  var ccErrorNo = 0;
  var ccErrors = new Array ()
   ccErrors [0] = "Unknown card type";
   ccErrors [1] = "No card number provided";
   ccErrors [2] = "Credit card number is in invalid format";
   ccErrors [3] = "Credit card number is invalid";
   ccErrors [4] = "Credit card number has an inappropriate number of digits";
  var cardname = placeOrder.payment_method.value;
  var cardnumber = placeOrder.cc_number.value;
  var card_id = placeOrder.cc_cin.value;   
  
  // Array to hold the permitted card characteristics
  var cards = new Array();
  
  //  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: "V", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "M", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "A", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (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) {
     ccErrorNo = 0;
     alert( "Please Enter A Valid Card Type" );
     placeOrder.payment_method.focus();
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     alert( "Please Enter A Valid Card Number" );
     placeOrder.cc_number.focus();
     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))  {
     ccErrorNo = 2;
     alert( "Please Enter A Valid Card Number" );
     placeOrder.cc_number.focus();
     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
    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)  {
     ccErrorNo = 3;
     alert( "Please Enter A Valid Card Number" );
     placeOrder.cc_number.focus();
     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) {
     ccErrorNo = 3;
     alert( "Please Enter A Valid Card Number" );
     placeOrder.cc_number.focus();
     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) {
     ccErrorNo = 4;
     alert( "Please Enter A Valid Card Number" );
     placeOrder.cc_number.focus();
     return false;
  };   
  
  // The credit card is in the required format.
  return true;
}


function popWindow( cable ) {
 var imageUrl = ("/cables/" + cable + ".htm"); 
 cableWindow=window.open( imageUrl,"cableWin", "height=325,width=400,toolbar=no,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,LEFT=0,TOP=0")
}

function openWindow( csc ) {
   win=window.open( csc,"CSC", "height=460,width=480,toolbar=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,LEFT=0,TOP=0")
}