function getURL(id){
  document.location=id;
}
function make_bookmark(url, name, script){
  try {
    window.external.AddFavorite(url, name)
  } catch(exc) {
    alert("Sorry, your browser doesn't support bookmarks")
  }

  try {
    var img=new Image()
    img.src=url+script
  } catch(exc) { }
}
function select_ship(frm) {
  if(frm.same_adrress.checked) {
    frm.sname.value = frm.fname.value+ ' ' +frm.lname.value;
    frm["shipping-address"].value = frm["billing-address"].value;
    frm["shipping-zip"].value = frm["billing-zip"].value;
    frm["shipping-country_id"].value = frm["billing-country_id"].value;
    frm["shipping-city"].value = frm["billing-city"].value;
    frm["shipping-state_id"].value = frm["billing-state_id"].value;
    return true;
  }
  return false;
}
function isCreditCard(cc,accepted) {
  cc=String(cc);
  if(cc.length<4 || cc.length>30) return false;
  // Start the Mod10 checksum process...
  var checksum=0;
  // Add even digits in even length strings or odd digits in odd length strings.
  for (var location=1-(cc.length%2); location<cc.length; location+=2) {
    var digit=parseInt(cc.substring(location,location+1));
    if(isNaN(digit)) return false;
    checksum+=digit;
  }
  // Analyze odd digits in even length strings 
  // or even digits in odd length strings.
  for (var location=(cc.length%2); location<cc.length; location+=2) {
    var digit=parseInt(cc.substring(location,location+1));
    if(isNaN(digit)) return false;
    if(digit<5) checksum+=digit*2;
    else checksum+=digit*2-9;
  }
  if(checksum%10!=0) return false;
  if(accepted!=null) {
    var t=parseInt(cc.substring(0,4)), l=cc.length;
    var type;
    if(t>=3000 && t<3060 && l==14) type="Diners Club";
    else if(t>=3400 && t<3500 && l==15) type="American Express";
    else if(t>=3528 && t<3590 && l==16) type="JCB";
    else if(t>=3600 && t<3700 && l==14) type="Diners Club";
    else if(t>=3700 && t<3800 && l==15) type="American Express";
    else if(t>=3800 && t<3890 && l==14) type="Diners Club";
  }
  return true
}
function isCCdateExpired(month, year) {
  var expires=new Date(year, month, 1);
  today=new Date();
  var one_day=1000*60*60*24;
  return Math.ceil((today.getTime()-expires.getTime())/(one_day)) >= 1;
}
function checkCCNumber(form, passed) {
  var card_types=new Array();
  card_types["VisaCard"]="Visa";
  card_types["MasterCard"]="MasterCard";
  card_types["AmExCard"]="American Express";
  card_types["DiscoverCard"]="Discover/Novus";
  card_types["Diners"]="Diners Club";
  card_types["JCB"]="JCB";
  card_types["Carte"]="Carte Blanche";
  card_types["BankCard"]="Australian BankCard";
  card_types["Other"]="Other";

  var cc=form.cc_number.value;
  var accepted=null;
  if (form.issuer_name.value.length == 0) {
    alert("Please enter card issuing bank name.");
    form.issuer_name.focus();
    return false;
  }
  if (form.cc_number.value.length == 0) {
    alert("Please enter a card number.");
    form.cc_number.focus();
    return false;
  }
  if (form.exp_month.value.length == 0) {
    alert("Please enter the expiration month.");
    form.exp_month.focus();
    return false;
  }
  if (form.exp_year.value.length == 0) {
    alert("Please enter the expiration year.");
    form.exp_year.focus();
    return false;
  }  
  if (isCCdateExpired((form.exp_month.options[form.exp_month.selectedIndex].value),(form.exp_year.options[form.exp_year.selectedIndex].value))) {
    alert("This credit card has expired!" );
    form.exp_month.focus();
    return false;
  }
  if ( (form.cc_cvv.value.length < 3 || form.cc_cvv.value.length > 3) && passed == 0) {
    alert("Please enter a CVV2 number.");
    form.cc_cvv.focus();
    return false;
  }
  accepted=new Array(card_types[form.cc_type.options[form.cc_type.selectedIndex].value]);
  if (!isCreditCard(cc,accepted)) {
    alert("Credit Card number is invalid! Please correct this");
    form.cc_number.focus();
    return false;
  }
  return true;
}
