﻿/*
' **************************************************
' © VWA Software Development 2008
' Release: 1.01.0000
' Changed: Okt 15, 2008
' **************************************************
*/

var iVisitID          = 0;
var timer             = null;
var bEventBubbleFirst = true; // Om te controleren of het om het eerste event gaat, of een bubble up.
var Menu              = null; // Timer voor het verbergen van het menu

// Vertraging van de even gedult melding in ms.
var tHourGlassShow = 500;

/*----------------------------------------------------------------------------------
                              menu code 
-----------------------------------------------------------------------------------*/
var oMenu =  function(){
    this.ActiveRootMenuId   = null;  // Het ID van het active root menu
    this.ActiveButton       = null;  // de knop onder de muis. 
    this.ActiveMenuId       = null;  // Het menu onder de muis
    this.PreviousButton     = null;  // Laatst geselecteerde knop
    this.PreviousMenu       = null;  // Laatste geselecteerd menu
    this.FixedDisplay       = 0;     // Submenu blijvend tonen  0 = nee
                                     //                         1 = Knop in submenu geselecteerd
                                     //                         2 = Ouder knop geselecteerd
                                     
    this.HoverTime         = 2000;  // Vertraaging van verbergen submenuus
}

Menu = new oMenu();

// Set het actieve menu, wanneer de muis over het menu gaat.
function mnuRootOver(Sender){
    Menu.ActiveRootMenuId = Sender.id;    
    Menu.FixedDisplay = toNumber($get(Sender.id + 'FD').value);
    Menu.HoverTime = toNumber($get(Sender.id + 'HT').value);   
}

function OnEndRequest(){
    HourGlassHide();
    return true;
}

function onSubmit() {  
    HourGlassShow();
    return true;
}  


function Page_load(){
    var manager = Sys.WebForms.PageRequestManager.getInstance();
    
   // Controleren of het een asyncpostback is
   if (!manager.get_isInAsyncPostBack()){
       // End en Beginrequest handlers toevoegen
       manager.add_endRequest(OnEndRequest);
       manager._onsubmit = onSubmit;
    }
}
// Postback maken met juiste knop info!!
function MenuClick(Sender,iButtonID, sRwrPath ,e){
	
	if (!e) var e = window.event;
	if(e){	
	    if (e.cancelBubble || !e.cancelBubble)
	        e.cancelBubble = true;
	    if (e.stopPropagation)
	        e.stopPropagation();
	}
	if (sRwrPath && sRwrPath.length > 0) 
	    theForm.action = sRwrPath;
	else
	    theForm.action = '';
	
    $get("__NEWBID").value = iButtonID;
    __doPostBack("__VWAmenu", iButtonID);
    
    // False retouneren zodat click event op link niet geactiveerd wordt.
    return false;    
}

// Onmouseover handler
function buttonover(Sender){
    if(bEventBubbleFirst){
        // Aktieve knop + menu onthouden
        Menu.ActiveButton = Sender;
    }
    bEventBubbleFirst = false;
}

function MenuExpand(Sender, sSubMenuID, iLevel, bForceVisible){
    // Para's
    // Sender          : Knop onder muis
    // sSubmenuID      : ID van submenu die uitgeklapt moet worden.
    // iLevel          : level van submenu.
    // bNoExpand       : Eenmaal uitgeklapt niet meer verbergen (in geval van alleen submenus tonen)
    
    var sClassName = '';
    var bCollapse = true;
    var oTargetMenu;
    
    if (!bForceVisible)
        bForceVisible = false;
 
   
//  Bijbehorend parent menu opzoeken.    
//  if(!Sender.ParentMenu)
//        Sender.ParentMenu = Menu.GetParentMenu(Sender);      
//             
//  Menu.ActiveMenuId = Sender.ParentMenu.id;        
  
    oTargetMenu = $get(sSubMenuID);
    
    Sender.ForceVisible = bForceVisible;    
    Sender.ChildMenuId = sSubMenuID;   
    Sender.Expanded = true;
    if (oTargetMenu) 
        ShowMenu(oTargetMenu);
    
    //oSubjectMenu.onMouseOut = HideMenu(oSubjectMenu,true);
    Menu.PreviousButton = Sender;                
    Menu.PreviousMenu = oTargetMenu;
    return true;
}


//maakt menu zichbaar
function ShowMenu(oSubMenu){
    oSubMenu.isMenu = true;
    oSubMenu.style.display='block';
}

// onmouse out handler.. (menu collapse)
function mc(Sender){
    bEventBubbleFirst = true;
    //Menu.SetParentMenuToHover(Sender,false);    
    Menu.ActiveButton = null;
    Menu.ActiveMenuId = '';
    
    if(timer){
        clearTimeout(timer);        
    }
    timer=setTimeout("HideMenu('" + Menu.ActiveRootMenuId + "')",  Menu.HoverTime);          
}

