var isns = (navigator.appName.indexOf('Netscape')<0)?0:1;
var d = document;
var isie  = document.all ? 1 : 0;
var isns4 = document.layers ? 1 : 0;
var isdom = document.getElementById ? 1 : 0;

function objectTree(objectroot,showAll) {
	var output = "";
	var i = 0;
		for (property in objectroot) {
			i++;
			//if (i>=140) alert(i+" :0: "+property);
			if (showAll) {
				if ((property!="innerHTML")&&(property!="outerHTML")&&(property!="fileModifiedDate")&&(property!="fileCreatedDate")&&(property!="mimeType")) {
					if ((objectroot[property] != null) && (objectroot[property] != "")) {
						propertyText = "" + objectroot[property];
						isNativeCode = (propertyText.indexOf("[native code]")>0) ? true : false;
						if (!isNativeCode) {
							output = output + property + " = " + objectroot[property] + ";";
						}
					} else {
						output = output + property + " = " + objectroot[property] + ";";
					}
				}
			} else if ((objectroot[property] != null) && (objectroot[property] != "")) {
					output = output + property + " = " + objectroot[property] + ";"; 
			}
		}
	alert(output);
}

// Preload any required images NB shouldn't need these for ordinary image mouse overs as we can use lowsrc
var imgArr=new Array();
function preloadImages(imgList) {
	for(var i=0; i<imgList.length; i++) {
	 	imgArr[i] = new Image();
		imgArr[i].src = imgList[i];
    }
}

// Enable mouseovers using preloads (for backgrounds)
function bg_rollover(overObj,preloadIndex) {
	overObj.background=imgArr[preloadIndex].src;
}

// Enables mouseovers using lowsrc (images only)
function img_rollover(imgObj) {
	imgTemp = imgObj.src;
	imgObj.src=imgObj.lowsrc;
	imgObj.lowsrc=imgTemp;
}

// Enables mouseovers using classes
function class_rollover(obj,className) {
	obj.className = className;
}

// Get the dimensions of the passed object
function getDivRect(divType,i) {
	divId = "tbl"+divType + i;
	menuObj = document.getElementById(divId);
	var obj = new Object;
	obj.top = menuObj.offsetTop;
	obj.left = menuObj.offsetLeft;
	obj.bottom = menuObj.offsetTop+menuObj.offsetHeight;
	obj.right = menuObj.offsetLeft+menuObj.offsetWidth;
	return obj;
}

function dims(t,l,b,r) {
	var obj = new Object;
	obj.top = t;
	obj.left = l;
	obj.bottom = b;
	obj.right = r;
	return obj;
}

function dimArray() {
	var args = dimArray.arguments;
	var argsl = args.length;
	var dimArr = new Array();
	for (i=0;i<argsl;i++) {
		dimArr[i]=args[i];
	}
	return dimArr;
}

// dynamically set the coordinates for the menu object if supported else use those passed
function showmenu(i,x,y) {
	yOffset = isns ? 13 : 12;
	xOffset = 0;
	if (!isns4) {
		menuItem = isdom ? d.getElementById("m"+i) : d.all["m"+i];
		navbar = (i != 6)?"topnav":"subnav";
		menubar = isdom ? d.getElementById(navbar) : d.all[navbar];	
		dmMenu = isdom ? d.getElementById("tblmenu"+i) : d.all["tblmenu"+i];
		y = menuItem.offsetTop + yOffset;
		x = menuItem.offsetLeft + xOffset;
		//if the menuitem overflows align it to the right
		if (i != 6) {
			menuEnd = x+dmMenu.offsetWidth;
			menuBarEnd = isdom ? d.getElementById("menubarend").offsetLeft : d.all["menubarend"].offsetLeft;
			x= x-((menuEnd > menuBarEnd)?(menuEnd-menuBarEnd):0);
		}
	} else {
		menuItem = document.layers["main"].layers["m"+i];
		//objectTree(menuItem,true);
		//x = menuItem.pageX;
		//y = menuItem.pageY;
	}
	
	//set the position of the dm
	var menuDiv = isdom ? d.getElementById("menu"+i+"Container") : isie ? d.all["menu"+i+"Container"] : d.layers["main"].layers["menu"+i+"Container"];
	menuStyle = isns4 ? menuDiv : menuDiv.style;
	menuStyle.top = y;
	menuStyle.left = x;
	
	//set the zIndex to force the menu to the front
	menuStyle.zIndex = 10;
	var contentDiv = isdom ? d.getElementById("menu"+i+"Content") : isie ? d.all["menu"+i+"Content"] : d.layers["main"].layers["menu"+i+"Container"].layers["menu"+i+"Content"];
	contentStyle = isns4 ? contentDiv : contentDiv.style;
	contentStyle.zIndex = 10;

	//show the menu
	slideOutMenu.showMenu("menu"+i);

}

