// for handling history
//window.onload = initialize;

/*function initialize() {
	// initialize the DHTML History
	// framework
	//dhtmlHistory.initialize();

	// subscribe to DHTML history change
	// events
	//dhtmlHistory.addListener(historyChange);

	// set focus to logon form's username box.
	if( document.logon_form ) {
		document.logon_form.username.focus();
	}
}*/

function historyChange(newLocation, historyData) {
	if(!historyData){
		historyData=new Array();
		historyData['url']='index.php';
	}
	debug("A history change has occurred: "
		+ "newLocation="+newLocation
		+ ", url="+historyData["url"]
		+ ", handler="+historyData["handler"]
		+ ", body="+historyData["body"], false);
	loadXMLDoc(historyData["url"], historyData["handler"], historyData["body"], false);
}

/** Displays messages to the screen. */
function debug(msg, alertme) {
	if (alertme == true)
		alert(msg);
        else {
//		  alert("history changed");// do nothing
        }
}

////
function updateSearchSubmit(target) {
	if( target.value == "servicecall" ) {
		document.searchForm.page.value="ServiceCall.php";
	} else {
		document.searchForm.page.value="Page.php";
	}
}
function flux_rent(type) {
	dd=document.getElementById('rc_day');
	ww=document.getElementById('rc_week');
	mm=document.getElementById('rc_month');
	yy=document.getElementById('rc_year');
	var perday=0, perweek=0, permonth=0, peryear=0;
	switch(type) {
		case 1:
			rent = parseFloat(dd.value);
			break;
		case 2:
			rent = parseFloat(ww.value);
			break;
		case 3:
			rent = parseFloat(mm.value);
			break;
		case 4:
			rent = parseFloat(yy.value);
			break;
	}
	if(isNaN(rent)) {
		dd.value="";
		ww.value="";
		mm.value="";
		yy.value="";
		return false;
	}
	switch(type) {
		case 1:
			perday = rent;
			perweek = perday * 7;
			peryear = perday * 365;
			permonth = peryear / 12;
			ww.value = perweek.toFixed(2);
			mm.value = permonth.toFixed(2);
			yy.value = peryear.toFixed(2);
			break;
		case 2:
			perweek = rent;
			perday = perweek / 7;
			peryear = perday * 365;
			permonth = peryear / 12;
			dd.value = perday.toFixed(2);
			mm.value = permonth.toFixed(2);
			yy.value = peryear.toFixed(2);
			break;
		case 3:
			permonth = rent;
			peryear = permonth * 12;
			perday = peryear / 365;
			perweek = perday * 7;
			dd.value = perday.toFixed(2);
			ww.value = perweek.toFixed(2);
			yy.value = peryear.toFixed(2);
			break;
		case 4:
			peryear = rent;
			permonth = peryear / 12;
			perday = peryear / 365;
			perweek = perday * 7;
			dd.value = perday.toFixed(2);
			ww.value = perweek.toFixed(2);
			mm.value = permonth.toFixed(2);
			break;
	}
}

