function LTAXEstimator()
{
  this.isValid               = LTAXEstimator_isValid;
  this.reset                 = LTAXEstimator_Reset;
  this.calculate             = LTAXEstimator_Calculate;
  this.getReportHTML         = LTAXEstimator_getReportHTML;
  
  this.oRounder              = new Rounder(); 
  
  this.ownerType = -1;
  this.ownerTypeValid = false;
  
  this.totUnimprovedValue1 = 0;
  this.totUnimprovedValue1Valid = false;

  this.totUnimprovedValue2 = 0;
  this.totUnimprovedValue3 = 0;
  
  this.ltaxPayable         = 0;
           
  /////////////////////// LTAX Estimator ////////////////////////////////////////
               
  this.putOwnerType                = LTAXEstimator_putOwnerType;
  this.isOwnerTypeValid            = LTAXEstimator_isOwnerTypeValid;
  this.getOwnerType                = LTAXEstimator_getOwnerType;
  
  this.putTotUnImprovedValue1      = LTAXEstimator_putTotUnImprovedValue1;
  this.isTotUnImprovedValue1Valid  = LTAXEstimator_isTotUnImprovedValue1Valid;
  this.getTotUnImprovedValue1      = LTAXEstimator_getTotUnImprovedValue1;
  
  this.putTotUnImprovedValue2      = LTAXEstimator_putTotUnImprovedValue2;
  this.isTotUnImprovedValue2Valid  = LTAXEstimator_isTotUnImprovedValue2Valid;
  this.getTotUnImprovedValue2       = LTAXEstimator_getTotUnImprovedValue2;

    
  this.putTotUnImprovedValue3      = LTAXEstimator_putTotUnImprovedValue3;
  this.isTotUnImprovedValue3Valid  = LTAXEstimator_isTotUnImprovedValue3Valid;
  this.getTotUnImprovedValue3      = LTAXEstimator_getTotUnImprovedValue3;
  this.calcTotUnImprovedValue3     = LTAXEstimator_calcTotUnImprovedValue3;

  this.calcForIndividual           = LTAXEstimator_CalculateForIndividual;
  this.calcForCTA                  = LTAXEstimator_CalculateForCTA;
  
  this.getLTAXPayable              = LTAXEstimator_getLTAXPayable;
    
    
  ///////////////////////////////////////////////////////////////////////
  
  this.getErrorText      = LTAXEstimator_getErrorText;
  this.errorText         = null;
  this.errorCode         = 0;
    
  this.isValidCalculation = LTAXEstimator_isValidCalculation;
  this.validCalculation  = false; 
}

function LTAXEstimator_isValidCalculation()
{
  return this.validCalculation;
}

