//upload images for animation
var aniframes = new Array(13);
for(var i = 0; i < 13; i++) {
	aniframes[i] = new Image();
	aniframes[i].src = "/BookingEngine/images/WaitScreen/cbeloading_" + i + ".gif";
}

var frame = 0;
var timeout_id = null;
var globalcounter = 0;
	
function PPO_Animate() {
	globalcounter = globalcounter + 1; 
	document.animation.src = aniframes[frame].src;
	frame = (frame + 1)%13;
	timeout_id = setTimeout("PPO_Animate()", 125);
}

function PPO_ShowAnimation() {
  scroll(0,0);
  document.getElementById("ppo_questions").style.display = "none";
	document.getElementById("ppo_Animation").style.display = "block";
  document.getElementById("ppo_boxsubmit").style.display = "none";
  PPO_Animate();
  $(".ppo_currencydiv").hide();
}

function DoMultiCurrency(defaultcurrency) {
	$("#ppo_AnimationText").html('Searching for Available Currencies...');	
    PPO_ShowAnimation();
    GetSailingList(defaultcurrency);
    return false;
}


function PPO_ClearRadioButtons(buttonGroup){ 
  var elems = document.getElementsByName(buttonGroup);
  for(i=0;i<elems.length;i++)
    elems[i].checked=false;
}; 

function PPO_ClearSelectBox(DropList){ 
  document.getElementById(DropList).selectedIndex = 0;
}; 

function PPO_ClearItem(item){ 
  document.getElementById(item).value = "";
}; 

function PPO_AutoSelectGender(droplist, radio){ 
  if (droplist.value == 'MR')
    //alert(document.getElementById('ppo_Title_' + PassengerNumber).selectedIndex);
    radio[0].checked = true;
  else
    //alert(document.getElementById('ppo_Title_' + PassengerNumber).value);
    radio[1].checked = true;
}; 

function PPO_ShowHide(Item, txtOn, txtOff) {
  //alert(document.getElementById(Item).style.display);
  if (document.getElementById(Item).style.display == "none" ) {
	  document.getElementById(Item).style.display = "block";
	  if (txtOff != undefined)
	    document.getElementById(Item + "_link").innerText = txtOff //"<< hide help";
  }
  else if (document.getElementById(Item).style.display == "block" ) {
	  document.getElementById(Item).style.display = "none";
	  if (txtOn != undefined)
  	  document.getElementById(Item + "_link").innerText = txtOn //"help with this >>";
  }
};

function PPO_ShowHideClear(objCheckBox, divSec, txtField) {
	// I don't think this is used.
  //alert(document.getElementById(divSec).style.display);
  //alert(divSec);
  
 	var statusCheckbox = document.getElementById(objCheckBox).checked;
  //alert(statusCheckbox);
  if (statusCheckbox == true) {
	  document.getElementById(divSec).style.display = "block";
  }
  else if (statusCheckbox == false) {
	  document.getElementById(divSec).style.display = "none";
	  PPO_ClearItem(txtField);
  }
};

function PPO_Show(Item, txtOn, txtOff) {
 document.getElementById(Item).style.display = "block";
 if (txtOff != undefined)
   document.getElementById(Item + "_link").innerText = txtOff
};

function PPO_Hide(Item, txtOn, txtOff) {
 document.getElementById(Item).style.display = "none";
 if (txtOff != undefined)
   document.getElementById(Item + "_link").innerText = txtOff
};

function PPO_ShowHideSection(MyId) {
  //alert(MyId);
	if ( document.getElementById(MyId).style.display == "block" ) {
		slideup(MyId);
		document.getElementById(MyId + 'text').innerHTML = "show this section <img src='/images/BookingEngine/show.gif' border='0'>";
		document.getElementById(MyId + 'backtotop').style.display = "none";
	}
	else {
		slidedown(MyId);
		document.getElementById(MyId + 'text').innerHTML = "hide this section <img src='/images/BookingEngine/hide.gif' border='0'>";
		document.getElementById(MyId + 'backtotop').style.display = "block";
	}
};

