
function navigation() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navigation");

		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function showflash(){
	
	if (document.getElementById){
		if (isTransparentFlashSupported()){
			document.getElementById("flashbanner").className="show";
		}
		else{
			document.getElementById("flashbannerimage").className="show";
			document.getElementById("flashbannerimage").src='/images/image-holidays-in-pembrokeshire.jpg';
		}
	}
}

function isTransparentFlashSupported(){
	//if browser is IE 5.5 or Moz or greater then supported

	// convert all characters to lowercase to simplify testing
	var agt=navigator.userAgent.toLowerCase();


	// *** BROWSER VERSION ***
	// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	
	// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
	// If you want to allow spoofing, take out the tests for opera and webtv.
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	        && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
	        && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var is_nav2 = (is_nav && (is_major == 2));
	var is_nav3 = (is_nav && (is_major == 3));
	var is_nav4 = (is_nav && (is_major == 4));
	var is_nav4up = (is_nav && (is_major >= 4));
	var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
	                  (agt.indexOf("; nav") != -1)) );
	var is_nav6 = (is_nav && (is_major == 5));
	var is_nav6up = (is_nav && (is_major >= 5));
	var is_gecko = (agt.indexOf('gecko') != -1);

	//safari
	var is_safari = (agt.indexOf('safari') != -1);
	
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3    = (is_ie && (is_major < 4));
	var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	var is_ie4up  = (is_ie && (is_major >= 4));
	var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
	var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
	
	// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
	// or if this is the first browser window opened.  Thus the
	// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
	var is_aol   = (agt.indexOf("aol") != -1);
	var is_aol3  = (is_aol && is_ie3);
	var is_aol4  = (is_aol && is_ie4);
	var is_aol5  = (agt.indexOf("aol 5") != -1);
	var is_aol6  = (agt.indexOf("aol 6") != -1);
	
	var is_opera = (agt.indexOf("opera") != -1);
	var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
	var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
	var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
	var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
	var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

	if ((is_ie5_5up&&!is_opera&&!is_safari)||is_gecko&&!is_safari){
		return true;
	}
	return false;
	
}

//Date Functions
function populateDateControls(theForm){
	//populates the date dropdowns
	
	//do pitch dates
	var dtCurrentDate = new Date();
	dtCurrentDate = new Date(dtCurrentDate.getTime() + 7*24*60*60*1000);
	var iNumNights = 7;
	populateDaysControl(theForm.elements['quick-search-arrival-day'],dtCurrentDate);
	populateMonthsControl(theForm.elements['quick-search-arrival-month'],dtCurrentDate);
	populateYearsControl(theForm.elements['quick-search-arrival-year'],dtCurrentDate);
}


function populateDaysControl(theControl,selectedDate){
	var iNumDays = 31;
	var i;
	var iDay;
	theControl.options.length = iNumDays;
	for(i=0;i<iNumDays;i++){
		iDay = i+1;
		if (iDay<10){
			theControl.options[i].text = iDay;
			theControl.options[i].value = "0" + iDay;
		}
		else{
			theControl.options[i].text = iDay;
			theControl.options[i].value = iDay;		
		}
		if (i % 2==1) theControl.options[i].className ='alt';
	}
	theControl.options.selectedIndex = selectedDate.getDate(selectedDate)-1;
}

function populateMonthsControl(theControl,selectedDate){
	var iNumMonths = 12;
	var i;
	var imonth;
	theControl.options.length = iNumMonths;
	for(i=0;i<iNumMonths;i++){
		theControl.options[i].text = getShortMonthFromNumber(i);
		imonth = i+1;
		if (imonth<10){
			theControl.options[i].value = "0" + imonth;
		}
		else{
			theControl.options[i].value = imonth;
		}

		if (i % 2==1) theControl.options[i].className ='alt';
	}
	theControl.options.selectedIndex = selectedDate.getMonth();
}

function populateYearsControl(theControl,selectedDate){
	var iNumYears = 2;
	var i;
	theControl.options.length = iNumYears;
	for(i=0;i<iNumYears;i++){
		theControl.options[i].text = selectedDate.getFullYear()+i;
		theControl.options[i].value = selectedDate.getFullYear()+i;
		if (i % 2==1) theControl.options[i].className ='alt';
	}
	theControl.options.selectedIndex = 0;
}

function getShortMonthFromNumber(iMonthNumber){
	switch(iMonthNumber){
		case 0:
			return "Jan";
			break;
		case 1:
			return "Feb";
			break;
		case 2:
			return "Mar";
			break;
		case 3:
			return "Apr";
			break;
		case 4:
			return "May";
			break;
		case 5:
			return "Jun";
			break;
		case 6:
			return "Jul";
			break;
		case 7:
			return "Aug";
			break;
		case 8:
			return "Sep";
			break;
		case 9:
			return "Oct";
			break;
		case 10:
			return "Nov";
			break;
		case 11:
			return "Dec";
			break;
	}
	return "Month out of range 0-11";
}