function LTAXEstimator_getReportHTML()
{   
   //var docDateHTML         = "<TR><TD><font face='Arial, Helvetica, sans-serif' size='1'><b>Document Date:</font></b></TD><TD><font face='Arial, Helvetica, sans-serif' size='1'>" + this.docDate.getDate() + "/" + (this.docDate.getMonth() + 1) + "/" + this.docDate.getFullYear() +  "</font></TD></TR>";
   //var fileRefHTML         = "<TR><TD><font face='Arial, Helvetica, sans-serif' size='1'><b>File Reference:</b></TD><TD><font face='Arial, Helvetica, sans-serif' size='1'>" + this.fileReference + "</font></TD></TR>";

   var periodDetailsHTML = "";

   var ownerType = this.getOwnerType();

   if (ownerType == 1){
	   ownerTypeDetailsHTML = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Selected Owner Type: </font></TD><TD><font face='Arial, Helvetica, sans-serif' size='1'> Individual Person (resident in Australia)</font></TD></TR>";      
   } else {

     if (ownerType == 2){
	   ownerTypeDetailsHTML = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Selected Owner Type: </font></TD><TD><font face='Arial, Helvetica, sans-serif' size='1'> Company or Trustee</font></TD></TR>";      
     } else{
         if (ownerType == 3){
	       ownerTypeDetailsHTML = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Selected Owner Type: </font></TD><TD><font face='Arial, Helvetica, sans-serif' size='1'> Absentee (non resident in Australia)</font></TD></TR>";      
         } else{
                ownerTypeDetailsHTML = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Selected Owner Type: </font></TD><TD><font face='Arial, Helvetica, sans-serif' size='1'> ERROR</font></TD></TR>";      
         }
     }
   }

   var totUnImprovedValue1HTML  = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Total unimproved value of all land holdings as at 30 June 2009:</font></TD><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>" + utilities_dollarformat(this.getTotUnImprovedValue1()) + "</font></TD></TR>";
   var totUnImprovedValue1CommentHTML  = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>(if land held jointly include only your share value of the land in calculating the total value of all land held)</font></TD><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>&nbsp</font></TD></TR>";
   var totUnImprovedValue2HTML  = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Less total unimproved value of land subject to a deduction (e.g.: for a principal place of residence):</font></TD><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>" + utilities_dollarformat(this.getTotUnImprovedValue2()) + "</font></TD></TR>";
   var totUnImprovedValue3HTML  = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Total unimproved value of land subject to land tax:</font></TD><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>" + utilities_dollarformat(this.getTotUnImprovedValue3()) + "</font></TD></TR>";
   var totLandTaxPayableHTML    = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>Land tax Payable:</font></TD><TD align='right'><font face='Arial, Helvetica, sans-serif' size='1'>" + utilities_dollarformat(this.previous) + "</font></TD></TR>";

   //var totUnImprovedValue1AmountHTML    = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='2'><b>" + this.getTotUnImprovedValue1() + "</b></font></TD><TD class='thinTopBtmUnderline' align='right'><font face='Arial, Helvetica, sans-serif' size='2'>" + utilities_dollarformat(this.unAscertainableAmount) + "</font></TD></TR>";
   //var totUnImprovedValue2AmountHTML    = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='2'><b>" + this.getTotUnImprovedValue2() + "</b></font></TD><TD class='thinTopBtmUnderline' align='right'><font face='Arial, Helvetica, sans-serif' size='2'>" + utilities_dollarformat(this.unAscertainableAmount) + "</font></TD></TR>";
   //var totUnImprovedValue3AmountHTML    = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='2'><b>" + this.getTotUnImprovedValue3() + "</b></font></TD><TD class='thinTopBtmUnderline' align='right'><font face='Arial, Helvetica, sans-serif' size='2'>" + utilities_dollarformat(this.unAscertainableAmount) + "</font></TD></TR>";

   var disclaimer1HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>Please note:</font></TD></TR>";
   var disclaimer2HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>&nbsp</font></TD></TR>";
   var disclaimer3HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>1. This land tax estimator has been simplified to allow users to obtain an approximate idea of land tax that would be payable in a limited number of circumstances.</font></TD></TR>";
   var disclaimer4HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>2. The actual calculation of land tax can be more complex depending on many factors set out in more detail in the authorised version of the legislation.</font></TD></TR>";
   var disclaimer5HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>3. Professional advice should be sought by readers.</font></TD></TR>";
      var disclaimer6HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>4. Copyright in the material presented on this site is retained by the State of Queensland.</font></TD></TR>";
      var disclaimer7HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>5. A user may download, store in cache, display, print and copy the material in unaltered form only.</font></TD></TR>";
      var disclaimer8HTML = "<TR><TD align='left'><font face='Arial, Helvetica, sans-serif' size='1'>6. A user may not transmit, distribute or commercialise the material without the permission of the State of Queensland.</font></TD></TR>";

   var ltaxDutyPayableHTML          = "<TR><TD align='right'><font face='Arial, Helvetica, sans-serif' size='2'><b>Land Tax Payable:</b></font></TD><TD class='thinTopBtmUnderline' align='right'><font face='Arial, Helvetica, sans-serif' size='2'>" + utilities_dollarformat(this.getLTAXPayable()) + "</font></TD></TR>";
   //var errorTextHTML          = "<TABLE><TR><TD><font face='Arial, Helvetica, sans-serif' size='2'>" + this.getStatusMsg() + "</font></TD></TR></TABLE>";
 
   
   //var reportHTML = "<TABLE>";
   //reportHTML += docDateHTML;
   //reportHTML += fileRefHTML;
   //reportHTML += "</TABLE>";
   
   //reportHTML += "<BR>";

   var reportHTML = "<TABLE>";
   reportHTML += disclaimer1HTML ;
   reportHTML += disclaimer2HTML ;
   reportHTML += disclaimer3HTML ;
   reportHTML += disclaimer4HTML ;
   reportHTML += disclaimer5HTML ;
   reportHTML += disclaimer6HTML ;
   reportHTML += disclaimer7HTML ;
   reportHTML += disclaimer8HTML ;
   reportHTML += "</TABLE>";
   
   reportHTML += "<BR>";
   
   reportHTML += "<TABLE>";
   reportHTML += ownerTypeDetailsHTML;
   reportHTML += "<BR>";

   reportHTML += totUnImprovedValue1HTML;
   reportHTML += totUnImprovedValue1CommentHTML;
   reportHTML += "<BR>";

   reportHTML += totUnImprovedValue2HTML;
   reportHTML += totUnImprovedValue3HTML;
   reportHTML += "<BR>";

   reportHTML += ltaxDutyPayableHTML;
   reportHTML += "</TABLE>";
      
   reportHTML += "<BR>";
      
   //reportHTML += errorTextHTML;
   
   return reportHTML;
}