function PPO_ShowPaymentDivs() {
  document.getElementById("ppo_paymentaddressfields").style.display = "block";
  document.getElementById("ppo_creditcardfields").style.display = "block";
};

function PPO_HidePaymentDivs() {
  document.getElementById("ppo_paymentaddressfields").style.display = "none";
  document.getElementById("ppo_creditcardfields").style.display = "none";
};

function PPO_ShowDocumentDivs() {
	alert("show");
  document.getElementById("ppo_documentfields").style.display = "block";
};

function PPO_HideDocumentDivs() {
	alert("hide");
  document.getElementById("ppo_documentfields").style.display = "none";
};

function PPO_ShowHideFromCheckbox(DivID, objCheckBox) {
	var currentstatus = objCheckBox.checked;
	if ( currentstatus == true ) {
		document.getElementById(DivID).style.display = "block";
	}
	else {
		document.getElementById(DivID).style.display = "none";
	}
};

function PPO_ShowHidePamentFields(DivID, objCheckBox) {
	var currentstatus = objCheckBox.checked;
	if ( currentstatus == true ) {
		document.getElementById(DivID).style.display = "block";
	}
	else {
		document.getElementById(DivID).style.display = "none";
	}
};

function PPO_ExpandCheckboxOnOpen(DivID, CbID) {
    if (document.getElementById(CbID)) {
        var currentstatus = document.getElementById(CbID).checked;
        if (currentstatus == true) {
            document.getElementById(DivID).style.display = "block";
        }
        else {
            document.getElementById(DivID).style.display = "none";
        }
    }
};

function PPO_ShowHideCheckboxClear(objCheckBox, DivID, txtField) {
	var currentstatus = objCheckBox.checked;
	if ( currentstatus == true ) {
		document.getElementById(DivID).style.display = "block";
	}
	else {
		document.getElementById(DivID).style.display = "none";
	  //PPO_ClearItem(txtField);
	}
};


function PPO_ShowHideAirports(objCheckBox, DivID, DropList) {
	var currentstatus = objCheckBox.checked;
	if ( currentstatus == true ) {
		document.getElementById(DivID).style.display = "block";
	}
	else {
		document.getElementById(DivID).style.display = "none";
		//document.getElementById(DropList).selectedIndex = 0;
	}
}

function PPO_ClearFieldIfUnchecked(objCheckBox, item) {
	var currentstatus = objCheckBox.checked;
	if ( currentstatus == false ) {
	  document.getElementById(item).value = "";
	}
}

function PPO_SwapDecks(DeckDivNumber, NumDecks, DeckId)
{
	// DeckId isn't used for anything.  Just debug

	//document.getElementById("DeckImg").src = path;
	for(var i = 1; i <= NumDecks; i++) {
		document.getElementById("DeckPlanDiv" + i).style.display = "none";
	}
	document.getElementById("DeckPlanDiv" + DeckDivNumber).style.display = "block";
	
//	alert(path);
//	if(document.all){
//		document.getElementById('DeckDescription').innerText = DeckDescription;
//	} else{
//		document.getElementById('DeckDescription').textContent = DeckDescription;
//	}
}

function PPO_StateroomPopup(shipid, CabinCategoryCode) {
	var parameters = 'width=640,height=600,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'StateroomCategory_' + CabinCategoryCode.toString();
	var PageURL = 'StateroomPopup.asp?ShipId=' + shipid.toString() + '&CabinCategoryCode=' + CabinCategoryCode.toString()
	window.open(PageURL,window_name,parameters);
}

function PPO_PastPassengerPopup(PassengerFormNumber) {
	var parameters = 'width=400,height=320,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'PastPassenger_' + PassengerFormNumber.toString();
	var PageURL = 'PastPassengerPopup.asp?pfn=' + PassengerFormNumber.toString();
	window.open(PageURL,window_name,parameters);
}

function PPO_TermsPopup(CruiseLine) {
	var parameters = 'width=730,height=500,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'TermsAndConditions';
	var PageURL = 'TermsPopup.asp?cl=' + CruiseLine.toString();
	window.open(PageURL,window_name,parameters);
}

