// this script is made with AJAX: Asynchronous JavaScript and XML
//
//	Author: Nico Lubbers		
//   www.booleanpark.com
//
var currentCalItem;

var isLoadingHtml = false;
var isIE = false;
var requestxml;
var dddag=[];
var clickedDiv;
var clickedDivActieID;
var bookButtonActive = false;
var newSelKol='';
var dateYYYYMM='';
//var dateDD='';
var globalDivId;
var globalDocType;
var loadCalendarOnly = false;
var dateBoundaryBegin='';
var dateBoundaryEnd='';
var nextMonth=null;
var prevMonth=null;
var dropdownXml;
var theAcc;
function strltrim() {return this.replace(/^\s+/,'');}
function strrtrim() {return this.replace(/\s+$/,'');}
function strtrim() {return this.replace(/^\s+/,'').replace(/\s+$/,'');}
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

var getXmlCached = "getXmlCached.aspx"
var getXml = "getXml.aspx"
if(typeof useCabsJS == 'undefined')
{
    alert("useCabsJS is undefined");
}
else if(useCabsJS)
{
    getXmlCached = "getXmlCabsCached.aspx"
    getXml = "getXmlCabs.aspx"
    if(typeof useCabsProxyJS == 'undefined')
    {
        alert("useCabsProxyJS is undefined");
    }
    else if (useCabsProxyJS)
    {
        getXmlCached = "getXmlCabsCachedProxy.aspx"
        getXml = "getXmlCabsProxy.aspx"
    }
}

