var formversion="091008";//YYMMDD

var IsChristmas=false;

var bookdata=[
 ["Lottery Master Guide",24.50],
 ["Lotto How to Wheel a Fortune",22.50],
 ["Lotto Wheel 5 to Win",19.95],
 ["Lotto Winning Wheels for Powerball & Mega Millions",14.95]
];

//format=name/price/64-bit compliant
var softwaredata=[
 ["Advantage Plus",79.95,0],
 ["Wheel Six Plus",59.50,0],
 ["Wheel Five Plus",57.50,0],
 ["Wheel Four Plus",58.50,0],
 ["Full Wheel Generator",34.50,1],
 ["Keno Wheel",59.95,0],
 ["Placeholder-Manual",0,1],
 ["Placeholder-Flash Drive Special",0,1],
 ["Filtering Full Wheel Generator",49.50,1]
];
var upgradedata=[
 ["Advantage Plus",0,26.00,26.00,15.00],
 ["Computer Wheel or Wheel Six Plus",0,24.00,24.00,10.00],
 ["Computer Wheel 5 or Wheel Five Plus",0,24.00,24.00,10.00],
 ["Wheel Four Plus",0,10.00],
 ["Full Wheel Generator",0,10.00,10.00],
 ["Keno Wheel",0,41.97,20.00,10.00],
 ["Manual Replacement",0,5.00,5.00,5.00,5.00,5.00,5.00],
 ["Flash Drive Current Version Special",10.00],
 ["Filtering Full Wheel Generator",0,25.00,15.00]
];

var countries=new Array(
 "Select Country",
 "United States",
 "Alderney",
 "Aruba",
 "Australia",
 "Austria",
 "Bahamas",
 "Barbados",
 "Belgium",
 "Brazil",
 "Canada",
 "Chile",
 "China",
 "Columbia",
 "Costa Rica",
 "Czech Republic",
 "Denmark",
 "Dominican Republic",
 "England",
 "Finland",
 "France",
 "Germany",
 "Greece",
 "Guernsey",
 "Guyana",
 "Hong Kong",
 "Hungary",
 "Iceland",
 "India",
 "Ireland",
 "Isle of Man",
 "Israel",
 "Italy",
 "Jamaica",
 "Japan",
 "Jersey",
 "Korea",
 "Latvia",
 "Liechtenstein",
 "Luxembourg",
 "Malaysia",
 "Mexico",
 "Netherlands",
 "New Zealand",
 "Northern Ireland",
 "Norway",
 "Philippines",
 "Poland",
 "Portugal",
 "Saint Lucia",
 "Sark",
 "Saudi Arabia",
 "Scotland",
 "Singapore",
 "Slovenia",
 "South Africa",
 "Spain",
 "Sweden",
 "Switzerland",
 "Taiwan",
 "Thailand",
 "Trinidad & Tobago",
 "Turks & Caicos Islands",
 "Vietnam",
 "Wales",
 "Other"
);
var indexusa,indexcanada;//array index of usa/canada
var bookcount=0;//used for..
var softcount=0;//..shipping..
var upgradecount=0;//..calculations
var softwarediscount=0;//discount..
var christmasdiscount=0;//..information
var non64progs_last=Array();
for(var i=0;i<countries.length;i++) {
 if(countries[i]=="Canada") { indexcanada=i; }
 if(countries[i]=="United States") { indexusa=i; }
}

