
window.onload = function(){
	
	// preload images
	navImg = new Array("nav_home", "nav_travelling", "nav_competitions", "nav_community");
	
	imagesArray = new Array();
	n = 0;
	if (document.images) {
		for (i=0; i<navImg.length; i++) {
			img_off = document.images[navImg[i]].src;
			img_on = img_off.substring(0,img_off.length-4) + "-over.png";
			imagesArray[n] = new Image();
			imagesArray[n].src = img_off;
			imagesArray[n+1] = new Image();
			imagesArray[n+1].src = img_on; 
			n = n+2;
		}
	}
}

function mouseOut(imgID) {
	if (document.getElementById) {
		img_on = document.getElementById(imgID).src;
		document.getElementById(imgID).src = img_on.substring(0,img_on.length-9) + ".gif";
	}
}
function mouseOver(imgID) {
	if (document.getElementById) {	
		img_on = document.getElementById(imgID).src;
		document.getElementById(imgID).src = img_on.substring(0,img_on.length-4) + "-over.gif";
	}
}

function setHeroImg() {
	if (document.getElementById("heroImg")) {
		rnd = Math.ceil(Math.random()*6);
		document.getElementById("heroImg").src = "/images/topdeck/hero/hero" + rnd + ".jpg";
	}
}

// global timeout for hiding menus
var timeOut = 150;
// show/hide Tripfinder

var closeTrip;
var stopClose = false;

function toggleTripfinder() {
    
    //Detect IE5.5+
    //version=0
    //if (navigator.appVersion.indexOf("MSIE")!=-1)
    //{
    //    temp=navigator.appVersion.split("MSIE")
    //    version=parseFloat(temp[1])
    //}
    
    //if (version!=6) // hide tripfinder dropdown in IE 6
    //{
        var tripfinder = document.getElementById('tripfinder');
	    if ((tripfinder.style.display == '')|(tripfinder.style.display == 'none')) {	
		    clearTimeout(closeTrip);
		    showTripFinder();
	    } else {
		    closeTrip = setTimeout("hideTripFinder()", timeOut);
	    }
    //}
	
}

function stopHideTripFinder() {
	clearTimeout(closeTrip);
}

function reHideTripFinder() {
	closeTrip = setTimeout("hideTripFinder()", timeOut);
}

function showTripFinder() {
	document.getElementById('tripfinder').style.display = "block";
}

function hideTripFinder() {
	if (!stopClose) {
		document.getElementById('tripfinder').style.display = "none";
	}
}

function selectFocus() {
	stopClose = true;
}

function selectBlur() {
	stopClose = false;
}

// show/hide Trips popup

var closeTrips;

function toggleTrips() {
	var tripsr = document.getElementById('trips');
	if ((tripsr.style.display == '')|(tripsr.style.display == 'none')) {	
		clearTimeout(closeTrips);
		showTrips();
	} else {
		closeTrips = setTimeout("hideTrips()", timeOut);
	}
}

function stopHideTrips() {
	clearTimeout(closeTrips);
}

function reHideTrips() {
	closeTrips = setTimeout("hideTrips()", timeOut);
}

function showTrips() {
	document.getElementById('trips').style.display = "block";
}

function hideTrips() {
	document.getElementById('trips').style.display = "none";
}


// set duration
   
function TripFinderSplitDuration() {
  var strVal, arDuration;
  strVal = document.tripfinder.TourDuration.value;
  if (strVal.indexOf('-') > -1) {
    arDuration = strVal.split('-');
    document.tripfinder.DurationDaysMin.value = arDuration[0];
    document.tripfinder.DurationDaysMax.value = arDuration[1];
  } else {
    document.tripfinder.DurationDaysMin.value = 0;
    document.tripfinder.DurationDaysMax.value = 0;
  }
  //alert(document.tripfinder.DurationDaysMin.value + ',' + document.tripfinder.DurationDaysMax.value);
}

// set background image and text for images
function setBGImage(iPic, sDiv, sImg) {
	if (document.getElementById(sDiv)) {
		document.getElementById(sDiv).style.backgroundImage = "url(" + sImg + ")";
	}
	if (document.getElementById("pic" + iPic + "Title")) {
		document.getElementById("picTitle").innerHTML = document.getElementById("pic" + iPic + "Title").innerHTML;
	} else {
		document.getElementById("picTitle").innerHTML = "";
	}
	if (document.getElementById("pic" + iPic + "Summary")) {
		document.getElementById("picSummary").innerHTML = document.getElementById("pic" + iPic + "Summary").innerHTML;
	} else {
		document.getElementById("picSummary").innerHTML = "";
	}
}

// form sort & order for search results
function sortResults(objFrm) {
	if (objFrm.Direction[0].checked || objFrm.Direction[1].checked) {
		objFrm.submit();
	}
}

// subscribe form checker
function checkSubscribe(objFrm) {
	if (objFrm.FirstName.value == "") {
		if (objFrm.email.value == "") { 
			alert("To subscribe, please enter your name and email address.");
		} else {
			alert("To subscribe, please enter your name.");
		}
		return false;
	} else if (objFrm.email.value == "") { 
		alert("To subscribe, please enter your email address.");
		return false;
	} else {
		return true;
	}
}

// general functions
function openWindow(url, width, height)
{
	displayWindow = window.open(url,'displayWindow','toolbar=no,width=' + width + ',height=' + height + ',directories=no,status=yes,scrollbars=yes,resize=no,menubar=no');			

	if(displayWindow != null && displayWindow.opener == null)
	{
		displayWindow.opener = window;
	}
}

// show/hide Country list

function toggleCountryList(iNum) {
	var cl = document.getElementById('countryList' + iNum);
	if ((cl.style.display == '')|(cl.style.display == 'none')) {	
		cl.style.display = "block";
	} else {
		cl.style.display = "none";
	}
}

// search validation

function validateSearch()
{
	if (document.search.keyword.value.length < 2) {
		alert('Please enter a valid search term!');
		document.search.keyword.focus();
		return false;
	}
	else
	{
		return true;
	}
}
