function clearbox(val){
  var box_val=document.getElementById("message").value;
  //alert(box_val.length);
  if(box_val.length==val) { document.getElementById("message").value=''; }
}

function GetBoxValues(type) {
     
	 if(type=='models') {
	   document.getElementById("models").innerHTML ="<img src='images/loading.gif' /> Loading...";	 
	   JsHttpRequest.query(
            'query.php', // backend
            {
                
                'make': document.getElementById("make").value,  
                't': document.getElementById("t").value,
				'box': type
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
               // document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                if (result) {
                    document.getElementById("models").innerHTML =result["models"];
					document.getElementById("trims").innerHTML =result["trims"];
                }
            },
            true  // do not disable caching
        );
	 }
	 
	 if(type=='trims') {
        document.getElementById("trims").innerHTML ="<img src='images/loading.gif' /> Loading..."; 
	   JsHttpRequest.query(
            'query.php', // backend
            {
                
                'make': document.getElementById("make").value,  
                'model': document.getElementById("model").value,
				't': document.getElementById("t").value,
				'box': type
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
               // document.getElementById("debug").innerHTML = errors; 
			  // alert(errors);
                // Write the answer.
                if (result) {
                    document.getElementById("trims").innerHTML =result["trims"];
                }
            },
            true  // do not disable caching
        );
	 }
	 
    }

function popitup(url) {
	newwindow=window.open(url,'name','height=200,width=150');
	if (window.focus) {newwindow.focus()}
	return false;
}
				
function popOpen(page,width,height,scrollbars){
	if(width==""){ width=457;}
	if(height==""){ height=459;}
	window.open(page,"w","width="+width+", height="+height+", menubar=0, scrollbars="+scrollbars);	
}


function loanCalculator(rate,term,price,downp){
	msg="";
	if(isNaN(price)){ 
		msg+="\nPlease enter just numbers in the 'Vehicle Price' field";
	}
	if(downp!="" && isNaN(downp)){ 
	 	msg+="\nPlease enter just numbers in the 'Down Payment' field";
	 }else{
		if(downp==""){	downp=0; }
	 }
	if(msg!=""){
		alert(msg);
	}else{
		if(parseInt(downp)<parseInt(price)){
			document.getElementById('monthly').innerHTML='<h3><strong> $'+ Math.round(((((parseInt(price)-parseInt(downp))/parseInt(term))*(1+parseInt(rate)/100))/12)*100)/100 + ' / mo</strong></h3>';
		}else{
			document.getElementById('monthly').innerHTML='<h3><strong> 0 </strong></h3>';
			alert("There's no monthly payment with your down payment!");
		}
	}
	
}
function showCoupon(id){
	window.open('http://www.dealerfire.com/coupons/?DealerID='+id+'','','resizable=yes,width=766,height=620');
}


function goto(val){
	if(val!=""){
		window.open(val,"s","width=800, height=600, top=0, left=0, menubar=1, resizable=1, location=1, scrollbars=1");
	}
}

function expand_info(val){
	var pos = document.getElementById('expand_info').style.display;
	if(pos!="block"){
		document.getElementById('expand_info').style.display='block';
		document.getElementById('expand_lnk').innerHTML='Less Info';
	}else {
	    document.getElementById('expand_info').style.display='none';
		document.getElementById('expand_lnk').innerHTML='Expand Info';
	}
}
