    var myroi = new ROI();
	var xmlhttp;
	var isIE = false;
	var incentivedata;

	function showtabs(id2)
    {
    
    if(id2==1)
     {
      document.getElementById('tabs-1').style.display='block';
      document.getElementById('tabs-2').style.display='none';
	 }
   
    if(id2==2)
    {
     document.getElementById('tabs-1').style.display='none';
     document.getElementById('tabs-2').style.display='block';
	 }
  }
 
 function showtab2(id)
	{
   if(id==1)
   {
    document.getElementById('tabs13').style.display='block';
    document.getElementById('tabs14').style.display='none';
    document.getElementById('tabs15').style.display='none';
   }
   
   if(id==2)
   {
    document.getElementById('tabs13').style.display='none';
    document.getElementById('tabs14').style.display='block';
    document.getElementById('tabs15').style.display='none';
   }
   
   if(id==3)
   {
    document.getElementById('tabs13').style.display='none';
    document.getElementById('tabs14').style.display='none';
    document.getElementById('tabs15').style.display='block';
   }
  
  }
  
  function showtab3(id)
	{
	
   if(id==1)
   {   
    document.getElementById('tabs16').style.display='block';
    document.getElementById('tabs17').style.display='none';
    document.getElementById('tabs18').style.display='none';
    document.getElementById('tabs19').style.display='none';
    document.getElementById('tabs20').style.display='none';
    document.getElementById('tabs21').style.display='none';
   }
   
   if(id==2)
   {
    document.getElementById('tabs16').style.display='none';
    document.getElementById('tabs17').style.display='block';
    document.getElementById('tabs18').style.display='none';
    document.getElementById('tabs19').style.display='none';
    document.getElementById('tabs20').style.display='none';
    document.getElementById('tabs21').style.display='none';
   }
   
   if(id==3)
   {
    document.getElementById('tabs16').style.display='none';
    document.getElementById('tabs17').style.display='none';
    document.getElementById('tabs18').style.display='block';
    document.getElementById('tabs19').style.display='none';
    document.getElementById('tabs20').style.display='none';
    document.getElementById('tabs21').style.display='none';
   }
   
   if(id==4)
   {
    document.getElementById('tabs16').style.display='none';
    document.getElementById('tabs17').style.display='none';
    document.getElementById('tabs18').style.display='none';
    document.getElementById('tabs19').style.display='block';
    document.getElementById('tabs20').style.display='none';
    document.getElementById('tabs21').style.display='none';
   }
  
   if(id==5)
   {
    document.getElementById('tabs16').style.display='none';
    document.getElementById('tabs17').style.display='none';
    document.getElementById('tabs18').style.display='none';
    document.getElementById('tabs19').style.display='none';
    document.getElementById('tabs20').style.display='block';
    document.getElementById('tabs21').style.display='none';
   }
   if(id==6)
   {
    document.getElementById('tabs16').style.display='none';
    document.getElementById('tabs17').style.display='none';
    document.getElementById('tabs18').style.display='none';
    document.getElementById('tabs19').style.display='none';
    document.getElementById('tabs20').style.display='none';
    document.getElementById('tabs21').style.display='block';
   }
  }
  
  function val1(id3)
  {
   // if(id3==4)
   // {
   // var txt1=document.getElementById('text1').value;
   // var t1=txt1.replace(!/[0-9]/,'');
   
   // document.getElementById('text1').value=t1;
   // document.getElementById('txt4').value=txt1;
   // }
  }
  
  function fuelusage(li)
  {
   var mpg=(Math.round((235.214584/li)*100000)/100000);
   //document.getElementById('text12').value=mpg;
   SetValue('l_per_km',mpg,2);
  }
  
  
  
  function fuelusage1(li1)
  {
   var mpg1=(Math.round((235.214584/li1)*100000)/100000);
   //document.getElementById('text11').value=mpg1;
   SetValue('m_per_g',mpg1,2);
   }
  
  
  
  function valid2()
  {
   if(document.getElementById('text1').value=="")
   {
    alert("Please, Provide Proper Soft/Hard Input");
    return false;
   }
   
   if(document.getElementById('text2').value=="")
   {
    alert("Please, Provide Proper Soft/Hard Input");
    return false;
   }
   
   if(document.getElementById('text1').value=="")
   {
    alert("Please, Provide Proper Soft/Hard Input");
    return false;
   }
   
   if(document.getElementById('text11').value=="")
   {
    alert("Please, Provide Proper Soft/Hard Input");
    return false;
   }
   
   if(document.getElementById('text13').value=="")
   {
    alert("Please, Provide Proper Soft/Hard Input");
    return false;
   }
   
   if(document.getElementById('text7').value=="")
   {
    alert("Please, Provide Proper Soft/Hard Input");
    return false;
   }
   
   if(document.getElementById('text7').value=="")
   {
    alert("Please, Provide Proper Soft/Hard Input");
    return false;
   }
   
  
  }
  
  
  
   
  function getdata()
  { 
	myroi.calc();
  }
  
  
  
  function change_class2()
   {
   getElementById('td1').className="blue-tab";
   getElementById('td3').className="lblue-tab";
    }
  
  function hardtab()
  {
   document.getElementById("td1").className="blue-tab";
   document.getElementById("td3").className="lblue-tab";
  }
  
  function softtab()
  {
   document.getElementById("td1").className="lblue-tab";
   document.getElementById("td3").className="blue-tab";
  }
  
  function change_class(id)
  {
	
	if(id==1){

	 document.getElementById("td1").className="blue-tab";
	 document.getElementById("td3").className="lblue-tab";
	}
	if(id==2){
	 document.getElementById("td1").className="lblue-tab";
	 document.getElementById("td3").className="blue-tab";
	}
   
  }
  
  function change_vehicle(){
		var vtype =  document.getElementById("vehicle_type");
		var vtext = document.getElementById("vehicletype");

		if (vtype.value=="1"){
			vtext.innerHTML="Ford Ranger";
		}
		if (vtype.value=="2"){
			vtext.innerHTML="Ford Escape";
		}
   }
   
   function showyear(){
   var d = new Date();
   var y5 = d.getFullYear()+5 ;
   var y10 = d.getFullYear()+10 ;
   
	document.getElementById("year5").innerHTML="in "+y5;
	document.getElementById("year10").innerHTML="in "+y10;
   }
  
  function addCommas(nStr)
 { 
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
 }
 
 function getStyleClass (className) {
	for (var s = 0; s < document.styleSheets.length; s++)
	{
		if(document.styleSheets[s].rules)
		{
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
			{
				if (document.styleSheets[s].rules[r].selectorText == '.' + className)
				{
					return document.styleSheets[s].rules[r];
				}
			}
		}
		else if(document.styleSheets[s].cssRules)
		{
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
			{
				if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
					return document.styleSheets[s].cssRules[r];
			}
		}
	}
	
	return null;
}