// Hide the menu
function hidemenu(i) {
	//set the position of the dm
	var menuDiv = isdom ? d.getElementById("menu"+i+"Container") : isie ? d.all["menu"+i+"Container"] : d.layers["main"].layers["menu"+i+"Container"];
	menuStyle = isns4 ? menuDiv : menuDiv.style;
	
	//set the zIndex to force the menu to the front
	menuStyle.zIndex = 9;
	var contentDiv = isdom ? d.getElementById("menu"+i+"Content") : isie ? d.all["menu"+i+"Content"] : d.layers["main"].layers["menu"+i+"Container"].layers["menu"+i+"Content"];
	contentStyle = isns4 ? contentDiv : contentDiv.style;
	contentStyle.zIndex = 9;
	slideOutMenu.hideMenu("menu"+i);
}

function showproduct (i,x,y) {
	
	yOffset = isns?-1:-1;
	xOffset = 0;
	if (!isns4) {
		prodtd = isdom ? d.getElementById("prodtd"+i) : d.all["prodtd"+i];
		bg_rollover(prodtd,1);
		productItem = isdom ? d.getElementById("p"+i) : d.all["p"+i];
		productBar =  isdom ? d.getElementById("tblProdList") : d.all["tblProdList"];
		productDetail =  isdom ? d.getElementById("tblprod"+i) : d.all["tblprod"+i];
		y = productItem.offsetTop + yOffset;
		x = productItem.offsetLeft + xOffset;
		//if the menuitem overflows align it to the right
		//if the productItem overflows align it to the bottom
		productItemEnd = y+productDetail.offsetHeight;
		productBarEnd = isdom ? d.getElementById("prodListEnd").offsetTop : d.all["prodListEnd"].offsetTop;
		y= y-((productItemEnd > productBarEnd)?(productItemEnd-productBarEnd):0);
	} else {
		// use the x, y co-ordinates passed
		
		//if the menuitem overflows align it to the right
		//if the productItem overflows align it to the bottom
		productItemEnd = y + d.layers["main"].layers["prod"+i+"Container"].clip.height;
		productBarEnd = 567;
		y= y-((productItemEnd > productBarEnd)?(productItemEnd-productBarEnd):0);
	}
	
	//set the position of the prodDiv
	var containerDiv = isdom ? d.getElementById("prod"+i+"Container") : isie ? d.all["prod"+i+"Container"] : d.layers["main"].layers["prod"+i+"Container"];
	containerStyle = isns4 ? containerDiv : containerDiv.style;
	containerStyle.top = y;
	containerStyle.left = x;
	
	//set the zIndex to force the menu to the front
	containerStyle.zIndex = 10;
	var contentDiv = isdom ? d.getElementById("prod"+i+"Content") : isie ? d.all["prod"+i+"Content"] : d.layers["main"].layers["prod"+i+"Container"].layers["prod"+i+"Content"];
	contentStyle = isns4 ? contentDiv : contentDiv.style;
	contentStyle.zIndex = 10;
	
	//show the menu
	slideOutMenu.showMenu("prod"+i);
}

