/* -----------------------------------------------
   Floating layer - v.1
   (c) 2006 www.haan.net
   contact: jeroen@haan.net
   You may use this script but please leave the credits on top intact.
   Please inform us of any improvements made.
   When usefull we will add your credits.
   Used and improved bij eP - 2010
  ------------------------------------------------ */
  




function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function MakeRequest(fileName)
{
document.getElementById('ContentDiv').innerHTML = '<center><div style="margin-top:70px;"><img style="height:17px;width:70px;" src="../view/images/loadbar7016.gif"></div></center>';
  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponse(xmlHttp.responseText);
    }
  }
  xmlHttp.open("GET", "?page=ajaxrequest&fname="+fileName, true); 
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlHttp.send(null);
}


function HandleResponse(response)
{
  document.getElementById('ContentDiv').innerHTML = response;
}







function MakeRequestChatboxOne(div,funct,parameter)
{
  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponseChatboxOne(xmlHttp.responseText,div);
    }
  }
  xmlHttp.open("GET", "?page=ajaxrequestchatbox&function="+funct+"&parameter1="+parameter, true); 
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlHttp.send(null);
}


function HandleResponseChatboxOne(response,div)
{
  document.getElementById(div).innerHTML = response;
}







function MakeRequestLogin(fileNameLogin,newFile,gebrNaam,wWoord,pageLoad)
{
if(newFile == ''){
var newFile = 'ajaxrequestlogin.php';
}
  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponseLogin(xmlHttp.responseText);
    }
  }
  xmlHttp.open("POST", "/controller/" + newFile, true); 
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlHttp.send('AjaxLogin=' +fileNameLogin+ '&inlogUser=' +gebrNaam+ '&inlogPass=' +wWoord+ '&pageLoad=' +pageLoad);
}



function HandleResponseLogin(responseLogin)
{
document.getElementById('LoginDiv').innerHTML = parseScript(responseLogin);;
}







function MakeRequestZoek(zoekString)
{
document.getElementById('zoekopdrachtdiv').innerHTML = '<img style="height:12px;width:70px;" src="../view/images/loadbar7016.gif">';
var newFile = 'ajaxzoeken.php';

  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponseZoek(xmlHttp.responseText);
    }
  }
  xmlHttp.open("POST", "/controller/" + newFile, true); 
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlHttp.send('zoeken=' +zoekString);
}


function HandleResponseZoek(responseZoek)
{
document.getElementById('zoekopdrachtdiv').innerHTML = parseScript(responseZoek);
}




function MakeRequestZoekUnit(zoekUnit)
{
document.getElementById('zoekunitdiv').innerHTML = '<img style="height:12px;width:70px;" src="../view/images/loadbar7016.gif">';
var newFile = 'unitzoeken.php';

  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponseZoekUnit(xmlHttp.responseText);
    }
  }
  xmlHttp.open("POST", "/controller/" + newFile, true); 
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlHttp.send('zoekunit=' +zoekUnit);
}


function HandleResponseZoekUnit(responseZoekUnit)
{
document.getElementById('zoekunitdiv').innerHTML = parseScript(responseZoekUnit);
}






function parseScript(_source)
{
		var source = _source;
		var scripts = new Array();
 
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
 
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
 
		// Loop through every script collected and eval it
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
				// do what you want here when a script fails
			}
		}
		// Return the cleaned source
		return source;
}



	
function GetInnerSize () {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}



function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

	

function placeIt(objInfo)
{
	var inner = GetInnerSize();
	var x,y;
	x = (inner[0]/2)-250;
	y = 0;
	z = (inner[1]/2)-160;
	y = z + y;
	objInfo = document.getElementById(objInfo);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	objInfo.style.left = theLeft + 'px';
	objInfo.style.top = theTop + 'px';
	
	var valElementInfo = getStyle(document.getElementById("ResponseDiv"), "visibility");
	if(valElementInfo == "visible"){
		setTimeout("placeIt('ResponseDiv')",7);	
	}
	else{

	}
}
	
	
document.onload = setTimeout("placeIt('ResponseDiv')",25);	

function setVisible(objInfo)
{
	objInfo = document.getElementById(objInfo);
	objInfo.style.visibility = 'visible';
	objInfo.style.height = '320px';
	objInfo.style.width = '500px';
	setLocation = placeIt('ResponseDiv');	
}

function setHide(objInfo)
{
	objInfo = document.getElementById(objInfo);
	objInfo.style.visibility = 'hidden';
	objInfo.style.height = '1px';
	objInfo.style.width = '1px';

}





function getPositionTop(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    finalvalue = topValue;
    return finalvalue;
}

function getPositionLeft(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    finalvalue = leftValue;
    return finalvalue;
}

function hideMenu()
{
usermenuTimer = setTimeout("hideNow()",500);
}

function hideNow()
{
obj = document.getElementById('UserMenuDiv');
obj.style.visibility = 'hidden';
resetUserTimer();
}

function ToggleClickNow()
{
var valElement = getStyle(document.getElementById("UserMenuDiv"), "visibility");
obj = document.getElementById('UserMenuDiv');
if(valElement == "visible"){
	obj.style.visibility = 'hidden';
}
else{
	obj.style.visibility = 'visible';
}
resetUserTimer();
}




function resetUserTimer()
{
if(typeof usermenuTimer == "undefined"){
	}
	else{
	clearTimeout(usermenuTimer);
	}
}

function showMenu(obj)
{
	resetUserTimer();
	obj = document.getElementById(obj);
	getPosDiv = document.getElementById("LoginDiv");
	var positieTop = getPositionTop(getPosDiv);
	var positieLeft = getPositionLeft(getPosDiv);
	obj.style.top = positieTop+13 + 'px'; 
	obj.style.left = positieLeft-3 + 'px';
	obj.style.visibility = 'visible';
}


function mouseReallyOut(oThis, e) 
{
        if (e.relatedTarget) {
        return(e.relatedTarget != oThis && e.relatedTarget.parentNode  != oThis);
        }
        return(e.toElement != oThis && e.toElement.parentNode  != oThis);
}





