function open_tag(tag){
	tag.style.display="inline";
  p_arrow=document.getElementById("p"+tag.id);
  if(p_arrow) p_arrow.className="arrow-open"; 
}
function close_tag(tag){
	tag.style.display="none";
  p_arrow=document.getElementById("p"+tag.id);
  if(p_arrow) p_arrow.className="arrow-close"; 
}
function ShowTab(tabname,tid,render_tab,onlyone){
 var allDivs=document.getElementsByTagName("div");
 var c=allDivs.length;
 if(render_tab){
 	 var mtb=document.getElementById(render_tab).childNodes;
 	 for(i=0;i<mtb.length;i++){
 	 	 if(mtb[i].id=="_"+tid)
 	 	   mtb[i].className="selected_tab";
 	 	 else mtb[i].className="";
 	 }
 }
 for(i=0;i<c;i++){
  if(allDivs[i].getAttribute("name")==tabname){
  	if(tid=='+'){//open all
  		open_tag(allDivs[i]);
  	}else if(tid=='-'){//close all
  		close_tag(allDivs[i]);
  	}else{
   		if(allDivs[i].id==tid){
   			if(!onlyone&&allDivs[i].style.display=="inline")//to be able close them on second click uncomment all
   			  close_tag(allDivs[i]);
   			else
   				open_tag(allDivs[i]);      	       	
   		}else{
   			if(!onlyone){
   				close_tag(allDivs[i]); 
   			}else{
   			  if(allDivs[i].style.display=="inline"||allDivs[i].style.display=='')
   			    close_tag(allDivs[i]);  
   			}			     						  
   		}
   	}
  }
 }
}
function SetPicture(img_addr,picn){
	PICNUMBER=picn;
	//	document.getElementById("largeimagep").href="show_largeimages.php?cid="+CID+"&picn="+picn;
	document.getElementById("mainpicture_plh").src=img_addr;
	scroll(0,100);
}
var current_tab="stockimages";
	function previewLarge(){
		var height = screen.height;
		var width = screen.width;
		var leftpos = (width / 2) - 350;
		var toppos = (height / 2) - 350;
		var prevwin=window.open("show_largeimages.php?cid="+CID+"&picn="+PICNUMBER,null,"location=no,menubar=no,toolbar=no,resizable=yes,width=500,height=400");
		prevwin.moveTo(leftpos,toppos);
		prevwin.focus();
	}
	function sendToFriend(carid){
    window.open("sendtofriend.php?cid="+carid,"_blank","directories=no,height=440,location=no,menubar=no,toolbar=no,width=600");
  }
  function openSticker(){
	var height = screen.height;
		var width = screen.width;
		var leftpos = (width / 2) - 350;
		var toppos = (height / 2) - 300;
		var prevwin=window.open("http://www-5.chrysler.com/vehsuite/dispatch.do?currentState=InventorySearchListResults&st=1%7C351C26BDFA96010CF7E5137938BE0200%7C1155581808254%7C4%7CChrysler%7Cen%24%7Ctrue%24InventorySearchListResults%7CSearchPageBasic%7Ctrue%7C0%24false%7Cfalse%7Cfalse%7C%7C%2436%5E-1%5E-1.0%5E-1%5Efalse%5E-1%5Efalse%5E-1%5Efalse%5E-1%5Efalse%5E-1.0%5E-1.0%5E-1.0%5E-1.0%5E0.0%7C60%5E-1.0%5E-1%5Efalse%5E-1%5Efalse%5E-1%5Efalse%5E-1.0%5E-1.0%5E-1.0%5E-1.0%5E-1.0%5E0.0%7C39%5E-1%5E-1.0%5E-1%5Efalse%5E-1%5Efalse%5E-1%5Efalse%5E-1%5Efalse%5E-1.0%5E-1.0%5E-1.0%5E-1.0%5E-1.0%5E0.0%7C-1.0%7C0.0%7C0.0%7CConventional%7C0.0%24false%7C%7C%24NjI1Mjk%3D%7C%7C%7C%7C%7C%7Ctrue%7Ctrue%7Cfalse%7Ctrue%7Cfalse%7Ctrue%7Cfalse%7Cinventory%7C%7C%24%7C%7Cfalse%7C%24%7C%23%23%23%23%23false%230.0%230.0%7C%7C%7C%7C-1%7C%23%23%23%23%23false%230.0%230.0%7C50%7C0%7Cany%7C%7C%7C62529%7C0%7C%7C%24%24null%7Cnull%7Cnull%242006300&&makeTransition=windowSticker&getWindowSticker=<?=$car->get_param('vin')?>&selectInventoryVehicle=lxch480.062DE^<?=$car->get_param('vin')?>^25265^EER^DGV^-D1^PPK^60641^2006300^0^23020",null,"location=yes,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=700,height=600");
		prevwin.moveTo(leftpos,toppos);
		prevwin.focus();
	}
	function openWinStick(){
		var height = screen.height;
		var width = screen.width;
		var leftpos = (width / 2) - 350;
		var toppos = (height / 2) - 300;
		var prevwin=window.open("inventory_pp.php?id="+CID,null,"location=yes,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=700,height=600");
		prevwin.moveTo(leftpos,toppos);
		prevwin.focus();
	}
	function open_stockTab(tabid){
  	if(current_tab!=tabid){
  		document.getElementById("stock_"+tabid).style.display="inline";
  		document.getElementById("stock_"+current_tab).style.display="none";
  		document.getElementById(tabid).id=tabid+"-selected";
  		document.getElementById(current_tab+"-selected").id=current_tab;
  		current_tab=tabid;
  		showFlash('',false);
  		if(tabid=="stockimages") document.getElementById("vli_link").style.display="inline";
  		else document.getElementById("vli_link").style.display="none";
  	}
  }
  function showFlash(file,doflash){
  	if(doflash){
  		document.getElementById("picture_placeholder").style.display="none";
  		document.getElementById("flash_placeholder").style.display="block";
  		document.getElementById("flash_placeholder").innerHTML='<object width="320" height="240" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#4,0,0,0"><param name="SRC" value="'+file+'"><param name="quality" value="high"><param name="play" value="true"><embed src="'+file+'" width="320" height="240" quality="high" type="application/x-shockwave-flash"></embed></object>';
  		
  	}else{
  		document.getElementById("picture_placeholder").style.display="block";
  		document.getElementById("flash_placeholder").style.display="none";
  		document.getElementById("flash_placeholder").innerHTML="";
  	}
  }