function loadHtmlSnippet(url,divID,docType) {
	globalDivId = divID;
	globalDocType = docType;
	if (isLoadingHtml) { 
  		requestxml.abort();
	}
	isLoadingHtml = true;
	// disable dropdowns while loading
	if(docType=='cal')	{
		if (spsThema=='campings') document.getElementById('ddStayType').disabled = true;
        document.getElementById('ddDuur').disabled = true;
		document.getElementById('ddAankomst').disabled = true;
		document.getElementById('ddAankomst_dag').disabled = true;
		//if (spsThema!='campings' && document.getElementById('ddAccommodatie')!=null) document.getElementById('ddAccommodatie').disabled = true;
	}
	if (window.XMLHttpRequest) { 	// no IE
        requestxml = new XMLHttpRequest();
        requestxml.onreadystatechange = checkStatus;
        requestxml.open("GET", url, true);
        requestxml.send(null);
    } else if (window.ActiveXObject) { // IE
        isIE = true;
        requestxml = new ActiveXObject("Microsoft.XMLHTTP");
        if (requestxml) {
            requestxml.onreadystatechange = checkStatus;
            requestxml.open("GET", url, true);
            requestxml.send(); 
        }
    }
}
function reloadHtmlSnippet(CalendarOnly) {
	lml("clear");
	curSelectedDivID ='';
	dateBoundaryBegin='';
	dateBoundaryEnd='';
	prevMonth=null;
	nextMonth=null;
	loadCalendarOnly = CalendarOnly;
	unselectCol();
	curSelectedColumnNr=0;
	hideKlikPanel();
	spsStayType = getSelectedValue(document.getElementById('ddStayType'));	
    if (spsThema!='campings')
    {
        spsDuur = getSelectedValue(document.getElementById('ddDuur'));
        setCookie('sel_stay', spsDuur);
    }else{
        if (spsStayType == 'M')
        {
            if (IsNumeric(getSelectedValue(document.getElementById('ddDuur'))))
            {
                spsDuur = 'WK';
            }else{
                spsDuur = getSelectedValue(document.getElementById('ddDuur'));
            }
            setCookie('sel_stay', spsDuur);
        }else{
            if (IsNumeric(getSelectedValue(document.getElementById('ddDuur'))))
            {
                spsNights = getSelectedValue(document.getElementById('ddDuur'));
            }else{
    			// number of nights default setting, requested by John Huizer (20090716)
                spsNights = 7;
            }
            setCookie('sel_nights', spsNights);
        }
    }
	//spsAantalpersonen = getSelectedValue(document.getElementById('ddAccommodatie'));	
	setCookie('sel_parkcode',spsParkcode);
	//if (spsThema=='campings') setCookie('sel_staytype',spsStayType);
	//if (spsThema!='campings') setCookie('sel_num',spsAantalpersonen);
	setCookie('sel_date',spsAankomstYYYYMMDD);
    
    if (spsThema=='campings') setCookie('sel_staytype',spsStayType);
	
	var thisUrl = snippetpath;
	if (spsThema=='campings')
		thisUrl = thisUrl + getXmlCached + '?datasoort=panelprice&thema='+spsThema+'&taalcode='+spsTaalcode+'&parkcode=' + spsParkcode + '&aankomstdatum=' + spsAankomstYYYYMMDD;
	else
		thisUrl = thisUrl + getXmlCached + '?datasoort=panelprice&thema='+spsThema+'&taalcode='+spsTaalcode+'&parkcode=' + spsParkcode + '&aankomstdatum=' + spsAankomstYYYYMMDD + '&aantalpersonen=' + spsAantalpersonen;
    if (spsStayType == 'M' || spsThema!='campings')
    {
        thisUrl = thisUrl + '&duur=' + spsDuur;
    }else{
        thisUrl = thisUrl + '&duur=' + spsNights;
    }
	if (spsToCode!='')
		thisUrl = thisUrl + '&to_filter=' + spsToCode + '&to_yieldgroep=' + spsToYieldgroep;
	if (spsThema=='campings')
		thisUrl = thisUrl + '&staytype=' + spsStayType;
	if (loadCalendarOnly)
		thisUrl += '&calendaronly=true';
	loadHtmlSnippet(thisUrl,'htmlContainer','cal');
}
function getSelectedValue(optionPtr) {
	if (optionPtr == null)
		return('');
	return optionPtr.options[optionPtr.selectedIndex].value;
}
function checkStatus() {
	try
	{
		if (requestxml.readyState == 4) {
			//testing local
			if (requestxml.status == 0) { 
				placeSnippet(); 
			} else if (requestxml.status == 200) {
    			placeSnippet();
			} else {
					isLoadingHtml = false;
				alert("Fout bij ophalen XML data:\n(" + requestxml.status + ") " + requestxml.statusText);
			}
		}
		resetGrid();
		setupGrid();
	}
	catch(e) {
		
	}
}
function placeSnippet() {
    
	if (!isLoadingHtml)	return; 
	if(globalDocType=='cal')
	{
		var responsexml = requestxml.responseXML.documentElement;
		if (responsexml==null) {/*alert('0');*/return;}
		if (responsexml.getElementsByTagName('calendar').length==0) {/*alert('1');*/return;}
		var el = responsexml.getElementsByTagName('boundary');
		if (el!=null)
			if (el.length==1) {
				dateBoundaryBegin=el[0].getAttribute('first');
				dateBoundaryEnd=el[0].getAttribute('last');
		}			
		// place HTML in divs
		var calHTML = responsexml.getElementsByTagName('calendar')[0].firstChild.data;
		document.getElementById(globalDivId).innerHTML = calHTML;

		// populate all dropdowns
		if (!loadCalendarOnly) {
			dropdownXml = requestxml.responseXML;//.getElementsByTagName('ym');
			dddag=[];
			if (spsThema=='campings') populateSelectFromXml(document.getElementById('ddStayType'),'staytype');
			populateSelectFromXml(document.getElementById('ddDuur'),'stay');
			populateSelectFromXml(document.getElementById('ddAankomst'),'ym');
			populateSelectFromXml(document.getElementById('ddAankomst_dag'),'dd');
			//if (spsThema!='campings') populateSelectFromXml(document.getElementById('ddAccommodatie'),'num');
		}
		else {
			// populate day dropdown only
			populateSelectFromXml(document.getElementById('ddAankomst_dag'),'dd',spsAankomstYYYYMMDD);
		}
		
		// enable dropdowns after loading
		document.getElementById('ddDuur').disabled = false;
		if (spsThema=='campings') document.getElementById('ddStayType').disabled = false;
		document.getElementById('ddAankomst').disabled = false;
		document.getElementById('ddAankomst_dag').disabled = false;
		//if (spsThema!='campings') document.getElementById('ddAccommodatie').disabled = false;
		//maak object met functies voor table en btns
		AccoList.lists["accolist"] = new AccoList("accolist", 0);

		if (curSelectedDivID != '' && document.getElementById(curSelectedDivID) != null) {
			var tmpdiv = curSelectedDivID;
			var tmpSimulateClick = document.getElementById(curSelectedDivID);
			if (tmpSimulateClick != null)
			    tmpSimulateClick.onclick();
			    //alert('cur' + curSelectedColumnId);
			scrollToColumn(curSelectedColumnId);
			cdiv(document.getElementById(tmpdiv), spsActieID, true, spsBeschikbaarheidID);
		}
		else {
		    //alert('placeSnippet() new' + newSelKol);
			scrollToColumn(newSelKol);
			// nieuwe kol-id bepalen
		}
		
        if($('acc'+currentCalItem))
            $('acc'+currentCalItem).addClassName("current");
	
	}
	else
	{   
		var responsexml = requestxml.responseXML.documentElement;
		var descHTML = responsexml.getElementsByTagName('description')[0].firstChild.data;
		// place HTML in div
		
		document.getElementById(globalDivId).innerHTML = descHTML;
		
		//set shadowheight
		var thePanel = document.getElementById('klikContainer');
		var theSchaduw = document.getElementById('klikContainerSchaduw');
		
		/* Issue in camping-site (in IE6). Panel didn't show up, so build this work around: */
		if(thePanel.offsetHeight<1)
		       document.getElementById('klikContainer').style.height = "130px"; 
		/* -- */
		theSchaduw.style.height = (thePanel.offsetHeight-2)+"px";
        
	}
	isLoadingHtml = false;
}
function populateSelectFromXml(fieldptr,tagname, SelectedDate) {
	var urlString = location.href;
	var selectedID='', disableOption = false;

	// check if <select> object exists. 
	// delete values in it to repopulate again
	if (fieldptr != null) {
		if (fieldptr.selectedIndex != null) {
			if (fieldptr.selectedIndex != -1) {
				if (fieldptr.options.length >= 0) {
			 		// delete all options
					fieldptr.options.length = 0;
			 	}
		 	}
		}
	}

	// populate option-list with the XML-tag values
	var collection;
	if (tagname=='dd')
		collection= dddag[spsSelectMonthIdx];
	else
		collection= requestxml.responseXML.getElementsByTagName(tagname);
	dropdowncnt = 0;

	if (collection == null)
		return;
		
	// checks if collection contains NO items
	if (collection.length == 0) {
		//  display message and disable option-box
		fieldptr.options[dropdowncnt++] = new Option("  ","");
		disableOption = true;
		//if (tagname=='ym')
		//	collection= dddag[0]={};
	}
	else { 
		var wasSelected=false;
		for(cnt=0; cnt < collection.length; cnt++) 
		{
			var thisID = collection[cnt].getAttribute('id');
			
			fieldptr.options[dropdowncnt] = new Option(collection[cnt].getAttribute('val'),thisID);
			if (tagname=='ym')
				dddag.push(collection[cnt].childNodes); // get dd tags (childnodes)

			// kijk in de xml-tags welke optie geselecteerd moet worden 
			//  (doe dit alleen direct na load van XML)
			if (SelectedDate!=null && tagname=='dd') {
				if (SelectedDate==thisID.substring(2,10)) {
					spsAankomstYYYYMMDD = thisID.substring(2,10);
					newSelKol = thisID;
					wasSelected = true;
				}
			}
			else if (collection[cnt].getAttribute('selected') != null && isLoadingHtml) {
				if(tagname == 'staytype' && thisID != '')
				{
					getTranslation('priceinfo_expand','campings','prijsfooter_'+thisID,spsTaalcode);
				}

				fieldptr.selectedIndex = dropdowncnt;  // select that option again
				wasSelected = true;
				if (tagname=='ym') {
					dateYYYYMM = thisID.substring(0,6);
					spsSelectMonthIdx = cnt;
				}
				if (tagname=='dd') {
					spsAankomstYYYYMMDD = thisID.substring(2,10);
					newSelKol = thisID;
				}
 			}
 			// indien we de dropdowns populaten (ym+dd) vanwege een klik in de prijstabel
 			if (!isLoadingHtml) {
				if (tagname=='dd') {
					if (curSelectedColumnId == thisID) {
						wasSelected = true;
						fieldptr.selectedIndex = dropdowncnt;
					}
				}
			}

			dropdowncnt++;
	   }
	   if (!wasSelected) {
	   	fieldptr.selectedIndex = 0;
	   }
	}
	fieldptr.disabled = disableOption;
}
function unselectCol(){
	//unselects hele kolom én div via parentNode (item)
	clickedDiv=null;
	setCookie('sel_div', '-')
	setCookie('sel_divactie','-');
	//alert('unselectCol:'+curSelectedColumnId);

	var divParent = document.getElementById(curSelectedColumnId);
	if (divParent != null){
		var selColArr = divParent.getElementsByTagName('div');
		selColArr[0].className = 'date';
		selColArr[1].className = 'duur';
		for(i=2; i<selColArr.length; i++){
			if (selColArr[i].innerHTML == '-')
				selColArr[i].className = 'duur';
			else
			{
				var surfix = "";
				if (selColArr[i].className.indexOf('Red') > -1)
					surfix = "Red";
				if (selColArr[i].className.indexOf('EarlyBooking') > -1)
					surfix = "EarlyBooking";
				
				selColArr[i].className = 'price1' + surfix;
			}
		}
	}
	//--maak boek btn grijs
	disableBoekenBtn();
	//document.getElementById('boekBtn').className = 'submitgrijs';	
	bookButtonActive = false;
}
function selectCol(divParent){
	
	if(divParent==null)
		return;
	var selColArr = divParent.getElementsByTagName('div');
	selColArr[0].className = 'selectCol';
	selColArr[1].className = 'selectColDuur';
	for(i=2; i<selColArr.length; i++){
		if (selColArr[i].innerHTML == '-')
			selColArr[i].className = 'duur';
		else
		{
			var surfix = "";
			if (selColArr[i].className.indexOf('Red') > -1)
				surfix = "Red";
			if (selColArr[i].className.indexOf('EarlyBooking') > -1)
				surfix = "EarlyBooking";
				
			selColArr[i].className = 'price2' + surfix;
		}
	}
}
function selectDiv(seldivid) {
    
	var selDiv = document.getElementById(seldivid);
	if (selDiv != null)	{
		var thedivCol = selDiv.parentNode;
		selectCol(thedivCol);			// zet hele kolom op class price2
		
		var surfix = "";
	
		if (selDiv.className.indexOf('Red') > -1)
		{	surfix = "Red";
			document.getElementById('lastminuteLegenda').className += " selected";
		}
		if (selDiv.className.indexOf('EarlyBooking') > -1)
		{	surfix = "EarlyBooking";
			document.getElementById('lastminuteLegenda').className += " selectedEarlyBooking";
		}
		
		selDiv.className = 'price3' + surfix;
		curSelectedDivID = seldivid; 	// curSelectedDivID = global var

		var aParent = document.getElementById('typetxt');
		var aArr = aParent.getElementsByTagName('a'); // collection met ahrefjes (hierin zit de beschrijving)
		var divArr = thedivCol.getElementsByTagName('div'); // collection met klikbare divjes (de eerste 2 moeten genegeerd worden... dat is de header)
		var divSelIdx = 0;
		if (divArr.length>2) // 2 divs voor datum en aantal_nachten negeren
 			for (i=2; i<divArr.length; i++){
				if (divArr[i].id == seldivid)
					divSelIdx = i;
		}
		if (divSelIdx>=2) // result found
			spsAccommodatieNaam=aArr[divSelIdx-2].getAttribute("res"); // index minus 2 

	}
}


