function getHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
}

function show_slideshow() {
        document.location.href = '#top';
        var height = getHeight();
        var width = getWidth();

        var left = (width-470)/2;
        var top = (height-520)/2;

        document.getElementById('background').style.width=width-16;
        document.getElementById('background').style.display='block';
        document.getElementById('slideshow').style.display='block';
        document.getElementById('slideshow').style.left=left;
        document.getElementById('slideshow').style.top=top;
}

function hide_slideshow() {
        document.getElementById('background').style.display='none';
        document.getElementById('slideshow').style.display='none';
}

function check_mail()
{
	var mail_naam      = document.getElementById('mail_naam');
        var mail_naam_ver  = document.getElementById('mail_email_verzender');
        var mail_email_ont = document.getElementById('mail_email_ontvanger');	
        var mail_security  = document.getElementById('mail_security');
	var code           = document.getElementById('mail_form_sec').value;
	var error = "";
	if(!mail_naam.value){ error = error + 'Naam\n'; }
	if(!mail_naam_ver.value.match('@')){ error = error + 'Email adres verzender\n'; }
	if(!mail_email_ont.value.match('@')){ error = error + 'Email adres ontvanger\n'; }
	if(mail_security.value != code ){ error = error + 'Beveiligingscode\n'; }
	if(error)
	{
		alert('Er is een fout opgetreden bij het versturen van uw email, de volgende velden zijn niet naar behoren ingevuld:\n\n'+error);
		return false;
	}else
	{
		return true;
	}
}

function mail(id,image,code,content)
{
	document.getElementById('rearlayer').style.display = "block";
	if(content)
	{
		document.getElementById('popup').oldHTML = document.getElementById('popup').innerHTML;
		document.getElementById('popup').innerHTML = '<div style="position: absolute; top: 5px; right: 5px;"><a href="javascript: mail_close();">Close</a></div>'+content;
	}else
	{
		document.getElementById('hidden_hotel_id').value = id;
		document.getElementById('mail_form_sec').value = code;
		document.getElementById('sec_code_img').innerHTML = "<img style='vertical-align: middle;' src='"+image+"'>";
	}
	document.getElementById('popup').style.display = "block";
}

function mail_close()
{
	if(document.getElementById('popup').oldHTML)
	{
		document.getElementById('popup').innerHTML = document.getElementById('popup').oldHTML;
	}
        document.getElementById('rearlayer').style.display = "none";
        document.getElementById('popup').style.display = "none";
}

function show_foto()
{
	document.getElementById('rearlayer').style.display = "block";
	document.getElementById('foto_popup').style.display = "block";
}

function close_foto()
{
        document.getElementById('rearlayer').style.display = "none";
        document.getElementById('foto_popup').style.display = "none";
}
function create_http() {
try
  {
        // Firefox, Opera 8.0+, Safari
         http=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    http=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      http=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  return http;
}
function getPrices(dateText){
	$('#priceBlock').html("<img src='/images/ajax-loader.gif'>");
	//initialize!
	var ciYear = null;
	var coYear = null;
	var hotelId = document.getElementById('hotelid').innerHTML;

	//get some user-vars
	if($('#datepicker').datepicker('getDate').getYear() < 2000){
		ciYear = ($('#datepicker').datepicker('getDate').getYear() + 1900);
	} else {
		ciYear = $('#datepicker').datepicker('getDate').getYear();
	}
	var ciDate = ciYear+"-"+($('#datepicker').datepicker('getDate').getMonth()+1)+"-"+$('#datepicker').datepicker('getDate').getDate();

	if($('#co_datepicker').datepicker('getDate').getYear() < 2000){
		coYear = ($('#co_datepicker').datepicker('getDate').getYear() + 1900);
	} else {
		coYear = $('#co_datepicker').datepicker('getDate').getYear();
	}
	var coDate = coYear+"-"+($('#co_datepicker').datepicker('getDate').getMonth()+1)+"-"+$('#co_datepicker').datepicker('getDate').getDate();

	//lets get prices
	$.ajax({
		type: "POST",
		url: "/ajax/bookings/getPrices.php",
		data: "ciDate="+ciDate+"&coDate="+coDate+"&hotel_id="+hotelId,
		success: function(msg){
			$('#priceBlock').html(msg);
		}
	});
}
function createCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function eraseCookie(name) {
        createCookie(name,"",-1);
}
function findReturnDates(dateText){
	$('#priceBlock').html("");
	$.ajax({
		type: "POST",
		url: "/ajax/bookings/findReturnDates.php",
		data: "date="+dateText+"&hotel_id="+document.getElementById('hotelid').innerHTML,
		success: function(msg){
			var parts = msg.split("--**TOEVAL**--");
			$("#returndateselector").html(parts[0]);
			eval(parts[1]);
		}
	});
}
function getMovies(hotelid){
        http = create_http();
        var url = "/ajax/youtube/index.php";

        var params = 'hotel_id='+hotelid;
        http.open("POST", url, true);
        document.getElementById('filmblok').innerHTML = '';

        //Send the proper header information along with the request
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.onreadystatechange = function() {//Call a function when the state changes.
                if(http.readyState == 4) {
                        var rt = http.responseText;
                        document.getElementById('filmblok').innerHTML = rt;
                }
        }
        http.send(params);
}