//-------------------------------------------------------------------------
// validate a user entered number.
function checkNumber(input,paymentcalculator)
{
        // blank field reset to default value.
        if (input.value=='') {
                input.value=input.defaultValue
        }

        // remove any user added commas
        input.value = strip_commas(input.value);

        // place a warning on the status line if the field contains invalid data
        status='';
        msg ="This field requires numeric data: " + input.value;
        var str = input.value;
        for (var i = 0; i < str.length; i++) {
                var ch = str.substring(i, i + 1)
                if ((ch < "0" || "9" < ch) && ch != '.') {
                        input.focus()
                        input.value="0";
                        input.select()
                        status=msg;
                }
        }
        add_input(input,paymentcalculator)
}

function add_input(input,paymentcalculator) {
        var total1;
        total1=(paymentcalculator.price.value*1)
        paymentcalculator.loan.value=(total1*1 -paymentcalculator.down_payment.value)
}

// Make a number a nice comma delimited number.
function put_commas(input) {
        var result, len;
        input += "";

        // Locate the decimal point if any.
        len = input.indexOf(".");
        if (len == -1) {
                len = input.length;
                result = "";
        } else {
                result = input.substring(len, input.length);
        }

        // 3 characters at a time through the integer portion.
        while (len > 3) {
                result = input.substring(len-3, len) + result;
                result = "," + result;
                len -= 3;
        }

        // Add any remaining characters.
        result = input.substring(0, len) + result;
        return result;
}

// Remove all commas from a passed string.
function strip_commas(input) {
        var newnum;
        var ch;
        newnum ="";
        for(var i=0; i<input.length; i++) {
                ch = input.charAt(i);
                if(ch != ",") {
                        newnum += ch;
                }
        }
        return parseFloat(newnum);
}

function checkNumPeriods(input) {
        input.value = strip_commas(input.value);
        input.value = parseFloat(input.value);
//        input.value = parseInt(input.value);
        if(input.value == null ||
         input.value.length == 0 ||
           input.value == "NaN") {
                input.value = "";
        }
        else {
                if(parseFloat(input.value) <= 0) {
                        input.value = "";
                }
        }
        calcMonthly(input.form);
        input.value = put_commas(input.value);
}

function checkTotal(input) {
        input.value = strip_commas(input.value);
        input.value = parseFloat(input.value);
        if(input.value == null ||
         input.value.length == 0 ||
           input.value == "NaN") {
                input.value = "";
        }
        else {
                if(parseFloat(input.value) < 0) {
                        input.value = "";
                }
        }
        calcMonthly(input.form);
        input.value = put_commas(input.value);
}

// Verify the interest rate is a reasonable number, or set it to one.
function checkInterest(input) {
        input.value = parseFloat(input.value);
        if (input.value == null ||
            input.value.length == 0 ||
            input.value == "NaN" ||
            input.value < 0 ||
            input.value > 100) {
                input.value = 8.9;
        }
        calcMonthly(input.form);
}

function calcMonthly(input) {
        if(input.interest.value == "" ||
           input.nper.value == "" ||
           input.loan.value == "") {
                input.monthly.value = "";
        }
        else {
                i = strip_commas(input.interest.value) / 100;
                if( i > 0){
                        i = i / 12;
                        n = strip_commas(input.nper.value);
                        tmp = (1/i) * (1 - Math.pow(1/(1+i), n));
                        tmp = strip_commas(input.loan.value) / tmp;
                        tmp = Math.round(tmp*100) / 100;
                        input.monthly.value = put_commas(tmp);
                        if(input.monthly.value == null ||
                         input.monthly.value.length == 0 ||
                           input.monthly.value == "NaN") {
                                input.total.value = "";
                        }
                } else {
                        nummonths  = strip_commas(input.nper.value);
                        loanamount = strip_commas(input.loan.value);

                        monthlypayment = Math.round((loanamount / nummonths)*100) / 100;
                        input.monthly.value = put_commas(monthlypayment);
                }

        }
}
function selectField(field)
{
        field.select()
}

// Reset the forms to default values.
function clearForm(paymentcalculator)
{
        paymentcalculator.down_payment.value = "0"
        paymentcalculator.loan.value = "0"
        paymentcalculator.interest.value = "8.9"
        paymentcalculator.nper.value = "48"
        paymentcalculator.monthly.value = "0"
 }