function selectRow(acc) {
	if(document.getElementById('acc'+acc)!=null)
	{	clearSelection('selectRow');
		document.getElementById('acc'+acc).className += " selectRow";
	}

}

function curddVal(ddName){
	var theDD = document.getElementById(ddName);
	if (ddName != theDD){
		var idx = theDD.selectedIndex;
		var ddVal = theDD.options[idx].value;
		return (ddVal);
	}
	return;
}
function fetchShowHide(isNext) {
	// collection van dd tags
	var ddcol = dropdownXml.getElementsByTagName('dd');
	// doorloop deze
	for (var t=0;t<ddcol.length;t++)
		if(isNext) {
			// als overeenkomstige gevonden
			if (ddcol[t].getAttribute('id')==dateBoundaryEnd)
				// check de parent (ym) en kijk of er een volgende is.
				if (ddcol[t].parentNode.nextSibling == null) {
					// er is geen volgende maand
					document.getElementById("next").style.visibility = 'hidden';
					break;
				}
				else
					// pak het id yyyymmdd van de volgende maand
					nextMonth=ddcol[t].parentNode.nextSibling.getAttribute('id');
		}
		else {
			// als overeenkomstige gevonden
			if (ddcol[t].getAttribute('id')==dateBoundaryBegin) {
				if (ddcol[t].parentNode.previousSibling == null || 
					 ddcol[t].parentNode.previousSibling.nodeName!='ym') {
					// check of er nog een vorige maand is 
					document.getElementById("prev").style.visibility = 'hidden';
					break;
				}
				else
					prevMonth=ddcol[t].parentNode.previousSibling.getAttribute('id');
			}
		}
}
function xmlfetch(isNext) {
	if(isNext) 
		if (nextMonth==null)
			return;
		else
			spsAankomstYYYYMMDD = nextMonth;
	else 
		if (prevMonth==null)
			return;
		else
			spsAankomstYYYYMMDD = prevMonth;
	if (spsAankomstYYYYMMDD==null)
		return;
	else
		changeMonthDropdown(spsAankomstYYYYMMDD.substring(0,6), true);
}
function ddMonthIsChanged(theSelect, mustReload)
{	lml("clear");
	curSelectedDivID ='';
	spsAankomstYYYYMMDD = getSelectedValue(theSelect);
	if (mustReload) {
		unselectCol();
		hideKlikPanel();
		// month is changed -> reload XML
		spsSelectMonthIdx = theSelect.selectedIndex;
		reloadHtmlSnippet(true);
	}
	else {
		unselectCol();
		hideKlikPanel();
		// month is changed -> populate ddAankomst_dag
		spsSelectMonthIdx = theSelect.selectedIndex;
		populateSelectFromXml(document.getElementById('ddAankomst_dag'),'dd', spsAankomstYYYYMMDD);
		var curKol = curddVal('ddAankomst_dag');
		if (curKol!='') {
			scrollToColumn(curKol);
			spsAankomstYYYYMMDD = curKol.substring(2,10);
		}
	}
}
function ddDayIsChanged(theSelect)
{	
	lml("clear");
	unselectCol();
	clearSelection('selectRow');
	hideKlikPanel();
	spsSelectDayIdx = theSelect.selectedIndex;
	var curKol = curddVal('ddAankomst_dag');
	scrollToColumn(curKol);
	spsAankomstYYYYMMDD = curKol.substring(2,10);

	//alert(spsSelectDayIdx);
	//alert(spsAankomstYYYYMMDD);

	setCookie('sel_date',spsAankomstYYYYMMDD);
	
	// test dirk reloadHtmlSnippet(true);
}
//--- on click (kalender)
function cdiv(thediv, theActieID, byParameter, bId){
	
	lmLeg = document.getElementById('lastminuteLegenda');
    lmLeg.className = lmLeg.className.replace(" selectedEarlyBooking", "");
	lmLeg.className = lmLeg.className.replace(" selected", "");
		
	unselectCol();
	
	var divarray = thediv.id.split("_");
	// prijs geklikt, ga verder het boekproces in
	var kolid = thediv.parentNode.id;
	if (kolid!=null)
		if (kolid.length > 3){
			curSelectedColumnId = kolid;
			spsAankomstYYYYMMDD = divarray[0];
			setCookie('sel_date',spsAankomstYYYYMMDD);
			spsAantalNachten=divarray[1];
			spsAccommodatieCode=divarray[2];
			spsActieID=theActieID;
			spsBeschikbaarheidID=bId;
			if (spsThema!='campings') {spsAantalpersonen=$("acc" + spsAccommodatieCode).readAttribute("nop");}
			if(byParameter!=true)
				changeMonthDropdown(thediv.id.substring(0,6),false);
			selectDiv(thediv.id); 	//hier: kol selected, wel price3
			selectRow(divarray[2]);
		//--maak boek btn oranje
		enableBoekenBtn();
		//document.getElementById('boekBtn').className = 'submitoranje';
		bookButtonActive = true;
	}
	clickedDiv = thediv;
	clickedDivActieID = theActieID;
	if (clickedDiv != null) {
		setCookie('sel_div', clickedDiv.id)
		setCookie('sel_divactie',clickedDivActieID);
	}

}
function changeMonthDropdown(theYYYYMM, mustReload){
	var theddAankomst = document.getElementById('ddAankomst');
	for (t=0;t<theddAankomst.options.length;t++) {
		if(theddAankomst.options[t].value.substring(0,6)==theYYYYMM) {
			theddAankomst.selectedIndex = t;
			ddMonthIsChanged(theddAankomst, mustReload);
			break;
		} 
	}
}

