
function changeImageAndMap(id)
{
	//alert(id);
	document.getElementById('theMap').src = document.getElementById('base_url').value+"templates/zavpictures/" + id + ".png";
	document.getElementById('theMap').useMap = "#Map-"+id;
	document.getElementById('provinceSelected').value = id;
	//alert(document.getElementById('provinceSelected').value);
}

function searchForAccommodation(id, page)
{
document.getElementById('regionSelected').value = id;
if(page == "" || typeof(page) == "undefined")
{
document.getElementById('pageSelected').value = 1;
}
else
{
document.getElementById('pageSelected').value = page;
}

if(document.getElementById('sortBy') == null) //it means the map is pressed for the first time and we don't have the select box
document.getElementById('sortSelected').value = 1;
else
document.getElementById('sortSelected').value = document.getElementById('sortBy').value;

document.forms.searchForAccommodationForm.submit();
}


function setVisibility(id, visibility) {
document.all[id].style.display = visibility;
}


function prepareDays()
{
	document.getElementById('day_f_date_c').submit();
}



function prepareRegions()
{
	document.getElementById('regionsForm').submit();
}

function prepareCities()
{

	document.getElementById('searchDestinationsForm').submit();
}


function prepareFilterMethod()
{

	document.getElementById('filterForm').submit();
}

function hideShowDiv(which)
{


	if (which.style.display == "none")
	{
	
		if( which.id == "entire_address" )
			{
			var curtextval = document.getElementById("message_show");
			
			curtextval.innerHTML = "Verbergen";
			}
		which.style.display = "block";
		
	}
	else
	{
		if( which.id == "entire_address" )
			{
			var curtextval = document.getElementById("message_show");
			curtextval.innerHTML = "Toon";
			}
		which.style.display = "none";
	}
	
}


// Gallery script.
// With image cross fade effect for those browsers that support it.
// Script copyright (C) 2004 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
function LoadGallery(pictureName,imageFile)
{
  var picture = document.getElementById(pictureName);
  if (picture.filters)
  {
    picture.style.filter="blendTrans(duration=1)";
    picture.filters.blendTrans.Apply();
  }
  picture.src = imageFile;
  if (picture.filters)
  {
    picture.filters.blendTrans.Play();
  }

}


function on_load_function() {				

	try
	{	
		var currentProvince = document.getElementById('curProvHidden').value;
		var currentRegion = document.getElementById('curRegiHidden').value;
		var currentCity = document.getElementById('curCityHidden').value;
		var change = 0;
		if(currentProvince != 0)
		{
			doChangeZone('provinces',currentProvince,0,0);
			if(currentRegion != 0)
			{
				doChangeZone('regions',currentRegion,currentProvince,0);
				if(currentCity != 0)
					doChangeZone('cities',currentCity,currentRegion,0);
				else
					doChangeZone('cities',0,currentRegion,0);
			}
			else
			{
				doChangeZone('regions',0,currentProvince,0);
				if(currentCity != 0)
					doChangeZone('cities',currentCity,0,currentProvince);
				else
					doChangeZone('cities',0,0,currentProvince);
			}
			change = 1;
		}
		//select the province regions and cities that are default
		if(change == 0)
		{
			doChangeZone('provinces',1,0,0);
			doChangeZone('regions',0,1,0);
			doChangeZone('cities',0,0,1);
		}
	}
	catch(err)
	{
		//alert('error1');
	}
		
			try
			{
				
				
				
				var today = new Date();
				var today_day = Number(today.getDate()) ;
				var today_month = Number(today.getMonth()) + 1;
				var today_year = Number(today.getFullYear() );
				
				if (document.getElementById('checkInDateHidden') != null)
				{
					
					 if (document.getElementById('checkInDateHidden') != null)
					 {
						
					 	var dateString = document.getElementById('checkInDateHidden').value ;
						
						var dt = new Date();
						dtYear = dt.getYear();
						if (dtYear < 1000) dtYear += 1900;
						dtFormated = dt.getDate() + "-" + (parseInt(dt.getMonth())+1) + "-" + dtYear;
						
						if(dateString == "")
							dateString = dtFormated;
						
						var dArray;
					 	
					 	if (dateString.indexOf("-") >= 0)
	    					dArray = dateString.split("-");
	    				
	    				d = parseInt(dArray[0], 10);
						
				        m = parseInt(dArray[1], 10);
				        y = parseInt(dArray[2], 10);
				      
						dochangeSelect('day_date_check_in', m, 0, y, d);
						dochangeSelect('month_date_check_in', m, 0, y, 0);
				      writeDataInTextBox('day_date_check_in', d,  m, y);
					  
					 } 
					 if (document.getElementById('checkOutDateHidden') != null)
					 {
						var dateString = document.getElementById('checkOutDateHidden').value ;
					 	var dArray;
					 	
					 	if (dateString.indexOf("-") >= 0)
	    					dArray = dateString.split("-");
							
						var dt = new Date();
						dtYear = dt.getYear();
						if (dtYear < 1000) dtYear += 1900;
						dtFormated = dt.getDate() + "-" + (parseInt(dt.getMonth())+1) + "-" + dtYear;
						
					 	
						if(dateString == "")
						{
							dateString = dtFormated;
							d = parseInt(dArray[0], 10);
						}
						else
						{
							d = parseInt(dArray[0], 10) - 1;
						}
				        m = parseInt(dArray[1], 10);
				        y = parseInt(dArray[2], 10);
				
				        dochangeSelect('day_date_check_out', d,  m, y, 0);
						dochangeSelect('month_date_check_out', m, 0, y, d);
					
						writeDataInTextBox('day_date_check_out', d,  m, y);
					 } 
				}
				
				else
				{	
					dochangeSelect('day_date_check_in', today_month, 0, today_year, today_day);
					dochangeSelect('month_date_check_in', today_month, 0, today_year, 0);
					
					
					
					dochangeSelect('day_date_check_out', today_day,  today_month, today_year, 0);
					dochangeSelect('month_date_check_out', today_month, 0, today_year, today_day);
				
					writeDataInTextBox('day_date_check_in', today_day,  today_month, today_year);
					writeDataInTextBox('day_date_check_out', today_day,  today_month, today_year);
				}
			}
			catch(err)
			{
				//alert('error2');
			}
	}