// alles verwijderen behalve de boom waar Menu.ActiveButton in staat
// Root UL = Sub0
function HideMenu(sMenuID){

    var RootMenu = document.getElementById(sMenuID);
    if (RootMenu){
        var RootButton;
        
        if(timer){
            clearTimeout(timer);        
        }
                
        // Door root knoppen lopen! ( van onderaf beginnen )
        for(var x=0; x<RootMenu.childNodes.length; x++){
            RootButton = RootMenu.childNodes[x];    
            RootButton.isRoot = true;  
                       
            // Controleren of Menu tak ingeklapt mag worden
            if(RootButton.childNodes)          
                  HideChildMenuNodes(RootButton);
        
        }     
    }
}


function HideChildMenuNodes(oParent, bParentVisible){
    var child = null;
      
    var bShow = false;
    
    // Controleren of oParent niet de actieve knop is, zoja niet verbergen.
    if (oParent == Menu.ActiveButton)
        bShow = true;  
   
   // alert(Menu.FixedDisplay);
   
    // Controleren of oParent de geselecteerde root knop is.
    if (oParent.tagName == 'LI' && oParent.className.substring(0,1) == 'S' && oParent.isRoot && Menu.FixedDisplay == 2)
        bShow = true;       
            
    if (oParent.ForceVisible)
        bShow = true;    
 
    if (oParent.ChildMenuId){
        child = $get(oParent.ChildMenuId);
        if (child){
             if (child.ForceVisible)
                bShow = true;
             
              // Controleren of oParent de geselecteerde root knop is.
              if (child.className.substring(0,1) == 'S' && Menu.FixedDisplay == 1)
                  bShow = true;   
                  
               // Child kan een li of een ul zijn (knop of submenu)        
               if (child == Menu.ActiveButton)
                    bShow = true;
                
               // tonen als in dit menu een active knop is, of als parent een actieve knop is.
               if(child.childNodes)          
                     bShow = (HideChildMenuNodes(child) || bShow);   
        }   
    }               
        
                
    // Door sub knoppen (menu's heen lopen)
    for(var x=0; x<oParent.childNodes.length; x++){
        child = oParent.childNodes[x];
        
        // Alleen iets doen met knoppen of menu's, de rest overslaan.
        if(child.tagName == 'LI' || child.tagName == 'UL'){
            //if (!child.isMenu)
           if (child.ForceVisible)
                bShow = true;
          
            // Controleren of oParent de geselecteerde root knop is.
            if (child.tagName == 'LI' && child.className.substring(0,1) == 'S' && Menu.FixedDisplay == 1)
               bShow = true;     
                      
            // Child kan een li of een ul zijn (knop of submenu)        
            if (child == Menu.ActiveButton)
                bShow = true;
             
            // tonen als in dit menu een active knop is, of als parent een actieve knop is.
            if(child.childNodes)          
                 bShow = (HideChildMenuNodes(child) || bShow);   
        }       
    }
        
    // het menu bij deze knop (on) zichtbaar maken
    if (oParent.ChildMenuId && !bShow && $get(oParent.ChildMenuId))
        $get(oParent.ChildMenuId).style.display='none';
        
    return bShow;    
    
}

function OpenButton(sBtnID){
    var iPos = sBtnID.indexOf('ButtonID=');
	if (iPos >= 0) {
		var iButtonID = sBtnID.substring(iPos + 9, sBtnID.length);
		iPos = iButtonID.indexOf('&');
		if (iPos < 0)
			iPos = iButtonID.indexOf('?');
		if (iPos < 0)
			iPos = iButtonID.indexOf('#');
		if (iPos >= 0)
			iButtonID = iButtonID.substring(0, iPos);
			
        MenuClick(this,iButtonID);
     }
}


