// navigation

sfHover = function() {
		
    if (!document.body.currentStyle) return;
	var el=document.getElementById("mainNavigation");
	if(!el) return;
    var sfEls = el.getElementsByTagName("li");
    for (var i = 0; i < sfEls.length; i++)
    {
        sfEls[i].onmouseover = function()
        {
            if (this.lastChild.style)
            {
                this.lastChild.style.display = 'block';
            }
        }
        sfEls[i].onmouseout = function()
        {
            if (this.lastChild.style)
            {
                this.lastChild.style.display = 'none';
            }
        }
    }
}
window.onload = sfHover;

// openpicwin
function openPicWin(pFileName,pWinName,pWidth,pHeight) {
	var isNS = (document.layers) ? true : false;
	
	if (isNS) pHeight = pHeight + 19;
		eval("allSettings = 'width="+pWidth+",height="+pHeight+",menubar=yes,scrollbars=yes,status=yes,resizable=yes'");
		w=window.open(pFileName,pWinName,allSettings);
		w.window.focus();
}

// functions for iframe expander in all various browsers
function getIFrameDoc( name ) {
  var IFrameDoc;
  var Height;
  var IFrameObj = document.getElementsByName(''+name)[0];
  
  if (typeof document.frames != 'undefined') {
    IFrameObj = document.frames[name];
  }
  
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
  	return false;
  }
  
  if(typeof IFrameDoc.body != 'undefined')
  {
    return IFrameDoc.body;
  }
  else
  {
    return IFrameDoc.documentElement;
  }
}

/* gets the height of an iframe document */
function getIFrameDocHeight( name )
{
var IFrameDoc = getIFrameDoc( name );
  if(typeof IFrameDoc == 'undefined')
    return false;
  return IFrameDoc.scrollHeight;
}

/* gets the width of an iframe document */
function getIFrameDocWidth( name )
{
var IFrameDoc = getIFrameDoc( name );
  if(typeof IFrameDoc == 'undefined')
    return false;
  return IFrameDoc.scrollWidth;
}




if (document.location.href.indexOf("tp://sites")>0)
	pathVar = "http://sites/ilef.ch/"; 
else 
{
	if(document.location.href.indexOf("tp://www.insign.ch/kunden/")>0)
		pathVar = "http://www.insign.ch/kunden/ilef.ch/";
	else
		if(document.location.href.indexOf("tp://extranet.insign.ch/ilef.ch/")>0)
			pathVar = "http://extranet.insign.ch/ilef.ch/";
		else
			if(document.location.href.indexOf("tp://ilef-ch.insign.ch/")>0)
				pathVar = "http://ilef-ch.insign.ch/";
			else
			{
				if (document.location.href.indexOf("tps://www.ilef.ch/") > 0)
					pathVar = "https://www.ilef.ch/";
				else
					pathVar = "http://www.ilef.ch/";
			}
}


var pic_off_ar = new Array();
var pic_on_ar = new Array();

pic_on_ar["ico_home"] = "images/icons/ico_home_ms.gif";
pic_off_ar["ico_home"] = "images/icons/ico_home_off.gif";

pic_on_ar["ico_sitemap"] = "images/icons/ico_sitemap_ms.gif";
pic_off_ar["ico_sitemap"] = "images/icons/ico_sitemap_off.gif";

pic_on_ar["ico_suche"] = "images/icons/ico_suche_ms.gif";
pic_off_ar["ico_suche"] = "images/icons/ico_suche_off.gif";

pic_on_ar["ico_online_schalter"] = "images/icons/ico_online_schalter_ms.gif";
pic_off_ar["ico_online_schalter"] = "images/icons/ico_online_schalter_off.gif";

pic_on_ar["ico_drucken"] = "images/icons/ico_drucken_ms.gif";
pic_off_ar["ico_drucken"] = "images/icons/ico_drucken_off.gif";

pic_on_ar["ico_az"] = "images/icons/ico_az_ms.gif";
pic_off_ar["ico_az"] = "images/icons/ico_az_off.gif";

