// tnmt1.js

//  Global javascript Variables - values set in the "content-specific" js, or the parent HTM
    
//-----------------------------------------------------------    
 var organiser="";
 var anydiscounts=0, familydiscount=0, discdescr1="";
 var penalty=0;
 var sparring_descr1="",  sparring_descr2="", entryfee_descr="", goto_url="", power_descr="",
     cost1event= 0, cost2events=0, cost3events=0, cost4events=0, costallevents=0;
 
 var numevents=0, spclBBonly=0, pwrBBonly=0, selectagediv=0;
 var ITFNZ=0,    country="",    organisation="";
 var xx; 
//-----------------------------------------------------------
 
function justDate(dt)
 { y=dt.getFullYear();   m=dt.getMonth();   d=dt.getDate();
   dt2=new Date(y, m, d);
   return dt2;
 }
 

function init()
{// var today=new Date(), discdt=new Date(discount_date);
 // alert("init");
 // discdatediv.innerHTML=discdt.toLocaleDateString() + ", today is " + today.toLocaleDateString();
   }



function blankcheck(entered)
{
 with (entered)
  {
   if (value==null || value=="" || value==0)
     { alert("Please enter " + entered.name); entered.focus(); return false; }
   else { return true; }
  }
}

function hasvalue(entered)
{
 with (entered)
  {
   if (value==null || value=="")
     { return false; }
   else { return true; }
  }
}

function settestvalues(thisform)
{
    
 with (thisform)
   { 
     lastname.value="l";
     firstname.value="f";
     age.value = "t";
     rank.value = "1";
     DateOfBirth.value = "t";
     phone.value = "t";
     email.value = "t";
     street.value = "t";
     town.value = "t";
     weight.value = "70";
     height.value = "140";
     if (countryorg)
       { country.value = "t";
         organisation.value = "t";
       }  
     else 
       { club.value = "t";
         instructor.value = "t";
       }  
   }
}



function xcheckform(thisform, cfm)
{ 
alert("1");
}


function checkform(thisform, cfm)
{ var evts=0, cost=0, disc=0, penal=0, fam_disc=0;
  var disc_dt, penalty_dt, today, diff, y, m, d;
  var tds="", ps="", ps2, ds="", ts2, tpay;
  
 if (thisform.lastname.value=='t') { settestvalues(thisform); }

 with (thisform)
  {
   if (ITFNZ!=undefined) 
       if (ITFNZ.value)
        { country.value="New Zealand"; organisation.value="ITFNZ"; }
   //dbgdiv.innerHTML= "P=" + patterns.checked + " S=" + sparring.checked + " Sc=" + specdiv.checked  + " Sc=" + pwrdiv.checked;
   if (blankcheck(lastname)==false) {return false;};
   if (blankcheck(firstname)==false) {return false;};
   if (blankcheck(age)==false) {return false;};
   //if (age > 17)
   //   { alert("Age must be less than 18"); return false; }
   if (age < 3)
      { alert("check Age"); return false; }


   if (blankcheck(DateOfBirth)==false) {return false;};

    //alert("(" + rank.value + ")");
    //if (rank.value=='-Rank-')
   if (rank.value=='0')
      { alert("select Rank"); return false; }
    //   if (rank.value.length < 3)
    //     if (rank.value<0) rank.value=rank.value + " dan"; else rank.value=rank.value+" gup";
    //   ranktype.innerHTML="D";
   
   if (! mf[0].checked && ! mf[1].checked) 
      { alert("Please select Male or Female"); return false; }
  
   if (blankcheck(phone)==false) {return false;};
   if (blankcheck(email)==false) {return false;};
   if (blankcheck(street)==false) {return false;};
   if (blankcheck(town)==false) {return false;};
   if (blankcheck(weight)==false) {return false;};
   if (blankcheck(height)==false) {return false;};
   if (countryorg)
        { 
           if (blankcheck(country)==false) {return false;};
           if (blankcheck(organisation)==false) {return false;};
        }
   else     
       {
         if (blankcheck(club)==false) {return false;};
         if (blankcheck(instructor)==false) {return false;};
       }  
   if (patterns.checked) { evts++; }
   if (sparring.checked) { evts++; }
   if (thisform.prearranged!=undefined) if (prearranged.checked) { evts++; }
   
   if (thisform.special!=undefined) if (special.checked) { evts++; }       
   if (thisform.power!=undefined) if (power.checked) { evts++; }       

   if (thisform.teampatterns!=undefined) if (teampatterns.checked) { evts++; }
   if (thisform.teamsparring!=undefined) if (teamsparring.checked) { evts++; }
   if (thisform.teampower!=undefined) if (teampower.checked) { evts++; }
   if (thisform.teamspecial!=undefined) if (teamspecial.checked) { evts++; }


   if (thisform.family !=undefined) if (family.checked) { fam_disc=familydiscount; ds=" -$5 family "; }       
   
   if (evts==0)
      { alert("No events ticked"); return false; }
   if (costallevents)
      { cost=costallevents; }   
   else
     {   
       switch (evts)
         {
           case 1: cost=cost1event; break;
           case 2: cost=cost2events; break;
           case 3: cost=cost3events; break;
           case 4: cost=cost4events; break;
         }
     }      
   tpay = cost - fam_disc;
   ts2=evts + " events entered. Cost = $" + cost + ds + ps + "." +
                "<b>Total payable = $" + tpay + "</b> " + tds;
    /*    "<b>Total payable = $" + (cost-disc-disc_for_webentry+penal) + "</b> " + tds; */
   totalsdiv.innerHTML=ts2; 
   thisform.totals.value=ts2; 
   
   numevents=evts;
   //discount.value = disc;
   //total.value=cost-disc;  
   //numevents.value=evts;
   if (cfm) 
     alert ("Total Payable $" + tpay + ".    Read the rest of the notes and click SendEntry");

  }
  
}  



function checkform2(thisform)
{
    
  if (numevents==0)
   { alert("Use the 'Check Form' button before sending"); return false; } ;
  if (blankcheck(thisform.DisclaimerName)==false) {return false;};
  checkform(thisform, 0);
 
}

function str_event_costs()
{
  var ts="<b>Entry Fee: ";

//  alert("X:" + costallevents);
  if (costallevents) ts = ts + "All events $" + costallevents;    

  if (cost1event) ts = ts + "1 event $" + cost1event;    
  if (cost2events) ts = ts + ", 2 events $" + cost2events;    
  if (cost3events) ts = ts + ", 3 events $" + cost3events;    
  if (cost4events) ts = ts + ", 4 events $" + cost4events;    
  ts=ts + "</b>";
  if (discdescr1) ts=ts + "<br>" + discdescr1;
  return ts;
}