function preload() {}


	function fix_bottom(){
		$d = document.getElementById('flux-footer-container');
		if($d)
			$d.style.top = (window.innerHeight - 52);
	}
	function fix_position(id, top, left, height, width){
		e = document.getElementById(id);
		if(!e){ return; alert(id + ' not found'); return;}
		if(top)
			e.style.top = top+'px';
		if(left)
			e.style.left = left+'px';
		if(height)
			e.style.height = height+'px';
		if(width)
			e.style.width = width+'px';
	}
	var isRightHidden=false;
	function adjust_position(){
		size = getWindowSize();	
		if(isRightHidden) right=20;
		else right=200;
		fix_position('top-header', 0, 210, null, size[0] - 240);
		fix_position('menu-header', 50, 10, null, size[0] - 40);
		fix_position('footer', null, null, null, size[0] - 240);
		fix_position('footer-shaded', null, null, null, size[0] - 240);
		fix_position('main-container', null, 210, null, size[0] - 240);
		fix_position('pagemenu-container', null, null, 15, size[0] - right - 250);
		fix_position('content', null, 210, null, size[0] - right - 270);
		fix_position('fluxlet-right', null, size[0] - 230, null, right);
		fix_position('footer-shaded-div', null, null, null, right);
		fix_position('page-body', null, null, null, size[0] - right - 280);
		fix_position('page-title', null, null, null, size[0] - right- 280);
	}
	function getWindowSize(){
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		return new Array(myWidth, myHeight);
	}
	
	
	
	
	function showhide(div){
		a = document.getElementById(div+'_a');
		if(!a){ alert(div+'_a not found!'); return; }
		b = document.getElementById(div+'_b');
		if(!b){ alert(div+'_b not found!'); return; }
		subs = document.getElementById(div+'_body');
		if(!subs){ alert(div+'_body not found!'); return; }
		if(subs.style.display=='none'){
			a.style.display = '';
			b.style.display = 'none';
			subs.style.display = '';
			return;
		}
		a.style.display = 'none';
		b.style.display = '';
		subs.style.display = 'none';
	}
	function FluxHighlight(me, checkbox){
		if(checkbox.checked){
			me.className = '';
			checkbox.checked = false;
			return;
		}
		me.className = 'pHover';
		checkbox.checked = true;
		return;
	}
	function HighlightPageMenu(menu, theitem){
		try{
		d = document.getElementById(menu);
		if(!d) return;
		uls = d.getElementsByTagName('li');
		for(i in uls)
			if(uls[i].className != 'active')
				uls[i].oldclass= uls[i].className;
			else
				uls[i].className = uls[i].oldclass;
		
		a = document.getElementById(theitem);
		if(!a) return;
		a.className='active';
		}catch(e){alert(e)}
	}
	function ActivatePageMenu(menudiv, active){
		d = document.getElementById(menudiv);
		if(!d) return;
		uls = d.getElementsByTagName('ul');
		for(i in uls)
			if(uls[i].style)
				uls[i].style.display='none' ;
		
		a = document.getElementById(active);
		if(!a) return;
		a.style.display='';
	}

	function ActivateGlobalMenu(menudiv, active, pagemenu){
		d = document.getElementById(menudiv);
		if(!d) return true;
		divs = d.getElementsByTagName('div');
		// close all dropdown menu
		for(i=0; i<divs.length; i++){
			if(divs[i].className=='dropdown') 
				divs[i].style.display = 'none';
		}
		lis = d.getElementsByTagName('li');
		// deactivate all li
		for(i=0; i<lis.length; i++){
			if(lis[i].className=='active')
				lis[i].className='';
		}
		// get the link clicked
		a = document.getElementById(active);
		if(!a) return true;
		// get the menu to display
		d = document.getElementById(pagemenu);
		if(!d) return true;
		// if inactive, activate the link else deactivate
			a.className='active';
			d.style.display = '';
		return false;
	}
	function DeActivateGlobalMenu(menudiv){
		d = document.getElementById(menudiv);
		if(!d) return true;
		divs = d.getElementsByTagName('div');
		// close all dropdown menu
		for(i=0; i<divs.length; i++){
			cls = divs[i].className;
			if(!cls)
				cls = divs[i].getAttribute('class');
			if(cls=='dropdown') 
				divs[i].style.display = 'none';
		}
		lis = d.getElementsByTagName('li');
		// deactivate all li
		for(i=0; i<lis.length; i++){
			if(lis[i].className=='active')
				lis[i].className='';
		}
		return false;
	}
	
	details = new Array();
	details['Property'] = new Array('Agreement', 'Landlord', 'Tenancy', 'Tenant');
	details['Contact'] = new Array('Agreement', 'Landlord', 'Tenancy', 'Tenant');

	function ShowDetails(checkbox, me, myid){
	}
	
	function ResetDetails(){
	}

	function showhide_rightmenu(div){
			a = document.getElementById(div+'_a');
			if(!a){ alert(div+'_a not found!'); return; }
			b = document.getElementById(div+'_b');
			if(!b){ alert(div+'_b not found!'); return; }
			subs = document.getElementById('fluxlet-right');
			divs = subs.getElementsByTagName('li');
			if(subs.style.width=='20px'){
				a.style.display = '';
				b.style.display = 'none';
				subs.style.width = '200px';
				for(i=0; i<divs.length; i++){
					d = divs[i];
					if(d.className=='fluxlet')
						d.style.display='';
				}
				isRightHidden = false;
				adjust_position();
				return;
			}
			a.style.display = 'none';
			b.style.display = '';
			subs.style.width = '10px';
			for(i=0; i<divs.length; i++){
				d = divs[i];
				if(d.className=='fluxlet')
					d.style.display='none';
			}
			isRightHidden = true;
			adjust_position();
	}

