function IsChild(cNode,pNode){
	while(cNode!=null){
		cNode=cNode.parentNode;
		if(cNode==pNode) return true; 
	}
	return false;
}

function getElt(aID) {
  return (document.getElementById) ? document.getElementById(aID)
                                   : document.all[aID];
}

var ajahCache=new Object();
function setClassName(str,sta){
	if (str.indexOf("normal")!=-1) {
	    str=str.replace("normal",""); 
	} else {
	    str=str.replace("active",""); 
	}
	    str=str.replace("  "," "); 
	return str+" "+sta;
}
function initAjaxTAB(){
	for(var i=0;i<arguments.length;i++) {
			var oTabBox=document.getElementById(arguments[i]);
			var arrTabs=oTabBox.getElementsByTagName("dd");			
			var oCurrTAB=null;
			for(var j=0;j<arrTabs.length;j++) {
				oCurrTAB=arrTabs[j];
				if(oCurrTAB.parentNode!=oTabBox) continue;
				var oTabLink=oCurrTAB.getElementsByTagName("a")[0];
				var sTabUrl=oTabLink.getAttribute("urn");
				var sDataAreaId=oTabLink.getAttribute("rel");
				oCurrTAB.setActive=function(bactive){
					if(bactive){
						this.status="active";
						this.className=setClassName(this.className,"active");
					}else{
						this.status="normal";
						this.className=setClassName(this.className,"normal");
					}
				}
				oCurrTAB.LoadTab=function(){
					this.setActive(true);
					this.parentNode.activetab.setActive(false);
					this.parentNode.activetab=this;					
					var oTabLink=this.getElementsByTagName("a")[0];
					var sDataPreId=oTabLink.getAttribute("rel");
					if (oTabLink.getAttribute("urn").indexOf("#default")!=-1) {
						 getElt(sDataPreId+"_default").style.display="";
						 getElt(sDataPreId+"_ajah").style.display="none";
					} else {
						loadAJAXTab(oTabLink.getAttribute("urn"),sDataPreId+"_ajah");
						getElt(sDataPreId+"_default").style.display="none";
						getElt(sDataPreId+"_ajah").style.display="";
					}
				}
				oCurrTAB.onclick=function(aEvent){
					var myEvent = window.event ? window.event : aEvent;
					var fm=myEvent.fromElement;
					if(IsChild(fm,this) || fm==this) return(false);
					if(this.status=="active") return(false);
					this.LoadTab();
					return(false);
				}
				if(sTabUrl.indexOf("#default")!=-1){
					oCurrTAB.setActive(true);
					oTabBox.activetab=oCurrTAB;
				} else {
					oCurrTAB.setActive(false);
				}

			}
		if(oTabBox.activetab==null) oTabBox.activetab=arrTabs[0];
	}
}

function getXmlhttp() {
	var http_request;	
	if(window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject) { 
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) { 
		window.alert("can't create XMLHttpRequest object.");
		return null;
	}	
	return http_request;
}

function loadAJAXTab(url,contentid){
	var ocontent=getElt(contentid);
	var sNowTime=new Date();
	if(ajahCache[url]==null) {
		var xhttp=getXmlhttp();		
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1)) {					
					ocontent.innerHTML=xhttp.responseText;
					ajahCache[url]=ocontent.innerHTML;
				}
			}
		xhttp.open("GET",url,true);
		xhttp.send(null);
	}else{
		ocontent.innerHTML=ajahCache[url];
	}
}


//window.onerror=function(){return true}
