/* ================================================================================== */
/* Statusbar tekst */
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

/* ================================================================================== */
/* Celkleur wisselaar */
function changeBgColor(tr,color)
{
	if (document.getElementById)
    {
    var o = document.getElementById(tr);
    if (o != null) o.style.backgroundColor = color;
    
    /*
		Was eerst:
		document.getElementById(tr).style.backgroundColor = color;
	*/
    }
}

/* cel stylesheet-class wisselaar */
function changeClass(tr, cssclass)
{
  if (document.getElementById)
  {
    var o = document.getElementById(tr);
    if (o != null) o.className = cssclass;
  }
}

/* ================================================================================== */
/* Div switcher */ 
function openDiv(divID) {
   var elem = document.getElementById(divID);
   elem.style.display = (elem.style.display == "none")?"":"none";
}

/* ================================================================================== */
/* Div + img switcher */ 
function openDivImgSwitch(divID,imgOpenID,imgCloseID,imgName) {
   var elem = document.getElementById(divID);
   elem.style.display = (elem.style.display == "none")?"":"none";
   
   var elemImg = document.getElementById(imgName);
   elemImg.src = (elem.style.display == "none")?imgOpenID:imgCloseID;
   
}

//Code
/*
  Op tag plaatsen:  style='display:none' id=''
*/

/* ================================================================================== */
/* Object + image switcher */ 
function showTag(waarde,locatieImg) 
{ 
    plaatje = "img_" + waarde; 
    if(document.getElementById(waarde).style.display=="none") 
    { 
        document.getElementById(waarde).style.display = ""; 
        document.getElementById(plaatje).src=locatieImg + '_open.gif'; 
    }
    else 
    { 
        document.getElementById(waarde).style.display = "none"; 
        document.getElementById(plaatje).src=locatieImg + '_dicht.gif'; 
    } 
} 

//Code
/*
  onClick='showTag('nr_1','../../xgt/shared/images/uitklappers/default')'
  Op tag plaatsen:  style='display:none' id='x'
  Op img tag plaatsen:   id='img_x'
*/

/* ================================================================================== */
/* Object switcher+ image switcher */ 
function showSwitch(Standaard,Detail,locatieImg) 
{ 
    plaatje = "img_" + Standaard; 
    if(document.getElementById(Standaard).style.display=="none") 
    { 
        document.getElementById(Standaard).style.display='block'; 
        document.getElementById(Detail).style.display='none';
        document.getElementById(plaatje).src=locatieImg + '_standaard.gif'; 
    }
    else 
    { 
        document.getElementById(Standaard).style.display="none"; 
        document.getElementById(Detail).style.display="block"; 
        document.getElementById(plaatje).src=locatieImg + '_detail.gif'; 
    } 
} 

//Code
/*
  onClick='showTag('Standaard','Detail','../../xgt/shared/images/uitklappers/default')'
  Op tag plaatsen:  style='display:none' id='Standaard'
  Op img tag plaatsen:   id='img_Standaard'
*/

/* ================================================================================== */
/* sets the value of a droplist */
function SetDropList(sDroplist, sValue)
{
	for (var i=0;i<document.forms[0].elements[sDroplist].length;i++)
	{
		if (document.forms[0].elements[sDroplist][i].value == sValue)
		{
			document.forms[0].elements[sDroplist].selectedIndex = i;
			break;
		}
	}
}

//Code
/*
	Link voorbeeld:
	<a href="#" onclick="openDivImgSwitch('divNaamg','default.gif','na_klik.gif','imgReplace');"><img id="imgReplace" src="default.gif"></a>


	<div id="divNaam" style="display:none;">
		Content
	</div>
*/


/* ================================================================================== */
/* Jump menu */
function jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//Code
/*
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
    <option selected>unnamed1</option>
</select>
*/


/* ================================================================================== */
/* Plaatjes wisselen (dreamweaver) */
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];}
}


/* ================================================================================== */
/* Lagen wisselen (dreamweaver) */

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

