﻿/* This file contains javascript functions used by DF websites */

/*Switches home page active tab (ports or routes)*/
function switchToTab(tab)
	{
		var activeTab;
		var activeTabInner;
		var activeDiv;
		var inactiveTab;
		var inactiveTabInner;
		var inactiveDiv;
		
		if(tab=='popularLinks')
		{
			activeTab = 'popularLinksTab';
			activeTabInner = 'popularLinksTabInner';
			activeDiv = 'popularLinks';
			inactiveTab = 'popularPortsTab';
			inactiveTabInner = 'popularPortsTabInner';
			inactiveDiv = 'popularPorts';
		}
		else
		{
			activeTab = 'popularPortsTab';
			activeTabInner = 'popularPortsTabInner';
			activeDiv = 'popularPorts';
			inactiveTab = 'popularLinksTab';
			inactiveTabInner = 'popularLinksTabInner';
			inactiveDiv = 'popularLinks';
		}
		
		if(document.getElementById){
		var elementRef = document.getElementById(inactiveDiv);
		if((elementRef.style) && (elementRef.style.visibility!=null)){
		elementRef.style.visibility = 'hidden';
		elementRef.style.height = '0';
		}
		}
		
		if(document.getElementById){
		var elementRef = document.getElementById(inactiveTab);
		if((elementRef.style) && (elementRef.style.visibility!=null)){
		elementRef.style.borderBottom = 'solid 1px #aaa';
		}
		}
		
		if(document.getElementById){
		var elementRef = document.getElementById(inactiveTabInner);
		if((elementRef.style) && (elementRef.style.visibility!=null)){
		elementRef.style.backgroundImage = 'url(/image/gradient.gif)';
		elementRef.style.backgroundRepeat = 'repeat-x';
		elementRef.style.backgroundPosition = 'bottom';
		}
		}
		
		
		
		if(document.getElementById){
		var elementRef = document.getElementById(activeDiv);
		if((elementRef.style) && (elementRef.style.visibility!=null)){
		elementRef.style.visibility = 'visible';
		elementRef.style.height = '198px';
		}
		}
		
		if(document.getElementById){
		var elementRef = document.getElementById(activeTab);
		if((elementRef.style) && (elementRef.style.visibility!=null)){
		elementRef.style.borderBottom = 'solid 1px #fff';
		}
		}
		
		if(document.getElementById){
		var elementRef = document.getElementById(activeTabInner);
		if((elementRef.style) && (elementRef.style.visibility!=null)){
		elementRef.style.background = '#fff';
		}
		}
		
	}
	
/*Launches Affiliate Signup form*/
function openAffiliateSignupForm(partnerCode){
    var url = 'http://www.directferries.com/affiliate/sign_up.aspx?stdc=' + partnerCode
	window.open(url, 'AffiliateSignup', 'status=0, toolbar=0, location=0, menubar=0, resizable=0, scrollbars=0, height=750, width=600');
}

/*Used by FerryDealMain page*/
function offer_submit(x,is_return)
{
	if(is_return==1)
	{
		arr=x.hidRoute1.value.split("-");
		x.hidRoute2.value=arr[1]+"-"+arr[0];
	}
	else
	{
		x.hidRoute2.value='';
	}
	return true;
}

/*Used by RouteMain page to redirect to selected route*/
function doRedirect()
{
	var dropdown;
	dropdown = document.getElementById('ddlRoutes');
	var url;
	url = dropdown.value;
	if (url=="")
	{
		return false;
	}
	window.location.replace( url );
	return false;
}

function doRedirect(listId) {
    var dropdown;
    dropdown = document.getElementById(listId);
    var url;
    url = dropdown.value;
    if (url == "") {
        return false;
    }
    window.location.replace(url);
    return false;
}

/*Used by Footer control for home page footer*/
function CreateBookmarkLink() { 
title = "Direct Ferries";
url = location.href;
if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");	}
else if(window.external) { // IE Favorite
window.external.AddFavorite(url, title); }	
else if(window.opera && window.print) { // Opera Hotlist
return true; } }

/*Sets up years in accommodation wizard*/
function setupAccomDates() {
    var checkIn = new Date();
    checkIn.setDate(checkIn.getDate() + 7);
    var checkOut = new Date();
    checkOut.setDate(checkOut.getDate() + 9);
    
    var arrivalMonth = document.getElementById("arrivalMonth");
	dropDownYears(arrivalMonth);
    var arrivalDay = document.getElementById("arrivalDay");
    selectMonthAndDay(arrivalMonth, arrivalDay, checkIn);
	
	var departureMonth = document.getElementById("departureMonth");
	dropDownYears(departureMonth);
	var departureDay = document.getElementById("departureDay");
	selectMonthAndDay(departureMonth, departureDay, checkOut);
}

