// JavaScript Document

function openmailfriend(mypage) 
	{
win = window.open(mypage,"blank","toolbar=yes, width=530, height=450");
win.window.focus();
}

function opentc(mypage)
	{
win = window.open(mypage,"blank","toolbar=yes, width=530, height=500");
win.window.focus();
}

function validate_mail_friend()
	{
errmsg = new Array();
	if (document.mail_friend.email.value == "")
		{
		errmsg.push("- Please indicate your email address.");
		}
	if (document.mail_friend.email.value != "")
		{
		i=document.mail_friend.email.value.indexOf("@");
	 	j=document.mail_friend.email.value.indexOf(".",i);
	 	k=document.mail_friend.email.value.indexOf(",");
	 	kk=document.mail_friend.email.value.indexOf(" ");
	 	jj=document.mail_friend.email.value.lastIndexOf(".")+1;
	 	len=document.mail_friend.email.value.length;
			if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) 
			{
 			}
 			else {
 			errmsg.push("- Please enter a valid email address.");
 				}
		}
	if (document.mail_friend.name.value == "")
		{
		errmsg.push("- Please enter your name");
		}
	if (document.mail_friend.email_friend.value == "")
		{
		errmsg.push("- Please indicate your friend's email address.");
		}
	if (document.mail_friend.email_friend.value != "")
		{
		i=document.mail_friend.email_friend.value.indexOf("@");
	 	j=document.mail_friend.email_friend.value.indexOf(".",i);
	 	k=document.mail_friend.email_friend.value.indexOf(",");
	 	kk=document.mail_friend.email_friend.value.indexOf(" ");
	 	jj=document.mail_friend.email_friend.value.lastIndexOf(".")+1;
	 	len=document.mail_friend.email_friend.value.length;
			if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) 
			{
 			}
 			else {
 			errmsg.push("- Please enter a valid address for your friend's email.");
 				}
		}
	if (document.mail_friend.name_friend.value == "")
		{
		errmsg.push("- Please enter your friend's name");
		}
	if (errmsg.length > 0) 
		{
		alert(("An error has been encountered:\n") + errmsg.join(",\n") + ("."));
		return false
		}
	else
		{
		return true;
		}
	}
	


function checkArrdate() {
var bookDay = document.bookingform.bookingdate.value.substr(0,2);
var bookMonth = document.bookingform.bookingdate.value.substr(3,2);
var bookYear = document.bookingform.bookingdate.value.substr(6,4);	
	if ((document.bookingform.month_Arr.value == 2)&&(document.bookingform.day_Arr.value > 29))
		{alert ("In February, there are only 28 or 29 days, please amend your selection");
		document.bookingform.day_Arr.focus();
		return false;
		}
	if ((document.bookingform.month_Arr.value == 4)&&(document.bookingform.day_Arr.value == 31))
		{alert ("In April, there are only 30 days, please amend your selection");
		document.bookingform.day_Arr.focus();
		return false;
		}
	if ((document.bookingform.month_Arr.value == 6)&&(document.bookingform.day_Arr.value == 31))
		{alert ("In June, there are only 30 days, please amend your selection");
		document.bookingform.day_Arr.focus();
		return false;
		}
	if ((document.bookingform.month_Arr.value == 9)&&(document.bookingform.day_Arr.value == 31))
		{alert ("In September, there are only 30 days, please amend your selection");
		document.bookingform.day_Arr.focus();
		return false;
		}
	if ((document.bookingform.month_Arr.value == 11)&&(document.bookingform.day_Arr.value == 31))
		{alert ("In November, there are only 30 days, please amend your selection");
		document.bookingform.day_Arr.focus();
		}
	if ((document.bookingform.year_Arr.value == bookYear)&&(document.bookingform.month_Arr.value < bookMonth))
		{alert ("This date is in the past, please amend your chosen date of travel");
		document.bookingform.day_Arr.focus();
		}
	if ((document.bookingform.year_Arr.value == bookYear)&&(document.bookingform.month_Arr.value == bookMonth)&&(document.bookingform.day_Arr.value < bookDay))
		{alert ("This date is in the past, please amend your chosen date of travel");
		document.bookingform.day_Arr.focus();
		}
	else
		{
		return true;
		}
}

