//=================================================================================================
lngMonths = [
			["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"],
			["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"],
			["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
			["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"]]
//=================================================================================================
function customBodyLoad( sender )
{
	if ( typeof(printing) != 'undefined' && printing )
	{
		window.print();
		window.close();
		return;
	}

	if (steID == 2)
		repositionDiv("Language", 286, 955, 761 );
	else
		repositionDiv("Language", 6, 955, 480 );
		
	repositionDiv("helpText", -231, 955, 240 );		
	try
	{
		var
			url = new Url();
		
		if ( url.get("obj") != null )
		{
			var
				obj    = document.getElementById("o" + url.get("obj") ),
				parent = obj.parentNode.parentNode;
			
			parent.scrollTop = obj.offsetTop;
		}
		
		if ( url.get("type") != null )
		{
			var
				obj    = document.getElementById("t" + url.get("type") ),
				parent = obj.parentNode.parentNode;
			
			parent.scrollTop = obj.offsetTop;
		}
	}
	catch ( error )
	{
	}
}
//=================================================================================================
function customBodyResize( sender, size )
{
	if (steID == 2)
		repositionDiv("Language", 286, 955, 761 );
	else
		repositionDiv("Language", 6, 955, 480 );
	repositionDiv("helpText", -231, 955, 240 );	
}
//=================================================================================================
function customBodyScroll( sender )
{
}
//=================================================================================================
function repositionDiv(name, left, width, defaultLeft )
{
	var div = document.getElementById(name);
	
	if (div)
	{
		if (document.body.offsetWidth > width)
		{			
			div.style.left = Math.round(left + (document.body.offsetWidth / 2)) + "px";
		}
		else
		{		
			div.style.left = defaultLeft + "px";
		}
	}
}
//=================================================================================================
function toggleDisplay( divName )
{
	var div = document.getElementById( divName );
	div.style.display = div.style.display == "none" ? "block" : "none";
	return div.style.display == "block";
}
//=================================================================================================
function setDisplay( divName, on )
{
	var div = document.getElementById( divName );
	div.style.display = on == true ? "block" : "none";
}
//=================================================================================================
function toggleWoningen( idObjType )
{
	var on = toggleDisplay('divWoningen' + idObjType);
	var a = document.getElementById( 'aWoningen' + idObjType );
	var top = $("top_" + idObjType);
	if (on)
	{
		a.innerHTML = getMessage("verberg_woningen");
		
		top.className = 'top open';
	}	
	else
	{
		a.innerHTML = getMessage("toon_woningen");
		top.className = 'top closed';
	}
}
//=================================================================================================
var map;
var baseIcon;
var directionsPanel;
var directions;
//=================================================================================================
function initBaseIcon()
{
	var currentUrl = new Url();

	baseIcon = new GIcon();
	baseIcon.image =  currentUrl.server() +"img/icon_google.png";	
	baseIcon.iconSize = new GSize(41, 49);	
	baseIcon.iconAnchor = new GPoint(20, 49);	
	baseIcon.infoWindowAnchor = new GPoint(20, 25);
}
//=================================================================================================
function initializeMap()
{
   if (GBrowserIsCompatible()) 
   {   
     map = new GMap2(document.getElementById("map_canvas"));      
     map.addControl( new GLargeMapControl3D() );
	  map.addControl( new GMapTypeControl() );	
	  map.setMapType( G_HYBRID_MAP );	  
	  
	  initBaseIcon();
	  
	  var point = new GLatLng(53.049237, 5.380147);
	  map.setCenter(point, 15);	  
  	  directionsPanel = document.getElementById("direction_text");
	  directions = new GDirections(map, directionsPanel);  
	  
	  map.enableContinuousZoom();
	  map.enableScrollWheelZoom();	  
	}
}
//=================================================================================================    
function addToMap(latitude, longitude, address, ID)
{
	var markerOptions = { icon:baseIcon };

	 var point = new GLatLng(latitude, longitude);	 
	 //map.addOverlay(new GMarker(point, markerOptions));
	 
	var marker = new GMarker(point, markerOptions) 	 
	
	address = address;

	GEvent.addListener(marker, 'click', function() 
	{				
	  marker.openInfoWindowHtml(address);
	});

	map.addOverlay(marker);	 	 
}
//=================================================================================================	
function showRoute(ID)
{
	var url = new Url();
	
	location.href = url.add("route", ID);
}
//=================================================================================================
function planRoute(address, routeaddress)
{
	toAddress = routeaddress;
	
	document.getElementById("toAddress").innerHTML = address;

	var directionsDiv = document.getElementById("directions"); 	
		
	if (directionsDiv)
		directionsDiv.style.display = "block";
		
		
	//var mapcanvas = $("map_canvas");	
	//if (mapcanvas)
	//	mapcanvas.style.width = "420px";
	
		
}
//=================================================================================================
function getDirections(toAddress, fromAddressID)
{	
	var fromAddress = document.getElementById(fromAddressID);


	if (fromAddress)
	{
		if (language == 2)
			directions.load("from: " + fromAddress.value + " to: " + toAddress, { "locale": "de_DE" });
		else
			directions.load("from: " + fromAddress.value + " to: " + toAddress, { "locale": "nl_NL" });
	}
		
	var directionsDiv = document.getElementById("direction_text"); 	
		
	if (directionsDiv)
		directionsDiv.style.display = "block";


	var printlink = $("printroutelink");

	if (printlink)
		printlink.style.display = "";

		
	//var mapcanvas = $("map_canvas");	
	//if (mapcanvas)
	//	mapcanvas.style.width = "410px";
		
}
//=================================================================================================	
function toggleLanguageSelect()
{
	var language = document.getElementById("Language");
	
	if (language)
	{		
		if (language.style.display == "none")
			language.style.display = "block"
		else
			language.style.display = "none"		
	}
}
//=================================================================================================	
function gotoImage(tab, sender)
{
	gotoTab(tab);
	
	var bigImage = $("bigImage");
	var smallImage = $(sender);	
	
	if (bigImage && smallImage)
	{	
		bigImage.src = smallImage.src.replace("_small.", "_large.");
		bigImage.alt = smallImage.alt;
	}
}
//=================================================================================================	
function gotoTab( index, name )
{
	var
		tabName = "";
	
	if ( typeof( name ) == "undefined")
		name = "content";
	else
		tabName = name.upperFirst();
	
	for ( var i = 1; i < 8; i++ )
	{
		var content = $( name + "_" + i);
		
		if (content)
			content.style.display = "none";
			
		var tab = $("tab" + tabName + "_" + i);
		
		if (tab)
			tab.className = "";	
	}
	
	var selectedContent = $( name + "_" + index);
	
	setCookie("beachresort.currentTab_" + name , name + "_" + index);
	
	if (selectedContent)
	{
		selectedContent.style.display = "";
	}
	
	var selectedTab = $("tab" + tabName + "_" + index);
	
	if (selectedTab)
		selectedTab.className = "current";
}
//=================================================================================================
var
	lightBox = null;
//-------------------------------------------------------------------------------------------------
function showLightBox(id)
{
	lightBox = new TLightBox(id);	
	
	lightBox.show();
}
//=================================================================================================	
function showAnswer(position)
{
	JQ.query("#faq_" + position).slideToggle(200);
}
//=================================================================================================	
function setEndDate(sender, target)
{
	var endDate = $(target)
		
	if (sender.selectedIndex >= endDate.selectedIndex)	
	{
		if (sender.selectedIndex == (endDate.options.length - 1))
		{
			sender.options[endDate.options.length - 2].selected = true
			$(target).options[endDate.options.length - 1].selected = true
		}
		else
			$(target).options[sender.selectedIndex + 1].selected = true
	}
}
//=================================================================================================	
function setBeginDate(sender, target)
{
	var beginDate = $(target)
	
	if (sender.selectedIndex > 0 && beginDate.selectedIndex == 0)
		beginDate.options[1].selected = true;	
			
	if (sender.selectedIndex <= beginDate.selectedIndex)	
	{
		if (sender.selectedIndex == 0)
		{
			$(target).options[0].selected = true			
		}
		else
			$(target).options[sender.selectedIndex - 1].selected = true		
	}
}
//=================================================================================================	
function changeAccDate()
{
	if (eind && begin)
	{	
		if ( eind.date() < begin.date())
		{
			eind.minDate(begin.date());
			eind.setDate(begin.date());				
		}
	}
}
//=================================================================================================
function toggleMessage(divId)
{
	var helptext = $(divId);
	
	if (helptext)
	{
		if (helptext.style.display == "none")
			helptext.style.display = "";
		else
			helptext.style.display = "none";
	}
}
//=================================================================================================
function showHelpMessage(divId)
{
	var helptext = document.getElementById(divId);
	
	if (helptext)
	{	
		helptext.style.display = "";	
	}
}
//=================================================================================================
function hideHelpMessage(divId)
{
	var helptext =  document.getElementById(divId);
	
	if (helptext)
	{
			helptext.style.display = "none";
	}
}
//=================================================================================================
function toggleBookBtn()
{
	var bookBtn = document.getElementById('bookBtn');
	
	if (bookBtn)
		bookBtn.disabled = !bookBtn.disabled;
}
//=================================================================================================
function checkZoekEnBoek()
{
	var beginDate = $("begindate");
	var endDate = $("enddate");
	
	if (beginDate && endDate)
	{
		if (beginDate.value && endDate.value)
			return true;
		else
		{
			alert(getMessage("geen_datum_geselecteerd"));
			return false;
		}
	}
	else
		return false;
}
//=================================================================================================
function handlePngs()
{
	var 
		arVersion = navigator.appVersion.split("MSIE"), 
		version   = parseFloat( arVersion[1] )
	
	if ( version >= 5.5 && version < 7.0 && document.body.filters )
	{
		for ( var i = 0; i < document.images.length; i++ )
		{
			var 
				img     = document.images[i], 
				imgName = img.src.toUpperCase();
			
			if ( imgName.substring( imgName.length - 3, imgName.length ) == "PNG")
			{
				var 
					imgID    = img.id        ? "id=\"" + img.id + "\" " : "", 
					imgClass = img.className ? "class=\"" + img.className + "\" " : "", 
					imgTitle = (img.title)   ? "title=\"" + img.title + "\" " : "title=\"" + img.alt + "\" ", 
					imgStyle = "display:inline-block;" + img.style.cssText;
				
				if ( img.align == "left") 
					imgStyle = "float:left;" + imgStyle;
				
				if (img.align == "right") 
					imgStyle = "float:right;" + imgStyle;
				
				if ( img.parentElement.href ) 
					imgStyle = "cursor:pointer;" + imgStyle;
				
				var
					width      = img.offsetWidth, 
					height     = img.offsetHeight, 
					strNewHTML = 
							"<span " + imgID + imgClass + imgTitle + " style=\"" + 
							"width:" + img.width + "px;" + 
							"height:" + img.height + "px;" + imgStyle + ";" + 
							"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + 
							"(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				
				i = i - 1;
			}
		}
	}
}
//-------------------------------------------------------------------------------------------------
	addEvent( window, "load", handlePngs );
//=================================================================================================
function submitStep1()
{
	if (isSame(arrivalCal.date(), departureCal.date())) return;
	document.getElementById('bookingDatesForm').submit();
}
//=================================================================================================
function submitStep2()
{
	var bookingForm = $("bookingDataForm");
	var aantalVolwassenen = $("aantalVolwassenen");
	var aantalKinderen = $("aantalKinderen");
	var aantalBabys = $("aantalBabys");
	var geboorteDatumOudste = $("geboorteDatumOudste");
	var geboorteDatumJongste = $("geboorteDatumJongste");
	var check = true;	
	
	if ( aantalVolwassenen )
	{
		var value = aantalVolwassenen.value;
		
		if (!isNumeric(value))
		{
			alert(getMessage("volwassenen_is_niet_ingevuld"));
			aantalVolwassenen.focus();
			check = false;		
			return;	
		}
		else if (value <= 0)
		{
			alert(getMessage("volwassenen_moet_een_of_meer_zijn"));
			aantalVolwassenen.focus();
			check = false;
			return;
		}
	}
	
	if ( aantalKinderen )
	{
		var value = aantalKinderen.value;
		
		if (value)
		{		
			if (!isNumeric(value))
			{
				alert(getMessage("waarde_aantal_kinderen_geen_getal"));
				aantalKinderen.focus();
				check = false;			
				return;
			}
			else if (value < 0)
			{
				alert(getMessage("aantal_kinderen_niet_negatief"));
				aantalKinderen.focus();
				check = false;
				return;
			}
		}
	}
	
	if ( aantalBabys )
	{
		var value = aantalBabys.value;
		
		if (value)
		{
			if (!isNumeric(value))
			{
				alert(getMessage("waarde_aantal_babies_geen_getal"));
				aantalBabys.focus();
				check = false;		
				return;	
			}
			else if (value < 0)
			{
				alert(getMessage("aantal_babies_niet_negatief"));
				aantalBabys.focus();
				check = false;
				return;
			}
		}
	}
	
	if (geboorteDatumOudste)
	{
		if (geboorteDatumOudste.value)
		{
			if (!isDate(geboorteDatumOudste.value))
			{
				alert(getMessage("datum_oudste_persoon_geen_datum"));
				geboorteDatumOudste.focus();
				check = false;
				return;
			}
		}
	}
	
	if (geboorteDatumJongste)
	{
		if (geboorteDatumJongste.value)
		{
			if (!isDate(geboorteDatumJongste.value))
			{
				alert(getMessage("datum_jongste_persoon_geen_datum"));
				geboorteDatumJongste.focus();
				check = false;
				return;
			}
		}
	}
	
	
	if (bookingForm && check)
		bookingForm.submit();	
}
//=================================================================================================
function submitStep4()
{
	var form = $("persoonsgegForm");

	var naam = $("achternaam");
	var geboortedatumInput = $("geboorteDatum");
	var postcode = $("postcode");
	var huisnummer = $("huisnummer");
	var straatnaam = $("straatnaam");
	var plaats = $("woonplaats");
	var telefoon = $("telefoon");
	var email = $("e-mailadres");
	var voorwaarden = $("voorwaarden");
	
	if (naam && !naam.value)
	{
		alert(getMessage("geen_naam"));
		naam.focus();
		return;
	}
	
	if (!geboortedatumInput.value)
	{
		alert(getMessage("geen_geboortedatum"));
		geboortedatumInput.focus();
		return;
	}
	
	if (postcode && !postcode.value)
	{
		alert(getMessage("geen_postcode"));
		postcode.focus();
		return;
	}
	
	if (straatnaam && !straatnaam.value)
	{
		alert(getMessage("geen_straat"));
		straatnaam.focus();
		return;
	}
	
	if (huisnummer && !huisnummer.value)
	{
		alert(getMessage("geen_huisnummer"));
		huisnummer.focus();
		return;
	}
	
	if (plaats && !plaats.value)
	{
		alert(getMessage("geen_plaats"));
		plaats.focus();
		return;
	}
	
	if (telefoon && !telefoon.value)
	{
		alert(getMessage("geen_telefoon"));
		telefoon.focus();
		return;
	}
	
	if (email)
	{
		if (!email.value)
		{
			alert(getMessage("geen_email"));
			email.focus();
			return;
		}
		else
		{
			if (!isEmail(email.value))
			{
				alert(getMessage("email_onjuist"));
				email.focus();
				return;
			}
		}
	}
	
	if (voorwaarden && !voorwaarden.checked)
	{
		alert(getMessage("geen_voorwaarden"));
		voorwaarden.focus();
		return;
	}
	
	if (form)
		form.submit();
}
//=================================================================================================
function completeAddress()
{
	var postcode = $("postcode").value;
	var huisnummer = $("huisnummer").value;

	try
	{
		var
			url = new Url("misc/getAddress.aspx");
			
		url = url.add("postcode", postcode).add("huisnummer", huisnummer);
		
		var XML = url.request( "post", null, true );
		
		if ( typeof( XML ) != "boolean")
		{			
			var straatnaam = $("straatnaam");
			var woonplaats = $("woonplaats");
			
					
			var plaats = XML.getElementsByTagName("PLAATS")[0].firstChild.nodeValue;
			var straat = XML.getElementsByTagName("STRAAT")[0].firstChild.nodeValue;											
				
			if (straatnaam && straat)
				straatnaam.value = straat;
			
			if (woonplaats && plaats)
				woonplaats.value = plaats;			
		}
	}
	catch ( error )
	{
	}

}
//=================================================================================================
function maxLength(sender, maxLength) 
{
	var str = $( sender ).value;

	var length = 0

	if (str)
	{
		var lns = str.match(/[^\r]\n/g);

		if (lns)
			length = str.length + lns.length;
		else
			length = str.length;
			
		alert(length);	
	
	/*	if (length > maxLength)
			return false;
		else
			return true;
	*/
	}
	
	
}
//=================================================================================================
function printReservation( itmID ) 
{
	var
		url = new Url().remove("msg"),
		win;
	
	if ( typeof( itmID ) != "undefined")
		url = url.remove("catID").add("itmID", itmID );
	
	win = window.open( url.replacePage("printReservation.aspx"), "printReservering", "menubar=0,location=0,toolbar=0,scrollbars=1,resizable=0,status=0,width=880,height=600");
	
	
	if ( win )
		win.focus();
}
//=================================================================================================
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
//=================================================================================================
function displayBusySearchingIndicator()
{
	var base = document.getElementById("showAccomodations"),
	iddiv = document.getElementById("busySearching");
	//alert(getLeft(logo));
	if (iddiv)
	{
		iddiv.style.display = "block";	//Remember: offsetWidth heeft alleen een waarde als de div zichtbaar is
		iddiv.style.left = getLeft(base) + Math.round(base.offsetWidth / 2) - Math.round(iddiv.offsetWidth / 2) + 'px';
		//iddiv.style.display = "none";
		iddiv.style.top = getScrollXY()[1] + 250 + 'px'; //getTop(base)


		setTimeout('document.images["imgLoader"].src = "/img/loaderBig.gif"', 200); 
	}
}
//=================================================================================================
function changeArrivalDate(sender, event)
{
	if(arrivalCal.date() != null && sender.date() != null )
	{
		if (departureCal && sender.date() > departureCal.date())
		{
			departureCal.setDate(arrivalCal.date());

			departureCal.minDate = arrivalCal.date();
		}
		
		 document.getElementById('aankomstdatum').value = sender.date().formatString("d");
		 document.getElementById('displayAankomstdatum').innerHTML = sender.date().formatString(" d MMMM yyyy"); 
	}
}
//=================================================================================================
function changeDepartureDate(sender, event)
{
	if (sender.date() != null)
	{
		document.getElementById('vertrekdatum').value = sender.date().formatString("d");

		document.getElementById('displayVertrekdatum').innerHTML = sender.date().formatString(" d MMMM yyyy");
	}
}
//=================================================================================================
function openFlipbook(itmID)
{
	var 
		url = new Url("../misc/flipbook.aspx").add("itmID", itmID),
		win = window.open(url, "frmFlipbook", "menubar=0,location=1,toolbar=0,scrollbars=0,resizable=0,status=0,width=940,height=650");

	if (win)
		win.focus();
}
//=================================================================================================
function webcam(BaseURL, camText) 
{

    var  
        DisplayWidth = "352",
        DisplayHeight = "288",
        File = "/axis-cgi/mjpg/video.cgi?resolution=CIF&compression=50&clock=1&date=1&text=1&textstring="+camText,
        output = "";

    if ((navigator.appName == "Microsoft Internet Explorer") &&
	   (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k")) {
        // If Internet Explorer under Windows then use ActiveX
        output = '<OBJECT ID="Player" width='
        output += DisplayWidth;
        output += ' height=';
        output += DisplayHeight;
        output += ' CLASSID="CLSID:745395C8-D0E1-4227-8586-624CA9A10A8D" ';
        output += 'CODEBASE="';
        output += BaseURL;
        output += '/activex/AMC.cab#version=3,0,20,1">';
        output += '<PARAM NAME="MediaURL" VALUE="';
        output += BaseURL;
        output += File + '">';
        output += '<param name="MediaType" value="mjpeg-unicast">';
        output += '<param name="ShowStatusBar" value="0">';
        output += '<param name="ShowToolbar" value="0">';
        output += '<param name="AutoStart" value="1">';
        output += '<param name="StretchToFit" value="1">';
        //  output += '<param name="PTZControlURL" value="/axis-cgi/com/ptz.cgi?camera=1">';
        //  output += '<param name="UIMode" value="ptz-relative">'; // or "ptz-absolute"
        output += '<B>Axis Media Control</B><br/>';
        output += 'The AXIS Media Control, which enables you ';
        output += 'to view live image streams in Microsoft Internet';
        output += ' Explorer, could not be registered on your computer.';
        output += '</OBJECT>';

    } else {
        // If not IE for Windows use the browser itself to display
        theDate = new Date();
        output = '<IMG SRC="';
        output += BaseURL;
        output += File;
        output += '&dummy=' + theDate.getTime().toString(10);
        output += '" HEIGHT="';
        output += DisplayHeight;
        output += '" WIDTH="';
        output += DisplayWidth;
        output += '" ALT="Camera Image">';

    }

    document.write(output);
    if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k"))
        document.Player.ToolbarConfiguration = "play,+snapshot,+fullscreen"

}
//=================================================================================================
function printRoute(addressTo, addressFromID)
{
	if (language == 2)
		window.open("http://maps.google.de/maps?f=d&source=s_d&saddr=" + fromAddress.value + "&daddr=" + addressTo + "&hl=de&mra=ls&ie=UTF8&t=h&z=12&layer=c&pw=2");
	else
		window.open("http://maps.google.nl/maps?f=d&source=s_d&saddr=" + fromAddress.value + "&daddr=" + addressTo + "&hl=nl&mra=ls&ie=UTF8&t=h&z=12&layer=c&pw=2");
}
//=================================================================================================
function downloadPDF()
{
	$("downloadPDF").href = pdf;
}
//=================================================================================================
function deleteFile( file )
{
	if ( confirm("Weet u zeker dat u dit bestand wilt verwijderen?") )
	{
		var
			url = new Url();
		
		url = new Url( url.toString().replace("/bestanden?", "/upload.aspx?") );
		url = url.add("action", "remove");
		url = url.add("file",   file    );
		
//		alert("url: " + valueString( url ) + "\r\n");
		
		document.location.href = url;
	}
}
//=================================================================================================
