isOP = (navigator.userAgent.indexOf('Opera') > 0)?true:false;
isIE = (navigator.appName=='Microsoft Internet Explorer' && !isOP)?true:false;
isMOZ = (navigator.appName.indexOf=='Netscape')?true:false;

if (!document.getElementById){
	document.getElementById = function(){return null;}
	document.getElementsByTagName = function(){return null;}
}

// Load functions
onLoadList = new Array();
function addOnLoad(func){
	onLoadList[onLoadList.length] = func;
}

function runOnLoad(){
	for(i in onLoadList){
		var addPar = "";
		if (onLoadList[i].indexOf("(") == -1) addPar = "()";
		eval(onLoadList[i]+addPar);
	}
}
if(location.href.indexOf('/admin') == -1){
	addOnLoad('styleCustomLayoutTables');
}else{
	addOnLoad('toggleSpecStatOnLoad');
}
addOnLoad('setNavItem');
addOnLoad('setCustDrop');
addOnLoad('parseLinks');
addOnLoad('setDiseaseTable');
addOnLoad('setHider');
if(location.href.indexOf('WBCMODE=AuthoringReedit') != -1 || location.href.indexOf('WBCMODE=AuthoringNew') != -1 || location.href.indexOf('wbc_purpose=Authoring') != -1){
	addOnLoad('initToggle');
}

window.onload = runOnLoad;



// Functions
function setHider(){
	if(document.getElementById('hider')){
		hi = document.getElementById('hider');
		hi.style.position = 'relative';		
		hiImg = document.createElement('img');
		hiImg.src = '/Resources/include/blank.gif';
		hiImg.style.position = 'absolute';
		//hiImg.style.background = 'red';
		hiImg.style.left = '0px';
		hiImg.style.top = '20px';
		hiImg.style.width = hi.offsetWidth + 'px';
		hiImg.style.height = hi.offsetHeight -20 + 'px';
		hi.appendChild(hiImg);
		
	}
}
function styleCustomLayoutTables(){
	tableCount=document.getElementsByTagName('table');
	for(var i=0;i<tableCount.length;i++){
		if(tableCount[i].className.indexOf('static') != -1){
			setRowClass(tableCount[i]);			
		}
	}
}
function setRowClass(obj){
	rowCount = obj.getElementsByTagName('tr')
	for(var i=0;i<rowCount.length;i++){
			rowCount[i].getElementsByTagName('td')[0].className = 'colOne';
			/*
			if(i != 0 && obj.className.indexOf('static') == -1){
				rowCount[i].onmouseover = function(){
					this.className += 'Over';	
				}
				rowCount[i].onmouseout = function(){
					this.className = (this.className == 'oddOver') ? this.className = 'odd' : this.className = '';
				}
			}
			*/
	}
	if(rowCount.length >= 1){
		rowCount[0].className='th';
		for(var i=2;i<rowCount.length;i+=2){
			rowCount[i].className='odd';
		}
		for(var j=1;j<rowCount.length;j+=2){
			rowCount[j].className='';
		}
	}
}