// Hide the menu
function hideproduct(i) {
	
	if (!isns4) {
		prodtd = isdom ? d.getElementById("prodtd"+i) : d.all["prodtd"+i];
		bg_rollover(prodtd,0);
	}
	var menuDiv = isdom ? d.getElementById("prod"+i+"Container") : isie ? d.all["prod"+i+"Container"] : d.layers["main"].layers["prod"+i+"Container"];
	menuStyle = isns4 ? menuDiv : menuDiv.style;
	
	//set the zIndex to force the menu to the front
	menuStyle.zIndex = 9;
	var contentDiv = isdom ? d.getElementById("prod"+i+"Content") : isie ? d.all["prod"+i+"Content"] : d.layers["main"].layers["prod"+i+"Container"].layers["prod"+i+"Content"];
	contentStyle = isns4 ? contentDiv : contentDiv.style;
	contentStyle.zIndex = 9;
	slideOutMenu.hideMenu("prod"+i);
}

function showsubscriptions (i,x,y) {
	
	yOffset = isns?-1:-1;
	xOffset = 0;
	if (!isns4) {
		menuitem = isdom ? d.getElementById("s"+i) : d.all["s"+i];
		offsets = objOffset (menuitem);
		subscriptions =  isdom ? d.getElementById("tblmenu"+i) : d.all["tblmenu"+i];
		y = offsets.offsetTop + yOffset;
		x = offsets.offsetLeft + xOffset;
	} else {
		// use the x, y co-ordinates passed
		menuitem = d.layers["main"].layers["s"+i];
		objectTree(menuitem,true);
	}
	
	//set the position of the prodDiv
	var containerDiv = isdom ? d.getElementById("menu"+i+"Container") : isie ? d.all["menu"+i+"Container"] : d.layers["main"].layers["menu"+i+"Container"];
	containerStyle = isns4 ? containerDiv : containerDiv.style;
	containerStyle.top = y;
	containerStyle.left = x;
	
	//set the zIndex to force the menu to the front
	containerStyle.zIndex = 10;
	var contentDiv = isdom ? d.getElementById("menu"+i+"Content") : isie ? d.all["menu"+i+"Content"] : d.layers["main"].layers["menu"+i+"Container"].layers["menu"+i+"Content"];
	contentStyle = isns4 ? contentDiv : contentDiv.style;
	contentStyle.zIndex = 10;
	
	//show the menu
	slideOutMenu.showMenu("menu"+i);
}

// Hide the menu
function hidesubscriptions(i) {
	
	var menuDiv = isdom ? d.getElementById("menu"+i+"Container") : isie ? d.all["menu"+i+"Container"] : d.layers["main"].layers["menu"+i+"Container"];
	menuStyle = isns4 ? menuDiv : menuDiv.style;
	
	//set the zIndex to force the menu to the front
	menuStyle.zIndex = 9;
	var contentDiv = isdom ? d.getElementById("menu"+i+"Content") : isie ? d.all["menu"+i+"Content"] : d.layers["main"].layers["menu"+i+"Container"].layers["menu"+i+"Content"];
	contentStyle = isns4 ? contentDiv : contentDiv.style;
	contentStyle.zIndex = 9;
	slideOutMenu.hideMenu("menu"+i);
}

function objOffset (obj) {
	// recursively calls itself until there are no more parent objects adding offset values as it goes
	var objOffset = new Object;
	objOffset.offsetTop = 0;
	objOffset.offsetLeft = 0;
	while (obj != null) {
		objOffset.offsetTop = objOffset.offsetTop + obj.offsetTop;
		objOffset.offsetLeft = objOffset.offsetLeft + obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return objOffset;
}

var timeoutId1;
var timeoutId2;

function startTicker(tickerId,noItems,delay) {
	timeoutId1 = setTimeout("doScroll('"+tickerId+"',"+noItems+")",delay);
}

function stopTicker() {
	clearTimeout(timeoutId1);
	clearTimeout(timeoutId2);
}

function doScroll(tickerId,noItems) {
	var itemArr = new Array();
	var styleArr = new Array();
	// get the itemDiv objects
	for (i=1;i<=noItems;i++) {
		var item = isdom ? d.getElementById(tickerId+"Item"+i) : isie ? d.all[tickerId+"Item"+i] : d.layers["main"].layers[tickerId].layers[tickerId+"Item"+i];
		itemArr[i] = item;
		style = isns4 ? item : item.style;
		styleArr[i] = style;			
	}
	endscroll = false;
	for (i=1;i<=noItems;i++) {
		var top = styleArr[i].top;
		top = parseInt(top);
		if (top==0) topDivi = i;
		styleArr[i].top = top-1;
		if ((top-1)==0) endscroll = true;
		
	}
	
	//call self recursively using setTimeout
	if (!endscroll) {
		timeoutId2 = setTimeout("doScroll('"+tickerId+"',"+noItems+")",50);
	} else {
		// move the item now scrolled off the screen to the bottom of the list
		styleArr[topDivi].top = (noItems-1)*15;
		// reset the timeout
		timeoutId1 = setTimeout("doScroll('"+tickerId+"',"+noItems+")",3000);
	}
}
	


function openWin(url,name,config){
	window.open(url,name,config);
	// "fullscreen=no,channelmode=no,toolbar=yes,location=no,directories=yes,status=n0,menubar=no,scrollbars=no,resizable=no,width=100,height=110,top=number,left=number"
}

function saveCookie(varname,val) {
     document.cookie=varname+"="+val;
}

function setcookie(name,value,duration,path){
	//format for cookie string
	//cookiestring = "name=value;EXPIRES=date;DOMAIN=domainName;PATH=pathName;SECURE"
	//EXPIRES format 
	//EXPIRES=Weekday, DD-Month-YY HH:MM:SS GMT
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration)+";PATH="+path;
	document.cookie=cookiestring;
}