function LTAXEstimator_getErrorText()
{
  return this.errorText;
}

function LTAXEstimator_isValid()
{ 
   this.ownerTypeValid = true;
       
   if (this.ownerType == -1) {
       this.errorText = "The owner type must be selected to calculate";
       this.ownerTypeValid = false;
       return false;
   }

   if (this.totUnimprovedValue1 == "") {
       this.errorText = "Please enter the total unimproved value of all land holdings as at 30 June 2009";
       this.totUnimprovedValue1Valid = false;
       return false;
   }
   
   return true;
}

function LTAXEstimator_Reset()
{
  this.ownerType = -1;
  this.ownerTypeValid = false;
    
  this.totUnimprovedValue1 = 0;
  this.totUnimprovedValue2 = 0;
  this.totUnimprovedValue3 = 0;
  
  this.ltaxPayable         = 0;

  this.errorText         = null;
  this.errorCode         = 0;

  this.validCalculation  = false; 

}

function LTAXEstimator_Calculate()
{   
  this.validCalculation  = false; 
       
  //// Calculate 
  
  this.totUnimprovedValue3 = this.calcTotUnImprovedValue3();
    
  if (this.ownerType == 1) {
      this.ltaxPayable = this.calcForIndividual();  
  } 
  
  if ((this.ownerType == 2) || (this.ownerType ==3)) {
	  this.ltaxPayable = this.calcForCTA();  
  } 
    
  this.validCalculation  = true; 

  return this.validCalculation;
}

function LTAXEstimator_CalculateForIndividual()
{
	var ltaxPayable = 0;
	var additional = 0;
	
	if ((this.totUnimprovedValue3 >= 0) && (this.totUnimprovedValue3 <= 599999)) {
		ltaxPayable = 0;
	}
	
	if ((this.totUnimprovedValue3 >= 600000) && (this.totUnimprovedValue3 <= 999999)) {
		ltaxPayable = 500;
		
		additional = (this.totUnimprovedValue3 - 600000) * 1.0;
	}
	
	if ((this.totUnimprovedValue3 >= 1000000) && (this.totUnimprovedValue3 <= 2999999)) {
		ltaxPayable = 4500;
		
		additional = (this.totUnimprovedValue3 - 1000000) * 1.65;
	}

	if ((this.totUnimprovedValue3 >= 3000000) && (this.totUnimprovedValue3 <= 4999999)) {
		ltaxPayable = 37500;
		
		additional = (this.totUnimprovedValue3 - 3000000) * 1.25;
	}

	
	if ((this.totUnimprovedValue3 >= 5000000)) {
		ltaxPayable = 62500;
		
		additional = (this.totUnimprovedValue3 - 5000000) * 1.75;
	}
	
	ltaxPayable = (ltaxPayable * 100) + additional;
	
	ltaxPayable = this.oRounder.truncatePrecision2(ltaxPayable/100);
	
 	return (ltaxPayable);
}

