	/*
	by Paul@YellowPencil.com and Scott@YellowPencil.com
	includes TextResizeDetector by Lawrence Carvalho <carvalho@uk.yahoo-inc.com>
	feel free to delete all comments except for the above credit
*/

// Replace 'center' 'right' and 'left' with the ID names of the columns you want to balance.
// The last one is there to show how you can add more columns.  Just delete the ones you're not using.
var divs = new Array('container_col_b','content_container','container_col_b');

// Initialize Scripts - is this a browser that understands DOM?
function scriptInit() { if (!document.getElementById) { return; } }

// Set up Event Listener
function addEvent(elm, evType, fn, useCapture) { 
	if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; } 
	else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; }
	else { elm['on' + evType] = fn; }
}

// Start Column Script
function setTall() {
	if (document.getElementById) { var maxHeight = 0; for (var i = 0; i < divs.length; i++) {
			if (document.getElementById(divs[i]) != null)
			{ var div = document.getElementById(divs[i]); div.style.height = null; if (div.offsetHeight > maxHeight) maxHeight = div.offsetHeight; }
		}
	for (var i = 0; i < divs.length; i++) {
			if (document.getElementById(divs[i]) != null)
			{ var div = document.getElementById(divs[i]); div.style.height = maxHeight + 'px'; if (div.offsetHeight > maxHeight) { div.style.height = (maxHeight - (div.offsetHeight - maxHeight)) + 'px'; } }
		}
	}
}

// Assign one of the columns to the TextResizeDetector.
function initTall() {
	if (document.getElementById) { for (var i = 0; i < divs.length; i++)
		{ if (document.getElementById(divs[i]) != null) { TextResizeDetector.TARGET_ELEMENT_ID = divs[i]; break; } }
	setTall(); } 
}

// Fire Events
addEvent(window, 'load', initTall, false);
addEvent(window, 'resize', setTall, false);

/*	Detects changes to font sizes when user changes browser settings
	Fires a custom event with the following data:
	iBase  : base font size
	iDelta : difference in pixels from previous setting
	iSize  : size in pixel of text
	author Lawrence Carvalho carvalho@uk.yahoo-inc.com */

// @constructor
TextResizeDetector = function() {
    var el  = null;
	var iIntervalDelay  = 200;
	var iInterval = null;
	var iCurrSize = -1;
	var iBase = -1;
 	var aListeners = [];
 	var createControlElement = function() {
	 	el = document.createElement('span');
		el.id='textResizeControl';
		el.innerHTML='&nbsp;';
		el.style.position="absolute";
		el.style.left="-9999px";
		var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
		// insert before firstChild
		if (elC)
			elC.insertBefore(el,elC.firstChild);
		iBase = iCurrSize = TextResizeDetector.getSize();
 	};

 	function _stopDetector() {
		window.clearInterval(iInterval);
		iInterval=null;
	};
	function _startDetector() {
		if (!iInterval) {
			iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay);
		}
	};

 	 function _detect() {
 		var iNewSize = TextResizeDetector.getSize();

 		if(iNewSize!== iCurrSize) {
			for (var 	i=0;i <aListeners.length;i++) {
				aListnr = aListeners[i];
				var oArgs = {  iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize};
				if (!aListnr.obj) {
					aListnr.fn('textSizeChanged',[oArgs]);
				}
				else  {
					aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]);
				}
			}

 		}
 		return iCurrSize;
 	};
	var onAvailable = function() {
		if (!TextResizeDetector.onAvailableCount_i ) {
			TextResizeDetector.onAvailableCount_i =0;
		}

		if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
			TextResizeDetector.init();
			if (TextResizeDetector.USER_INIT_FUNC){
				TextResizeDetector.USER_INIT_FUNC();
			}
			TextResizeDetector.onAvailableCount_i = null;
		}
		else {
			if (TextResizeDetector.onAvailableCount_i<600) {
	  	 	    TextResizeDetector.onAvailableCount_i++;
				setTimeout(onAvailable,200)
			}
		}
	};
	setTimeout(onAvailable,500);

 	return {
		 	/*
		 	 * Initializes the detector
		 	 *
		 	 * @param {String} sId The id of the element in which to create the control element
		 	 */
		 	init: function() {

		 		createControlElement();
				_startDetector();
 			},
			/**
			 * Adds listeners to the ontextsizechange event.
			 * Returns the base font size
			 *
			 */
 			addEventListener:function(fn,obj,bScope) {
				aListeners[aListeners.length] = {
					fn: fn,
					obj: obj
				}
				return iBase;
			},
			/**
			 * performs the detection and fires textSizeChanged event
			 * @return the current font size
			 * @type {integer}
			 */
 			detect:function() {
 				return _detect();
 			},
 			/**
 			 * Returns the height of the control element
 			 *
			 * @return the current height of control element
			 * @type {integer}
 			 */
 			getSize:function() {
	 				var iSize;
			 		return el.offsetHeight;


 			},
 			/**
 			 * Stops the detector
 			 */
 			stopDetector:function() {
				return _stopDetector();
			},
			/*
			 * Starts the detector
			 */
 			startDetector:function() {
				return _startDetector();
			}
 	}
 }();

