/*
 * Wheeler Javascript Library
 *
 * (c) 2004-2010 Hexon BV -- www.hexon.cx
 *
 */
function wh_gel(id) {
	if(typeof id == 'object') {
		return id;
	} else {
		return document.getElementById(id);
	}
}

// Eenmalig gebruikt in whdelta
function util_shuffleArray(a, b) {
	return (2 * Math.floor(Math.random() * 2)) - 1;
}

// Eenmalig gebruikt in whdelta
function util_getPosX(obj) {
	if(obj.offsetParent) {
		return obj.offsetLeft + util_getPosX(obj.offsetParent);
	} else {
		return obj.offsetLeft;
	}
}

// gebruikt in whdelta (1x) en elke esc-site (oud)
function util_getPosY(obj) {
	if(!obj.offsetParent) {
		return obj.offsetTop;
	} else {
		return obj.offsetTop + util_getPosY(obj.offsetParent);
	}
}

function util_trim(s) {
	while(s.substring(0,1) == ' ') {
		s = s.substring(1, s.length);
	}
	while(s.substring(s.length - 1, s.length) == ' ') {
		s = s.substring(0, s.length - 1);
	}
	return s;
}

function util_replaceAll(str, search, repl) {
	while(str.indexOf(search) != -1) {
		str = str.replace(search, repl);
	}
	return str;
}

// @returns a point or comma if a decimal point is found or false when no decimal point is found
function util_findDecimalPoint(value, forInt) {
	if(typeof forInt == undefined) {
		forInt = false;
	}

	value = value +'';
	var indexComma = value.lastIndexOf(',');
	var indexPoint = value.lastIndexOf('.');

	if(indexComma < 0 && indexPoint < 0) {
		return false;
	}

	var dp = '';
	if(indexComma > indexPoint) {
		dp = ',';
	} else {
		dp = '.';
	}

	var parts = value.split(new RegExp(util_escapeSymbol(dp)));
	if(parts.length > 2) {
		return false;
	}

	if(!forInt && dp == '.' && /\.[0-9]{3}$/.test(value)) {
		return false;
	} else if(forInt && /[\.,][0-9]{3}$/.test(value)) {
		return false;
	}

	return dp;
}

// @returns a point, comma or space if a thousands separator is found or false when no thousands separator is found
function util_findThousandsSeparator(value, decimal_point) {
	if(decimal_point === false) {
		if(/-?[0-9]{1,3}(\.[0-9]{3})+/.test(value)) {
			return '.';
		} else if(/-?[0-9]{1,3}(,[0-9]{3})+/.test(value)) {
			return ',';
		} else if(/-?[0-9]{1,3}( [0-9]{3})+/.test(value)) {
			return ' ';
		} else {
			return false;
		}
	} else {
		parts = value.split(decimal_point);
		return util_findThousandsSeparator(parts[0], false);
	}
}

function util_escapeSymbol(s) {
	if(s == '.') {
		return '\\.';
	} else {
		return s;
	}
}

function util_parseInteger(value, decimal_point, thousands_separator) {
	if(typeof decimal_point == 'undefined') {
		decimal_point = util_findDecimalPoint(value, true);
		thousands_separator = util_findThousandsSeparator(value, decimal_point);
	} else if(typeof thousands_separator == 'undefined') {
		thousands_separator = util_findThousandsSeparator(value, decimal_point);
	}

	if(thousands_separator) {
		while(new RegExp(util_escapeSymbol(thousands_separator) +'[0-9]{3}').test(value)) {
			value = value.replace(new RegExp(util_escapeSymbol(thousands_separator) +'([0-9]{3})'), '$1');
		}
	}
	if(decimal_point) {
		value = value.replace(new RegExp(util_escapeSymbol(decimal_point)), '.');
	}
	if(!value.match(/^-?[0-9]+(\.[0-9]+)?$/)) {
		return false;
	}
	var intval = Math.round(value);
	if(isNaN(intval)) {
		return false;
	}
	return intval;
}

function util_formatInteger(i, thousands_separator) {
	if(i === false) {
		return '';
	}
	if(typeof thousands_separator == 'undefined' || (thousands_separator != '.' && thousands_separator != ',' && thousands_separator != ' ')) {
		thousands_separator = '.';
	}
	i = i +'';
	while(/(-?[0-9]+)([0-9]{3})/.test(i)) {
		i = i.replace(/(-?[0-9]+)([0-9]{3})/, '$1'+ thousands_separator +'$2');
	}
	return i;
}

function util_parseFloat(value, decimal_point, thousands_separator) {
	if(typeof decimal_point == 'undefined') {
		decimal_point = util_findDecimalPoint(value);
		thousands_separator = util_findThousandsSeparator(value, decimal_point);
	} else if(typeof thousands_separator == 'undefined') {
		thousands_separator = util_findThousandsSeparator(value, decimal_point);
	}

	if(thousands_separator) {
		while(new RegExp(util_escapeSymbol(thousands_separator)).test(value)) {
			value = value.replace(new RegExp(util_escapeSymbol(thousands_separator)), '');
		}
	}
	if(decimal_point) {
		value = value.replace(new RegExp(util_escapeSymbol(decimal_point)), '.');
	}
	if(!value.match(/^-?[0-9]+(\.[0-9]+)?$/)) {
		return false;
	}
	var floatval = parseFloat(value);
	if(isNaN(floatval)) {
		return false;
	}
	return floatval;
}

function util_formatFloat(value, decimals, decimal_point, thousands_separator) {
	if(typeof(decimal_point) == 'undefined') {
		decimal_point = ',';
	}
	if(typeof(thousands_separator) == 'undefined') {
		thousands_separator = '.';
	}

	if(value === false) {
		return '';
	}

	if(decimal_point == thousands_separator) {
		return '';
	}

	value = value +'';
	var parts = value.split('.');

	if(typeof(parts[1]) == 'undefined') {
		return util_formatInteger(value, thousands_separator);
	}

	while(/(-?[0-9]+)([0-9]{3})/.test(parts[0])) {
		parts[0] = parts[0].replace(/(-?[0-9]+)([0-9]{3})/, '$1'+ thousands_separator +'$2');
	}
	if(decimals !== 0 && decimals > 0) {
		if(parts[1].length > decimals) {
			var base = parseInt(parts[1].substr(0, decimals), 10);
			var omh_oml = parseInt(parts[1].substr(decimals, 1), 10);
			if(omh_oml >= 5) {
				base++;
				if(new Number(base).toString().length > decimals) {
					base = 0;
					parts[0]++;
				}
			}
			parts[1] = new String(base);
		} else if(parts[1].length < decimals) {
			var over = decimals - parts[1].length;
			for(var i = 0; i < over; i++) {
				parts[1] += '0';
			}
		}
	}
	return parts[0] + decimal_point + parts[1];
}

function htmlentities(str) {
	var norm = ["<",">","é","É","è","È","ê","Ê","ë","Ë","à","À","ù","Ù","ç","Ç","Š"];
	var spec = ['&lt;','&gt;','&eacute;', '&Eacute;', '&egrave;', '&Egrave;', '&ecirc;', '&Ecirc;', '&euml;', '&Euml;', '&agrave;', '&Agrave;', '&ugrave;', '&Ugrave;', '&ccedil;', '&Ccedil;', '&Scaron;'];
	for(i = 0; i < norm.length; i++) {
		str = util_replaceAll(str, norm[i], spec[i]);
	}
	return str;
}

function serialize(variable) {
	var type = typeof(variable);

	switch(type) {
		case 'string':
			return 's:' + variable.length + ':"' + variable + '";';

		case 'number':
			return 's:' + ('' + variable).length + ':"' + variable + '";';

		case 'boolean':
			return 'b:' + (variable ? '1' : '0') + ';';

		case 'object':
			if(variable.length == undefined || variable.length == 0) {
				// Of een lege array, of een associatieve array
				var str = '';
				var len = 0;
				for(var i in variable) {
					str = str + 's:' + ("" + i).length + ':"' + i + '";' + serialize(variable[i]);
					len++;
				}
				return 'a:' + len + ':{' + str + '}';
			} else {
				// Normale array
				str = '';
				for(i = 0; i < variable.length; i++) {
					str = str + 'i:' + i + ';' + serialize(variable[i]);
				}
				return 'a:' + variable.length + ':{' + str + '}';
			}

		case 'undefined':
			return 'N;';

		default:
			return 'N;';
	}
}

/**
 * util_addToFavorites -- add the current page as a bookmark
 *
 * TODO: safari, opera, konqueror, ...
 *
 * Known bugs: firefox adds a 'open in side panel' option by default, probably from version 1.5.0.1 on
 */
function util_addToFavorites() {
	var title = document.title;
	var url = document.location.href;

	if(window.external) { // IE Favorite
		window.external.AddFavorite(url, title);
	} else if(window.sidebar) { // Mozilla/Firefox Bookmark
		window.sidebar.addPanel(title, url, '');
	} else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
}

function util_setSelectionRange(input, start, end) {
}

function util_getSelectedText(input) {
	startpos = util_getSelectionStart(input);
	endpos = util_getSelectionEnd(input);
	if(startpos == endpos) {
		return '';
	}
	return input.value.substr(startpos, endpos - startpos);
}

function util_getSelectionStart(input) {
	return 0;
}

function util_getSelectionEnd(input) {
	return 0;
}

// backwards compatibility
function shuffleArray(a, b) {
	return util_shuffleArray(a, b);
}

function whf_getPosX(el) {
	return util_getPosX(el);
}

function whf_getPosY(el) {
	return util_getPosY(el);
}

function trim(str) {
	return util_trim(str);
}

function replaceAll(str, search, replace) {
	return util_replaceAll(str, search, replace);
}

function whf_parseInteger(value, decimal_point, thousands_separator) {
	return util_parseInteger(value, decimal_point, thousands_separator);
}

function whf_formatInteger(value, thousands_separator) {
	return util_formatInteger(value, thousands_separator);
}

function whf_parseFloat(value, decimal_point, thousands_separator) {
	return util_parseFloat(value, decimal_point, thousands_separator);
}

function whf_formatFloat(value, decimal_point, thousands_separator) {
	return util_formatFloat(value, decimal_point, thousands_separator);
}
var whf_fields = [];
var whf_cb = [];
var whf_masks = [];
var whf_preventmultiplesubmit = true;
var whf_doJavaScriptChecks = true;
var whf_submitId = null;

var whf_visibleDiv = -1;
var whf_IE = (document.all ? true : false);
var whf_defaultErrorStyles = [];
var whf_defaultErrorListDivision = '';
var whf_defaultErrorListStyle = 'ul';
var whf_defaultErrorListFormat = '%l %e';
var whf_formErrorListDivision = whf_defaultErrorListDivision;
var whf_formErrorListStyle = whf_defaultErrorListStyle;
var whf_formErrorListFormat = whf_defaultErrorListFormat;
var whf_formValidationCallback = '';
var whf_defaultValidationMethod = 'WHF_ON_SUBMIT';
var whf_inputErrorBackgroundColor = '#ffdddd';
var whf_errorFloatBoxWidth = 200;
var whf_errListItemCount = [];
var whf_labelRequired = '';
var whf_exclamationImage = new Image(16, 16);
var whf_oldhandler = '';
var whf_handlerRegistered = false;
var whf_inputHash = '';
var whf_maxtries = 20;

function whf_populate_by_slave(nameM, nameC) {
	var objM = document.getElementById(nameM);
	var objC = document.getElementById(nameC + '-sel');
	var objCb = null;
	if(objC == null) {
		objC = document.getElementById(nameC);
	} else {
		objCb = document.getElementById(nameC);
	}
	if(objM == null || objC == null) {
		return;
	}

	objC.innerHTML = '';
	if(objCb != null) {
		objCb.value = '';
	}

	var k = objM.value;

	var ids = eval('whf_items_' + nameC + '_id[' + k + ']');
	var vals = eval('whf_items_' + nameC + '_val[' + k + ']');

	whf_populate(objC, ids, vals);
}

