<!-- Copyright Global Journeys Pty Ltd -->
var win = null;

// Navigation
$(document).ready(function(){
	
	$('#new_nav a.nav_roll').click(function(){ 
		div='#'+$(this).attr('id')+'_div';
		
		//if we dont have a div, return true so the nav link gets clicked instead
		if($(div).length == 0 ){
			return true;
		} 			
		
		//if current item is selected, we have to hide it
		if($(this).hasClass('nav_selected')){
			
			$(this).removeClass('nav_selected');
			$(div).fadeOut('slow');
			$('#menu').animate({height:'28px'},500 );
			$('#tag').animate({top:'255px'},500 );
		
		//otherwise it could be another item, swap our item for it	
		}else if($('.nav_selected').length !=0){
			other_id = '#'+$('.nav_selected').attr('id');
			
			$(other_id).removeClass('nav_selected');
			$(this).addClass('nav_selected');
			
	//		$(other_id+'_div').animate({height:$(div).attr('container-height')}, 500);
			$('#menu').animate({height:$(div).css('height')}, 500);	
			$('#tag').animate({top:(parseInt($(div).css('height').replace('px',''))+227)+'px'}, 500);	
			
			$(other_id+'_div').fadeOut('slow'); 
			$(div).fadeIn('slow');
			
		//otherwise nothing is selected	
		}else{				
			$(this).addClass('nav_selected');
			
			$(div).fadeIn('slow');
			$('#menu').animate({height:$(div).css('height')},500 ).fadeIn();			
			$('#tag').animate({top:(parseInt($(div).css('height').replace('px',''))+227)+'px'}, 500);
		}
		
		//always return false so that the link doesnt actually click
		return false; 
		
	});	
	
	//hover functionality currently not used
	$('.nav_left a').hover(function(){
		$(this).parents('div').prev('.info').html($(this).next('div').html());
	}, function(){
		$(this).parents('div').prev('.info').html(' ');
	});
	
	//closes div
	$('.close').click(function(){
		
		div = '#'+$(this).parents('.nav_div').attr('id');
		
		$(div.replace('_div','')).removeClass('nav_selected');
		$(div).fadeOut('slow');
		$('#menu').animate({height:'28px'},500 );
		
		return false;
	});
	
	//class implementation
	if($('.price_tab').length > 0){
		
		//river cruise dual-year pricing tab functions
		$('.price_tab').click(function(){
			id=$(this).attr('id').replace('price_tab_','');	
			
			$('.price_tab_div').each(function(){
				if($(this).attr('id') != 'prices_div_'+id){			
					$(this).hide();
				}		
				if($(this).hasClass('prices_div_'+id)){
					$(this).show();
				}
			});
			
			$('#prices_div_'+id).show();	
			$('.prices_selected').removeClass('prices_selected');	
			$(this).addClass('prices_selected');	
		});
		
		//set first price div as selected 
		$('.price_tab:first').addClass('prices_selected');
		$('.price_tab_div:first').show();
		
		id=$('.price_tab:first').attr('id').replace('price_tab_','');
		$('.prices_div_'+id).each(function(){$(this).show();});
		
		
	}else{
		
		$('.price_tab_div').each(function(){$(this).show();});
	}
	
	
	
	//river cruise dual - upgrade lists for different year booking form changes
	if($('#HiddenUpgrades').length >0){
		
		$('#TourDate').change(function(){
			year = $(this).val().split(' ')[2];		
			set_upgrade(year);
		});
	
		//initialise
		year = $('#TourDate').val().split(' ')[2];
		set_upgrade(year);
	}
});

