﻿// Douro Azul - Javascript functions
function MoreCruises(ParagraphToShow, ParagraphToHide) {
  document.getElementById('Paragraph' + ParagraphToHide).style.display = "none";
  document.getElementById('Paragraph' + ParagraphToShow).style.display = "block";
}

function OverMainMenu(TheMenuItem) {
 document.getElementById(TheMenuItem).style.backgroundColor = "#000000";
}

function OutMainMenu(TheMenuItem) {
 document.getElementById(TheMenuItem).style.backgroundColor = "#6699CC";
}



// Ler parâmetros URL
function gup(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if(results==null)
    return "";
  else
    return results[1];
}



// Adicionar aos favoritos
function CreateBookmarkLink() {
  title = document.title + " - Douro Azul";
  url = window.location;

  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
    alert("Press CTRL + D, to add this page to your bookmarks!");
  }
}



/* PopUp Functions */
var originalDocumentWidth;

function showPopup(CruiseID,TheLanguage) {
  
  // Get source HTML structure
  var el = document.getElementById('popupMask');
  var elContent = document.getElementById('popupContent');
  
  // Store input dimensions
  originalDocumentWidth = document.documentElement.scrollWidth;
  
  // Set dimensions
  setPopupDimensions();
  
  // Set visibility
  el.style.display = '';
  elContent.style.display = '';
  
  // Detect resizes
  window.onresize = setPopupDimensions;
  window.onscroll = setPopupDimensions;

  document.getElementById('ReservasDouroAzul').src = "https://reservas.douroazul.pt/reservation1.aspx?Lang=lang" + TheLanguage + "&CruiseID=" + CruiseID;
}

function setPopupDimensions() {

  // Get source HTML structure
  var el = document.getElementById('popupMask');
  var elContent = document.getElementById('popupContent');
  
  // Get scroll position
  var scrollY = document.documentElement.scrollTop;
  var scrollX = document.documentElement.scrollLeft;
  
  // Get document dimensions
  var documentHeight = document.body.clientHeight > document.documentElement.clientHeight ? document.body.clientHeight : document.documentElement.clientHeight;
  var documentWidth = originalDocumentWidth < document.documentElement.scrollWidth ? originalDocumentWidth : document.documentElement.scrollWidth;
  
  // Get browser dimensions
  if(typeof(window.innerWidth) == 'number') {
    //Non-IE
    myInnerWidth = window.innerWidth;
    myInnerHeight = window.innerHeight;
  }
  else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    myInnerWidth = document.documentElement.clientWidth;
    myInnerHeight = document.documentElement.clientHeight;
  }
  else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    myInnerWidth = document.body.clientWidth;
    myInnerHeight = document.body.clientHeight;
  }
  
  if(documentWidth < myInnerWidth)
    documentWidth = myInnerWidth;
  
  // Set dimensions of background mask
  el.style.width = document.body.clientWidth + 'px';  //myInnerWidth + 'px';
  el.style.height = document.body.clientHeight + 'px';  //myInnerHeight + 'px';
  el.style.top = 0;
  el.style.left = 0;
  
  // Set dimensions of content
  height = myInnerHeight - 30;
  width = myInnerWidth - 30;
  elContent.style.top =  '10px';   //(scrollY + myInnerHeight / 2 - height / 2 - 20 / 2) + 'px';
  elContent.style.left =  (myInnerWidth / 2 - 710 / 2) + 'px';   //(scrollX + myInnerWidth / 2 - width / 2) + 'px';
}

function cancelPopup() {
  // Hide view
  document.getElementById('popupMask').style.display = 'none';
  document.getElementById('popupContent').style.display = 'none';
  
  // Don't handle resizes
  window.onresize = null;
  window.onscroll = null;
}