/*
  Utitlity functions die ik in meerdere projecten kan gebruiken.
  
  
*/


DOM = (document.getElementById) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
Konqueror = (navigator.userAgent.indexOf("Konqueror") > -1) ? 1 : 0;
Konqueror22 = (navigator.userAgent.indexOf("Konqueror 2.2") > -1 || navigator.userAgent.indexOf("Konqueror/2.2") > -1) ? 1 : 0;
Opera = (navigator.userAgent.indexOf("Opera") > -1) ? 1 : 0;
Opera5 = (navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1) ? 1 : 0;
Opera6 = (navigator.userAgent.indexOf("Opera 6") > -1 || navigator.userAgent.indexOf("Opera/6") > -1) ? 1 : 0;
Opera56 = Opera5 || Opera6;
IE = (navigator.userAgent.indexOf("MSIE") > -1) ? 1 : 0;
IE = IE && !Opera;
IE5 = IE && DOM;
IE4 = (document.all) ? 1 : 0;
IE4 = IE4 && IE && !DOM;
MOZ = (navigator.userAgent.indexOf("Gecko") > -1) ? 1 : 0;



var click_message="Deze functie is uitgeschakeld!";

/**************************************************************
algemene abstaherende functies
**************************************************************/

	function getDoc() {
		return window.document;
	}
	
	function getObject(id) {
		return window.document.getElementById(id);
	}
	
	function msg(String) {
		window.alert(String);
	}
	
/**************************************************************
EIDNE algemene abstaherende functies
**************************************************************/


function popupFail(link) {
	var aref = document.getElementById("__failde_link");
	aref.href = link;
	var div = document.getElementById("__failde_link_div");
	var datadiv = document.getElementById("_datadiv");
	var height = document.body.offsetHeight;
	var width = datadiv.offsetWidth;
	var dh = div.offsetHeight;
	var dw = div.offsetWidth;	
	var top = Math.round((height - dh) / 2);
	top=window.event.y + window.document.body.scrollTop
	var left =  Math.round((width - dw) / 2);
	if (MOZ) {
		div.style.top = "200px";
		div.style.left = "130px";
	} else {
		div.style.top = "300px";
		div.style.left = "250px";
	}
	div.style.zorder = 10000;
	div.style.visibility = "visible";	
}
	

function clickIE(){
	if (event.button==2){
		alert(click_message);
		return false;
	}
}

function clickMOZ(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
		alert(click_message);
		return false;
		}
	}
}

if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
	else if (document.all&&!document.getElementById){
	document.onmousedown=clickIE4;
}
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
		
	} //End While
	return strTemp;
	
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function


//document.oncontextmenu=new Function("alert(click_message);return false")

function ShowInfo(location) {
  mh = window.screen.availHeight;
  mw = window.screen.availWidth;
  w=540;
  h=650;
  l = (mw - w) / 2;
  t = (mh - h) / 2;

  window.open("/showinfo.php?file=" + location,"_blank","scrollbars=yes,location=no,height=" + h + ",width=" + w + ",left=" + l + ",top=" + t + ",menubar=no,status=no,titlebar=no,resizable=yes");
  return false;
}

function ShowInfoWindow(location) {
  mh = window.screen.availHeight;
  mw = window.screen.availWidth;
  w=540;
  h=650;
  l = (mw - w) / 2;
  t = (mh - h) / 2;
  window.open(location,"_blank","scrollbars=yes,location=no,height=" + h + ",width=" + w + ",left=" + l + ",top=" + t + ",menubar=no,status=no,titlebar=no,resizable=yes");
  return false;
}



function hideInfoDiv(fire,name)
{
	var obj = document.getElementById(name);
	obj.style.visibility = "hidden";
}

function showInfoDiv(fire,name,height)
{
	var obj = document.getElementById(name);
	var innerHTML = obj.innerHTML;
	pos = innerHTML.indexOf("deletepic.gif")
	if (pos == -1) {
	 obj.innerHTML = "<img src=\"images/deletepic.gif\" title=\"" + txt_close_window + "\" onclick=\"hideInfoDiv('" + fire + "','" + name + "')\"><br>" + innerHTML;
  }
	obj.style.zIndex=99;
  if (obj.getAttribute("centered") == "true") {
    w = obj.style.width;
    if (isNaN(w)){ w=w.substr(0,w.length-2); }
    obj.style.left = ((500 - w) / 2);
    if (obj.style.top == "") {
    	obj.style.top=200 + window.document.body.scrollTop;
   	}
   } else {
	  if (obj.getAttribute("centered") == "none") {
	  		//onzin
	  		var testingvar = 0;
	  } else {
	  	obj.style.left=window.event.x + window.document.body.scrollLeft + 4;
	  	obj.style.top=window.event.y + window.document.body.scrollTop + 4;
	  }
  }
	obj.style.visibility = "visible";
	obj.scrollIntoView;
	if (height != 0 ) {obj.style.height = height;}
}

function toggleInfoDiv(fire,name,width) {
	if (fixedcenter = null) {fixedcenter = "true";}
	  if (width == null) {
	  	showOKDialog(document.getElementById(name).innerHTML,'info','45em',fixedcenter);
	  } else {
	  	showOKDialog(document.getElementById(name).innerHTML,'info',width,fixedcenter);
	  }
 }
 
 
function checkJava() {
	var _javachecker = $("javachecker");
	if (_javachecker != null) {
		setTimeout(function () {
			_javachecker.innerHTML = '<APPLET code="JavaTester.class" codebase="/java/" align="baseline" ' +
				'    width="200" height="200" mayscript="yes" > ' +
				' <param name = "scriptable" value="true"> '  +
	    		' <param name = "mayscript" value="yes"> '  +
				' </APPLET>	';
		},2000);
	}
}

function javaversion(version) {
	SetCookie('javaversion',version,null,'/');
}

function openCentered(location, width, height) {
  mh = window.screen.availHeight;
  mw = window.screen.availWidth;
  w=width;
  h=height;
  l = (mw - w) / 2;
  t = (mh - h) / 2;
  window.open(location,"_blank","scrollbars=yes,location=no,height=" + h + ",width=" + w + ",left=" + l + ",top=" + t + ",menubar=no,status=no,titlebar=no,resizable=yes");
  return false;
}

 