//sets the upgrade when there is a hidden upgrade sorter
function set_upgrade(year){
	
	if($('#HiddenUpgrades optgroup').length >0){
		
		$('#Upgrades optgroup').each(function(){
				$(this).remove();
		});
		
		$('#HiddenUpgrades optgroup').each(function(){
			if($(this).hasClass('upgrade_option_year_'+year)) {
				$("#Upgrades").append($(this).clone());
			}
		});
		
	}else{	
		$('#Upgrades option').each(function(){
				$(this).remove();
		});
			
		$('#HiddenUpgrades option').each(function(){
			if($(this).hasClass('upgrade_option_year_'+year) && $('#Upgrades option[value='+$(this).attr('value')+']').length <1) {
				$("#Upgrades").append($(this).clone());
			}
		});
	}
}
	
<!-- Pop JS -->
$(document).ready(function() {
	if($("a.pop").length > 0){		
		$("a.pop").fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: false,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'		: 500,
			'overlayShow'			: true,
			'frameWidth'				: 425,
			'frameHeight'			: 555,
			'hideOnContentClick'	: false
		});
	}
	if($("a.specialSML").length > 0){		
		$("a.specialSML").fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: false,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'		: 500,
			'overlayShow'			: true,
			'frameWidth'				: 625,
			'frameHeight'			: 225,
			'hideOnContentClick'	: false
		});
	}
	if($("a.specialLRG").length > 0){		
		$("a.specialLRG").fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: false,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'		: 500,
			'overlayShow'			: true,
			'frameWidth'				: 625,
			'frameHeight'			: 325,
			'hideOnContentClick'	: false
		});
	}
});
<!-- End Pop JS -->

<!-- Form Checker -->
function checkCheckBox(f){
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	<!-- Dummy Field -->
	if (f.Field2.value != "") {
		return false;
	}

	if (f.Adults.value == "") {
		alert('Please ensure you have typed in how many adults are travelling.');
		f.Adults.focus();
		return false;
	}
	
	if (f.FirstName.value == "") {
		alert('Please ensure you have typed in your first name.');
		f.FirstName.focus();
		return false;
	}
	
	if (f.Surname.value == "") {
		alert('Please ensure you have typed in your last name.');
		f.Surname.focus();
		return false;
	}
	
	if (f.Address.value == "") {
		alert('Please ensure you have typed in your address.');
		f.Address.focus();
		return false;
	}

	if (f.Email.value == "") {
		alert('Please ensure you have typed in an email address.');
		f.Email.focus();
		return false;
	}

	if (filter.test(f.Email.value))
		testresults=true
	else {
		alert('Please ensure you have typed in your email address correctly.');
		f.Email.focus();
		return false;
	}

	if(f.Pax2DOB !=undefined){

	//added by Michael van den Hout, 10/08/2011
	//edited by Michael van den Hout, 29/11/2011 for child booking for DOB support
	if( f.Pax1FN.value !='' && ( f.Pax1DOB.value=='' ||  f.Pax1DOB.value=='DD/MM/YYYY') && ($('#Pax1_Child_DOB').length == 0 || $('#Pax1_Child_DOB').is(":visible"))){
		alert('Please enter a valid DOB for person #1');
		f.Pax1DOB.focus();
		return false;
	}
	
	if( f.Pax2FN.value !='' && ( f.Pax2DOB.value=='' ||  f.Pax2DOB.value=='DD/MM/YYYY') && ($('#Pax2_Child_DOB').length == 0 || $('#Pax2_Child_DOB').is(":visible"))){
		alert('Please enter a valid DOB for person #2');
		f.Pax2DOB.focus();
		return false;
	}
	
	if( f.Pax3FN.value !='' && ( f.Pax3DOB.value=='' ||  f.Pax3DOB.value=='DD/MM/YYYY') && ($('#Pax3_Child_DOB').length == 0 || $('#Pax3_Child_DOB').is(":visible"))){
		alert('Please enter a valid DOB for person #3');
		f.Pax3DOB.focus();
		return false;
	}
	
	if( f.Pax4FN.value !='' && ( f.Pax4DOB.value=='' ||  f.Pax4DOB.value=='DD/MM/YYYY') && ($('#Pax4_Child_DOB').length == 0 || $('#Pax4_Child_DOB').is(":visible"))){
		alert('Please enter a valid DOB for person #4');
		f.Pax4DOB.focus();
		return false;
	}
	
	if(f.Pax1DOB.value=='DD/MM/YYYY'){f.Pax1DOB.value='';}
	if(f.Pax2DOB.value=='DD/MM/YYYY'){f.Pax2DOB.value='';}
	if(f.Pax3DOB.value=='DD/MM/YYYY'){f.Pax3DOB.value='';}
	if(f.Pax4DOB.value=='DD/MM/YYYY'){f.Pax4DOB.value='';}	
	}

	if (f.Terms.checked == false) {
		alert('Please tick that you have read the Terms & Conditions to continue...');
		return false;
	}

}
<!-- End Form Checker -->

