//Set subscription Prices Here
var CrypticAustralia = 26.00;
var CrypticAsiaPacific = 33.00;
var CrypticRestOfWorld = 39;
var CodebreakAustralia = 20;
var CodebreakAsiaPacific = 27;
var CodebreakRestOfWorld = 33;

function openWindow(pageToOpen,winW,winH){
newWindow =window.open(pageToOpen,"","width=" + winW + ",height=" + winH + ",scrollbars=0")
}

function FindIt(form){
document.location = form.FastFind.options[form.FastFind.selectedIndex].value;
}

function setPrice(form){
var i=getSelectedButton(form.Location)
if(form.Cryptic.checked && form.Codebreak.checked){
     if (i == 0) document.forms[0].Price.value = formatNum(CrypticAustralia + CodebreakAustralia,2);
     if (i == 1) document.forms[0].Price.value = formatNum(CrypticAsiaPacific + CodebreakAsiaPacific,2);
     if (i == 2) document.forms[0].Price.value = formatNum(CrypticRestOfWorld + CodebreakRestOfWorld,2);
  }else if(form.Cryptic.checked){
     	if (i == 0) document.forms[0].Price.value = formatNum(CrypticAustralia,2);
     	if (i == 1) document.forms[0].Price.value = formatNum(CrypticAsiaPacific,2);
     	if (i == 2) document.forms[0].Price.value = formatNum(CrypticRestOfWorld,2);
  }else if(form.Codebreak.checked){
     	    if (i == 0) document.forms[0].Price.value = formatNum(CodebreakAustralia,2);
            if (i == 1) document.forms[0].Price.value = formatNum(CodebreakAsiaPacific,2);
            if (i == 2) document.forms[0].Price.value = formatNum(CodebreakRestOfWorld,2);
  }else{
     alert("Please Select Subscription Type");
  }
}

function getSelectedButton(Location){
   for (var i=0;i<Location.length; i++){
	if(Location[i].checked){
		return i;
	}
   }
}


function validateSubscription(theForm){

   var j=0;
   for (var k=0;k<theForm.Location.length; k++){
	if(theForm.Location[k].checked) j++;
	}
if (j==0){
alert("please select your Mailing Area");
theForm.Location[0].focus();
return (false);
}


  if (theForm.order_firstname.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.order_firstname.focus();
    return (false);
  }

  if (theForm.order_lasttname.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.order_lasttname.focus();
    return (false);
  }

  if (theForm.order_email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    theForm.order_email.focus();
    return (false);
  }

  if (theForm.order_address.value == "")
  {
    alert("Please enter a value for the \"Delivery Address\" field.");
    theForm.order_address.focus();
    return (false);
  }

  if (theForm.order_city.value == "")
  {
    alert("Please enter a value for the \"Town\" field.");
    theForm.order_city.focus();
    return (false);
  }

  if (theForm.order_postcode.value == "")
  {
    alert("Please enter a value for the \"Postcode\" field.");
    theForm.order_postcode.focus();
    return (false);
  }


  if (theForm.order_state.selectedIndex == 0)
  {
    alert("Please choose your State from the drop-down menu.");
    theForm.order_state.focus();
    return (false);
  }

  if (theForm.order_country.value == "")
  {
    alert("Please enter a value for the \"Country\" field.");
    theForm.order_country.focus();
    return (false);
  }

  if (theForm.order_card_type.selectedIndex == 0)
  {
    alert("Please select one of the \"Credit Card Type\" options.");
    theForm.order_card_type.focus();
    return (false);
  }


  if (theForm.order_card_number.value == "")
  {
    alert("Please enter your Credit Card Number.");
    theForm.order_card_number.focus();
    return (false);
  }

  if (theForm.order_card_exp_month.value == "")
  {
    alert("Please enter a value for the \"Expiry month\" field.");
    theForm.order_card_exp_month.focus();
    return (false);
  }

  if (theForm.order_card_exp_year.value == "")
  {
    alert("Please enter a value for the \"Expiry year\" field.");
    theForm.order_card_exp_year.focus();
    return (false);
  }

  if (theForm.order_card_name.value == "")
  {
    alert("Please enter your Name as it appears on the Credit Card.");
    theForm.order_card_name.focus();
    return (false);
  }
  return (true);
}

function formatNum(expr,decplaces) {
	var str = (Math.round(parseFloat(expr) * Math.pow(10,decplaces))).toString()
	while (str.length <= decplaces) {
		str = "0" + str
	} 
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length)
}