function setHandlingFee(fee) {

	var cardType = document.getElementById('CardType');
	var handling_fee = document.getElementById('handling_fee');
	
	switch ( cardType.value ) {
	
		case 'Visa Credit Card' :
		case 'MasterCard' :
		case 'Amex' :
			handling_fee.value = fee;
			break;
			
		default :
			handling_fee.value = 0;
			break;	
	
	}
	
	update_booking_cost();
	return true;

}

function validate_booking_form() {

	var party_size = document.getElementById('party_size');
	var checkbox_linenDouble = document.getElementById('checkbox_linenDouble');
	var checkbox_linenSingle = document.getElementById('checkbox_linenSingle');
	var checkbox_cot = document.getElementById('checkbox_cot');
	if ( document.getElementById('checkbox_towels') != undefined ) var checkbox_towels = document.getElementById('checkbox_towels');
	var checkbox_highChair = document.getElementById('checkbox_highChair');
	var FirstName = document.getElementById('FirstName');
	var LastName = document.getElementById('LastName');
	var Address = document.getElementById('Address');
	var PostCode = document.getElementById('PostCode');
	var CountryISO = document.getElementById('country');
	var Mobile = document.getElementById('Mobile');
	var Phone = document.getElementById('Phone');
	var PhoneAH = document.getElementById('PhoneAH');
	var EmailAddress = document.getElementById('EmailAddress');
	var book_ferry = document.getElementById('book_ferry');	

	var HolderName = document.getElementById('HolderName');
	var CardType = document.getElementById('CardType');
	var CardNumber = document.getElementById('Number');
	var CCVCode = document.getElementById('CCVCode');
	var StartDateMonth = document.getElementById('StartDateMonth');
	var StartDateYear = document.getElementById('StartDateYear');
	var ExpireDateMonth = document.getElementById('ExpireDateMonth');
	var ExpireDateYear = document.getElementById('ExpireDateYear');

	var terms = document.getElementById('terms');
	
	var error_message = '<p>Some of the information needed appears to be missing:</p><ul>';
	var errors = 0;
	var error_container = document.getElementById('error_container');
	error_container.innerHTML = '';
	
	
	if ( party_size.value == 0 ) {
		error_message += '<li>You have not selected the <a href="#party_size">number of people staying</a></li>';
		errors = 1;
	} else {
		var member_name_array = new Array();
		for ( var a = 0; a < party_size.value; a++ ) {
			eval("member_name_array[" + a + "] = document.getElementById('party_member_" + ( a + 1 ) + "').value");
		}	
		for ( var b = 0; b < member_name_array.length; b++ ) {
			if ( member_name_array[b] == '' ) {
				error_message += '<li>You have not entered the name for <a href="#party_member_' + ( b + 1 ) + '">person ' + ( b + 1 ) + '</a></li>';
				errors = 1;
			}
		}
	}
	
	
	if ( checkbox_linenDouble.checked && checkbox_linenDouble.disabled != true ) {
		var qty_linenDouble = document.getElementById('qty_linenDouble').value;
		if ( qty_linenDouble == '' || qty_linenDouble == '0' ) {
			error_message += '<li>You have select to hire <a href="#checkbox_linenDouble">Linen Double Bet Sets</a>, but have not entered <a href="#qty_linenDouble">a quantity</a></li>';
			errors = 1;
		}
	}

	if ( checkbox_linenSingle.checked && checkbox_linenSingle.disabled != true ) {
		var qty_linenSingle = document.getElementById('qty_linenSingle').value;
		if ( qty_linenSingle == '' || qty_linenSingle == '0' ) {
			error_message += '<li>You have select to hire <a href="#checkbox_linenSingle">Linen Single Bet Sets</a>, but have not entered <a href="#qty_linenSingle">a quantity</a></li>';
			errors = 1;
		}
	}	

	if ( checkbox_cot.checked && checkbox_cot.disabled != true ) {
		var qty_cot = document.getElementById('qty_cot').value;
		if ( qty_cot == '' || qty_cot == '0' ) {
			error_message += '<li>You have select to hire a <a href="#checkbox_cot">Cot / Cot Rail</a>, but have not entered <a href="#qty_cot">a quantity</a></li>';
			errors = 1;
		}
	}	
	
	if ( document.getElementById('checkbox_towels') != undefined ) {
		if ( checkbox_towels.checked && checkbox_towels.disabled != true ) {
			var qty_towels = document.getElementById('qty_towels').value;
			if ( qty_towels == '' || qty_towels == '0' ) {
				error_message += '<li>You have select to hire <a href="#checkbox_towels">Towels</a>, but have not entered <a href="#qty_towels">a quantity</a></li>';
				errors = 1;
			}
		}
	}

	if ( checkbox_highChair.checked && checkbox_highChair.disabled != true ) {
		var qty_highChair = document.getElementById('qty_highChair').value;
		if ( qty_highChair == '' || qty_highChair == '0' ) {
			error_message += '<li>You have select to hire <a href="#checkbox_highChair">High Chairs</a>, but have not entered <a href="#qty_highChairs">a quantity</a></li>';
			errors = 1;
		}
	}	
	
	
	if ( FirstName.value == '' ) {
		error_message += '<li>You have not entered the <a href="#FirstName">First Name</a> of the person making the booking</li>';
		errors = 1;
	}
	
	if ( LastName.value == '' ) {
		error_message += '<li>You have not entered the <a href="#LastName">Last Name</a> of the person making the booking</li>';
		errors = 1;
	}
	
	if ( Address.value == '' ) {
		error_message += '<li>You have not entered the <a href="#Address">Address</a> of the person making the booking</li>';
		errors = 1;
	}
	
	if ( PostCode.value == '' ) {
		error_message += '<li>You have not entered the <a href="#PostCode">Post Code</a> of the person making the booking</li>';
		errors = 1;
	}
	
	if ( CountryISO.value == '0' ) {
		error_message += '<li>You have not selected the <a href="#country">Country</a> of the person making the booking</li>';
		errors = 1;
	}
	
	if ( Mobile.value == '' && Phone.value == '' && PhoneAH.value == '' ) {
		error_message += '<li>You have not entered a phone number.  You must enter a <a href="#Mobile">Mobile</a>, <a href="#Phone">Day Time Phone Number</a> or an <a href="#PhoneAH">Evening Phone Number</a></li>';
		errors = 1;		
	}
	
	if ( EmailAddress.value == '' ) {
		error_message += '<li>You have not entered an <a href="#Email">Email Address</a> for the person booking</li>';
		errors = 1;
	}
	
	if ( EmailAddress.value != '' && ! (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(EmailAddress.value)) ) {
		error_message += '<li>The <a href="#Email">Email Address</a> you entered does not appear to be correct</li>';
		errors = 1;
	}
	
	
	if ( book_ferry.checked ) {
		var ferry_route = document.getElementById('ferry_route');
		var ferry_to_date = document.getElementById('ferry_to_date');
		var ferry_to_time = document.getElementById('ferry_to_time');
		var ferry_from_date = document.getElementById('ferry_from_date');
		var ferry_from_time = document.getElementById('ferry_from_time');
		if ( ferry_route.value == '' ) {
			error_message += '<li>You have not selected a <a href="#ferry_route">Ferry Route</a></li>';
			errors = 1;
		}
		if ( ferry_to_date.value == '' ) {
			error_message += '<li>You have not entered a <a href="#ferry_to_date">date for the Ferry to the Isle of Wight</a></li>';
			errors = 1;		
		}
		if ( ferry_to_time.value == '' ) {
			error_message += '<li>You have not entered a <a href="#ferry_to_time">time for the Ferry to the Isle of Wight</a></li>';
			errors = 1;		
		}
		if ( ferry_from_date.value == '' ) {
			error_message += '<li>You have not entered a <a href="#ferry_to_date">date for the Ferry from the Isle of Wight</a></li>';
			errors = 1;		
		}
		if ( ferry_from_time.value == '' ) {
			error_message += '<li>You have not entered a <a href="#ferry_to_time">time for the Ferry from the Isle of Wight</a></li>';
			errors = 1;		
		}	
	}
		
	if ( HolderName.value == '' ) {
		error_message += '<li>You have not entered the <a href="#HolderName">Card Holder\'s Name</a></li>';
		errors = 1;
	}
	if ( CardType.value == '' ) {
		error_message += '<li>You have not selected the <a href="#CardType">Card Type</a></li>';
		errors = 1;
	}
	if ( CardNumber.value == '' ) {
		error_message += '<li>You have not entered the <a href="#CardNumber">Card Number</a></li>';
		errors = 1;
	}
	if ( CCVCode.value == '' ) {
		error_message += '<li>You have not entered your card\'s <a href="#CCVCode">Security Code</a></li>';
		errors = 1;
	}
	if ( StartDateMonth.value == '' ) {
		error_message += '<li>You have not selected your card\'s <a href="#StartDateMonth">start month</a></li>';
		errors = 1;
	}
	if ( StartDateYear.value == '' ) {
		error_message += '<li>You have not selected your card\'s <a href="#StartDateYear">start year</a></li>';
		errors = 1;
	}
	if ( ExpireDateMonth.value == '' ) {
		error_message += '<li>You have not selected your card\'s <a href="#ExpireDateMonth">expiry month</a></li>';
		errors = 1;
	}
	if ( ExpireDateYear.value == '' ) {
		error_message += '<li>You have not selected your card\'s <a href="#ExpireDateYear">expiry year</a></li>';
		errors = 1;
	}
	
	if ( terms.checked == false ) {
		error_message += '<li>You have not agreed to our <a href="#terms">Terms &amp; Conditions</a></li>';
		errors = 1;
	}

	
	
	if ( errors == 1 ) {
		error_message += '</ul>';
		error_container.innerHTML = error_message;
		return false;
	} else {
		return true;
	}

}