function setNavItem(){
	var navElem = document.getElementById('nav');
	if(navElem){
		var navRoot = navElem.getElementsByTagName('UL')[0];
		if (navRoot)
		{
		var navNodes = navRoot.childNodes;
		for(var i=0;i<navNodes.length;i++){
			navNodes[i].style.zIndex = 50-i;
			if(i > 0){
				posX = navNodes[i-1].offsetLeft + navNodes[i-1].offsetWidth + 4;
				navNodes[i].style.left=posX+'px';
			}
			if(navNodes[i].className == 'sel'){
				navNodes[i].style.zIndex = 99;
			}else{
				navNodes[i].onmouseover = function(){
					this.className = 'over';
				}
				navNodes[i].onmouseout = function(){
					this.className = '';
				}
			}
		}
		}
	}
}
function setCustDrop(){
	var toggler = document.getElementById('customer');
	if(toggler){
		toggler.onmousedown = function(){
			var navNode = toggler.parentNode;
			navNode.className = (navNode.className == 'custOn') ? '' : 'custOn';
		}
	}
}
function parseLinks() 
{   
	var doc = document.getElementById('content');

	var mode1024 = (doc.offsetWidth > 630) ? true: false;
	var popWidth = (mode1024) ? 685 : 500;
	var popWidthFull = (mode1024) ? 857 : 672;
		
	var a = doc.getElementsByTagName('a');

	for (var i=a.length;i!=0;i--) {
		var c = a[i-1];
		if (!c.href) continue;
		if (c.className.indexOf('popUp') == -1) continue;
		c.onclick = function() {
			/*var w = (this.className == 'popUpFull') ? popWidthFull : popWidth;*/
			
			var w = popWidth;
			if(this.className == 'popUpFull')
			    w = popWidthFull;
			else if(this.className == 'popUpTall')
			    w = popWidthFull;   
			
			var wProps = 'width=' + w + ',height=400,scrollbars=1,toolbar=0,status=1,resizable=1';
			if(this.className == 'popUpCal')wProps = 'width=230,height=180,scrollbars=0,toolbar=0,status=0,resizable=1';
			if(this.className == 'popUpTall')wProps = 'width=' + w + ',height=750,scrollbars=1,toolbar=0,status=0,resizable=1';
			var win = window.open(this.href,'',wProps);
			if (win) return false;
		}
	}
}
function setDiseaseTable(){
	disTable = document.getElementById('disease');
	if(disTable){
		var checks = disTable.getElementsByTagName('input');
		for(i=0; i < checks.length; i++){
			checks[i].onmousedown = setDisease;
			checks[i].onmouseout = operaDiseaseFix;
			if(checks[i].checked){
				checks[i].parentNode.parentNode.className = checks[i].parentNode.className;
			}
		}
	}
}
function setDisease(){
	disRow = this.parentNode.parentNode;
	disRowChecks = disRow.getElementsByTagName('input');
	for(i=0; i < disRowChecks.length; i++){
		if(disRowChecks[i] != this){
			disRowChecks[i].checked = false;
		}
	}
	disRow.className = (this.checked) ? '' : this.parentNode.className;	
}
function operaDiseaseFix(){
	this.checked = (this.parentNode.parentNode.className == this.parentNode.className)?true:false;
}


// CreunaMCMSLib functions
function initToggle(){
	elems = getCheckBoxesByParentNodeClassName('mcmsLibToggle');
	for(i=0;i<elems.length;i++){
		
		//Show already active on onLoad
		if(elems[i].checked){
			elems[i].parentNode.parentNode.className = 'on';
		}
		
		//Attatch functions
		elems[i].onmousedown = setToggle;
		elems[i].onmouseout = maxCompat;
	}
}

function setToggle(){
	this.parentNode.parentNode.className = (this.checked)?'':'on';
}

function maxCompat(){
	this.checked = (this.parentNode.parentNode.className == 'on')?true:false;
}

function getCheckBoxesByParentNodeClassName(clName){
	checkBoxCollection = new Array();
	inputs = document.getElementsByTagName('input');
	for(i=0;i<inputs.length;i++){
		if(inputs[i].type == 'checkbox' && inputs[i].parentNode.className == clName){
			checkBoxCollection.push(inputs[i]);
		}
	}
	return checkBoxCollection;
}
function toggleSpecStatOnLoad(){
	if(document.getElementById('specStat') && document.getElementById('specStatToggler')){
		if(document.getElementById('specStatToggler').childNodes[0].checked){
			document.getElementById('specStat').style.display = 'block';
		}
	}
}
function toggleSpecStat(obj){
	isChecked = obj.childNodes[0].checked;
	obj.childNodes[0].checked = !isChecked;
	if(isChecked){
		document.getElementById('specStat').style.display = 'none';
	}
	else{
		document.getElementById('specStat').style.display = 'block';
	}
}
function togglePane(id){
	navs = document.getElementById('contentNav').getElementsByTagName('li');
	panes = document.getElementById('contentPanes').childNodes;
	for(var i = 0;i < panes.length;i++){
		navs[i].className = "";
		panes[i].className = "skip";
	}
	navs[id].className = "sel";
	panes[id].className = "";
}
function toggleBetingetHistory(){
	if(document.getElementById('divBetingetCurrent') && document.getElementById('divBetingetHistory')){
		document.getElementById('divBetingetCurrent').className = "skip";
		document.getElementById('divBetingetHistory').className = "";
	}
}