function ChangeUnits(){
	
	var unittype = document.getElementById("States").value;
	

	if (unittype.indexOf("_I")>0){
		getStyleClass('Imperial-Units').style.display = 'inline';
		getStyleClass('Metric-Units').style.display = 'none';
	}
	else{
		getStyleClass('Imperial-Units').style.display = 'none';
		getStyleClass('Metric-Units').style.display = 'inline';
	}
}

function SetValue(controlid,value,tofix){
	
	if (isNaN(value)) {
		if  (value.length){
		
		}
		else{
		value ='';
		}
	}
	else{
		value = addCommas(value.toFixed(tofix));
	}

	var control= document.getElementById(controlid);
	var postcon = document.getElementById('hd_'+controlid);
	if (postcon){
		postcon.value = value;
	}
	if (control && control.tagName.toLowerCase()=='input'){
		control.value = value;
	}
	else if(control && control.tagName.toLowerCase()=='span'){
		control.innerHTML = value;
	}
	else if(control && control.tagName.toLowerCase()=='div'){
		control.innerHTML = value;
	}
}

function GetValue(controlid,valuetype,defaultvalue){
	var control = document.getElementById(controlid);
	if (valuetype==0){
		var intvalue=parseInt(control.value);
		if (isNaN(intvalue)){
			intvalue=defaultvalue;
		}
		return intvalue;
	}
	else if(valuetype==1){
		var floatvalue=parseFloat(control.value);
		if (isNaN(floatvalue)){
			floatvalue=defaultvalue;
		}
		return floatvalue;
	}
	else{
		return control.value;
	}
}