/*Adds the correct year to the months dropdown in the accommodation wizard*/
/*Ensures we always offer 1 year in the future*/
function dropDownYears(list) {
    var now = new Date();
    
    for (var i = 0; i < list.options.length; i++){
        if (now.getMonth() > list.options[i].value){
            list.options[i].text += " " + (now.getFullYear() + 1);
        }
        else{
            list.options[i].text += " " + now.getFullYear();
        }
    }		
}
 
/*Sets the month and day dropdowns in the accommodation wizard*/
function selectMonthAndDay(monthList, dayList, dateToSet){
    // Set the month / year dropdown
    for (var i = 0; i < monthList.options.length; i++)
    {
    	if (dateToSet.getMonth() == monthList.options[i].value) {
    	    monthList.options[i].selected = true;
    	}
    }
    // Set the day dropdown
    for (var i = 0; i < dayList.options.length; i++)
    {
    	if (dateToSet.getDate() == dayList.options[i].value) {
    	    dayList.options[i].selected = true;
    	}
    }
}

/*Checks that a phone number is available and hide the Call Us section if not*/
function checkPhoneNumber() {
    if (!has_phone_number()) {
        var p = document.getElementById("phone");
        if (p != null) {
            p.style.visiblity = 'hidden';
            p.style.display = 'none';
        }
    }
}

/*Ship Page Functions*/
/*Switch view to relevant tab*/
function switchToTabShip(tab) {
    var activeShipTab;
    var activeShipDiv;
    var inactiveShipDiv1;
    var inactiveShipDiv2;
    var inactiveShipDiv3;
    var inactiveShipTab1;
    var inactiveShipTab2;
    var inactiveShipTab3;
    if (tab == 'pictures') {
        activeShipTab = 'pictureTab';
        activeShipDiv = 'pictures';
        inactiveShipDiv1 = 'reviews';
        inactiveShipDiv2 = 'videos';
        inactiveShipDiv3 = 'reviews2';
        inactiveShipTab1 = 'reviewTab';
        inactiveShipTab2 = 'videoTab';
        inactiveShipTab3 = 'reviewTab2';
    }
    if (tab == 'videos') {
        activeShipTab = 'videoTab';
        activeShipDiv = 'videos';
        inactiveShipDiv1 = 'pictures';
        inactiveShipDiv2 = 'reviews';
        inactiveShipDiv3 = 'reviews2';
        inactiveShipTab1 = 'pictureTab';
        inactiveShipTab2 = 'reviewTab';
        inactiveShipTab3 = 'reviewTab2';
    }
    if (tab == 'reviews') {
        activeShipTab = 'reviewTab';
        activeShipDiv = 'reviews';
        inactiveShipDiv1 = 'pictures';
        inactiveShipDiv2 = 'videos';
        inactiveShipDiv3 = 'reviews2';
        inactiveShipTab1 = 'pictureTab';
        inactiveShipTab2 = 'videoTab';
        inactiveShipTab3 = 'reviewTab2';
    }
    if (tab == 'reviews2') {
        activeShipTab = 'reviewTab2';
        activeShipDiv = 'reviews2';
        inactiveShipDiv1 = 'pictures';
        inactiveShipDiv2 = 'videos';
        inactiveShipDiv3 = 'reviews';
        inactiveShipTab1 = 'pictureTab';
        inactiveShipTab2 = 'videoTab';
        inactiveShipTab3 = 'reviewTab';
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(inactiveShipDiv1);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'inactive'
        }
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(inactiveShipDiv2);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'inactive'
        }
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(inactiveShipDiv3);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'inactive'
        }
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(inactiveShipTab1);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'zboxcontent inactivetab'
        }
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(inactiveShipTab2);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'zboxcontent inactivetab'
        }
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(inactiveShipTab3);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'zboxcontent inactivetab'
        }
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(activeShipDiv);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'zboxcontent active'
        }
    }
    if (document.getElementById) {
        var elementShipRef = document.getElementById(activeShipTab);
        if ((elementShipRef.style)) {
            elementShipRef.className = 'zboxcontent activetab'
        }
    }
}

/*Show relevant picture*/
function showPic(whichpic) {
    if (document.getElementById) {
        document.getElementById('placeholder').src = whichpic.href;
        return false;
    } else {
        return true;
    }
}
