// JavaScript Document

function _setVar(param,value)
{
	field=document.getElementById(param);
	field.value=value;
}

function _submitForm(name)
{
	_form=document.getElementById(name);
	_form.submit();
}

function findObj(n, d)
{
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n]) && d.all)
	x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
	x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
	x=findObj(n,d.layers[i].document);
	if(!x && d.getElementById)
	x=d.getElementById(n);
	return x;
}

function toggleFields()
{
	ob=document.getElementById('mnuShow');
	if(ob.style.display=='none')
	ob.style.display='';
	else
	ob.style.display='none';
}

function ckAll()
{
	ob=document.getElementById('ckAny');
	document.getElementById('ckApartment').checked=ob.checked;
	document.getElementById('ckBungalow').checked=ob.checked;
	document.getElementById('ckCondo').checked=ob.checked;
	document.getElementById('ckCottage').checked=ob.checked;
	document.getElementById('ckDuplex').checked=ob.checked;
	document.getElementById('ckFourPlex').checked=ob.checked;
	document.getElementById('ckGuestHouse').checked=ob.checked;
	document.getElementById('ckHotelMotel').checked=ob.checked;
	document.getElementById('ckHouse').checked=ob.checked;
	document.getElementById('ckTownHouse').checked=ob.checked;
	document.getElementById('ckTriplex').checked=ob.checked;
}

function updateTableCheckboxes(me,form,tablename)
{

	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr))
		{
			supported = 1;
			var r1 = new RegExp(tablename+"Sel[0-9a-zA-Z_]+");
			var r2 = new RegExp(tablename+"SelMerged[0-9a-zA-Z_]+");
		}
	}

	for (i=0; i<form.elements.length; i++){
		var chkName=form.elements[i];
		if (form.elements[i].type=='checkbox' && form.elements[i].name!=me.name)
		{
			var checkname=' '+chkName.name;
			if (!supported)
			{
				if(checkname.indexOf(tablename+'Sel'))
				{
					chkName.checked=me.checked;
				}
			}
			else
			{
				if(r1.test(checkname) && !r2.test(checkname))
				{
					chkName.checked=me.checked;
				}
			}
			//filter only checkbox
		}
	}
}

function updateTableMergedCheckboxes(me,form,tablename)
{
	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr))
		{
			supported = 1;
			var r1 = new RegExp(tablename+"SelMerged[0-9a-zA-Z_]+");
		}
	}
	for (i=0; i<form.elements.length; i++){
		var chkName=form.elements[i];
		if (form.elements[i].type=='checkbox' && form.elements[i].name!=me.name)
		{
			var checkname=' '+chkName.name;
			if (!supported)
			{
				if(checkname.indexOf(tablename+'Sel'))
				{
					chkName.checked=me.checked;
				}
			}
			else
			{
				if(r1.test(checkname))
				{
					chkName.checked=me.checked;
				}
			}
			//filter only checkbox
		}
	}
}

var SaveRowColor="";
var SaveRowClass="";
var OverRowColor='#eeeeee';
var OverRowStyleClass='';
var FirstCell=0;

function setRowColor(theRow, theAction)
{
	var theCells = null;
	if (typeof(theRow.style) == 'undefined') {
		return false;
	}
	if (theAction == "over") {
		theRow.style.cursor='pointer';
	} else {
		theRow.style.cursor='default';
	}
	if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	}
	else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	}
	else {
		return false;
	}
	var rowCellsCnt  = theCells.length;
	var domDetect    = null;
	var currentColor = null;
	var newColor     = null;
	if (typeof(window.opera) == 'undefined'
	&& typeof(theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[FirstCell].getAttribute('bgcolor');
		currentClass = theCells[FirstCell].className;
		domDetect    = true;
	}
	else {
		currentColor = theCells[FirstCell].style.backgroundColor;
		currentClass = theCells[FirstCell].className;
		domDetect    = false;
	}
	if(currentColor)
	{
		if (currentColor.indexOf("rgb") >= 0)
		{
			var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
			currentColor.indexOf(')'));
			var rgbValues = rgbStr.split(",");
			currentColor = "#";
			var hexChars = "0123456789ABCDEF";
			for (var i = 0; i < 3; i++)
			{
				var v = rgbValues[i].valueOf();
				currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
			}
		}
	}
	if(theAction=='over')
	{
		newColor=OverRowColor;
		if(currentColor)
		{
			SaveRowColor=currentColor;
		}
		if(currentClass)
		{
			SaveRowClass=currentClass;
		}
		newClass=OverRowStyleClass;
	}
	else
	{
		newColor=SaveRowColor;
		newClass=SaveRowClass;
	}
	if (1) {
		var c = null;
		if (domDetect) {
			for (c = FirstCell; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', newColor, 0);
				theCells[c].className = newClass;
			}
		}
		else {
			for (c = FirstCell; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = newColor;
				theCells[c].className = newClass;
			}
		}
	}
	return true;
}