//-------------------------------------
function dge(pid) {//return element with id of pid
 return document.getElementById(pid);
}
//-------------------------------------
function fixsets() {//fix various things before calculating totals
 //add keno history to advantage plus if keno wheel is bought
 if(dge("csoft1").checked && dge("csoft6").checked) {
  dge("csoft1c").checked=true;
 }
 //if selected download only, click download checkbox
 if( dge("delivery3").checked ) {
  dge("cdownload").checked=true;
 }
}
//-------------------------------------
function clicksoft() {//if upgrade of type of software is selected, this will deselect the upgrade
 for(var i=1;i<50;i++) {
  var oSoft=dge("csoft"+i),oUpd=dge("cupdate"+i);
  if(oSoft!=null && oUpd!=null && dge("vupdate"+i)!=null) {
   if(oSoft.checked && oUpd.checked && (dge("vupdate"+i).selectedIndex>0)) { oUpd.checked=false; }
  }
 }
 calcAll();
}
//-------------------------------------
function clickupgrade() {//if software of type being upgraded is selected, this will deselect the software
 for(var i=1;i<50;i++) {
  var oSoft=dge("csoft"+i),oUpd=dge("cupdate"+i);
  if(oSoft!=null && oUpd!=null && dge("vupdate"+i)!=null) {
   if(oSoft.checked && oUpd.checked && (dge("vupdate"+i).selectedIndex>0)) { oSoft.checked=false; }
  }
 }
 calcAll();
}
//-------------------------------------
function calcAll() {//calculate all prices
 fixsets();
 var tot_book=calcBookTotal();
 var tot_soft=calcSoftwareTotal();
 var tot_upgr=calcUpgradeTotal();
 var tot_ship=calcShipping();
 var tot_media=calcMedia();

 if(dge("winver_confirm_hold")!=null) {
  if(tot_soft==0 && tot_upgr==0) {
   dge("winver_confirm_hold").innerHTML="";
  } else {
   var non64progs=[];
   for(var i=0;i<softwaredata.length;i++) {
    if(!softwaredata[i][2]) {
     if(dge("csoft"+(i+1))!=null && dge("csoft"+(i+1)).checked) {
      non64progs[non64progs.length]=softwaredata[i][0];
     } else if(dge("cupdate"+(i+1))!=null && dge("cupdate"+(i+1)).checked) {
      non64progs[non64progs.length]=softwaredata[i][0];
     }
    }
   }
   if(non64progs.join()!=non64progs_last.join()) {
    var non64msg="";
    if(non64progs.length>0) { non64msg="<input type='checkbox' id='winver_confirm' />Please confirm that you have a 32 bit version of Windows operating system, as the following software offerings do not work on the 64 bit versions: <b style=\"color:red;\">"+non64progs.join("<span style=\"color:#000\">,</span> ")+"</b>"; }
    dge("winver_confirm_hold").innerHTML=non64msg;
    non64progs_last=non64progs;
   }
  }
 }
 dge("finalbook").value=formatPrice(tot_book);
 dge("finalsoft").value=formatPrice(tot_soft);
 dge("finalupgrade").value=formatPrice(tot_upgr);
 dge("finalmedia").value=formatPrice(tot_media);
 var chrdisc=0;
 if(IsChristmas) {
  chrdisc=Math.round((tot_book+tot_soft)*15)/100;
  christmasdiscount=chrdisc;//set global discount
  dge("christmas").value=formatPrice(chrdisc);
 }
 dge("finalall").value=formatPrice(tot_book+tot_soft+tot_upgr+tot_ship+tot_media-chrdisc);
}
//-------------------------------------
function calcBookTotal() {//calculate total book cost(and return it)
 bookcount=0;
 var quan=new Array(bookdata.length);
 for(var i=0;i<quan.length;i++) {
  if(dge("qbook"+(i+1))!=null) {
   quan[i]=dge("qbook"+(i+1)).selectedIndex;
  } else {
   quan[i]=0;
  }
  bookcount+=quan[i];
 }
 var allbooks=0;
 var info="";
 for(var i=0;i<quan.length;i++) {
  if(dge("pbook"+eval(i+1))!=null) { dge("pbook"+eval(i+1)).value=formatPrice(quan[i]*bookdata[i][1]); }
  allbooks+=quan[i]*bookdata[i][1];
  if(quan[i]>0) info+=formatPrice(quan[i]*bookdata[i][1])+" - "+quan[i]+" "+bookdata[i][0]+" @ "+formatPrice(bookdata[i][1])+"\n";
 }
 dge("booktotal").value=formatPrice(allbooks);
 dge("infobooks").value=info;
 return allbooks;
}
//-------------------------------------
function calcSoftwareTotal() {//calculate total software cost(and return it)
 var allsoft=0;
 var info="";
 softcount=0;
 //advantage plus(special case)
 if(dge("csoft1").checked) {
  softcount++;
    var setCnt=0;
  if(dge("csoft1a").checked) setCnt++;
  if(dge("csoft1b").checked) setCnt++;
  if(dge("csoft1c").checked) setCnt++;
  if(dge("csoft6").checked) setCnt--;//because keno history is free(and forced 'ON')
  if(setCnt<=0) setCnt=1;//force at least one set(for price display purposes)
//This moved to checkAll() to prevent int'l buying usa on accident
//  if(setCnt==0) {//must have a set selected, if not, select usa
//   dge("csoft1a").checked=true;
//   setCnt=1;
//  }
  var thissoft=(setCnt-1)*34.5+79.95;
    var thissoft=79.95;
  info+=formatPrice(thissoft)+" - Advantage Plus ";
  if(dge("csoft1a").checked) info+="+USA History ";
  if(dge("csoft1b").checked) info+="+International History ";
  if(dge("csoft1c").checked) info+="+Keno History";
  info+="\n";
  allsoft+=thissoft;
  dge("psoft1").value=formatPrice(thissoft);
 } else {
  dge("psoft1").value=formatPrice(0);
 }

 //software 1 is a special case, so start with second one
 for(var i=1;i<softwaredata.length;i++) {
  if(dge("csoft"+(i+1))!=null) {
   if(dge("csoft"+(i+1)).checked) {
    softcount++;
    allsoft+=softwaredata[i][1];
    info+=formatPrice(softwaredata[i][1])+" - "+softwaredata[i][0]+"\n";
    dge("psoft"+(i+1)).value=formatPrice(softwaredata[i][1]);
   } else {
    dge("psoft"+(i+1)).value=formatPrice(0);
   }
  }
 }
 var discount=new Array(0,0,20,30,40,55,70,70,70,70,70,70,70,70)[softcount];
 allsoft-=discount;
 dge("softdiscount").value=formatPrice(discount);
 softwarediscount=discount;//set global discount
 dge("softtotal").value=formatPrice(allsoft);
 dge("infosoftware").value=info;
 return allsoft;
}
//-------------------------------------
function calcUpgradeTotal() {//calculate total upgrade cost(and return it)
 var allup=0;
 var thisup=0;
 var thisver=0;
 var info="";
 upgradecount=0;

 for(var i=0;i<upgradedata.length;i++) {
  if(dge("cupdate"+eval(i+1))!=null) {
   if(dge("cupdate"+eval(i+1)).checked) {
    thisver=dge("vupdate"+eval(i+1)).selectedIndex;
    thisup=upgradedata[i][thisver+1];
    allup+=thisup;
    dge("pupdate"+eval(i+1)).value=formatPrice(thisup);
    if(thisup>0) {
     info+=formatPrice(thisup)+" - "+upgradedata[i][0]+" upgrade("+dge("supdate"+eval(i+1)).value+")\n";
     upgradecount++;
    }
   } else {
    dge("pupdate"+eval(i+1)).value=formatPrice(0);
   }
  }
 }
 if(dge("cupdate7")!=null) {
  if(dge("cupdate7").checked) {//manual replacement(place program in serial slot)
   var tmp=dge("vupdate7").options[dge("vupdate7").selectedIndex].text;
   tmp=tmp.substring(0,tmp.length-5);
   dge("supdate7").value=tmp;
  } else {
   dge("supdate7").value="";
  }
 }
 dge("infoupgrades").value=info;
 return allup;
}
//-------------------------------------
function calcShipping() {//calculate total shipping cost(and return it)
 var ret=0;
 var perbook=0;
 var firstbook=0;
 var firstsoft=0;
 var manualcost=0;
 var manualcount=0; //((dge("cupdate7").checked)&&(dge("vupdate7").selectedIndex>0))?1:0;
 var thiscountry=dge("percountry").selectedIndex;
 if(thiscountry==indexusa) {//usa selected
  firstbook=5; perbook=2.5; firstsoft=3; manualcost=1;
  dge("shiptype").value=1;
 } else if(thiscountry==indexcanada) {//canada selected
  firstbook=9; perbook=4.5; firstsoft=8; manualcost=3;
  dge("shiptype").value=2;
 } else if(thiscountry==dge("percountry").options.length-1) {//"other" selected
  firstbook=11; perbook=5.5; firstsoft=11; manualcost=3;
  dge("shiptype").value=4;
 } else {//a gpm country is selected
  firstbook=11; perbook=5.5; firstsoft=11; manualcost=3;
  dge("shiptype").value=3;
 }

 if( (dge("delivery3").checked) && (bookcount==0) ) {//download only - no shipping if no books
  ret=(manualcount>0)?manualcost:0;
  dge("finalshipping").value=formatPrice(ret);
  return ret;
 }
 if( dge("percountry").selectedIndex==0 ) {//check if no country is selected
  dge("finalshipping").value=formatPrice("?");
  return 0;
 }

 if(bookcount>0) manualcost=0;
 ret=((bookcount)?firstbook:0)+((bookcount)?(bookcount-1)*perbook:0)+((softcount+upgradecount)?((dge("delivery3").checked)?((manualcount)?manualcost:0):((softcount+upgradecount-manualcount)?firstsoft:manualcost)):0);
 dge("finalshipping").value=formatPrice(ret);
 return ret;
}
//-------------------------------------
function calcMedia() {//calculate media cost(and return it)
 var mediacost=0;
 if(dge("delivery4")!=null && dge("delivery4").checked){ //if flash drive selected, add 25 dollars to media cost
  mediacost=25;
 } else if(dge("delivery5")!=null && dge("delivery5").checked){ //if cd and flash drive selected, add 35 dollars to media cost
  mediacost=35; 
 } else {
  mediacost=0;
 }
 dge("finalmedia").value=formatPrice(mediacost);
 return mediacost;
}
//-------------------------------------
function formatPrice(dollars) {//returns formatted version of price passed in
 if(dollars=="?") return "$    ??.??";
 if(dollars==0) return "$     0.00";
 var ret=Math.round(dollars*100)/100;//to fix rounding errors
 ret=ret.toString();
 if(ret.indexOf('.')==-1) {//decimal not found in number
  ret+=".00"
 } else {//decimal found in number
  ret+=("00").substring(ret.length-ret.indexOf('.')-1,2);
 }
 return "$"+("         ").substring(0,9-ret.length)+ret;
}
//-------------------------------------
function initorder() {//initialize all data
 dge("submitall").value="Submit "+((((document.location).toString()).substr(0,5)=="https")?"":"Non-")+"Secure Order";
 //place correct years into credit card year selector
 var curryear=(new Date()).getYear();
 if(curryear<2000) curryear+=1900;
 dge("perccexpmonth").options.length=12;
 dge("perccexpyear").options.length=12;
 for(var i=0;i<12;i++) {
  dge("perccexpmonth").options[i].text=(i+1);
  dge("perccexpyear").options[i].text=curryear+i;
  dge("perccexpyear").options[i].value=curryear+i;
 }
 dge("percountry").options.length=countries.length;
 for(var i=0;i<countries.length;i++) {
  dge("percountry").options[i].text=countries[i];
 }
 var successpage=(document.location).toString();
 dge("success").value=successpage.substring(0,successpage.lastIndexOf("/")+1)+"thanks.htm";
 dge("fver").value=formversion;
 calcAll();
}
//-------------------------------------
function CheckAll() {//called before form is submitted...final checks+confirmation
 if((dge("csoft1").checked)&&(!dge("csoft1a").checked)&&(!dge("csoft1b").checked)&&(!dge("csoft1c").checked)) {
  if(dge("percountry").selectedIndex==indexusa) {
   dge("csoft1a").checked=true;
  } else {
   dge("csoft1b").checked=true;
  }
 }
 calcAll();
 //make sure products are selected
 if ((dge("finalsoft").value==formatPrice(0)) && (dge("finalbook").value==formatPrice(0)) && (dge("finalupgrade").value==formatPrice(0)) ) {
  alert("No products have been selected");
  return false;
 }
 if ((dge("finalsoft").value==formatPrice(0)) && (dge("finalmedia").value!=formatPrice(0)) && (dge("finalupgrade").value==formatPrice(0)) ) {
  dge("delivery2").checked=true;
  return CheckAll();
 }

 var ret="";
 var em="";
 //check personal info validity
 ret=checkPersonalInfo();
 if(ret!="OK") {
  if(ret=="NONAME") em="Please enter your name.";
  if(ret=="NOFULLNAME") em="Please enter your FULL name.";
  if(ret=="NOSHIPADDRESS") em="Please enter the address that the product will be shipped to.";
  if(ret=="NOCITY") em="Please enter your city.";
  if(ret=="NOCOUNTRY") em="Please select your country.";
  if(ret=="NOSTATE") em="Please enter your state.";
  if(ret=="NOPROVINCE") em="Please enter your province.";
  if(ret=="NOZIP") em="Please enter your zip/postal code.";
  if(ret=="NOPHONE") em="Please enter your phone number.";
  if(ret=="NOEMAIL") {
   em="You have not entered your email address. If you do not provide a valid "+//continued
    "email address, you will not recieve an order confirmation.\n\n Do you "+//continued
    "want to continue without listing an email address and no confirmation email?";
   ret=confirm(em);
   if(ret) {
    dge("peremail").value="NO EMAIL CONFIRMATION";
    return CheckAll();
   } else {
    return false;
   }
  }
  if(ret=="INVALIDEMAIL") em="Your email address appears to be invalid.";
  if(ret=="DOWNLOADNOEMAIL") em="You have selected to download software, but have not provided an email address to receive download codes. Please either provide an email address OR uncheck 'download software'";
  if(ret=="NOCREDITCARD") em="Please enter your credit card number.";
  if(ret=="NOCCCARDHOLDER") em="Please enter the cardholder name of your credit card.";
  alert(em);
  return false;
 }
 //check credit card
 ret=checkCreditCard();
 if(ret!="OK") {
  if(ret=="CCNOTYPE") em="Credit card is invalid.";
  if(ret=="CCTOOLONG") em="Credit card number has too many digits.";
  if(ret=="CCTOOSHORT") em="Credit card number has too few digits.";
  if(ret=="CCFAILCHECK") em="Numbers entered are not a valid credit card number.\nPlease re-enter the number.";
  if(ret=="CCEXPIRED") em="Credit card is expired OR expiration date was entered incorrectly.";
  if(ret=="CCSECURITYFAIL") em="Credit card security code not entered correctly.";
  alert(em);
  return false
 }
 //confirm order and build form for submitting
 ret=buildFormData();
 if(ret!="OK") return false;
 for(var i=0;i<4;i++) {
  if(dge("qbook"+(i+1)).selectedIndex>1){
   ret=confirm("Are you sure you want more than one copy of the same book?\n\nPress OK to continue or CANCEL to change book quantity.");
   if(!ret) { return false; }
  }
 }
 //confirm that they have confirmed windows version, if applicable
 if(dge("winver_confirm")!=null) {
  if(!dge("winver_confirm").checked) { alert("Please check box confirming you have 32 bit Windows");return false; }
 }
 return true;
}
//-------------------------------------
function checkCreditCard() {//checks validity of credit card(returns true if valid)
 //card type indentifier/card prefix/number length
 var ccdata=[
  ["AM","34",15],
  ["AM","37",15],
  ["VC","4",16],
  ["MC","5",16],
  ["DC","6011",16]
 ];
 var mycc=dge("perccnum").value
 //clean up number - replace L with 1 and o with 0 and remove anything else that is not a digit
 var newstr="";
 for(var i=0;i<mycc.length;i++) {
  var ci=mycc.charAt(i);
  if( (ci=='l')||(ci=='L') ) ci=1;
  if( (ci=='o')||(ci=='O') ) ci=0;
  if( ("0123456789").indexOf(ci)!=-1 ) newstr+=ci;
 }
 mycc=newstr;
 //determine cc type
 var mytype=-1;
 for(var i=0;i<5;i++) {
  if( mycc.indexOf(ccdata[i][1])==0 ) mytype=i;
 }
 if( mytype==-1 ) return "CCNOTYPE";
 //check length of credit card number
 if( mycc.length!=ccdata[mytype][2] ) {
  return ((mycc.length>ccdata[mytype][2])?"CCTOOLONG":"CCTOOSHORT");
 }
 //make a formatted version of the cc number
 var gap=((mycc.length==15)?6:4);
 var newcc=mycc.substring(0,4)+"-"+mycc.substring(4,4+gap)+"-"+mycc.substring(4+gap,4+gap+gap);
 if( 4+gap+gap<mycc.length ) newcc+="-"+mycc.substring(4+gap+gap,mycc.length);
 //set in new cc number and type in main form
 dge("retccType").value=ccdata[mytype][0];
 dge("retccNum").value=newcc;
 dge("retccSec").value=dge("perccsec").value;
 //check card validity
 var flag=false;
 var csum=0;
 for(var i=mycc.length-1;i>=0;i--) {
  var d=parseInt(mycc.charAt(i));
  if( flag ) {
   d*=2;
   if( d>9 ) d-=9;
  }
  csum+=d;
  flag=!flag;
 }
 if( (csum%10)!=0 ) return "CCFAILCHECK";
 if( (dge("perccsec").value.length>4)||(dge("perccsec").value.length<3) ) return "CCSECURITYFAIL";
 var curryear=(new Date()).getYear();
 if(curryear<2000) curryear+=1900;
 var currmonth=(new Date()).getMonth();
 if(curryear==dge("perccexpyear").value) {
  if(currmonth>dge("perccexpmonth").selectedIndex) return "CCEXPIRED";
 }
 return "OK";
}
//-------------------------------------
function checkPersonalInfo() {//makes sure all needed info is set
 if( dge("pername").value.length==0 ) return "NONAME";
 if( (dge("pername").value.indexOf(" ")<=0) || (dge("pername").value.indexOf(" ")==dge("pername").value.length-1) ) return "NOFULLNAME";
 if( dge("peraddress").value.length==0 ) return "NOSHIPADDRESS";
 if( dge("percity").value.length==0 ) return "NOCITY";
 if( dge("percountry").selectedIndex==0 ) return "NOCOUNTRY";
 if( dge("percountry").selectedIndex==dge("percountry").options.length-1 ) {
  if( dge("percountry2").value.length==0 ) return "NOCOUNTRY";
 }
 if( (dge("percountry").selectedIndex==indexusa) || (dge("percountry").selectedIndex==indexcanada) ) {
  if( dge("perstate").value.length==0 ) return ((dge("percountry").selectedIndex==indexusa)?"NOSTATE":"NOPROVINCE");
  if( dge("perzip").value.length==0 ) return "NOZIP";
 }
 if( dge("perphone").value.length==0 ) return "NOPHONE";
 var em=dge("peremail").value;
 if( em.length==0 ) return "NOEMAIL";
 if( em!="NO EMAIL CONFIRMATION" ) {
  if( em.indexOf("@")==-1 ) return "INVALIDEMAIL";
  if( em.indexOf(".")==-1 ) return "INVALIDEMAIL";
  if( em.indexOf("@")>em.lastIndexOf(".") ) return "INVALIDEMAIL";
 } else {
  if( (dge("cdownload").checked)&&((calcSoftwareTotal()>0)||(calcUpgradeTotal()>0)) ) return "DOWNLOADNOEMAIL";
 }
 if( dge("perccnum").value.length==0 ) return "NOCREDITCARD";
 if( dge("perccname").value.length==0 ) return "NOCCCARDHOLDER";
 return "OK";
}
//-------------------------------------
function checkCountry() {//check if "other" is selected as country(if so, add extra field)
 if( dge("percountry").options[dge("percountry").selectedIndex].text=="Other" ) {
  dge("percountryext").innerHTML="&nbsp;<input type=\"text\" class=\"jsotext\" size=\"18\" name=\"percountry2\" id=\"percountry2\" />";
 } else {
  dge("percountryext").innerHTML="";
 }
 calcAll();
}
//-------------------------------------
function fixcountry(thecountry) {//removes the part of the country in ()'s
 var start=thecountry.indexOf("(");
 if(start==-1) { return thecountry; }
 return thecountry.substring(0,start);
}
//-------------------------------------
function buildFormData() {//fill in all data in the form to be submitted
 dge("retEmail").value=dge("peremail").value;
 dge("retName").value=dge("pername").value;
 if( dge("percountry").selectedIndex==dge("percountry").options.length-1 ) {
   //other country - use extra box
   dge("retCountry").value=dge("percountry2").value;
  } else {
   dge("retCountry").value=fixcountry(dge("percountry").options[dge("percountry").selectedIndex].text);
  }
 dge("retOrder").value=dge("finalall").value;
 var myprod="";
 myprod+=dge("pername").value+"\n";
 if( dge("percompany").value.length>0 ) myprod+=dge("percompany").value+"\n";
 myprod+=dge("peraddress").value+"\n";
 if( dge("peraddress2").value.length>0 ) myprod+=dge("peraddress2").value+"\n";
 myprod+=dge("percity").value+", "+dge("perstate").value+" "+dge("perzip").value+"\n";
 myprod+=dge("retCountry").value+"\n";
 if( dge("perccbill").value.length>0 ) {
  myprod+="Billing Address:\n"+dge("perccname").value+"\n"+dge("perccbill").value;
 }
 var tmp=dge("retccNum").value;
 for(var i=0;i<tmp.length-4;i++) {
  myprod+=((("0123456789").indexOf(tmp.charAt(i))==-1)?tmp.charAt(i):"x");
 }
 myprod+=tmp.substring(tmp.length-4,tmp.length)+"\n"+//continued
  "Phone Number: "+dge("perphone").value+"\n"+//continued
  "Email Address: "+dge("peremail").value+"\n\n"+//continued
  "---------ORDER DETAILS-------------\n"+//continued
  dge("infobooks").value+dge("infosoftware").value+dge("infoupgrades").value;
 if(dge("softdiscount").value!=formatPrice(0)) {
  myprod+=formatPrice(-softwarediscount)+" <= Multi-Program Software Discount\n";
 }
 if(IsChristmas) {
  myprod+=formatPrice(-christmasdiscount)+" <=15% Christmas discount(books+software)\n"
 }
 myprod+="===============================================\n"+//continued
  formatPrice(calcBookTotal()+calcSoftwareTotal()+calcUpgradeTotal()-christmasdiscount)+" <=Sub-Total\n"+//continued
  dge("finalshipping").value+" <=Shipping & Handling\n";
 myprod+=" ===========\n"+dge("finalall").value+" <=Total\n";
 dge("retProducts").value=myprod;
 //if( !confirm(myprod+"\n\nPlease verify the details of this order. Press OK to proceed.") ) return "NOCONFIRM";
 if(softcount+upgradecount>0) {
  if( dge("delivery2").checked ) {
   dge("retMedia").value="Ship Software on CD"
  } else if( dge("delivery4").checked ) {
   dge("retMedia").value="Ship Software on Flash Drive"
  } else if( dge("delivery5").checked ) {
   dge("retMedia").value="Ship Software on CD and Flash Drive"
  } else {
   dge("retMedia").value="Download Software Only"
  }
 } else {
  dge("retMedia").value="";
 }
 dge("retDownload").value=((dge("retMedia").checked)?"(Email Software Install Codes)":"");
 dge("retccMonth").value=dge("perccexpmonth").options[dge("perccexpmonth").selectedIndex].text;
 dge("retccYear").value=(dge("perccexpyear")).options[dge("perccexpyear").selectedIndex].text;
 dge("retccHolderName").value=dge("perccname").value;
// if( document.cookie.indexOf("adSource=")!=-1 ) {  var i=document.cookie.indexOf("=")+1;  var j=document.cookie.indexOf(";");  if( j==-1) j=document.cookie.length;  dge("retAdSource").value=document.cookie.substring(i,j);  document.cookie="adSource="; }

  if(document.cookie.length>0) {
   var loc=document.cookie.indexOf("adSource=");
   if(loc!=-1) { 
    loc+=9;
    var loc2=document.cookie.indexOf(";",loc)
    if(loc2==-1) { loc2=document.cookie.length; }
    dge("retAdSource").value=unescape(document.cookie.substring(loc,loc2));
    document.cookie="adSource=";
   } 
  }

 dge("retRefer").value=dge("perrefer").value;
 dge("retRemarks").value=dge("percomment").value;
 return "OK";
}


