function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function P7_swapClass(){ //v1.4 by PVII
 var i,x,tB,j=0,tA=new Array(),arg=P7_swapClass.arguments;
 if(document.getElementsByTagName){for(i=4;i<arg.length;i++){tB=document.getElementsByTagName(arg[i]);
  for(x=0;x<tB.length;x++){tA[j]=tB[x];j++;}}for(i=0;i<tA.length;i++){
  if(tA[i].className){if(tA[i].id==arg[1]){if(arg[0]==1){
  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}else{tA[i].className=arg[2];}
  }else if(arg[0]==1 && arg[1]=='none'){if(tA[i].className==arg[2] || tA[i].className==arg[3]){
  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}
  }else if(tA[i].className==arg[2]){tA[i].className=arg[3];}}}}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function cursorhand() {
    if (navigator.userAgent.indexOf('MSIE')>0)
	document.body.style.cursor='hand';
    else
	document.body.style.cursor='pointer';
}

function cursordefault() {
    document.body.style.cursor='auto';
}

function OverResult(nr)
{
   if( el = document.getElementById('result'+nr) ) {
      if (el.className.substr(-2) != 'on') {
         el.className = el.className+'on';
      }
   }
}

function OutResult(nr)
{
   if (document.getElementById('Detail'+nr).style.display != 'none') return;
   ResetClass('result'+nr);
}

function ResetClass(id)
{
   if( el = document.getElementById(id) ) {
      pos = el.className.length-2;
      if (el.className.substr(pos,2) == 'on')
      {
         el.className = el.className.substr(0, pos);
      }
   }
}

function ToggleFeedback(nr)
{
   var id = 'Feedback' + nr
   if (document.getElementById(id).style.display=='none')
   {
      ShowLayerById(id)
      for(var a=1;a<=1000 && document.getElementById('Feedback' + a);a++)
      {
         if (id!='Feedback'+a)
	 {
            HideLayerById('Feedback' + a);
	 }
      }
   }
   else {
      HideLayerById(id);
   }
}

function submitFeedback($form,divID) {
	var xhr;
	try {
		xhr = new XMLHttpRequest();
	} catch(e) {
		xhr = new ActiveXObject(Microsoft.XMLHTTP);
	}

	xhr.onreadystatechange  = function() {
		if(xhr.readyState  == 4) {
			txt = xhr.responseText;
			if(xhr.status == 200) {
				if( $pc = document.getElementById(divID) ) {
					$pc.innerHTML=txt;
				}
			} else {
				if( $pc = document.getElementById(divID) ) {
					$pc.innerHTML=xhr.status + trl("An unknown error has occurred") + ': ' + txt;
				}
			}
		}
	};

	if( $form ) {
		$values = Array();
		$params = "";

		$elems = $form.elements;
		for( $i=0; $i<$elems.length; $i++ ) {
			if( $params ) $params += '&';
			$params += $elems[$i].name + '=' + $elems[$i].value;
		}
	}

	xhr.open("POST", "trac_feedback.php",  true);
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr.send( $params );
}

function ToggleDetail(nr)
{
   id = 'Detail' + nr;
   if (document.getElementById(id).style.display=='none') {
      ShowLayerById(id)
      OverResult(nr)
      for(var a=1;a<=1000 && document.getElementById('Detail' + a);a++) {
         if (a!=nr) {
            HideLayerById('Detail' + a);
            ResetClass('vacature' + a);
            ResetClass('result' + a);
         }
      }
//       setSessionProperty('showdetails', nr);
   } else {
      HideLayerById(id);
      ResetClass('vacature' + nr);
      ResetClass('result' + nr);
//       setSessionProperty('showdetails', 0);
   }
}

function CheckUncheckAll(obj)
{
   for(var a=0;a<document.forms[0].elements.length;a++)
   {
      if ( (document.forms[0].elements[a].type=='checkbox')  )
      {
         document.forms[0].elements[a].checked=obj.checked;
      }
   }
}

function ShowLayerById(id)
{
	if( $elem = document.getElementById(id) ) $elem.style.display = '';
}
function HideLayerById(id)
{
	if( $elem = document.getElementById(id) ) $elem.style.display = 'none';
}

function HideSearch()
{
   HideLayerById('searchnav')
   HideLayerById('searchopener')
   ShowLayerById('searchcloser')
}

function ShowSearch()
{
   ShowLayerById('searchnav')
   ShowLayerById('searchopener')
   HideLayerById('searchcloser')
}

var xmlhttpreq;

function setSessionProperty(property, value, statechangehandler)
{
    xmlhttpreq = newXMLHttpRequest();
    if (xmlhttpreq) {
	var url = window.location.protocol+'//'+window.location.host+window.location.pathname.substr(0,window.location.pathname.lastIndexOf('/')+1)+'setsessionproperty.php';
	//xmlhttpreq.onreadystatechange = showreqreturn;
	xmlhttpreq.open("POST", url, true);
	if (statechangehandler!=null) {
	    xmlhttpreq.onreadystatechange = statechangehandler;
	}
	xmlhttpreq.setRequestHeader("Content-Type", "text/xml");
	xmlhttpreq.send('<?xml version="1.0" encoding="UTF-8"?>'+"\n"+
		'<request>'+
		'<property>'+property+'</property>'+
		'<value>'+value+'</value>'+
		'</request>');
    }
}

function newXMLHttpRequest(){
    var req;
    if (window.XMLHttpRequest) { // Non-IE browsers
	try {
	    req = new XMLHttpRequest();
	} catch(e) {
	    req = false;
	}
    }
    else if (window.ActiveXObject) { // IE
	try {
	    req = new ActiveXObject('Microsoft.XMLHTTP');
	} catch(e) {
	    req = false;
	}
    }
    return req;
}

function showreqreturn()
{
    if (xmlhttpreq.readyState==4) {
	if (xmlhttpreq.status==200) {
	    alert('Response: '+xmlhttpreq.responseText);
	}
	else {
	    alert('Problem: '+xmlhttpreq.statusText);
	}
    }
}

