<!--

function error_message(error) {
  error_win = Window.open("","Error","height=200,width=300,resize=no");
  error_win.document.write(error);
  error_win.document.close;
}

// rounds number to X decimal places
function variable_round(number,x) {
  return Math.round(number*Math.pow(10,x))/Math.pow(10,x);
}
 
// convert a numeric value to dollars and cents
function format_to_dollars(dollar_amount) {
  // force code to treat this as a number
  dollar_amount = dollar_amount - 0;
  // now round it to specified precision
  dollar_amount = (dollar_amount == Math.floor(dollar_amount)) ? dollar_amount + '.00' : (  (dollar_amount*10 == Math.floor(dollar_amount*10)) ? dollar_amount + '0' : dollar_amount);
  return dollar_amount;
}

function object_is_ok(string_to_validate,min_length,max_length,validation_string,error_string) {

  for (var i = 0; i < string_to_validate.length; i++) {
    if (validation_string.indexOf(string_to_validate.charAt(i)) < 0) {
      // alert(error_string + ' has invalid characters');
      return false;
    }
  }

  // zero for min and max means ignore length
  if (string_to_validate.length < min_length) {
    // alert(error_string+' is too short');
    return false;
  }

  if (string_to_validate.length > max_length) {
    // alert(error_string + ' has too many characters');
    return false;
  }

  return true;
}

function validate_cart (thisForm){
  var errors = "";
  var item_quantity = thisForm.product_quantity.value;
// reset item_quantity to zero if invalid data
  if (object_is_ok(item_quantity,0,4,'0123456789','Quantity') ==  false) {
    item_quantity = '1';
    thisForm.product_quantity.value = 1;
    errors += "Invalid value for quantity.\n";
  }
  if (thisForm.product_quantity.value == "0") {
    errors += "You did not order anything.\n";
  }
  if (errors == "") {
    return true;
  } else {
    alert('The following error(s) occurred:\n'+errors);
	return false;
  }
}

function validate_checkout (thisForm){
  var errors = "";
  if (thisForm.customer_credit_card.value == "") {
    errors += "You did not enter your credit card number.\n";
  }
  if (thisForm.customer_card_expiration.value == "") {
    errors += "You did not enter your credit card expiration date.\n";
  }
  if (thisForm.customer_card_security_code.value == "") {
    errors += "You did not enter your credit card security code.\n";
  }
  if (errors == "") {
    return true;
  } else {
    alert('The following error(s) occurred:\n'+errors);
	return false;
  }
}

//-->