function scrollToColumn(kolid){
	//alert('scrollToColumn : '+kolid);
	//zet selected kolom bij klik en form-change
	//selectCol( document.getElementById(kolid) );
	if (kolid!=null){
		if (kolid.length > 10){
			// zoek het id van de TD op waarbinnen de gevonden DIV geplaatst is en scrollIntoView
			var kolref = document.getElementById(kolid);
			if (kolref==null)
				return;
			var tdid = kolref.parentNode.id;
			var newkolnum = parseInt(tdid.substring(2),10);
			var dist = Math.abs(curSelectedColumnNr - newkolnum);
			var speed=13;
			if(dist > 2) speed=26;
			curSelectedDivID=''; 
			curSelectedColumnNr = newkolnum;
			curSelectedColumnId = kolid;
			myahref = document.getElementById('next');
			mypanel = myahref.panel;
			if (newkolnum ==0) newkolnum = 1;
			mypanel.scrollIntoView(-52*(newkolnum - 1), speed); // 52=breedte vd kolommen
		}
	}
}
//---- end scroll kalender script ----//


function getFlashMovieObject(movieName)
{
	if (window.document[movieName]) 
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName]; 
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	}
}			

function enableBoekenBtn()
{	

    if(document.getElementById('flashboekBtn')!=null)
    {
	    var flashMovie=getFlashMovieObject("boekenbutton");
	    // 4 is the index of the property for _currentFrame
	    var currentFrame=flashMovie.TGetProperty("/", 4);
	    var nextFrame=parseInt(currentFrame);
	    if (nextFrame != 6)
		    flashMovie.GotoFrame(6);					
    }
    
    if(document.getElementById('boekBtn')!=null)
    {
        $('boekBtn').addClassName("BoekenBtnEnabled").removeClassName("BoekenBtnDisabled");
        $('bookBtnLayer').setStyle({ display : 'block'});
        setTimeout("$('bookBtnLayer').fade()",3000);
    }
    
} 

