var oPrcForm = null;
var sCurAction = null;
var nSf = 0;
var sStr="";
var enableSbox = true;

function getData(sDiv, sAction,sExtra) {

  var url = sJsR+'processor.php'; 
  var pars = 'action='+sAction;
  if (sExtra.length != 0){
	 pars += '&'+sExtra;
  }
  if (sExtra.length != 0){
	 pars += '&lc='+lc;
  }
  new Ajax.Updater( {success: sDiv}, url, {method: 'post', parameters: pars,  onFailure: reportError, onCreate: startProcess, onComplete: endProcess, evalScripts: true}); 
  return;
}

function getData2(sDiv, sAction,sExtra) {

  var url = sJsR+'processor.php'; 
  var pars = 'action='+sAction;
  if (sExtra.length != 0){
	 pars += '&'+sExtra;
  }
  new Ajax.Updater( {success: sDiv}, url, {method: 'post', parameters: pars,  onFailure: reportError, evalScripts: true}); 
  return;
}

function getData3(sAction,sExtra) {

  var url = sJsR+'processor.php'; 
  var pars = 'action='+sAction;
  if (sExtra.length != 0){
	 pars += '&'+sExtra;
  }
  new Ajax.Request( url, {methode:'post', parameters: pars ,onCreate: startProcess, onFailure: reportError, onComplete: endProcess}); 
  return;
}

function getForm(sDiv, sForm,sExtra) {

  var url = sJsR+'processor.php'; 
  var pars = 'getform='+sForm;
  if (sExtra.length != 0){
	 pars += '&'+sExtra;
  }
  new Ajax.Updater( {success: sDiv}, url, {method: 'post', parameters: pars,  onFailure: reportError, onCreate: startProcess, onComplete: endProcess, evalScripts: true}); 
  return;
}

function process(oForm) {
     
  oPrcForm = oForm
  document.body.style.cursor = "wait";
  sStr = Form.serialize(oForm);
  Form.disable(oForm);
  new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcessForm, onFailure: reportError, onComplete: endProcessForm, evalScripts: true});  
  return false;
}

function getZoekboxDays(oObj, sForm, sSource) {
     
  oForm = $(sForm);
  oPrcForm = oForm;
  sCurAction = oForm.action.value;
  oForm.action.value="zbDays";  
  document.body.style.cursor = "wait";
  sStr = Form.serialize(oForm);
  sStr += '&src='+sSource;
  oForm.action.value=sCurAction;
  Form.disable(oForm);
  new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcessForm, onFailure: reportError, onComplete: endZoekboxDays, evalScripts: true});  
  return false;
}

function endZoekboxDays(originalRequest) {
  //alert(originalRequest.responseText);
  document.body.style.cursor = "default";
  Form.enable(oPrcForm);
  oObj = $('fldsDag');
  getZoekboxTotal(oObj, oPrcForm.id);
  return;
}

function getZoekboxDaysSpecial(oObj, sForm, sSource) {
     
  oForm = $(sForm);
  oPrcForm = oForm;
  sCurAction = oForm.action.value;
  oForm.action.value="zbDaysSpecial";
  document.body.style.cursor = "wait";
  sStr = Form.serialize(oForm);
  sStr += '&src='+sSource;
  oForm.action.value=sCurAction;
  Form.disable(oForm);
  new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcessForm, onFailure: reportError, onComplete: endZoekboxDaysSpecial, evalScripts: true});  
  return false;
}

function endZoekboxDaysSpecial(originalRequest) {
  document.body.style.cursor = "default";
  Form.enable(oPrcForm);
  oObj = $('fldsDag');
  //getZoekboxTotal(oObj, oPrcForm.id);
  return;
}


