// JavaScript Document

image1 		= new Image();
image1.src 	= "images/spacer.gif";

image2 		= new Image();
image2.src 	= "images/center_left_top.gif";

image3 		= new Image();
image3.src 	= "images/center_hor_top.gif";

image4 		= new Image();
image4.src 	= "images/center_right_top.gif";

image5 		= new Image();
image5.src 	= "images/center_ver_left.gif";

image6 		= new Image();
image6.src 	= "images/center_ver_right.gif";

image7 		= new Image();
image7.src 	= "images/center_left_bottom.gif";

image8 		= new Image();
image8.src 	= "images/center_hor_bottom.gif";

image9 		= new Image();
image9.src 	= "images/center_right_bottom.gif";


// JavaScript Document
function expand(name) {
	document.getElementById( name ).style.display = "block";
}



function collapse(name) {
	document.getElementById( name ).style.display = "none";
}



function change_color(el, bg1, bg2){
	for (i = 0; i < el.parentNode.childNodes.length; i++)
		if (el.parentNode.childNodes[i].tagName)
		el.parentNode.childNodes[i].style.backgroundImage=bg2
		el.style.backgroundImage=bg1
}



function preview_image(url, text){
	document.photo_img.src 								= url;
	document.getElementById("photo_text").innerHTML 	= text;
}



function print_page(listing) {
	var leftPos = (screen.availWidth-700) / 2;
	var topPos = (screen.availHeight-500) / 2;
	Press1Win = window.open('site_detail_print.php?listing=' + listing,'','width=700,height=500,scrollbars=yes,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
}



function slideshow(listing) {
	var leftPos = (screen.availWidth-700) / 2;
	var topPos = (screen.availHeight-600) / 2;
	Press1Win = window.open('site_detail_slideshow.php?listing=' + listing,'','width=700,height=600,scrollbars=yes,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
}



function open_subscription(listing) {
	var leftPos = (screen.availWidth-350) / 2;
	var topPos = (screen.availHeight-300) / 2;
	Press1Win = window.open('site_detail_calculator.php?listing=' + listing,'','width=350,height=300,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
}



function open_calculator(listing) {
	var leftPos = (screen.availWidth-350) / 2;
	var topPos = (screen.availHeight-300) / 2;
	Press1Win = window.open('site_detail_calculator.php?listing=' + listing,'','width=350,height=300,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
}



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 (num + '.' + cents);
	
}



function format_number(val) {

	val	= val.replace(/,/g , "");
	return parseFloat(val); 

}



function calculate_mortgage(form) {

	var amount 	= format_number(form.loan_price.value);
	var amount2	= format_number(form.loan_price.value);
	var down 	= format_number(form.loan_down.value);
	var rate 	= format_number(form.loan_interest.value) / 100;
	var term 	= format_number(form.loan_years.value) * 12;
	var payment = 0;
	
	amount		= amount - down;
	payment 	= amount * (rate / 12) / (1 - Math.pow ((1 + rate/12), -term));
	payment 	= Math.round (100 * payment) / 100;
	
	form.loan_price.value 	= formatCurrency(amount2);
	form.loan_down.value 	= formatCurrency(down);
	form.loan_monthly.value = formatCurrency(payment);
	
}