function switchRange()
{
	if(document.getElementById('sale_type').value==2)
	{
		document.getElementById('min_price_range').innerHTML = "" +
		"<select name='price_min' id='prices' style='width: 100px; font-size: 11px; border: 1px solid #003399' >" +
			"<option value='1'>&pound;1 pcm</option>" +
			"<option value='1000'>&pound;1,000 pcm</option>" +
			"<option value='1500'>&pound;1,500 pcm</option>" +
			"<option value='2000'>&pound;2,000 pcm</option>" +
			"<option value='2500'>&pound;2,500 pcm</option>" +
		"</select>";
		document.getElementById('price_range').innerHTML = "" +
		"<select name='price_max' id='prices' style='width: 100px; font-size: 11px; border: 1px solid #003399' >" +
			"<option value='1000'>&pound;1,000 pcm</option>" +
			"<option value='1500'>&pound;1,500 pcm</option>" +
			"<option value='2000'>&pound;2,000 pcm</option>" +
			"<option value='2500'>&pound;2,500 pcm</option>" +
			"<option value='10000'>&pound;1,500 + pcm</option>" +
		"</select>";
	} else {
		document.getElementById('min_price_range').innerHTML = "" +
		"<select name='price_min' id='prices' style='width: 100px; font-size: 11px; border: 1px solid #003399' >" +
			"<option value='1'>&pound;1</option>" +
			"<option value='275000'>&pound;275,000</option>" +
			"<option value='550000'>&pound;550,000</option>" +
			"<option value='750000'>&pound;750,000</option>" +
			"<option value='1250000'>&pound;1,250,000</option>" +
		"</select>";
		document.getElementById('price_range').innerHTML = "" +
		"<select name='price_max' id='prices' style='width: 100px; font-size: 11px; border: 1px solid #003399' >" +
			"<option value='275000'>&pound;275,000</option>" +
			"<option value='550000'>&pound;550,000</option>" +
			"<option value='750000'>&pound;750,000</option>" +
			"<option value='1250000'>&pound;1,250,000</option>" +
			"<option value='10000000'>&pound;1,250,000 +</option>" +
		"</select>";
	}
}

function atocurr( x ) {

	var num, decnum, decstr, retval;
	
	x = "" + eval( x );
	
	num = parseInt( x );
	
	if( isNaN( num ) ) num = 0;
	
	decnum = Math.abs( parseFloat( x ) - num );
	
	if( isNaN( decnum ) ) decnum = .0;
	
	decnum *= 100;
	
	decstr = "" + Math.abs( Math.round( decnum ) );
	
	while( decstr.length < 2 ) {
	
		decstr = "0" + decstr;
	
	}
	
	retval =  num + "." + decstr ;
	
	while( retval.length < 10 ) {
	
		retval = " " + retval;
	
	}
	
	return retval;
	
}

function atof( x ) {

	if ( isNaN( parseFloat( x ) ) ) {
	
		return 0;
	
	} else {
	
		return parseFloat( x );
	
	}
	
}

  
function trim(strText) {
	
	while (strText.substring(0,1) == ' '){
		strText = strText.substring(1, strText.length);
	}
    while (strText.substring(strText.length-1,strText.length) == ' '){
		strText = strText.substring(0, strText.length-1);}
	return strText;
	
} 

function recalctotal( ) {

	var p = atof( document.myform["mortamount"].value );
	
	var	r = atof( document.myform["intrate"].value );
	
	var n = atof( document.myform["mortterm"].value );
	
	var i = .0;

//	if ( document.myform.repaymethod[0].checked )	{

	if (document.myform.repaymethod.value != "na" && document.myform["mortamount"].value != "" && document.myform["intrate"].value != "" && document.myform["mortterm"].value != "")	{
		
		if (document.myform.repaymethod.value == "capnint") {
			
			i =  p * Math.pow( (1 + (r / 100)),n) * (r / 100) * ( 1 / ( Math.pow( 1 + (r / 100), n) -1) ) * ( 1 / 12);
			
		} else	{
	
			i = r * p / 1200;
			
		}
		
		document.myform["repayment"].value = trim(atocurr(i));
		
	}
	
}

function mortgagerecalc( ) {

	var p = atof( document.myform["mortamount"].value );
	
	var	r = atof( document.myform["intrate"].value );
	
	var n = atof( document.myform["mortterm"].value );
	
	var i = .0;
	var ri = .0;

//	if ( document.myform.repaymethod[0].checked )	{

	if (document.myform["mortamount"].value != "" && document.myform["intrate"].value != "" && document.myform["mortterm"].value != "")	{
			
		i =  p * Math.pow( (1 + (r / 100)),n) * (r / 100) * ( 1 / ( Math.pow( 1 + (r / 100), n) -1) ) * ( 1 / 12);
	
		ri = r * p / 1200;
		
		document.getElementById("interest_payment").innerHTML = "&pound;" + trim(atocurr(i)) + " pcm";
		document.getElementById("repayment_payment").innerHTML= "&pound;" + trim(atocurr(ri)) + " pcm";
	}
	
}