function PPO_AgeRestrictionsPopup(CruiseLine) {
	var parameters = 'width=730,height=500,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'AgeRestrictions';
	var PageURL = 'AgeRestrictionsPopup.asp?cl=' + CruiseLine.toString();
	window.open(PageURL,window_name,parameters);
}

function PPO_SubmitStep(stepform) {
  document.getElementById(stepform).submit();
}

function PPO_Breadcrumb(BreadCrumbLink) {
  var url = BreadCrumbLink
  document.location.href = url;
}

function PPO_SameDocsAddress() {
 	var statusCheckbox = document.getElementById("ppo_SameDocsAddressFlag").checked;

	if ( statusCheckbox == true ) {
    document.getElementById("ppo_DocumentsFullName").value = document.getElementById("ppo_CardFirstName").value + " " + document.getElementById("ppo_CardLastName").value;
    document.getElementById("ppo_DocumentsAddress1").value = document.getElementById("ppo_Address1").value;
    document.getElementById("ppo_DocumentsAddress2").value = document.getElementById("ppo_Address2").value;
    document.getElementById("ppo_DocumentsCity").value = document.getElementById("ppo_City").value;
    document.getElementById("ppo_DocumentsState").selectedIndex = document.getElementById("ppo_State").selectedIndex;
    document.getElementById("ppo_DocumentsPostalCode").value = document.getElementById("ppo_PostalCode").value;
    document.getElementById("ppo_DocumentsPhoneNumber").value = document.getElementById("ppo_PhoneNumber").value;
	}
};

function PPO_SameAirport() {
  document.getElementById("ppo_DepartureCity").selectedIndex = document.getElementById("ppo_CityOfResidence").selectedIndex;
};

function PPO_PopulateNewAccountPassword() {
 	var statusCheckbox = document.getElementById("ppo_SavePastPassengerFlag").checked;

	if ( statusCheckbox == true ) {
    document.getElementById("ppo_LoginEmail").value = document.getElementById("ppo_Email_0").value;
	}
};

function PPO_RequestPassword(EmailField) {
	if (EmailField == '') {
		alert('You must supply your email address to continue.');
	}
	else {
		var parameters = 'width=350,height=200,scrollbars=yes,resizable=yes,top=190,left=230,toolbar=no,menubar=no,status=no,location=no,directories=no';
		var PageURL = 'RequestPassword.asp?Email=' + EmailField;
		window.open(PageURL,'password_request',parameters);
	}
}

function PPO_PrintPage() {
  window.print();
}

function PPO_FareDescriptionPopup(TransactionID, BookingSessionID, CruiseFareCode) {
	var parameters = 'width=650,height=300,scrollbars=yes,resizable=yes,top=100,left=100,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'FareDescriptionPopup';
	var PageURL = 'FareDescriptionPopup.asp?TransactionID=' + TransactionID + '&BookingSessionID=' + BookingSessionID + '&CruiseFareCode=' + CruiseFareCode;
	window.open(PageURL,window_name,parameters);
}

function PPO_ProductDescriptionPopup(TransactionID, BookingSessionID, CruiseLineCode) {
	var parameters = 'width=650,height=500,scrollbars=yes,resizable=yes,top=100,left=100,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'ProductDescriptionPopup';
	var PageURL = 'ProductDescriptionPopup.asp?TransactionID=' + TransactionID + '&BookingSessionID=' + BookingSessionID + '&CruiseLineCode=' + CruiseLineCode;
	window.open(PageURL,window_name,parameters);
}

function PPO_PackageDescriptionPopup(TransactionID, BookingSessionID, PackageType, PackageCode, PreOrPost) {
	var parameters = 'width=650,height=300,scrollbars=yes,resizable=yes,top=100,left=100,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'PackageDescription' + PreOrPost;
	var PageURL = 'PackageDescriptionPopup.asp?TransactionID=' + TransactionID + '&BookingSessionID=' + BookingSessionID + '&PackageType=' + PackageType  + '&PackageCode=' + PackageCode+ '&PreOrPost=' + PreOrPost;
	window.open(PageURL,window_name,parameters);
}

