// JavaScript Document
function check_chars() { 
	var str = window.document.contact_form.msg.value;
	var num = 0;
	
	if (str.length > 500) {
		window.document.contact_form.msg.value = str.substring(0,500);
	} else {		
		//document.getElementById("counter").innerHTML = 500 - window.document.contact_form.msg.value.length + " characters remaining.";
		num = 500 - window.document.contact_form.msg.value.length;
	}
	document.getElementById("counter").innerHTML = "You onlyl have " + num + " characters left.";
}

function check_chars2() { 
	var str = window.document.book_form.msg.value;
	var num = 0;
	
	if (str.length > 500) {
		window.document.book_form.msg.value = str.substring(0,500);
	} else {		
		//document.getElementById("counter").innerHTML = 500 - window.document.contact_form.msg.value.length + " characters remaining.";
	
		num = 500 - window.document.book_form.msg.value.length;
	}
	document.getElementById("counter").innerHTML = "You onlyl have " + num + " characters left.";	
}

	function trim(txt) {		
		tmp = (txt.replace(/^\W+/,'')).replace(/\W+$/,'');
		return tmp;
	}
	
	function doit() {
		var myname = window.document.contact_form.name.value;
		var myemail = window.document.contact_form.email.value;
		var msg = window.document.contact_form.msg.value;
		myname  = trim(myname);
		myemail = trim(myemail);
		msg = trim(msg);

		if ((myname.length > 0) && (msg.length > 0) && (myemail.length > 0)) {
			return true;
		} else {
			alert("Please enter all your details.");
			return false;
		}

		return false;
	}
	

function showPic(mypic)
{
	document.getElementById("bigpic").src = "images/gallery/" + mypic.id;
	
}


var xmlHttp;

function getPic(str)
{ 
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
  {
	  alert ("Your browser does not support AJAX!");
	  return;
  } 

//show loading gif
document.getElementById("picholder").innerHTML = "<div style='background: url(images/loading.gif) center no-repeat; width:400px; height:300px;' ></div>";
var url = "pages/ajax_getpic.php?fn=" + str.id;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("picholder").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function show(id) 
{
	document.getElementById(id).style.display = "block";
}

function hide(id) 
{
	document.getElementById(id).style.display = "none";
}

function check_book_form(form) {
		var myname = form.name.value;
		var myemail = form.email.value;
		var flight_no = form.flight_no.value;
		var date_arrive = form.date_arrive.value;
		var no_persons = form.no_persons.value;
		var no_days = form.no_days.value;
		myname  = trim(myname);
		myemail = trim(myemail);
		flight_no = trim(flight_no);
		date_arrive = trim(date_arrive);
		no_persons = trim(no_persons);
		no_days = trim(no_days);

		if (myemail.length == 0) {
			alert("Please enter your email address.");
			form.email.focus();
		} else if (myname.length == 0) {
			alert("Please enter you name.");
			form.name.focus();
		} else if (flight_no.length == 0) {
			alert("Please enter your flight no.");
			form.flight_no.focus();
		} else if (date_arrive.length == 0) {
			alert("Please indicate your date of arrival."); 
			form.date_arrive.focus();
		} else if (no_persons.length == 0) {
			alert("Please enter the number of persons for this booking.");
			form.no_persons.focus();
		} else if (no_days.length == 0) {
			alert("Kindly indicate the number of days you intend to stay.");
			form.no_days.focus();
		} else {
			return true;
		}

		return false;	
}
