﻿/****************************************************************************************/
/****************************************************************************************/
// Navigation functions
/****************************************************************************************/
/****************************************************************************************/

function getPageURL() {
    var sPath = window.location.href;
    var sPage = sPath.substring(0,sPath.lastIndexOf('.aspx') + 5);
    return sPage;
}


/****************************************************************************************/
// 
/****************************************************************************************/
function getLocation()
{
    /*
    var location = displayItem("location");

    if (location!="")
        return "&location=" + location ;
    else
        return "";
    */
    return "";
}

function getMenuId()
{
    var menuid = displayItem("menuid");

    if (menuid!="")
        return "&menuid=" + menuid ;
    else
        return "";
}

function getParentMenuId()
{
    var parentmenu = displayItem("parent");

    if (parentmenu!="")
        return "&parent=" + parentmenu ;
    else
        return "";
}

function getSHM()
{
    var shm = displayItem("shm");

    if (shm!="")
        return "&shm=" + shm ;
    else
        return "";
}

/****************************************************************************************/
// Show Detail
/****************************************************************************************/
function showDetail(id) 
{
    showDetail(id,'');
}

function showDetail(id,pMenuId) 
{

    var indefini; // "indefini" est undefined
    if (pMenuId == indefini)
        pMenuId = id;
        
    var url = "";
    var page = getPageURL();
    if (page.substring(page.length-9) == "Home.aspx"){
        page = "LBBW.aspx";
		
		
		/*
		LBBW Luxemburg S.A.		799747f1-4ad5-4ccd-a983-acb3d168e74e	LBBW.aspx?id=8c1e8843-908a-4728-a18a-c074e37baa0e
		Private Kunden			c1616bd2-9ddd-4ee6-81d1-4670ba496cb5	Private.aspx?id=d6ab9618-0499-459a-bcf0-db191fad9c95
		Institutionelle Kunden	b201c071-d63b-4d36-ab5a-95b0e38d3d47	Professional.aspx?id=6e378809-be99-4bac-b076-8e619a089050
		Online-Zugang			c91eeab6-239e-452d-bbd6-d8cf8913e452	OnLine.aspx?view=login&id=230a49f3-3ab1-4fa4-8f24-029ed7299bc5
		*/

		if(id == '799747f1-4ad5-4ccd-a983-acb3d168e74e'){
			window.location.href = 'LBBW.aspx?id=8c1e8843-908a-4728-a18a-c074e37baa0e';
			return null;
		}else if(id == 'c1616bd2-9ddd-4ee6-81d1-4670ba496cb5'){
			window.location.href = 'Private.aspx?id=d6ab9618-0499-459a-bcf0-db191fad9c95';
			return null;
		}else if(id == 'b201c071-d63b-4d36-ab5a-95b0e38d3d47'){
			window.location.href = 'Professional.aspx?id=6e378809-be99-4bac-b076-8e619a089050';
			return null;
		}else if(id == 'c91eeab6-239e-452d-bbd6-d8cf8913e452'){
			window.location.href = 'OnLine.aspx?view=login&id=230a49f3-3ab1-4fa4-8f24-029ed7299bc5';
			return null;
		}
	}
        
    url = page + "?view=detail&id=" + escape(id) ;
    
    //url = url + getLocation() + getMenuId() + getParentMenuId();
    url = url + getMenuId() + getParentMenuId();
    
    if (pMenuId!='')
        url = url + "&shm=" + pMenuId; //escape(pMenuId);

    window.location.href = url;

}

function showSearchDetail(id,pMenuId, pTopMenuId, pPage, pTitle) 
{

    var indefini; // "indefini" est undefined
    if (pMenuId == indefini)
        pMenuId = id;
        
    var url = "";
    var page = getPageURL();
    if (page.substring(page.length-9) == "Home.aspx")
        page = "LBBW.aspx";
    
    if (pPage != '')
        page = pPage;
           
    //url = page + "?view=detail&id=" + escape(id) ;
    url = page + "?view=detail&id=" + escape(id) ;
    
    //url = url + getLocation() + getMenuId() + getParentMenuId();
    url = url + getMenuId() + getParentMenuId();
    
    if (pMenuId!='')
        url = url + "&shm=" +  pMenuId; //escape(pMenuId);
    
    if( pTopMenuId != '')
        url = url + "&topparent=" + pTopMenuId;
        
    if( pTitle != '')
        url = url + "&title=" + escape(pTitle);
        
    window.location.href = url;

}
/****************************************************************************************/
// Show Detail Anchor
/****************************************************************************************/
function showDetailAnchor(id,pAnchorID) 
{
    var location = displayItem("location");

    if (location=="")
        window.location.href = getPageURL() + "?view=detail&id=" + id + "&location=" + location + "#" + pAnchorID ;
}

