function paymentEvent(){
	if (isNaN(document.Search_By_Payment.Desired_Payment.value) || (document.Search_By_Payment.Desired_Payment.value==''))
		document.Search_By_Payment.Desired_Payment.value="0";
	else
		document.Search_By_Payment.Desired_Payment_results.value=document.Search_By_Payment.Desired_Payment.value;
	if (isNaN(document.Search_By_Payment.APR.value))
		document.Search_By_Payment.APR.value="0";
	if (document.Search_By_Payment.APR.value=='')
		document.Search_By_Payment.APR.value='0';
	if (isNaN(document.Search_By_Payment.sales_tax.value))
		document.Search_By_Payment.sales_tax.value="0";
	if (document.Search_By_Payment.sales_tax.value=='')
		document.Search_By_Payment.sales_tax.value='0';
	if (isNaN(document.Search_By_Payment.Loan_Term.value) || (document.Search_By_Payment.Loan_Term.value==''))
		document.Search_By_Payment.Loan_Term.value="0";
	else
		document.Search_By_Payment.Loan_Term_results.value=document.Search_By_Payment.Loan_Term.value;
		
var yint = document.Search_By_Payment.APR.value;
var mint = yint / 100 / 12;
var pmt = document.Search_By_Payment.Desired_Payment.value;
var down_pmt = document.Search_By_Payment.Down_Payment.value;
var n = document.Search_By_Payment.Loan_Term.value;
var tax = document.Search_By_Payment.sales_tax.value;
if(mint == 0)
	pv = (pmt * n) - (pmt * n * (0.01 * tax));
else
	pv = ((pmt) / (mint / (1 - (1 / Math.pow(1 + mint, n))))) - (pmt * (.01 * tax));
pv = parseInt(pv)+parseInt(down_pmt);
document.Search_By_Payment.Total_Payment.value=pv;
}

function Search_by_Payment(){
	paymentEvent();
	var total_payment=document.Search_By_Payment.Total_Payment.value;
	if (total_payment == 0){
		alert("Please enter your desired monthly payment amount.");
	}
	else{
		Search_By_Payment.action="inventory_action.cfm";
		Search_By_Payment.submit();
	}
}

function show_advanced(){
	document.all.advanced_search.style.display="block";
	document.all.advanced_div.style.display="none";
	document.all.basic_div.style.display="block";
	document.all.Search_Mode.value="Advanced";
}

function show_basic(){
	document.all.advanced_search.style.display="none";
	document.all.advanced_div.style.display="block";
	document.all.basic_div.style.display="none";
	document.all.Search_Mode.value="Basic";
}

function submit_search(){
	Vehicle_Search.target="_self";
	Vehicle_Search.action="index.cfm";
	Vehicle_Search.submit();
}

function turn_page(offset){
	Vehicle_Search.target="_self";
	Vehicle_Search.action="index.cfm?start_row="+offset;
	Vehicle_Search.submit();
}

var allowclicks = 1;

function view_vehicle_details(inventory_id){
	if (allowclicks==1){
		Vehicle_Search.target="_blank";
		Vehicle_Search.action="vehicle_details.cfm?inventory_id="+inventory_id;
		Vehicle_Search.submit();
	}
	else{
		alert("Please Submit or Cancel the Form you have open before attempting to take another action.");
	}
}