function PPO_ViewSpecialPopup(AmenityID,PriceID) {
	var parameters = 'width=660,height=350,scrollbars=yes,resizable=yes,top=50,left=50,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'Special';
	var PageURL = '../../latesttraveloffers/ViewSpecialPopup.asp?AmenityID=' + AmenityID + '&PriceID=' + PriceID;
	window.open(PageURL,window_name,parameters);
}	

function PPO_ShowItineraryPopup(OfferId) {
	var parameters = 'width=680,height=450,scrollbars=yes,resizable=yes,top=100,left=100,toolbar=no,menubar=no,status=no,location=no,directories=no';
	var window_name = 'Itinerary';
	var PageURL = 'ItineraryPopup.asp?OfferId=' + OfferId
	window.open(PageURL,window_name,parameters);
}

// B2B Select Cat Scrolling
scrollStep=5
timerBoth=""

function PPO_ToLeft(id){
  document.getElementById(id).scrollLeft=0
}

function PPO_ScrollDivLeft(id){
  clearTimeout(timerBoth) 
  document.getElementById(id).scrollLeft+=scrollStep
  timerBoth=setTimeout("PPO_ScrollDivLeft('"+id+"')",5)
}

function PPO_ScrollDivRight(id){
  clearTimeout(timerBoth)
  document.getElementById(id).scrollLeft-=scrollStep
  timerBoth=setTimeout("PPO_ScrollDivRight('"+id+"')",5)
}

function PPO_ToRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}

function PPO_StopMe(){
  clearTimeout(timerBoth) 
  clearTimeout(timerBoth)
}
// End Scrolling

//B2B highlight payment choice
function PPO_ChangeHighlight(id)  
{ 
	document.getElementById(id).className = 'ppo_highlight';  
	var lastHighlight = document.getElementById('CurrentHighlightDiv').value;  
	if(lastHighlight != '')  
	{
		document.getElementById(lastHighlight).className = 'ppo_highlightoff';  
	}  
	document.getElementById("CurrentHighlightDiv").value = id;   
}  


// --------------------------------------------------------------------------------------------
//      2011-03-08 DK
//      Functions for showing / hiding closed and waitlisted categories
//
var bShowUnavailableCats = false;
var allUnavailableCats = new Array();
var UnavailableCatHeight = new Array();

function toggleUnavailableCats(){
    var args = new Array(1);
    var i = 0;
    var newHeight;
    var newRowHeight = 0;
    var sContainerID;
    var sID;

	for(i=0;i<=allUnavailableCats.length-1;i++){
	    args = allUnavailableCats[i].split(',');
	    sID = args[0];
	    sContainerID = args[1];
	    
	    newHeight = parseInt(document.getElementById(sContainerID).style.height);
        newRowHeight = parseInt(UnavailableCatHeight[i] + 10);
	    //document.getElementById(sID).style.height = '57px'; // the rollup animation needs an explicit target height.
	    
	    if(bShowUnavailableCats){
	        newHeight = parseInt(newHeight - newRowHeight)
		    slideup(sID);
	    }else{
	        newHeight = parseInt(newHeight + newRowHeight)
		    slidedown(sID);	    
	    }
	    document.getElementById(sContainerID).style.height = newHeight + 'px';
	}
	bShowUnavailableCats = !bShowUnavailableCats
}

