  var contests = new Array("Ultimate Lindy Hop Showdown", "Choreography Showcase", "Slow Swing and Blues", "Solo Blues", "Solo Jazz", "Jack and Jill", "Endurance", "Dancer Baseball Team");
  var contestsCost = new Array(50, 0, 50, 20, 20, 20, 0, 0);
  var classes = new Array();
  var classesCost = new Array();

  var showClasses = false;
  var showContests = true;
  var showHousing = false;
  var showMerchandise = false;


  var showEvent    = true;

  var price_id     = -1;
  var discount_id  = -1;  
 
function validate() {
  errorstring = '';
  var elements = document.forms[0].elements;
  var required = new Array("fname", "lname", "email", "address1", "city", "state", "country");
  var reqNames = new Array("First Name", "Last Name", "Email", "Address", "City", "State", "Country"); 
	
  for (i=0;i<required.length;i++) {
    if (!elements[required[i]].value) 
      errorstring += "* " + reqNames[i] + " is a required field!<br/>\n";
  }


  //  Contest Validation
if (showContests && (contests.length > 0)) {
  for (i = 0; i < contests.length; i++) {
    var tName = contests[i]+"Partner";
    if (elements[contests[i]].checked & (elements[tName] != null) ) {
        //& (tName in elements) ) {
      if (elements[tName].value == "")
       errorstring += "* " + contests[i] + " requires a partner!<br/>\n"; 
    }
  }
}

  // Class Validation
  var classSelected = false;
if (showClasses && (classes.length > 0)) {
  for (i = 0; i < classes.length; i++) {
    if (elements[classes[i]].checked)
	classSelected = true;
  }
  if (! classSelected) 
    errorstring += "\n* You must select a class!<br/>";
}

  if (!(elements["gender"][0].checked || elements["gender"][1].checked)) {
	errorstring += "\n* You must select a gender!<br/>";
  } 

  return errorstring;
}