function disableBoekenBtn()
{	
    if(document.getElementById('flashboekBtn')!=null)
    { 
	    var flashMovie=getFlashMovieObject("boekenbutton");
	    // 4 is the index of the property for _currentFrame
	    var currentFrame=flashMovie.TGetProperty("/", 4);
	    var nextFrame=parseInt(currentFrame);
	    if (nextFrame != 1)
		    flashMovie.GotoFrame(1);					
    }
    if(document.getElementById('boekBtn')!=null)
    {
        $('boekBtn').removeClassName("BoekenBtnEnabled").addClassName("BoekenBtnDisabled");
        $('bookBtnLayer').setStyle({ display : 'none'});
        
    }
} 

function isBoekenBtnEnabled()
{   
    if(document.getElementById('flashboekBtn')!=null)
    {   
	    var flashMovie=getFlashMovieObject("boekenbutton");
	    // 4 is the index of the property for _currentFrame
	    var currentFrame=flashMovie.TGetProperty("/", 4);
	    var nextFrame=parseInt(currentFrame);
	    if (nextFrame > 5)
		    return "true";
	    else
		    return "false";
    }
    
    if(document.getElementById('boekBtn')!=null)
    {
        if(document.getElementById('boekBtn').hasClassName("BoekenBtnEnabled")) return "true";
        else return "false";
    }
    
}

