/**
 *
 * Alternative javascript functions
 *
 */

function ecmHideShow (hide,show) {

	if ((hide!=null)&&(hide!="")) {
		document.getElementById(hide).style.display="none"
	}

	if ((show!=null)&&(show!="")) {
		document.getElementById(show).style.display=""
	}

}

function ecmToggleDisplay (elm) {
	if (elm.style.display=="") {
		elm.style.display="none";
	} else {
		elm.style.display="";
	}
}

function ecmToggleDisplayById (elmid) {
	var elm=document.getElementById(elmid)
	if (elm!=null) {
		ecmToggleDisplay(elm);
	}
}


function ecmToggleDisplayByAttribute (attrname,attrvalue,multi) {
	var elms=document.getElementsByAttribute(attrname,attrvalue,multi);
	if ((elms!=null)&&(elms.length>0)) {
		for (i=0;i<elms.length;i++) {
			ecmToggleDisplay(elms[i]);
		}
	}
}


function ecmSelectSection(sectionid) {

	rows=document.getElementById("sections").getElementsByTagName('td');
	if (rows==null) return false;

	for (i=0;i<rows.length;i++) {

		if ((rows[i].id!=null)&&(rows[i].id!="")) {

			if ((sectionid+"Off"!=rows[i].id)&&(sectionid+"On"!=rows[i].id)) {
				if (rows[i].id==rows[i].getAttribute("sectionid")+"Off") {
					document.getElementById(rows[i].id).style.display='';
				}
				if (rows[i].id==rows[i].getAttribute("sectionid")+"On") {
					document.getElementById(rows[i].id).style.display='none';
				}
			}
			if ((sectionid+"Off"==rows[i].id)||(sectionid+"On"==rows[i].id)) {
				if (rows[i].id==rows[i].getAttribute("sectionid")+"Off") {
					document.getElementById(rows[i].id).style.display='none';
				}
				if (rows[i].id==rows[i].getAttribute("sectionid")+"On") {
					document.getElementById(rows[i].id).style.display='';
				}
			}
		}

	}

}

function ecmShowSection (sectionid) {

	var sectionlist=_PFWGUI["navigation.sections"];
	if (_PFWGUI["navigation.plugins"]!="") {
		sectionlist+=","+_PFWGUI["navigation.plugins"];
	}

	var sections=sectionlist.split(",");
	var funcleft="/main/func.left.php";

	for (i=0;i<sections.length;i++) {
		if (document.getElementById(sections[i])!=null) {
			if (sectionid!=sections[i]) {
				document.getElementById(sections[i]).style.display='none';
			} else {
				if ((_PFWGUI["navigation.section."+sections[i]+".funcleft"]!=null)&&(_PFWGUI["navigation.section."+sections[i]+".funcleft"]!="")) {
					funcleft=_PFWGUI["navigation.section."+sections[i]+".funcleft"];
				}
				ecmLoad(funcleft,'','');
				top.fApp.fLeftTree.document.getElementById(sections[i]).style.display='';
			}
		}
	}

	var items=_PFWGUI["navigation.section."+sectionid].split(",");
	for (i=0;i<items.length;i++) {
		eval("mytree=my"+items[i]+"tree;")
		if (mytree) {
			if ((_PFWGUI["navigation.section."+sectionid+"."+items[i]+".autoreload"]!=null)&&(_PFWGUI["navigation.section."+sectionid+"."+items[i]+".autoreload"]=="1")) {
				guiTreeReload(mytree);
			}
			if ((_PFWGUI["navigation.section."+sectionid+"."+items[i]+".autoopen"]!=null)&&(_PFWGUI["navigation.section."+sectionid+"."+items[i]+".autoopen"]=="1")) {
				guiTreeExpand(mytree,"dmy"+items[i]+"tree");
			}
		}
	}

}


function ecmTabSwap (tabname,tabid,fire) {

	check=true;
	if (fire!='') {
		eval ("check="+fire+";");
	}

	if (check) {

		lastActive=document.getElementById("guiTab_"+tabname).getAttribute('active_tab');

		document.getElementById("guiTabHeader_"+tabname+"_"+lastActive+"_on").style.display='none';
		document.getElementById("guiTabHeader_"+tabname+"_"+lastActive+"_off").style.display='';
		document.getElementById("guiTabContent_"+tabname+"_"+lastActive).style.display='none';

		document.getElementById("guiTabHeader_"+tabname+"_"+tabid+"_off").style.display='none';
		document.getElementById("guiTabHeader_"+tabname+"_"+tabid+"_on").style.display='';
		document.getElementById("guiTabContent_"+tabname+"_"+tabid).style.display='';

		document.getElementById("guiTab_"+tabname).setAttribute('active_tab',tabid);

	}

}

function ecmShowLoading() {
	if (document.getElementById('ecmLoadingDiv')!=null) {
		if (!document.all) {
			document.getElementById('ecmLoadingDiv').style.position="fixed";
			document.getElementById('ecmLoadingImg').style.position="fixed";
		} else {
			document.getElementById('ecmLoadingDiv').style.position="absolute";
			document.getElementById('ecmLoadingImg').style.position="absolute";
			document.getElementById('ecmLoadingDiv').style.top=document.body.scrollTop;
		}
		document.getElementById('ecmLoadingDiv').style.width="100%";
		document.getElementById('ecmLoadingDiv').style.height="100%";
		document.getElementById('ecmLoadingImg').style.left=((document.body.clientWidth/2)-(document.getElementById('ecmLoadingImg').width/2))*100/document.body.clientWidth+"%";
		document.getElementById('ecmLoadingImg').style.top=((document.body.clientHeight/2)-(document.getElementById('ecmLoadingImg').height/2))*100/document.body.clientHeight+"%";
		document.getElementById('ecmLoadingDiv').style.display='';
		document.getElementById('ecmLoadingImg').style.display='';
	}
}


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;
  } else {
    alert("Handler could not be removed");
  }
} 


function prepareTextBoxes(){
	if (!document.getElementsByTagName) return;
	var oi=0;
	var thisObj;
	var objs = document.getElementsByTagName("input");
	for (oi=0;oi<objs.length;oi++) {
		thisObj = objs[oi];
		if((thisObj.getAttribute('type') == 'text')||(thisObj.getAttribute('type') == 'password')||(thisObj.getAttribute('type') == 'file')){
			thisObj.className = 'textinputs';
		} else if ((thisObj.getAttribute('type') == 'button')||(thisObj.getAttribute('type') == 'submit')||(thisObj.getAttribute('type') == 'reset')) {
			thisObj.className = 'buttoninputs';
		}
	}
	var objs = document.getElementsByTagName("select");
	for (oi=0;oi<objs.length;oi++) {
		thisObj = objs[oi];
		thisObj.className = 'textinputs';
	}
}

addEvent(window, "load", prepareTextBoxes);