function checkDepdate() {
var bookDay = document.bookingform.bookingdate.value.substr(0,2);
var bookMonth = document.bookingform.bookingdate.value.substr(3,2);
var bookYear = document.bookingform.bookingdate.value.substr(6,4);	

	if ((document.bookingform.month_Dep.value == 2)&&(document.bookingform.day_Dep.value > 29))
		{alert ("In February, there are only 28 or 29 days, please amend your selection");
		document.bookingform.day_Dep.focus();
		return false;
		}
	if ((document.bookingform.month_Dep.value == 4)&&(document.bookingform.day_Dep.value == 31))
		{alert ("In April, there are only 30 days, please amend your selection");
		document.bookingform.day_Dep.focus();
		return false;
		}
	if ((document.bookingform.month_Dep.value == 6)&&(document.bookingform.day_Dep.value == 31))
		{alert ("In June, there are only 30 days, please amend your selection");
		document.bookingform.day_Dep.focus();
		return false;
		}
	if ((document.bookingform.month_Dep.value == 9)&&(document.bookingform.day_Dep.value == 31))
		{alert ("In September, there are only 30 days, please amend your selection");
		document.bookingform.day_Dep.focus();
		return false;
		}
	if ((document.bookingform.month_Dep.value == 11)&&(document.bookingform.day_Dep.value == 31))
		{alert ("In November, there are only 30 days, please amend your selection");
		document.bookingform.day_Dep.focus();
		}
	if ((document.bookingform.year_Dep.value == bookYear)&&(document.bookingform.month_Dep.value < bookMonth))
		{alert ("This date is in the past, please amend your chosen date of travel");
		document.bookingform.day_Dep.focus();
		}
	if ((document.bookingform.year_Dep.value == bookYear)&&(document.bookingform.month_Dep.value == bookMonth)&&(document.bookingform.day_Dep.value < bookDay))
		{alert ("This date is in the past, please amend your chosen date of travel");
		document.bookingform.day_Dep.focus();
		}
	else
		{
		return true;
		}
}


function validate_contactform()
	{
errmsg = new Array();
	if (document.contactform.email.value == "")
		{
		errmsg.push("- please enter your email address");
		}
	if (document.contactform.email.value != "")
		{
		i=document.contactform.email.value.indexOf("@")
	 	j=document.contactform.email.value.indexOf(".",i)
	 	k=document.contactform.email.value.indexOf(",")
	 	kk=document.contactform.email.value.indexOf(" ")
	 	jj=document.contactform.email.value.lastIndexOf(".")+1
	 	len=document.contactform.email.value.length
			if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) 
			{
 			}
 			else {
 			errmsg.push("- please enter a valid email address");
 				}
		}
	
	if (document.contactform.name.value == "")
		{
		errmsg.push("- please enter your name");
		}
	if (document.contactform.phone.value == "")
		{
		errmsg.push("- please enter a phonenumber");
		}
	if (document.contactform.message.value == "")
		{
		errmsg.push("- please enter your message");
		}
	var iChars = "#%^*+=-[]\\\/{}|\<>";
	for (var i = 0; i < document.contactform.message.value.length; i++) 
		{
  		if (iChars.indexOf(document.contactform.message.value.charAt(i)) != -1) 
			{
  			errmsg.push("- Your message has some invalid characters (only letters and numbers, no signs allowed). Please review your message.");
			}
		}
	if (errmsg.length > 0) 
		{
		alert(("Your message can not be submitted:\n") + errmsg.join(",\n") + ("."));
	//	{
	//	alert(errmsg);
		return false
		}
	else
		{
		return true;
		}
	}/**/