function ROI(){
//input
	//hard
	this.annual_km = Number.NaN;
	this.gas_price_today = Number.NaN;
	this.gas_price_5year = Number.NaN;
	this.gas_price_10year = Number.NaN;
	this.m_per_g = Number.NaN;
	this.l_per_km = Number.NaN;
	this.m_per_kwh = 6.1;
	this.km_per_kwh = 9.8;
	this.annual_maint = Number.NaN;
	this.annual_maint_e = Number.NaN;
	this.elect_price = Number.NaN;
	this.vehicle_type = Number.NaN;
	this.co2_price = Number.NaN;
	this.co2_per_year = Number.NaN;
	this.unit_system = 2; //default Metric
	this.ca_cost = 50000.0;
	this.us_cost = 40000.0;
	//soft
	this.pr_value = Number.NaN;
	this.social_value = Number.NaN;
	this.res_value = Number.NaN;
	//incentives
	this.incentives_amount = Number.NaN;	
	this.incentives_exists = false;
	//other
	this.state = '';
	this.year5 = new Date().getFullYear()+5 ;
	this.year10 =new Date().getFullYear()+10 ;
	
	//output
	this.gas_price_5year_avg = Number.NaN;
	this.gas_price_10year_avg = Number.NaN;
	this.elect_price_5year_avg = Number.NaN;
	this.elect_price_10year_avg = Number.NaN;
	this.gas_cost_5year = Number.NaN;
	this.gas_cost_10year = Number.NaN;
	this.elect_cost_5year = Number.NaN;
	this.elect_cost_10year = Number.NaN;
	this.maint_cost_5year = Number.NaN;
	this.maint_cost_10year = Number.NaN;
	this.maint_cost_5year_e = Number.NaN;
	this.maint_cost_10year_e = Number.NaN;
	this.co2_cost_5year = Number.NaN;
	this.co2_cost_10year = Number.NaN;
	this.co2_manu_saving = Number.NaN;
	
	//annual gain
	this.annual_gain_5year = Number.NaN;
	this.annual_gain_10year = Number.NaN;
	//total
	this.total_own_5year = Number.NaN;
	this.total_own_10year = Number.NaN;
	this.total_own_5year_e = Number.NaN;
	this.total_own_10year_e = Number.NaN;
	
	this.total_saving_5year = Number.NaN;
	this.total_saving_10year = Number.NaN;
	
	this.pay_itself = Number.NaN;
	this.mail_body = "";
	
	this.readinput = function() {
		this.mail_body = "";
		this.unit_system = GetValue('States',2,0);
		this.mail_body += "<p>State: " + this.unit_system  + "</p>";
		if (this.unit_system.indexOf("_I")>0){
			this.unit_system = 1;
		}
		else{
			this.unit_system = 2;
		}
		this.annual_km = GetValue('annual_km',0,0);
		this.gas_price_today = GetValue('gas_price_today',1,0);
		this.gas_price_5year = GetValue('gas_price_5year',1,0);
		this.gas_price_10year = GetValue('gas_price_10year',1,0);
		this.m_per_g = GetValue('m_per_g',1,0);
		this.l_per_km = GetValue('l_per_km',1,0);
		
		this.mail_body += "<p>annual_km: " + this.annual_km  + "</p>";
		this.mail_body += "<p>gas_price_today: " + this.gas_price_today  + "</p>";
		this.mail_body += "<p>gas_price_5year: " + this.gas_price_5year  + "</p>";
		this.mail_body += "<p>m_per_g: " + this.m_per_g  + "</p>";
		this.mail_body += "<p>l_per_km: " + this.l_per_km  + "</p>";
		
		
		
		this.annual_maint = GetValue('annual_maint',0,0);
		this.annual_maint_e = this.annual_maint / 10;
		this.elect_price = GetValue('elect_price',1,0);
		this.vehicle_type = GetValue('vehicle_type',0,0);
		
		
		
		if (this.vehicle_type==1){ // REV 300 ACX SUV
			this.vehicle_type_txt = "REV 300 ACX SUV";
		}
		else if(this.vehicle_type==2){//REV Pickup
			this.vehicle_type_txt = "REV Pickup";
		}
		else{
			this.vehicle_type_txt = "REV Vehicle";
		}
		
		
		this.mail_body += "<p>annual_maint: " + this.annual_maint  + "</p>";
		this.mail_body += "<p>elect_price: " + this.elect_price  + "</p>";
		this.mail_body += "<p>vehicle_type: " + this.vehicle_type_txt  + "</p>";
		
		
		this.co2_price = GetValue('co2_price',1,0);
		this.co2_per_year = GetValue('co2_per_year',0,0);
		
		this.mail_body += "<p>co2_price: " + this.co2_price  + "</p>";
		this.mail_body += "<p>co2_per_year: " + this.co2_per_year  + "</p>";
		
		
		//soft
		this.pr_value = GetValue('pr_value',0,0);
		this.social_value = GetValue('social_value',0,0);
		this.res_value = GetValue('res_value',0,0);
		
		this.mail_body += "<p>pr_value: " + this.pr_value  + "</p>";
		this.mail_body += "<p>social_value: " + this.social_value  + "</p>";
		this.mail_body += "<p>res_value: " + this.res_value  + "</p>";
		
		
		
		//incentives
		this.incentives_exists = false;
		this.incentives_amount = 0;
		var incentiveinputs = document.getElementById("incentivelistholder").getElementsByTagName("input");
		for(i=0;i<incentiveinputs.length;i++){
			if (incentiveinputs[i].checked){
				this.mail_body += "<p>incentive: " + incentiveinputs[i].id  + " amount:" + incentiveinputs[i].value +  "</p>";
				var avalue = incentiveinputs[i].value;
				if (avalue.indexOf("$")>=0){
					this.incentives_amount += parseInt(avalue.replace("$",""));
					this.incentives_exists = true;
				}
				
				if (avalue.indexOf("%")>=0){
					if (this.unit_system ==1){ //Imperial
						this.incentives_amount += parseInt(avalue.replace("%","")) * this.us_cost / 100.0 ;
					}
					else{// metric
						this.incentives_amount += parseInt(avalue.replace("%","")) * this.ca_cost / 100.0 ;
					}
					
					
					this.incentives_exists = true;
				}
			}
		}
		
		//this.incentives_amount = Number.NaN;	
		//this.incentives_code = Number.NaN;
	}
	
	this.calc = function() {
		this.readinput();
		//5 year gas price avg
		if  (this.gas_price_5year>0){
			this.gas_price_5year_avg = (this.gas_price_today + this.gas_price_5year)/2.0;
		}
		else{
			this.gas_price_5year_avg = this.gas_price_today;
		}
		//10 year gas price avg
		if  (this.gas_price_10year>0){
			this.gas_price_10year_avg = (this.gas_price_today + this.gas_price_10year)/2.0;
		}
		else{
			this.gas_price_10year_avg = this.gas_price_today;
		}
		
		this.elect_price_5year_avg = this.elect_price;
		this.elect_price_10year_avg = this.elect_price;
		
		//gas and electricity cost
		if (this.unit_system ==1){ //Imperial
		
		    
			this.gas_cost_5year = (this.annual_km/this.m_per_g)*this.gas_price_5year_avg*5;
			this.gas_cost_10year = (this.annual_km/this.m_per_g)*this.gas_price_10year_avg*10;
			this.elect_cost_5year = (this.annual_km/this.m_per_kwh)*this.elect_price_5year_avg*5;
			this.elect_cost_10year = (this.annual_km/this.m_per_kwh)*this.elect_price_10year_avg*10;
		}
		else{ // Metric
			this.gas_cost_5year = (this.annual_km/100.0)*this.l_per_km*this.gas_price_5year_avg*5;
			this.gas_cost_10year = (this.annual_km/100.0)*this.l_per_km*this.gas_price_10year_avg*10;
			this.elect_cost_5year = (this.annual_km/this.km_per_kwh)*this.elect_price_5year_avg*5;
			this.elect_cost_10year = (this.annual_km/this.km_per_kwh)*this.elect_price_10year_avg*10;
		}
		

		this.co2_cost_5year = this.co2_price * this.co2_per_year*5;
		this.co2_cost_10year = this.co2_price * this.co2_per_year*10;
		
		if (this.vehicle_type==1){ // REV 300 ACX SUV
			this.co2_manu_saving = this.co2_price * 12;
		}
		else if(this.vehicle_type==2){//REV Pickup
			this.co2_manu_saving = this.co2_price * 12;
		}
		else{
			this.co2_manu_saving = this.co2_price * 15;
		}
		
		//annual gain
		this.annual_gain_5year = this.gas_cost_5year + this.annual_maint*5 + this.co2_cost_5year + this.pr_value + this.social_value - this.elect_cost_5year - this.annual_maint_e*5;
		this.annual_gain_10year = this.gas_cost_10year + this.annual_maint*10 + this.co2_cost_10year + this.pr_value + this.social_value - this.elect_cost_10year - this.annual_maint_e*10;
		//total
		this.total_own_5year = (this.gas_cost_5year + this.annual_maint*5 + this.co2_cost_5year);
		this.total_own_10year = (this.gas_cost_10year + this.annual_maint*10 + this.co2_cost_10year);
		this.total_own_5year_e = (this.elect_cost_5year + this.annual_maint_e*5);
		this.total_own_10year_e = (this.elect_cost_10year + this.annual_maint_e*10);
		
		this.total_saving_5year = this.annual_gain_5year + this.incentives_amount;
		this.total_saving_10year = this.annual_gain_10year + this.incentives_amount;
		
		
		if (this.unit_system ==1){ //Imperial
		this.pay_itself = (this.ca_cost - this.incentives_amount) /(this.annual_gain_10year/10);
		}
		else{ // Metric
		this.pay_itself = (this.us_cost -  this.incentives_amount) /(this.annual_gain_10year/10);
		}
		
		
		this.mail_body += "<p>total_gain_5year: " + this.annual_gain_5year.toFixed(0)  + "</p>";
		this.mail_body += "<p>total_gain_10year: " + this.annual_gain_10year.toFixed(0)  + "</p>";
		
		this.mail_body += "<p>total_own_5year: " + this.total_own_5year.toFixed(0)  + "</p>";
		this.mail_body += "<p>total_own_10year: " + this.total_own_10year.toFixed(0)  + "</p>";
		this.mail_body += "<p>total_own_5year_REV: " + this.total_own_5year_e.toFixed(0)  + "</p>";
		this.mail_body += "<p>total_own_10year_REV: " + this.total_own_10year_e.toFixed(0)  + "</p>";
		
		this.mail_body += "<p>total_incentives_amount: " + this.incentives_amount.toFixed(0)  + "</p>";
		this.mail_body += "<p>total_saving_10year: " + this.total_saving_10year.toFixed(0)  + "</p>";
		this.mail_body += "<p>pay_itself: " + this.pay_itself.toFixed(0)  + "</p>";
		
		
		this.display();
		ChangeUnits();
	}
	

	this.display = function() {
		
		document.getElementById("vehicletype").innerHTML = this.vehicle_type_txt;
		SetValue('hd_vehicle_type_txt',this.vehicle_type_txt,0);
		SetValue('hd_unit_sys',this.unit_system,0);
		
		if (this.pr_value == 0 & this.social_value == 0){
			document.getElementById("soft_warning").style.display="block";
		}
		else{
			document.getElementById("soft_warning").style.display="none";
		}
		
		if (this.incentives_exists){
			document.getElementById("incent_warning").style.display="none";
			document.getElementById("txt_incentives_amount").style.display="inline";
			document.getElementById("total_incentives_amount").style.display="inline";
			SetValue('total_saving_10year_txt','Total Savings With Incentives (10 years)',0);
		}
		else{
			document.getElementById("incent_warning").style.display="block";
			document.getElementById("txt_incentives_amount").style.display="none";
			document.getElementById("total_incentives_amount").style.display="none";
			
			SetValue('total_saving_10year_txt','Total Savings (10 years)',0);
		}
		
		SetValue('mpg_5year',this.m_per_g,2);
		SetValue('mpg_10year',this.m_per_g,2);
		SetValue('lpkm_5year',this.l_per_km,2);
		SetValue('lpkm_10year',this.l_per_km,2);
		
		SetValue('mpkwh_5year',this.m_per_kwh,2);
		SetValue('mpkwh_10year',this.m_per_kwh,2);
		SetValue('kmpkwh_5year',this.km_per_kwh,2);
		SetValue('kmpkwh_10year',this.km_per_kwh,2);
		

		SetValue('kmmile_5year',this.annual_km,0);
		SetValue('kmmile_10year',this.annual_km,0);
		SetValue('kmmile_5year_e',this.annual_km,0);
		SetValue('kmmile_10year_e',this.annual_km,0);
		
		SetValue('g_price_5year',this.gas_price_5year_avg,2);
		SetValue('g_price_10year',this.gas_price_10year_avg,2);
		SetValue('e_price_5year',this.elect_price,2);
		SetValue('e_price_10year',this.elect_price,2);
		
		SetValue('g_cost_5year',this.gas_cost_5year,0);
		SetValue('g_cost_10year',this.gas_cost_10year,0);
		SetValue('e_cost_5year',this.elect_cost_5year,0);
		SetValue('e_cost_10year',this.elect_cost_10year,0);
		
		SetValue('maint_cost_5year',this.annual_maint*5,0);
		SetValue('maint_cost_10year',this.annual_maint*10,0);
		SetValue('maint_cost_5year_e',this.annual_maint_e*5,0);
		SetValue('maint_cost_10year_e',this.annual_maint_e*10,0);
		
		SetValue('co2_cost_5year',this.co2_cost_5year,0);
		SetValue('co2_cost_10year',this.co2_cost_10year,0);
		SetValue('co2_cost_5year_e',0,0);
		SetValue('co2_cost_10year_e',0,0);
		
		SetValue('total_manu_saving',this.co2_manu_saving,0);
		
		SetValue('pr_value_5year',this.pr_value,0);
		SetValue('pr_value_10year',this.pr_value,0);
		SetValue('so_value_5year',this.social_value,0);
		SetValue('so_value_10year',this.social_value,0);
		
		SetValue('annual_gain_5year',this.annual_gain_5year,0);
		SetValue('annual_gain_10year',this.annual_gain_10year,0);
		
		
		SetValue('total_own_5year',this.total_own_5year,0);
		SetValue('total_own_10year',this.total_own_10year,0);
		SetValue('total_own_5year_e',this.total_own_5year_e,0);
		SetValue('total_own_10year_e',this.total_own_10year_e,0);
		
		SetValue('pay_itself',this.pay_itself,1);
	
		SetValue('total_saving_10year',this.total_saving_10year,0);
		SetValue('total_incentives_amount','$'+this.incentives_amount,0);
		
		SetValue('ROI_input',this.mail_body,0);
	}
}