<!-- Shortlist -->
var arrRecords = new Array();

expireDate = new Date;
oldDate    = new Date;
expireDate.setDate(expireDate.getDate()+60);

function cookieVal(cookieName) 
{
	thisCookie = document.cookie.split("; ")
	for (i = 0; i < thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1];
		}
	}
	return null;
}

function loadCookie() 
{
	if(document.cookie != "") {
		retStr = cookieVal("Tours") ;
		// alert ("retStr=" + retStr );
		if (retStr != null) {
			arrRecords = retStr.split(",");
		}
    }
}

function addTour(id) 
{
	var i = 0;
	var recCount = getNumTours() ;
	var found = false;
	var rTour;
	// var newurl = document.location +'#Tour'+id;

	// check it is not already there
    for(i = 0; i < recCount; i++) {
		rTour = arrRecords[i];
		if (rTour == id) {
			found=true;
			break;
		}
	}

	if (found==false)
	{
		lastitem = arrRecords.length;
		arrRecords[lastitem] = id;
		
		document.cookie = "Tours="+arrRecords+";expires=" + expireDate.toGMTString()+"; path=/";
		// alert(newurl);
		// document.location.href=newurl;
		document.getElementById("Tour"+id).innerHTML = "<a href=\"/shortlist.php\" class=\"icons\" id=\"saveshortlist\"></a>";
		// location.reload();
	}
	 else
	 {
		alert('This tour has already been added to your saved tour list.');
	}
}

function getNumTours()
{
	if (arrRecords.length != "" ) 	{
		return arrRecords.length ;
	} else {
		return 0;
	}
}

function deleteTour(id, rl) 
{
	var arrTemp = new Array();
	var i = 0;
	var j = 0;
	var recCount = getNumTours() ;
	var rTour = null;

	if (recCount == 1)
	{
		nullStr = "";
		document.cookie = "Tours="+nullStr+";expires=" + oldDate.toGMTString()+"; path=/";
		//if (rl) {
			location.reload();
		//}
		return ;
	}

	// copy active array into temp array
	// skip the item to be deleted
    for (i = 0, j = 0; i < recCount; i++) {
		rTour = arrRecords[i];
		if (rTour != id) {
			arrTemp[j++] = arrRecords[i];
		} 
		//else 
		//{
		//	alert('found item to delete : ' + rTour);
		//}
	}

    arrRecords = arrTemp ;
	document.cookie = "Tours="+arrRecords+";expires=" + expireDate.toGMTString()+"; path=/";
	//if (rl) {
		location.reload();
	//}
}

function getTour(index)
{
	if (arrRecords.length != "" && index < arrRecords.length) 	{
		return arrRecords[index] ;
	} else {
		return 0;
	}
}

function delTours() {
	if (window.confirm('Are you sure you want to clear all your tours?')) {
		nullStr = "";
		document.cookie = "Tours="+nullStr+";expires=" + oldDate.toGMTString()+"; path=/";
		location.reload();
	}
}

function ClearTours() {
    document.write ('<a href="javascript:delTours();"><img src="/images/plus.png" width="21" height="21" border="0" align="left"></a>&nbsp;&nbsp;<a href="javascript:delTours();">Remove ALL Tours from your Shortlist</a>');
}			


loadCookie();
<!-- End Shortlist -->
