var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;
var NS = (window.Event) ? 1 : 0;
var type = "ie"; //hold default browser id.
var defaultdesc = "Please move your mouse over a symbol to view its description.";

function checkKey(e) {
  var code = (NS) ? e.which : event.keyCode;
  if (code == "13"){
	return false; }
}
document.onkeypress = checkKey;

function setSrc(id, url) {
  if (NS4) {eval("document." + id + ".document." + id).src = url}
  else if (IE4) {eval("document.all." + id).src = url}
       else if (IE5 || N6) {document.getElementById(id).src = url};
}

function getObject(object) {
    if (document.getElementById && document.getElementById(object) != null){
        return document.getElementById(object);
	}else if (document.layers && document.layers[object] != null){
		return document.layers[object];
	}else if (document.all){
		return document.all[object];
	}
}

function showHide(object) {

    if (document.getElementById && document.getElementById(object) != null){
		if (document.getElementById(object).style.display == 'none'){
	        document.getElementById(object).style.display ='';
	    }else {
	        document.getElementById(object).style.display ='none';
	    }
	}else if (document.layers && document.layers[object] != null){
        if (document.layers[object].visibility == 'hidden'){
			document.layers[object].visibility = 'visible'
		}else {
			document.layers[object].visibility = 'hidden'
		}
	}else if (document.all){
		if (document.all[object].style.display == 'none'){
			document.all[object].style.display = '';
		}else {
			document.all[object].style.display = 'none';
		}
	}
}

function showHideByAction(object,Action) {
    if (document.getElementById && document.getElementById(object) != null){
	        document.getElementById(object).style.display = (Action == 'show') ? '' : 'none';
	}else if (document.layers && document.layers[object] != null){
			document.layers[object].visibility = (Action == 'show') ? 'visible' : 'hidden';
	}else if (document.all){
			document.all[object].style.display = (Action == 'show') ? '' : 'none';
	}
}

function showHideExt(object,img) {

    if (document.getElementById && document.getElementById(object) != null){
		if (document.getElementById(object).style.display == 'none'){
	        document.getElementById(object).style.display ='';
	        setSrc(img,"img/interior/prodselect_exp.gif");
	    }else {
	        document.getElementById(object).style.display ='none';
	        setSrc(img,"img/interior/prodselect_min.gif");
	    }
	}else if (document.layers && document.layers[object] != null){
        if (document.layers[object].visibility == 'hidden'){
			document.layers[object].visibility = 'visible'
	        setSrc(img,"img/interior/prodselect_exp.gif");
		}else {
			document.layers[object].visibility = 'hidden'
			setSrc(img,"img/interior/prodselect_min.gif");
		}
	}else if (document.all){
		if (document.all[object].style.display == 'none'){
			document.all[object].style.display = '';
	        setSrc(img,"img/interior/prodselect_exp.gif");
		}else {
			document.all[object].style.display = 'none';
			setSrc(img,"img/interior/prodselect_min.gif");
		}
	}
}

function ShowHideFerry(ddlRouteType)
{
	for (var i = 1 ; i < 5; i++)
		showHideByAction('divRoute' + i,'hide');

	showHideByAction('divImgRet','hide');
	showHideByAction('divImgMul','hide');
	showHideByAction('dv_hpa_engine_logos','hide');
	
	getObject('divOutTxt').innerText = 'Outward route';
	getObject('divRetTxt').innerText = 'Return route';
	
	switch (ddlRouteType)
	{
		case 'out':
			showHideByAction('divRoute1','show');
			showHideByAction('divImgRet','show');
			if (getObject('dv_hpa_engine_form_multiple') != null) 
				getObject('dv_hpa_engine_form_multiple').id = 'dv_hpa_engine_form';
				
			showHideByAction('dv_hpa_engine_logos','show');
			break;
		case 'ret':
			showHideByAction('divRoute1','show');
			showHideByAction('divRoute2','show');
			showHideByAction('divImgRet','show');
			if (getObject('dv_hpa_engine_form_multiple') != null) 
				getObject('dv_hpa_engine_form_multiple').id = 'dv_hpa_engine_form';
			showHideByAction('dv_hpa_engine_logos','show');
			break;				
		case 'mul':
			getObject('divOutTxt').innerText = 'Route A';
			getObject('divRetTxt').innerText = 'Route B';
			
			for (var i = 1 ; i < 5; i++)
				showHideByAction('divRoute' + i,'show');
			if (getObject('dv_hpa_engine_form') != null) 
				getObject('dv_hpa_engine_form').id = 'dv_hpa_engine_form_multiple';
			showHideByAction('divImgMul','show');

	}
}


function DoExpand(divt,divd)
{
	showHide(divd)
	showHide(divt)
}

function DoExpandExt(divt,divd,img)
{
	showHideExt(divt,img)
	showHide(divd)
}

function setDates(Type)
{
	
	var iDay   = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateDay').value;
	var iMonth = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateMonth').value;
	var iYear  = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateYear').value;
	var pType  = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'PolicyType').value

	if (pType == 3)
	{
		if (iDay == 1)	iDay = 32;
		
		if (iDay == 32 && iMonth == 1){ 
			iMonth = 12;
			iYear -= 1;
		}else if (iDay == 32){ 
			iMonth -= 1
		}
		if (iDay==32   && iMonth==2) iDay=29
		if ((iDay==32) && (iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11)) iDay=31
		
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateDay').value   = --iDay;
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateMonth').value = iMonth;
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateYear').value  = ++iYear;
	}

	if (pType == 1)
	{
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateDay').value   = ++iDay
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateMonth').value = iMonth;
		eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateYear').value  = iYear;
	}
}