function ShowTab(tabid){
	var tab1 = document.getElementById("td1");
	var tab2 = document.getElementById("td3");
	var tab3 = document.getElementById("td5");
	
	var tabpage1 = document.getElementById("tabs-1");
	var tabpage2 = document.getElementById("tabs-2");
	var tabpage3 = document.getElementById("tabs-3");
	
	
	tab1.className="lblue-tab";
	tab2.className="lblue-tab";
	tab3.className="lblue-tab";
	tabpage1.style.display = 'none';
	tabpage2.style.display = 'none';
	tabpage3.style.display = 'none';
	
	
	switch(tabid)
	{
	case 1:
	  tab1.className="blue-tab";
	  tabpage1.style.display = 'block';
	  
	  break;
	case 2:
	  tab2.className="blue-tab";
	  tabpage2.style.display = 'block';
	 
	  break;
	case 3:
	  tab3.className="blue-tab";
	  tabpage3.style.display = 'block';
	 
	  break;
	default:
	 
	}
	

	HideAllPanel();	
	document.getElementById('header').scrollIntoView(true);
}

function HideAllPanel(){
	var  panelname = 'tabs';
	for (i=13;i<=24;i++){
		var p = document.getElementById(panelname+i);
		if (p){
			p.style.display = 'none';
		}
	}

}