function _regEv(objid,ev,reg_only)
{
	if(typeof(objid)!='string')
	{
		objid=objid.id;
	}
	dont_ret=0;
	if(eval('typeof(_'+objid+ev+')=="function"'))
	{
		eval('dont_ret=_'+objid+ev+'();');
	}
	var objform;
	if(document.getElementById(objid).form)
	{
		objform=document.getElementById(objid).form.name;
	}
	else
	{
		objform=getParentForm(document.getElementById(objid));
	}
	if(objform)
	{
		objforms=document.getElementsByTagName('FORM');
		for(i=0;i<objforms.length && !_form;i++)
		{
			if(objforms.item(i).name==objform || objforms.item(i).id==objform)
			{
				var _form=objforms.item(i);
			}
		}
		var ed=_form.elements['__ev_dispatcher'];
		ed.value+=objid+'='+ev+';';
		if(!reg_only && !dont_ret)
		{
			if(typeof(chilli_display_loader)!= "undefined" && chilli_display_loader)
			{
				chilliDisplayLoader();
			}
			_form.submit();
			return false;
		}
	}
	else
	{
		alert("Chilli error: cannot find parent form for this object");
	}
}

function toggleVisibility(object,img,collapse_img,expand_img)
{
	var obj=document.getElementById(object);
	if(img)
	{
		if(typeof(img)=="string")
		{
			var image=document.getElementById(img);
			if(!image.src)
			{
				var imgs=image.getElementsByTagName("IMG");
				image=imgs.item(0);
			}
		}
		else
		{
			if(img.src)
			{
				var image=img;
			}
			else
			{
				var imgs=img.getElementsByTagName("IMG");
				image=imgs.item(0);
			}
		}
	}
	if(obj.style.display=='none')
	{
		obj.style.display='';
		if(image)
		{
			if(collapse_img)
			{
				image.src=collapse_img;
			}
			else
			{
				image.src='images/controls/minus.gif';
			}
		}
	}
	else
	{
		obj.style.display='none';
		if(image)
		{
			if(expand_img)
			{
				image.src=expand_img;
			}
			else
			{
				image.src='images/controls/plus.gif';
			}
		}
	}
}

function updateContainerCheckboxes(me,container)
{
	var cont=document.getElementById(container);
	if(!cont) return;
	var els=cont.getElementsByTagName('INPUT');
	for (i=0; i<els.length; i++){
		var el=els[i];
		if (el.type=='checkbox')
		{
			el.checked=me.checked;
		}
	}
}

function getParentForm(obj)
{
	while(obj && obj.tagName!='FORM')
	{
		obj=obj.parentNode;
	}
	if(obj) return obj.name; else return '';
}

// Show / hide a named DOM object
function toggleControl(object)
{
	var ob=document.getElementById(object);

	if(ob.style.display=='none')
	ob.style.display='';
	else
	ob.style.display='none';
}

function chilliFindPosition(obj,pType) {
	if(!obj) return 0;
	cur = 0;
	if(obj.offsetParent) {
		while(obj.offsetParent) {
			cur+=pType?obj.offsetLeft:obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return cur;
}


function chilliOutlineObj(obj) {
	if(!obj) return 0;
	outline = "1px solid red";
	obj.style.MozOutline = outline;
	obj.style.outline = outline;
}

function chilliSetOpacity(obj,op) {
	if(!obj) return 0;
	if(!document.all)op/=100;
	obj.style.opacity = op;
	obj.style.MozOpacity = op;
	obj.style.filter = "alpha(opacity=" + op + ")";
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function chilliGetPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function chilliGetPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function chilliGetScrollX()
{
	var xScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
	}
	return xScroll;
}

function chilliGetIECanvas()
{
	var canv = null;
	if (!window.opera && document.all && typeof document.body.clientWidth != "undefined")
	{
		var cm = document.compatMode && document.compatMode == "CSS1Compat";
		canv = cm ? document.documentElement : document.body;
	}
	return canv;
}

function chilliGetScrollX()
{
	var canv,scrollX;
	if (canv = chilliGetIECanvas())
	scrollX = canv.scrollLeft;
	else if (window.pageXOffset)
	scrollX = window.pageXOffset;
	else if (window.scrollX)
	scrollX = window.scrollX;
	else
	scrollX = 0;
	
	return scrollX;
}

function chilliGetScrollY()
{
	var canv,scrollY;
	if (canv = chilliGetIECanvas())
	scrollY = canv.scrollTop;
	else if (window.pageYOffset)
	scrollY = window.pageYOffset;
	else if (window.scrollY)
	scrollY = window.scrollY;
	else
	scrollY = 0;
	
	return scrollY;
}

function chilliGetWinWidth()
{
	var canv;
	if ( canv = chilliGetIECanvas() )
	return canv.clientWidth;
	else
	return window.innerWidth - 18;
}

function chilliGetWinHeight()
{
	var canv;
	if (canv = chilliGetIECanvas())
	return canv.clientHeight;
	else
	return window.innerHeight - 18;
}

// Current Page Reference
// copyright Stephen Chapman, 1st Jan 2005
// you may copy this function but please keep the copyright notice with it
function chilliGetURL(uri) {
	if(!uri) uri = new Object();
	uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
	uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/' || uri.dom.substr(0,7) == 'https:\/\/') {
		uri.proto = uri.dom.substr(0,7);
		uri.dom = uri.dom.substr(7);
	}
	uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
	uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
	pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
	uri.file = uri.page;
	if (uri.ext != '') uri.file += '.' + uri.ext;
	if (uri.file == '') uri.page = 'index';
	uri.args = location.search.substr(1).split("?");
	return uri;
}


// Macromedia buttons functions

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