function christmasfield() {
 if( !IsChristmas ) return;
 document.write("<div class=\"jsominor\"><div style=\"position:static;\"><div class=\"jsodel12\">");
 document.write("<span style=\"color:#008080;\" class=\"jsomedium\">Price reflects a 15% discount on books and software</span></div>");
 document.write("<div class=\"jsodel3\"><span class=\"jsomedium\">Christmas Discount:</span>");
 document.write("<input type=\"text\" class=\"jsotext\" size=\"10\" name=\"christmas\" id=\"christmas\" />");
 document.write("</div><div style=\"clear:both;\"></div></div></div>");
}
function christmastext() {
 if(IsChristmas) {
  document.write("<b style='color:#008080;'>Christmas discount ends December 31st, "+(new Date().getYear())+"</b>");
 }
}
function setname() {
 if( dge("perccname").value.length==0 ) {
  dge("perccname").value=dge("pername").value;
 }
 if(dge("pername").value=="test") {
  ///////TEST VALUES
  dge("pername").value="Test Test";
  dge("peraddress").value="123 Test";
  dge("percity").value="Test City";
  dge("perstate").value="Test State";
  dge("perzip").value="12345";
  dge("perphone").value="(555)555-5555";
  dge("peremail").value="NO EMAIL CONFIRMATION";
  dge("perccnum").value="5000000000000009";
  dge("perccexpmonth").selectedIndex=10;
  dge("perccexpyear").selectedIndex=10;
  dge("percountry").selectedIndex=1;
  dge("perccname").value="Test Test";
  dge("qbook1").selectedIndex=2;
  dge("csoft6").checked=true;
  dge("perccsec").value="123";
  dge("cupdate1").checked=true;
  dge("vupdate1").selectedIndex=3;
  dge("supdate1").value="123-456-789";
  calcAll();
 }
}
// function checkYahoo() {
// if(dge("peremail").value.toLowerCase().indexOf("@yahoo.com")!=-1){
//  var ret=confirm("NOTE: Yahoo email addresses have been known to put emails from us into the bulk mail folder instead of the inbox. \n\nPress OK to continue with this address (be sure to check bulk mail) or \n\nPress CANCEL to enter a different email address.");
//  return ret;
// }
//  return true;
// }
function checkSpam() {
 if((dge("peremail").value.toLowerCase().indexOf("@optus.net.au")!=-1)||(dge("peremail").value.toLowerCase().indexOf("@portugalmail.pt")!=-1)||(dge("peremail").value.toLowerCase().indexOf("@rediffmail.com")!=-1)){
  if(confirm("NOTE: The email address you entered has been known to block emails from us. \n\nPress OK to read more about this problem or \n\nPress CANCEL to enter a different email address. You must enter a different email address to continue with your order.")){
   window.open("http://www.smartluck.com/faq/faq210.htm"); 
  }
 }
 return true;
}


function cancelFlash() {
 if(dge("cupdate8").checked){
  if(confirm("By selecting this, you will be removing the flash drive current version special.")) {
   dge("cupdate8").checked=false;
   calcAll();
   return true;
  } else {
   dge("delivery4").checked=true;
   return false;
  }
 }else {
  return true;
 }
}