/****************************************************************************************/
// Show Template
/****************************************************************************************/
function showTemplate(id,tmpl)
{
    var location = displayItem("location");


    if (location=="")
        window.location.href = getPageURL() + "?view=detail&templatename=" + id +"&template=" + escape(tmpl) + "&location=" + location; ;
}


/****************************************************************************************/
// Show Folder
/****************************************************************************************/
function showFolder(id) 
{
    var location = displayItem("location");

    if (location=="")
        window.location.href = getPageURL() + "?view=folder&id=" + id;
    else
        window.location.href = getPageURL() + "?view=folder&id=" + id + "&location=" + location;
}

function showFolder(id,pMenuId) 
{
    var indefini; // "indefini" est undefined
    if (pMenuId == indefini)
        pMenuId = id;

    var location = displayItem("location");

    var url = "";
    var page = getPageURL();
        
    url = page + "?view=folder&id=" + escape(id) ;
    
    url = url + getLocation() + getMenuId() + getParentMenuId();
    
    if (pMenuId!='')
        url = url + "&shm=" + escape(pMenuId);

    window.location.href = url;

}


function showFond(pMenuId,pTitle) 
{  
    var url = "";
    var page = getPageURL();
    var parentmenu = displayItem("parent");
    var menu = displayItem("menuid");
        
    url = page + "?id=" + escape(pMenuId) ;    

    url = url + "&menuid=" + escape(pMenuId) + "&parent=" + menu + "&topparent=" + parentmenu ;
    url = url + "&title=" + escape(pTitle);
    window.location.href = url;
}


function showUrl(url)
{
    window.location.href = url;
}

/****************************************************************************************/
// Show Tools
/****************************************************************************************/
function showTools(menuid, parentid)
{
    var indefini; // "indefini" est undefined
    var url = "";
    
    //Private.aspx?view=tools
    url = getPageURL()+ "?id=" + escape(menuid) +  "&menuid=" + escape(menuid) + "&parent=" + parentid  ;
    //Private.aspx?id=3205bca1-6573-4291-8c3d-f2347332c28c&menuid=3205bca1-6573-4291-8c3d-f2347332c28c&parent=3576d000-9a63-42c5-bca5-5b40bd7c269c&title=Simulationen
    //url = url + getLocation() + getMenuId() + getParentMenuId();
    
    //url = url + getSHM();

    window.location.href = url;
}

/****************************************************************************************/
// Show Template
/****************************************************************************************/

function showTemplate(id) 
{
    showTemplate(id,'');
}

function showTemplate(id,pMenuId) 
{
    var indefini; // "indefini" est undefined
    var url = "";
    
    url = getPageURL()+ "?view=template&templatename=" + escape(id) ;
    
    url = url + getLocation() + getMenuId() + getParentMenuId();
    
    if (pMenuId != indefini)
        url = url + "&shm=" + escape(pMenuId);
    else
    {
        url = url + getSHM();
    }

    window.location.href = url;
}


/****************************************************************************************/
// Show Template Anchor
/****************************************************************************************/

function showTemplateAnchor(pTemplateName,pAnchorID)
{
        showTemplateAnchor(pTemplateName,pAnchorID,'');
}


function showTemplateAnchor(pTemplateName,pAnchorID,pMenuId)
{
    
    var location = displayItem("location");
    var url = "";
    
    url = getPageURL() + "?view=template&templatename=" + escape(pTemplateName);
    
    
    // Location    
    if (location!="")
        url = url +  "&location=" + location ;	    
    
    // related Menu
    if (pMenuId!="")
        url = url + "&shm=" + escape(pMenuId);
    
    // Menu
    if (displayItem("menuid")!="")
        url = url + "&menuid="+displayItem("menuid");
    
    if (displayItem("parent")!="")
        url = url + "&parent="+displayItem("parent");
    
    // Anchor
    url = url + "#" + escape(pAnchorID);    
    
    
    window.location.href = url;
}


/****************************************************************************************/
// Show View
/****************************************************************************************/
function showView(mode) 
{
    var location = displayItem("location");

    if (location=="")
        window.location.href = getPageURL() + "?view=" + mode;
    else
        window.location.href = getPageURL() + "?view=" + mode + "&location=" + location;;
}

/****************************************************************************************/
/****************************************************************************************/
// Sub Menu
/****************************************************************************************/
/****************************************************************************************/

function checkIE() {
	// IE 5.x o >
	if (navigator.userAgent.indexOf("IE") >= 0 && navigator.platform=="Win32")
		return(true);
	else
		return(false);
}