rate = 7;

amount = 0;

term = 25;

intonly = 0;

queryString = document.location.search.substring(1);

queryArray = queryString.split("&");

for (i=0; i < queryArray.length; i++) {

	pairSplit = queryArray[i].indexOf("=");

	if (pairSplit != -1) {
	
		pairKey = queryArray[i].substring(0,pairSplit);
		
		pairValue = queryArray[i].substring(pairSplit+1);
		
		pairEval = pairKey + "=\"" + pairValue + "\"";
		
		eval(pairEval);
	
	}

}

function getinterest(a) {

	var p = a;
	
	var	r = 5;
	
	var n = 25;
	
	var i = .0;
			
	i =  p * Math.pow( (1 + (r / 100)),n) * (r / 100) * ( 1 / ( Math.pow( 1 + (r / 100), n) -1) ) * ( 1 / 12);
		
	return	trim(atocurr(i));
	
}



function swap_image(image_name) {

	var image_source = 'images/properties/original/' + image_name + '.jpg';

	document.getElementById("preview").src = image_source;

}

function admin(act, id) {
	
	window.open('/admin/?act=' + act + '&id=' + id, null, "height=450,width=445,scrollbars=yes,left=150,top=150");	
	
}

function admin_del(act, id, pid) {
	
	if (confirm("Are you sure you wish to delete this " + act + "?") == true) {
	
		window.location = "?act=property&id=" + id + "&pid=" + pid + "&del=" + act;
	
	}
	
}

function admin_default_vt(id, pid) {
	
	if (confirm("Are you sure you wish to set this property as your home page virtual tour?") == true) {
	
		window.location = "?act=property&id=" + id + "&vt=" + pid;
	
	}
	
}

function close_admin() {
	
	window.opener.location = window.opener.location;
	window.close();

}

function load_item(id) {
	
	document.getElementById("slide_item").style.display = 'none';
	document.getElementById("virtual_item").style.display = 'none';
	document.getElementById("floor_item").style.display = 'none';
	document.getElementById("calculator_item").style.display = 'none';
	document.getElementById("local_item").style.display = 'none';
	document.getElementById("mobile_item").style.display = 'none';
	document.getElementById("hip_item").style.display = 'none';
	
	document.getElementById(id + "_item").style.display = '';
	
}

function coming_soon() {

	alert("Feature Offline: Coming Soon");
	
}

$px_count = 0

$speed = 1;

$width = 0;
$height = 0;

$scroll_cleared = false;

function scroll_div(direction) {

	if (direction == 'right') {
	
		$px_count = $px_count + $speed;
	
	} else if (direction == 'left') {
	
		$px_count = $px_count - $speed;
	
	} else {
	
		return false;
	
	}
	
	if (($px_count + 450) > $width) {
			
		$px_count = $width - 450;
				
		document.getElementById('pan').style.left = '-' + $px_count + 'px';
		
		$scroll_cleared = true;
		
		return false;
		
	
	}
	
	if ($px_count < 0) {
	
		$px_count = 0;
	
		document.getElementById('pan').style.left = '-' + $px_count + 'px';
		
		$scroll_cleared = true;
		
		return false;
	
	}
	
	document.getElementById('pan').style.left = '-' + $px_count + 'px';
		
	$timer = setTimeout('scroll_div(\'' + direction +'\')', 1);
	
	return true;
	
		
}

function scroll_stop() {

	if ($scroll_cleared == true) {
	
		$scroll_cleared = false;
	
	} else {
		
		clearTimeout($timer);
	
	}
		
}

function scroll_speed() { 
	
	$speed = $speed * 2;
	
	if ($speed > 8) {
	
		$speed = 1;
	
	}
	
	document.getElementById('speed').innerHTML = 'Speed: ' + $speed + 'x';

}

function load_360 (width, height) {

	$width = width;
	
	$height = height;

	//document.getElementById('pan').style.top = '-' + (Math.round($height / 2) - 100) + 'px';
	document.getElementById('pan').style.left = '-' + (Math.round($width / 2)) + 'px';
	
	$px_count = Math.round($width / 2)
	
	document.getElementById('loading').style.display = 'none';
	document.getElementById('pan').style.display = '';

}

function copy_url(url) {

	window.open('/copy_url.php/?url=' + url + '&id=' + id, null, "height=150,width=400,scrollbars=no,left=150,top=150");
	
}