function OpenNewPage(url, width, height, e){
	if (allowclicks==1){
		window.open(url, "_new", "status=1,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height);
	}
	else{
		alert("Please Submit or Cancel the Form you have open before attempting to take another action.");
	}
}

function change_sort(){
	var sort=Sort_Form.Sort_By.value;
	Vehicle_Search.target="_self";
	Vehicle_Search.action="index.cfm?sort_by="+sort;
	Vehicle_Search.submit();
}

function change_location(dealercode,nu){
	var this_location=Vehicle_Search.Location_ID.value;
	location.href="index.cfm?Dealercode="+dealercode+"&New_Used="+nu+"&Search_Mode=Advanced&Location_ID="+this_location
}

function show_photo(div_id,photo_id,imageurl,slideshow_id) {
	var show_photo = document.getElementById(div_id).style;
	var this_photo = document.getElementById(photo_id);
	var this_slideshow = document.getElementById(slideshow_id);
	if (allowclicks == 1 && this_slideshow.src != "http://showroom.worlddealer.net/Photos/Inventory/coming_soon_115.jpg"){
		this_photo.src=imageurl;
		show_photo.display="block";
	}
}

function hide_photo(div_id) {
	var hide_photo = document.getElementById(div_id).style;
	hide_photo.display="none";
}

function show_form(div_id) {
	var showform = document.getElementById(div_id).style;
	if (allowclicks==1){
		showform.display="block";
		allowclicks = 0;
		}
	else{
		alert("Please Submit or Cancel the Form you have open before attempting to fill out a Form for another vehicle.");
	}
}

function hide_form(div_id) {
	var hideform = document.getElementById(div_id).style;
	hideform.display="none";
	allowclicks = 1;
}

function submit_quick_quote(quote_form){
	var themessage = "There was an error in your information request:\n ";
	if (quote_form.First_Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your First Name.";
	}
	if (quote_form.Last_Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your Last Name.";
	}
	if (echeck(quote_form.Email.value)==false){
		themessage = themessage + "\n- Email is Invalid.";
	}
	if (quote_form.Phone_1.value.length != 3 || quote_form.Phone_2.value.length != 3 || quote_form.Phone_3.value.length != 4) {
		themessage = themessage + "\n- Phone is invalid.";
	}
	if (themessage == "There was an error in your information request:\n ") {
		quote_form.submit();
	}
	else {
		alert(themessage);
   		}
}

function submit_email_seller(){
	var themessage = "There was an error in your information request:\n ";
	if (email_seller_form.First_Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your First Name.";
	}
	if (email_seller_form.Last_Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your Last Name.";
	}
	if (echeck(email_seller_form.Email.value)==false){
		themessage = themessage + "\n- Email is Invalid.";
	}
	if (email_seller_form.Phone_1.value.length != 3 || email_seller_form.Phone_2.value.length != 3 || email_seller_form.Phone_3.value.length != 4) {
		themessage = themessage + "\n- Phone is invalid.";
	}
	if (themessage == "There was an error in your information request:\n ") {
		email_seller_form.submit();
	}
	else {
		alert(themessage);
   		}
}

function submit_make_offer(){
	var themessage = "There was an error in your information request:\n ";
	if (make_offer_form.Offer.value.length == 0){
		themessage = themessage + "\n- Please Enter Your Offer.";
	}
	if (make_offer_form.First_Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your First Name.";
	}
	if (make_offer_form.Last_Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your Last Name.";
	}
	if (echeck(make_offer_form.Email.value)==false){
		themessage = themessage + "\n- Email is Invalid.";
	}
	if (make_offer_form.Phone_1.value.length != 3 || make_offer_form.Phone_2.value.length != 3 || make_offer_form.Phone_3.value.length != 4) {
		themessage = themessage + "\n- Phone is invalid.";
	}
	if (themessage == "There was an error in your information request:\n ") {
		make_offer_form.submit();
	}
	else {
		alert(themessage);
   		}
}

function submit_email_friend(){
	var themessage = "There was an error in your information request:\n ";
	if (send_friend_form.Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your Name.";
	}
	if (echeck(send_friend_form.Email.value)==false){
		themessage = themessage + "\n- Email is Invalid.";
	}
	if (send_friend_form.Friend_Name.value.length == 0){
		themessage = themessage + "\n- Please Enter Your Friend's Name.";
	}
	if (echeck(send_friend_form.Friend_Email.value)==false){
		themessage = themessage + "\n- Your Friend's Email is Invalid.";
	}
	if (themessage == "There was an error in your information request:\n ") {
		send_friend_form.submit();
	}
	else {
		alert(themessage);
   		}
}

function change_inventory_type() {
	Sort_Form.action="inventory_action.cfm?page_action=change_inv_type";
	Sort_Form.submit();
}

function HighlightRow(row) {
	row.className = 'inventory_row_div_over'; 
}
	
function DelightRow(row){
	row.className = 'inventory_row_div'; 
}

function doCalculate() {
	validateInput(calc.price,calc)
}

function validateInput(input,calc) {

        if(input.value == ''){
            alert('This field requires numeric data');
            input.value=input.defaultValue;
        	 }

        if(input.value > 9999999 || input.value < 0) {
            alert('Value out of bounds');
            input.value=input.defaultValue;
        	 }

        // status = '';
        // msg = "This field requires numeric data: " + input.value;
        var str = input.value;

        var str = input.value;
        if (isNaN(str)) {
            var straray = str.split(',');
            if (straray[1]) { 
                str = straray[0].concat(straray[1]);    
            }
   
            if (straray[2]) { 
                str = str.concat(straray[2]);   
            } 
  
            if (str.substr(0, 1) == "$") {
                str = str.substr(1, str.length);
            }

            if (str.substr((str.length - 1), str.length) == "%") {
                str = str.substr(0, (str.length - 1));
            }

            input.value = str;
            if(isNaN(input.value)) {
                alert('This field requires numeric data');
                input.value=input.defaultValue;   
                }

        } //if

        add_input(calc);
} //validate input


function add_input(calc) {
        var total_cost;
        total_cost = (calc.price.value * 1 - calc.down_payment.value);

	var b = calc.rate.value;
	if(b == 0){
		
        calc.out_36.value = Math.round(total_cost/36);
        calc.out_48.value = Math.round(total_cost/48);
        calc.out_60.value = Math.round(total_cost/60);
        calc.out_72.value = Math.round(total_cost/72);
	}

	else{
        var i = calc.rate.value;
        i = i / 100.0;
        i /= 12;


        var pow36 = 1;
        for (var j = 0; j < 36; j++) {
            pow36 = pow36 * (1 + i);
        	 }
        var pow48 = 1;
        for (var j = 0; j < 48; j++) {
            pow48 = pow48 * (1 + i);
        	 }
        var pow60 = 1;
        for (var j = 0; j < 60; j++) {
            pow60 = pow60 * (1 + i);
        	 }
        var pow72 = 1;
        for (var j = 0; j < 72; j++) {
            pow72 = pow72 * (1 + i);
        	 }
    


        calc.out_36.value = Math.round((total_cost * pow36 * i) / (pow36 - 1));
        calc.out_48.value = Math.round((total_cost * pow48 * i) / (pow48 - 1));
        calc.out_60.value = Math.round((total_cost * pow60 * i) / (pow60 - 1));
        calc.out_72.value = Math.round((total_cost * pow72 * i) / (pow72 - 1));

		}


        return false;
}
function selectField(field) {
        field.select()
}

if (document.images)
{
var but1 = new Image();
but1.src = "tc_calculator_butt_on.gif";
}

var current_but = "sc_nav_1";

   function turnOn(button) {
      if (document.images)
           {
           document[button].src = button + "_on.gif";
           }}

   function turnOff(button) {
      if (document.images)
           {
           document[button].src = button + "_of.gif";
           }}

function Show_Email_Seller(){
	document.all.Email_Seller.src="images/default_theme/tab_email_seller.jpg";
	document.all.Make_Offer.src="images/default_theme/tab_make_offer_over.jpg";
	document.all.Email_Friend.src="images/default_theme/tab_send_friend_over.jpg";
	document.all.Calculator.src="images/default_theme/tab_calculator_over.jpg";
	document.all.Email_Seller_Div.style.display="block";
	document.all.Make_Offer_Div.style.display="none";
	document.all.Email_Friend_Div.style.display="none";
	document.all.Thank_You_Div.style.display="none";
	document.all.Calculator_Div.style.display="none";
}
function Show_Make_Offer(){
	document.all.Email_Seller.src="images/default_theme/tab_email_seller_over.jpg";
	document.all.Make_Offer.src="images/default_theme/tab_make_offer.jpg";
	document.all.Email_Friend.src="images/default_theme/tab_send_friend_over.jpg";
	document.all.Calculator.src="images/default_theme/tab_calculator_over.jpg";
	document.all.Email_Seller_Div.style.display="none";
	document.all.Make_Offer_Div.style.display="block";
	document.all.Email_Friend_Div.style.display="none";
	document.all.Thank_You_Div.style.display="none";
	document.all.Calculator_Div.style.display="none";
}
function Show_Email_Friend(){
	document.all.Email_Seller.src="images/default_theme/tab_email_seller_over.jpg";
	document.all.Make_Offer.src="images/default_theme/tab_make_offer_over.jpg";
	document.all.Email_Friend.src="images/default_theme/tab_send_friend.jpg";
	document.all.Calculator.src="images/default_theme/tab_calculator_over.jpg";
	document.all.Email_Seller_Div.style.display="none";
	document.all.Make_Offer_Div.style.display="none";
	document.all.Email_Friend_Div.style.display="block";
	document.all.Thank_You_Div.style.display="none";
	document.all.Calculator_Div.style.display="none";
}
function Show_Thank_You(){
	document.all.Email_Seller.src="images/default_theme/tab_email_seller_over.jpg";
	document.all.Make_Offer.src="images/default_theme/tab_make_offer_over.jpg";
	document.all.Email_Friend.src="images/default_theme/tab_send_friend_over.jpg";
	document.all.Calculator.src="images/default_theme/tab_calculator_over.jpg";
	document.all.Email_Seller_Div.style.display="none";
	document.all.Make_Offer_Div.style.display="none";
	document.all.Email_Friend_Div.style.display="none";
	document.all.Thank_You_Div.style.display="block";
	document.all.Calculator_Div.style.display="none";
}
function Show_Calculator(){
	document.all.Email_Seller.src="images/default_theme/tab_email_seller_over.jpg";
	document.all.Make_Offer.src="images/default_theme/tab_make_offer_over.jpg";
	document.all.Email_Friend.src="images/default_theme/tab_send_friend_over.jpg";
	document.all.Calculator.src="images/default_theme/tab_calculator.jpg";
	document.all.Email_Seller_Div.style.display="none";
	document.all.Make_Offer_Div.style.display="none";
	document.all.Email_Friend_Div.style.display="none";
	document.all.Thank_You_Div.style.display="none";
	document.all.Calculator_Div.style.display="block";
	doCalculate();
}