function set_booking_options( opt ) {
	
	var required = document.getElementById('checkbox_' + opt);
	var cost = document.getElementById('cost_' + opt);
	var qty = document.getElementById('qty_' + opt);
	var total = document.getElementById('total_' + opt);
	var qty_container = document.getElementById('qty_' + opt + '_container');
	
	//	option is required
		if ( required.checked ) {
	
			show('qty_' + opt + '_container');
			qty.value = '';
			qty.focus();
			
	//	option not required
		} else {
		
			qty.value = 0;
			update_booking_cost();
			hide('qty_' + opt + '_container');


		}
	
}

function update_booking_cost() {
	
	var total_cost_field = document.getElementById('total_cost');
	var total_cost_container = document.getElementById('total_cost_container');
	var base_cost = document.getElementById('base_cost').value;
	var handling_fee = document.getElementById('handling_fee').value;
	
	var total_cost = base_cost;
	
	var doubleLinen = 0;
	var singleLinen = 0;
	var cot = 0;
	var towels = 0;
	var highChair = 0;
	var microwave = 0;
	var earlyCheckIn = 0;
	var dogs = 0;
	
	//	check for additional people cost
		var extra_people = 0;
		var park_id = document.getElementById('park_id').value;
		var accommodation_name = document.getElementById('accommodation_name').value;
		var party_size = document.getElementById('party_size').value;
		var duration = document.getElementById('duration').value;
		var additional_person_cost = document.getElementById('additional_person_cost').value;
		var additional_party_cost_container = document.getElementById('additional_party_cost_container');
		if ( party_size > 4 && ( park_id == '1' || ( park_id == '4' && accommodation_name.substring(0,22) == 'Rookley Bungalow 2 Bed' ) ) ) {
			var num_weeks = parseFloat(duration) / 7;
			extra_people = ( party_size - 4 ) * additional_person_cost * Math.ceil(num_weeks);
			additional_party_cost_container.innerHTML = '<strong>Charge for additional people: &pound;' + extra_people.toFixed(2) + '</strong>';
		} else {
			extra_people = 0;
			additional_party_cost_container.innerHTML = '';
		}
		
	//	dogs
		if ( document.getElementById('checkbox_dogs') != null ) {
			var qty_dogs = document.getElementById('qty_dogs').value;
			if ( qty_dogs == '' ) qty_dogs = 0;
			var cost_dogs = document.getElementById('cost_dogs').value;
			dogs = parseInt(qty_dogs) * parseInt(cost_dogs);
		}
		
	//	double linen
		var qty_linenDouble = document.getElementById('qty_linenDouble').value;
		if ( qty_linenDouble == '' ) qty_linenDouble = 0;
		var cost_linenDouble = document.getElementById('cost_linenDouble').value;
		doubleLinen = parseInt(qty_linenDouble) * parseInt(cost_linenDouble);
		
	//	single linen
		var qty_linenSingle = document.getElementById('qty_linenSingle').value;
		if ( qty_linenSingle == '' ) qty_linenSingle = 0;
		var cost_linenSingle = document.getElementById('cost_linenSingle').value;
		singleLinen = parseInt(qty_linenSingle) * parseInt(cost_linenSingle);
	
	//	cost
		var qty_cot = document.getElementById('qty_cot').value;
		if ( qty_cot == '' ) qty_cot = 0;
		var cost_cot = document.getElementById('cost_cot').value;
		cot = parseInt(qty_cot) * parseInt(cost_cot);
	
	//	towels
		if ( document.getElementById('checkbox_towels') != null ) {
			var qty_towels = document.getElementById('qty_towels').value;
			if ( qty_towels == '' ) qty_towels = 0;
			var cost_towels = document.getElementById('cost_towels').value;
			towels = parseInt(qty_towels) * parseInt(cost_towels);
		}
	
	//	high chair
		var qty_highChair = document.getElementById('qty_highChair').value;
		if ( qty_highChair == '' ) qty_highChair = 0;
		var cost_highChair = document.getElementById('cost_highChair').value;
		highChair = parseInt(qty_highChair) * parseInt(cost_highChair);
	
	//	microwave
		if ( document.getElementById('checkbox_microwave').checked ) {
			var cost_microwave = document.getElementById('cost_microwave').value;
			microwave = parseInt(cost_microwave);
		}
	
	//	early checkin
		if ( document.getElementById('checkbox_earlyCheckIn') != null && document.getElementById('checkbox_earlyCheckIn').checked ) {
			var cost_earlyCheckIn = document.getElementById('cost_earlyCheckIn').value;
			earlyCheckIn = parseInt(cost_earlyCheckIn);
		}
	
		total_cost = parseFloat(handling_fee) + parseFloat(extra_people) + parseFloat(base_cost) + parseFloat(dogs) + parseFloat(doubleLinen) + parseFloat(singleLinen) + parseFloat(cot) + parseFloat(towels) + parseFloat(highChair) + parseFloat(microwave) + parseFloat(earlyCheckIn);
		
		total_cost_field.value = total_cost;
		
		
		if ( isNaN(total_cost) ) {
			total_cost_container.innerHTML = '&hellip;calculating';
		} else {
			total_cost_container.innerHTML = 'Total Cost: &pound;' + total_cost.toFixed(2);
		} 

		
		var payment_amount_total = document.getElementById('payment_amount_total');
		var payment_amount_total_label = document.getElementById('payment_amount_total_label');
		
		var payment_amount_deposit = document.getElementById('payment_amount_deposit');
		var payment_amount_deposit_label = document.getElementById('payment_amount_deposit_label');
		
		payment_amount_total.value = total_cost.toFixed(2);
		payment_amount_total_label.innerHTML = 'Total payable of &pound;' + total_cost.toFixed(2);	

		var base_deposit_amount = document.getElementById('base_deposit_amount');
		var deposit_amount = parseFloat(base_deposit_amount.value) + parseFloat(handling_fee);
		
		payment_amount_deposit_label.innerHTML = 'Deposit of &pound;' + deposit_amount.toFixed(2);
		payment_amount_deposit.value = deposit_amount;
		
		var remaining_balance_amount = document.getElementById('remaining_balance_amount');
		var remaining_balance = total_cost.toFixed(2) - deposit_amount; 
		remaining_balance_amount.innerHTML = remaining_balance.toFixed(2);

		var remaining_balance_field = document.getElementById('remaining_balance');
		remaining_balance_field.value = remaining_balance;

		var remainder_container = document.getElementById('remainder_container');
		if ( payment_amount_deposit.checked ) {
			remainder_container.style.display = '';
		} else {
			remainder_container.style.display = 'none';
		}



}

