﻿// Associação de Voo Livre da Madeira

var Categories = [];
for (i=0; i<4;i++) {
  Categories[i] = [];
  Categories[i][0] = i+1;
}
Categories[0][1] = "Files/System/AVLM/forum/Lazer.jpg";
Categories[1][1] = "Files/System/AVLM/forum/Competicao.jpg"
Categories[2][1] = "Files/System/AVLM/forum/Formacao.jpg";
Categories[3][1] = "Files/System/AVLM/forum/Outros.jpg";

function CheckField(TheField) {
  tempValue = document.getElementById(TheField).value;

  if (TheField == "q") {
    if (tempValue == "") {
      document.getElementById(TheField).value = "pesquisar";
    }
    else if (tempValue == "pesquisar") {
      document.getElementById(TheField).value = "";
    }
  }
  else if (TheField == "username") {
    if (tempValue == "") {
      document.getElementById(TheField).value = "utilizador";
    }
    else if (tempValue == "utilizador") {
      document.getElementById(TheField).value = "";
    }
  }
  else if (TheField == "password") {
    if (tempValue == "password") {
      document.getElementById(TheField).value = "";
    }
  }
}


// Funções Show/Hide
function My_ShowHide(PID){
  var MyLinkValue = "";
 
  MyLinkValue = document.getElementById('toggleLink' + PID).innerHTML;
  
  if(MyLinkValue == "[+]") {
    document.getElementById('toggleLink' + PID).innerHTML = "[-]";
  }
  else {
    document.getElementById('toggleLink' + PID).innerHTML = "[+]";
  }

  animatedcollapse.toggle('Show' + PID);
}
function My_Show(PID){
  document.getElementById('MyHideLink' + PID).style.display = "block";
  document.getElementById('toggleLink' + PID).style.display = "none";
  animatedcollapse.toggle('Show' + PID);
}
function My_Hide(PID){
  document.getElementById('MyHideLink' + PID).style.display = "none";
  document.getElementById('toggleLink' + PID).style.display = "block";
  animatedcollapse.toggle('Show' + PID);
}



function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ) {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}



/* PopUp Functions */
var originalDocumentWidth;

function showPopup(album) {
  // 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 PopUp URL  
  if (album != "") {
    album = "&amp;album=" + album;
  }
  PopUpURL = "http://www.voolivremadeira.com/Default.aspx?ID=79" + album;
  if (document.getElementById('Multimedia').src != PopUpURL) {
    document.getElementById('Multimedia').src = PopUpURL;
  }
  
 document.documentElement.scrollTop = 0;

  // Set visibility
  el.style.display = '';
  elContent.style.display = '';
  
  // Detect resizes
  window.onresize = setPopupDimensions;
  window.onscroll = setPopupDimensions;
}

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';
  el.style.height = document.body.clientHeight + 'px';
  el.style.top = 0;
  el.style.left = 0;
  
  // Set dimensions of content
  height = myInnerHeight - 30;
  width = myInnerWidth - 30;
  elContent.style.top =  '20px';   //(scrollY + myInnerHeight / 2 - height / 2 - 20 / 2) + 'px';
  elContent.style.left =  (myInnerWidth / 2 - 980 / 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;
}