function updatePayment() {
  var elements = document.forms[0].elements;

// HIDE GENDER RELATED THINGS HERE, like JNJ  

// HIDE Residency for Follow, 8/3/2008
  if (elements["gender"][1].checked) {
//        elements["Residency Classes"].disabled = true;
//        elements["Residency Classes"].checked  = false;
  } else if (elements["gender"][0].checked) {
//        elements["Residency Classes"].disabled = false;
  }



// DETERMINE COSTS
  var cost = 0;
  var costEvent = 0.00; 
  var discount = 0;

function lookupCost(cost) {
if (cost == 16) {  price_id = cost; cost = 145; } 
else if (cost == 17) {  price_id = cost; cost = 160; } 
else if (cost == 18) {  price_id = cost; cost = 115; } 
else if (cost == 19) {  price_id = cost; cost = 125; } 
else if (cost == 20) {  price_id = cost; cost = 40; } 
else if (cost == 21) {  price_id = cost; cost = 175; } 
else if (cost == 22) {  price_id = cost; cost = 180; } 
else if (cost == 23) {  price_id = cost; cost = 145; } 
else if (cost == 24) {  price_id = cost; cost = 135; } 
else if (cost == 25) {  price_id = cost; cost = 45; } 
else if (cost == 26) {  price_id = cost; cost = 50; } 
else if (cost == 27) {  price_id = cost; cost = 55; } 
if (isNaN(cost)) cost = 0;
return cost; 
}

// Determine costs for group "Event"

cost_Event = parseInt(elements["cost_Event"].value);
if (isNaN(cost_Event)) {
    for (i=0; i<elements["cost_Event"].length; i++) {
      if (elements["cost_Event"][i].checked) {
        cost_Event = parseInt(elements["cost_Event"][i].value);
      }
    }
  } else {
    if (elements["cost_Event"].checked == false)  
      cost_Event = 0;
  }
price_id_Event = cost_Event;
cost_Event = lookupCost(cost_Event);


// Determine costs for group "Workshops"

cost_Workshops = parseInt(elements["cost_Workshops"].value);
if (isNaN(cost_Workshops)) {
    for (i=0; i<elements["cost_Workshops"].length; i++) {
      if (elements["cost_Workshops"][i].checked) {
        cost_Workshops = parseInt(elements["cost_Workshops"][i].value);
      }
    }
  } else {
    if (elements["cost_Workshops"].checked == false)  
      cost_Workshops = 0;
  }
price_id_Workshops = cost_Workshops;
cost_Workshops = lookupCost(cost_Workshops);

 

 
  var today = new Date();

discount_id_cost_Event = -1;
discount_id_cost_Workshops = -1;
discount_id_costEvent = -1;

// cost_Event Discounts
if ((elements["discount"].value == "ulhs2009REPThurs") &&  true  && (price_id_Event != 0) ) {
  cost_Event = 145; discount_id_cost_Event = 9;

} if ((elements["discount"].value == "ulhs2009REPFri") &&  true  && (price_id_Event != 0) ) {
  cost_Event = 115; discount_id_cost_Event = 10;

} if ((elements["discount"].value == "ulhs2009REPthurs") &&  true  && (price_id_Event != 0) ) {
  cost_Event = 145; discount_id_cost_Event = 14;

} if ((elements["discount"].value == "ulhs2009REPfri") &&  true  && (price_id_Event != 0) ) {
  cost_Event = 115; discount_id_cost_Event = 15;

} 
// cost_Workshops Discounts
if ((elements["discount"].value == "ulhs2009REPThurs") &&  true  && (price_id_Workshops != 0) ) {
  cost_Workshops = 40; discount_id_cost_Workshops = 11;

} if ((elements["discount"].value == "ulhs2009REPFri") &&  true  && (price_id_Workshops != 0) ) {
  cost_Workshops = 40; discount_id_cost_Workshops = 12;

} if ((elements["discount"].value == "ulhs2009REPthurs") &&  true  && (price_id_Workshops != 0) ) {
  cost_Workshops = 40; discount_id_cost_Workshops = 16;

} if ((elements["discount"].value == "ulhs2009REPfri") &&  true  && (price_id_Workshops != 0) ) {
  cost_Workshops = 40; discount_id_cost_Workshops = 17;

} if ((elements["discount"].value == "LocalNOdiscount") &&  true  && (price_id_Workshops != 0) ) {
  cost_Workshops = 40; discount_id_cost_Workshops = 26;

} 

costEvent = cost_Event + cost_Workshops;


// costEvent Discounts
if ((elements["discount"].value == "LocalNOdiscount") &&  (price_id == 21)  && true ) {
  costEvent = 145; discount_id_costEvent = 22;

} if ((elements["discount"].value == "LocalNOdiscount") &&  (price_id == 24)  && true ) {
  costEvent = 115; discount_id_costEvent = 23;

} if ((elements["discount"].value == "LocalNOdiscount") &&  (price_id == 22)  && true ) {
  costEvent = 145; discount_id_costEvent = 24;

} if ((elements["discount"].value == "LocalNOdiscount") &&  (price_id == 23)  && true ) {
  costEvent = 115; discount_id_costEvent = 25;

}   
  var contestCost = 0;
  var classCost   = 0;

// HOUSING REQUEST CHECK
  var housingReq;

  if (elements["Housing"].checked) 
    housingReq = "Requested";
  else 
    housingReq = "Not&nbsp;Requested";

// Contest Costs
//  var contestsCost = new Array(10, 20, 30);
  for (i = 0; i < contests.length; i++) {
    if (elements[contests[i]].checked) 
      contestCost += contestsCost[i];
  }

// Class Costs
/*
  var classes = new Array("Workshop - Full Price", "Workshop - Student Price", "Residency Classes");
  var classesCost = new Array(50, 45, 75);
*/
  for (i = 0; i < classes.length; i++) {
    if (elements[classes[i]].checked)
      classCost += classesCost[i];
  }


  var totalCost = classCost + contestCost + costEvent;
 
// SET ACTION OR ERROR STRING

  var errorString = validate();
  var actionString = "process";
 
  if (errorString == '') {
    actionString = "<center>";
    actionString += "<input type=\"hidden\" name=\"LEMS_totalCost\" value=\"" + (new Number(totalCost).toFixed(2)) + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_costEvent\" value=\"" + (new Number(costEvent).toFixed(2)) + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_classCost\" value=\"" + (new Number(classCost).toFixed(2)) + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_contestCost\" value=\"" + (new Number(contestCost).toFixed(2)) + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_price_id\" value=\"" + price_id + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_price_ids[]\" value=\"" + price_id_Event + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_price_ids[]\" value=\"" + price_id_Workshops + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_discount_groups[]\" value=\"cost_Event\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_discount_groups[]\" value=\"cost_Workshops\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_discount_groups[]\" value=\"costEvent\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_discount_ids[]\" value=\"" + discount_id_cost_Event + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_discount_ids[]\" value=\"" + discount_id_cost_Workshops + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_discount_ids[]\" value=\"" + discount_id_costEvent + "\"/>";
    actionString += "<input type=\"hidden\" name=\"LEMS_discount_id\" value=\"" + discount_id + "\"/>";

    actionString += "<input type=\"submit\" name=\"submit\" value=\"Submit and goto payment.\" class=\"LEMS\" />";
    actionString += "</center>";
  } else {
    actionString = errorString;
  }

// Create Payment HTML
 
  var innerHTML = "<table width=\"100%\" cellspacing=\"3\" cellpadding=\"0\" border=\"0\">";
  innerHTML += "<tr><th width=\"40%\">Item</th><th width=\"10%\">Cost</th><td width=\"1%\">&nbsp;</td><th width=\"49%\">Action</th></tr>";
 
  innerHTML += "<tr><td>Admission</td><td align=\"right\">" + (new Number(costEvent).toFixed(2)) + "$ US</td>"; 
  innerHTML += "<td rowspan=\"99\" >&nbsp;</td>";
  innerHTML += "<td rowspan=\"99\" valign=\"top\"><div style=\"margin-left: 2px;\">" + actionString + "</div></td></tr>";

  if (showContests) {
  innerHTML += "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
  innerHTML += "<tr><td>Contests</td><td align=\"right\">" + (new Number(contestCost).toFixed(2)) + "$ US</td></tr>";
  }

  if (showClasses) {
  innerHTML += "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
  innerHTML += "<tr><td>Classes</td><td align=\"right\">" + classCost + "$ US</td></tr>";
  }

  if (showHousing) {
  innerHTML += "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
  innerHTML += "<tr><td>Housing</td><td align=\"right\">" + housingReq + "</td></tr>";
  }

  innerHTML += "<tr><td colspan=\"2\"><hr /></td></tr>";
  innerHTML += "<tr><td>Total</td><td align=\"right\">";
  innerHTML += new Number(totalCost).toFixed(2); 
  innerHTML += "$ US</td></tr>";
  innerHTML += "<tr><td colspan=\"2\">&nbsp;</td></tr>";
  innerHTML += "<tr><td colspan=\"2\">** Not looking right? Go back and edit!<br/><i>(Reported issues with Safari have been remedied.)</i></td></tr>";
  innerHTML += "</table>";
   
  document.getElementById('LEMS_regPaymentContent').innerHTML = innerHTML;

  return true;
}
 
