var dispatcherurl = 'server/dispatcher.php';
var ajax;


function run(){
	ajax = new GLM.AJAX();
//	showSubpage(showonload);
//	if (subpages.length > 1){
//		show('subpagetabbar');
//	}
}

/*
function showSubpage(id){
	for(var i = 0; i < subpages.length; i++){
		hide(subpages[i]);
		removeClass(subpages[i]+"_tab", 'active');
	}
	show(id);
	
	addClass(id+"_tab", 'active');
}

function replace(from, to, text){
	var e_v = new RegExp(from, 'g');
	return text.replace(e_v, to);
}

function addClass(elementid, classname){
	var obj = document.getElementById(elementid);
	if (obj) obj.className += ' '+classname;
}
	
function removeClass(elementid, classname){
	var obj = document.getElementById(elementid);
	if (obj) obj.className = replace(classname, '', obj.className);
}

function show(id){
	var theElement = document.getElementById(id);
	if (theElement) theElement.style.display = "block";
}

function hide(id){
	var theElement = document.getElementById(id);
	if (theElement) theElement.style.display = "none";	
}
*/

/*
function sendSollicitatie(){
	var fn = 'sendSollicitatie';
	var params = 'fn='+fn;
	
  var els = getFormElements('sollicitatieform');
	for(var i = 0; i < els.length; i++){
		params = params + '&' + els[i].name + '=' + encode(els[i].value);
	}
	
	callPhpFunction(dispatcherurl, params, fn);
}
*/

function sendContact(){
	var fn = 'sendContact';
	var params = 'fn='+fn;
	
  var els = getFormElements('contactform');
	for(var i = 0; i < els.length; i++){
		params = params + '&' + els[i].name + '=' + encode(els[i].value);
	}
	
	callPhpFunction(dispatcherurl, params, fn);
}

function sendReservering(){
	var fn = 'sendReservering';
	var params = 'fn='+fn;
	
  var els = getFormElements('reserveringsform');
	for(var i = 0; i < els.length; i++){
		params = params + '&' + els[i].name + '=' + encode(els[i].value);
	}
	
	callPhpFunction(dispatcherurl, params, fn);	
}

/*
function stateChanged_sendSollicitatie(response){
	eval(response);
	document.forms['sollicitatieform'].reset();
}
*/

function stateChanged_sendContact(response){
	eval(response);
	document.forms['contactform'].reset();
}

function stateChanged_sendReservering(response){
	eval(response);
	document.forms['reserveringsform'].reset();
}

function getFormElements(formid){
	var els = document.forms[formid].elements;
	return els;
}

function decode(encoded) {
	encoded = String(encoded);
	return unescape(encoded.replace(/\+/g,  " "));
}

function encode(unencoded) {
	return escape(unencoded); 
}

function trim(value) {
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  value = value.replace(/^\0+/,''); 
  value = value.replace(/\0+$/,'');
  return value;
}

function in_array(el, ar){
	for(i = 0; i < ar.length; i++){
		if (el == ar[i]) return true;
	}
	return false;
}