// Recherche la règle souhaité en prenant compte IE et/ou FF/NS6
function getCssRule(indexCss,cssName)
{    
    var rules = document.styleSheets[indexCss].rules||document.styleSheets[indexCss].cssRules;
    for(var r=0;r<rules.length;r++)
	{
	        if(rules[r].selectorText.toUpperCase()==cssName.toUpperCase())
		    {
		        return rules[r].style;
		    }
	}		

    return null;
}


/*
*
*/
function changeStyleAttribute(cssName,StyleAttribute,AttributeName,newValue)
{
   var indexCss = -1;
   
   cssName = cssName.toUpperCase();
   // Recherche le bon CSS
   for (i=0; i<document.styleSheets.length; i++)
   {
        if (document.styleSheets[i].href.toUpperCase().match(cssName)!=null)
            indexCss = i;
   } 
   
   
   if (indexCss>=0)
   {
        // Retrouve la regle CSS
        var mystyle = getCssRule(indexCss,AttributeName);
        if (mystyle!=null)
        {
            // Pour le moment uniquement 2 attributs implementés, à poursuivre en fonction des besoins
            // Comment passer d'une propriété de style css à celle qui correspond en javascript?
            // On remplace les "-" par une majuscule sur le mot suivant. Ex: z-index => element.style.zIndex
            switch (StyleAttribute.toUpperCase())
            {
                case "BORDERLEFT":
                            mystyle.borderLeft = newValue;
                            break;
                case "BORDERCOLOR":
                            mystyle.borderColor = newValue;
                            break;
                case "WIDTH":
                            mystyle.width = newValue;
                            break;
            }
            
        }
   }
    
}

/****************************************************************************************/
/****************************************************************************************/
// QueryString manipulation functions
/****************************************************************************************/
/****************************************************************************************/

function PageQuery(q) {
    if(q.length > 1) 
        this.q = q.substring(1, q.length);
    else 
        this.q = null;
    this.keyValuePairs = new Array();
    if(q) {
        for(var i=0; i < this.q.split("&").length; i++) {
        this.keyValuePairs[i] = this.q.split("&")[i];
    }
}

this.getKeyValuePairs = function() { 
    return this.keyValuePairs; 
}

this.getValue = function(s) {
    for(var j=0; j < this.keyValuePairs.length; j++) {
        if(this.keyValuePairs[j].split("=")[0] == s)
            return this.keyValuePairs[j].split("=")[1];
    }
    return false;
}

this.getParameters = function() {
    var a = new Array(this.getLength());
    for(var j=0; j < this.keyValuePairs.length; j++) {
        a[j] = this.keyValuePairs[j].split("=")[0];
    }
    return a;
}

this.getLength = function() { 
    return this.keyValuePairs.length; }
}

function queryString(key) {
    var page = new PageQuery(window.location.search);
    return unescape(page.getValue(key));
}

function displayItem(key){
    if(queryString(key)=='false')
    {
        return "";
    }
    else
    {
        return queryString(key);
    }
}

/****************************************************************************************/
/****************************************************************************************/
// Print
/****************************************************************************************/
/****************************************************************************************/
function showPrintPopup() {

  
  // Capture the content of the content area
  var source = document.getElementById('ContentDIV'); 
  if(navigator.appName == "Mozilla" ||navigator.appName == "Netscape") // For Firefox
    {  
        //alert('navigator.appName 1 = ' + navigator.appName);     
    }    
  else if(source==null)  
    {
      var maintenant = new Date();    
      var temps = maintenant.getTime() / 1000;
      
      while (source ==null)
        {           
            source = popup.document.getElementById('ContentDIV');
            var maintenant2 = new Date();
            var temps2 = maintenant2.getTime() / 1000;
            var reste = Math.floor(temps2 - temps);
            if(reste>30)
            {   
                break;        
            }
        }   
    } 
   
  if (source!=null) 
  {
    // Open a new popup window
    var popup = window.open("PrintPopup.aspx");
    popup.focus();
        
    var target = popup.document.getElementById('divPrintable');
    
    var maintenant = new Date();    
    var temps = maintenant.getTime() / 1000;
    
    if(navigator.appName == "Mozilla" ||navigator.appName == "Netscape") // For Firefox
    {          
        target = popup.document.body;        
    }    
    else if(target==null)  
    {    
        while (target ==null)
        {           
            target = popup.document.getElementById('divPrintable');
            var maintenant2 = new Date();
            var temps2 = maintenant2.getTime() / 1000;
            var reste = Math.floor(temps2 - temps);
            if(reste>30)
            {                
                break;        
            }
        }        
    }
    
    
    if (target!=null) 
    {      
      // Pass the HTML from the parent window to the popup
      target.innerHTML = source.innerHTML;    
      popup.print();
    }    
    popup.close();
  }
 
}