function draw_members_table(size, park_id, accommodation_name) {
		xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				document.getElementById('party_members_container').innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET","party_members.php?size=" + size + "&park_id=" + park_id + "&name=" + accommodation_name,true);
		xmlHttp.send(null);
}

function focus_start_date() {
	
	var sd = document.getElementById('check_start_date');
	if ( sd.value == 'dd-mm-yyyy' ) sd.value = '';
	return true;
	
}

function blur_start_date() {

	var sd = document.getElementById('check_start_date');
	if ( sd.value == '' ) sd.value = 'dd-mm-yyyy';
	return true;

}

function update_duration() {

	var hsStart = document.getElementById('highSeasonStart').value;
	var hsEnd = document.getElementById('highSeasonEnd').value;
	
	

	var start_date = document.getElementById('check_start_date');
	if ( start_date.value == 'dd-mm-yyyy' ) {
		alert("You have not entered a date.\nDates must be dd-mm-yyyy");
		return false;
	}
	var start_date_array = start_date.value.split('-');
	
	if ( ! isValidDate(start_date_array[0],(start_date_array[1]-1),start_date_array[2]) ) {
		alert("The date you entered is not valid.\nDates must be dd-mm-yyyy");
		return false;
	}

	var entered_date = new Date(start_date_array[2],(start_date_array[1]-1),start_date_array[0]);
	var entered_day = entered_date.getDay();
	
	var duration = document.getElementById('duration');
	duration.options.length = 1;
	
	switch ( entered_day ) {
		
		//	monday
		case 1:
			duration.options[1] = new Option("4 nights", "4", false, false);
			break;
			
		//	friday
		case 5:
			duration.options[1] = new Option("3 nights", "3", false, false);
			break;
			
		//	saturday
		case 6:
			duration.options[1] = new Option("7 nights", "7", false, false);
			duration.options[2] = new Option("2 Weeks", "14", false, false);
			duration.options[3] = new Option("3 Weeks", "21", false, false);
			duration.options[4] = new Option("4 Weeks", "28", false, false);
			break;
	
		default :
			alert('You can only arrive on Monday, Friday or Saturday');
			return false;
	
	}
	
	
}


