var document_fee = 335;

var current_site_path = 'http://stadiumcars.co.nz' ;

function refreshCaptcha()
{
	var img = document.images['captchaimg'];

	var q_str = img.src.substring(img.src.indexOf("&"));

	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000+q_str;
}
function validateFormWorth()
{
	if($("#phone").val() == '')
	{
		alert('Phone number must be filled out.');
		$("#phone").focus();
		return false;
	}
	if($("#captcha").val() == '')
	{
		alert('Verification code must be filled out');

    	$("#captcha").focus();	
		return false;
	}	
	return true;
}
//////To get finance Rate////////////////////
function finance_calc()
{
	var cal_price = 0;
	var finance_rate = $("#finance_rate").val();
	var finance_month = $("#finance_period").val();

	var price = $("#price").val();

	var sale_price = $("#sale").val();

	cal_price = (price == '')?cal_price = sale_price:cal_price = price;

	cal_price = parseFloat(cal_price) + document_fee;

	if((finance_rate != '') && (finance_rate > 0)  && (cal_price > document_fee))
	{

	  var monthly_price = (cal_price*((finance_rate/100)/12))/(1-Math.pow((1+(finance_rate/100)/12),-finance_month));

	  var weekly_payment = (monthly_price*12)/48;

	  var price_final = parseFloat(weekly_payment).toFixed(2);

	  var price_array = price_final.split('.');

	  $("#doller_price").html('$'+price_array[0]);

	  $("#cent_price").html('.'+price_array[1]);

	}

}
function finance_calculator()
{
	var cal_price = 0;	

	var deposits_trade = 0;		

	var finance_rate = $("#finance_rate").val();
	var finance_month = $("#term").val();

	var warranty = $("#warranty option:selected").val();


	var price = ($("#price").val() != '')?price = parseFloat($("#price").val())+parseFloat(warranty):price = 0;

	deposits_trade = $("#dip_trade").val();

	var cal_price = (price-deposits_trade)+document_fee;

	if(price == 0)
	{

		alert("Please enter price");
	}
	if((finance_rate != '') && (finance_rate > 0) && (cal_price > document_fee))
	{
    var monthly_price = ( cal_price *( ( finance_rate/100 )/12 ) )/( 1-Math.pow( (1+(finance_rate/100)/12),-finance_month));
	
    var weekly_payment = (monthly_price*12)/48;

    var price_final_weekly = parseFloat(weekly_payment).toFixed(2);

    var price_final_monthly = parseFloat(monthly_price).toFixed(2);

	  $("#payment_m").val(price_final_monthly);

	  $("#payment_w").val(price_final_weekly);

	}

}
function insert_sort(obj)
{
document.getElementById('srt').value=obj.value;

document.getElementById('search_form_new').submit();

}
function setupRemoveDefault() {

   var els = document.getElementsByTagName("input");



    for(var i=0,j=els.length; i<j; i++) {



     els[i].onclick = function () {removeDefault(this);}



    }    



}



function removeDefault(el) {



  if(el.name == 'model')



   {



		if((!el.rel || el.value == el.rel) && (el.type == "text" || el.type == "")) {     el.rel = el.value;



		 el.value = '';



		 var elName = el.id;



		 el.onblur = function () { if(!el.value) {addDefault(elName);}}



		 return true;



		}



    }

  }



function addDefault(elName) {

		var el = document.getElementById(elName);

		var searched_model = document.getElementById('searched_model').value;

		if(searched_model == '')



		{



		el.value = el.rel;



		}



		else



		{



		el.value = 'Model';



		}



   }



function submit_form()



 {



  $('#compare').submit();



 }



function save(list_id,list_location)



 {



var site_path = $('#site_path').val(); 



$.post(site_path+"/includes/common_ajax.php",{action:'list',list_id:list_id,location:list_location}, function(response){



       if(response)



	   {

		$('#div_saved_cart').html(response);



	   }



   });



 }

function img_delete(id,list_id)



{



var site_path = $('#site_path').val();	



$.post(site_path+"/includes/common_ajax.php",{action:'delete_record',list_id:list_id}, function(response){



       if(response)



	   {



		 $('#car_'+id).remove();



	   }

   });

}



function new_window(src, width, height) {

	window.open(src, '', "width=" + width + ",height=" + height + ",scrollbars=yes");

}
