    
// Global variables
	
var NewWin;


// Functions
                                           

function estimate(){
  j=0;    
  

  var strChoice = new Array(5);
  var Quantity = new Array(5);

  if(!document.forms["cost"].training.checked){
    strChoice[j] = "training"
    Quantity[j] = "1"
    j++
  } // end if 
  
  if(document.forms["cost"].children.value != ""){
    strChoice[j] = "children"
    Quantity[j] = document.forms["cost"].children.value
    j++
    
  } // end if
  else{
    alert("Please tell us how many children you intend to homeschool");
    return false;
  } // end else

  
  if(document.forms["cost"].childrenDiagsPrinted.value != "0"){
    strChoice[j] = "NeedDiagsPrinted"
    Quantity[j] = document.forms["cost"].childrenDiagsPrinted.value
    j++
  } // end if
  
  if(document.forms["cost"].childrenDiagsOnline.value != "0"){
    strChoice[j] = "NeedDiagsOnline"
    Quantity[j] = document.forms["cost"].childrenDiagsOnline.value
    j++
  } // end if

  if((document.forms["cost"].childrenDiagsOnline.value == "0") && 
  (document.forms["cost"].childrenDiagsPrinted.value == "0")){
    strChoice[j] = "NoNeedDiags"
    Quantity[j] = 0
    j++
  } // end if
    
 // checks to see if the cookie already has something in it and if so empties it
  if( document.cookie != ''){
  aStr = unescape(document.cookie);
  
  document.cookie = "";
  }
  for(i=0; i<4; i++){
      addProduct(strChoice[i],Quantity[i]);
  } // end for
  showBasket();
} // end function

function showBasket(){
   this.location.href='basket.html';
}// showBasket

                                         
function changeProduct(pID,pQuantity)
{  
var i;
 

 // split the cookies up and rebuild with new value for the cookie

 strCookies = unescape(document.cookie);                                                              

    cookies = strCookie.split('"');  

    // get rid of the first "
    //cookies[0]=cookies[0].substr(1,cookies[0].length);
  
    for(var i = 0 ; i < cookies.length; i++){
            
 document.cookie = '';
 }

 for(i = 0 ; i < cookies.length; i++){
 
// the cookie split that conquers the extra cookie problem                                              
      aCookie  = cookies[i];//.split(';'); 
      //aCookie  = cookies[i].split(';');       

      
       Something= aCookie.split(';')
      //document.write(aCookie[0]+'<br>'); 
      
       nameValue = Something[0].split('=');


   if( nameValue[0] != pID){
    addProduct(nameValue[0],nameValue[1]); 
   }  
   else {
   
   // -----------------------------------------------------
       
    addProduct(nameValue[0],pQuantity);
   }     
 }

}// change


function addProduct(pID,pQuantity)
{                 
  expireDate = new Date;
  expireDate.setMonth(expireDate.getMonth()+6);  
  
  if( document.cookie != '') 
   aStr = unescape(document.cookie) + ';"' +pID + '=' +pQuantity + ';expires=' + expireDate.toGMTString() + ';path=\"';
  else
    aStr = '"' +pID + '=' +pQuantity + ';expires=' + expireDate.toGMTString() + ';path=\"'; 

   
  document.cookie = escape(aStr);
}  


