function textbox(object, text, check) {
	if(check && object.value == text)
		object.value = '';
	else if(!check && object.value == '')
		object.value = text;
}

// Dropdown menu code for IE
startList = function() {
	fadeInit();
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("dropdownMenu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
	setLeftSideHeight();
}

function setLeftSideHeight(){
	if(document.getElementById("rightside")){
		tally = document.getElementById("rightside");
		shorty = document.getElementById("gap");
		lefty  = document.getElementById("leftside");
		if(tally.offsetHeight){
			divHeight=tally.offsetHeight-8;
			leftHeight=lefty.offsetHeight;
		} else if(tally.style.pixelHeight){
			divHeight=tally.style.pixelHeight-9;
			leftHeight=lefty.style.pixelHeight;
		}
		if(navigator.appVersion.indexOf("MSIE 7")>-1 && location.href.search(/\/en\//) != -1) {
			shorty.style.height = divHeight-leftHeight-20+'px';
		}
		else shorty.style.height = divHeight-leftHeight+'px';
		shorty.style.zIndex = 1;
		document.contactus.style.zIndex=300;
		document.getElementById("contact").style.zIndex=200;
	}
}

window.onload = startList;

function hideSelects(){
	if (document.all&&document.getElementById) {
		document.getElementById("locationSelect").style.visibility = "hidden";
		document.getElementById("paxSelect").style.visibility = "hidden";
	}
}
function showSelects(){
	if (document.all&&document.getElementById) {
		document.getElementById("locationSelect").style.visibility = "visible";
		document.getElementById("paxSelect").style.visibility = "visible";
	}
}

/********code to do the tab changes and rollovers*****/
function setActiveTab(tabid, contentid, fader){
	
	var info=document.getElementById("content");
	var contents=info.getElementsByTagName("DIV");
	for (i=0; i<contents.length; i++){
		if (contents[i].className=="activeContent"){
			contents[i].className="inactiveContent";
		}
	}
	document.getElementById(contentid).className="activeContent";
	
	var tabs=document.getElementById("tabs");
	var buttons=tabs.getElementsByTagName("DIV");
	for (i=0; i<buttons.length; i++){
		if (buttons[i].className=="activeTab"){
			buttons[i].className="inactiveTab";
		}
	}
	if(tabid){
		tabid.className="activeTab";
	}
	
	slideshow = document.getElementById("gallery");
	if(fader){
		slideshow.style.display = "block";
	} else {
		slideshow.style.display = "none";
	}
	
	setLeftSideHeight();
	
}

function setActiveSubTab(contentid){
	
	var info=document.getElementById("content");
	var contents=info.getElementsByTagName("DIV");
	for (i=0; i<contents.length; i++){
		if (contents[i].className=="activeContent"){
			contents[i].className="inactiveContent";
		}
	}
	document.getElementById(contentid).className="activeContent";
			
	setLeftSideHeight();
	
}

function hoverTab(tabid){
	if (tabid.className != "activeTab"){
		tabid.className = "inactiveTabHover";
		tabid.onmouseout = function(){
			if (tabid.className != "activeTab"){
				this.className = "inactiveTab";
			}
		}
	}

}

//to show floor plans
function showFloor(imgUrl,title,w,h) {
	if(typeof(newWin)!="undefined"){
		if(!newWin.closed){
			newWin.close();
		}
	}
	w+= 40;
	h+=95;
	t = (screen.height/2)-(h/2);
	l = (screen.width/2)-(w/2);
	newWin = window.open('','newWin',"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width="+w+",height="+h+",left="+l+",top="+t);
	newWin.document.write("<html><head><title>The Executive Centre</title><LINK type='text/css' rel='stylesheet' href='../../../scripts/popup.css'></head><body><div id='frame'><div id='floorplan' class='bodybox'><p class='titleText'>"+title+"</p><p class='closeLink'><a href='javascript: window.close()'>Close</a></p><img src='../../../images/locations/floorplans/"+imgUrl+".jpg' id='fplan'></div><div class='footer' id='footer'><img src='../../../images/vivachilogo.jpg' alt='' width='66' height='23'><p>TEC 2005 ©</p></div></div></body></html>");
	newWin.document.close;
	if(window.focus) {
		newWin.focus();
	}
}
/***********************************************
* Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated April 2nd, 2005.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="../whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
for (i=0; i<rootobj.length; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}


function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate


/********cross fade code*********/
/*

Better(?) Image cross fader (C)2004 Patrick H. Lauke aka redux

Inspired by Steve at Slayeroffice http://slayeroffice.com/code/imageCrossFade/ 

preInit "Scheduler" idea by Cameron Adams aka The Man in Blue
http://www.themaninblue.com/writing/perspective/2004/09/29/ 

*/

/* general variables */

var galleryId = 'gallery'; /* change this to the ID of the gallery list */
var	gallery; /* this will be the object reference to the list later on */
var galleryImages; /* array that will hold all child elements of the list */
var currentImage; /* keeps track of which image should currently be showing */
var previousImage;
preInit();

/* functions */

function preInit() {
	/* an inspired kludge that - in most cases - manages to initially hide the image gallery list
	   before even onload is triggered (at which point it's normally too late, and the whole list already
	   appeared to the user before being remolded) */
	if ((document.getElementById)&&(gallery=document.getElementById(galleryId))) {
		gallery.style.visibility = "hidden";
		clearTimeout(preInitTimer);
		//
		galleryImages = gallery.getElementsByTagName('img');
		for(i=0;i<galleryImages.length;i++) {
			galleryImages[i].style.display='none';
		}
		//
	} else {
		preInitTimer = setTimeout("preInit()",2);
	}	
}

function fader(imageNumber,opacity) {
	/* helper function to deal specifically with images and the cross-browser differences in opacity handling */
	var obj=galleryImages[imageNumber];
	if (obj.style.MozOpacity!=null) {  
		/* Mozilla's pre-CSS3 proprietary rule */
		obj.style.MozOpacity = (opacity/100) - 0.001;
	} else if (obj.style.opacity!=null) {
		/* CSS3 compatible */
		obj.style.opacity = (opacity/100) - 0.001;
	} else if (obj.style.filter!=null) {
		/* IE's proprietary filter */
		obj.style.filter = "alpha(opacity="+opacity+")";
	}
}

function fadeInit() {
	if (document.getElementById&&gallery) {
		preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
		/* get all child nodes...yes, lazy, as i should really check that they're the "proper" type
		of child nodes (i.e. filter out duff text only nodes, such as white space) */
		galleryImages = gallery.getElementsByTagName('img');
		for(i=0;i<galleryImages.length;i++) {
			/* loop through all these child nodes and set up their styles */
			galleryImages[i].style.position='absolute';
			galleryImages[i].style.top='15px';
			galleryImages[i].style.zIndex=0;
			galleryImages[i].style.display='block';
			/* set their opacity to transparent */
			fader(i,0);
		}
		/* make the list visible again */
		gallery.style.visibility = 'visible';
		/* initialise a few parameters to get the cycle going */
		currentImage=0;
		previousImage=galleryImages.length-1;
		opacity=100;
		fader(currentImage,100);
		/* start the whole crossfade process after a second's pause */
		window.setTimeout("crossfade(100)", 1000);
	}
}

function crossfade(opacity) {
		if (opacity < 100) {
			/* current image not faded up fully yet...so increase its opacity */
			fader(currentImage,opacity);
			/* fader(previousImage,100-opacity); */
			opacity += 10;
			window.setTimeout("crossfade("+opacity+")", 100);
		} else {
			fader(currentImage,opacity);
			/* make the previous image - which is now covered by the current one fully - transparent */
			fader(previousImage,0);
			/* current image is now previous image, as we advance in the list of images */
			previousImage=currentImage;
			currentImage+=1;
			if (currentImage>=galleryImages.length) {
				/* start over from first image if we cycled through all images in the list */
				currentImage=0;
			}
			/* make sure the current image is on top of the previous one */
			galleryImages[previousImage].style.zIndex = 0;
			galleryImages[currentImage].style.zIndex = 50;
			/* and start the crossfade after a second's pause */
			opacity=0;
			window.setTimeout("crossfade("+opacity+")", 1500);
		}
		
}

function VirtualTour(text) {
	document.write(text);
}

/* initialise fader by hiding image object first */
//addEvent (window,'load',fadeInit)



/* 3rd party helper functions */

/* addEvent handler for IE and other browsers 
function addEvent(elm, evType, fn, useCapture) 
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
} 
*/