function setDatesEVA(Type)
{
	
	var iDay   = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateDay').value;
	var iMonth = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateMonth').value;
	var iYear  = eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'StartDateYear').value;

	eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateDay').value   = ++iDay
	eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateMonth').value = iMonth;
	eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'EndDateYear').value  = iYear;
}

function ShowHideSelection(ddlCoverFor,Type)
{
	HideControls(Type);
	switch (ddlCoverFor)
	{
		case '5':
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'PolicyType').value = 1;
			eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Adults').value = 3;
			setDates(Type);
			break;
	}
}

function HideControls(Type)
{
	eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'Adults').value = 0;

}

function ResetSelection(Type)
{
	ShowHideSelection(eval('document.frmPageForm.cntrlInsSearch_ddl' + Type + 'CoverFor').value,Type)
}


function make_return(ouwardlist,returnlist){
	arr = ouwardlist.value.split(" - ");
	if (returnlist != null)
		returnlist.value = arr[1] + " - " + arr[0];
}

function make_return_nav(x){
	arr = x.Interior_engine1_ddlOutward1.value.split(" - ");
	if (x.Interior_engine1_ddlReturn1 != null)
		x.Interior_engine1_ddlReturn1.value = arr[1] + " - " + arr[0];
}

function checkoption(x,cntrl){
	 if (x.value  == -1)
		alert("No option selected from the list");
	else
		__doPostBack(cntrl,'')
}

function go_insurance(x)
{
	if(!x){
	x = document.frmPageForm
	}
	
	var cf = x.coverFor.value;
	var pt = x.policyType.value;
	var ar = x.area.value;
	window.open("http://www.cheap4travelcover.com/?CoverFor=" + cf + "&PolicyType=" + pt + "&Area=" + ar + "&r=171");
}

function flip(id,s,m){
	for(n=1;n<=m;n++){
		div=id+n
		if(document.getElementById(div)){
		n==s?sShow(div):sHide(div)
		}
	}

  }
  
function flipext(div)  
{
	sShow(div)
	sHide(div)
}

function flip(id,s,m){
	for(n=1;n<=m;n++){
		div=id+n
		div2='img'+n
		if(document.getElementById(div)){
			xImg = document.getElementById(div2)
			n==s?xImg.src='img/disney/accom_a2_minimise.gif':xImg.src='img/disney/accom_a2_expand.gif'
			n==s?sShow(div):sHide(div)
		}
	}

  }

 function imgflip(id,s,m){
	div2='img'+s
	xImg = document.getElementById(div2)
	xImg.src.indexOf('img/disney/accom_a2_expand.gif')>0?flip(id,s,m):flip(id,0,m)
 } 
  

function sShow(div){
if(document.getElementById){
obj=eval("document.getElementById('"+div+"')")
}
else if(document.all){
obj=eval("document.all."+div)
}
else if(document.layers){
obj=eval("document.layers['"+div+"']")
}

!document.layers?obj.style.display='block':obj.visibility='show'
}

function sHide(div){
if(document.getElementById){
obj=eval("document.getElementById('"+div+"')")
}
else if(document.all){
obj=eval("document.all."+div)
}
else if(document.layers){
obj=eval("document.layers['"+div+"']")
}
!document.layers?obj.style.display='none':obj.visibility='hidden'
  }

function doContinue(sValue)
{
	if (document.all != null)
	{
		gbIsIE = true;
		gDoc = document.all;
	}
	else
	{
		gbIsIE = false;
		gDoc = document;
	}
	
	if (gDoc.frmengine != null){
		gFrm = gDoc.frmengine;
		gFrm.action = 'ferry_accommodation_search.aspx?id=' + sValue;
		gFrm.method = 'post';
		gFrm.submit();
	}
}

var ShowPicture = new Array();
ShowPicture[1] = 'img/disney/pod1.gif';
ShowPicture[2] = 'img/disney/pod2.gif';

// Set the slideshow speed (in ms)
var SlideShowSpeed = 5000;
// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 10;

// Declare variables
var slide_current;
var slide_next = 1;
var slide_total = ShowPicture.length-1;

var preLoad = new Array();
for (slide_current = 1; slide_current < slide_total+1; slide_current++){
	preLoad[slide_current] = new Image();
	preLoad[slide_current].src = ShowPicture[slide_current];
}

function runSlideShow()
{
	if (document.all){
		document.images.slide.style.filter="blendTrans(duration=CrossFadeDuration)";
		document.images.slide.filters.blendTrans.Apply();
	}

	document.images.slide.src = preLoad[slide_next].src;
	if (preLoad[slide_next].src.indexOf("pod1.gif") > 0)
		changeLinkHref("hlink","ferry_accommodation.aspx","breakdown.aspx");
	else
		changeLinkHref("hlink","breakdown.aspx","ferry_accommodation.aspx");

	if (document.all){
		document.images.slide.filters.blendTrans.Play()
	}

	slide_next = slide_next + 1;

	if (slide_next > (slide_total)){
		slide_next=1
	}
	tss = setTimeout('runSlideShow()', SlideShowSpeed);
}

function findLinkByHref(href) {
  for (var i=0; i<document.links.length; i++) {
    if (document.links[i].href == href) return i;
  }
  return -1;
}

function changeLinkHref(id,newHref,oldHref) {
  if (document.links.length > 0) {
    if (document.getElementById) {
		if (document.getElementById(id) != null)
			document.getElementById(id).href = newHref;
    }
    else if (document.all) {
		if (document.all[id] != null)
			document.all[id].href = newHref;
    }
    else {
      var index = findLinkByHref(oldHref);
      if (index > -1)
		if (document.links[index] != null)
			document.links[index].href = newHref;
    }
  }
}

function showSym(desc) {
	getObject('symTxt').innerHTML = desc;
}

function hideSym() {
	getObject('symTxt').innerHTML = defaultdesc;
}