function movediv(id){
	d = document.getElementById(id);
	if(!d) return;
	d.style.border='';
}
function showmove(id){
	d = document.getElementById(id);
	if(!d) return;
	d.style.border='1px dotted #4C4D4F';
}

function loadPage($page, $params){
   
   loadXMLDoc("?page="+$page+"&"+$params);
    return;
}

function actionsHandler() {
    if( req.readyState == 4 ) {
	writeAt(ActionsIdName, req.responseText);
	isWorking=false;
    } else {
	loadingSpinner( ActionsIdName );
    }
}

function submitHandler(form){
	return true;
	var url=form.action;
	if(!url) url="";
	var body="";
	var plusCode = "2B";
	for(i=0;i<form.length;i++){
		var elmt = form.elements[i];
		if(elmt.type == "checkbox" || elmt.type == "radio" ){
			if(elmt.checked!=true){
				continue;
			}
		}
		if(elmt.type == "submit" ) {
		    continue;
		}
		var val = form.elements[i].value;
		var nval = val;
		if(val.indexOf('+')>-1){
			nval="";
			var vals = val.split('+');
			for(j=0;j<vals.length-1;j++){
				nval += escape(vals[j])+"%"+plusCode;
			}
			nval += escape(vals[vals.length-1]);
		}
		body += "&"+form.elements[i].name+"="+nval;
	}
	if( submitbutton != null ) {
	    body += "&"+submitbutton.name+"="+submitbutton.value;
	    submitbutton = null;
	}
	loadXMLDoc(""+url, processReqChange, body);
	return false;
}


function processReqChange(){
    if( req.readyState == 4 ) {
		document.write(req.responseText);
	isWorking=false;
    } else {
		document.write("");
    }
}

function loadingSpinner( bodyID ) {
	switch(req.readyState) {
		case 4:
		    return;
		case 1:
		case 2:
		case 3:
		default:
			document.write("");
			break;
	}
}

var req;
function loadXMLDoc(url_go, handler, body) {
    if(!handler) handler=processReqChange;
    if(!body) body="";
	if(url_go.indexOf("http://")>0){ //firefox error
		var urls = new Array();
		urls = url_go.split("http://");
		url_go=urls[0];
		urls = urls[1].split("?");
		url_go = url_go + "?"+urls[1];
	}
    // branch for native XMLHttpRequest object
		if( body == null || body =="") {
//alert(url_go);
		    window.location=(url_go);
		} else {
//alert("->"+body+"<-");
		    window.location=(url_go+"?&"+body);
		}
}

function submitSearch(form){
	submitHandler(form);
	return false;
}

function copy(fromEl, toEl){
	var f = document.getElementById(fromEl);
	var t = document.getElementById(toEl);
	if(f && t){
		t.value = f.value;
	}
}
function clearIt(toEl){
	var t = document.getElementById(toEl);
	if(t){
		t.value = "";
		alert(t.value);
	}
}
function toggleIt(obj,id){
		
	
		if(obj.title == 'hideMe'){
			//obj.innerHTML = '<img src="images/expand.gif" border="0" height="12">';
			obj.title = 'showMe';
		}
		else{
			//obj.innerHTML = '<img src="images/collapse.gif" border="0" height="12">';
			obj.title = 'hideMe'
		}
		new Effect.toggle(id,'Slide', {duration: 0.25}); 
		
	}	
	
/*function ac_init(id,loading){
		var options = {
		script: function (input) { return ('listSuburb.php?input='+input); },
		//callback: function (obj) { $(loading).update('you have selected: '+obj.id + ' ' + obj.value + ' (' + obj.info + ')'); }
		};

		var xml=new AutoComplete(id,options);
		return true;
}*/	

function setActive(obj){
	obj.className = 'activeInput';
	return true;
}

function resetActive(obj){
	obj.className = 'null';
	return true;
				
}

// pop up window //

function openNeWin(){
	//alert('dd');
	var nWin;
	nWin = window.open("http://flux.in/flux/eNewsletter/working/kayburton/submission.php","loadMeEmail","width=465,height=635, top=0, left=0,scrollbars=0");
	//nWin.document.write('<title>Email Me Properties</title>');
	//alert('dd');
}
// pop up window //
	