var i=0;

function get_random_img() {
	// String before random number
	var imgPrefix = "<div class='img_mainpic'><img src='pics/safari_experience";
	// String after random number
	var imgSuffix = ".jpg' width='240' height='150' vspace='0'></div>";
	// Generate random integer between 0 and 9
	var ranNum = Math.round(Math.random() * 7) +1;
	// Build image name
	var imgName = imgPrefix + ranNum + imgSuffix;
	return imgName;
}

function slideshow(){
	myslide=document.getElementById('slide');
	myslide.setAttribute("src", "pics/slideshow"+i+".jpg");
	i++;
	if(i>3){
		i=0;
	}
}

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function FormValidator(theForm)
{

  if (theForm.realname.value == "")
  {
    alert("Please enter your first name.");
    theForm.realname.focus();
    return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Please enter your valid email address.");
    theForm.email.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.email.value))
  {
    alert("Please enter a complete email address\ni.e. yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }
   
  if (theForm.email.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }
  return (true);
}

function FormValidator1(theForm)
{

  if (theForm.recommend_realname.value == "")
  {
    alert("Please enter your first name.");
    theForm.recommend_realname.focus();
    return (false);
  }

  if (theForm.recommend_friends_name.value == "")
  {
    alert("Please enter your friend's name.");
    theForm.recommend_friends_name.focus();
    return (false);
  }

  if (theForm.recommend_email_friend.value == "")
  {
    alert("Please enter your friend's valid email address.");
    theForm.recommend_email_friend.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.recommend_email_friend.value))
  {
    alert("Please enter a complete email address\ni.e. yourname@yourdomain.com");
    theForm.recommend_email_friend.focus();
    return (false);
  }
   
  if (theForm.recommend_email_friend.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"email\" field.");
    theForm.recommend_email_friendfocus();
    return (false);
  }
  return (true);
}

function ValidateRecommend(form) {
	with (form) {
		if (!recommend_realname.value || !recommend_friend_name.value || !recommend_friend_email.value) {
			alert("Please fill in all the fields");
			return false;
		} else {
			// validate e-mail address
			with (recommend_friend_email) {
				apos = value.indexOf("@"); 
				dotpos = value.lastIndexOf(".");
				lastpos = value.length - 1;
				if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2) {
					alert("Your e-mail address does not appear to be valid.");
					return false;
				} else {
					return true;
				}
			}
		}
	}
}

function ValidateBooking(form) {
	with (form) {
		if (!firstname.value || !lastname.value || !email.value) {
			alert("Please fill in all the required fields");
			return false;
		} else {
			// validate e-mail address
			with (email) {
				apos = value.indexOf("@"); 
				dotpos = value.lastIndexOf(".");
				lastpos = value.length - 1;
				if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2) {
					alert("Your e-mail address does not appear to be valid.");
					return false;
				} else {
					return true;
				}
			}
		}
	}
}
function FormValidatorContact(theForm)
{
  if (theForm.email.value == "")
  {
    alert("Please enter your valid email address.");
    theForm.email.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.email.value))
  {
    alert("Please enter a complete email address\ni.e. yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }
   
  if (theForm.email.value != theForm.confirm_email.value)
  {
    alert("Please confirm your email address by entering it again in the Confirm Email field.");
    theForm.confirm_email.focus();
    return (false);
  }
  if (theForm.request.value == "")
  {
    alert("Please enter a request.");
    theForm.request.focus();
    return (false);
  }
  return (true);
}
