/* ================================================================
This copyright notice must be kept untouched in the stylesheet at
all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/pro_drop_1.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any
way to fit your requirements.
=================================================================== */
stuHover = function() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var gElm = document.getElementById("header_menu");
	if(gElm){
		var getElm = document.getElementById("header_menu").getElementsByTagName("LI");
		for (var i=0; i<getElm.length; i++) {
			getElm[i].onmouseover=function() {
				this.className+=" iehover";
			}
			getElm[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);


toggleSearchText = function(toggle){
	var valText = "Search";
	var searchFld = $("#besearch_text");
	//check if has text already
	if(searchFld.val().length == 0 || searchFld.val()==valText){
		if(toggle)
			searchFld.val("");
		else searchFld.val(valText);
	}
}


checkSearchVal = function(){
	if($("#besearch_text").val() != "Postcode, Suburb or ID")
		$(".box_besearch_boxc form").submit();
	else alert("keyword is required for search.")
}

$(document).ready(function(){
	/*
	var show = true;
	$().mouseover(function(){
		if(show == true){
			$().ajaxSubmit({
				url: "checkSession.php?key=realtytech",
				type: "POST",
				timeout: 20000,
				beforeSubmit: function(){},
				error: function(xhr, desc, e) {},
				success: function(msg){
					//alert(msg);
					var msg_arr = msg.split("||");
					switch(msg_arr[0]){
						case "session":
							if(msg_arr[1] == "false"){
								show = false;
								$.blockUI({
									theme:     true,
									title:    'Session Expired',
									message:  'Your session has expired. Please <a href="http://'+ msg_arr[2] +'">log in</a> again.'
								});
							}
							break;
						case "allowlogin":
							if(msg_arr[1] == "false"){
								show = false;
								$.blockUI({
									theme:     true,
									title:    'Sorry',
									message:  'We are doing system maintenance. The system will be back as soon as possible. Please <a href="http://'+ msg_arr[2] +'">here</a> to go back to your website.'
								});
							}
							break;
						default:
							//alert(msg);
					}
				},
				complete: function(){}
			});
		}
	})
	*/
	$("#feedbackForm").validate({
		rules: {
			comment: { required: true }
		},
		messages: {
			comment: { required: "Please give us your comments." }
		},
		submitHandler: function() {
			$("#feedbackForm").ajaxSubmit({
				url: $("#feedbackForm").attr("action"),
				type: $("#feedbackForm").attr("method"),
				timeout: 20000,
				beforeSubmit: function(){
					$("#feedbackBox").dialog("close");
				},
				error: function(xhr, desc, e) {
					var msg = (desc == 'timeout') ? 'Connection 20 sec Time Out, Please try again Later.': desc;
					alert("Failed to send: " + msg);
					alert(xhr.responseText);
				},
				success: function(msg){
					if(msg){
						var msg_arr = msg.split("||");
						$("#sessionExpired").html(msg_arr[1]);
						$("#sessionExpired").dialog("open");
					}else{
						$('#feedbackForm').clearForm();
					}
				},
				complete: function(){}
			});
		}
	});
	
	$("#feedback img").click(function(){
		$("#feedbackBox").dialog("open");
	});

	$('#feedbackBox').dialog({
		autoOpen: false,
		width: 360,
		modal: true,
		zIndex: 3999,
		resizable: false,
		buttons: {
			"Cancel": function() {
				$(this).dialog("close");
			},
			"Submit": function() {
				$("#feedbackForm").submit();
			}
		}
	});
	
	$('#sessionExpired').dialog({
		autoOpen: false,
		width: 360,
		modal: true,
		zIndex: 3999,
		resizable: false,
		buttons: {
			"Ok": function() {
				$(location).attr('href', '/login');
			}
		}
	});
});