function whf_populate(id, vals, defaultval, add, vals_associative) {
	if(id == null) {
		return;
	}

	if(vals == null) {
		vals = [];
	}

	if(defaultval != null) {
		var cbid = document.getElementById(id.id + '-sel');
		if(cbid != null) {
			id.value = defaultval;
			id = cbid;
		}
	}

	if(add == null) {
		add = 1;
	}

	if(vals_associative == null) {
		vals_associative = false;
	}

	id.innerHTML = '';

	var defaultfound = false;
	if(defaultval != null) {
		if(vals_associative) {
			if(vals[defaultval]) {
				defaultfound = true;
			} else {
				defaultfound = false;
			}
		} else {
			match = defaultval.toLowerCase();
			for(i in vals) {
				if(vals[i].toLowerCase() == match) {
					defaultfound = true;
				}
			}
		}

		if(!defaultfound && add) {
			var opt = document.createElement('option');
			opt.value = defaultval;
			opt.innerHTML = defaultval;
			opt.selected = true;
			id.appendChild(opt);
		}
	}

	for(var i in vals) {
		var opt = document.createElement('option');
		if(vals_associative) {
			opt.value = i;
		} else {
			opt.value = vals[i];
		}
		opt.innerHTML = vals[i];
		opt.selected = false;
		if(defaultfound) {
			if(vals_associative) {
				if(i == defaultval) {
					opt.selected = true;
				}
			} else {
				if(vals[i].toLowerCase() == match) {
					opt.selected = true;
				}
			}
		}
		id.appendChild(opt);
	}
}

function whf_setDropdownByKey(obj, key) {
	// TODO: Support for comboboxes

	for(var i = 0; i < obj.options.length; i++) {
		if(obj.options[i].value == key) {
			obj.selectedIndex = i;
			return;
		}
	}
}

function whf_set(obj, value) {
	var obj_sel = document.getElementById(obj.id + '-sel');
	var obj_text = null;
	if(obj_sel != null) {
		obj_text = obj;
		obj = obj_sel;
	}

	value = value + '';
	var value_escaped = value.replace(/&/, '&amp;');

	var match = value.toLowerCase();
	var match_escaped = value_escaped.toLowerCase();

	if(obj.selectedIndex >= 0 && obj.options[obj.selectedIndex]) {
		if(obj.options[obj.selectedIndex].selected) {
			obj.options[obj.selectedIndex].selected = false;
		}
	}

	for(var i = 0; i < obj.options.length; i++) {
		if(typeof obj.options[i] == 'string') {
			if(obj.options[i].toLowerCase() == match || obj.options[i].toLowerCase() == match_escaped) {
				if(obj_sel != null) {
					obj_text.value = value;
				}
				obj.selectedIndex = i;
				return;
			}
		} else {
			if(obj.options[i] == value || obj.options[i] == value_escaped) {
				if(obj_sel != null) {
					obj_text.value = value;
				}
				obj.selectedIndex = i;
				return;
			}
		}
	}
	for(var i = 0; i < obj.options.length; i++) {
		if(obj.options[i].innerHTML.toLowerCase() == match || obj.options[i].innerHTML.toLowerCase() == match_escaped) {
			if(obj_sel != null) {
				obj_text.value = value;
			}
			obj.selectedIndex = i;
			return;
		}
	}

	// not found: add
	var opt = document.createElement('option');
	opt.value = value;
	opt.innerHTML = value;
	opt.selected = true;
	if(obj.options.length > 0) {
		var first = obj.options[0];
		obj.insertBefore(opt, first);
		obj.selectedIndex = 0;
	} else {
		obj.appendChild(opt);
		obj.selectedIndex = obj.options.length - 1;
	}
	if(obj_sel != null) {
		obj_text.value = value;
	}
}

function whf_setIfExists(obj, value) {
	var obj_sel = document.getElementById(obj.id + '-sel');
	var obj_text = null;
	if(obj_sel != null) {
		obj_text = obj;
		obj = obj_sel;
	}

	var value_escaped = value.replace(/&/, '&amp;');

	var match = value.toLowerCase();
	var match_escaped = value_escaped.toLowerCase();

	for(var i = 0; i < obj.options.length; i++) {
		if(typeof obj.options[i] == 'string') {
			if(obj.options[i].toLowerCase() == match || obj.options[i].toLowerCase == match_escaped) {
				if(obj_sel != null) {
					obj_text.value = value;
				}
				obj.selectedIndex = i;
				return;
			}
		} else {
			if(obj.options[i].value == value || obj.options[i].value == value_escaped) {
				if(obj_sel != null) {
					obj_text.value = value;
				}
				obj.selectedIndex = i;
				return;
			}
		}
	}
	for(var i = 0; i < obj.options.length; i++) {
		if(obj.options[i].innerHTML.toLowerCase() == match || obj.options[i].innerHTML.toLowerCase() == match_escaped) {
			if(obj_sel != null) {
				obj_text.value = value;
			}
			obj.selectedIndex = i;
			return;
		}
	}
}

function whf_registerField(id, required, label) {
	whf_fields[id] = [];
	whf_fields[id]['required'] = required;
	whf_fields[id]['min_length'] = null;
	whf_fields[id]['max_length'] = null;
	whf_fields[id]['min'] = null;
	whf_fields[id]['max'] = null;
	whf_fields[id]['allow_past'] = null;
	whf_fields[id]['allow_future'] = null;
	whf_fields[id]['date_field'] = null;
	whf_fields[id]['with_seconds'] = null;
	whf_fields[id]['regexps'] = [];
	whf_fields[id]['regexpErrCodes'] = [];
	whf_fields[id]['errorScript'] = '';
	whf_fields[id]['valid'] = true;
	whf_fields[id]['label'] = label;
	whf_fields[id]['items'] = null;
	whf_fields[id]['obj'] = document.getElementById(id);

	if(whf_defaultValidationMethod == 'WHF_ON_BLUR' && whf_fields[id]['validationMethod'] == undefined) {
		whf_fields[id]['validationMethod'] = 'WHF_ON_BLUR';
		whf_addOnBlur(id,'whf_checkField(this.id, false)', false);
	}
}

function whf_registerRadioItem(id, value) {
	if(whf_fields[id]['items'] == null) {
		whf_fields[id]['items'] = [];
	}
	var field = document.getElementById(id +'_'+ value);
	whf_fields[id]['items'].push(field);
}

function whf_registerMultiCheckboxItem(id, value) {
	if(whf_fields[id]['items'] == null) {
		whf_fields[id]['items'] = [];
	}
	var field = document.getElementById(id +'_'+ value);
	whf_fields[id]['items'].push(field);
}

function whf_setRequired(id, required) {
	whf_fields[id]['required'] = required;

	var lId = null;
	if(document.getElementById('label'+ id) != undefined) {
		lId = document.getElementById('label'+ id);
	} else {
		return;
	}

	if(required) {
		var found = false;
		for(var i = 0; i < lId.childNodes.length; i++) {
			if(lId.childNodes[i].nodeType == 1 && lId.childNodes[i].tagName && lId.childNodes[i].tagName.toLowerCase() == 'span' && lId.childNodes[i].innerHTML == whf_labelRequired) {
				found = true;
			}
		}
		if(!found) {
			var lrSpan = document.createElement('span');
			lrSpan.appendChild(document.createTextNode(whf_labelRequired));
			lId.appendChild(lrSpan);
		}
	} else {
		for(var i = 0; i < lId.childNodes.length; i++) {
			if(lId.childNodes[i].nodeType == 1 && lId.childNodes[i].tagName && lId.childNodes[i].tagName.toLowerCase() == 'span' && lId.childNodes[i].innerHTML == whf_labelRequired) {
				lId.childNodes[i].parentNode.removeChild(lId.childNodes[i]);
			}
		}
	}
}

function whf_setMinLength(id, value) {
	whf_fields[id]['min_length'] = value;
}

function whf_setMaxLength(id, value) {
	whf_fields[id]['max_length'] = value;
}

function whf_setMin(id, value) {
	whf_fields[id]['min'] = value;
}

function whf_setMax(id, value) {
	whf_fields[id]['max'] = value;
}

function whf_addValidationRegExp(id, regexp, errCode) {
	whf_fields[id]['regexps'].push(regexp);
	whf_fields[id]['regexpErrCodes'].push(errCode);
}

function whf_setAllowPast(id, value) {
	whf_fields[id]['allow_past'] = value;
}

function whf_setAllowFuture(id, value) {
	whf_fields[id]['allow_future'] = value;
}

function whf_linkDateField(id, datef) {
	whf_fields[id]['date_field'] = datef;
}

function whf_setWithSeconds(id, value) {
	whf_fields[id]['with_seconds'] = value;
}

function whf_focus(id) {
	try {
		focusfield(id);
	} catch(e) {
		try {
			document.getElementById(id).focus();
		} catch(e) {
			// Nothing
		}
	}
}

function whf_setLabelRequired(str) {
	whf_labelRequired = str;
}

function whf_setErrorStyle(id, style) {
	whf_fields[id]['errorStyle'] = style;
}

function whf_setErrorScript(id, script) {
	whf_fields[id]['errorScript'] = script;
}

function whf_setDefaultErrorList(division, style, format) {
	whf_defaultErrorListDivision = division;
	whf_defaultErrorListStyle = style;
	whf_defaultErrorListFormat = format;
}

function whf_setErrorList(id, division, style, format) {
	if(id == 'form') {
		whf_formErrorListDivision = division;
		whf_formErrorListStyle = style;
		whf_formErrorListFormat = format;
	} else {
		whf_fields[id]['errorDivision'] = division;
		whf_fields[id]['errorListStyle'] = style
		whf_fields[id]['errorListFormat'] = format;
	}
}

function whf_setExclamationPosition(id, position) {
	whf_fields[id]['errorExclamationPosition'] = position;
}