//---boekbtn alert
function showBoekAlert(){
	// als btn grijs is, positioneer rode boekAlert panel op boekBtn 
	renderAlert = function(){
		if(isBoekenBtnEnabled() == "false"){
		    var y = parseInt( document.getElementById('flashboekbutton').offsetTop )+57;
		    document.getElementById('boekAlertSchaduw').style.top = document.getElementById('boekAlert').style.top = y +"px";
		}
	}
	timer = setTimeout(renderAlert, 200);

}
function hideBoekAlert(){
	clearTimeout(timer);
	if(isBoekenBtnEnabled() == "false"){
		document.getElementById('boekAlertSchaduw').style.top = document.getElementById('boekAlert').style.top = -100 +"px";
	}
}
//---klikpanel en hoverpanel functies
function clearSelection(clearClass){
	if(document.getElementById('typetxt')){
		var aParent = document.getElementById('typetxt');
		var aArr = aParent.getElementsByTagName('a');
		for (i=0; i<aArr.length; i++){
			//aArr[i].className = "";
			aArr[i].className = aArr[i].className.replace(" "+clearClass, "");
		}
	}
}

function showVideoPlayer() 
{
	var el = document.getElementById("videoplayer");
	if (el != null) 
	{
		el.style.marginLeft = "11px";		
	}
	var el = document.getElementById("parkyoutube");
	if (el != null) 
	{
		el.style.marginLeft = "11px";		
	}
}

function hideVideoPlayer() 
{
	var el = document.getElementById("videoplayer");
	if (el != null) 
	{
		el.style.marginLeft = "-999em";			
	}
	var el = document.getElementById("parkyoutube");
	if (el != null) 
	{
		el.style.marginLeft = "-999em";			
	}
}

var lastAccomPanel;
var lastAccomPanelTheA;
var lastAccomPanelTheAcc;

function showAccomPanel2(theAcc,thePark) {
	showAccomPanel(lastAccomPanelTheA,theAcc, thePark)
}
function showAccomPanel(theA,theAcc, thePark){
	lastAccomPanelTheAcc = theAcc;

	stopDelayHide();
	
	if (isLoadingHtml) {
		if (lastAccomPanel!=null)
			clearTimeout(lastAccomPanel);
		var tmpstr = "showAccomPanel2('" + theAcc + "','" + thePark + "')";
		lastAccomPanelTheA = theA;
		lastAccomPanel = setTimeout(tmpstr,250);
		return;
	}
	
	hideVideoPlayer();
	//alert(snippetpath + 'getXML.aspx?datasoort=accdescription&taalcode='+spsTaalcode+'&parkcode='+thePark+'&acc_code='+theAcc);
	loadHtmlSnippet(snippetpath + getXmlCached + '?datasoort=accdescription&taalcode=' + spsTaalcode + '&parkcode=' + thePark + '&acc_code=' + theAcc, 'mainKlikPanel', 'acc');
	hideHoverPanel();
	showHoverPanel = function(){ };
	var thePanel = document.getElementById('klikContainer');
	var theSchaduw = document.getElementById('klikContainerSchaduw');
	
	//welke rij is geklikt
	var aParent = document.getElementById('typetxt');
	var aArr = aParent.getElementsByTagName('a');
	for (i=0; i<aArr.length; i++){
		//verwijder eventuele selected class
		aArr[i].className = aArr[i].className.replace(" selected", "");
		if(aArr[i]==theA) {
			//zet selectiekleur en rijnummer
			aArr[i].className += " selected";
			var numrow = i;
		}
		
	}
	//positioneer panel
	
	var fromTop = offsetTop; //236
	offsetrow = numrow*17;
	thePanel.style.top = theSchaduw.style.top = parseInt(fromTop+offsetrow) +"px";
}

var hideKlikPanelTimer;

function delayHideKlikPanel() {
	stopDelayHide();
	hideKlikPanelTimer=setTimeout("hideKlikPanel()",250);
}
function stopDelayHide() {
	clearTimeout(hideKlikPanelTimer);
}


function hideKlikPanel(){
	lastAccomPanelTheAcc = false;
	
	//global var voor positionering hover- en klikpanels
	if(spsThema == "campings") {
    	offsetTop = 264;	
	} else {
	    if (navigator.appName.indexOf("Microsoft Internet")!=-1) {
	        offsetTop = 220;
	    }
	    else {
	        offsetTop = 227;
	    }
	}
	    
	//enable rollover hoverpanel
	showHoverPanel = function(theA){
		//plaats txt uit a(res) in panel
		var aTxt = theA.getAttribute("res");
		document.getElementById('hoverPanel').innerHTML = aTxt;
		//get offset
		var aParent = document.getElementById('typetxt');
		var aArr = aParent.getElementsByTagName('a');
		for (i=0; i<aArr.length; i++){
			if(aArr[i]==theA) {
				var offset = i;
			}
		}
		var fromTop = offsetTop+24; 
		offset = offset*17;
		document.getElementById('hoverContainer').style.top = parseInt(fromTop+offset) +"px";
	};
	hideHoverPanel = function (){
		document.getElementById('hoverContainer').style.top = -100 +"px";
	};
	
	showVideoPlayer();
	
	//verwijder selected class
	clearSelection('selected');		
	//verberg klikpanel
	document.getElementById('klikContainerSchaduw').style.top = document.getElementById('klikContainer').style.top = -500 +"px";	
}
//start show en hide functions (met hideKlikPanel) bij window.onload!

