/*
function help_popup(id) {
    F = window.open('/help/'+id,"Popup"+id,"width=420,height=300,top=200,left=200,scrollbars=yes,scrolling=yes");
}
*/



function imgpop(img) {
    F = window.open('/imgpop.php?img='+img,"Popup","width=660,height=500,top=20,left=20,scrollbars=no,scrolling=no,menubar=no,toolbar=no,location=no,status=no");
}

/* popup layer */
function jqshow(url, selector, title, anker) {
    buttons = [{text: "schließen",click: function() { $(this).dialog("close"); }}];
    if (typeof title == "undefined") { title = "Hinweis"; }
    $(selector, $.ajax({ type: "GET", url: url, async: false, dataType:'html' }).responseText).css('margin', '0px').dialog({'dialogClass':'jqshow jqshow-no-title','height':400,'width':638,'modal':true,'title':title,'buttons':buttons});
}

function number_format (number, decimals, dec_point, thousands_sep) {
    var exponent = "";
    var numberstr = number.toString ();
    var eindex = numberstr.indexOf ("e");
    var i;
    if (eindex > -1) {
        exponent = numberstr.substring (eindex);
        number = parseFloat (numberstr.substring (0, eindex));
    }
    if (decimals != null) {
        var temp = Math.pow (10, decimals);
        number = Math.round (number * temp) / temp;
    }
    var sign = number < 0 ? "-" : "";
    var integer = (number > 0 ? Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
    var fractional = number.toString ().substring (integer.length + sign.length);
    dec_point = dec_point != null ? dec_point : ".";
    fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";
    if (decimals != null && decimals > 0) {
        for (i = fractional.length - 1, z = decimals; i < z; ++i) fractional += "0";
    }
    thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;
    if (thousands_sep != null && thousands_sep != "") {
    	for (i = integer.length - 3; i > 0; i -= 3) integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
    }
    return sign + integer + fractional + exponent;
}

/* cart position note */
var addNoteID;
var addNoteTitle;
var addNoteHtml;
           
function addNote(prodID) {
    $('.addNoteDialog').remove();
    addNoteID = prodID;
    if (addNoteHtml) {
        addNoteShow(addNoteID);
        $('#addnotetext')[0].value = $('#input_note'+addNoteID).attr('value');
    }
    else {
        $.ajax({type:"GET",url:"/js/template/addnote.jtpl",data:null,dataType:"html", success:function (html, prodID) {
        addNoteHtml = $(html);
        addNoteShow(addNoteID);
        }});
    }
}
            
function addNoteShow(prodID) {
    html = $('<div id="addnoteshow'+prodID+'" title="Ihre Bemerkung zur Warenkorbposition"></div>');
    html.append(addNoteHtml) //.clone()
    html.dialog({
        bgiframe: true,
        autoOpen: true,
        modal: true,
        buttons: { "übernehmen": function() { 
            $('#input_note'+prodID).attr('value', $('#addnotetext')[0].value);
            addNoteUpdateLink(prodID);
            $(this).dialog("close"); 
        } }
        , width: '380px'
    });
}

function delNote(prodID) {
    $('#input_note'+prodID).attr('value', '');
    addNoteUpdateLink(prodID);
}

function addNoteUpdateLink(prodID) {
    $('#addnotelink'+prodID+' *').remove();
    if ($('#input_note'+addNoteID).attr('value')) {
        $('#addnotelink'+prodID).append($('<a style="display:block;" href="javascript:addNote('+prodID+');">Bemerkung ändern</a>'));
        $('#addnotelink'+prodID).append($('<a style="display:block;" href="javascript:delNote('+prodID+');">Bemerkung löschen</a>'));
    }
    else {
        $('#addnotelink'+prodID).append($('<a href="javascript:addNote('+prodID+');">Bemerkung hinzufügen</a>'));
    }
}

/* help text note */
function help_popup(helpID) {
    $('.addNoteDialog').remove();
    $.ajax(
            {
                type:"GET"
                ,url:"/jquery_help.php?id="+helpID
                ,data:null,dataType:"html"
                , success:function (html, helpID) {
                    helpHtml = $(html);
                    $("a.lboxlive", helpHtml).fancybox(fancyParam);
                    topic = $('.title', helpHtml).html();
                    $('.title', helpHtml).remove()
                    helpHtml.dialog({
                        bgiframe: true,
                        autoOpen: true,
                        title: topic,
                        modal: false,
                        draggable: true,
                        dialogClass: 'help_pop',
                        maxHeight: 400,
                        buttons: { "schliessen": function() {
                            $(this).dialog("close");
                        } }
                        , width: '380px'
                    });
                }
        });
}

var popupWindow;

function print_view(jq_selector, url, start_print) {

        w = 740;
        h = 500;
        x = screen.availWidth/2-w/2;
        y = screen.availHeight/2-h/2;

        var show_url;
        var show_date;

        js_serverTime = serverTime * 1000;
        var  Zeit = new Date();
        Zeit.setTime (js_serverTime);
        show_date = Zeit.toLocaleString();

        if (typeof url == "undefined") {
            show_url = document.URL;
        }
        else {
            show_url = 'http://www.hofsaess-online.de'+url;
        }

        popupWindow = window.open('','','scrollbars=yes,menubar=0,toolbar=0,location=0,status=1,width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y);
        popupWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Druckansicht</title><link rel="stylesheet" href="/style.css" type="text/css"/><link rel="stylesheet" href="/print.css" type="text/css" /></head><body class="print"><div><img src="/pics/printview.png" alt="" style="display:block;margin-bottom:8px;" /><table class="print_head"><tbody><tr><td>URL:</td><td>'+show_url+'</td><td rowspan="2" style="text-align:center;"><span class="non-printable"><input type="button" value="drucken" onclick="window.print();" class="transaction" /></span></td></tr><tr><td>Datum:</td><td>'+show_date+'</td></tr></tbody></table></div><div id="insert"></div></body></html>');

        if (typeof url == "undefined") {
            inner = $($(jq_selector).clone().html(), popupWindow.document);
        }
        else {
            inner = $(jq_selector,  $($.ajax({ type: "GET", url: url, async: false, dataType:'text' }).responseText, popupWindow.document));
        }
//alert(inner.html());
        if (inner == null) {
            inner = $(jq_selector,  $($.ajax({ type: "GET", url: document.URL, async: false, dataType:'text' }).responseText, popupWindow.document));
        }

        $('.button', inner).remove();
        $('script', inner).remove();
        $('input,select', inner).attr('disabled', 'disabled');
        $('*', inner).each(
            function () {
                if ($(this).css('color') == 'white') $(this).css('color', 'red');
                if ($(this).css('color') == '#FFFFFF') $(this).css('color', 'orange');
                if ($(this).css('color') == '#ffffff') $(this).css('color', 'blue');
                if ($(this).css('color') == 'rgb(255, 255, 255)') $(this).css('color', 'green');
            }
        );
        //alert($('#std1', inner).css('color'));
        $('a', inner).each(
            function () {
                //$(this).replaceWith($(this).html());
                $(this).attr('href', 'javascript:return false;');
            }
        );
        $('#insert', popupWindow.document).append(inner);
        popupWindow.document.close();
}

/* CART FUNCTIONS */

        function open_table() {
          document.getElementById('div_open_table').style.display = 'block';
        }
        function sendwk() {
           prot = (et_ssl == 1) ? 'https' : 'http';
           if (document.getElementById('nachname').value != '' && document.getElementById('vorname').value != '' && document.getElementById('email').value != '') {
           url = prot+'://www.hofsaess-online.de/wksave.php?nachname='+encodeURIComponent(document.getElementById('nachname').value)+'&vorname='+encodeURIComponent(document.getElementById('vorname').value)+'&email='+encodeURIComponent(document.getElementById('email').value)+'&{_SID}';
      if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        text = null;
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        text = false;
    } else {
        alert('Ihre Anfrage kann leider nicht bearbeitet werden');
    }
    if (req) {
                 req.open("GET", url, true);
        req.send(text);
        alert('Der Link zu Ihrer gespeicherten Wunschliste wurde an die angegebene E-Mail Adresse versandt.');
    }}
else {
        alert('Bitte fuellen Sie alle 3 Eingabefelder aus.');
}
        }
     

var fancyParam = {
            'speedIn':600,
            'speedOut':200,
            'overlayShow':false,
            'transitionIn':'elastic',
            'easingIn':'swing',
            'easingOut':'swing',
            'hideOnContentClick':true
    };
   
$(document).ready(function() {
    // Lightbox
    $("a.lbox").fancybox(fancyParam);
    // Menu Highlight
    $("a", $('.menu')).each(function () {
        var url = window.document.URL.replace(/http:\/\/www.hofsaess-online.de/, "");
        var re = new RegExp($(this).attr('href').replace(/\.html$/, '').replace(/\/$/, ''));
        if (re.test(url)) {
            $(this).addClass('on').parent().addClass('on');
        }
    });
});