function whf_showError(id, errHandle) {
	// Controle of de errorlistdivision al bestaat
	if(whf_formErrorListDivision && document.getElementById(whf_formErrorListDivision) != undefined) {
		if(whf_maxtries > 0) {
			setTimeout(function() {
				whf_showError(id, errHandle);
			}, 50);
		}
		whf_maxtries = whf_maxtries -1;
		return;
	}

	// apply error at form level
	var isFormError = false;
	if(id == '_whf_form') {
		isFormError = true;
	}

	if(errHandle == '') {
		errHandle = 'ERR_UNSPECIFIED';
	}

	var errMsg = null;
	if(whf_errMsg[errHandle] == undefined) {
		errMsg = 'Unspecified error: '+errHandle;
	} else {
		errMsg = whf_errMsg[errHandle];
	}

	if(isFormError) {
		// formbreed
		for(var errType in whf_defaultErrorStyles) {

			// ErrorScript:
			if(whf_defaultErrorStyles[errType] == 'errScript') {
				if(whf_defaultErrorScript.length > 0) {
					eval(whf_defaultErrorScript +'("form", "'+ errHandle +'");');
				}
				continue;
			}

			// list
			if(whf_defaultErrorStyles[errType] == 'list') {
				// defaults
				if(whf_formErrorListDivision.length <= 0) {
					whf_formErrorListDivision = whf_defaultErrorListDivision;
				}
				if(whf_formErrorListStyle.length <= 0) {
					whf_formErrorListStyle = whf_defaultErrorListStyle;
				}
				if(whf_formErrorListFormat.length <= 0) {
					whf_formErrorListFormat = whf_defaultErrorListFormat;
				}

				if(document.getElementById(whf_formErrorListDivision) == undefined) {
					break;
				}

				if(whf_formErrorListStyle == 'ol') {
					listDef = 'ol';
					listItemDef = 'li';
				} else if(whf_formErrorListStyle == 'dl') {
					listDef = 'dl';
					listItemDef = 'dd';
				} else if(whf_formErrorListStyle == 'none') {
					listDef = 'span';
					listItemDef = 'span';
				} else {
					listDef = 'ul';
					listItemDef = 'li';
				}

				if(document.getElementById(whf_formErrorListDivision +'_list_'+ listDef) == undefined) {
					document.getElementById(whf_formErrorListDivision).innerHTML = document.getElementById(whf_formErrorListDivision).innerHTML +'<'+ listDef +' id="'+ whf_formErrorListDivision +'_list_'+ listDef +'"></'+ listDef +'>';
				}

				if(document.getElementById('list_li_form') == undefined) {
					document.getElementById(whf_formErrorListDivision +'_list_'+ listDef).innerHTML = document.getElementById(whf_formErrorListDivision +'_list_'+ listDef).innerHTML +'<'+ listItemDef +' id="list_li_form"><'+ listItemDef +'>';
				}

				var _errMsg = whf_formErrorListFormat;
				_errMsg = _errMsg.replace(/%l/, '');
				_errMsg = _errMsg.replace(/%e/, errMsg);

				document.getElementById('list_li_form').innerHTML = _errMsg;

				document.getElementById('list_li_form').style.visibility = 'inherit';
				document.getElementById('list_li_form').style.display= '';

				if(whf_errListItemCount[listDef] == undefined) {
					whf_errListItemCount[listDef] = 1;
				} else {
					whf_errListItemCount[listDef] = whf_errListItemCount[listDef] + 1;
				}
				continue;
			}
		}
	} else {
		// field specific

		if(!whf_fields[id]['valid']) {
			whf_resetError(id, false);
		}

		var sId = document.getElementById('input_'+ id);
		var iId = document.getElementById(id);
		var lId = null;
		if(document.getElementById('label'+ id) != undefined) {
			lId = document.getElementById('label'+ id);
		} else {
			lId = undefined;
		}

		var defaultStyle = false;
		if(whf_fields[id]['errorStyle'] == undefined) {
			whf_fields[id]['errorStyle'] = whf_defaultErrorStyles;
			defaultStyle = true;
		}

		for(var errType in whf_fields[id]['errorStyle']) {
			// LabelColor:
			if(whf_fields[id]['errorStyle'][errType] == 'labelColor') {
				if(lId != undefined) {
					if(whf_colorError == null) {
						lId.style.color = 'red';
					} else {
						lId.style.color = whf_colorError;
					}
				}
				continue;
			}

			// inputColor:
			if(whf_fields[id]['errorStyle'][errType] == 'inputColor') {
				iId.style.backgroundColor = whf_inputErrorBackgroundColor;
				continue;
			}

			// Exclamation
			if(whf_fields[id]['errorStyle'][errType] == 'exclamation') {
				if(whf_fields[id]['errorExclamationPosition'] == undefined) {
					whf_fields[id]['errorExclamationPosition'] = whf_defaultErrorExclamationPosition;
				}

				if (document.getElementById('exclamation'+ id) == undefined) {
					excl = document.createElement('span');
					excl.id = 'exclamation'+ id;
					excl.innerHTML ='<img id="exclamationimg'+ id +'" alt="!" title=""></img>';

					if(whf_fields[id]['errorExclamationPosition'] == 'beforeLabel') {
						if(lId != undefined) {
							lId.insertBefore(excl,lId.firstChild);
						}
					} else if(whf_fields[id]['errorExclamationPosition'] == 'beforeInput') {
						sId.insertBefore(excl,sId.firstChild);
					} else if(whf_fields[id]['errorExclamationPosition'] == 'behindInput') {
						sId.appendChild(excl);
					} else {
						// default = behindLabel
						if(lId != undefined) {
							lId.appendChild(excl);
						}
					}
				}

				document.getElementById('exclamationimg'+ id).src = whf_exclamationImage.src;
				document.getElementById('exclamation'+ id).style.visibility = 'inherit';
				document.getElementById('exclamation'+ id).style.display= 'inline';
				continue;
			}

			// FloatingBox:
			if(whf_fields[id]['errorStyle'][errType] == 'floatingBox') {
				if(!whf_handlerRegistered) {
					if(document.onmousemove != undefined) {
						whf_oldhandler = document.onmousemove;
					}

					if(!whf_IE) {
						document.captureEvents(Event.MOUSEMOVE);
					}
					document.onmousemove = whf_getMouseXY;
					whf_handlerRegistered = true;
				}

				if(document.getElementById('errmsg'+ id) == null) {
					util_createFloatingDiv('errmsg'+ id);
				}

				document.getElementById('errmsg'+ id).innerHTML = errMsg;

				if(lId != undefined) {
					lId.onmouseover = function() {
						util_showFb(this, 'label');
					}
					lId.onmouseout = util_hideFb;
				}

				if(document.getElementById('exclamation'+ id) != undefined) {
					document.getElementById('exclamation'+ id).onmouseover = function() {
						util_showFb(this, 'exclamation');
					}
					document.getElementById('exclamation'+ id).onmouseout = util_hideFb;
				}

				continue;
			}

			// ErrorScript:
			if(whf_fields[id]['errorStyle'][errType] == 'errScript') {
				if(defaultStyle || whf_fields[id]['errorScript'].length == 0) {
					if(whf_defaultErrorScript.length > 0) {
						eval(whf_defaultErrorScript +'("'+ id +'", "'+ errHandle +'");');
					}
				} else {
					if (whf_fields[id]['errorScript'].length > 0) {
						eval(whf_fields[id]['errorScript'] +'("'+ id +'","'+ errHandle +'");');
					}
				}
				continue;
			}

			// list
			if(whf_fields[id]['errorStyle'][errType] == 'list') {

				if(document.getElementById(whf_fields[id]['errorListDivision']) == undefined) {
					if(document.getElementById(whf_defaultErrorListDivision) == undefined) {
												continue;
					}
					whf_fields[id]['errorListDivision'] = whf_defaultErrorListDivision;
				}

				if(whf_fields[id]['errorListFormat'] == undefined) {
					whf_fields[id]['errorListFormat'] = whf_defaultErrorListFormat;
				}

				if(whf_fields[id]['errorListStyle'] == undefined) {
					whf_fields[id]['errorListStyle'] = whf_defaultErrorListStyle;
				}

				if(whf_fields[id]['errorListStyle'] == 'ol') {
					listDef = 'ol';
					listItemDef = 'li';
				} else if(whf_fields[id]['errorListStyle'] == 'dl') {
					listDef = 'dl';
					listItemDef = 'dd';
				} else if(whf_fields[id]['errorListStyle'] == 'none') {
					listDef = 'span';
					listItemDef = 'span';
				} else {
					listDef = 'ul';
					listItemDef = 'li';
				}

				if(document.getElementById(whf_fields[id]['errorListDivision'] +'_list_'+ listDef) == undefined) {
					document.getElementById(whf_fields[id]['errorListDivision']).innerHTML = document.getElementById(whf_fields[id]['errorListDivision']).innerHTML + '<'+ listDef +' id="'+ whf_fields[id]['errorListDivision'] +'_list_'+ listDef +'"></'+ listDef +'>';
				}

				if (document.getElementById('list_li'+ id) == undefined) {
					document.getElementById(whf_fields[id]['errorListDivision'] +'_list_'+ listDef).innerHTML = document.getElementById(whf_fields[id]['errorListDivision'] +'_list_'+ listDef).innerHTML +'<'+ listItemDef+ ' id="list_li'+ id +'"></'+ listItemDef +'>';
				}

				var _errMsg = whf_fields[id]['errorListFormat'];
				_errMsg = _errMsg.replace(/%l/, whf_fields[id]['label']);
				_errMsg = _errMsg.replace(/%e/, errMsg);
				document.getElementById('list_li'+ id).innerHTML = _errMsg;

				document.getElementById('list_li'+ id).style.visibility = 'inherit';
				document.getElementById('list_li'+ id).style.display= '';

				if(whf_errListItemCount[listDef] == undefined) {
					whf_errListItemCount[listDef] = 1;
				} else {
					whf_errListItemCount[listDef] = whf_errListItemCount[listDef] + 1;
				}
				document.getElementById(whf_fields[id]['errorListDivision'] +'_list_'+ listDef).style.visibility = 'inherit';
				document.getElementById(whf_fields[id]['errorListDivision'] +'_list_'+ listDef).style.display = '';
				continue;
			}
		}
		whf_fields[id]['valid'] = false;
	}
}

// id: field for which the error needs to reset,
// isValid: only reset the value, or reset the (optional) callback as well
function whf_resetError(id, isValid) {
	if(whf_fields[id]['valid'] == true) {
		return;
	}

	var defaultStyle = false;
	if(whf_fields[id]['errorStyle'] == undefined) {
		whf_fields[id]['errorStyle'] = whf_defaultErrorStyles;
		defaultStyle = true;
	}

	var iId = document.getElementById(id);
	var lId = undefined;
	if(document.getElementById('label'+ id) != undefined) {
		lId = document.getElementById('label'+ id);
	}

	for(errType in whf_fields[id]['errorStyle']) {
		if(whf_fields[id]['errorStyle'][errType] == 'labelColor' && lId != undefined) {
			lId.style.color = '';
			continue;
		}

		if(whf_fields[id]['errorStyle'][errType] == 'inputColor') {
			iId.style.backgroundColor = '';
			continue;
		}

		if(whf_fields[id]['errorStyle'][errType] == 'exclamation') {
			document.getElementById('exclamation'+ id).style.visibility = 'hidden';
			document.getElementById('exclamation'+ id).style.display = 'none';
		}

		if(isValid) {
			if(whf_fields[id]['errorStyle'][errType] == 'errScript') {
				if(defaultStyle || whf_fields[id]['errorScript'].length == 0) {
					if(whf_defaultErrorScript.length > 0) {
						eval(whf_defaultErrorScript +'("'+ id +'", "ERR_NONE");');
					}
				} else {
					if(whf_fields[id]['errorScript'].length > 0) {
						eval(whf_fields[id]['errorScript'] +'("'+ id +'", "ERR_NONE");');
					}
				}
			}
		}

		if(whf_fields[id]['errorStyle'][errType] == 'floatingBox') {
			if(lId != undefined && lId.onmouseover != undefined && lId.onmouseout != undefined) {
				lId.onmouseover = function() {};
				lId.onmouseout = function() {};
			}
			continue;
		}

		if(whf_fields[id]['errorStyle'][errType] == 'list') {
			if(document.getElementById('list_li'+ id) != undefined) {
				document.getElementById('list_li'+ id).style.visibility = 'hidden';
				document.getElementById('list_li'+ id).style.display = 'none';
			}

			var listDef = 'ul';
			if(whf_fields[id]['errorListStyle'] == 'ol') {
				listDef = 'ol';
			} else if(whf_fields[id]['errorListStyle'] == 'dl') {
				listDef = 'dl';
			} else if(whf_fields[id]['errorListStyle'] == 'none') {
				listDef = 'span';
			}

			if(whf_fields[id]['valid'] == false || whf_fields[id]['valid'] == undefined && whf_errListItemCount[listDef] > 0) {
				whf_errListItemCount[listDef] = whf_errListItemCount[listDef] - 1;
				if(whf_errListItemCount[listDef] == 0) {
					document.getElementById(whf_fields[id]['errorListDivision'] +'_list_'+ listDef).style.visibility = 'hidden';
					document.getElementById(whf_fields[id]['errorListDivision'] +'_list_'+ listDef).style.display = 'none';
				}
			}
			continue;
		}
	}
	whf_fields[id]['valid'] = true;
}


