/* Function domTab()
	Based on http://www.onlinetools.org/tools/domtabdata
	written by Christian Heilmann
	Further modification by Driek Heesakkers
	(more robust errortrapping)
	Even further modification by Acdhirr
	(className assignments & complete view)
*/	

function domTab(i){

	// Variables for customisation:
	var maxNumberOfTabs = 9;
	// end variables
	
	if (document.getElementById){
	
		// unhiglight tab0 'complete view'
		if (testElem('tab0')) document.getElementById('tab0').className="";
	
		for ( f=1; f < maxNumberOfTabs+1; f++ ) {

			if ( f != i ) {
				// hide contentblock
				if (testElem('contentblock'+f)) document.getElementById('contentblock'+f).style.display='none';
				// if index is 0 fold out all tabs
				if (testElem('contentblock'+f) && i==0) document.getElementById('contentblock'+f).style.display='block';
				// gray-out tab
				if (testElem('tab'+f)) document.getElementById('tab'+f).className="";
			} 
			else {
				// show contentblock
				if (testElem('contentblock'+f)) document.getElementById('contentblock'+f).style.display='block';
				// highlight tab
				if (testElem('tab'+f)) document.getElementById('tab'+f).className="active";
			}
		}
		// if index is 0 highlight tab 0 (complete view)
		if (testElem('tab0') && i==0) document.getElementById('tab0').className="active";
	}
	return true;
}


function initTabs(nTab) {

	colLinks = document.getElementsByTagName("a");
	
	/* Any JavaScript enabled browser should ignore the anchored hyperlinks 
	attached to	the	tabs. Therefore they are ripped. */
	for (var i=0; i<colLinks.length; i++) {
		if (colLinks[i].className == "") {
			// Only remove when it points to an anchor
			if (colLinks[i].href.indexOf('#target') != -1) {
				colLinks[i].removeAttribute('href');
			}
		}
	}

	/* Open specified tab when present in url hash 
	var tab = document.location.hash.replace("#target","");
	
	for (var i=0; i<document.anchors.length; i++) {
		if (document.anchors[i].name == "target" + tab) {
			domTab(tab);
			return;
		}
	} */
	return (domTab(nTab));//default value 
}


function toggleID(oSender,id) {

	if (document.getElementById){
		if (testElem(id)) {
			var displaystate = document.getElementById(id).style.display;
			if ( displaystate != 'block' ) {
				displaystate = 'block';
				oSender.className = "listFieldToggleOff";
			} else {
				displaystate = 'none';
				oSender.className = "listFieldToggleOn";
			}
			
			document.getElementById(id).style.display = displaystate;
		}
	}
}


function testElem(e){
	if ( document.getElementById(e) ) {
		return true;
	} else {
		return false;
	}
}

/* Added by Mohamed */
/* add the tab=x parameter to the url */
function addTabParam(url) {

  var maxNumberOfTabs = 9;
	// end variables
	var activeTab = 0;
	
	if (document.getElementById){
		for ( f=1; f < maxNumberOfTabs+1; f++ ) {
		  if (testElem('tab'+f)) {
		    if (document.getElementById('tab'+f).className=='active') {
		      activeTab = f;      
		    }
		  }
		}
	}
  
  if (activeTab > 0 ) {
    url = url + ';tab=' + activeTab;
   }
  document.location = url;
}


