var $curShowing="";
var $lastShowing="";

function cancelLink(event) {
//	evt = event || window.event;
//	alert(evt);
    if (window.event) {
    	if(window.event.srcElement.tagName == "A")	window.event.returnValue = false;
	}else{
   	event.preventDefault();
   }
}

function getObjectByID($id){
	var $obj;
	if (document.getElementById){
		// this is the way the standards work
		$obj = document.getElementById($id);
	}else if (document.all){
		// this is the way old msie versions work
		$obj = document.all[$id];
	}else if (document.layers){
		// this is the way nn4 works
		$obj = document.layers[$id];
	}
	return $obj;
}

function showByID($id){
	var $obj;
	$obj = getObjectByID($id);
	if($obj){
		if($obj.style.display == "run-in" || !$obj.style.display)	$obj.style.display = "none";
		else														$obj.style.display = "block";
	}
}

function hideByID($id){
	var $obj;
	$obj = getObjectByID($id);
	if($obj)	$obj.style.display = "none";
}

function hideNav(){
	if($lastShowing=="") hideByID($curShowing);
	else{
		if($lastShowing!=$curShowing) hideByID($curShowing);	
		showNav($lastShowing,1)
	}
}

function showNav($id,$clicked){
	var $show = "";
	if($curShowing==$lastShowing) $show = $curShowing;
	else									$show	= $lastShowing;
	if($show){
		$ids 	= $id.split("#");
		$lids	= $show.split("#");
		//normal tree action
		if($ids.length==$lids.length){
			if($show!=$id)	hideByID($show);
			showByID($id);
		}
		//drilling down the tree
		if($ids.length>$lids.length){
			showByID($id);
		}
		//walking up the tree last step set id to current open after possible toggle
		if($ids.length<$lids.length){
			$cid=$lids[0];
			for (i = 0; i < $lids.length; i++){
				 if(i>0) $cid +="#"+$lids[i]; 
				 if(i>=($ids.length-1))hideByID($cid);
			}
			showByID($id);
		}
	}else	showByID($id);
	$curShowing=$id;
	if($clicked==1)$lastShowing=$id;
}

var $lastLink 			= "";
function colorNav($linkId){
	//alert($lastShowing+" "+$curShowing);
	var $obj = "";
	var $lastobj = "";

	$obj = getObjectByID($linkId);

	if($lastLink !="" && $lastLink != $linkId){
		$lastobj = getObjectByID($lastLink);
		if($lastobj){
			$lastobj.style.color = "#444444";
			$lastobj.style.fontWeight = "normal";
		}	
	}	
	
	if($obj){
			$obj.style.color = "#D5292C";
			$obj.style.fontWeight = "bolder";
	}
	$lastLink = $linkId;
}


var $xmlHttp;
function GetXmlHttpObject2(){
	var $oXMLHttp=null;
	if(window.XMLHttpRequest){
		$oXMLHttp=new XMLHttpRequest()
	}else if(window.ActiveXObject){
			//$oXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
			$oXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return $oXMLHttp
}

function GetXmlHttpObject(){
	var $oXMLHttp;
	try{// Firefox, Opera 8.0+, Safari
		$oXMLHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer
		try{
			$oXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				$oXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return;
			}
		}
	}
	return $oXMLHttp;
}


function getMenuResponse(){
	
	if ($xmlHttp.readyState==4 || $xmlHttp.readyState=="complete"){
		lcoverflow="none";
		mcoverflow="none";
		rcoverflow="none";
		headimg="";
		lcpane="";
		mcpane="";
		rcpane="";
		pagetitle="";
		mdescription="";
		$response="";
		$response= $xmlHttp.responseText;
//	alert($response);
		eval($response);
// alert(pagetitle);
		if(lcpane.length>1){
			$obj=getObjectByID("LCPane");
			if($obj){
				$obj.style.overflow=lcoverflow;
				$obj.innerHTML=	lcpane;
			}
		}
		if(mcpane.length>1){
			$obj=getObjectByID("MCPane");
			if($obj){
				$obj.style.overflow=mcoverflow;
				$obj.innerHTML=	mcpane;
			}
		}
		if(rcpane.length>1){
			$obj=getObjectByID("RCPane");
			if($obj){
				$obj.style.overflow=rcoverflow;
				$obj.innerHTML=	rcpane;
			}
		}
		if(pagetitle.length>1){
			document.title=pagetitle;
			//alert(pagetitle);
		}
		if(mdescription.length>1){
			changeDescription(mdescription);
		}
		if(headimg.length>1){
			changeImage("headimage",headimg);
		}

	}
}

function changeImage($id,$image){
	$obj=getObjectByID($id);
	//alert($image);
	if($obj)	$obj.src=$image;
}


function changeDescription($text){
	var metaArray = document.getElementsByName("description");
	for (var i=0; i<metaArray.length; i++) {
       metaArray[i].content=$text;
   // alert(metaArray[i].content);
	}
}

function followMenu($url,event){
	$xmlHttp=GetXmlHttpObject();
	$url="/index.php?c="+$url;

	if($xmlHttp==null){
//	if(1){
		alert ("Browser does not support HTTP Request: "+$url);
		this.location=$url;
	}else{
		cancelLink(event);
		$url=$url+"&t=body&sid="+Math.random();
			//alert ("HTTP Request: "+$url);
		$xmlHttp.onreadystatechange=getMenuResponse; 
		$xmlHttp.open("GET",$url,true);
		$xmlHttp.send(null);
	}
} 



window.status="loading complete";

