function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1,width=700,height=500,left = 320,top = 272');");
}

function newWindow(mypage,w,h){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1';
	day = new Date();
	id = day.getTime();
	win=window.open(mypage,id,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function changepic(imgFile) {
	document.image_main.src = imgFile;
}

$(function(){															// On document-ready
	$('form.ajaxform').ajaxSubmit();									// Ajaxify forms
	$("div.formMessage").html($("div.formMessage").html() + "<div class=\"close\"><a href=\"javascript:void(0);\" onclick=\"$('div.formMessage').fadeOut('normal');\">X</a></div>");
});

$.fn.ajaxSubmit = function(e) {		
	/* Change a form's submission type to ajax */
	this.submit(function(){
						 
	var params = {};
	$(this)
	.find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
	.filter(":enabled")
	.each(function() {
	  params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
	});
	$("body").addClass("curWait");
	
		$.post(this.getAttribute("action") + "&call=ajax", params, function(xml){
			$("body").removeClass("curWait");
			strError = "Unable to submit form. Please try again later.";
			oFocus = null;
			$("AjaxResponse", xml).each(function() {
				//strRedirect = this.getAttribute("redirecturl");
				strError = this.getAttribute("error");
				strMessage = this.getAttribute("message");
				oFocus = this.getAttribute("focus");
			});
			
			if (strError.length == 0) {
				$("div.formErrors").hide();
				$("div.formMessage").html("<h5>Success!<\/h5><div class=\"close\"><a href=\"javascript:void(0);\" onclick=\"$('div.formMessage').fadeOut('normal');\">X</a></div><p>" + strMessage + "<\/p>").filter(":hidden").fadeIn("normal");
			} else {
				$("div.formMessage").hide();
				$("div.formErrors").html("<h5>Error<\/h5><div class=\"close\"><a href=\"javascript:void(0);\" onclick=\"$('div.formErrors').fadeOut('normal');\">X</a></div><ul>" + strError.replace(/(\t)(.+)/g, "<li>$2<\/li>") + "<\/ul>").filter(":hidden").fadeIn("normal");
				if (oFocus) $("#" + oFocus).get(0).focus();
			}
		});
		return false;
	});	
	return this;
}

function startSearch(new_order) {
	if( $('#quick_search').length > 0 ){
		$("#order_by").attr("value",new_order);	
		$("#quick_search").submit();
	}
}

function setRef(ref_no) {
	if( $('#quick_search').length > 0 ){
		$("#propertyref").attr("value",ref_no);
	}
}
	
function orderRental(new_order) {
	window.location = "rental_hamilton.php?order_by="+new_order;	
}