function getexpirydate( nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function getcookie(cookiename) {
	 var cookiestring=""+document.cookie;
	 var index1=cookiestring.indexOf(cookiename);
	 if (index1==-1 || cookiename=="") return false; 
	 var index2=cookiestring.indexOf(';',index1);
	 if (index2==-1) index2=cookiestring.length; 
	 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function moveTo(loc) {
	location = loc;
}

function doNada() {
}

function openProdWin(url,prod){
	config = "fullscreen=no,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=400,top=number,left=number";
	winid = window.open(url+"?prod="+prod,"prodwin",config);
	winid.focus();
}

function validateIPVal(formobj) {
	if (formobj.CAT_CODE.value == 0) {
		alert ("Please select an option for the 'Category' field.");
		formobj.CAT_CODE.focus();
		return false;
	}
	if (formobj.TYPE_CODE.value==0) {
		alert ("Please select an option for the 'Building Type' field.");
		formobj.TYPE_CODE.focus();
		return false;
	}
	if (formobj.BREAKUP_CODE.value==0) {
		alert ("Please select an option for the 'Sub Type' field.");
		formobj.BREAKUP_CODE.focus();
		return false;
	}
	if (formobj.LEVEL_CODE.value==0) {
		alert ("Please select an option for the 'Levels' field.");
		formobj.LEVEL_CODE.focus();
		return false;
	}
	if (!validNum(formobj.GSF,"Total Square Meters",true)) {
		return false;	
	}
	if (!validNum(formobj.POSTCODE,"Postcode",false)) {
		return false;	
	}

	formobj.SUBMIT.value="true";
}

function CreateList()
{
    output = "";
	checkformArr = document.getElementsByName("checkform");
	for (i=0;i<checkformArr.length;i++) {
		frmObj = checkformArr.checkform[i];
        if (frmObj.checkbox.checked == true) {
			if (output == "") {
				output = output + frmObj.checkbox.value;
			} else {
				output = output + "," + frmObj.checkbox.value;
			}
		}
	}
    if (output == "") {
        alert("No projects selected");
        return false;
    } else {
		saveCookie("DET_PROJECT_ID",output);
		return true;
	}
}

function gotoDetail(issNum,seqNum,detAction,projId,orderBy)
{
	saveCookie("DET_ISSUE_NUMBER",issNum);
	saveCookie("DET_ACTION",detAction);
	saveCookie("DET_SEQ_NUM",seqNum);
	saveCookie("DET_ORDER_BY",orderBy);
	if (detAction=="SINGLE")
	{
		saveCookie("DET_PROJECT_ID",projId);
	}
	moveTo('early_det.php');
}

function reorderSummary(field,sort) {
	saveCookie("SUM_FIELD",field);	
	saveCookie("SUM_SORT",sort);	
	moveTo('early_sum.php');
}

function gotoSummary(prodCode,issNum)
{
	moveTo('early_sum.php');
}

function gotoNext(issNum,seqNum,detAction,projId,orderBy)
{
	gotoDetail(issNum,seqNum,detAction,projId,orderBy)
}

function gotoPrevious(issNum,seqNum,detAction,projId,orderBy)
{
	gotoDetail(issNum,seqNum,detAction,projId,orderBy)
}

function showDiv(prefix,divId,noDivs) {
	for (i=1;i<=noDivs;i++) {
		var divObj = isdom ? d.getElementById(prefix+i) : isie ? d.all[prefix+i] : d.layers[prefix+i];
		var styleObj = isns4 ? divObj : divObj.style;
		if (divObj.id==prefix+divId) {
			styleObj.visibility = "visible";
		} else {
			styleObj.visibility = "hidden";
		}
	}
}

function breakout_of_frame() {
	if (parent.location != location) {    parent.location = location ;  }
}

function signup() {
	product = "none";
	frmObj = document.getElementById("logonfrm");
	for (i=0;i<frmObj.product.length;i++) {
		if (frmObj.product(i).checked) product = frmObj.product(i).value;
	}
	openWin('signup/signup.php?product='+product,'','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes');
}

function logon() {
	product = "none";
	frmObj = document.getElementById("logonfrm");
	for (i=0;i<frmObj.product.length;i++) {
		if (frmObj.product(i).selected) product = frmObj.product(i).value;
	}
	if (product=="none") return	alert ("You have not selected a product.");
	switch (product) {
		case "0":
			break;
		case "4":
			infoLogin();
			break;
		case "2":
			appWin('http://ebulletin.rcd.com.au/chk_pwd.php','http://ebulletin.rcd.com.au/login.php','USERNAME','PASSWORD');
			break;
		case "1":
			appWin('http://www.cordellconnect.com.au/login.asp','http://www.cordellconnect.com.au/default.asp','uName','pName');
			break;
		case "3":
			appWin('http://ecosting.rcd.com.au/chk_pwd.php','http://ecosting.rcd.com.au/login.php','USERNAME','PASSWORD');
			break;
		case "5":
			appWin('http://housing.rcd.com.au/login.asp','http://housing.rcd.com.au/login.asp','USERNAME','PASSWORD');
			break;
		case "6":
			appWin('https://secure.cordell.com.au/valuer_residential/profiles/cordell_full_ecommerce/index.php','USERNAME','PASSWORD');
			break;
		case "7":
			appWin('http://estimator.rcd.com.au/login.asp','http://estimator.rcd.com.au/login.php','USERNAME','PASSWORD');
			break;
		default:
			alert ("Unknown Product.");
	}
}

function infoLogin() {
	username = document.getElementById("uid").value;
	password = document.getElementById("pwd").value;
	frm = document.getElementById("logonfrm");
	document.getElementById("USERNAME").name = "logon";
	document.getElementById("USERNAME").value = username;	
	document.getElementById("PASSWORD").name = "password";	
	document.getElementById("PASSWORD").value = password;
	if ((username!="") && (password!="")) 
	{frm.action = "http://infopartners.rcd.com.au/chk_login.php";} 
	else 
	{frm.action = "http://infopartners.rcd.com.au/login.php";}	
	frm.target = "_top";
	//frm.submit();
}

function appWin(url,alt,uidVarName,pwdVarName){
	username = document.getElementById("uid").value;
	password = document.getElementById("pwd").value;
	frm = document.getElementById("logonfrm");
	document.getElementById("USERNAME").name = uidVarName;
	document.getElementById("USERNAME").value = username;	
	document.getElementById("PASSWORD").name = pwdVarName;	
	document.getElementById("PASSWORD").value = password;
	//frm.target = "_top";
	if ((username!="") && (password!="")) {
		saveCookie("ENABLED","true");	
		frm.action = url;
		//frm.submit();
	} else {
		frm.action = alt;
		//frm.submit();
	}	
	// "fullscreen=no,channelmode=no,toolbar=yes,location=no,directories=yes,status=no,menubar=no,scrollbars=no,resizable=no,width=100,height=110,top=number,left=number"
}

function admin(){
	if(window.event.ctrlKey){
		if(window.event.shiftKey){
			if(window.event.keyCode == 1){
				window.open("admin/index.php","Admin","");
			}
		}
	}
}