/*** end TextResizeDetector */

TextResizeDetector.TARGET_ELEMENT_ID = 'doc';
TextResizeDetector.USER_INIT_FUNC = function() {
	var iBase = TextResizeDetector.addEventListener(setTall, null);
};

	
	function MM_reloadPage(init) 
	{  
		//reloads the window if Nav4 resized
		if (init==true) with (navigator) 
		{
			if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
			{
				document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
			}
		}
		else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
	MM_reloadPage(true);

	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_showHideLayers() 
	{ 
		//v6.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; 
		}
	}
	function paginalink(theURL,winName) 
	{ 
		//v2.0
		window.open(theURL,winName);
	}
	function paginalink_get(theURL,winName,oldprojectvar,oldmaandvar,oldjaarvar) 
	{ 
		var projectval = document.forms['form_mijnuren'].projecten.value;
		var maandval = document.forms['form_mijnuren'].pulldown_maand.value;
		var jaarval = document.forms['form_mijnuren'].pulldown_jaar.value;
		
		var theURL_new = theURL;
		
		if (theURL_new.search("projectid") > 1)
		{
			var theURL_new = theURL_new.replace('/'+oldprojectvar,'/'+projectval);
		}
		else
		{
			var theURL_new = theURL_new + '/'+projectval;
		}
		if (theURL_new.search("maand") > 1)
		{
			var theURL_new = theURL_new.replace('/'+oldmaandvar,'/'+maandval);
		}
		else
		{
			var theURL_new = theURL_new + '/'+maandval;
		}
		if (theURL_new.search("jaar") > 1)
		{
			var theURL_new = theURL_new.replace('/'+oldjaarvar,'/'+jaarval);
		}
		else
		{
			var theURL_new = theURL_new + '/'+jaarval+'/#kalender';
		}
		//alert (theURL_new);
		window.open(theURL_new,winName);
	}
	function doSubmit(url, form) 
	{
  		var theForm			=	document.getElementById(form);
  		theForm.action 		= 	url;
  		theForm.submit();
	}
	function t_to_t_pw(cont,elm)
	{
		tVal=elm.value;
		initvalue = document.forms['loginmedewerkers'].ww_initvalue.value;
		if (tVal == initvalue)
		{
			tVal_display = '';
		}
		else
		{
			tVal_display = tVal;
		}
		document.getElementById(cont).innerHTML='<input type="password" id="frontend_wachtwoord" name="frontend_wachtwoord" class="formelement_single1" value="'+tVal_display+'" onblur="t_to_t_txt(\'wwcontainer\',this)">';
		field = document.getElementById('frontend_wachtwoord');
		field.focus();
		field.focus();
	}
	function t_to_t_txt(cont,elm)
	{
		tVal=elm.value;
		initvalue = document.forms['loginmedewerkers'].ww_initvalue.value;
		if (tVal == '')
		{
			tVal_display = initvalue;
			input_type = 'text'
		}
		else
		{
			tVal_display = tVal;
			input_type = 'password'
		}
		document.getElementById(cont).innerHTML='<input type="'+input_type+'" id="frontend_wachtwoord" name="frontend_wachtwoord" class="formelement_single1" value="'+tVal_display+'" onfocus="t_to_t_pw(\'wwcontainer\',this)">';
	}
	
	
	
	
	function isNumberKey(evt)
    {
     	var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

        return true;
    }
	  
	function numberOfDays(nYear,nMonth) 
	{  
		return new Date(nYear,nMonth+1,0).getDate();
	}
	function validatenumber(event, obj)
  	{
		
		// ---------------------------------------------------------------------------------------------
		//
		// BLOKKEREN VAN BEPAALDE INPUTS ZOALS TEKSTEN OF KOMMA'S
		//
		// ---------------------------------------------------------------------------------------------
    	
		var code = (event.which) ? event.which : event.keyCode;
    	var character = String.fromCharCode(code);

    	if ((code >= 48 && code <= 57))
    	{ 
			
			// ---------------------------------------------------------------------------------------------
			//
			// INVOER VAN CIJFERS?
			//
			// ---------------------------------------------------------------------------------------------

        	var place_of_first_dot = obj.value.indexOf(".");
			
			tekens_voor 	= obj.value.substring(0);
			aantal_voor 	= tekens_voor.length;
				
			tekens_achter 	= obj.value.substring(place_of_first_dot+1);
			aantal_achter 	= tekens_achter.length;
				
			if (place_of_first_dot < 0) // cijfers voor de komma
			{
				if (aantal_voor >= 2) // mag niet meer dan 2 cijfers voor de komma
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			if (place_of_first_dot > -1) // cijfers achter de komma
			{
				if (aantal_achter >= 2) // mag niet meer dan 2 cijfers na de komma
				{
					return false;
				}
				else
				{
					return true;
				}
			}
    	}
    	else if (code == 46)
    	{ 
			// punten toegestaan
      		if (obj.value.indexOf(".") < 0)
			{
				return true;
			}
		}
		else if (code == 8)
		{ 
			// backspace toegestaan
		  	return true;
		}
		else if (code == 110)
		{ 
			// delete toegestaan
		  	return true;
		}
		else if (code >=37 && code <= 40)
		{ 
			// gebruik van pijltjes toetsen toegestaan
		  	return true;
		}
		return false;
  	}
 	function in_array (needle, haystack, argStrict) 
	{
		// http://kevin.vanzonneveld.net
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: vlado houba
		// +   input by: Billy
		// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
		// *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
		// *     returns 1: true
		// *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
		// *     returns 2: false
		// *     example 3: in_array(1, ['1', '2', '3']);
		// *     returns 3: true
		// *     example 3: in_array(1, ['1', '2', '3'], false);
		// *     returns 3: true
		// *     example 4: in_array(1, ['1', '2', '3'], true);
		// *     returns 4: false
	
		var key = '', strict = !!argStrict;
	
		if (strict) 
		{
			for (key in haystack) 
			{
				if (haystack[key] === needle) 
				{
					return true;
				}
			}
		} 
		else 
		{
			for (key in haystack) 
			{
				if (haystack[key] == needle) 
				{
					return true;
				}
			}
		}
		return false;
	}

  	function validatefield(obj, error, uren_allowed)
  	{ 
		array_uren_allowed		= uren_allowed.split(",");
		
		// ---------------------------------------------------------------------------------------------
		//
		// UPDATE DE VELDEN BIJ HET VERLATEN VAN HET VELD
		//
		// ---------------------------------------------------------------------------------------------
		
		if (isNaN(obj.value))
		{
			alert (error)
			obj.value = "";
			obj.focus();
		}
		else
		{
			if (obj.value != '')
			{
				val = obj.value;
				val = Math.abs(val);
				val = val.toFixed(2);
				obj.value = val;	
			}
		}
		
		// ---------------------------------------------------------------------------------------------
		//
		// START UPDATE DE TOTALEN
		//
		// ---------------------------------------------------------------------------------------------
		
		str_totaal_id			= obj.id;
		str_split				= str_totaal_id.split("_");
		str_dag					= str_split[1];
		str_uurtype				= str_split[2];
		aantal_dagen			= str_split[3];
		totaal_uurtypes			= str_split[4];
		
		// ---------------------------------------------------------------------------------------------
		//
		// TOTAAL VAN ÉÉN DAG IN DE MAAND
		//
		// ---------------------------------------------------------------------------------------------
		
		var changed_style_bgcolor = '#f16729';
		var changed_style_fontcolor = '#ffffff';
		
		var new_dag_total = '0';
		var old_dag_total = document.getElementById('oldtotaal_dag_'+str_dag).value;
		old_dag_total = Math.abs(old_dag_total);
		
		for (var x_type = 1; x_type <= totaal_uurtypes; x_type++)
		{
			bestaat_het_veld_type = in_array(x_type, array_uren_allowed);
			if (bestaat_het_veld_type == true)
			{
				dag_waarde = document.getElementById('uur_' + str_dag + '_' + x_type + '_' + aantal_dagen + '_' + totaal_uurtypes).value;
				new_dag_total = Math.abs(new_dag_total) + Math.abs(dag_waarde);
			}
		}
		if (old_dag_total != new_dag_total)
		{
			document.getElementById('opmaak_totaal_dag_'+str_dag).style.backgroundColor = changed_style_bgcolor;
			document.getElementById('opmaak_totaal_dag_'+str_dag).style.color = changed_style_fontcolor;
		}
		else
		{
			document.getElementById('opmaak_totaal_dag_'+str_dag).style.backgroundColor = '';
			document.getElementById('opmaak_totaal_dag_'+str_dag).style.color = '';
		}
		new_dag_total = new_dag_total.toFixed(2);
		document.getElementById('totaal_dag_'+str_dag).innerHTML = new_dag_total;
		
		// ---------------------------------------------------------------------------------------------
		//
		// TOTAAL VAN EEN UURTYPE OVER ALLE DAGEN VAN DE MAAND
		//
		// ---------------------------------------------------------------------------------------------
		
		var new_type_total = '0';
		var old_type_total = document.getElementById('oldtotaal_type_'+str_uurtype).value;
		old_type_total = Math.abs(old_type_total);
		for (var x_dag = 1; x_dag <= aantal_dagen; x_dag++)
		{
			type_waarde = document.getElementById('uur_' + x_dag + '_' + str_uurtype + '_' + aantal_dagen + '_' + totaal_uurtypes).value;
			new_type_total = Math.abs(new_type_total) + Math.abs(type_waarde);
		}
		if (old_type_total != new_type_total)
		{
			document.getElementById('opmaak_totaal_type_'+str_uurtype).style.backgroundColor = changed_style_bgcolor;
			document.getElementById('opmaak_totaal_type_'+str_uurtype).style.color = changed_style_fontcolor;
		}
		else
		{
			document.getElementById('opmaak_totaal_type_'+str_uurtype).style.backgroundColor = '';
			document.getElementById('opmaak_totaal_type_'+str_uurtype).style.color = '';
		}
		new_type_total = new_type_total.toFixed(2);
		document.getElementById('totaal_type_'+str_uurtype).innerHTML = new_type_total;
		
		// ---------------------------------------------------------------------------------------------
		//
		// COMPLETE TOTAAL
		//
		// ---------------------------------------------------------------------------------------------
		
		var new_totaal = '0';
		for (var x_dag = 1; x_dag <= aantal_dagen; x_dag++)
		{
			for (var x_type = 1; x_type <= totaal_uurtypes; x_type++)
			{
				bestaat_het_veld_type = in_array(x_type, array_uren_allowed);
				if (bestaat_het_veld_type == true)
				{
					input_waarde = document.getElementById('uur_' + x_dag + '_' + x_type + '_' + aantal_dagen + '_' + totaal_uurtypes).value;
					new_totaal = Math.abs(new_totaal) + Math.abs(input_waarde);
				}
			}
		}
		new_totaal = new_totaal.toFixed(2);
		document.getElementById('totaal_compleet').innerHTML = new_totaal;
  	}

	  