function getAllElementsByName(name)
{
	var elems = document.getElementsByTagName('select');
	var arr = new Array();

	for ( var i = 0; i < elems.length; i++ )
	{
		var elem = elems[i];
	
		if ( elem.getAttribute('name') == name )
		{
		
		var val = elem.value;
		
		}
	}
	return val;
}	






//for showing up the info message
function getCode()
	{
	
	var codHTML = '';
	/*codHTML += "Find hotels in a village or city. Example:";
	codHTML += "<ul>";
	codHTML += "	<li>";
	codHTML += "		<i>Berlin</i> to find Berlin";
	codHTML += "	</li>";
	codHTML += "</ul>";
	
	codHTML += "Find hotels in a village or city. Example:";
	codHTML += "<ul>";
		codHTML += "<li>";
			codHTML += "<i>Berlin</i> to find Berlin";
		codHTML += "</li>";
		codHTML += "<li>";
			codHTML += "<i>Berlin</i> to find Berlin";
		codHTML += "</li> 	";
		 	
	codHTML += "</ul>";
	codHTML += "Find hotels near an airport. Examples:";
	codHTML += "<ul>";
		codHTML += "<li>";
			codHTML += "<i>Heathrow</i> to find London Heathrow Airport";
		codHTML += "</li>";
		codHTML += "<li>";
			codHTML += "<i>LHR</i> to find Heathrow Airport by airport code";
		codHTML += "</li>"; 	
		 	
	codHTML += "</ul>";*/
	codHTML += "U kunt hier uw bestemming selecteren;<br /> U kunt direct in de 'bestemming' box de gewenste plaats selecteren.<br /> Of u selecteert per regio in de Western Cape provincie, waarna u de<br /> plaats kunt selecteren in de 'bestemming' box.";
	return codHTML;
		
	} 
function getCode2()
	{
	
	var codHTML = '';
	/*codHTML += "Find hotels in a village or city. Example:";
	codHTML += "<ul>";
	codHTML += "	<li>";
	codHTML += "		<i>Berlin</i> to find Berlin";
	codHTML += "	</li>";
	codHTML += "</ul>";
	
	codHTML += "Find hotels in a village or city. Example:";
	codHTML += "<ul>";
		codHTML += "<li>";
			codHTML += "<i>Berlin</i> to find Berlin";
		codHTML += "</li>";
		codHTML += "<li>";
			codHTML += "<i>Berlin</i> to find Berlin";
		codHTML += "</li> 	";
		 	
	codHTML += "</ul>";*/
	codHTML += "Hier kunt u de zoekfunctie starten.<br /> Voor een gedetailleerder zoekresultaat,<br /> zoals bijvoorbeeld een zwembad,<br />  kunt u de box 'zoekresultaat verfijnen'<br /> aanvinken.";
	return codHTML;
		
	} 
