﻿// Denne skal kaldes "onload" på siden
function PN1_PopUp_Init(){
  try {
    PN1_addPopUp(8, 1024, 768, 'https://fronter.com/vucsv/', 'resizable=yes,scrollbars=yes,toolbar=yes,status=yes,location=yes,titlebar=yes,menubar=yes');
    PN1_addPopUp(65, 1024, 768, 'http://vuc.holstebro-vuc.dk/', 'resizable=yes,scrollbars=yes,toolbar=yes,status=yes,location=yes,titlebar=yes,menubar=yes');
// Denne SKAL kaldes når man har tilføjet sine popUp's vha "PN1_addPopUp(..)"
    PN1_installPopUp();
  } catch(e) {
    alert(e.description); 
  }
}

/*******************************************************  
    PN1_PopUp.js
    Version 1.0
    Programm?r: Sten Hougaard sh@pn1.dk

    Anvendelse:
    Giver mulighed for at f? en DW menu til at ?bne en side i et vindue.

    Hvordan:
    - I body.onload inds?ttes kode der tilf?jer pop-up til et side id.
      EKSEMPEL: 
      PN1_addPopUp(66);
      PN1_addPopUp(67, 309, 292, 'http://www.dr.dk');
      PN1_addPopUp(67, 309, 292, 'http://www.dr.dk', 'resizable=no,toolbar=yes,status=yes');

    - Man kalder PN1_installPopUp() n?r man har tilf?jet sine pop-up's

*********************************************************/

// Global intern variabel
var aPopUpSideId  = new Array();

/*  [] = default værdi.
    sId = side ie
    iWidth = bredde [315]
    iHeight = h?jde [256]
    sURL = URL på side som skal vises [den URL som man er på]
    sParams = Settings for nye vindue [resizable=no,toolbar=no,status=no]
*/ 
function PN1_addPopUp(sId, iWidth, iHeight, sURL, sParams) {
  iWidth = (iWidth) ? iWidth+6 : 315;
  iHeight = (iHeight) ? iHeight+6 : 256;
  sURL = (sURL) ? sURL : false;
  aPopUpSideId[aPopUpSideId.length] = new PN1_popUp(sId, iWidth, iHeight, sURL, sParams);
}
// Intern funktion
function PN1_popUp(sId, iWidth, iHeight, sURL, sParams) {
  this.id = sId;
  this.iWidth = (iWidth) ? iWidth+6 : 315;
  this.iHeight = (iHeight) ? iHeight+6 : 256;
  this.sURL = (sURL) ? sURL : getLocationRoot()+'?id='+this.id
  this.sParams = (sParams) ? sParams : '';
  return this
}
// Intern funktion
function PN1_installPopUp() 
{
  try {
    var sHref;
    var aLinks = document.getElementsByTagName('a');
    var aParams;
    for(var i=0; i<aLinks.length; i++) {
     sHref = aLinks[i].href+'';
     if (sHref.indexOf('?')>-1) {
       aParams = getParamsHashtable(sHref.substr(sHref.indexOf('?'), sHref.length));
       for(var iPopUpHandler=0; iPopUpHandler<aPopUpSideId .length; iPopUpHandler++) {
         if (aParams['ID']==aPopUpSideId [iPopUpHandler].id) {
          var sNewHref = 'javascript:void(window.open("'+aPopUpSideId[iPopUpHandler].sURL+'", "", "'+((aPopUpSideId[iPopUpHandler].sParams) ? aPopUpSideId[iPopUpHandler].sParams : 'resizable=no,toolbar=no,status=no')+',width='+aPopUpSideId[iPopUpHandler].iWidth+',height='+aPopUpSideId[iPopUpHandler].iHeight+'"))';
          aLinks[i].href = sNewHref;
         }
       }
     }
   }  

   // Og nu til "menu-links"
   // De har en attribut: onclick="doclck('/Default.aspx?ID=68')"
   var sOnclick;
   var aTrs = document.getElementsByTagName('tr');
   for(var i=0; i<aTrs.length; i++) {
     sOnclick = aTrs[i].onclick+'';
     
     if (sOnclick.indexOf('doclck(')>-1) {
     
       var iQuestion = sOnclick.indexOf('?');
       var iQuote = sOnclick.lastIndexOf("\"");
       iQuote = (iQuote<0) ? sOnclick.lastIndexOf("'") : iQuote;
       var sSearch = sOnclick.substr(iQuestion, iQuote-iQuestion);
       aParams = getParamsHashtable(sSearch);
       
       for(var iPopUpHandler=0; iPopUpHandler<aPopUpSideId .length; iPopUpHandler++) {
         if (aParams['ID']==aPopUpSideId [iPopUpHandler].id) {
          
          aTrs[i].onclick = '';
          aTrs[i].attachEvent('onclick', _openVideo);
          //addEvent(aTrs[i], 'click', _openVideo);    
          aTrs[i].firstChild.id = aTrs[i].id;
         }
       }
     }
   }
  } catch(e) {
    //alert('PN1_installPopUp: '+e.description);
  }
}

/* Retunerer en hash table der indeholder Name-Value v?rdier af
   querystringen p? siden, samt en numereret liste over Names
   i hashtablen.
   Eks: mypage.aspx?hello=world&goodbye=world 
   [0]=hello, [1]=goodbye, [hello]=world, [goodbye]=world
*/
function getParamsHashtable(sSearch) {
  try {
    sSearch = (sSearch) ? sSearch : document.location.search;
    sSearch = sSearch.substr(1, sSearch.length-1);
    var aTemp = sSearch.split('&');
    var aParams = new Array();
    for(var i=0; i<aTemp.length; i++) {
       var aNameValue = aTemp[i].split('=');
       aParams[i] = aNameValue[0];
       aParams[aNameValue[0]] = aNameValue[1];
    }
    return aParams
  } catch(e) {
    reportError('getParamsHashtable', e, arguments);
  }
}
function getLocationRoot() {
  var sLocation = document.location.toString()
  return sLocation.substr(0, sLocation.indexOf(document.location.pathname))
}