var childrenDiagsPrinted;
var childrenDiagsOnline;
function displayBasket(){                              
  
  var Something;
  var govAllow;
  var fees;
  var costChild;
  var children;
  var training
  var diagnostic;
  var NeedDiags;  
  numNeedDiagsPrinted = 0;
  numNeedDiagsOnline = 0;  
  count = 0;
  initial = 0;
  firstYear=0;
  otherYear=0;
  PACEs = 0;
  numchildren=0;

          // get date in nice format
        function makeArray() {
          for (i = 0; i<makeArray.arguments.length; i++)
          this[i + 1] = makeArray.arguments[i];
        }

    var months = new makeArray('January','February','March',
    'April','May','June','July','August','September',
    'October','November','December');

    var date = new Date();
    var month = date.getMonth() + 1;
    var yy = date.getYear() + 1;
    var year = (yy < 1000) ? yy + 1900 : yy;
    
    feesDate = months[month] + ", " + year;
        
    // end of getting date
  
  document.write('<FORM name="display">' );   
  document.write(' <table width=90% cellpadding="7" cellspacing="2" border="1" bordercolor="#003399" bgcolor="#99CCFF">');
  document.write(' <TR class="title">');                                                                                                                                                                           
  document.write('  <TH>  Description </TH> <TH> Estimated Cost </TH> <TH width="60" colspan="2">Regularity</TH>');
  document.write(' </TR>');
  
  strCookie = unescape(document.cookie);

  if( strCookie != '' )
  {                     
    cookies = strCookie.split('"');  

    // get rid of the first "
    //cookies[0]=cookies[0].substr(1,cookies[0].length);
  
    for(var i = 0 ; i < cookies.length; i++){
      
// the cookie split that conquers the extra cookie problem                                              
      aCookie  = cookies[i];//.split(';'); 
      //aCookie  = cookies[i].split(';');       

      
       Something= aCookie.split(';')
      //document.write(aCookie[0]+'<br>'); 
      
       nameValue = Something[0].split('=');
       
    
      
/* ---------------------------------------------------------------------
    do an if statement to see what values are in the cookie and document.write out a line for each name value pair that should be there don't even bother about the findProduct function 
----------------------------------------------------------------------- */

    
     // figure out the amount for printed diags by how many children need printed diags 
      if(nameValue[0] == "NeedDiagsPrinted"){
		 DiagsPrinted="NeedDiagsPrinted";
         if(nameValue[1] > 0){
           NeedDiags = "yes"; 
         }
        numNeedDiagsPrinted=nameValue[1];
        // find out the cost of diagnostic tests
        child = child + numNeedDiagsPrinted * 30;
		childrenDiagsPrinted = numNeedDiagsPrinted;		
      }
     // figure out the amount for online diags by how many children need online diags 
      if(nameValue[0] == "NeedDiagsOnline"){
		 DiagsOnline="NeedDiagsOnline";
         if(nameValue[1] > 0){
           NeedDiags = "yes"; 
         }
        numNeedDiagsOnline=nameValue[1];
        // find out the cost of diagnostic tests
        child = child + numNeedDiagsOnline * 7.50;
		childrenDiagsOnline = numNeedDiagsOnline;		
      }

      if(NeedDiags != "yes"){  
        child = 0;
      }
        
      if(nameValue[0] == "children"){
       // put value children into children
       children = "children"; 
        // put number of children into variable numchildren
        numchildren=nameValue[1];
      } // end if = children 

        
    // tallying up the cost
    initial = initial + child;     

    
     if(nameValue[0] == "training"){
       training = "training";
       initial = initial + 140;
     } // end if training
   
 
     if(nameValue[0] == "children"){
       pairName = "children";
       children == "children"
       // debug PACE price, put proper PACE price!!! ----------------
       PACEs = numchildren * 844;
     } // end if children                  

    }// for  ---------------------------------------- cookies split finish

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()


function yearfee(){
     
        document.write('<TR>');      
        document.write('<TD colspan="4"> &nbsp;</TD>');         
        document.write('</TR>'); 
        
        document.write('<TR>'); 
        document.write('<TD colspan="4" class="subtitle">Once-Off Initial Fees</TD>');
        document.write('</TR>');
        
        document.write("<TD> Family Affiliation Fee</TD>");
      
      // write out different line depending on whether training done  
      if(training=="training"){  
        document.write('<TD>$140</TD>');
        
        firstYear = firstYear+140;
      } // end if  
      else if(training!="training"){
      firstYear = firstYear+60;  
        document.write('<TD>$60</TD>');
      } // end else  
        
        document.write('<TD colspan="2"> Once off</TD>');
        document.write('</TR>');
                 
    } // end function yearfee

    function monthly(){
      
      firstYear=firstYear+320;
      otherYear=otherYear+320;
        document.write('<TR>');      
        document.write('<TD colspan="4"> &nbsp;</TD>');         
        document.write('</TR>'); 
        
        document.write('<TR>');      
        document.write('<TD colspan="4" class="subtitle"> Regular Costs </TD>');        
        document.write('</TR>');  
        document.write('<TR>');      

        document.write('<TD> Annual Fee</TD>');
        document.write('<TD> $320  </TD>');
        document.write('<TD colspan="2"> We will send you an account for $160 every 6 months.</TD>');       
        document.write('</TR>');
         
     } // end function monthly 

 
    function childrenCost(){
     if(children == "children"){
     firstYear=firstYear+PACEs;
     otherYear=otherYear+PACEs;   
         document.write('<TR>');      
        document.write("<TD>PACEs & Keys</TD>");
        document.write('<TD> $'+ PACEs +'</TD>');
        document.write('<TD> Per Year</TD>');             
                    
          document.write('<TD>Number of children <input type="text" name="children"  value="'+ numchildren +'" size="4" > <input type="button" name="change" value="Change" onclick="changeProduct(pairName,document.forms[\'display\'].children.value);history.go(0)" ></TD>');
        fieldChild = document.forms['display'].children.value;          
        document.write('</TR>');                 
                     
     } // end if children   
    } // end function children
    

    function diagsCost(){
     firstYear=firstYear+child;   
         document.write('<TR>');      
        document.write("<TD>Diagnostic Tests</TD>");
        document.write('<TD> $'+ CurrencyFormatted(child) +'</TD>');
        document.write('<TD> Once Off</TD>');             
                    
          document.write('<TD>Number of children needing printed diagnostic tests.<BR><input type="text" name="childrenDiagsPrinted"  value="'+ numNeedDiagsPrinted +'" size="4" > <input type="button" name="change" value="Change" onclick="changeProduct(DiagsPrinted,document.forms[\'display\'].childrenDiagsPrinted.value);history.go(0)" ></br>Number of children needing online diagnostic tests.<BR><input type="text" name="childrenDiagsOnline"  value="'+ numNeedDiagsOnline +'" size="4" > <input type="button" name="change" value="Change" onclick="changeProduct(DiagsOnline,document.forms[\'display\'].childrenDiagsOnline.value);history.go(0)" ></TD>');
        fieldChild = document.forms['display'].children.value;          
        document.write('</TR>');                 
		document.write('<TR>'); 
        document.write('<TD colspan="4"><font color="#003399">These initial fees are usually paid when you send in your registration form.</font></TD>');
        document.write('</TR>');                     
    } // end function diagsCost              

      function allowance(){
        if(numchildren==1){
          govAllow=743;
        } // end if
        if(numchildren==2){
          govAllow=743+632;
        } // end if
        if(numchildren==3){
          govAllow=743+632+521;
        } // end if
        if(numchildren > 3){
          overThree=numchildren-3;      
          govAllow=(overThree*372);
          govAllow=743+632+521+govAllow;
        }
        
        document.write('<TR>');      
        document.write('<TD colspan="4"> &nbsp;</TD>');         
        document.write('</TR>'); 
        
        document.write('<TR>');      
        document.write('<TD colspan="4" class="subtitle"> Allowance </TD>');        
        document.write('</TR>');  
        document.write('<TR>');      

        document.write('<TD> <table border="0" width="110"><tr><td>Supervisory Allowance</td><td>&nbsp;<img src="images/question.gif" alt="What is this?" Onmouseover=SwapMenu("Over","Menus") Onmouseout=SwapMenu("Out","Menus")></td></tr></TABLE><div id="Menus" OnMouseOver=SwapMenu("Over","Menus") Onmouseout=SwapMenu("Out","Menus") align="right"> <TABLE border="1" align="right" cellpadding="2" cellspacing="2" width="300" bordercolor="#003399" bgcolor="#99CCFF"><TR><td valign="center" align="left">The homeschooler supervisory allowance is an allowance paid by the New Zealand government to homeschooling families.</td></TR></TABLE></div></TD>');
        document.write('<TD> -$' + govAllow + '</TD>');
        document.write('<TD colspan="2"> Paid in January & July Every Year<BR><FONT size="-2">Your first payment may be a partial amount if you have been homeschooling for less than 6 months when it is paid.</FONT> </TD>');       
        document.write('</TR>');
        
        
      } // end function allowance
       
      function totals(){
      afterAllowFirst=firstYear-govAllow;
      afterAllowOther=otherYear-govAllow;
        document.write('<TR>');      
        document.write('<TD colspan="4"> &nbsp;</TD>');         
        document.write('</TR>'); 
        document.write('<TR>');      
        document.write('<TD colspan="4"><B class="subtitle">Totals:</B></TD>');         
        document.write('</TR>');         
                                
        document.write('<TR>');      
        document.write('<TD> <B>Costs for the First 12 Months</B></TD>');
        document.write('<TD> $'+ CurrencyFormatted(firstYear) +'</TD>');
        document.write('<TD colspan="2"> Including the fees you pay to us and the estimated number of PACEs and Score Keys you would purchase from SCEE.</TD>');       
        document.write('</TR>');
        
        document.write('<TR>');      
        document.write('<TD> <B>Minus Supervisory Allowance</B> </TD>');
        document.write('<TD> <font color="red">-$'+ CurrencyFormatted(govAllow) +'</font></TD>');
        document.write('<TD colspan="2"> Paid in January & July</TD>');      
        document.write('</TR>');
		
        document.write('<TR>');      
        document.write('<TD> <B>Equals</B> </TD>');
        document.write('<TD> <font class="subtitle">$'+ CurrencyFormatted(afterAllowFirst) +'</font></TD>');
        document.write('<TD colspan="2"> &nbsp;</TD>');      
        document.write('</TR>');		
        
        document.write('<TR>');      
        document.write('<TD colspan="4">&nbsp;</TD>');         
        document.write('</TR>');
         
        document.write('<TR>');      
        document.write('<TD colspan="2"> <B>Cost for the Following Years</B><BR><FONT size="-2">Including the fees you pay to us and the estimated number of PACEs and Score Keys you would purchase from SCEE.</FONT></TD>');
        document.write('<TD colspan="2"> $'+ otherYear +'</TD>');
        
        document.write('<TR>');      
        document.write('<TD colspan="2"> <B>Minus Supervisory Allowance</B></TD>');
        document.write('<TD colspan="2"> <font color="red">-$'+ govAllow +'</font></TD>');
        document.write('</TR>');
		
        document.write('<TR>');      
        document.write('<TD colspan="2"> <B>Equals</B></TD>');
        document.write('<TD colspan="2"> <font class="subtitle">$'+ afterAllowOther +'</font></TD>');
        document.write('</TR>');		



        
      } // end function totals


// ----------------------------------------------------------------- 

 yearfee();
 diagsCost();
 monthly();
 childrenCost();
 allowance();
 totals();

        document.write('</TD>');         
        document.write('</TR>');              
    document.write('</TABLE>');
        document.write('</FORM>'); 
    
  }// if document.cookie
  
}// showbasket 