function ShowPanel(pid){
	HideAllPanel();
	var  panelname = 'tabs';
	var p = document.getElementById(panelname+pid);
		if (p){
			p.style.display = 'block';
			var innertable = p.getElementsByTagName("table");
			if(innertable.length>=2){
			
				if (pid==13 | pid==14 | pid==15)
				{
					innertable[1].style.height = (54*3 + 36) + "px";
				}
				else if (pid==24){
				}
				else{
					innertable[1].style.height = (54*8 + 36) + "px";
				}
			}
		}

}

function getincentive()

{
        url = "incentive.xml";
        // AJAX code for Mozilla, Safari, Opera etc.
        if (window.XMLHttpRequest) {
				  isIE = false;

                  xmlhttp = new XMLHttpRequest();
                  xmlhttp.onreadystatechange = xmlhttpChange;
                  xmlhttp.open("GET", url, true);
                  xmlhttp.send(null);
        }
        // AJAX code for IE
        else if (window.ActiveXObject)  {
				  isIE = true;

                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                        if (xmlhttp)
                        {
                                xmlhttp.onreadystatechange = xmlhttpChange;
                                xmlhttp.open("GET", url, true);
                                xmlhttp.send();
                        }
          }
}

function xmlhttpChange()
{
        //create XMLDOM object if xmlhttp shows "loaded"
        if (xmlhttp.readyState == 4) {
          // if "OK"
          if (xmlhttp.status == 200) {
						incentivedata = xmlhttp.responseXML;
						statechange();
                        
          } else {
                //alert(xmlhttp.status);
				//alert(xmlhttp.readyState);
          }
      }
}