function OpenMenu(sURL) {
	// Ga naar opgegeven menu
	var iMenuID = 0;
	var iPos = sURL.indexOf('MenuID=');
	if( iPos >=0 ) {
	    iMenuID = sURL.substring(iPos + 7, sURL.length);
		iPos = iMenuID.indexOf('&');
		
		if (iPos < 0)
			iPos = iMenuID.indexOf('?');
		if (iPos < 0)
			iPos = iMenuID.indexOf('#');
		if (iPos >= 0)
			iMenuID = iMenuID.substring(0, iPos);
			
	    // Negatieve knop wordt als menu verwerkt.
        MenuClick(this, iMenuID * -1);
	 
	}
	// MenuClick(this,sURL,-99);		
}
function GotoA(sURL) {
	// Spring naar juiste plek
	location.href = '#' + sURL;
}
function FindA() {
	var oFrame = this;
	var sURL = '', sPrefFrame = '';
	
	// Controleren of deze pagina al interne link heeft
	sURL = oFrame.location.href;
	
	if (sURL.indexOf('#') >= 0)
		return;
	
	GotoA(sURL);
		
	// Frame naam onthouden
	sPrefFrame = oFrame.name;
	
}
function OpenURL(sURL, bOpenInContent) {
	if (!bOpenInContent) {
	    // Nieuw browser venster
	    window.open(sURL); 
	} else {
	    // Open de pagina in dit frame
		self.location.href = sURL;
	}
}

function OpenDoc(sURL, iPopupWidth, iPopupHeight, iPopupType) {
	// Naar content dir verwijzen
	var sDir = '';
	if (!(typeof(sContentDir) == 'undefined') || (sContentDir == null))
		sDir = sContentDir;
	if (sDir.length == 0)
		sDir = '../content/';
	OpenExtern(sDir + sURL, iPopupWidth, iPopupHeight, iPopupType);
}

