// JS-Functions for cf.protal4


//---[switch elements on/off ]--------------------------------------------------------------
function toggle(obj) {
	var el = document.getElementById(obj);
	var elPic = document.getElementById(obj + "Pic");
		if ( el.style.display != 'none' ) {
				el.style.display = 'none';
				elPic.src = "../zz/images/pic_plus.gif";
				sendXMLDoc('../sys/session.cfm?SettingTable=false');
		} else {
				el.style.display = 'block';
				elPic.src = "../zz/images/pic_minus.gif";
				sendXMLDoc('../sys/session.cfm?SettingTable=true');
		}
}

//---[select checkboxes ]--------------------------------------------------------------
function checkAllbox(formname, checkname, bState) {
	//var el_collection=eval("document.forms."+formname+"."+checkname)
	var el_collection = document.getElementsByName("Sel");	
	for (i=0;i<el_collection.length;i++) el_collection[i].checked=bState;		
}

//---[set Focus on Field ]----------------------------------------------------------
function setFocus( elementname ) {
	if (elementname != '' && document.getElementById(elementname)) document.getElementById(elementname).focus();
}

//---[show PopupWindow ]----------------------------------------------------------
function showSelect(URL, anchor, width, height) {
	var win = new PopupWindow();
	win.autoHide();
	if(!width) var width = 750;
	if(!height) var height = 450;
	win.setSize(width,height);
	win.offsetX = 20;
	win.offsetY = -150;
	win.setWindowProperties("toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable,alwaysRaised,dependent,titlebar=no");
	win.setUrl(URL);
	win.showPopup(anchor);
}

//---[set index/register ]----------------------------------------------------------
function setIndexA(v) {
	document.frmSort.FilterIndex.value=v;			
	document.frmSort.submit();
	return true;
}

//---[set export ]----------------------------------------------------------
function setHiddenField(Feld, Wert) {
	document.getElementById(Feld).value=Wert;			
	document.frmSort.submit();
	document.getElementById(Feld).value='';
	return true;
}

//---[css menubar horizontal ]--------------------------------------------------------------
var cssmenuids=["menu1"] //Enter id(s) of CSS Horizontal UL menus, separated by commas
var csssubmenuoffset=-1 //Offset of submenus from main menu. Default is 0 pixels.

function createcssmenu2(){
  for (var i=0; i<cssmenuids.length; i++){    
    try {
      var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul")
      for (var t=0; t<ultags.length; t++){
        ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
        var spanref=document.createElement("span")
        spanref.className="arrowdiv"
        spanref.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;"
        ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
        ultags[t].parentNode.onmouseover=function(){
          this.style.zIndex=100
  	  this.getElementsByTagName("ul")[0].style.visibility="visible"
	  this.getElementsByTagName("ul")[0].style.zIndex=0
        }
        ultags[t].parentNode.onmouseout=function(){
	  this.style.zIndex=0
	  this.getElementsByTagName("ul")[0].style.visibility="hidden"
	  this.getElementsByTagName("ul")[0].style.zIndex=100
        }
      }
    }	  
    catch(err) {}
  }
}

//if (window.addEventListener)
//window.addEventListener("load", createcssmenu2, false)
//else if (window.attachEvent)
//window.attachEvent("onload", createcssmenu2)


//---[page tabs ]--------------------------------------------------------------
function ShowNav(panelShow, tabShow) {
	obj = document.getElementById('panels');	
	for (i=0;i<obj.childNodes.length;i++) {
		if (typeof obj.childNodes[i].id == 'string') obj.childNodes[i].style.display='none';
	}
	document.getElementById(panelShow).style.display='block';
	obj = document.getElementById('tabs');
	for (i=0;i<obj.childNodes.length; i++) {
		if (typeof obj.childNodes[i].id == 'string') obj.childNodes[i].className='tab';		
	}
	document.getElementById(tabShow).className='tabOn';
	//document.getElementById('TabOn').value=tabShow;
	document.getElementsByName('TabOn')[0].value = tabShow;
}

//---[insert TextModul ]--------------------------------------------------------------
function insertTextModul(objSelect, objText) {
	var i = objSelect.selectedIndex;
	if (i != 0) {
		objText.value = objText.value + String.fromCharCode(10) + objSelect.options[i].value;
		objSelect.selectedIndex = 0;
	}	
	return true;
}

//---[tooltip ]--------------------------------------------------------------
/***********************************************
* Cool DHTML tooltip script II- ? Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
* /changed by eco-vision 
***********************************************/
var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip
var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=13 //Customize y offset of tooltip DIV relative to pointer image

document.write('<div id="con1"></div>') //write out container DIV
document.write('<div id="tooltip"></div>') //write out tooltip DIV
document.write('<img id="tippointer" src="../zz/images/icon_arrow_tt.gif">') //write out pointer image
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["tooltip"] : document.getElementById? document.getElementById("tooltip") : ""
var pointerobj=document.all? document.all["tippointer"] : document.getElementById? document.getElementById("tippointer") : ""

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtip(thetext, thewidth, isSicky){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+'px';
		if (typeof isSicky!="undefined" && isSicky) {
			tipobj.innerHTML='<a href="#" onclick="hidetip();" id="tipheader">[X]</a>'+thetext;			
			document.onmousemove="";
			enabletip=true;
			positiontip(event);				
		}
		else {
			document.onmousemove=positiontip;
			tipobj.innerHTML=thetext;
			enabletip=true;
		}
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			nondefaultpos=true
		}
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
		}

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
		}
		else{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
		tipobj.style.visibility="visible"
		if (!nondefaultpos) 
			pointerobj.style.visibility="visible"
		else pointerobj.style.visibility="hidden"
	}
}

function hidetip() {
	if (ns6||ie){
		enabletip=false;
		tipobj.style.visibility="hidden";
		pointerobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}

//---[AJAX ]--------------------------------------------------------------
function sendXMLDoc(url) {
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			//req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChange()
{
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			//response  = req.responseXML.documentElement;
			//keepAlive    = response.getElementsByTagName('keepAlive')[0].firstChild.data;
			//alert(keepAlive);
			//eval(method + '(\'\', result)');
		} else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