function getCodeNewsletter()
	{
	
	var codHTML = '';
	/*codHTML += "AAAAAAA";
	codHTML += "<ul>";
	codHTML += "	<li>";
	codHTML += "		<i>Berlin</i> to find Berlin";
	codHTML += "	</li>";
	codHTML += "</ul>";
	
	codHTML += "Find hotels in a village or city. Example:";
	codHTML += "<ul>";
		codHTML += "<li>";
			codHTML += "<i>Berlin</i> to find Berlin";
		codHTML += "</li>";
		codHTML += "<li>";
			codHTML += "<i>Berlin</i> to find Berlin";
		codHTML += "</li> 	";
		 	
	codHTML += "</ul>";*/
	codHTML += "U kunt zich aanmelden door hier uw emailadres in te vullen.<br /> Opzeggen gaat eenvoudig; onderaan elke nieuwsbrief treft u hiervoor een link aan.";

	return codHTML;
		
	} 	
function getUpFrontPay()
	{
	
	var codHTML = '';
	codHTML += "Indien u er voor kiest om het volledige bedrag te betalen bij boeking,<br /> dan hoeft u niets meer te betalen ter plekke in uw accommodatie.<br /> Wij betalen het volledige bedrag voor aankomst aan uw accommodatie.<br /> Wel zo makkelijk!";

	return codHTML;
		
	} 	