function OpenExtern(sURL, iPopupWidth, iPopupHeight, iPopupType) {
	// Open de pagina in popup venster
	if (!iPopupWidth)
		iPopupWidth = screen.availWidth * (2/3);
	if (!iPopupHeight)
		iPopupHeight = screen.availHeight * (2/3);
	if (!iPopupType)
		iPopupType = 0;
	
	// Juiste venstertype openen
	switch (iPopupType) {
	case -1: // Zelfde scherm
		document.location.href = sURL;
		break;
	case 1: // Normaal popup venster
		oWin = window.open(sURL, 'Popup', 'width=' + iPopupWidth + ',height=' + iPopupHeight + ',left=' + (screen.availWidth - iPopupWidth) / 2 + ',top=' + (screen.availHeight - iPopupHeight) / 2 + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes');
		if (oWin)
			oWin.focus();
		break;
	case 2: // Modaal popup venster
		if (window.showModalDialog)
			oWin = window.showModalDialog(sURL, 'Popup', 'dialogWidth:' + iPopupWidth + 'px;dialogHeight:' + iPopupHeight + 'px;font-family:Verdana;font-size:12;status:no;scroll:no;center:yes;edge:raised;resizable:no;help:no;unadorned:yes;');
		else
			window.open(sURL, 'Popup', 'width=' + iPopupWidth + ',height=' + iPopupHeight + ',left=' + (screen.availWidth - iPopupWidth) / 2 + ',top=' + (screen.availHeight - iPopupHeight) / 2 + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,modal=yes');
		break;
	default: // Normaal venster
		oWin = window.open(sURL, 'Popup', 'width=' + iPopupWidth + ',height=' + iPopupHeight + ',left=' + (screen.availWidth - iPopupWidth) / 2 + ',top=' + (screen.availHeight - iPopupHeight - 140) / 2 + ',status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes');
		try{
		 if (oWin && oWin.focus)
			oWin.focus();
		}
		catch(e) {}		
		break;
	}
}

/*---------------------------------------------------------------------------------------------
    Functies voor het tonen van foto's
---------------------------------------------------------------------------------------------*/
var sLargeImgUrl = '';

var oBoxImageColl = null;

function box_click(sURL, Sender, sOrgUrl, sCaption){
    var sPopupID = 'Box';
    var iWidth = 0;
    var iHeight = 0;
    var sOkId = '';
    var sCancelId = '';  
    var oBounds;
    var bSenderIsImg = (Sender.tagName && Sender.tagName.toLowerCase() == 'img');
  
    if (!sCaption)
        sCaption = ''; 
  
    oBounds = new Sys.UI.Bounds(0, 0, 50, 50);     
  
    if(bSenderIsImg){     
       oBounds = Sys.UI.DomElement.getBounds(Sender);
    }
    
    if (!sOrgUrl || sOrgUrl.length == 0){
        if(bSenderIsImg){
           sOrgUrl =  Sender.src;           
        }
        else{
            sOrgUrl = 'Update/Img/hourglass.gif'; 
            oBounds = new Sys.UI.Bounds(0, 0, 50, 50);            
        }      
    }
  
    iWidth = oBounds.width;
    iHeight = oBounds.height;
    
    sLargeImgUrl = sURL;
      
    sHTML = '<div style="width:100%;height:5px;overflow:hidden"></div>';
    sHTML += '<img onmouseover="this.src=\'buttons/windowclose_over.gif\'" onmouseout="this.src=\'buttons/windowclose.gif\'"';
    sHTML += ' onclick="ModalPopupClose()" id="btnCancel" src="buttons/windowclose.gif" style="position:absolute;right:7px;top:7px;" />';
    sHTML += '<center><img  id="imgSmall" width="' + (iWidth) + '" height="' + (iHeight) ;
    sHTML += '" align="absmiddle" id="boxImage" src="' + sOrgUrl ;
    sHTML += '" /><img id="imgLarge" onclick="ModalPopupClose()" style="display:none" align="absmiddle" src="' + sLargeImgUrl + '" /></center>';       
    sHTML += '<div class="imgCaption" style="width:100%;heigth:40px;overflow:hidden;">'
    sHTML += '<span id="boxCaption" style="height:20px" class="boxCaption">' + sCaption + '</span><br/><span id="boxNav" style="height:20px"  class="boxNav"></span></div>';
    
    ModalPopupOpen(sPopupID, iWidth + 20, iHeight + 20, sHTML, 'btnCancel');
    setTimeout(box_imgLoaded, 100);
}

function box_imgLoaded(){
    var iWidth = 600;
    var iHeight = 400;
    
    // Grote afbeelding opzoeken.
    var LargeImg = $get('imgLarge',oPopup);
    var SmallImg = $get('imgSmall',oPopup);
    
    if (!LargeImg)
        return;
    
    // Controleren of grote afbeelding klaar is met laden.
    if (!(LargeImg.complete == null || LargeImg.complete) ){
        setTimeout(box_imgLoaded, 500); 
        return false;       
    }
    
    // popup opnieuw opzoeken
    var oPopup = $get('divOpener' + _sModalPopup);    
    SmallImg.src = LargeImg.src;
    
    LargeImg.style.display = 'block';
    SmallImg.style.display = 'none';   
          
    var oBounds = Sys.UI.DomElement.getBounds(LargeImg);
    iWidth = oBounds.width;
    iHeight = oBounds.height;
    
    var sNavTxt = '';
   
    if (typeof(oBoxImageColl) != 'undefined'){
       
        var iLength = oBoxImageColl.length;
        if (iLength>0) {
            var src = LargeImg.src;
            var iLastIndexOf = src.toLowerCase().lastIndexOf('content/');  
            var index = 1;
             
            src = src.substr(iLastIndexOf);
            
            // Controleren of er nog meer afbeeldingen geregisteerd zijn.         
            for(i=0; i < iLength; i++){
                // Huidige positie bepalen.
                if (oBoxImageColl[i].Contains(src)){
                    index = i + 1;
                    break;
                }
            }
             
            sNavTxt = index.toString() + ' van ' + iLength.toString();
            
            // Volgende tonen?
            if (index < iLength){
                sNavTxt += '<span class="nav" id="boxNavNext" onclick="box_goto(' + index + ')">&nbsp;- Volgende</span>';   
                
                // Volgende vast laden.
                var aURLn = oBoxImageColl[index].split('~');
                LargeImg.src = aURLn[0];                 
            }
            if (index>1){
                sNavTxt = '<span class="nav" onclick="box_goto(' + (index - 2 ).toString() + ')">Vorige -&nbsp;</span>' + sNavTxt;
            }
            
            var aURL = oBoxImageColl[index - 1].split('~');
            if (aURL.length > 1)
                $get('boxCaption',oPopup).innerHTML = aURL[1];
           
                           
            var oTarget = $get('divOpener' + _sModalPopup);
            oTarget.OkId = 'boxNavNext';
        }              
    } 
    
    LargeImg.style.display = 'none';
    SmallImg.style.display = 'block';
    SmallImg.style.width = iWidth + 'px';
    SmallImg.style.height = iHeight + 'px';
            
    $get('boxNav').innerHTML= sNavTxt;
   // alert(oBoxImageColl.length);
    
    // Popup op maat maken.
    SetPosition(oPopup, iWidth + 10, iHeight + 50);    
}

function box_goto(iIndex, Caption){
    if(!Caption)
        Caption = '';
    
    // popup opnieuw opzoeken
    var oPopup = $get('divOpener' + _sModalPopup);    
    
    // Grote afbeelding opzoeken.
    var LargeImg = $get('imgLarge',oPopup);
    var SmallImg = $get('imgSmall',oPopup);
        
    aURL = oBoxImageColl[iIndex].split('~');
    LargeImg.src = aURL[0];
       
    setTimeout(box_imgLoaded, 500);
}

// Webservice aanroepen om conversie op te slaan.
function ConversionReached(sConversionName) {
    VWA.FrontService.OnConversionReachedString(iSiteID, sConversionName, iOptimizerID);
    return true;
}


