//////////////////////////////////////////////////////////////////////////////////////////////
var OtherString = "******";
var OrderOther = false;
var OrderRenew = false;

document.onkeydown = checkKeys;
//window.onkeydown = checkKeys;

//////////////////////////////////////////////////////////////////////////////////////////////
function checkKeys (evt) {
  var keyCode = document.layers ? evt.which : document.all ? event.keyCode : document.getElementById ? evt.keyCode : 0;
  
  if (keyCode < 65 || keyCode > 90 ) { thisChar = "*" }

  OtherString = OtherString.substring(1) + String.fromCharCode(keyCode);

  if (OtherString == "DRAGON") {
    //OrderOther = confirm("Order 'Other' Laserdisc Games?\nThis is a 4 game set for $" + laser_other_cost + " that includes:\n\nDragon's Lair\nDragon's Lair II\nSpace Ace\nThayer's Quest");
    document.frmRefresh.misc.value = "dragon";
    document.frmRefresh.submit();
  }

  return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
function flip( box ) {
	box.checked = !box.checked
}
//////////////////////////////////////////////////////////////////////////////////////////////
function alloff() {
	if (document.frmInfo.laser_full.checked) {
		for (i = 0; i < 12; i++) {
			document.getElementById('d' + i).checked = false;
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
// trims out leading and trailing spaces as well as trailing commas
function trim(s) {
	iBegin = 0;
	iEnd = s.length;
	
	while (s.substring(iBegin,iBegin+1) == ' ') iBegin++;
	while (s.substring(iEnd-1, iEnd) == ' ' || s.substring(iEnd-1, iEnd) == ',') iEnd--;
	return s.substring(iBegin, iEnd)
}
//////////////////////////////////////////////////////////////////////////////////////////////
function makepayment() {
	var dgames = [ "Cobr","Clif","BadL","Astr","Bega","Intr","Mach","EshA","Glxy","Goal","SupD","UsTm","GpWo","RdBl","Fire" ];
	
	var sets = "";
	var dsets = "";
	var msets="";
	
	var tot = 0;
	var num = 0;
	var dtot = 0;
	var mtot = 0;
	var dc = 0;
	var mc = 0;
	
	if (document.frmInfo.mame_full.checked         ) { mc++; mtot += mame_full_cost;         msets += mame_full_desc         + "_" + mameversion + " "; };
	if (document.frmInfo.mame_roms.checked         ) { mc++; mtot += mame_roms_cost;         msets += mame_roms_desc         + "_" + mameversion + " "; };
	if (document.frmInfo.mame_chds.checked         ) { mc++; mtot += mame_chds_cost;         msets += mame_chds_desc         + " "; };
	if (document.frmInfo.mame_chds_remixes.checked ) { mc++; mtot += mame_chds_remixes_cost; msets += mame_chds_remixes_desc + " "; };
//	if (document.frmInfo.mame_chds_extras.checked  ) { mc++; mtot += mame_chds_extras_cost;  msets += mame_chds_extras_desc  + " "; };
	if (document.frmInfo.mame_full_sub.checked     ) { mc++; mtot += mame_full_sub_cost;     msets += mame_full_sub_desc     + "_" + mameversion + " "; };
	if (document.frmInfo.mame_roms_sub.checked     ) { mc++; mtot += mame_roms_sub_cost;     msets += mame_roms_sub_desc     + "_" + mameversion + " "; };
	if (document.frmInfo.mame_sub.checked          ) { mc++; mtot += mame_sub_cost;          msets += mame_sub_desc          + " "; };
	if (document.frmInfo.mame_movies.checked       ) { mc++; mtot += mame_movies_cost;       msets += mame_movies_desc       + " "; };
	if (document.frmInfo.mame_genres.checked       ) { mc++; mtot += mame_genres_cost;       msets += mame_genres_desc       + " "; };
	if (document.frmInfo.mame_xbox.checked         ) { mc++; mtot += mame_xbox_cost;         msets += mame_xbox_desc         + " "; };
	if (document.frmInfo.mame_iphone.checked       ) { mc++; mtot += mame_iphone_cost;       msets += mame_iphone_desc       + " "; };
	if (document.frmInfo.laser_full.checked        ) { mc++; mtot += laser_full_cost;        msets += laser_full_desc        + " "; };
	if (OrderOther                                 ) { mc++; mtot += laser_other_cost;       msets += laser_other_desc       + " "; };
	
	for (i = 0; i < num_laser_games; i++) {
		if (document.getElementById("d" + i).checked) {
			dsets += dgames[i] + ",";
			dc++;
		}
	}
	
	if (dc > 0) {
		mc++;
		dsets = "Laser:" + dsets;
		dtot = dc * laser_cost_per_game;
	}
	
	sets = trim(trim(msets) + " " + trim(dsets));

	tot += dtot + mtot;
	
	if (mc == 0) {
		alert("Please Choose the Sets you would like to order");
		document.frmInfo.mame_full.focus();
		return false;
	}
	
	if (!document.frmInfo.agree.checked) {
		alert("You must agree to the terms to continue");
		document.frmInfo.agree.focus()
		return false;
	}
	
	document.frmPayment.item_name.value = sets;
	document.frmPayment.amount.value = tot;
	
	// dont add shipping to just subscriptions or renewals
	if ((mc > 1) || (mc == 1 && !document.frmInfo.mame_sub.checked)) {
		document.frmPayment.shipping.value = shipping_local;
	}
	
	document.frmPayment.custom.value = OtherString;
	document.frmPayment.submit();
}