function testContactPayForm()
{
	var isOk = true;
	
	//document.getElementById('title').style.borderColor = "#CCCCCC";
	document.getElementById('firstname').style.borderColor = "#CCCCCC";
	document.getElementById('surename').style.borderColor = "#CCCCCC";
	document.getElementById('email').style.borderColor = "#CCCCCC";
	document.getElementById('reemail').style.borderColor = "#CCCCCC";
	document.getElementById('phone').style.borderColor = "#CCCCCC";
	document.getElementById('timeArrival').style.borderColor = "#CCCCCC";
		
	/*if(document.getElementById('title').value == '')
	{
		document.getElementById('title').style.borderColor = "#FF0000";
		isOk = false;
	}*/
	if(document.getElementById('firstname').value == '')
	{
		document.getElementById('firstname').style.borderColor = "#FF0000";
		isOk = false;
	}
	if(document.getElementById('surename').value == '')
	{
		document.getElementById('surename').style.borderColor = "#FF0000";
		isOk = false;
	}
	if(document.getElementById('email').value == '')
	{
		document.getElementById('email').style.borderColor = "#FF0000";
		isOk = false;
	}
	if(document.getElementById('reemail').value == '')
	{
		document.getElementById('reemail').style.borderColor = "#FF0000";
		isOk = false;
	}
	if(document.getElementById('phone').value == '')
	{
		document.getElementById('phone').style.borderColor = "#FF0000";
		isOk = false;
	}
	if(document.getElementById('timeArrival').value == '')
	{
		document.getElementById('timeArrival').style.borderColor = "#FF0000";
		isOk = false;
	}
	
	if(document.getElementById('email').value != document.getElementById('reemail').value)
	{
		document.getElementById('email').style.borderColor = "#FF0000";
		document.getElementById('reemail').style.borderColor = "#FF0000";
		isOk = false;
	}
	
	return isOk;
}
function UncheckStars(nr)
{
	var i;
	for(i = 1; i<=5; i++)
	{
		if(i != nr)
		{
			document.getElementById('stars'+i+'Choose').checked = false;
		}
	}
}
function checkDatesCron()
{
	/*var select_list_field = document.getElementsByName('month_date_check_in');
	var select_list_selected_index = select_list_field[0].selectedIndex;
	var textStartMY = select_list_field[0].options[select_list_selected_index].text;
	
	var select_list_field1 = document.getElementsByName('month_date_check_out');
	var select_list_selected_index1 = select_list_field1[0].selectedIndex;
	var textEndMY = select_list_field1[0].options[select_list_selected_index1].text;
	
	var startYear = parseInt("20"+textStartMY.substr(textStartMY.indexOf("'",0)+1));
	var endYear = parseInt("20"+textEndMY.substr(textEndMY.indexOf("'",0)+1));
	
	var textStartMonth = textStartMY.substr(0,textStartMY.indexOf("'",0));
	var textEndMonth = textStartMY.substr(0,textEndMY.indexOf("'",0));
	
	alert(textStartMonth);
	alert(textEndMonth);
	
	alert(startYear);
	alert(endYear);
	return false;
	/*var isError = false;
	/*var startDay = document.getElementById('').value;
	var startMonthY = document.getElementById('').value;
	var endDay = document.getElementById('').value;
	var endMonthY = document.getElementById('').value;
	*/
	
}
function checkTermsConditions()
{
	document.getElementById('terms-cond').style.display = "none";
	if(document.getElementById('conditionsNo').checked == true)
	{
		document.getElementById('terms-cond').style.display = "block";
		return false;
	}
	return true;
}
function roomDetailsDisplay(id)
{
	var the_item = document.getElementById(id);
	if(the_item != null)
	{
		if(the_item.style.display == 'none')
		{
			the_item.style.display = 'block';
		}
		else
		{
			the_item.style.display = 'none';
		}
	}
}
/*
function automaticResize(element,width,height)
{
	
	if (width_orig / width < height_orig / height)
	{
		w = (int) ((height / height_orig) * width_orig);
		   h = height;
	   }
	   else
	   {
		   h = (int) ((width / width_orig) * height_orig);
		   w = width;
	   }
}*/
function resizeImage(element) {
	img = element;
	//img.src='images/'+newPhoto;
	var width = img.naturalWidth;
	var height = img.naturalHeight;
	var newx = 200; // set to whatever you want the images max width to be.
	var newy = 130; // whatever you want the images maximum height to be.
	if ( width >= height ) {
		// landscape
		var tmpy = height*newx/width;
		if ( tmpy <= newy )
			newy = tmpy;
		else
			newx = width*newy/height;
	}
	else 
	{
		// portrait
		tmpx = width*newy/height;
		if ( tmpx <= newx )
			newx = tmpx;
		else
			newy = height*newx/width;
	}
	img.width = newx;
	img.height = newy;
}
function delay_loading(the_url)
{
	$.fancybox.close();
	window.location = the_url;
}
function searchForAccommodation()
{
	
	var the_url = document.getElementById('base_url').value + 'search-destinations/';
	var the_form = document.getElementById('searchDestinationsForm');
	//alert(document.getElementById('checkBoxSearchMore').checked);
	rLoading = $.ajax({
		  url: the_url,
		  global: false,
		  type: "POST",
		  data: (
			{
				citiesId : document.getElementById('citiesId').value,
				provinces : document.getElementById('provincesH').value,
				regions : document.getElementById('regionsH').value,
				cities : document.getElementById('citiesH').value,
				destinationType : document.getElementById('destinationType').value,
				nrOfPersons : document.getElementById('nrOfPersons').value,
				check_in_date : document.getElementById('check_in_date').value,
				check_out_date : document.getElementById('check_out_date').value,
				CityAjax : document.getElementById('CityAjax').value,
				chBoxSearchMore: document.getElementById('checkBoxSearchMore').checked,
				stars1Choose: document.getElementById('stars1Choose').checked,
				stars2Choose: document.getElementById('stars2Choose').checked,
				stars3Choose: document.getElementById('stars3Choose').checked,
				stars4Choose: document.getElementById('stars4Choose').checked,
				stars5Choose: document.getElementById('stars5Choose').checked,
				swimmingpoolChoose: document.getElementById('swimmingpoolChoose').checked,
				
				ajaxRedirect : 1,
				destinationSearchTool : document.getElementById('destinationSearchToolSearchPage').value,
				destinationSearchToolAjax : 1
			}
		  ),
		  dataType: "text",
		  async:true,
		  success: function(msg){
			//$.fancybox.close();
			/*document.getElementById('destinationSearchToolAjax').value = 1;
			the_form.submit();*/
			setInterval( function() { delay_loading(the_url); }, 5000 );
			//window.location = the_url;
		  },
		  error: function(x,msg,y){
			setInterval( function() { delay_loading(the_url); }, 5000 );
		  }
	   }
	)
	
}
function filterStar(el, value)
{
	var the_url = '';
	the_url = document.getElementById('base_url').value + 'filterStar/';
	the_url_r = document.getElementById('base_url').value + 'search-destinations/';
	if(el.checked == true)
		tempAction = "add";
	else
		tempAction = "remove";
	
	rLoading = $.ajax({
		  url: the_url,
		  global: false,
		  type: "POST",
		  data: (
			{
				item : value,
				action : tempAction
			}
		  ),
		  dataType: "text",
		  async:false,
		  success: function(msg){
			window.location = the_url_r;
		  },
		  error: function(msg){
			window.location = the_url_r;
		  }
	   }
	)
}
function filterAvailability(el, value)
{
	var the_url = '';
	the_url = document.getElementById('base_url').value + 'filterAvailability/';
	the_url_r = document.getElementById('base_url').value + 'search-destinations/';
	if(el.checked == true)
		tempAction = "add";
	else
		tempAction = "remove";
	
	rLoading = $.ajax({
		  url: the_url,
		  global: false,
		  type: "POST",
		  data: (
			{
				item : value,
				action : tempAction
			}
		  ),
		  dataType: "text",
		  async:false,
		  success: function(msg){
			window.location = the_url_r;
		  },
		  error: function(msg){
			window.location = the_url_r;
		  }
	   }
	)
}
function filterCities(el, value)
{
	var the_url = '';
	the_url = document.getElementById('base_url').value + 'filterCities/';
	the_url_r = document.getElementById('base_url').value + 'search-destinations/';
	if(el.checked == true)
		tempAction = "add";
	else
		tempAction = "remove";
	
	rLoading = $.ajax({
		  url: the_url,
		  global: false,
		  type: "POST",
		  data: (
			{
				item : value,
				action : tempAction
			}
		  ),
		  dataType: "text",
		  async:false,
		  success: function(msg){
			window.location = the_url_r;
		  },
		  error: function(msg){
			window.location = the_url_r;
		  }
	   }
	)
}
function filterTypes(el, value)
{
	var the_url = '';
	the_url = document.getElementById('base_url').value + 'filterTypes/';
	the_url_r = document.getElementById('base_url').value + 'search-destinations/';
	if(el.checked == true)
		tempAction = "add";
	else
		tempAction = "remove";
	
	rLoading = $.ajax({
		  url: the_url,
		  global: false,
		  type: "POST",
		  data: (
			{
				item : value,
				action : tempAction
			}
		  ),
		  dataType: "text",
		  async:false,
		  success: function(msg){
			window.location = the_url_r;
		  },
		  error: function(msg){
			window.location = the_url_r;
		  }
	   }
	)
}
function filterSwim(el, value)
{
	var the_url = '';
	the_url = document.getElementById('base_url').value + 'filterSwim/';
	the_url_r = document.getElementById('base_url').value + 'search-destinations/';
	if(el.checked == true)
		tempAction = "add";
	else
		tempAction = "remove";
	
	rLoading = $.ajax({
		  url: the_url,
		  global: false,
		  type: "POST",
		  data: (
			{
				item : value,
				action : tempAction
			}
		  ),
		  dataType: "text",
		  async:false,
		  success: function(msg){
			window.location = the_url_r;
		  },
		  error: function(msg){
			window.location = the_url_r;
		  }
	   }
	)
}
function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}
function filterNameAccommodation(el)
{
	var the_url = '';
	the_url = document.getElementById('base_url').value + 'filterNameAccommodation/';
	the_url_r = document.getElementById('base_url').value + 'search-destinations/';
	
	/*if(trim(el.value) != "")
	{*/
		rLoading = $.ajax({
			  url: the_url,
			  global: false,
			  type: "POST",
			  data: (
				{
					item : "filterNameAccommodation",
					action : el.value
				}
			  ),
			  dataType: "text",
			  async:false,
			  success: function(msg){
				window.location = the_url_r;
			  },
			  error: function(msg){
				window.location = the_url_r;
			  }
		   }
		)
	//}
}
function checkSite(el)
{
	var tempA = el.options[el.selectedIndex].value.split("-");
	if(tempA[1])
		if(tempA[1] == 1 && tempA[1] != document.getElementById('current_site').value)
			window.location = 'http://www.kaapstadvakantiehuizen.nl/router/'+tempA[0]+'/';
		else if(tempA[1] == 0 && tempA[1] != document.getElementById('current_site').value)
			window.location = 'http://www.zuidafrikavakantiehuizen.nl/router/'+tempA[0]+'/';
}
function checkFullPay(el)
{
	if(el.checked == true)
	{
		document.getElementById('upfront').style.display = '';
	}
	else
	{
		document.getElementById('upfront').style.display = 'none';
	}
}
function startLoading(region, city)
{
	if(region == 1)
	{
		document.getElementById('loading-region').style.display = '';
	}
	if(city == 1)
	{
		document.getElementById('loading-city').style.display = '';
	}
}