function validate_bookingform()
	{
	errmsg = new Array();
	if (document.bookingform.surname.value == "")
		{
		errmsg.push("- please enter your surname");
		}
	if ((document.bookingform.address1.value == "") && (document.bookingform.address2.value == "") && (document.bookingform.address3.value == ""))
		{
		errmsg.push("- please enter the first part of your address");
		}
	if ((document.bookingform.postcode.value == "") && (document.bookingform.town.value == ""))
		{
		errmsg.push("- please enter your postcode and town");
		}
	if (document.bookingform.country.value == "")
		{
		errmsg.push("- please enter your country");
		}
	if (document.bookingform.phone.value == "")
		{
		errmsg.push("- please enter a phonenumber");
		}
	if (document.bookingform.email.value == "")
		{
		errmsg.push("- please enter your email address");
		}
	if (document.bookingform.email.value != "")
		{
		i=document.bookingform.email.value.indexOf("@")
	 	j=document.bookingform.email.value.indexOf(".",i)
	 	k=document.bookingform.email.value.indexOf(",")
	 	kk=document.bookingform.email.value.indexOf(" ")
	 	jj=document.bookingform.email.value.lastIndexOf(".")+1
	 	len=document.bookingform.email.value.length
			if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) 
			{
 			}
 			else {
 			errmsg.push("- please enter a valid email address");
 				}
		}
	if (document.bookingform.party.value == 0)
		{
		errmsg.push("- Please tell us how many adults are in your party");
		}
	if (document.bookingform.day_Arr.value == "dd")
      	{
		errmsg.push("- Please indicate your day of arrival");
		}
	if (document.bookingform.month_Arr.value == "mm")
      	{
		errmsg.push("- Please indicate your month of arrival");
		}
	if (document.bookingform.location.value== "choose")
      	{
		errmsg.push("- Please indicate your chosen location");
		}
	if (!document.bookingform.tc.checked)
      	{
		errmsg.push("- Please confirm that you have read and agree to Art of Your Travel terms and conditions");
		}
	var iChars = "#%^*+=-[]\\\/{}|\<>";
	var countIll = 0
	for (var i = 0; i < document.bookingform.comments.value.length; i++) 
		{
  		if ((iChars.indexOf(document.bookingform.comments.value.charAt(i)) != -1) && (countIll ==0))
			{
  			errmsg.push("- Your comments have some invalid characters (only letters and numbers, no signs allowed). Please review your comments text.");
			var countIll = countIll + 1;
			}
		}
	if (errmsg.length > 0) 
		{
		alert(("Your enquiry can not be submitted:\n") + errmsg.join(",\n") + ("."));
		return false;
		}
	else
		{
		return true;
		}
	}

function validate_shortform()
	{
	errmsg = new Array();
	if (document.bookingform.location.value == "choose")
		{
		errmsg.push("- please enter your preferred destination");
		}	
	if (document.bookingform.day_Arr.value == "dd")
      	{
		errmsg.push("- Please indicate your day of arrival");
		}
	if (document.bookingform.month_Arr.value == "mm")
      	{
		errmsg.push("- Please indicate your month of arrival");
		}
	if (document.bookingform.party.value == 0)
		{
		errmsg.push("- please enter the number of participants");
		}	
	if (document.bookingform.email.value == "")
      	{
		errmsg.push("- Please indicate your email address");
		}
	if (document.bookingform.email.value != "")
		{
		i=document.bookingform.email.value.indexOf("@")
	 	j=document.bookingform.email.value.indexOf(".",i)
	 	k=document.bookingform.email.value.indexOf(",")
	 	kk=document.bookingform.email.value.indexOf(" ")
	 	jj=document.bookingform.email.value.lastIndexOf(".")+1
	 	len=document.bookingform.email.value.length
			if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) 
			{
 			}
 			else {
 			errmsg.push("- please enter a valid email address");
			
 				}
		}
	if (errmsg.length > 0) 
		{
		alert(("Your enquiry can not be submitted:\n") + errmsg.join(",\n") + ("."));
		return false;
		}
	else
		{
		return true;
		}
	}