function clearincentivelist(){
	
}

function clearincentive(){
	
}

function statechange(){
	var statecode = document.getElementById("States").value;
	statecode = statecode.substr(0,2); 
	buildincentivelist(statecode);
}

function showincentive(sidx,cidx){
	var state = incentivedata.getElementsByTagName("state")[sidx];
	var incentive = state.getElementsByTagName("incentive")[cidx];
	var htmltemp = document.getElementById("incentiveinfotemp").innerHTML;
	htmltemp = htmltemp.replace("[incentiveinfo]",getElementTextNS("", "desc", incentive, 0));
	htmltemp = htmltemp.replace("[incentiveurl]",getElementTextNS("", "url", incentive, 0));
	htmltemp = htmltemp.replace("%5Bincentiveurl%5D",getElementTextNS("", "url", incentive, 0));
	
	document.getElementById("incentiveinfoholder").innerHTML = htmltemp;
}

function buildincentivelist(statecode){
	document.getElementById("incentivelistholder").innerHTML = "";
	HideAllPanel();
	var states = incentivedata.getElementsByTagName("state");
	var state = null;
	var sindex = -1;
	for(i=0;i<states.length;i++){
		if(getElementAtt(states[i],"id","")==statecode){
			state = states[i];
			sindex = i;
			break;
		}
	}
	if (state){
			var htmltemp=document.getElementById("incentivetemplate").innerHTML;
			var html="";
			var temp="";
			var incentives =  state.getElementsByTagName("incentive");
			
			
			for(i=0;i<incentives.length;i++){
				var inid = getElementAtt(incentives[i],"id", 0);
				var inamount = getElementAtt(incentives[i],"amount", 0);
				temp = htmltemp.replace("[incentivename]",getElementTextNS("", "name", incentives[i], 0));
				temp = temp.replace("[incentiveamount]",inamount);
				temp = temp.replace("[incentiveid]",inid);
				temp = temp.replace("[sindex]",sindex);
				temp = temp.replace("[cindex]",i);
				//exclude id
				var exid = getElementTextNS("", "exclude", incentives[i], 0).split(",");//incentives[i].getElementsByTagName("exclude");
				var exidscript = "";
				
				for(j=0;j<exid.length;j++){
					exidscript = exidscript+"setExclude(\"incentive_" + exid[j] + "\",this.checked);"
				}
				
				var inputhtml = "<input id='incentive_" + inid + "' type='checkbox' onclick='" + exidscript + "getdata();' value='" + inamount + "' name='incentive_" + inid + "'/>"
				//alert(inputhtml);
				temp = temp.replace("[incentiveinput]",inputhtml);
				html = html + temp;
				//alert(getElementTextNS("", "name", incentives[i], 0));
				//alert(getElementAtt(incentives[i],"amount", 0));
			}
			setPanelHeight('incentiveinfoholder',36+incentives.length*54);

			if (incentives.length>0){
				document.getElementById('incentivehint').style.display= "none";
			}
			else{
				document.getElementById('incentivehint').style.display= "block";
			}
			
			document.getElementById("incentivelistholder").innerHTML = html;
	}
	else{
			document.getElementById('incentivehint').style.display= "block";
	}
}

function setPanelHeight(pid,height){
		var p = document.getElementById(pid);
		if (p){
			p.style.height = height+'px';
		}
}


function setExclude(inputid,disabled){
	var input = document.getElementById(inputid);
	if (disabled){
		input.checked = false;
		input.disabled = true;
	}
	else{
		input.disabled = false;
	}
}

function getElementAtt(parentElem,AttName,defaultvalue){
	var ret = parentElem.getAttribute(AttName);
	if(ret){
		return ret;
	}
	else{
		return defaultvalue;
	}
}

function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}

function redirectandpost(){
setTimeout("window.location.href='presentation.php'",1000);
return true;
}