function urlencode( str ) {
    var ret = str;
    
    ret = ret.toString();
    ret = encodeURIComponent(ret);
    ret = ret.replace(/%20/g, '+');
 
    return ret;
}

function gotoPage(myAccCode) {
	var url='';
	if (myAccCode!='price') {
		hideKlikPanel();  // accommodatie details
		url = '/template3.aspx?cp=accommodationdetail&menu=parken&mid=parkenaccommodaties&acc_code=' + urlencode(myAccCode); //+ '&sel_num='+spsAantalpersonen+'&sel_stay='+spsDuur;
	}
	else { // uitgebreide prijsinfo
		url = '/template3.aspx?cp=prijzen&mid=parkenprijsinformatie&menu=parken'; //&sel_num='+spsAantalpersonen+'&sel_stay='+spsDuur;
	}
	if (clickedDiv != null) 
		url = url + '&sel_div='+clickedDiv.id + '&sel_divactie='+clickedDivActieID;	
	else
		url = url + '&sel_date='+spsAankomstYYYYMMDD		
	url += '&taal=' + myTaal; 
		    
	document.location.href = url;
}

function gotoPage(myAccCode, parkcode, accId) {
	setCookie('accommodationNumberOfPersons', '');
	var url='';
	//alert('gotoPage('+myAccCode+', '+parkcode+', '+accId+')');
	if (myAccCode!='price') {
		hideKlikPanel();  // accommodatie details
		if(spsThema == 'campings')
			url = '/template3.aspx?cp=accommodationdetail&menu=campingparken&mid=campingparkencampingplaatsen&acc_code=' + urlencode(myAccCode) + '&taal='+myTaal //+ '&sel_num='+spsAantalpersonen+'&sel_stay='+spsDuur;
		else if(spsThema == 'wintersport')
		    url = '/template3.aspx?cp=accommodationdetail&mid=wintersportparkenaccommodaties&menu=wintersportparken&taal=' + myTaal + '&acc_code=' + urlencode(myAccCode);
        else if(myTaal == 'cz-cz')
            url = '/template3.aspx?cp=accommodationdetail&mid=pesparkenaccommodaties&menu=pesparken&taal=' + myTaal + '&acc_code=' + urlencode(myAccCode) //+ '&sel_num='+spsAantalpersonen+'&sel_stay='+spsDuur;		
		else		
			url = '/template3.aspx?cp=accommodationdetail&mid=parkenaccommodaties&menu=parken&taal='+myTaal+'&acc_code=' + urlencode(myAccCode) //+ '&sel_num='+spsAantalpersonen+'&sel_stay='+spsDuur;		
	}
	else { // uitgebreide prijsinfo
		url = '/template3.aspx?cp=prijzen&mid=parkenprijsinformatie&menu=parken&taal='+myTaal+'';//&sel_num='+spsAantalpersonen+'&sel_stay='+spsDuur;
	}
	
	if (clickedDiv != null) 
		url = url + '&sel_div='+clickedDiv.id + '&sel_divactie='+clickedDivActieID;	
	else
		url = url + '&sel_date='+spsAankomstYYYYMMDD;

	if (!(url.indexOf('parkcode') > -1)) 
		url = url + '&parkcode='+parkcode;

	if(typeof(accId) != 'undefined')
	    url = url + '&id=' + accId
		
	//alert(url);
			
	document.location.href = url;
}