function isValidDate(dateStr) {

	var now = new Date();

	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	// To require a 4 digit year entry, use this line instead:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[1]; // parse date into variables

	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false;
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
		}
	}
	var currentday = parseInt(now.getDate(),10);
	var currentmonth = parseInt(now.getMonth(),10)+1;
	var currentyear = parseInt(now.getFullYear(),10);
	
	year = parseInt(year,10);
	month = parseInt(month,10);
	day = parseInt(day,10);


	
	if (year<currentyear||(year==currentyear&&month<currentmonth)||(year==currentyear&&month==currentmonth&&day<currentday)){
		alert("Please choose a date in the future");
		return false;
	}

	return true;  // date is valid
}


function checkEmailForm(theform)   {
	email=theform.email.value;
	if (email==""||((email.indexOf("@") == -1)||email.indexOf(".") == -1)) { 
		alert("Your email address is either missing or in an invalid format...\n\nPlease try again"); 
		return false;			
		}
	else  { return true; }
	}

function checkPropertyRefForm(theform)   {
	if (theform.propertyref.value=="") { 
		alert("The Property Reference is missing...\n\nPlease try again"); 
		return false;			
		}
	else  { return true; }
	}
	
function checkQuickSearchForm(theform){
	//check date
	if(!isValidDate(theform.arrivalmonth.options[theform.arrivalmonth.options.selectedIndex].value + '/' + theform.arrivalday.options[theform.arrivalday.options.selectedIndex].value + '/' + theform.arrivalyear.options[theform.arrivalyear.options.selectedIndex].value)){
		alert("Please choose a valid date")
		return false;
	}
	
	//check future date
	
	return true;
	
}


function popup(URL,winwidth,winheight,scroll)  {
	nwinheight=Number(winheight);	
	day = new Date();
	id = day.getTime();
	pleft=(screen.width-winwidth)/2;
	ptop=(screen.height-nwinheight)/2;
	eval("page" + id + " = window.open('"+URL+"', '" + id + "', 'toolbar=0,scrollbars="+scroll+",location=0,statusbar=0,menubar=0,resizable=1,width="+winwidth+",height="+nwinheight+",left="+pleft+",top="+ptop+"');");
	}
	
// func to preset the a select box to the correct value
function setselectedvalue(elementname)  {
		var selindex;
		
		eval("selvalue=document.parameterlist."+elementname+".value;");
		eval("felement=document.quicksearch."+elementname+";");

		
		for (i=0;i<felement.length;i++)   {
			if (felement.options[i].value==selvalue){
				felement.selectedIndex=i;
				return;
			}
		}
	}

function presetSearchBoxes()  {
	var propertyref;
	if (location.href.indexOf('property-',1) > -1)  {
		// only execute this if the form 'parameterlist' exists, otherwise we be displaying a 'no-result' for a prop ref search
		if (document.parameterlist!=undefined)   {
			//propertyref=document.parameterlist.propertyref.value;
			//if (propertyref!="0") document.propertyrefform.propertyref.value=propertyref.toUpperCase();
			setselectedvalue("regioncode");
			setselectedvalue("partysize");
			setselectedvalue("numbedrooms");
			setselectedvalue("allowpets");
			setselectedvalue("arrivalday");
			setselectedvalue("arrivalmonth");
			setselectedvalue("arrivalyear");
			setselectedvalue("duration");
			}
		else   {
			document.propertyrefform.propertyref.value=document.proprefreturnform.propertyref.value;
		}
	}
	}


function showhidesb(show) {
	if (show){
		document.getElementById('sbchoices').className='sb-show';
	}
	else{
		document.getElementById('sbchoices').className='sb-hide';
	}
}



function addtoWishList(productid, returnURL)
{

if (returnURL == null){
    var sreturnURL = new String(window.location);
    //returnURL = returnURL.replace(/^(http¦ftp¦news)s?:\/+/i, '');
    var iSlashIndex = sreturnURL.indexOf("//");
    if (iSlashIndex != -1){
		sreturnURL = sreturnURL.substring(iSlashIndex +2);
    }
    
    returnURL = sreturnURL;
}

window.open( "http://www.fbmholidays.co.uk/add-to-shortlist.aspx?productid=" + productid + "&ururl=" + escape(returnURL), "addtoshortlist", "status = 1, height = 150, width = 300, resizable = 0" )

}

function safeParentWindowLocation(url, qsToEncode, closeSelf)
{
 self.opener.location = url + encodeURIComponent(qsToEncode);

if (closeSelf == 'true')
{
self.close();
}
}
