var sSub="";
var sStr="";
var sWar="";
var sSta="";
var sChangeType="agent";
var sTimeCache = 14400;
var _d = (new Date()).getTime()+ sTimeCache;

function initForm(){				
	doLoadPropertyListing(1);				
}
function gotoPage(pg){				
	doLoadPropertyListing(pg);
}
function doLoadPropertyListing(pg){
	if(sChangeType=="raovat")	
		doLoadPropertyListingRV(1);			
	else
	{
		Element.show("loader");
		var act = "act=htr";
		if(sSub!="")			
			act = "act=htr&suburb="+sSub;					
		if(sStr!=""&&sSub!="")		
			act = "act=htr&street="+sStr+"&suburb="+sSub;
		if(sWar!="")		
			act = "act=htr&ward="+sWar;
		var page = "&maxpg=10&pindex="+pg;		
		var url = pathClientAjax+"handler/Misc.aspx?"+ act + page +nocacheAjax();	
		Element.setInnerHTML("DivPropertyList1", "");				
		Element.hide("dvPaging");
		new Ajax.Request(url, {   
			method: 'get',					
			onSuccess: function(transport) {
				Element.hide("loader");			
				Element.setInnerHTML("DivPropertyList1", transport.responseText);			
				var tps = (parseInt($("hTotalRows").value)/(10) - parseInt(parseInt($("hTotalRows").value)/(10)))>0?((parseInt(parseInt($("hTotalRows").value)/(10)))+1):parseInt(parseInt($("hTotalRows").value)/(10));
				mjDrawLbPage(tps, $("hCurrentPage").value, "dvPaging");
				},
			onFailure: function(e){ alert(e.responseText);
			}
			}
		)
	}
}
function mjRemoveListingHistory(id){
	Element.show("loader");
	var act = "&act=rmvhis";	
	var url = pathClientAjax+"handler/Misc.aspx?id="+ id + act + nocacheAjax();	
	Element.setInnerHTML("DivPropertyList1", "");
	Element.hide("dvPaging");
	new Ajax.Request(url, {   
		method: 'get',					
		onSuccess: function(transport) {
			doLoadPropertyListing(1);
			},
		onFailure: function(e){ alert(e.responseText);
		}
		}
	)
}
function mjRemoveListingHistoryRV(id){
	Element.show("loader");
	var act = "&act=rmvhis";	
	var url = pathClientAjax+"handler/Misc.aspx?id="+ id + act + nocacheAjax();	
	Element.setInnerHTML("DivPropertyList1", "");
	Element.hide("dvPaging");
	new Ajax.Request(url, {   
		method: 'get',					
		onSuccess: function(transport) {
			doLoadPropertyListingRV(1);
			},
		onFailure: function(e){ alert(e.responseText);
		}
		}
	)
}
function gotoPageRV(pg){				
	doLoadPropertyListingRV(pg);
}
function doLoadPropertyListingRV(pg){
	Element.show("loader");
	var act = "act=htrrv";
	if(sSub!="")		
		act = "act=htrrv&suburb="+sSub;
	if(sStr!=""&&sSub!="")		
		act = "act=htrrv&street="+sStr+"&suburb="+sSub;
	if(sWar!="")		
		act = "act=htrrv&ward="+sWar;
	var page = "&maxpg=10&pindex="+pg;		
	var url = pathClientAjax+"handler/Misc.aspx?"+ act + page +nocacheAjax();	
	Element.setInnerHTML("DivPropertyList1", "");				
	Element.hide("dvPaging");
	new Ajax.Request(url, {   
		method: 'get',					
		onSuccess: function(transport) {
			Element.hide("loader");			
			Element.setInnerHTML("DivPropertyList1", transport.responseText);			
			var tps = (parseInt($("hTotalRows").value)/(10) - parseInt(parseInt($("hTotalRows").value)/(10)))>0?((parseInt(parseInt($("hTotalRows").value)/(10)))+1):parseInt(parseInt($("hTotalRows").value)/(10));
			mjDrawLbPageNew(tps, $("hCurrentPage").value, "dvPaging","gotoPageRV");
			},
		onFailure: function(e){ alert(e.responseText);
		}
		}
	)
}
function DoSearchBySuburb(suburbID)
{	
	sSub=suburbID;
	sStr="";
	sWar="";
	sSta="";
	doLoadPropertyListing(1);
}
function FindByStreet(txt,sub)
{	
	sStr=txt;
	sSub=sub;
	sWar="";
	sSta="";
	doLoadPropertyListing(1);
}
function FindByWard(txt)
{	
	sWar=txt;
	sSub="";
	sStr="";
	sSta="";
	doLoadPropertyListing(1);
}
var TabOld="";
function GetDataForAgentOrUser(TabActive)
{		
	sStr="";
	sSub="";
	sWar="";
	sSta="";
	if(TabOld==TabActive) return;
	if(TabActive=="li1")
	{	
		
		$("li1").toggleClassName('active-tab');
		$("li2").removeClassName('active-tab');		
		sChangeType="agent";
		doLoadPropertyListing(1);
	}
	else 	
	{
		$("li2").toggleClassName('active-tab');
		$("li1").removeClassName('active-tab');		
		sChangeType="raovat";		
		doLoadPropertyListingRV(1);
	}
	TabOld=TabActive;	
}
Event.observe(window, 'load', initForm, false);