function getZoekboxTotal(oObj, sForm) {
  if (oObj.id == "fldsDag") {
	  oObj2 = $('fldsMaand');
	  d=oObj.options[oObj.selectedIndex].value;
	  if (d < 10) d="0"+d;
	  md=oObj2.options[oObj2.selectedIndex].value;
	  $('seldate').value = d+"/"+md;
  }
  oForm = $(sForm);
  oPrcForm = oForm;
  oForm.selfield.value=oObj.id;
  sCurAction = oForm.action.value;
  switch (oForm.zoekbox.value) {
     case 'zoekbox':
		oForm.action.value="zbTotal";
	    break;
     case 'zoekbox2':
		 if (oForm.psrc.value != 'bungalowparken'){
		    oForm.action.value="zbTotal";
		 } else {
		    oForm.action.value="showParkenDirect";
		 }
	    break;
     case 'zoekbox3':
		oForm.action.value="showAanbiedingenDirect";
	    break;
     case 'zoekboxspecial':
		oForm.action.value="showParkenSpecial";
	    break;
  }
  document.body.style.cursor = "wait";
  sStr = Form.serialize(oForm);
  oForm.action.value=sCurAction;
  Form.disable(oForm);
  if (oForm.zoekbox.value == "zoekbox" || oForm.zoekbox.value == "zoekbox2" || oForm.zoekbox.value == "zoekboxspecial") {
	 enableSbox = true;
	 new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcessForm, onFailure: reportError, onComplete: endProcessForm, evalScripts: true});  
  } else {
	sStr += "&lst="+curList;
	nPage = 0;
	oListarea = $('listarea');
	oListarea.innerHTML='<IMG height=320 src="images/ontwerp/loading.gif" width=320 border=0>';
	enableForm = true;
	enableSbox = false;
	new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcessForm, onFailure: reportError, onComplete: endProcessForm, evalScripts: true});
  }
  
  return false;   
}


function setSort(sField, sOrder, nPage) {
	  sStr = "action=setSort&sField="+sField+"&sOrder="+sOrder+"&nPage="+nPage;
	  new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcess, onFailure: reportError, onComplete: endProcess});  
  return false;
}

function showList(nPakket) {
	  sStr = "action=showList&pakket="+nPakket;
	  new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcess, onFailure: reportError, onComplete: endProcess});  
  return false;
}


function showProv(nProv, sPage) {
	  sStr = "action=showProv&prov="+nProv+"&page="+sPage;
	  new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcess, onFailure: reportError, onComplete: endProcess});  
  return false;
}

function showLocations() {
	nSf = 1;	
	if (sStr == "") {	   
	   oForm = $('formSearch');
       oForm.action.value="showLocations";
	   sStr = Form.serialize(oForm);
	} else {
	   sStr = sStr.replace(/getListValues/i, "showLocations");
	}
    sStr += "&initLoad="+initload;
	new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcess, onFailure: reportError, onComplete: endProcess});  
  return false;
}

function showTot(region) {
	if (region == 0) {
		 $('oTotAcco').innerHTML = '&nbsp';
  } else { 
	   getData2('oTotAcco', 'totacco','region='+region);	   
	}
	return;
}

function gotoPage(sForm) {
	
  oForm = $(sForm);
  oPrcForm = oForm
  oForm.action.value="gotoPage";
  sStr = Form.serialize(oForm);
  new Ajax.Request(sJsR+'processor.php', {methode:'post', parameters: sStr ,onCreate: startProcess, onFailure: reportError, onComplete: endProcess});  
  return false;	
  
}


function reportError(request) {
  //alert('fout ' + request);
  return;
}

function startProcess() {

  return;
}

function endProcess(originalRequest) {

	//alert(originalRequest.responseText);
	document.body.style.cursor = "default";

  return;
}


function completed() {
  return;
}

function loader() {
  return;
}

function startProcessForm(originalRequest) {
  return;
}

function endProcessForm(originalRequest) {
  //alert(originalRequest.responseText);
  if (enableSbox){
	  document.body.style.cursor = "default";
	  Form.enable(oPrcForm);
  }
  return;
}

function hideSelects() {
	
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		//selects[i].style.visibility = "hidden";
		selects[i].hide();
	}	
	return;
}

function showSelects() {
 
  var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		//selects[i].style.visibility = "visible";
		selects[i].show();
	}	
	return;
}


function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
   removeEvents();
}


function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function removeEvents() {
	var style = getActiveStyleSheet();
	var date = new Date();
	setCookie("BTfontsize", style, 1);
}

function onLoadInit() {
	var cookie = getCookie('BTfontsize');
	var title = cookie ? cookie : 'basis_standaard';
	if (title == null || title == "null") title = 'basis_standaard';
	setActiveStyleSheet(title);

}

function setCookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=/" + path : ";path=/" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

//Event.observe(window, 'load', function () {onLoadInit();}, false);
//Event.observe(window, 'unload', function () {removeEvents();}, false);