function whf_isEmpty(field) {
	if(field.value == '') {
		return true;
	}

	var nr = field.getAttribute('maskNr');
	if(nr != null) {
		var mask = whf_masks[nr].mask;
		mask = mask.replace(/[#X]/g, ' ');
		if(util_trim(mask) == util_trim(field.value)) {
			return true;
		}
	}

	if(field.type == 'checkbox' && field.checked == false) {
		return true;
	}
	return false;
}

function setDefaultErrorValidationMethod(method) {
	whf_defaultValidationMethod = method;
}

function whf_checkField(id, checkRequired) {
	var field = document.getElementById(id);
	var error = false;
	var errMessage = '';
	var __first = null;
	try {
		if(whf_fields[id]['items'] != null) {
			if(whf_fields[id]['required'] && checkRequired) {
				error = true;
				errMessage = 'ERR_EMPTY';
				for(var i = 0; i < whf_fields[id]['items'].length; i++) {
					if(whf_fields[id]['items'][i].checked) {
						error = false;
						errMessage = '';
					}
				}
			}
		} else if(whf_isEmpty(field)) {
			if(whf_fields[id]['required'] && checkRequired) {
				error = true;
				errMessage = 'ERR_EMPTY';
			}
		} else {
			if(!error && whf_fields[id]['min_length'] != null && field.value.length < whf_fields[id]['min_length']) {
				errMessage = 'ERR_MIN_LENGTH';
				error = true;
			}

			if(!error && whf_fields[id]['max_length'] != null && field.value.length > whf_fields[id]['max_length']) {
				errMessage = 'ERR_MAX_LENGTH';
				error = true;
			}

			if(!error && whf_fields[id]['min'] != null && util_parseFloat(field.value) < whf_fields[id]['min']) {
				errMessage = 'ERR_MIN_VALUE';
				error = true;
			}

			if(!error && whf_fields[id]['max'] != null && util_parseFloat(field.value) > whf_fields[id]['max']) {
				errMessage = 'ERR_MAX_VALUE';
				error = true;
			}

			if(!error) {
				for(var regexp in whf_fields[id]['regexps']) {
					var ret = whf_fields[id]['regexps'][regexp].exec(field.value);
					if(!ret) {
						errMessage = whf_fields[id]['regexpErrCodes'][regexp];
						error = true;
					}
				}
			}

			if(!error && whf_fields[id]['allow_past'] != null && whf_fields[id]['allow_past'] == false) {
				var now = new Date();
				var input = field.value.split('-');
				now = new Date(now.getFullYear(), now.getMonth(), now.getDate());
				input = new Date(parseInt(input[2], 10), parseInt(input[1], 10) - 1, parseInt(input[0], 10));
				if(now.getTime() > input.getTime()) {
					errMessage = 'ERR_PAST';
					error = true;
				}
			}

			if(!error && whf_fields[id]['allow_future'] != null && whf_fields[id]['allow_future'] == false) {
				var now = new Date();
				var input = field.value.split('-');
				now = new Date(now.getFullYear(), now.getMonth(), now.getDate());
				input = new Date(parseInt(input[2], 10), parseInt(input[1], 10) - 1, parseInt(input[0], 10));
				if(now.getTime() < input.getTime()) {
					errMessage = 'ERR_FUTURE';
					error = true;
				}
			}
			if(!error && whf_fields[id]['date_field'] != null && whf_fields[whf_fields[id]['date_field']]['valid'] == true) {
				var datef = whf_fields[whf_fields[id]['date_field']];
				var now = new Date();
				var tinput = field.value.split(':');
				if(datef['allow_past'] != null && datef['allow_past'] == false) {
					var dinput=datef['obj'].value.split('-');
					if(!tinput[2]) {
						tinput[2] = 0;
					}
					var input = new Date(parseInt(dinput[2], 10), parseInt(dinput[1], 10) - 1, parseInt(dinput[0], 10), parseInt(tinput[0], 10), parseInt(tinput[1], 10), parseInt(tinput[2], 10));
					if(now.getTime() > input.getTime()) {
						errMessage = 'ERR_PAST';
						error = true;
					}
				}
				if(datef['allow_future'] != null && datef['allow_future'] == false) {
					var dinput = datef['obj'].value.split('-');
					if(!tinput[2]) {
						tinput[2] = 0;
					}
					var input=new Date(parseInt(dinput[2], 10), parseInt(dinput[1], 10) - 1, parseInt(dinput[0], 10), parseInt(tinput[0], 10), parseInt(tinput[1], 10), parseInt(tinput[2], 10));
					if(now.getTime() < input.getTime()) {
						errMessage = 'ERR_FUTURE';
						error = true;
					}
				}
			}

			// javascript callbacks :
			// TODO?? //
		}
	} catch(e) {
	}
	if(error) {
		whf_showError(id,errMessage);
		__first = id;
	} else {
		whf_resetError(id,true);
	}
	return __first;
}

function whf_submitIntermediate() {
	whf_doJavaScriptChecks = false;

	var whf_hiddenField = document.createElement('input');
	whf_hiddenField.type = 'hidden';
	whf_hiddenField.name = 'intermediateSubmit';
	whf_hiddenField.value = '1';

	document.getElementById('whf_form').appendChild(whf_hiddenField);
	document.getElementById('whf_form').submit();
}

function whf_checkForm(obj) {
	var btn = null;
	if(whf_submitId != null) {
		btn = document.getElementById(whf_submitId);
	}

	var first = null;
	var _first = null;
	if(whf_doJavaScriptChecks) {
		for(var id in whf_fields) {
		  _first = whf_checkField(id, true);
			if(first == null) {
				first = _first;
			}
		}
	}

	if(first != null) {
		whf_focus(first);
		return false;
	}

	// do form level javascriptCallbackValidation
	var formOk = true;
	if(whf_formValidationCallback != '') {
		var exec = 'formOk = '+ whf_formValidationCallback +'();';
		eval(exec);
	}

	if(formOk != true) {
		whf_showError('_whf_form', formOk);
		return false;
	}

	// form is ok
	var onsend = obj.getAttribute('onsend');
	if(onsend != '') {
		eval(onsend);
	}
	if(whf_preventmultiplesubmit && btn != null) {
		btn.disabled = true;
		var unix = new Date().getTime();
		var func = function() {
			var now = new Date().getTime();
			if(now - unix > 1000) {
				btn.disabled = false;
			} else {
				setTimeout(func, 500);
			}
			unix = now;
		}
		setTimeout(func, 500);
	}
	return true;
}

function whf_Combobox(id, div_id, defaultValue) {
	this.id = id;
	this.autocompleteQueued = false;
	this.changed = false;

	this.div = document.getElementById(div_id + '-div');
	this.div.setAttribute('cbid', this.id);

	this.sel = document.getElementById(div_id + '-sel');
	this.sel.setAttribute('cbid', this.id);

	this.inp = document.getElementById(div_id);
	this.inp.setAttribute('cbid', this.id);

	this.img = document.getElementById(div_id + '-img');
	this.img.setAttribute('cbid', this.id);

	this.defaultValue = defaultValue;

	if(this.defaultValue != null) {
		this.setValue(this.defaultValue);
	}
}

whf_Combobox.prototype.initialize = function() {
	if(this.sel.offsetWidth == 0) {
		window.setTimeout('whf_cb['+ this.id +'].initialize()', 40);
		return;
	}

	this.div.onfocus = function() {
		whf_cb_focus(this);
	}

	this.sel.selectedIndex = -1;
	this.sel.tabIndex = -1;
	if(!this.sel.onchange) {
		this.sel.onchange = function() {
			whf_cb_change(this);
		}
	} else {
		var tmp = this.sel.onchange;
		this.sel.onchange = function() {
			whf_cb_change(this);
			tmp();
		}
	}

	this.inp.onkeydown = function() {
		whf_cb_keydown(this);
	}
	this.inp.onkeyup = function() {
		whf_cb_keyup(this);
	}
	this.inp.onblur = function() {
		whf_cb_blur(this);
	}

	this.resize();
}

whf_Combobox.prototype.resize = function() {
	this.width = this.sel.offsetWidth;
	this.height = this.sel.offsetHeight;
	this.arrowWidth = this.height * 0.88;

	this.div.style.width = this.width +'px';
	this.div.style.height = this.height +'px';

	this.sel.style.width = this.width +'px';
	this.sel.style.clip = 'rect(auto auto auto '+ (this.width - this.arrowWidth) +'px)';

	this.inp.style.width = (this.width - this.arrowWidth + 2) +'px';

	this.img.style.height = '1px';
	this.img.style.width = this.width +'px';
}

whf_Combobox.prototype.setValue = function(value) {
	this.inp.value = value;

	value = value.toLowerCase();
	for(i = 0; i < this.sel.options.length; i++) {
		var search = this.sel.options[i].innerHTML.toLowerCase();
		if(value == search) {
			this.sel.selectedIndex = i;
		}
	}
	if(this.inp.fireEvent) {
		this.inp.fireEvent('onchange');
	} else if(this.inp.onchange) {
		this.inp.onchange();
	}
}

whf_Combobox.prototype.autocomplete = function() {
	if(!this.autocompleteQueued) {
		return;
	}

	this.autocompleteQueued = false;

	var match = this.inp.value.toLowerCase();
	if(match == '') {
		return;
	}

	for(var i = 0; i < this.sel.options.length; i++) {
		var search = this.sel.options[i].innerHTML.toLowerCase();
		if(search.indexOf(match) == 0) {
			this.inp.value += this.sel.options[i].innerHTML.substring(match.length, search.length);
			this.changed = true;
			var range = this.inp.createTextRange();
			range.moveStart('character', match.length);
			range.select();
			break;
		}
	}
}

whf_Combobox.prototype.setCase = function() {
	var match = this.inp.value.toLowerCase();

	if(match == '') {
		return;
	}

	for(var i = 0; i < this.sel.options.length; i++) {
		var search = this.sel.options[i].innerHTML.toLowerCase();
		if(match == search && this.inp.value != this.sel.options[i].innerHTML) {
			this.inp.value = this.sel.options[i].innerHTML;
			this.changed = true;
			break;
		}
	}
}

whf_Combobox.prototype.sel_stepEntry = function(step) {
	var newidx = this.sel.selectedIndex + step;
	if(newidx < 0) {
		return;
	}
	if(newidx > (this.sel.options.length - 1)) {
		return;
	}
	this.sel.selectedIndex = newidx;
	this.sel_change();
}

whf_Combobox.prototype.sel_change = function() {
	this.inp.value = this.sel.options[this.sel.selectedIndex].innerHTML;
	if(this.inp.fireEvent) {
		this.inp.fireEvent('onchange');
	} else if(this.inp.onchange) {
		this.inp.onchange();
	}
	this.changed = false;
	this.inp.select();
	this.inp.focus();
}

whf_Combobox.prototype.inp_keydown = function() {
	if(event.keyCode == 38) {
		this.sel_stepEntry(-1);
	} else if(event.keyCode == 40) {
		this.sel_stepEntry(1);
	}
}

whf_Combobox.prototype.inp_keyup = function() {
	if(event.keyCode < 49 && event.keyCode != 32) {
		return;
	} else if(event.Control || event.Alt) {
		return;
	}

	this.autocompleteQueued = true;
	window.setTimeout('whf_cb['+ this.id +'].autocomplete()', 50);
}

whf_Combobox.prototype.inp_blur = function() {
	this.setCase();
	if(this.changed) {
		if(this.inp.fireEvent) {
			this.inp.fireEvent('onchange');
		} else if(this.inp.onchange) {
			this.inp.onchange();
		}
		this.changed = false;
	}
}

function whf_cb_init(div_id, defaultValue) {
	var id = whf_cb.length;
	whf_cb[id] = new whf_Combobox(id, div_id, defaultValue);
	whf_cb[id].initialize();
}

function whf_cb_focus(sel_obj) {
	var id = sel_obj.getAttribute('cbid');
	whf_cb[id].inp.focus();
}

function whf_cb_change(sel_obj) {
	var id = sel_obj.getAttribute('cbid');
	whf_cb[id].sel_change();
}

function whf_cb_keydown(inp_obj) {
	var id = inp_obj.getAttribute('cbid');
	whf_cb[id].inp_keydown();
}

function whf_cb_keyup(inp_obj) {
	var id = inp_obj.getAttribute('cbid');
	whf_cb[id].inp_keyup();
}

function whf_cb_blur(inp_obj) {
	var id = inp_obj.getAttribute('cbid');
	whf_cb[id].inp_blur();
}

function whf_toggleInteger(obj, disable, decimal_point, thousands_separator) {
	var value = null;
	if(typeof obj == 'object') {
		value = obj.value;
	} else {
		value = obj +'';
	}

	var intval = util_parseInteger(value, decimal_point, thousands_separator);
	var result = '';

	if(disable) {
		if(!intval) {
			result = '';
		} else {
			result = intval;
		}
	} else if(!disable && intval) {
		result = util_formatInteger(intval, thousands_separator);
	}

	if(typeof obj == 'object') {
		if(result != obj.value && result) {
			obj.value = result;
		}
	} else {
		return result;
	}
}

function whf_toggleFloat(obj, decimals, disable, decimal_point, thousands_separator) {
	if(decimals === 0) {
		return whf_toggleInteger(obj, disable, decimal_point, thousands_separator);
	}
	var value = null;
	if(typeof obj == 'object') {
		value = obj.value;
	} else {
		value = obj + '';
	}

	var floatval = util_parseFloat(value, decimal_point, thousands_separator);

	var result = '';
	if(disable) {
		if(!floatval) {
			result = '';
		} else {
			//TODO: , vervangen door decimal_separator indien ingevuld
			result = new String(floatval).replace(/\./, ',');
		}
	} else if(!disable && floatval) {
		result = util_formatFloat(floatval, decimals, decimal_point, thousands_separator);
	}

	if(typeof obj == 'object') {
		if(result != obj.value && result) {
			obj.value = result;
		}
	} else {
		return result;
	}
}

function whf_formatKenteken(obj, disable) {
	var value = null;
	if(typeof obj == 'object') {
		value = obj.value;
	} else {
		value = obj +'';
	}

	var result = value.replace(/-/g, '').toUpperCase();

	if(!disable && result.length == 6) {
		if(/[0-9]{2}[A-Z]{3}[0-9]|[A-Z]{2}[0-9]{3}[A-Z]/.exec(result)) {
			result = result.substring(0, 2) + '-' + result.substring(2, 5) + '-' + result.substring(5, 6);
		} else if(/[0-9][A-Z]{3}[0-9]{2}|[A-Z][0-9]{3}[A-Z]{2}/.exec(result)) {
			result = result.substring(0, 1) + '-' + result.substring(1, 4) + '-' + result.substring(4, 6);
		} else {
			result = result.substring(0, 2) + '-' + result.substring(2, 4) + '-' + result.substring(4, 6);
		}
	}

	if(typeof obj == 'object') {
		if(result != obj.value) {
			obj.value = result;
		}
	} else {
		return result;
	}
}

function whf_createInputHash() {
	var inputHash = '';

	for(var index in whf_fields) {
		try {
			// commented fields:
			if (document.getElementById(index) == undefined) {
				continue;
			}

			if(whf_fields[index]['items'] != null) {
				// Radio Field
				inputHash = inputHash +'^%^'+ whf_fields[index]['items'][0].value;
				continue;
			}
			value = document.getElementById(index).value;

			if(document.getElementById(index).type == 'checkbox') {
				value = (document.getElementById(index).checked ? 'true' : 'false');
			} else if(document.getElementById(index).type == 'hidden') {
				value = '';
			}

			inputHash = inputHash +'_'+ value;
		} catch(e) {
		}
	}

	try {
		return whf_simpleHash(inputHash);
	} catch(e) {
	}
}

function whf_simpleHash(content) {
	var len = content.length;
	var total = 0;
	for(var teller = 0; teller < len; teller++) {
		total = (total + ((teller + 1) * content.charCodeAt(teller)*(len-teller+1))) & 131071;
	}
	return total;
}

function whf_formChanged() {
	if(whf_createInputHash() != whf_inputHash) {
		return true;
	} else {
		return false;
	}
}

function whf_newMask(id, mask) {
	if(mask.length == 0) {
		return;
	}
	var nr = whf_masks.length;
	whf_masks[nr] = new whf_Mask(nr, id, mask);
}

function whf_Mask_onkeydown(obj) {
	var nr = obj.getAttribute('maskNr');
	return whf_masks[nr].onkeydown();
}

function whf_Mask_onkeyup(obj) {
	var nr = obj.getAttribute('maskNr');
	return whf_masks[nr].onkeyup();
}

function whf_Mask_onkeypress(obj) {
	var nr = obj.getAttribute('maskNr');
	return whf_masks[nr].onkeypress();
}

function whf_Mask_onfocus(obj) {
	var nr = obj.getAttribute('maskNr');
	return whf_masks[nr].onfocus();
}

function whf_Mask_onclick(obj) {
	var nr = obj.getAttribute('maskNr');
	return whf_masks[nr].onclick();
}

function whf_Mask_onpaste(obj) {
	var nr = obj.getAttribute('maskNr');
	return whf_masks[nr].onpaste();
}

function whf_Mask(nr, id, mask) {
	this.nr = nr;
	this.mask = mask;
	this.value = '';
	if(typeof id == 'object') {
		this.id = null;
		this.field = id;
	} else {
		this.id = id;
		this.field = document.getElementById(this.id);
	}
	this.field.setAttribute('maskNr', this.nr);
	if(!this.field.className) {
		this.field.style.fontFamily = 'Courier New, courier';
		this.field.style.fontSize = '9pt';
	}
	if(this.field.size == 20 && this.mask.length != 0) {
		this.field.size = this.mask.length;
	}
	this.maxLength = this.mask.replace(/[^#Xx]/g, '').length;
	this.field.maxLength = this.mask.length;
	this.caretPos = 0;
	this.inputPos = 0;

	var oldValue = this.field.value;
	this.field.value = '';
	this.redraw(false);

	if(oldValue != '') {
		this.handleInput(oldValue);
	}

	if(!this.field.onkeydown) {
		this.field.onkeydown = function() {
			return whf_Mask_onkeydown(this);
		}
	} else {
		var tmp = this.field.onkeydown;
		this.field.onkeydown = function() {
			var ret1 = whf_Mask_onkeydown(this);
			var ret2 = tmp();
			return(ret1 && ret2);
		}
	}
	if(!this.field.onkeyup) {
		this.field.onkeyup = function() {
			return whf_Mask_onkeyup(this);
		}
	} else {
		var tmp = this.field.onkeyup;
		this.field.onkeyup = function() {
			var ret1 = whf_Mask_onkeyup(this);
			var ret2 = tmp();
			return(ret1 && ret2);
		}
	}
	if(!this.field.onkeypress) {
		this.field.onkeypress = function() {
			return whf_Mask_onkeypress(this);
		}
	} else {
		var tmp = this.field.onkeypress;
		this.field.onkeypress = function() {
			var ret1 = whf_Mask_onkeypress(this); 
			var ret2 = tmp();
			return(ret1 && ret2);
		}
	}
	if(!this.field.onfocus) {
		this.field.onfocus = function() {
			return whf_Mask_onfocus(this);
		}
	} else {
		var tmp = this.field.onfocus;
		this.field.onfocus = function() {
			var ret1 = whf_Mask_onfocus(this);
			var ret2 = tmp();
			return(ret1 && ret2);
		}
	}
	if(!this.field.onclick) {
		this.field.onclick = function() {
			return whf_Mask_onclick(this);
		}
	} else {
		var tmp = this.field.onclick;
		this.field.onclick = function() {
			var ret1 = whf_Mask_onclick(this);
			var ret2 = tmp();
			return(ret1 && ret2);
		}
	}
	if(!this.field.onpaste) {
		this.field.onpaste = function() {
			return whf_Mask_onpaste(this);
		}
	} else {
		var tmp = this.field.onpaste;
		this.field.onpaste = function() {
			var ret1 = whf_Mask_onpaste(this);
			var ret2 = tmp();
			return(ret1 && ret2);
		}
	}
}

whf_Mask.prototype.getCaretPos = function() {
	this.caretPos = util_getSelectionStart(this.field);
}

whf_Mask.prototype.calcInputPos = function() {
	this.inputPos = 0;
	var moveLeft = 0;
	for(i = 0; i < this.caretPos; i++) {
		if(this.inputPos < this.value.length) {
			if(this.isSpecialMaskChar(i)) {
				this.inputPos++;
			}
		} else {
			moveLeft++;
		}
	}

	if((this.caretPos - moveLeft) < this.mask.length && !this.isSpecialMaskChar(this.caretPos - moveLeft)) {
		moveLeft--;
	}

	if(moveLeft > 0) {
		this.moveLeft(moveLeft);
	}
	if(moveLeft < 0) {
		this.moveRight(-moveLeft);
	}
}

whf_Mask.prototype.isSpecialMaskChar = function(pos) {
	var maskChar = this.mask.charAt(pos);
	if(maskChar == 'X' || maskChar == 'x' || maskChar == '#') {
		return true;
	} else {
		return false;
	}
}

/* Look if we should move the caret to the right */
whf_Mask.prototype.checkMoveRight = function() {
	var moveRight = 0;
	while(this.caretPos + moveRight < this.mask.length && !this.isSpecialMaskChar(this.caretPos + moveRight)) {
		moveRight++;
	}

	if(moveRight > 0) {
		this.moveRight(moveRight);
	}
}

whf_Mask.prototype.redraw = function(setCaret) {
	var s = '';
	var j = 0;
	for(var i = 0; i < this.mask.length; i++) {
		if(!this.isSpecialMaskChar(i)) {
			s += this.mask.charAt(i);
		} else {
			if(j >= this.value.length) {
				s += ' ';
			} else {
				s += this.value.charAt(j);
				j++;
			}
		}
	}
	this.field.value = s;

	// Reposition caret
	if(setCaret) {
		window.setTimeout('whf_masks[' + this.nr + '].moveTo(' + this.caretPos + ')', 5);
	}
}

whf_Mask.prototype.handleInput = function(input) {
	if(input.length == 0) {
		return;
	}

	var redraw = false;
	var seltext = util_getSelectedText(this.field);
	if(seltext != '') {
		if(seltext.length == this.mask.length) {
			this.value = '';
			redraw = true;
		} else {
			// We can't handle partly selections yet
			return;
		}
	}

	var s = '';
	var pos = this.caretPos;
	for(var i = 0; i < input.length; i++) {
		var inputChar = input.charAt(i);
		while(pos < this.mask.length && !this.isSpecialMaskChar(pos)) {
			pos++;
		}
		if(pos < this.mask.length) {
			var maskChar = this.mask.charAt(pos);
			switch(maskChar) {
				case 'X':
					inputChar = inputChar.toUpperCase();
					if( (inputChar >= 'A' && inputChar <= 'Z') ||
						 (inputChar >= '0' && inputChar <= '9') ) {
						s += inputChar;
						pos++;
					}
					break;
				case 'x':
					if( (inputChar >= 'A' && inputChar <= 'Z') ||
						 (inputChar >= 'a' && inputChar <= 'z') ||
						 (inputChar >= '0' && inputChar <= '9') ) {
						pos++;
						s += inputChar;
					}
					break;
				case '#':
					if(inputChar >= '0' && inputChar <= '9') {
						s += inputChar;
						pos++;
					}
					break;
			}
		}
	}
	this.insertChar(s);

	if(redraw) {
		this.redraw(true);
	}
}

whf_Mask.prototype.handleBackspace = function() {
	var seltext = util_getSelectedText(this.field);
	if(seltext != '') {
		if(seltext.length == this.mask.length) {
			if(this.value != '') {
				this.value = '';
				this.redraw(true);
			} else {
				this.moveHome();
			}
			return;
		} else {
			// We can't handle partly selections yet
			return;
		}
	}

	if(this.value != '') {
		if(!this.isSpecialMaskChar(this.caretPos - 1)) {
			this.caretPos = this.caretPos - 2;
		} else {
			this.caretPos--;
		}
		this.value = this.value.substring(0, this.inputPos - 1) + this.value.substring(this.inputPos, this.value.length);
		this.redraw(true);
	} else {
		this.moveHome();
	}
}

whf_Mask.prototype.handleDelete = function() {
	var seltext = util_getSelectedText(this.field);
	if(seltext != '') {
		if(seltext.length == this.mask.length) {
			this.value = '';
			this.redraw(true);
			return;
		} else {
			// We can't handle partly selections yet
			return;
		}
	}

	this.value = this.value.substring(0, this.inputPos) + this.value.substring(this.inputPos + 1, this.value.length);
	this.redraw(true);
}

whf_Mask.prototype.insertChar = function(input) {
	if(input == '') {
		return;
	}

	if(this.value.length + input.length > this.maxLength) {
		return;
	}

	redraw = false;

	if(this.inputPos == this.value.length) {
		this.value += input;
	} else {
		this.value = this.value.substring(0, this.inputPos) + input + this.value.substring(this.inputPos, this.value.length);
		redraw = true;
	}
	this.inputPos += input.length;

	if(input.length > 1) {
		this.caretPos = this.mask.length;
		redraw = true;
	} else {
		var r = document.selection.createRange();
		r.moveEnd('character', 1);
		r.text = input;
		r.select();

		this.caretPos++;
		this.checkMoveRight();
	}
	if(redraw) {
		this.redraw(true);
	}
}

whf_Mask.prototype.moveRight = function(amount) {
	if(amount == null) {
		amount = 1;
	}
	if(amount == 0) {
		return;
	}

	this.caretPos += amount;

	var r = this.field.createTextRange();
	r.move('character', this.caretPos);
	r.select();

	this.calcInputPos();
}

whf_Mask.prototype.moveLeft = function(amount) {
	if(amount == null) {
		amount = 1;
	}
	if(amount == 0) {
		return;
	}

	this.caretPos -= amount;
	if(this.caretPos < 0) {
		this.caretPos = 0;
	}

	var r = this.field.createTextRange();
	r.move('character', this.caretPos);
	r.select();

	this.calcInputPos();
}

whf_Mask.prototype.moveHome = function() {
	var r = this.field.createTextRange();
	r.move('character', 0);
	r.select();

	this.caretPos = 0;
	this.inputPos = 0;
}

whf_Mask.prototype.moveEnd = function() {
	var r = this.field.createTextRange();
	r.move('character', this.mask.length);
	this.caretPos = this.mask.length;
	this.calcInputPos();
}

whf_Mask.prototype.moveTo = function(pos) {
	var r = this.field.createTextRange();
	r.move('character', -999999);
	r.move('character', pos);
	r.select();

	this.caretPos = pos;
	this.calcInputPos();
}


whf_Mask.prototype.onkeydown = function() {
	var keyCode = event.keyCode;

	if(event.ctrlKey || event.altKey) {
		return true;
	}

	switch(keyCode) {
		case 8:
			// Backspace
			this.handleBackspace();
			return false;

		case 27:
			// Escape
			this.value = '';
			this.redraw(true);
			return false;

		case 33:
			// Pageup
			this.moveHome();
			return false;

		case 34:
			// Pagedown
			this.moveEnd();
			return false;

		case 35:
			// End
			this.moveEnd();
			return false;

		case 36:
			// Home
			this.moveHome();
			return false;

		case 37:
			// Move left
			moveLeft = 1;
			while(this.caretPos - moveLeft >= 0 && !this.isSpecialMaskChar(this.caretPos - moveLeft)) {
				moveLeft++;
			}
			this.moveLeft(moveLeft);
			return false;

		case 38:
			// Move up
			this.moveHome();
			return false;

		case 39:
			// Move right
			this.moveRight(1);
			return false;

		case 40:
			// Move down
			this.moveEnd();
			return false;

		case 46:
			// Delete
			this.handleDelete();
			return false;

		default:
			break;
	}

	return true;
}

whf_Mask.prototype.onkeyup = function() {
	return true;
}

whf_Mask.prototype.onkeypress = function() {
	var keyCode = event.keyCode;
	var inputChar = String.fromCharCode(keyCode);
	this.handleInput(inputChar);
	return false;
}

whf_Mask.prototype.onfocus = function() {
	this.getCaretPos();
	this.calcInputPos();
	return true;
}

whf_Mask.prototype.onclick = function() {
	this.getCaretPos();
	this.calcInputPos();
	return true;
}

whf_Mask.prototype.onpaste = function() {
	var pasteData = window.clipboardData.getData('Text');
	this.handleInput(pasteData);
	return false;
}

/**
 *  util_showFb triggers a floating box to show
 *  howto: Create a division like:
 * 	<DIV id="[name]">
 * 	</DIV>
 *
 * Usage
 * onmouseOver="util_showFb('[title]','[content]');" onmouseOut="util_hideFb();"
 */
function util_showFb(element, type) {
	var floatingBoxId = 'errmsg'+ element.id.substr(type.length);
	if(whf_visibleDiv != floatingBoxId && document.getElementById(floatingBoxId) != undefined) {
		document.getElementById('whf_error_root').style.display = 'inline';
		document.getElementById('whf_error_root').style.visibility = 'inherit';
		document.getElementById(floatingBoxId).style.display = 'inline';
		document.getElementById(floatingBoxId).style.visibility = 'inherit';
		whf_visibleDiv = floatingBoxId;
	}
}

function util_hideFb() {
	if(whf_visibleDiv != -1) {
		document.getElementById('whf_error_root').style.display = 'none';
		document.getElementById('whf_error_root').style.visibility = 'hidden';
		document.getElementById(whf_visibleDiv).style.display = 'none';
		document.getElementById(whf_visibleDiv).style.visibility = 'hidden';
		whf_visibleDiv = -1;
	}
}

// TODO
function util_createFloatingDiv(id) {
	var _style = 'border: 1px solid black; border-color: #000; background-color: #fff; padding: 2px;';
	if(typeof whf_floatingDivStyle != 'undefined') {
		_style = whf_floatingDivStyle;
	}
	document.getElementById('whf_error_root').innerHTML = document.getElementById('whf_error_root').innerHTML +'<div id="'+ id +'" class="whf_Floatbox" style="position: absolute; z-index: 1000; visibility: hidden; display: none; width: '+ whf_errorFloatBoxWidth +'px; '+ _style +'"></div>';
}

/** MouseHandler
 *  Receives a handle from any mousemovement in the document, moves whf_visibleDiv accordingly (if set)
 */
function whf_getMouseXY(e) {
	var mousePosX, mousePosY, tempX, tempY, winW, winH;

	if(whf_visibleDiv != -1) {
		if(whf_IE) {
			var iebody = (document.compatMode && document.compatMode != 'BackCompat' ? document.documentElement : document.body);
			tempX = event.x + document.body.scrollLeft;
			tempY = event.y + document.body.scrollTop;
			mousePosX = event.clientX;
			mousePosY = event.clientY;
			winW = iebody.clientWidth;
			winH = iebody.clientHeight;
		} else {
			tempX = e.layerX;
			tempY = e.layerY;
			mousePosX = e.clientX;
			mousePosY = e.clientY;
			winW = window.innerWidth;
	 		winH = window.innerHeight;
		}

		if(tempX < 0) {
			tempX = 0;
		}
		if(tempY < 0) {
			tempY = 0;
		}

		if(parseInt(mousePosX, 10) + 15 + whf_errorFloatBoxWidth > winW) {
			tempX = tempX - whf_errorFloatBoxWidth - 30;
		}

		if(parseInt(mousePosY, 10) + 100 > winH) {
			tempY = tempY - 120;
		}

		document.getElementById(whf_visibleDiv).style.left = (tempX + 15) +'px';
		document.getElementById(whf_visibleDiv).style.top = (tempY + 15) +'px';
	}

	if(whf_oldhandler.length > 0) {
		whf_oldhandler(e);
	}
}

function whf_addOnBlur(id, handler, addBeforeFirst) {
	if(whf_fields[id]['onblur'] == undefined) {
		whf_fields[id]['onblur'] = [handler];
	} else if(addBeforeFirst) {
		var tmp = whf_fields[id]['onblur'];
		whf_fields[id]['onblur'] = [handler];
		for(var teller = 0; teller < tmp.length; teller++) {
			whf_fields[id]['onblur'].push(tmp[teller]);
		}
	} else {
		whf_fields[id]['onblur'].push(handler);
	}

	var onblurCaption = '';
	for(index in whf_fields[id]['onblur']) {
		 onblurCaption = onblurCaption + whf_fields[id]['onblur'][index] +'; ';
	}
	whf_fields[id]['_onblurcaption'] = onblurCaption;
	if(whf_fields[id]['obj'] != undefined) {
		whf_fields[id]['obj'].onblur = function() {
			eval(whf_fields[this.id]['_onblurcaption']);
		};
	}
}

function whf_fixTime(field, duration) {
	if(field.value.length == 0) {
		return;
	}
	var id = field.id;
	var split = field.value.split(':');
	for(var i = 0; (whf_fields[id]['with_seconds'] ? 3 : 2) > i; i++) {
		if(typeof split[i] == 'undefined') {
			split[i] = '00';
		}
		split[i] = split[i].replace(/ +/, '');
		if(split[i].length == 0) {
			split[i] = '00';
		}
		if(isNaN(split[i])) {
			return;
		}
		if(i == 0 && duration) {
			split[i] = parseInt(split[i], 10);
			continue;
		}
		while(split[i].length < 2) {
			split[i] = '0'+ split[i];
		}
	}
	field.value = split.join(':');
}
var wh_columnviews = [];

function ColumnView(container_id) {
	this.id = wh_columnviews.length;
	wh_columnviews[this.id] = this;
	this.container_id = container_id;
	this.tr_id = container_id + '_tr';
	this.container = document.getElementById(this.container_id);
	this.items = [];
	this.itemsPerColumn = 0;
	this.columnPadding = 10;
	this.minColumnWidth = 150;
	this.minVisibleColumns = 0;
	this.numColumns = 0;
	this.itemHeight = 20;
	this.itemClassName = 'option';
	this.columnmClassName = 'column';
	this.redrawing = false;
}

ColumnView.prototype.add = function(s) {
	this.items.push(s);
}

ColumnView.prototype.clear = function() {
	this.items = [];
}

ColumnView.prototype.onresize = function() {
	if(this.resizeTimer) {
		window.clearTimeout(this.resizeTimer);
	}
	this.resizeTimer = window.setTimeout('wh_columnviews[' + this.id + '].draw()', 40);
}

ColumnView.prototype.draw = function(redrawItems) {
	if(this.redrawing) {
		return;
	}
	this.drawing = true;

	var totalHeight = this.container.offsetHeight;
	totalHeight = totalHeight - 23;	// Scrollbar

	itemsPerColumn = Math.floor(totalHeight / this.itemHeight);
	minVisibleColumns = Math.floor(this.container.offsetWidth / (this.minColumnWidth + this.columnPadding));

	if(!redrawItems && itemsPerColumn == this.itemsPerColumn && minVisibleColumns == this.minVisibleColumns) {
		return;
	}

	if(!redrawItems) {
		for(i = 0; i < this.items.length; i++) {
			this.items[i] = document.getElementById(this.container_id + '_option' + i).innerHTML;
		}
	}

	this.itemsPerColumn = itemsPerColumn;
	this.minVisibleColumns = minVisibleColumns;
	this.container.innerHTML = '<table cellspacing="0" cellpadding="0"><tr id="' + this.tr_id + '"></tr></table>';

	this.numColumns = Math.ceil(this.items.length / this.itemsPerColumn);

	if(this.minVisibleColumns > this.numColumns) {
		if(this.numColumns > 0) {
			columnWidth = (this.container.offsetWidth / this.numColumns) - this.columnPadding;
		} else {
			columnWidth = 120;
		}
	} else {
		if(this.minVisibleColumns > 0) {
			columnWidth = (this.container.offsetWidth / this.minVisibleColumns) - this.columnPadding;
		} else {
			columnWidth = 120;
		}
	}

	curColumn = 0;
	curRow = 0;
	column = [];
	opt = [];
	for(i = 1; i <= this.items.length; i++) {
		if(curRow == 0) {
			curColumn++;
			column[curColumn] = document.createElement('td');
			column[curColumn].className = this.columnClassName;
			column[curColumn].style.width = columnWidth;
			column[curColumn].style.verticalAlign = 'top';
		}

		opt[i] = document.createElement('div');
		opt[i].id = this.container_id + '_option' + (i - 1);
		opt[i].className = this.itemClassName;
		opt[i].style.width = columnWidth;
		opt[i].style.height = this.itemHeight +'px';
		opt[i].innerHTML = this.items[i - 1];
		column[curColumn].appendChild(opt[i]);

		curRow++;
		if(curRow >= this.itemsPerColumn) {
			curRow = 0;
			document.getElementById(this.tr_id).appendChild(column[curColumn]);
		}
	}
	if(curRow > 0) {
		document.getElementById(this.tr_id).appendChild(column[curColumn]);
	}

	this.drawing = false;
}

ColumnView.prototype.drawVert = function(redrawItems) {
	if(this.redrawing) {
		return;
	}
	this.drawing = true;

	var totalWidth;

	if(typeof this.container.width == 'undefined')  {
		totalWidth = this.container.offsetWidth;
	} else {
		totalWidth = this.container.width;
	}
	totalWidth = totalWidth - 23;	// Scrollbar

	var numColumns = Math.floor(totalWidth / this.minColumnWidth);
	var extraColumnWidth = (totalWidth % this.minColumnWidth) / numColumns;

	if(!redrawItems && itemsPerColumn == this.itemsPerColumn && minVisibleColumns == this.minVisibleColumns) {
		return;
	}

	if(!redrawItems) {
		for(i = 0; i < this.items.length; i++) {
			this.items[i] = document.getElementById(this.container_id + '_option' + i).innerHTML;
		}
	}

	this.numColumns = numColumns;
	this.itemsPerColumn  = Math.ceil(this.items.length / this.numColumns);
	this.container.innerHTML = '<table cellspacing="0" cellpadding="0"><tr id="' + this.tr_id + '"></tr></table>';

	var columnWidth = this.minColumnWidth + extraColumnWidth;

	var curColumn = 0;
	var curRow = 0;
	var column = [];
	var opt = [];
	for(i = 1; i <= this.items.length; i++) {
		if(curRow == 0) {
			curColumn++;
			column[curColumn] = document.createElement('td');
			column[curColumn].className = this.columnClassName;
			column[curColumn].style.width = columnWidth;
			column[curColumn].style.verticalAlign = 'top';
		}

		opt[i] = document.createElement('div');
		opt[i].id = this.container_id + '_option' + (i - 1);
		opt[i].className = this.itemClassName;
		opt[i].style.width = columnWidth;
		opt[i].style.height = this.itemHeight +'px';
		opt[i].innerHTML = this.items[i - 1];
		column[curColumn].appendChild(opt[i]);

		curRow++;
		if(curRow >= this.itemsPerColumn) {
			curRow = 0;
			document.getElementById(this.tr_id).appendChild(column[curColumn]);
		}
	}
	if(curRow > 0) {
		document.getElementById(this.tr_id).appendChild(column[curColumn]);
	}

	this.drawing = false;
}
whf_ajax = {};

whf_ajax = function(url, callback) {
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
		this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			this.xmlHttp = false;
		}
	}
	@end @*/
	if (!this.xmlHttp && typeof XMLHttpRequest != 'undefined') {
		this.xmlHttp = new XMLHttpRequest();
	}

	if(callback) {
		var self = this;
		this.xmlHttp.onreadystatechange = function() {
			self.handler();
		};
		this.callback = callback;
		this.async = true;
	}
	else {
		this.async = false;
	}
	this.url = url;
}

whf_ajax.prototype = {
	xmlHttp: null,
	callback: null,
	url: null,
	method: 'GET',
	async: true,
	postdata: null
};

whf_ajax.prototype.handler = function() {
	if(!this.xmlHttp) {
		return;
	}
	if(this.xmlHttp.readyState == 4) {
		this.doCallback();
	}
}

whf_ajax.prototype.doCallback = function() {
	this.callback(this.xmlHttp);
}

whf_ajax.prototype.setCallback = function(callback) {
	this.callback = callback;
}

whf_ajax.prototype.setRealCallback = function(callback) {
	this.xmlHttp.onreadystatechange = callback;
}

whf_ajax.prototype.setPostData = function(postdata) {
	this.postdata = postdata;
	this.method = 'POST';
}

whf_ajax.prototype.setAsync = function(async) {
	this.async = async;
}

whf_ajax.prototype.setMethod = function(method) {
	this.method = method;
}

whf_ajax.prototype.send = function() {
	this.xmlHttp.open(this.method, this.url, this.async);
	this.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	this.xmlHttp.send(this.postdata);
	if(!this.async && this.callback) {
		this.doCallback();
	} else if(!this.async) {
		return this.xmlHttp.responseText;
	}
}
var wh_md5_state = new wh_array(4);
var wh_md5_count = new wh_array(2);
wh_md5_count[0] = 0;
wh_md5_count[1] = 0;
var wh_md5_buffer = new wh_array(64);
var wh_md5_transformBuffer = new wh_array(16);
var wh_md5_digestBits = new wh_array(16);

var wh_md5_S11 = 7;
var wh_md5_S12 = 12;
var wh_md5_S13 = 17;
var wh_md5_S14 = 22;
var wh_md5_S21 = 5;
var wh_md5_S22 = 9;
var wh_md5_S23 = 14;
var wh_md5_S24 = 20;
var wh_md5_S31 = 4;
var wh_md5_S32 = 11;
var wh_md5_S33 = 16;
var wh_md5_S34 = 23;
var wh_md5_S41 = 6;
var wh_md5_S42 = 10;
var wh_md5_S43 = 15;
var wh_md5_S44 = 21;

var wh_md5_ascii="01234567890123456789012345678901" +
	  " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
	  "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

function wh_array(n) {
	for(i = 0; i < n; i++) {
		this[i] = 0;
	}
	this.length = n;
}

function wh_integer(n) {
	return n % (0xffffffff + 1);
}

function wh_shr(a, b) {
	a = wh_integer(a);
	b = wh_integer(b);
	if(a - 0x80000000 >= 0) {
		a = a % 0x80000000;
		a >>= b;
		a += 0x40000000 >> (b - 1);
	} else {
		a >>= b;
	}
	return a;
}

function wh_shl1(a) {
	a = a % 0x80000000;
	if (a & 0x40000000 == 0x40000000) {
		a -= 0x40000000;
		a *= 2;
		a += 0x80000000;
	} else {
		a *= 2;
	}
	return a;
}

function wh_shl(a, b) {
	a = wh_integer(a);
	b = wh_integer(b);
	for(var i = 0; i < b; i++) {
		a = wh_shl1(a);
	}
	return a;
}

function wh_and(a, b) {
	a = wh_integer(a);
	b = wh_integer(b);
	var t1 = a - 0x80000000;
	var t2 = b - 0x80000000;
	if(t1 >= 0) {
		if(t2 >= 0) {
			return (t1 & t2) + 0x80000000;
		} else {
			return t1 & b;
		}
	} else {
		if(t2 >= 0) {
			return a & t2;
		} else {
			return a & b;	
		}
	}
}

function wh_or(a ,b) {
	a = wh_integer(a);
	b = wh_integer(b);
	var t1 = a - 0x80000000;
	var t2 = b - 0x80000000;
	if(t1 >= 0) {
		if(t2 >= 0) {
			return (t1 | t2) + 0x80000000;
		} else {
			return (t1 | b) + 0x80000000;
		}
	} else {
		if(t2 >= 0) {
			return (a | t2) + 0x80000000;
		} else {
			return a | b;	
		}
	}
}

function wh_xor(a, b) {
	a = wh_integer(a);
	b = wh_integer(b);
	var t1 = a - 0x80000000;
	var t2 = b - 0x80000000;
	if (t1 >= 0) {
		if (t2 >= 0) {
			return t1 ^ t2;
		} else {
			return (t1 ^ b) + 0x80000000;
		}
	} else {
		if (t2 >= 0) {
			return (a ^ t2) + 0x80000000;
		} else {
			return a ^ b;
		}
	}
}

function wh_not(a) {
  a = wh_integer(a);
  return 0xffffffff - a;
}

function wh_md5_F(x, y, z) {
	return wh_or(wh_and(x, y), wh_and(wh_not(x), z));
}

function wh_md5_G(x, y, z) {
	return wh_or(wh_and(x, z), wh_and(y, wh_not(z)));
}

function wh_md5_H(x, y, z) {
	return wh_xor(wh_xor(x, y), z);
}

function wh_md5_I(x, y, z) {
	return wh_xor(y, wh_or(x , wh_not(z)));
}

function wh_md5_rotateLeft(a, n) {
	return wh_or(wh_shl(a, n), wh_shr(a, 32 - n));
}

function wh_md5_FF(a, b, c, d, x, s, ac) {
	a = a + wh_md5_F(b, c, d) + x + ac;
	a = wh_md5_rotateLeft(a, s);
	a = a + b;
	return a;
}

function wh_md5_GG(a, b, c, d, x, s, ac) {
	a = a + wh_md5_G(b, c, d) +x + ac;
	a = wh_md5_rotateLeft(a, s);
	a = a + b;
	return a;
}

function wh_md5_HH(a, b, c, d, x, s, ac) {
	a = a + wh_md5_H(b, c, d) + x + ac;
	a = wh_md5_rotateLeft(a, s);
	a = a + b;
	return a;
}

function wh_md5_II(a, b, c, d, x, s, ac) {
	a = a + wh_md5_I(b, c, d) + x + ac;
	a = wh_md5_rotateLeft(a, s);
	a = a + b;
	return a;
}

function wh_md5_transform(buf,offset) {
	var a = 0;
	var b = 0;
	var c = 0;
	var d = 0;
	var x = wh_md5_transformBuffer;

	a = wh_md5_state[0];
	b = wh_md5_state[1];
	c = wh_md5_state[2];
	d = wh_md5_state[3];

	for(var i = 0; i < 16; i++) {
		x[i] = wh_and(buf[i * 4 + offset], 0xff);
		for(var j = 1; j < 4; j++) {
			x[i] += wh_shl(wh_and(buf[i * 4 + j + offset], 0xff), j * 8);
		}
	}

	/* Round 1 */
	a = wh_md5_FF(a, b, c, d, x[ 0], wh_md5_S11, 0xd76aa478); /* 1 */
	d = wh_md5_FF(d, a, b, c, x[ 1], wh_md5_S12, 0xe8c7b756); /* 2 */
	c = wh_md5_FF(c, d, a, b, x[ 2], wh_md5_S13, 0x242070db); /* 3 */
	b = wh_md5_FF(b, c, d, a, x[ 3], wh_md5_S14, 0xc1bdceee); /* 4 */
	a = wh_md5_FF(a, b, c, d, x[ 4], wh_md5_S11, 0xf57c0faf); /* 5 */
	d = wh_md5_FF(d, a, b, c, x[ 5], wh_md5_S12, 0x4787c62a); /* 6 */
	c = wh_md5_FF(c, d, a, b, x[ 6], wh_md5_S13, 0xa8304613); /* 7 */
	b = wh_md5_FF(b, c, d, a, x[ 7], wh_md5_S14, 0xfd469501); /* 8 */
	a = wh_md5_FF(a, b, c, d, x[ 8], wh_md5_S11, 0x698098d8); /* 9 */
	d = wh_md5_FF(d, a, b, c, x[ 9], wh_md5_S12, 0x8b44f7af); /* 10 */
	c = wh_md5_FF(c, d, a, b, x[10], wh_md5_S13, 0xffff5bb1); /* 11 */
	b = wh_md5_FF(b, c, d, a, x[11], wh_md5_S14, 0x895cd7be); /* 12 */
	a = wh_md5_FF(a, b, c, d, x[12], wh_md5_S11, 0x6b901122); /* 13 */
	d = wh_md5_FF(d, a, b, c, x[13], wh_md5_S12, 0xfd987193); /* 14 */
	c = wh_md5_FF(c, d, a, b, x[14], wh_md5_S13, 0xa679438e); /* 15 */
	b = wh_md5_FF(b, c, d, a, x[15], wh_md5_S14, 0x49b40821); /* 16 */

	/* Round 2 */
	a = wh_md5_GG(a, b, c, d, x[ 1], wh_md5_S21, 0xf61e2562); /* 17 */
	d = wh_md5_GG(d, a, b, c, x[ 6], wh_md5_S22, 0xc040b340); /* 18 */
	c = wh_md5_GG(c, d, a, b, x[11], wh_md5_S23, 0x265e5a51); /* 19 */
	b = wh_md5_GG(b, c, d, a, x[ 0], wh_md5_S24, 0xe9b6c7aa); /* 20 */
	a = wh_md5_GG(a, b, c, d, x[ 5], wh_md5_S21, 0xd62f105d); /* 21 */
	d = wh_md5_GG(d, a, b, c, x[10], wh_md5_S22,  0x2441453); /* 22 */
	c = wh_md5_GG(c, d, a, b, x[15], wh_md5_S23, 0xd8a1e681); /* 23 */
	b = wh_md5_GG(b, c, d, a, x[ 4], wh_md5_S24, 0xe7d3fbc8); /* 24 */
	a = wh_md5_GG(a, b, c, d, x[ 9], wh_md5_S21, 0x21e1cde6); /* 25 */
	d = wh_md5_GG(d, a, b, c, x[14], wh_md5_S22, 0xc33707d6); /* 26 */
	c = wh_md5_GG(c, d, a, b, x[ 3], wh_md5_S23, 0xf4d50d87); /* 27 */
	b = wh_md5_GG(b, c, d, a, x[ 8], wh_md5_S24, 0x455a14ed); /* 28 */
	a = wh_md5_GG(a, b, c, d, x[13], wh_md5_S21, 0xa9e3e905); /* 29 */
	d = wh_md5_GG(d, a, b, c, x[ 2], wh_md5_S22, 0xfcefa3f8); /* 30 */
	c = wh_md5_GG(c, d, a, b, x[ 7], wh_md5_S23, 0x676f02d9); /* 31 */
	b = wh_md5_GG(b, c, d, a, x[12], wh_md5_S24, 0x8d2a4c8a); /* 32 */

	/* Round 3 */
	a = wh_md5_HH(a, b, c, d, x[ 5], wh_md5_S31, 0xfffa3942); /* 33 */
	d = wh_md5_HH(d, a, b, c, x[ 8], wh_md5_S32, 0x8771f681); /* 34 */
	c = wh_md5_HH(c, d, a, b, x[11], wh_md5_S33, 0x6d9d6122); /* 35 */
	b = wh_md5_HH(b, c, d, a, x[14], wh_md5_S34, 0xfde5380c); /* 36 */
	a = wh_md5_HH(a, b, c, d, x[ 1], wh_md5_S31, 0xa4beea44); /* 37 */
	d = wh_md5_HH(d, a, b, c, x[ 4], wh_md5_S32, 0x4bdecfa9); /* 38 */
	c = wh_md5_HH(c, d, a, b, x[ 7], wh_md5_S33, 0xf6bb4b60); /* 39 */
	b = wh_md5_HH(b, c, d, a, x[10], wh_md5_S34, 0xbebfbc70); /* 40 */
	a = wh_md5_HH(a, b, c, d, x[13], wh_md5_S31, 0x289b7ec6); /* 41 */
	d = wh_md5_HH(d, a, b, c, x[ 0], wh_md5_S32, 0xeaa127fa); /* 42 */
	c = wh_md5_HH(c, d, a, b, x[ 3], wh_md5_S33, 0xd4ef3085); /* 43 */
	b = wh_md5_HH(b, c, d, a, x[ 6], wh_md5_S34,  0x4881d05); /* 44 */
	a = wh_md5_HH(a, b, c, d, x[ 9], wh_md5_S31, 0xd9d4d039); /* 45 */
	d = wh_md5_HH(d, a, b, c, x[12], wh_md5_S32, 0xe6db99e5); /* 46 */
	c = wh_md5_HH(c, d, a, b, x[15], wh_md5_S33, 0x1fa27cf8); /* 47 */
	b = wh_md5_HH(b, c, d, a, x[ 2], wh_md5_S34, 0xc4ac5665); /* 48 */

	/* Round 4 */
	a = wh_md5_II(a, b, c, d, x[ 0], wh_md5_S41, 0xf4292244); /* 49 */
	d = wh_md5_II(d, a, b, c, x[ 7], wh_md5_S42, 0x432aff97); /* 50 */
	c = wh_md5_II(c, d, a, b, x[14], wh_md5_S43, 0xab9423a7); /* 51 */
	b = wh_md5_II(b, c, d, a, x[ 5], wh_md5_S44, 0xfc93a039); /* 52 */
	a = wh_md5_II(a, b, c, d, x[12], wh_md5_S41, 0x655b59c3); /* 53 */
	d = wh_md5_II(d, a, b, c, x[ 3], wh_md5_S42, 0x8f0ccc92); /* 54 */
	c = wh_md5_II(c, d, a, b, x[10], wh_md5_S43, 0xffeff47d); /* 55 */
	b = wh_md5_II(b, c, d, a, x[ 1], wh_md5_S44, 0x85845dd1); /* 56 */
	a = wh_md5_II(a, b, c, d, x[ 8], wh_md5_S41, 0x6fa87e4f); /* 57 */
	d = wh_md5_II(d, a, b, c, x[15], wh_md5_S42, 0xfe2ce6e0); /* 58 */
	c = wh_md5_II(c, d, a, b, x[ 6], wh_md5_S43, 0xa3014314); /* 59 */
	b = wh_md5_II(b, c, d, a, x[13], wh_md5_S44, 0x4e0811a1); /* 60 */
	a = wh_md5_II(a, b, c, d, x[ 4], wh_md5_S41, 0xf7537e82); /* 61 */
	d = wh_md5_II(d, a, b, c, x[11], wh_md5_S42, 0xbd3af235); /* 62 */
	c = wh_md5_II(c, d, a, b, x[ 2], wh_md5_S43, 0x2ad7d2bb); /* 63 */
	b = wh_md5_II(b, c, d, a, x[ 9], wh_md5_S44, 0xeb86d391); /* 64 */

	wh_md5_state[0] += a;
	wh_md5_state[1] += b;
	wh_md5_state[2] += c;
	wh_md5_state[3] += d;
}

function wh_md5_init() {
	wh_md5_count[0] = 0;
	wh_md5_count[1] = 0;
	wh_md5_state[0] = 0x67452301;
	wh_md5_state[1] = 0xefcdab89;
	wh_md5_state[2] = 0x98badcfe;
	wh_md5_state[3] = 0x10325476;
	for (i = 0; i < wh_md5_digestBits.length; i++) {
		wh_md5_digestBits[i] = 0;
	}
}

function wh_md5_update(b) {
	var index, i;

	index = wh_and(wh_shr(wh_md5_count[0],3) , 0x3f);
	if(wh_md5_count[0]<0xffffffff-7) {
		wh_md5_count[0] += 8;
	} else {
		wh_md5_count[1]++;
		wh_md5_count[0] -= 0xffffffff + 1;
		wh_md5_count[0] += 8;
	}
	wh_md5_buffer[index] = wh_and(b, 0xff);
	if(index >= 63) {
		wh_md5_transform(wh_md5_buffer, 0);
	}
}

function wh_md5_finish() {
	var bits = new wh_array(8);
	var	padding;
	var	i = 0, index = 0, padLen = 0;

	for (i = 0; i < 4; i++) {
		bits[i] = wh_and(wh_shr(wh_md5_count[0],(i * 8)), 0xff);
	}
	for (i = 0; i < 4; i++) {
		bits[i+4]=wh_and(wh_shr(wh_md5_count[1],(i * 8)), 0xff);
	}
	index = wh_and(wh_shr(wh_md5_count[0], 3) ,0x3f);
	padLen = (index < 56 ? 56 - index : 120 - index);
	padding = new wh_array(64);
	padding[0] = 0x80;
	for (i = 0; i < padLen; i++) {
	  wh_md5_update(padding[i]);
	}
	for (i = 0; i < 8; i++) {
	  wh_md5_update(bits[i]);
 	}

	for(i = 0; i < 4; i++) {
		for(j = 0; j < 4; j++) {
			wh_md5_digestBits[i * 4 + j] = wh_and(wh_shr(wh_md5_state[i], j * 8) , 0xff);
		}
	}
}

function wh_md5_hexa(n) {
	var hexa_h = '0123456789abcdef';
	var hexa_c = '';
	var hexa_m = n;
	for(hexa_i = 0; hexa_i < 8; hexa_i++) {
		hexa_c = hexa_h.charAt(Math.abs(hexa_m) % 16) + hexa_c;
		hexa_m = Math.floor(hexa_m/16);
	}
	return hexa_c;
}

function wh_MD5(entree) {
	var l, s, k, ka, kb, kc, kd;

	wh_md5_init();
	for(k = 0; k < entree.length; k++) {
		l = entree.charAt(k);
		wh_md5_update(wh_md5_ascii.lastIndexOf(l));
	}
	wh_md5_finish();
	ka = kb = kc = kd = 0;
	for(i = 0; i < 4; i++) {
		ka += wh_shl(wh_md5_digestBits[15-i], (i*8));
	}
	for(i = 4; i < 8; i++) {
		kb += wh_shl(wh_md5_digestBits[15-i], ((i-4)*8));
	}
	for(i = 8; i < 12; i++) {
		kc += wh_shl(wh_md5_digestBits[15-i], ((i-8)*8));
	}
	for(i = 12; i < 16; i++) {
		kd += wh_shl(wh_md5_digestBits[15-i], ((i-12)*8));
	}
	s = wh_md5_hexa(kd) + wh_md5_hexa(kc) + wh_md5_hexa(kb) + wh_md5_hexa(ka);
	return s;
}

// backwards compatibility
function whe_MD5(entree) {
	return wh_MD5(entree);
}