function initUnavailableCats(sPath){
    var i = 0
    var sID
    var args = new Array(1)
    var xx = 0
    var yy = 0
    
    if(allUnavailableCats.length > 0){
        for(i=0;i<=allUnavailableCats.length-1;i++){
            args = allUnavailableCats[i].split(',');
            sID = args[0];
            sContainerID = args[1];
            
            UnavailableCatHeight[i] = parseInt(document.getElementById(sID).offsetHeight);
            document.getElementById(sID).style.height = parseInt(UnavailableCatHeight[i])+'px';
            //document.getElementById(sID).style.backgroundImage='url(images/overlay_red.png)';
            //document.getElementById(sID).style.backgroundRepeat='repeat-y';
            document.getElementById(sID).style.display='none';
            //document.getElementById(sID).disabled=true;
            document.getElementById(sID).className='ppo_catrowdisabled';
            document.getElementById(sID).style.backgroundColor='#f5f5f5';
            document.getElementById(sID+'_detlink').className='ppo_link_catrowdisabled';
            if(document.getElementById(sID+'_pricepointer')){
                document.getElementById(sID+'_pricepointer').style.backgroundImage='url('+sPath+'/BookingEngine/LowestCostPointer_disabled.gif)';
            }
            if(document.getElementById(sID+'_pricepointer_air')){
                document.getElementById(sID+'_pricepointer_air').style.backgroundImage='url('+sPath+'/BookingEngine/LowestCostPointer_disabled.gif)';
            }            
            if(document.getElementById(sContainerID).offsetHeight < 75){
                // Since this container is so small, is must be completely unavailable.
                // Show the "Cabin Type Unavailable" box.
                document.getElementById(sContainerID+'_unavailable').style.display='block';
            }
        }
    }else{
        // There are no unavailable cats to show, so we'll hide the checkbox.
        document.getElementById('UnavailableCatsCheckboxContainer').style.display='none';
    }
}

//---------------------------------------------------------------------------------------------


var oAjax = null;
var BookingSessionId = ""; // set from server code

function GetSailingList(defaultcurrency) {
    var querystring = "BookingSessionId=" + BookingSessionId + "&StepCode=AjaxGetCurrencyOptions"
    oAjax = $.ajax({
        type: "GET",
        url: "/BookingEngine/BookingStep.asp",
        data: querystring + "&t=" + Math.floor(Math.random() * 1000001),
        async: true,
        contentType: "application/json; charset=utf-8",
        dataType: "html",
        error: function(e, textStatus, errorThrown) {
            alert("AJAX ERROR: " + e.responseText);
            //alert("status: " + textStatus);
            //alert("error:" + errorThrown);
            $("#bookingform").submit();
        },
        success: function(msg) {
            $("#ppo_AnimationText").html('We are Searching for the Best Cruise Prices for You...');
            if (msg == "") {
                $("#bookingform").submit();
            }
            //else if (msg.length == 3) { // single currency pass thru
            //    $(".currencylist").append("<input type='hidden' name='currency' value='" + msg + "' />");
            //    $("#bookingform").submit();
            //}
            else if (msg.length == 3) { // single currency pass thru
                $(".currencylist").html("<input type='hidden' name='currency' value='" + msg + "' />");
                if (msg == defaultcurrency) {
                    $("#bookingform").submit();
                } else {
                    $(".currencytitle").html("<span class='ppo_title'>Currency Change</span><br/><br/>");
                    $(".currencylist").append("<br/><span>This cruise is only available for booking in the following currency:</span>");
                    $(".currencylist").append("<br/><ul><li><b>" + msg + "</b></li></ul>");
                    $(".currencylist").append("<span>Please click to continue booking in this currency.</span><br/><br/>");
                    $(".ppo_currencydiv").show();
                    $("#ppo_Animation").hide();
                }
            }
            else { // show currency options
                $(".currencytitle").html("<span class='ppo_title'>Please Select Your Desired Currency</span><br/><br/>");
                $(".currencylist").html("<span>This cruise is available to be booked in multiple currencies.  Please select the currency you would like to use:</span><br/>");
                var arr = msg.split(",");
                for (i = 0; i <= arr.length - 1; i++) {
                    if (arr[i] == defaultcurrency)
                        $(".currencylist").append("<br/><input type='radio' name='currency' checked='checked' value='" + arr[i] + "' /> Book using " + arr[i]);
                    else
                        $(".currencylist").append("<br/><input type='radio' name='currency' value='" + arr[i] + "' /> Book using " + arr[i]);
                }
                $(".ppo_currencydiv").show();
                $("#ppo_Animation").hide();
            }
        }
    });
}

