// JavaScript Document

function qsFocus() {
	lu = document.getElementById('id');
	if (lu.value == " ID number") {
	lu.value = "";
	}
}

function qsBlur() {
	lu = document.getElementById('id');
	if (lu.value == "") {
	lu.value = " ID number";
	}
}

function preloadImage(image_src, image_name) {
					
	this[image_name] = new Image();
	this[image_name].src = image_src;
	
};

function swapImage(target_image, image_src) {
	
	var tempTarget = document.getElementById(target_image);

	if (tempTarget.src != image_src) {
		
		tempTarget.src = image_src;
		
	}

};

function swapInfo(element_id, new_contents) {

	document.getElementById(element_id).innerHTML = new_contents;

};

function popup(url, name, width, height) {
	var properties = '';

	properties += 'toolbar=no,';
	properties += 'menubar=yes,';
	properties += 'scrollbars=yes,';
	properties += 'resizable=yes,';
	properties += 'status=no,';
	properties += 'location=no,';
	properties += 'directories=no,';
	properties += 'copyhistory=no,';
	properties += 'height=' + height + ',';
	properties += 'width=' + width;

	window.open(url, name, properties);
	
}

function swapPriceRanges() {

	var mylist = document.getElementById('type');
	
	var catVal = mylist.options[mylist.selectedIndex].value;
	
	if (catVal == 'sale') {
	
		var priceType = 's';
		
		var targetArr = saleArr;
	
	} else {
	
		var priceType = 'r';
		
		var targetArr = rentArr;
	
	}
	
	//Now dump the options for min and max price options into the visible.
	
	//Build the from options.
	
	var tempStr = '';
	
	for (var i=0; i<targetArr.length; i++) {
	
		tempStr += '<option value="' + targetArr[i][0] + '">' + targetArr[i][1] + '</option>';
	
	}
	
	//
	
	var targetFrom = document.getElementById('min_price_cell');
	
	targetFrom.innerHTML = '<select id="minimumPrice" name="minimumPrice">' + tempStr + '</select>';
	
	var targetTo = document.getElementById('max_price_cell');
	
	targetTo.innerHTML = '<select id="maximumPrice" name="maximumPrice">' + tempStr + '</select>';

}

function swapSection() {

	var mylist = document.getElementById('type');
	
	var catVal = mylist.options[mylist.selectedIndex].value;

	var tempTarget = document.getElementById('section');
	
	if (catVal == 'sale') {
		
		var val = 'buying';
		
	} else if (catVal == 'rent') {
		
		var val = 'renting';
		
	} else if (catVal == 'holiday') {
		
		var val = 'renting';
		
	}
	
	tempTarget.value = val;
	
}

function imgpopup(url, name, width, height) {
	var properties = '';

	properties += 'toolbar=no,';
	properties += 'menubar=yes,';
	properties += 'scrollbars=yes,';
	properties += 'resizable=yes,';
	properties += 'status=no,';
	properties += 'location=no,';
	properties += 'directories=no,';
	properties += 'copyhistory=no,';
	properties += 'height=' + height + ',';
	properties += 'width=' + width;

	window.open(url, name, properties);
	
}

//
//For the slideshow.
//

function slideTabs() {
	
	//swapImage('main_slideshow', tabsArray[0]);
	
	setInterval(stepTabs, 7000);
	
}

function stepTabs() {
	
	swapImage('main_slideshow', tabsArray[index]);
	
	if (index < (tabsArray.length - 1)) {
		
		index ++;
		
	} else {
		
		index = 0;
		
	}
	
}

//
//Quick emailer.
//

function timeOutAjax() {
	
	var ajaxResponse = $('ajaxResponse');
	
	ajaxResponse.className = 'hide';
	
}

function sendMail() {
	
	var ajaxResponse = $('ajaxResponse');
	
	var params = Form.serialize($('ajax_mail_f'));
	var obj = new Ajax.Updater('ajaxResponse', 'include.ajax_mail.php', {asynchronous:true, parameters:params, onComplete:function () {  setTimeout(timeOutAjax, 8000);  }});
	
}