﻿

var strContentFlash = "";

function openOptifog()      { $.openPopupLayer({ name: "divOverlay", url: "frames/clip_optifog.aspx" }); }
function openLageplan()     { $.openPopupLayer({ name: "divOverlay", url: "frames/lageplan.aspx" }); }
function openClip(pID)      { $.openPopupLayer({ name: "divOverlay", url: "frames/clips.aspx?id="+pID+"&res="+iResolution }); }
function openFlash(pSrc)    
{
    strContentFlash = $(".divContentFlash").html();
    $(".divContentFlash").html("");
    $.openPopupLayer({ name: "divOverlay", url: "frames/flash.aspx?src="+pSrc+"&res="+iResolution });
}

function openProdukt(pID, pHerstellerID, pKategorieID)  
{
    var strUrl = "frames/produkte.aspx?id="+pID+"&res="+iResolution;

    if(pHerstellerID.length > 0)    { strUrl += "&hid=" + pHerstellerID; }
    if(pKategorieID.length > 0)     { strUrl += "&kid=" + pKategorieID; }

    $.openPopupLayer({ name: "divOverlay", url: strUrl });
}

function changeMarke(pValue)        { addParamToUrl(window.location.href, "hid", pValue, true); }
function changeKategorie(pValue)    { addParamToUrl(window.location.href, "kid", pValue, true); }
function changeJahr(pValue)         { addParamToUrl(window.location.href, "yid", pValue, true); }
function changeZeitung(pValue)      { addParamToUrl(window.location.href, "zid", pValue, true); }

function addParamToUrl(pUrl, pParam, pValue, pRedirect) 
{
    var strDelimiter = "?";
    var iStart = pUrl.indexOf(strDelimiter + pParam + "=");

    if (iStart == -1) { strDelimiter = "&"; iStart = pUrl.indexOf(strDelimiter + pParam + "="); }

    if (iStart > -1) 
    {
        var iLen = 0;

        if (pUrl.indexOf("&", iStart + 1) > -1)
             { iLen = pUrl.indexOf("&", iStart + 1) - iStart; }
        else { iLen = pUrl.length - iStart; }

        if (pValue == 0 && strDelimiter == "?")
             { pUrl = pUrl.replace(pUrl.substr(iStart, iLen)+"&", "?"); } 
        else { pUrl = pUrl.replace(pUrl.substr(iStart, iLen), ""); }
    }

    if (pValue.length > 0) { pUrl = pUrl + strDelimiter + pParam + "=" + pValue; }

    if(pRedirect)
         { window.location.href = pUrl; }
    else { return pUrl; }
}

function setSuche(pValue)
{
    if(pValue.length > 0)
         { window.location.href = "search.aspx?search=" + pValue; }
    else {  }
}

function selectText(pID) 
{
    document.getElementById(pID).style.color = "#000000";
    document.getElementById(pID).select();
}

function prevImg() 
{
    if ($('img' + navIndex) && typeof(imgCount) != 'undefined') 
    {
        if (navIndex > 0) 
        {
            navIndex = (navIndex - 1);

            $('#img' + (navIndex + 1)).hide();
            $('#img' + navIndex).show();

            $("#divBlättern").html((navIndex + 1) + " / " + imgCount);
        }
        else
        {
            $('#img0').hide();

            navIndex = (imgCount - 1);

            $('#img' + navIndex).show();

            $("#divBlättern").html((navIndex + 1) + " / " + imgCount);            
        }
    }
}

function nextImg() 
{
    if ($('img' + navIndex) && typeof(imgCount) != 'undefined') 
    {
        if (navIndex < (imgCount - 1)) 
        {
            navIndex = (navIndex + 1);

            $('#img' + (navIndex - 1)).hide();
            $('#img' + navIndex).show();
            
            $("#divBlättern").html((navIndex + 1) + " / " + imgCount);
        }
        else 
        {
            $('#img' + navIndex).hide();

            navIndex = 0;

            $('#img'+navIndex).show();
            
            $("#divBlättern").html((navIndex+1) + " / " + imgCount);            
        }
    }
}

var printWin;

function printscreen() 
{
    var myLayer = null;

    if (document.getElementById("divLageplan") != null)
         { myLayer = document.getElementById("divLageplan").parentNode; }
    else { myLayer = document.getElementById("mainContent"); }

    today = new Date();

    var strDateTime = today.getDate() + "." + (today.getMonth() + 1) + "." + today.getFullYear() + ", " + today.toLocaleTimeString() + " Uhr";

    var parameter = "menubar=yes,toolbar=yes,scrollbars=yes,statusbar=no,location=no,resizable=yes,width=820px,height=620px";

    printWin = window.open("", "printSpecial", parameter);

    var text = "<table width=100%><tr><td style=\"padding-bottom:4px\" valign=bottom><img src=\"grafik/sonstiges/img_druck_logo.jpg\" style=\"width:200px\" border=\"0\"></td><td align=right style=\"font-size:12px;line-height:24px\" valign=bottom>www.federerbuchs.ch<br/>" + strDateTime + "</td></table><br>";

    text += myLayer.innerHTML;
    text = text.replace(/<a/, "<a style='disable:true'").replace(/<A/, "<a style='disable:true'");    
    text = replaceAll(text, "onclick=\"", "onclick = \"return false;");
    text = replaceAll(text, "onfocus=\"", "onfocus = \"return false;"); 
    text = replaceAll(text, "overflow: auto", "overflow: visible");
    text = replaceAll(text, "OVERFLOW: auto", "overflow: visible");
    
    printWin.document.open();
    printWin.document.write("<html><head><link href='css/style.css' rel='stylesheet' type='text/css' /><script src='javascript/print.js' type='text/javascript'></script></head><style> body {background-color:white;text-align:left;} div {overflow:visible;} .scroll{overflow:visible;} .highlight{color:black;background-color:white;} .divSlogan{display:none} .divInhalt .divScrollbar{width:100%} .divNewsDetail{display:none} .printheader { font-family: Verdana; border-style: solid; padding: 0px; margin-right: 0px; padding-right: 0px; border-width: 0px; border-bottom-width: 1px; border-color: black; margin-bottom: 1px; } </style><body><div class='text'><form onsubmit='return false;'>" + text + "</form></div><br><table width=100%><tr><td class=printheader style=\"font-size:10px;padding-bottom:4px;padding-top:10px\">" + document.URL + "</td></tr><tr><td align=right style=\"font-size:10px;margin-top:0px\">&copy; 2011 Federer Augenoptik Buchs SG</td></tr></table></body></html>");
    printWin.document.close();

    if (typeof (running) != "undefined") 
    {        
        if (typeof (aktperson) != "undefined") 
        {
            window.setTimeout("printWin.print()", 3000);
            printWin.gotoPerson(aktperson);
        }
        else 
        {
            printWin.running = false;
            printWin.print();
        }
    }
    else printWin.print();
}