function validate_availability() {
	var start_date = document.getElementById('check_start_date');
	
	if ( start_date.value == 'dd-mm-yyyy' ) {
		alert("You have not entered a date.\nDates must be dd-mm-yyyy");
		return false;
	}

	
	var start_date_array = start_date.value.split('-');
	
	if ( ! isValidDate(start_date_array[0],(start_date_array[1]-1),start_date_array[2]) ) {
		alert("The date you entered is not valid.\nDates must be dd-mm-yyyy");
		return false;
	}
	
	var duration = document.getElementById('duration');
	if ( duration.value == '0' ) {
		alert( "You have not selected the duration of your stay" );
		return false;
	}
	
	return true;


}


function isValidDate(day,month,year){
/*
Purpose: return true if the date is valid, false otherwise

Arguments: day integer representing day of month
month integer representing month of year
year integer representing year

Variables: dteDate - date object

*/
var dteDate;

//set up a Date object based on the day, month and year arguments
//javascript months start at 0 (0-11 instead of 1-12)
dteDate=new Date(year,month,day);

/*
Javascript Dates are a little too forgiving and will change the date to a reasonable guess if it's invalid. We'll use this to our advantage by creating the date object and then comparing it to the details we put it. If the Date object is different, then it must have been an invalid date to start with...
*/

return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}


