//here you place the ids of every element you want.
var ids=new Array('details','features','location','seller_info');

function switchid(id)
{
	hideallids();
	showdiv(id);
}

function hideallids()
{
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id)
{
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	} else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		} else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id)
{
	//safe function to show an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	} else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		} else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

// declare a global  XMLHTTP Request object
var XmlHttpObj;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") {
		XmlHttpObj = new XMLHttpRequest();
	}
}

function getModel(makeListId)
{
	makeListFormId = makeListId;
	var makeList = document.getElementById(makeListId);
	var selectedMake = makeList.options[makeList.selectedIndex].value;
	var requestUrl;
	requestUrl = "xml_data_provider.php" + "?filter=" + encodeURIComponent(selectedMake);

	CreateXmlHttpObj();
	if(XmlHttpObj) {
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl, true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// this function called when state of  XmlHttpObj changes
// we're interested in the state that indicates data has been
// received from the server
function StateChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4) {
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200) {
			populateModelList(XmlHttpObj.responseXML.documentElement);
		} else {
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// populate the contents of the dropdown list
function populateModelList(modelNode)
{
	if(makeListFormId == 'makeSideList') {
		var modelFormId = 'modelSideList';
	} else if(makeListFormId == 'makeSearchList') {
		var modelFormId = 'modelSearchList';
	} else if(makeListFormId == 'makeIndexList') {
		var modelFormId = 'modelIndexList';
	}

    var modelList = document.getElementById(modelFormId);

	// clear the list 
	for (var count = modelList.options.length-1; count >-1; count--) {
		modelList.options[count] = null;
	}

	var modelNode = modelNode.getElementsByTagName('model');
	var idValue;
	var textValue; 
	var optionItem;
	
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < modelNode.length; count++) {
   		textValue = GetInnerText(modelNode[count]);
		idValue = modelNode[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		modelList.options[modelList.length] = optionItem;
	}
}

function getZone(zoneListId)
{
	zoneListFormId = zoneListId;
	var zoneList = document.getElementById(zoneListId);
	var selectedCountry = zoneList.options[zoneList.selectedIndex].value;
	var requestUrl;
	requestUrl = "xml_zone_data.php" + "?filter=" + encodeURIComponent(selectedCountry);

	CreateXmlHttpObj();
	if(XmlHttpObj) {
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = ZoneChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl, true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// this function called when state of  XmlHttpObj changes
// we're interested in the state that indicates data has been
// received from the server
function ZoneChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4) {
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200) {
			populateZoneList(XmlHttpObj.responseXML.documentElement);
		} else {
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// populate the contents of the dropdown list
function populateZoneList(zoneNode)
{
	if(zoneListFormId == 'country') {
		var zoneFormId = 'state';
	}

    var zoneList = document.getElementById(zoneFormId);
	
	// clear the list 
	for (var count = zoneList.options.length-1; count >-1; count--) {
		zoneList.options[count] = null;
	}

	var zoneNode = zoneNode.getElementsByTagName('zone');
	var idValue;
	var textValue; 
	var optionItem;
	
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < zoneNode.length; count++) {
   		textValue = GetInnerText(zoneNode[count]);
		idValue = zoneNode[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		zoneList.options[zoneList.length] = optionItem;
	}
}

// returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}


// Affordability Calculator //

function calcRound(num) 
{
   result=Math.floor(num)+"." ;
   n = result.length;
   var cents=100*(num-Math.floor(num))+0.5;
   result += Math.floor(cents/10);
   result += Math.floor(cents%10);
   return(result)
}

function Cal() 
{
	var Month;
	var Interest;
	var Downpayment;
	var IPay;
	var total;
	
	Month = document.LoanCal.Month.value;
	Interest = document.LoanCal.Interest.value;
    Downpayment = document.LoanCal.Downpayment.value;
    IPay = document.LoanCal.IPay.value;
    
	document.LoanCal.Budget.value = calcRound(((IPay * Month)/(1 + (Interest/100*(Month/12)))));
	document.LoanCal.Afford.value = calcRound((eval(document.LoanCal.Budget.value) + eval(Downpayment)));
	return false;
}

//Settlement Calculator //

function calcRound(num) 
{
   result=Math.floor(num)+"." ;
   n = result.length;
   var cents=100*(num-Math.floor(num))+0.5;
   result += Math.floor(cents/10);
   result += Math.floor(cents%10);
   return(result)
}

function calc_rebate()
{
	with (document.rebate)
	{
		//T = fullperiod.value; 
		//P = eval(paidperiod.value); 		
		//C = (loanamount.value * intrate.value/100) * fullperiod.value/12;		
		//N = eval(T) - eval(paidperiod.value);		
		//T1 = C * N * (eval(N) + 1.0);
		//T2 = T * (eval(T) + 1.0);
		//T3 = T1 / T2 ;
		
		T = fullperiod.value; 
		P = eval(paidperiod.value); 		
		C = (loanamount.value * intrate.value/100) * fullperiod.value/12;
		n = T - P - 1;
		
		T1 = n * (n + 1);		
		T2 = eval(T) * (eval(T) + 1);
		T3 = T1 / T2 * C;
				
		totalrebate.value = calcRound(T3);				
		settleamount.value = calcRound(eval(C) + eval(loanamount.value) - eval(paidperiod.value * install.value) - eval(totalrebate.value));		
	}		
}

function alertMsg(field,msg) 
{
   alert(msg);
   field.focus();
   field.select();
} 

function validDigit(ch) {
    if ((ch != ".") && (ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") &&
        (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))
	 {return false;}
    else {return true;}
} 

function digit(string) {
    var i;
    var chr;
    for (i = 0; i < string.length; i++) {
        chr = string.substring(i, i+1);
        if (!validDigit(chr)) {
            return false;
        }
    }
    return true;
} 

function empty(string) 
{
    if(string.length==0)
      {
       return true;
      }
    else
      {
       for(i=0;i< string.length;i++)
         { ch=string.substring(i,i+1);
           if (ch != " ") 
            {
              return false;
            }
         }
      return true;   
      }
} 
 

function check_empty(field,alert_msg) 
{
    if(empty(field.value)) 
      {
       alertMsg(field, alert_msg);
       return false; 
      }
    return true;
}

function validate() 
{
   with (document.rebate)
   {      
		if(!check_empty(loanamount, "Loan Amount cannot be blank!"))
	      return false;

    	if(!digit(loanamount.value))  
	      {
	       alertMsg(loanamount, "Please enter only valid digit!");
	       return false;
		  }
		if(!check_empty(intrate, "Interest Rate cannot be blank!"))
	      return false;

    	if(!digit(intrate.value))  
	      {
	       alertMsg(intrate, "Please enter only valid digit!");
	       return false;
		  } 

       if(!check_empty(fullperiod, "Total installment period cannot be blank!"))
	      return false;

    	if(!digit(fullperiod.value))  
	      {
	       alertMsg(fullperiod, "Please enter only valid digit!");
	       return false;
		  } 
	   if(!check_empty(paidperiod, "Installment paid (how many months) cannot be blank!"))
           return false;

    	if(!digit(paidperiod.value))  
	      {
	       alertMsg(paidperiod, "Please enter only valid digit!");
	       return false;
		  } 
	   if(!check_empty(install, "Installment cannot be blank!"))
           return false;

    	if(!digit(install.value))  
	      {
	       alertMsg(install, "Please enter only valid digit!");
	       return false;
		  }
  }
	calc_rebate();
}

// Road Tax Calculator //

//<!-- 
function calcRound(num) {

   result=Math.floor(num)+"." ;

   n = result.length;

   var cents=100*(num-Math.floor(num))+0.5;

   result += Math.floor(cents/10);

   result += Math.floor(cents%10);

	if (Math.floor(cents%10) >= 0.1)
		{
		x = "0.0" + Math.floor(cents%10);
		//result = (result - x) + 0.1;
		result = Math.round(((result - x) + 0.1)*100)/100  
		}
	else
		result = result;

return(result)
}

function cal()
{
tcc = document.rtax.cc.value;

if (document.rtax.fuel[0].checked)
{
if (tcc <= 1000)
	{
	troadtax = 20;
	fuel(troadtax);
	return(false);
	}
	
if (tcc <= 1200)
	{
	troadtax = 55;
	fuel(troadtax);
	return(false);
	}

if (tcc <= 1400)
	{
	troadtax = 70;
	fuel(troadtax);
	return(false);
	}

if (tcc <= 1600)
	{
	troadtax = 90;
	fuel(troadtax);
	return(false);
	}

if (tcc <= 1800)
	{
	troadtax = 200 + ((tcc - 1600) * 0.40);
	fuel(troadtax);
	return(false);
	}

if (tcc <= 2000)
	{
	troadtax = 280 + ((tcc - 1800) * 0.50);
	fuel(troadtax);
	return(false);
	}

if (tcc <= 2500)
	{
	troadtax = 380 + ((tcc - 2000) * 1.0);
	fuel(troadtax);
	return(false);
	}
	
if (tcc <= 3000)
	{
	troadtax = 880 + ((tcc - 2500) * 2.5);
	fuel(troadtax);
	return(false);
	}

if (tcc > 3000)
	{
	troadtax = 2130 + ((tcc - 3000) * 4.5);
	fuel(troadtax);
	return(false);
	}
}
else //for diesel
{
	if (tcc <= 1000)
	{
	troadtax = 20;
	fuel(troadtax);
	return(false);
	}
	
if (tcc <= 1200)
	{
	troadtax = 55;
	fuel(troadtax);
	return(false);
	}

if (tcc <= 1400)
	{
	troadtax = 70;
	fuel(troadtax);
	return(false);
	}

if (tcc <= 1600)
	{
	troadtax = 90;
	fuel(troadtax);
	return(false);
	}

if (tcc <= 1800)
	{
	troadtax = 200 + ((tcc - 1600) * 0.40);
	fuel(troadtax);
	return(false);
	}

if (tcc <= 2000)
	{
	troadtax = 280 + ((tcc - 1800) * 0.50);
	fuel(troadtax);
	return(false);
	}

if (tcc <= 2500)
	{
	troadtax = 380 + ((tcc - 2000) * 1.0);
	fuel(troadtax);
	return(false);
	}
	
if (tcc <= 3000)
	{
	troadtax = 880 + ((tcc - 2500) * 2.5);
	fuel(troadtax);
	return(false);
	}

if (tcc > 3000)
	{
	troadtax = 2130 + ((tcc - 3000) * 4.5);
	fuel(troadtax);
	return(false);
	}
	
}}
function fuel(troadtax1)
{
	//if (document.rtax.fuel[0].checked)
   		document.rtax.roadtax.value = calcRound(troadtax1);
	//else
	//	document.rtax.roadtax.value = calcRound(troadtax1*2);
}	
//-->// JavaScript OTHER
<!--//
		var P = 0;		// Price
		var M = 0;		// Monthly Payment
		var D = 0;		// Down Payment
		var T = 0;		// Term
		var R = 0;		// Rate -- in Decimal form
		var Pa = 0.0;		// result of the Pa Formula

		//----------------------------------------------------
		function debug() {
			var val;
			val = "D = " + D;
			val = "T = " + document.calculator.term.options[document.calculator.term.selectedIndex].value;
			document.calculator.debug1.value = val;
		}

		//----------------------------------------------------
		function getVars(cf) {
			if (cf == "monthly")
				f = document.M_calculator;
			else if (cf == "payment")
				f = document.P_calculator;

			P = parseFloat(f.price.value);
			M = parseFloat(f.monthlypayment.value);
			D = parseFloat(f.downpayment.value);
			T = parseFloat(f.term.options[f.term.selectedIndex].value);
			R = parseFloat(f.rate.value / 100);
		}

		//----------------------------------------------------
		function calcPa(cf) {
			// formula is Pa = 1-(1+r)^-n / r
			// r = R/12;

			getVars(cf);
			var r = R / 12;
			Pa = (1 - Math.pow(1+r, -T)) / r;
		}

		//----------------------------------------------------
		function strip (val) {

			var dollarpos = val.indexOf('$');
		  	var str;

			// strip out the '$'
			if (dollarpos != -1) {
				str = val.substring(dollarpos+1);
			} else {
				str = val;
			}

			if (isNaN(str))
				str = "0.00";

			return str;
		}

		//----------------------------------------------------
		function prettyPrintCash(val) {
		  // requires that val has no more than 2 decimal places
		  // ensures that val _leaves_ with 2 decimal places

			var decpos = val.indexOf (".");
		  	var endpos = val.length;

			// is more than three decimal places, make it 2 then check again.
			if (endpos - decpos > 3) {
				val = 100 * val;
				val = Math.floor(val);
				val = val / 100;
			}

			// back to String
			val = "" + val;

			decpos = val.indexOf(".");

		  	if (decpos == -1) {                           // no decimal found
				val = val + ".00";
		  	} else if (endpos-decpos == 2) {                     // only one decimal found
			 	val = val + "0";
		  	}

			return val;
		}

		//----------------------------------------------------
		function printCash(field, cf) {

			var e;
			var val;

			if (cf == "monthly") {
				e = document.M_calculator.elements[field];
			} else {
				e = document.P_calculator.elements[field];
			}

			if (isNaN(e.value)){
				value = strip (e.value);
			} else {
				value = e.value;
			}

			e.value = prettyPrintCash(value);
		}

		//----------------------------------------------------
		function prettyPrintPercent(field, cf) {
			var e;
			if (cf == "monthly") {
				e = document.M_calculator.elements[field];
			} else {
				e = document.P_calculator.elements[field];
			}

			var val = "" + e.value;
			var percpos = val.indexOf('%');

			//strip everything away after the %
			if (percpos != -1)
				val = e.value.substring(0,percpos);

			e.value = val;
		}

		//----------------------------------------------------
		function CalcPrice() {
			//calcPa("payment");
			getVars("payment");
			//var result = (Pa * M) + D;
			var result = (M*T)/(1+(R*T/12)) + D
			
			if(!isNaN(result)){
				document.P_calculator.price.value = prettyPrintCash(""+result);
			}else{
				alert('Please fill in all the fields.');
			}
		}

		//----------------------------------------------------
		function CalcMonthlyPayment() {
			//calcPa("monthly");
			getVars("monthly");
			//var result = (P-D) / Pa;
			var result = (((P-D)*R*T/12)+(P-D))/T
			if(!isNaN(result)){
				document.M_calculator.monthlypayment.value = prettyPrintCash(""+result);
			}else{
				alert('Please fill in all the fields.');
			}
		}

//sunny
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function formatCurrencyShort(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num );
}

function disp_rate(rate, big_star)
{ 
	var rating = parseFloat(rate);
	var total=5; var bal=0;
	var converted = parseFloat(rating); // Make sure we have a number 
	var decimal = (converted - parseInt(converted, 10)); 
	
	var blue_star = new Array("img/stars/0qtr_star.gif","img/stars/2qtr_star.gif","img/stars/full_star.gif");
	var gold_star = new Array("js/spry/rating/SpryStarEmpty.png","js/spry/rating/SpryStarHalf.png","js/spry/rating/SpryStarFull.png");
	var red_star = new Array("img/stars/0qtr_red_star.gif","img/stars/2qtr_red_star.gif","img/stars/full_red_star.gif");
	
	var wh_star=new Array();
	var msg = "<span><span style=\"white-space: nowrap;\">";		
	var img_tag_st="<img src=\"";
	var img_tag_end="\" alt=\"*\" class=\"img_rating\"/>" + "\n";
	if (isNaN(rating)) rating=0;
	if (big_star==true) { wh_star = red_star; img_tag_end="\" alt=\"*\" class=\"img_rating_bg\"/>" + "\n";
	} else wh_star = blue_star;
	for (var x = 1; x <= rating; x++)
	   msg = msg + img_tag_st + wh_star[2] + img_tag_end; // full star
	
	if (decimal>=0.5 && decimal<1) {
	   msg = msg + img_tag_st + wh_star[1] + img_tag_end; // half star
	} else if (decimal>0) {msg = msg + img_tag_st + wh_star[0] + img_tag_end;}
	
	bal=parseInt((total-rating), 10);
	for (var x = 1; x <= bal; x++)
	   msg = msg + img_tag_st + wh_star[0] + img_tag_end; // empty star
	
	msg = msg + "</span></span>";	 
	return msg;
}  

function stripHTML(oldString)
{
  return oldString.replace(/<[^>]*>/g, "");
}

function stringInsertBR(oldString)
{
  return oldString.replace(/\n/g, "<br>");
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function Calc_Installment(interest_rate, downpayment_percent, loan_period, sp_otr_price)
   { 
   	 var int_rate=(interest_rate/100);
	 var sp_downpayment = parseFloat(sp_otr_price * downpayment_percent);
	 var sp_inst = Math.floor((((sp_otr_price-sp_downpayment)*loan_period*int_rate) + (sp_otr_price-sp_downpayment))/(loan_period*12));
     return formatCurrency(parseFloat(sp_inst) );
   }      


//-->
//-->// JavaScript OTHER	
//-->// JavaScript Document
