/* This file contains generic javascript functions to be applied anywhere */

// function openPopup(theURL,winName, features) 
// Desc: opens popup window
// Parameters:
// theURL : url of the page you want to open (String)
// winName : name of the new window (String)
// OPTIONAL features
// width : width of window in pixels 
// height : height of window in pixels
// toolbar : values yes/no
// location : yes/no
// status : yes/no
// menubar : yes/no
// scrollbars : yes/no
// resizable : yes/no

// EXAMPLE : <a href="#" onClick = "openPopup('http://www.javascript.com', 'javascript', 'width=500, height=500');">Open window</a>
// NB make sure to separate each of the 'features' with a comma

function openPopup(theURL,winName, features) { 
    window.open(theURL,winName,features);
    void(0);
}
// function clearField(val)
// should be called from an onFocus event
// clears an input textbox f if the value is val
function clearField(f, val) {
	// alert(field);
    if (f.value == val)
		f.value = "";
}
// function showHide
// @param	div_id	The id of the element to hide/show
function showHide(div_id){
	div = document.getElementById(div_id);
	div.style.display == 'none'?div.style.display = 'block':div.style.display = 'none';
}
// function getURL(form)
// desc: takes user to url selected from select form
// @param	form : reference to the calling form
function goThere(element){
	loc = element.options[element.options.selectedIndex].value;
	if(loc){
		window.top.location.href = loc;
	}
}
// function maxLength (obj)
// checks length of textarea
function ismaxlength(obj, mlength){
	//var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
// Framework hack to prevent double id attributes
// function removeInputError(obj, defaultVal)
// desc: removes the error msg when a field receives focus
// implementation: onfocus="removeInputError(this);"
function removeInputError(obj, defaultVal){
		obj.className='correcting_input';
		return true;
	}
// function setInputError(obj, defaultVal)
// desc: restores the error msg when a field loses focus and error has not been corrected
// implementation: onblur="setInputError(this,'{naam}');" >> where {naam} should be replaced with the appropriate template variable
function setInputError(obj, defaultVal){
	if(defaultVal==obj.value ) obj.className='error_input';
	return true;
}

function ExtraOnload(eventHandler) {
	var extraOnload = eventHandler, oldload = window.onload;
  if (typeof(eventHandler) == "string") {
    extraOnload = function() { eval(eventHandler); };
  }
  window.onload = function() {
    if (oldload) {
      oldload();
    }
    extraOnload();
  };
}