function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}
function createCookie(name,value,days) {
//alert(name +':'+ value)
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else {
    var expires = "";
  }
  document.cookie = name+"="+value+expires+"; path=/";
}

// this creates an order cookie that will only last 60 seconds.
// it's used to control the submit order button
function createOrderCookie(name,value) {
//alert(name +':'+ value)
  var date = new Date();
  date.setTime(date.getTime() + 60);
  var expires = "; expires="+date.toGMTString();
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function loadACCode() {
//alert('load AC code')
  var loc = window.location;
  var ac = getQueryVariable("ac");
  if (ac) {
    createCookie("acCode", ac, 7);  //acCode for 7 days
  }
}

function loadSCCode() {
  var loc = window.location;
  var sc= getQueryVariable("sc");
  if (sc) {
    createCookie("scCode", sc, 7);  //scCode for 7 days
  }
}

function loadCouponCode() {
  var loc = window.location;
  var coupon= getQueryVariable("coupon");
  if (coupon) {
    createCookie("AEODCoupon", coupon, 7);  //Coupon Code for 7 days
  }
}

function doSubmit(frm,todo,value) {
  todo.value=value;
}