function appendQryString(queryString, strParamlabel, strParamvalue, toCookie) {
	// test of deze ook opgeslagen moet worden in de cookie
	if (toCookie==true)
		setCookie(strParamlabel,strParamvalue);

	// return directly if parameters are null
	if ((strParamlabel == null) || (strParamvalue == null))
		return(queryString);
	// this function builds a URL querystring 
	if (strParamlabel.length > 0) { // only append label when label is valid
		if (strParamvalue.length > 0) { // only append label + value when filled with a value

			queryString = queryString.trim(); // remove trailing and leading spaces
			if (queryString.length == 0)
				var strDivider = '?'; // first parameter
			else
				var strDivider = '&'; // next parameters

			// voordat er geURLencoded wordt eerst +coderen
  			var tmpstrParamvalue = escape(strParamvalue);
			while (tmpstrParamvalue.indexOf('+') > -1) {
				tmpstrParamvalue = tmpstrParamvalue.replace('+', '%2B');
			}
			
			queryString = queryString + strDivider + escape(strParamlabel) + '=' + tmpstrParamvalue
		}
	}
	return(queryString);
}
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function openBooking()
{
	if (!bookButtonActive)
		return;
	var qryStr = '';
	qryStr = appendQryString('ingang=directbooking', 'vk_land', spsLandcode, false);
	qryStr = appendQryString(qryStr, 'boekditpark', spsParkcode, false); 
	qryStr = appendQryString(qryStr, 'vk_bungalow_user', ''+spsAantalpersonen+'', false); // convert to string
	qryStr = appendQryString(qryStr, 'vk_acc_code', spsAccommodatieCode, false);
	if (spsActieID != 0)
	{
		// wanneer er geen actie aan een prijs is gekoppeld, dan de actieid niet mee sturen.
		qryStr = appendQryString(qryStr, 'actieid', spsActieID, false);
	}
	qryStr = appendQryString(qryStr, 'vk_duur', spsDuur, false);
	qryStr = appendQryString(qryStr, 'vk_nachten', spsAantalNachten, false);
	qryStr = appendQryString(qryStr, 'vk_acc_naam', spsAccommodatieNaam, false);

	var YMMDD='';
	if (spsAankomstYYYYMMDD.length == 8)
	{
		YMMDD = spsAankomstYYYYMMDD.substring(3,8);
		qryStr = appendQryString(qryStr, 'vk_aankomst_YMMDD', YMMDD, false);
	}
	openSps(qryStr);
}

function doBooking() {
	if(isBoekenBtnEnabled() == "true" && spsBeschikbaarheidID.charAt(0)!="-"){
	    // normal booking
		openSps('beschikbaarheidid='+spsBeschikbaarheidID);
	}
	else
	    if(isBoekenBtnEnabled() == "true" && spsBeschikbaarheidID.charAt(0)=="-"){
	        // earlybooking
	        var spsQry = 'beschikbaarheidid='+spsBeschikbaarheidID;
	        var aankYMMDD = spsAankomstYYYYMMDD.substring(3);
            spsQry = spsQry + "&vk_duur=" + spsDuur + "&vk_bungalow_user=" + spsAantalpersonen + "&vk_aankomst_YMMDD=" + aankYMMDD + "&vk_acc_code=" + spsAccommodatieCode + "&vk_nachten=" + spsAantalNachten + "&vk_acc_naam=" + escape(spsAccommodatieNaam)+ "&boekditpark=" + spsParkcode + "&ingang=directbooking"
	        openSps(spsQry);
	    }
}

function hld(theDate,acc,state) { // highlightDate
	if(lastAccomPanelTheAcc!=null && lastAccomPanelTheAcc==acc) stopDelayHide();
	else hideKlikPanel();
	//document.getElementById('date'+theDate).style.backgroundColor = '#ff0000';
	el1 = document.getElementById('date'+theDate);
	el2 = document.getElementById('duur'+theDate);
	el3 = document.getElementById('acc'+acc);
	el4className = document.getElementById(theDate+'_'+acc).className
	el5 = document.getElementById('lastminuteLegenda');
	

	
	if(state == "in") { 
		el1.className += " over";
		el2.className += " over";
		el3.className += " selected";
		
		if(el4className.indexOf("Red")>-1)
		{
			if(el4className.indexOf("price3Red")<0) 
				el5.className += " over"; 
		}
		else { el5.className += " forceHide";}

		if(el4className.indexOf("EarlyBooking")>-1)
		{
			el5.className += " overEarlyBooking"; 
		}
	}
	else { 
		el1.className = el1.className.replace(" over", "");
		el2.className = el2.className.replace(" over", "");
		el3.className = el3.className.replace(" selected", "");
		el5.className = el5.className.replace(" overEarlyBooking", "");
		el5.className = el5.className.replace(" over", "");
		el5.className = el5.className.replace(" forceHide", "");
	}

//	alert('el5.className: ' + el5.className);
}

function lml(sh) { // last mintue legenda
	el = document.getElementById('lastminuteLegenda');
	hideKlikPanel();

	if(sh=="show") { el.className = el.className.replace(" forceHide", ""); }
	if(sh=="hide")  { el.className += " forceHide"; }
	if(sh=="clear")  {	el.className = el.className.replace(" selectedEarlyBooking", "");
						el.className = el.className.replace(" selected", "");
						el.className = el.className.replace(" forceHide", "");
						el.className = el.className.replace(" overEarlyBooking", "");  
						el.className = el.className.replace(" over", "");  }
}

function openEarlyBooking(){
// sps.aspx?ingang=directbooking&vk_duur=WE&vk_bungalow_user=6&vk_aankomst_YMMDD=00205&boekditpark=AHT&vk_acc_code=6C&vk_nachten=4&vk_acc_naam=6C%3a+6-persoonsbungalow&beschikbaarheidid=-20100205
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function getTranslation(divId,category,original,languageCode) {
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		//alert("Your browser does not support XMLHTTP!");
	}
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4) // everything ok :)
		{
			document.getElementById(divId).innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","/datapark/sps/vertalingen.aspx?categorie="+category+"&original="+original+"&taalcode="+languageCode,true);
	xmlhttp.send(null);
}