/* ================================================================================== */
/*	Nieuw venster
	Optioneel in te vullen bij onClick: toolbar, menubar, statusbar, location
*/
function XGT_Window(mypage, myname, w, h, scroll, resize, toolbar, menubar, statusbar, location) {
	if (toolbar == null) {
		toolbar = 0;
	}
	if (menubar == null) {
		menubar = 0;
	}
	if (statusbar == null) {
		statusbar = 0;
	}
	if (location == null) {
		location = 0;
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+
				',resizable='+resize+',toolbar='+toolbar+',menubar='+menubar+',statusbar='+statusbar+
				',location='+location+'';


	if (parseInt(navigator.appVersion) >= 4)
	{
		win = window.open("about:blank", myname, winprops);
		win.window.focus();
	}
		
	win = window.open(mypage, myname, winprops);
}


function XGT_Window_Base(mypage, myname, props) {
	
	if (parseInt(navigator.appVersion) >= 4)
	{
		win = window.open(mypage, myname, props);
		win.window.focus();
	}
		
	win = window.open(mypage, myname, props);
}

/* ================================================================================== */
/* Tekst zichtbaar maken a.d.h.v. checkbox status */

function XGT_Hide_Div_CheckBox(id,showLayer) { 
var checkBoxje = document.getElementById(id);
	
	if (checkBoxje.checked == true) { 
		openDiv(showLayer);
	}else{
		openDiv(showLayer);
	}
} 

//Code
/*
	Op checkbox:
	onClick="XGT_Hide_Div_CheckBox(this.id,'divNaam');"


	<div id="divNaam" style="display:none;">
		Content
	</div>
*/


/* ==================================================================================
 Anti-tabel inklapper 

IE en Opera 'bugfix' zodat de hoofdtabel niet 'inklapt'.

function PixelPlant()
{
	var dummyPix = document.body.offsetWidth - 625;
	document.getElementById('PixelPlant').width = dummyPix;
}

	<script language="javascript">
		window.onresize = PixelPlant;
		window.onload = PixelPlant;
	</script>
	<img src="../../XGT/Shared/images/px.gif" width="1" height="1" id="PixelPlant">
*/

/* =======================================================================
Focus verplaatser naar een volgend veld als de bron "vol" is

aanroepen: onKeyUp="MoveFocusToNextField(this,'anderveldID',2, event)"
*/
function MoveFocusToNextField(pSourceObject, pTargetField, pMaxLength, e)
{
	if (document.all)e=event; // FF cannot read event, so must be given using e param
	
	// pass the key-check for old browsers
	var validKey = true;
	if (typeof e != 'undefined')
	{
		var key = e.keyCode;
		validKey = (key > 31); // everything from ASCII 32 and higher is ok
	}
	if (validKey && pSourceObject.value != '')
	{
		if (pSourceObject.value.length >= pMaxLength)
		{
			var targetElem = document.getElementById(pTargetField);
			if (targetElem != null)
			{
				if (targetElem.type == "text")
					targetElem.select();
				else
					targetElem.focus();
			}
		}	
	}
}	

/* =======================================================================
Paste info to the clipboard or alert when not possible

*/

function CopyToClipBoard(pValue)
{
	if (window.clipboardData)
	{
		window.clipboardData.setData("text", pValue);
		alert("Data staat op clipboard (ctrl-V om te plakken)");
	}
	else
	{
		prompt("Data", pValue);
	}
}


/* ================================================================================== */
/* Tekst zichtbaar maken a.d.h.v. checkbox status
 * htmlEntities
 *
 * Convert all applicable characters to HTML entities
 *
 * object string
 * return string
 *
 * example:
 *   test = 'äöü'
 *   htmlEntities(test) //returns '&auml;&ouml;&uuml;'
 * 
 * http://www.dieterraber.net/jsStringFuncs.htm
 
 
 Bizar maar waar, de à zorgt ervoor dat onderstaande functie niet werkt (EC)
 
 */

function htmlEntities(data)
{

	var chars = new Array ('&','<','>');
	var entities = new Array('amp', 'lt', 'gt');

 /* var chars = new Array ('&','à','á','â','ã','ä','å','æ',
							'ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',                        
							'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',                       
							'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',                     
							'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',                  
							'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',          
							'>','¢','£','¤','¥','¦','§','¨','©','ª','«',   
							'¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸',
							'¹','º','»','¼','½','¾');


  var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
                              'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
                              'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
                              'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
                              'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
                              'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
                              'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
                              'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
                              'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
                              'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
                              'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
                              'sup2','sup3','acute','micro','para','middot','cedil','sup1',
                              'ordm','raquo','frac14','frac12','frac34');
*/
  newString = data;
  for (var i = 0; i < chars.length; i++)
  {
    myRegExp = new RegExp();
    myRegExp.compile(chars[i],'g')
    newString = newString.replace (myRegExp, '&' + entities[i] + ';');
  }
  return newString;
}

/*******************************************
	Scherm info opvragen
*******************************************/
function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}