function validate_blog_comment() {
		
		var comment_content = document.getElementById('comment_content');
		var posted_by_name = document.getElementById('posted_by_name');
		var posted_by_email = document.getElementById('posted_by_email');
		var security_code = document.getElementById('security_code');
		
		var data = "comment_content=" + comment_content.value + "&posted_by_name=" + posted_by_name.value + "&posted_by_email=" + posted_by_email.value + "&security_code=" + security_code.value;

		var xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				if ( xmlHttp.responseText != '' ) {
					document.getElementById('error_container').innerHTML=xmlHttp.responseText;
					return false;
				} else {
					document.getElementById('comment_form').submit()
					return true;
				}
			}
		}
		xmlHttp.open("POST","blog_comment.php",true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.send(data);
		
}

function autofill_blog(el) {
	
	switch (el) {
	
		case 'identifier' :
		
			var sourceField = document.getElementById('title');
			var targetField = document.getElementById('identifier');
			var identifier = sourceField.value;
			identifier = identifier.toLowerCase();
			identifier = identifier.replace(/ /g, "-");
			identifier = identifier.replace(/\'/g, "");
			identifier = identifier.replace(/\"/g, "");
			identifier = identifier.replace(/@/g, "");
			identifier = identifier.replace(/~/g, "");
			identifier = identifier.replace(/--/g, "-");
			targetField.value = identifier;
			
			break;
			
		case 'author' :
		
			var targetField = document.getElementById('entry_author');
			targetField.value = 'Island View Holidays';
			break;
	
	}

	return true;

}

function add_new_category() {
	
	var tbody = document.getElementById('category_table').getElementsByTagName('tbody')[0];
	var num_rows = document.getElementById('category_table').getElementsByTagName('tbody').length;
	var row = document.createElement('tr');
	
	var desc = document.createElement('input');
	desc.type = 'text';
	desc.className = 'field_text_focus';
	desc.name = 'categories[]';
	
	var box = document.createElement('input');
	box.type = 'checkbox';
	box.name = 'box';
	box.checked = true;
	
	var desc_cell = document.createElement('td');
	desc_cell.style.paddingTop = "5px";
	desc_cell.style.paddingBottom = "5px";
	desc_cell.appendChild(desc);
	
	var box_cell = document.createElement('td');
	box_cell.style.paddingTop = "5px";
	desc_cell.style.paddingBottom = "5px";
	box_cell.appendChild(box);
	
	row.appendChild(box_cell);
	row.appendChild(desc_cell);
	
	tbody.appendChild(row);
	
	desc.focus();
	

}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

//	bookmark a page
	function bookmark_page( url, title ) {
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

//	limit number of characters in a textarea field
	function limit_characters( limit_field, limit_count_field, limit_num ) {
		var limit_field = document.getElementById(limit_field);
		var limit_count_field = document.getElementById(limit_count_field);
		if ( limit_field != undefined ) {
			if ( limit_field.value.length > limit_num ) {
				limit_field.value = limit_field.value.substring( 0, limit_num );
			} else {
				limit_count_field.innerHTML	= (limit_num - limit_field.value.length) + ' characters remaining';
			}		
		}	
	}


//	show events on the home page
		function show_events(type) {
			var type;
			var tab_summary = document.getElementById('tab_summary');
			var tab_water = document.getElementById('tab_water');
			var tab_ashore = document.getElementById('tab_ashore');
			var container_summary = document.getElementById('event_summary');
			var container_water = document.getElementById('event_water');
			var container_ashore = document.getElementById('event_ashore');
			switch ( type ) {
				case 'water' :
					tab_summary.className = 'off';
					tab_water.className = 'on';
					tab_ashore.className = 'off';
					container_summary.style.display = 'none';
					container_water.style.display = '';
					container_ashore.style.display = 'none';
					break;
				case 'ashore' :
					tab_summary.className = 'off';
					tab_water.className = 'off';
					tab_ashore.className = 'on';
					container_summary.style.display = 'none';
					container_water.style.display = 'none';
					container_ashore.style.display = '';
					break;
				default :
					tab_summary.className = 'on';
					tab_water.className = 'off';
					tab_ashore.className = 'off';
					container_summary.style.display = '';
					container_water.style.display = 'none';
					container_ashore.style.display = 'none';
					break;
					
			}
		}


//	when the search field gets the focus
	function search_focus() {
		var search = document.getElementById('q');
		if ( search.value == 'Search...' ) {
			search.value = '';
		} else {
			search.select();
		}
		search.className = 'field_search_focus';
	}
	
//	when the search field loses the focus
	function search_blur() {
		var search = document.getElementById('q');
		if ( search.value == '' ) {
			search.value = 'Search...';
		}
		search.className = 'field_search';
	}

// 	retrieve a url parameter
	function get_url_parameter( name ) {
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null ) {
			return "";
		} else {
			return results[1];
		}
	}

//	preload images
	function preload_images () {
		arImageSrc = new Array ();
		arImageList = new Array ();
		for (counter in arImageSrc) {
			arImageList[counter] = new Image();
			arImageList[counter].src = arImageSrc[counter];
		}
	}

//	convert date and time to unixtimestamp
	function date_to_unixtime(target_field, month_el, day_el, year_el, hour_el, minute_el) {
		var target = document.getElementById(target_field);
		var year = document.getElementById(year_el).value;
		var month = document.getElementById(month_el).value;
		var day = document.getElementById(day_el).value;
		var hour = document.getElementById(hour_el).value;
		var minute = document.getElementById(minute_el).value;
		var second = '01';
		
		var errors = 0;
		var error_message = 'The following elements appear to be missing or incorrect' + "\n";
		if ( year.length != 4 ) {
			error_message += ' - you must enter a 4 digit year' + "\n";
			errors = 1;
		}
		if ( month > 12 ) {
			error_message += ' - the month must be between 1 and 12' + "\n";
			errors = 1;
		}
		if ( day > 31 ) {
			error_message += ' - the day must be between 1 and 31' + "\n";
			errors = 1;
		}
		if ( hour > 24 ) {
			error_message += ' - the hour must be 24 hour (e.g. 13 = 1pm)' + "\n";
			errors = 1;
		}
		if ( minute > 59 ) {
			error_message += ' - the minutes must be between 0 and 59' + "\n";
			errors = 1;
		}
		if ( errors == 1 ) {
			alert( error_message );
		} else {
			var humDate = new Date(Date.UTC(year, (nozeros(month)-1), nozeros(day), nozeros(hour), nozeros(minute), nozeros(second))); 
			target.value = (humDate.getTime()/1000.0);
		}
	
	}

//	get the current page
	function get_current_page() {
		var fullpath = location.pathname;
		var patharray = fullpath.split('/');
		var folderposition = patharray.length - 1;
		var filename = patharray[folderposition];
		var filearray = filename.split('.');
		var nav = filearray[0];
		return nav;
	}

//	open external links in a new window - replaces target="_blank"
	function externalLinks () { 
		if ( ! document.getElementsByTagName ) return; 
		var anchors = document.getElementsByTagName("a"); 
		for ( var i=0; i < anchors.length; i++ ) { 
			var anchor = anchors[i]; 
			if ( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" ) anchor.target = "_blank"; 
		} 
	} 

//	add given page to favourites (bookmark)
	function setBookmark ( url, str ) {
		if ( str == '' ) str = url;
		if ( document.all ) window.external.AddFavorite( url, str );
		else alert( 'Sorry, this function only works in Internet Explorer.\n\nPlease press CTRL and D to add a bookmark to \n"' + str + '".' );
	}

//	toggle a given elements visibility
	function toggle (el) {
		if ( document.getElementById(el) == undefined ) return false;
		if ( document.getElementById(el).style.display == 'none' ) {
			document.getElementById(el).style.display = '';
		} else {
			document.getElementById(el).style.display = 'none';
		}
	}

//	show a given element
	function show (el) {
		if ( document.getElementById(el) != undefined ) document.getElementById(el).style.display = '';
	}

//	hide a given element
	function hide (el) {
		if ( document.getElementById(el) != undefined ) document.getElementById(el).style.display = 'none';
	}

//	manage the show/hide buttons
	function showhide( source_el, target_el ) {
		var source = document.getElementById(source_el);
		var target = document.getElementById(target_el);
		toggle(target_el);
		if ( target.style.display == 'none' ) {
			source.innerHTML = 'Show &darr;';
			source.className = 'showhide';
		} else {
			source.innerHTML = 'Hide &uarr;';
			source.className = 'hideshow';
		}
	}


//	activate the correct navigation
	function activate_nav() {
		var nav = get_current_page();
		if ( nav == '' ) {
			nav = 'index';
		}
		if ( nav == 'search' || nav == 'email' ) {
			nav = 'blank';
		}
		var parent_page = nav;
		switch ( parent_page ) {
		
			case 'google-map-hillgrove-field-lane' :
				parent_page = 'hillgrove-field-lane';
				break;

			case 'google-map-island-view-colwell-bay' :
				parent_page = 'island-view-colwell-bay';
				break;

			case 'google-map-rookley' :
				parent_page = 'rookley-country-park';
				break;

		
		}
		
		
		
		if ( document.getElementById('nav_' + parent_page) != undefined ) document.getElementById('nav_' + parent_page).className = 'active';


		var show_menu = '';
		switch ( nav ) {
		
			case 'holiday-locations' :
			case 'rookley-country-park' :
			case 'hillgrove-field-lane' :
			case 'membership_application' :
			case 'island-view-colwell-bay' :

			case 'google-map-hillgrove-field-lane' :
			case 'google-map-island-view-colwell-bay' :
			case 'google-map-rookley' :
			
				show_menu = 'holiday-locations';
				break;
				
			case 'holiday-accommodation' :
			case 'holiday-bungalows' :
			case 'holiday-caravans' :
				show_menu = 'holiday-accommodation';
				break;
				
		}
		if ( document.getElementById('sub_nav_'+show_menu) != undefined ) document.getElementById('sub_nav_'+show_menu).style.display = '';

		

	}

//	make a textarea grow
	function extend_textarea(el) {
		if ( document.getElementById(el) == undefined ) return false;
		var el = document.getElementById(el);
		if ( el.value.length > 150 ) {
			el.style.height = "200px";
		} else {
			el.style.height = "100px";
		}
	}

//	populate a business card
	function populate_business_card(card_id,card_type) {
		xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				document.getElementById('business_card_content').innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET","business_card.php?card_id=" + card_id + "&card_type=" + card_type,true);
		xmlHttp.send(null);
	}



//	initialise an httpRequest object
	function initiate_ajax() {
		var xmlHttp;
		try {

			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {

			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		return xmlHttp;
	}


//	perform the following functions when the page loads
	window.onload = function(e) {
		externalLinks();
		activate_nav();
		initiate_ajax();
	}