function replaceAll(str, from, to) {
    var idx = str.indexOf(from);

    var i = 0;
    while (idx > -1 && i < 100) {
        i++;
        str = str.replace(from, to);
        idx = str.indexOf(from);
    }
    return str;
}


/* LIGHTBOX FUNCTIONS */
var lightboximages;
var lightboximagesindex;

function showTop(obj) 
{
    lightboximages = new Array();
    for (var i = 0; (t = obj.parentNode.childNodes[i]); i++) 
    {
        if (t.className == "divBild") 
        {
            if (t == obj) 
            {
                lightboximagesindex = lightboximages.length;
            }

            lightboximages[lightboximages.length] = t;
        }
    }

    if (lightboximages.length < 2) 
    {
        document.getElementById("lightbuttons").getElementsByTagName("img")[0].style.display = "none";
        document.getElementById("lightbuttons").getElementsByTagName("img")[1].style.display = "none";
    }
    else
    {
        document.getElementById("lightbuttons").getElementsByTagName("img")[0].style.display = "inline";
        document.getElementById("lightbuttons").getElementsByTagName("img")[1].style.display = "inline";
    }

    var img = obj.getElementsByTagName("img")[0];

    //Position the topBox. In this example I am just centering it on the screen
    if (iResolution == 1280)
         { boxWidth = 600; boxHeight = 400; }
    else { boxWidth = 420; boxHeight = 280; }

    $("#lightBoxImg").load(function () 
    {
        //boxWidth = 700; // $("#lightBoxImg").width();
        //boxHeight = 550; // $("#lightBoxImg").height();

        screenWidth = document.all ? document.body.clientWidth : window.innerWidth;
        screenHeight = document.all ? document.body.clientHeight : window.innerHeight;

        xPos = (screenWidth - boxWidth) * 0.5;
        yPos = (screenHeight - boxHeight) * 0.5;

        document.getElementById('topbox').style.left = xPos + "px";
        document.getElementById('topbox').style.top = yPos + "px";
        document.getElementById('topbox').style.width = boxWidth + "px";
        document.getElementById('topbox').style.height = boxHeight + "px";

        //Show the background overlay and topbox...
        document.getElementById('screenoverlay').style.visibility = 'visible';
        document.getElementById('topbox').style.visibility = 'visible';
    });

    document.getElementById("lightBoxImg").src = setImg(img.src, boxHeight, boxWidth);

    //var src = img.src.substr(img.src.indexOf("http://europa.gmgnet.li/federer"));
    //document.getElementById("lightBoxImg").src = src.substr(0, src.indexOf("&"));
}

// --------------------------------------------------------
// Bild RESIZE funktionen
// --------------------------------------------------------
function setImg(pSource, pHeight, pWidth) 
{
    if (pSource.length > 0) 
    {
        if (pHeight)    { pSource = replaceImgSize(pSource, "h", pHeight); }
        if (pWidth)     { pSource = replaceImgSize(pSource, "w", pWidth); }
    }

    return pSource;
}

function replaceImgSize(pSource, pSize, pNewSize) 
{
    pSize = "&" + pSize + "=";

    if (pSize == "&w=") { pSource = pSource.replace("&w=0", "&w="); }

    var iStartIndex = pSource.indexOf(pSize) + pSize.length;
    var iLength = pSource.indexOf("&", iStartIndex) - iStartIndex;

    if (iLength < 0) { iLength = pSource.length - iStartIndex; }

    var iOldSize = pSource.substr(iStartIndex, iLength);

    if (isNaN(iOldSize) || iOldSize.length == 0)
         { pSource = pSource.replace(pSize, pSize + pNewSize); }
    else { pSource = pSource.replace(pSize + iOldSize, pSize + pNewSize); }

    return pSource;
}


function nextLightBox(direction) {
    if (direction == 1)
        lightboximagesindex++;
    else lightboximagesindex--;

    if (lightboximagesindex >= lightboximages.length)
        lightboximagesindex = 0;
    else if (lightboximagesindex < 0)
        lightboximagesindex = lightboximages.length - 1;

    showTop(lightboximages[lightboximagesindex]);
}

function delayedShowTop(seconds) {
    setTimeout("showTop()", seconds * 1000);
}

function closeTop() {
    //Hide the overlay and tobox...
    document.getElementById('screenoverlay').style.visibility = 'hidden';
    document.getElementById('topbox').style.visibility = 'hidden';
}