pic_on_ar["ico_rss"] = "images/icons/ico_rss_ms.gif";
pic_off_ar["ico_rss"] = "images/icons/ico_rss_off.gif";


var pic_off = new Array();
var pic_on = new Array();
for (var i in pic_off_ar)
{
	pic_off[i] = new Image();
	pic_off[i].src = pathVar+pic_off_ar[i];
	pic_on[i] = new Image();
	pic_on[i].src = pathVar+pic_on_ar[i];
}

function mouseEnter(name,text)
{
	if(!text)
		text="";
	

	if (document.images)
		document.images[name].src = pic_on[name].src;
	window.status=text;
	return true;
}

function mouseExit(name)
{
	if (document.images)
		document.images[name].src = pic_off[name].src;
	window.status="";
	return true;
}

function goToSearch(myform)
			{
				var searchstring = "";
				
				searchstring = myform.elements['newsearch'].value;
				
				if (searchstring.length<3)
				{
					alert("Bitte geben Sie im Suchfeld mindestens 3 Zeichen ein.");
					return false;
					
				}
				else
				{
					myform.elements['keyword'].value = myform.elements['newsearch'].value;
					return true;
				}
} 







// call after every checkbox that needs to be checked or not according to the state of trigger
// trigger can either be 0 or 1 or false or true
// example for call: <input type=checkbox ....><script>checkboxChecker("%module.criteria%")</script>
function checkboxChecker(trigger)
{
if(trigger.substr(0,1)=='%') return;	
document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1].checked=parseInt(trigger);
}


// call after every selectbox whitch items need to be selected according to the state of trigger
// trigger can be one or more values (comma-separated). Every item with the same value as on of the triggers will be selected
// example for call: <select ....><script>selectSelecter("%module.criteria%")</script>
function selectSelecter(trigger,defaultvalue)
{

	if(trigger.substr(0,1)=='%')
	{
		if(defaultvalue) trigger=defaultvalue;
		else return 0;
	}

	myselect=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
	items = trigger.split(",");
	for(j=0;j<myselect.options.length;j++)
	{
		myselect.options[j].selected=false;
	}
	for(i=0;i<items.length;i++)
	{
		for(j=0;j<myselect.options.length;j++)
		{
			if(myselect.options[j].value==items[i])
			{
				myselect.options[j].selected=true;
			}
			

		}

	}
	if(myselect.selectedIndex>=0) return myselect.selectedIndex;
	else return 0;
}

// call after the last radiobutten whitch items need to be selected according to the state of trigger
// trigger must be one of the values of the radio-buttons. 
// example for call: <input type="radio" value="pic_ico_graph.gif" name="content.data[type]><script>checkRadios("%module.criteria%")</script>

function checkRadios(trigger)
{
	if(trigger.substr(0,1)=='%') return;	
	
	myselect=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
	myradio = document.forms[document.forms.length-1].elements[myselect.name];
	for(i=0;i<myradio.length;i++)
	{
		if(myradio[i].value==trigger)
		{
			myradio[i].checked=true;
			break;
		}
		
	}
	
}


// call in the end of HTML-Code
// <script>formClearer()</script>
// scans all fields of all forms of the current document and clears them if value starts with %
function formClearer()
{
	for(i=0;i<document.forms.length;i++)
	{
		for(j=0;j<document.forms[i].elements.length;j++)
		{
			if(document.forms[i].elements[j].value)
			{
				if(document.forms[i].elements[j].value.substr(0,1)=="%")
				{
					document.forms[i].elements[j].value="";
				}
			}
		}
	}
	
	setFocus();
}







// call after the form element which focus needs to be set
// example for call: <input type=checkbox ....><script>setFocus()</script>
var focusobject=null;

function setFocus()
{
	if(focusobject)
		focusobject.focus();
	else
	{
		if(!document.forms.length) return;
		focusobject=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
		focusobject.focus();
		
	}
}

// call after the form element which focus needs to be unset
// example for call: <input type=checkbox ....><script>blurIt()</script>

function blurIt()
{
	if(!document.forms.length) return;
	focusobject=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
	focusobject.blur();
}