function LTAXEstimator_CalculateForCTA()
{

	var ltaxPayable = 0;
	var additional = 0;
	
	if ((this.totUnimprovedValue3 >= 0) && (this.totUnimprovedValue3 <= 349999)) {
		ltaxPayable = 0;
	}
	
	if ((this.totUnimprovedValue3 >= 350000) && (this.totUnimprovedValue3 <= 2249999)) {
		ltaxPayable = 1450;
		
		additional = (this.totUnimprovedValue3 - 350000) * 1.7;
	}
	
	if ((this.totUnimprovedValue3 >= 2250000) && (this.totUnimprovedValue3 <= 4999999)) {
		ltaxPayable = 33750;
		
		additional = (this.totUnimprovedValue3 - 2250000) * 1.5;
	}

	if ((this.totUnimprovedValue3 >= 5000000)) {
		ltaxPayable = 75000;
		
		additional = (this.totUnimprovedValue3 - 5000000) * 2.0;
	}
	
	ltaxPayable = (ltaxPayable * 100) + additional;
	
	ltaxPayable = this.oRounder.truncatePrecision2(ltaxPayable/100);
	
 	return (ltaxPayable);
}

function LTAXEstimator_putOwnerType(obj)
{
	this.ownerType = obj;
}

function LTAXEstimator_getOwnerType(obj)
{
	return this.ownerType;
}

function LTAXEstimator_isOwnerTypeValid()
{
    return this.ownerTypeValid;
}
  
function LTAXEstimator_putTotUnImprovedValue1(obj)
{
      if (obj == "") {obj = 0;}
	this.totUnimprovedValue1 = obj;
}

function LTAXEstimator_getTotUnImprovedValue1(obj)
{
	return this.totUnimprovedValue1;
}

function LTAXEstimator_isTotUnImprovedValue1Valid()
{
	return this.totUnimprovedValue1Valid;
}
  
function LTAXEstimator_putTotUnImprovedValue2(obj)
{
      if (obj == "") {obj = 0;}
      this.totUnimprovedValue2 = obj;
}

function LTAXEstimator_getTotUnImprovedValue2(obj)
{
	return this.totUnimprovedValue2;
}


function LTAXEstimator_isTotUnImprovedValue2Valid()
{
	return true;
}
    
function LTAXEstimator_putTotUnImprovedValue3(obj)
{
      if (obj == "") {obj = 0;}
	this.totUnimprovedValue3 = obj;
}

function LTAXEstimator_isTotUnImprovedValue3Valid()
{
	return true;
}

function LTAXEstimator_getTotUnImprovedValue3()
{
    this.totUnimprovedValue3 = this.calcTotUnImprovedValue3();
	
	return this.totUnimprovedValue3;
}

function LTAXEstimator_calcTotUnImprovedValue3()
{
    var totUnimprovedValue3 = 0;
    
	if (this.totUnimprovedValue1 < 0) {this.totUnimprovedValue1 = 0;}
	if (this.totUnimprovedValue2 < 0) {this.totUnimprovedValue2 = 0;}

	totUnimprovedValue3 = this.totUnimprovedValue1 - this.totUnimprovedValue2;
	
	if (totUnimprovedValue3 < 0) {totUnimprovedValue3 = 0;}
	
	return totUnimprovedValue3;
}

function LTAXEstimator_getLTAXPayable()
{
	return this.ltaxPayable;
}


