//alert(window.onload);
//projectwise.js


//function that hides an element
function hidefield(elid){
	var trgField;
	if (document.getElementById(elid)) {
		trgField = document.getElementById(elid);
		trgField.style.display = "none";
	}
}
//function that shows an element
function showfield(elid){
	var trgField;
	if (document.getElementById(elid)) {
		trgField = document.getElementById(elid);
		trgField.style.display = ""; //nb: door hier lege string te gebruiken wordt de default gebruikt, is bij verschillende browsers anders
	}
}

// function that toggles display mode of an element
function togglefield(elid){
	var trgField;
	if (document.getElementById(elid)) {
		trgField = document.getElementById(elid);
		if (trgField.style.display == 'inline') {
			trgField.style.display = 'none';
		} else if (trgField.style.display == 'none') {
			trgField.style.display = "inline";
		}
	}
}


//function to set focus to a form
function FormSelect() {
	for (i=0; i<document.all.length; i++){
		obj = document.all[i];
		if (!obj || !obj.offsetParent) continue;
		//alert(obj.type)
		if (obj.className.toUpperCase() == 'FOCUSINPUTFIELD' ) {
			obj.focus();
			return;
		}
	}
}

// functie om option element aan selectlist toe te voegen
function addMenuitem(listobj, value, caption, selected) {
 	var cboOptions = eval(listobj);

	cboOptions.options[cboOptions.options.length] = new Option(caption, value);
	if (selected) { 
		cboOptions.options[cboOptions.options.length-1].selected=true;
	}
}
	
function ConfirmDelete(varprompt, varurl){
//deze functie opent een weet u het zeker venster voordat een deletelink uitgevoerd wordt.
	if (confirm(varprompt)) {
		//alert(varurl);
		document.location = varurl;
	}	
}

function RedirectTo(url) {
	document.location.href = url;
}

function openWindow(url){
	winEdit = window.open(url,"","width=500,height=500,resizable=yes,locationbar=0,toolbar=0,statusbar=0");
	}


// Onderstaande functies worden gebruikt om mogelijk te maken dat mensen blijven doortypen in een pull-down
// menu. 
// Gevonden op: http://www.oreillynet.com/pub/a/javascript/2003/09/03/dannygoodman.html
// Klein beetje aangepast om goed de alt-toets en pijltjestoetsen te negeren
// Gebruik: 	
// either as an attribute of the <select> tag:
// <select name="state" id="state" onkeydown="typeAhead()">or as a property of the element assigned by script:
// document.getElementById("state").onkeydown = typeAhead;


// global storage object for type-ahead info, including reset() method
var typeAheadInfo = {last:0, 
                     accumString:"", 
                     delay:4000,
                     timeout:null, 
                     reset:function() {this.last=0; this.accumString=""}
                    };

// function invoked by select element's onkeydown event handler
function typeAhead() {
	//alert (window.event.keyCode);
   // limit processing to IE event model supporter; don't trap Ctrl+keys en tab
   //if (window.event && (window.event.keyCode >= 65) && (window.event.keyCode <= 90)) {
   //changed to allow entering a space (keycode 32)
   //changed to allow entering numbers (keycode 48 - 57)
   if (window.event && (((window.event.keyCode >= 65) && (window.event.keyCode <= 90))|| (window.event.keyCode == 32) || (window.event.keyCode >= 48 && window.event.keyCode <= 57))) {
      // timer for current event
      var now = new Date();
      // process for an empty accumString or an event within [delay] ms of last
      if (typeAheadInfo.accumString == "" || now - typeAheadInfo.last < typeAheadInfo.delay) {
         // make shortcut event object reference
         var evt = window.event;
         // get reference to the select element
         var selectElem = evt.srcElement;
         // get typed character ASCII value
         var charCode = evt.keyCode;
         // get the actual character, converted to uppercase
         var newChar =  String.fromCharCode(charCode).toUpperCase();
         // append new character to accumString storage
         typeAheadInfo.accumString += newChar;
         // grab all select element option objects as an array
         var selectOptions = selectElem.options;
         // prepare local variables for use inside loop
         var txt, nearest;
         // look through all options for a match starting with accumString
         for (var i = 0; i < selectOptions.length; i++) {
            // convert each item's text to uppercase to facilitate comparison
            // (use value property if you want match to be for hidden option value)
            txt = selectOptions[i].text.toUpperCase();
			//doe een trimString om voorloopspaties eruit te halen
			//txt = trimString(txt);
            // record nearest lowest index, if applicable
            nearest = (typeAheadInfo.accumString > 
                       txt.substr(0, typeAheadInfo.accumString.length)) ? i : nearest;
            // process if accumString is at start of option text
            if (txt.indexOf(typeAheadInfo.accumString) == 0) {
               // stop any previous timeout timer
               clearTimeout(typeAheadInfo.timeout);
               // store current event's time in object 
               typeAheadInfo.last = now;
               // reset typeAhead properties in [delay] ms unless cleared beforehand
               typeAheadInfo.timeout = setTimeout("typeAheadInfo.reset()", typeAheadInfo.delay);
               // visibly select the matching item
               selectElem.selectedIndex = i;
			   //fire onchange event van select
			   selectElem.fireEvent("onchange");
               // prevent default event actions and propagation
               evt.cancelBubble = true;
               evt.returnValue = false;
               // exit function
               return false;   
            }            
         }
         // if a next lowest match exists, select it
         if (nearest != null) {
            selectElem.selectedIndex = nearest;
			//fire onchange event van select
			selectElem.fireEvent("onchange");
         }
      } else {
         // not a desired event, so clear timeout
         clearTimeout(typeAheadInfo.timeout);
      }
      // reset global object
      typeAheadInfo.reset();
   }
   return true;
}

