
/*PAGETOOLS JS NEW*/

$(document).ready(function() {
                        var markerCookie = $.cookieJar('pagemarker');
                        var markerCookieName = 'Marker';
                        var getlang_mark = $('#opensubpage').text();//document.getElementById('marklist').innerHTML;
                        var counts = 0;
                        var arrDel = 'false';
                        var mCookie;
                        var pageEmailTitle;
                        var pageEmailLink;
                        window.sendallPage = false;
                        var clicked = 'no';
                        var element = $(this) //.attr('id')
                        var node = $(this).attr('id')
                        pagemailID = 148;
                        $('#arrdel').text(arrDel);


                        $.each(window.pageRealLink, function(title, link){
                            $('#pagetitle').text(title);
                            $('#pagelink').text(link);
                        });

                        var counts = fillHistory(getlang_mark);

                        $('#bin').click(function() {
                            var counts = fillHistory(getlang_mark);

                            $('#container').empty();
                            $('#opensubpage').text(getlang_mark);
                            var arrDel= 'true';
                            $('#arrDel').text(arrDel);
                            var mCookie = markerCookie.set(markerCookieName,{});
                            $('#marklist2').slideUp(400);
                            $('#slideBtn').hide();
                            clicked = 'no';
                            var counts = fillHistory(getlang_mark);
                        });

                        $('#send').click(function() {
                            //Screen berechnung mitte
                            var fhoehe = ((Fensterhoehe()/2)-(430/2));
                            var fweite = ((Fensterweite()/2)-(630/2));
                            $.blockUI.defaults = {
                            // styles for the message when blocking; if you wish to disable
                            // these and use an external stylesheet then do this in your code:
                            // $.blockUI.defaults.css = {};
                            css: {
                            padding:        0,
                            margin:         0,
                            top:            fhoehe,
                            left:           fweite,
                            textAlign:      'center',
                            color:          '#000',
                            border:         '0',
                            backgroundColor:'#fff',
                            cursor:         'default',
                            position:         'absolute'
                            },

                            // styles for the overlay
                            overlayCSS:  {
                            backgroundColor:'#000',
                            opacity:        '0.6'
                            },

                            // z-index for the blocking overlay
                            baseZ: 1000,

                            // set these to true to have the message automatically centered
                            centerX: true, // <-- only effects element blocking (page block controlled via css above)
                            centerY: true,

                            // allow body element to be stetched in ie6; this makes blocking look better
                            // on "short" pages.  disable if you wish to prevent changes to the body height
                            allowBodyStretch: true,

                            // be default blockUI will supress tab navigation from leaving blocking content;
                            constrainTabKey: true,

                            // fadeOut time in millis; set to 0 to disable fadeout on unblock
                            fadeOut:  400,

                            // suppresses the use of overlay styles on FF/Linux (due to significant performance issues with opacity)
                            applyPlatformOpacityRules: true
                            };

                            $.each( pageRealLink, function(title, link){
                                                    var pageEmailTitle = title;
                                                    var pageEmailLink = link;
                            });



                            $.blockUI({ message: $('#bel2-shader-pagetool'), css: { width: '630px' ,height:'430px', cursor: 'pointer'}});
                            window.scrollTo(0, 0);
                        });

                        $('#sendall').click(function() {
                             //Screen berechnung mitte
                            var fhoehe = ((Fensterhoehe()/2)-(430/2));
                            var fweite = ((Fensterweite()/2)-(630/2));
                            $.blockUI.defaults = {
                            // styles for the message when blocking; if you wish to disable
                            // these and use an external stylesheet then do this in your code:
                            // $.blockUI.defaults.css = {};
                            css: {
                            padding:        0,
                            margin:         0,
                            top:            fhoehe,
                            left:           fweite,
                            textAlign:      'center',
                            color:          '#000',
                            border:         '0',
                            backgroundColor:'#fff',
                            cursor:         'default',
                            position:         'absolute'
                            },

                            // styles for the overlay
                            overlayCSS:  {
                            backgroundColor:'#000',
                            opacity:        '0.6'
                            },

                            // z-index for the blocking overlay
                            baseZ: 1000,

                            // set these to true to have the message automatically centered
                            centerX: true, // <-- only effects element blocking (page block controlled via css above)
                            centerY: true,

                            // allow body element to be stetched in ie6; this makes blocking look better
                            // on "short" pages.  disable if you wish to prevent changes to the body height
                            allowBodyStretch: true,

                            // be default blockUI will supress tab navigation from leaving blocking content;
                            constrainTabKey: true,

                            // fadeOut time in millis; set to 0 to disable fadeout on unblock
                            fadeOut:  400,

                            // suppresses the use of overlay styles on FF/Linux (due to significant performance issues with opacity)
                            applyPlatformOpacityRules: true
                            };
                            window.sendallPage = true;

                            $.blockUI({ message: $('#bel2-shader-pagetool'), css: { width: '630px' ,height:'430px', cursor: 'default'}});
                            window.scrollTo(0, 0);
                        });


                        $('#opensubpage').click(function(e) {
                           var pos = $(this).position();
                           $("#marklist2").css("top",pos.top + 26);
                           $("#marklist2").animate({
                              "height": "toggle", "opacity": "toggle"
                              }, 400);
                        });

                        $('#close_x').click(function() {
                            clicked = 'no';
                            $("#icon_change").replaceWith('<img  id="icon_change" border="0" src="fileadmin/templates/global/img/icon_page_right.gif"/>');
                        });


                        $('#mark').click(function() {
                                                var arrDel = $('#arrDel').text();
                                                var arrDel = document.getElementById('arrDel').innerHTML;
                                                counts = fillHistory(getlang_mark);
                                                if(arrDel != 'true'){
                                                    $("#container li").remove();
                                                    var mCookie = markerCookie.get(markerCookieName);
                                                    $.extend(mCookie,pageRealLink);
                                                    markerCookie.set(markerCookieName, mCookie);
                                                    var counts = fillHistory(getlang_mark);
                                                }else{
                                                    var arrDel = 'false';
                                                    $('#arrDel').text(arrDel);
                                                    markerCookie.set(markerCookieName, pageRealLink);
                                                    //var counts  = 1;
                                                    var counts = fillHistory(getlang_mark);
                                                }
                        });
                        $('#no').click(function() {
                                                $.unblockUI();
                                               // window.location.reload();
                                                return false;
                        });

                        $("#shader").keypress(function (e) {
                            var emailsender_mail  = document.getElementById('email_sender').value;
                            var emailreciver_mail = document.getElementById('email_reciver').value;
                            var matchPos11 = emailsender_mail.search('@');
                            var matchPos22 = emailreciver_mail.search('@');
                            if(matchPos11 != -1){
                                                    $("#errormail1").css("color","black");
                            }
                            if(matchPos22 != -1){
                                                    $("#errormail2").css("color","black");
                            }
                        });
                        $('#sendyes').click(function() {
                            var emailsender_mail  = document.getElementById('email_sender').value;
                            var emailreciver_mail = document.getElementById('email_reciver').value;
                            var matchPos1 = emailsender_mail.search('@');
                            var matchPos2 = emailreciver_mail.search('@');

                            if(matchPos1 != -1 && matchPos2 != -1){
                                var emailsender_mail  = document.getElementById('email_sender').value;
                                var emailreciver_mail = document.getElementById('email_reciver').value;
                                var emailtext_mail    = document.getElementById('email_text').value;
                                var pageEmailLink = $('#pagelink').text();
                                var pageEmailTitle = $('#pagetitle').text();
                                                                                                        //var pageEmailLink = document.getElementById('pagelink').innerHTML;
                                //var pageEmailTitle = document.getElementById('pagetitle').innerHTML;
                                if(window.sendallPage == true){
                                    $.get("index.php?id="+pagemailID+"&L="+L+"&no_cache=1&email_send_all=true&email_sender=" + encodeURIComponent(emailsender_mail)+"&email_reciver=" + encodeURIComponent(emailreciver_mail) +"&email_text=" + encodeURIComponent(emailtext_mail));
                                    sendallPage = false;
                                }
                                else{
                                    $.each(pageRealLink, function(title, link){
                                        var tmplinks = link.split(",");
                                        $.get("index.php?id="+pagemailID+"&L="+L+"&no_cache=1&email_sender=" + encodeURIComponent(emailsender_mail)+"&email_reciver=" + encodeURIComponent(emailreciver_mail) +"&email_text=" + encodeURIComponent(emailtext_mail) +"&email_page_title=" + encodeURIComponent(title) +"&email_page_url=" + encodeURIComponent(tmplinks[0]));
                                    });
                                }

                                $.blockUI({ message: email_send});
                                setTimeout($.unblockUI, 2000);
                                window.setTimeout("location.reload()", 2000);
                            }
                            else{
                                if(matchPos1 == -1){
                                    $("#errormail1").css("color","red");
                                }
                                if(matchPos2 == -1){
                                    $("#errormail2").css("color","red");
                                }
                            }
                        });

                        $('#no_shader').click(function() {
                            $.unblockUI();
                            //window.location.reload();
                            return false;
                        });
                    });

                    function fillHistory(getlang_mark){
                        var markerCookie = $.cookieJar('pagemarker');
                        var markerCookieName = 'Marker';
                        var mCookie = markerCookie.get(markerCookieName);
                        if (mCookie != null){

                            $('#opensubpage').text('0')
                            var counts = 0;
                            $.each( mCookie, function(i, n){

                                //$('#marklistcontainer').slideDown(400);
                                var tmplinks = n.split(",");
                                var arrDel= 'false';
                                $('#arrDel').text(arrDel);
                                counts++;
                                var content = ' <li id="subpagetool-bar_new'+counts+'">\n\
                                                    <p>\n\
                                                        <a href="javascript:void(0);">'+i+'</a>\n\
                                                    </p>\n\
                                                    <ul class="icons">\n\
                                                        <li class="empfehlen">\n\
                                                            <a class="subpagetool-mail" mail="'+i+'" href="javascript:void(0);">\n\
                                                                <span>empfehlen</span>\n\
                                                            </a>\n\
                                                        </li>\n\
                                                        <li class="drucken">\n\
                                                            <a class="subpagetool-print" href="'+tmplinks[1]+'">\n\
                                                                <span>drucken</span>\n\
                                                            </a>\n\
                                                        </li>\n\
                                                        <li class="loeschen">\n\
                                                            <a class="subpagetool-trash" delete="'+i+'" href="javascript:void(0);">\n\
                                                                <span>löschen</span>\n\
                                                            </a>\n\
                                                        </li>\n\
                                                    </ul>\n\
                                                </li>';

                                $("#container").append(content);
                                $('#opensubpage').text(counts)
                                $('#slideBtn').show();

                            });

                            pagetoolsBind();
                            return counts;

                        }else{
                            var arrDel= 'true';
                            $('#opensubpage').text('0');
                            $('#slideBtn').hide();
                            $('#arrDel').text(arrDel);
                        }


                    }

function checkMyhighlight(item){
    $(item).toggleClass("subpagetool-bar-h1");
    item = $(item).find('div div.subpagetool-icons');
    if($(item).css("display") == 'block'){
        $(item).css("display", "none");
    }else{
        $(item).css("display", "block");
    }
}


 function getPosition(id){
    ele = document.getElementById(id)
    var topValue= 0,leftValue= 0;
    while(ele){
      leftValue += ele.offsetLeft;
      topValue += ele.offsetTop;
      ele = ele.offsetParent;
      }
    result = new Array(leftValue, topValue);
    return result;
    }

function pagetoolsBind(getlang_mark){
                        $(".subpagetool-mail").bind("click", function(e){
                            var element = $(this) //.attr('id')
                            var node = $(this).attr('id')
                            var markerCookie = $.cookieJar('pagemarker');
                            var markerCookieName = 'Marker';
                            var index = $("a.subpagemail").index(this);
                            var elementAttr = $(this).attr('mail');
                            var mCookie = markerCookie.get(markerCookieName);

                            $('#pagetitle').text(elementAttr);
                            $('#pagelink').text(mCookie[elementAttr]);
                            sendPageClip = true;

                            ele = $(element).attr('id')
                            var topValue= 0,leftValue= 0;
                            while(ele){
                              leftValue += ele.offsetLeft;
                              topValue += ele.offsetTop;
                              ele = ele.offsetParent;
                              }
                            offsets = new Array(leftValue, topValue);


                            //Screen berechnung mitte

                            var vanillaLeft = (($(window).width() - (630)) / 2),
                                vanillaTop = (($(window).height() - (430)) / 2);
                            var resultLeft = vanillaLeft + $(window).scrollLeft() - offsets[0],
                                resultTop = vanillaTop + $(window).scrollTop() - offsets[1];

                            var topPix = (Fensterhoehe()/2) - (630/2);

                            $.blockUI.defaults = {
                            // styles for the message when blocking; if you wish to disable
                            // these and use an external stylesheet then do this in your code:
                            // $.blockUI.defaults.css = {};
                            css: {
                            padding:        0,
                            margin:         0,
                            top:            resultTop,
                            left:           resultLeft,
                            textAlign:      'center',
                            color:          '#000',
                            border:         '0',
                            backgroundColor:'#fff',
                            cursor:         'default',
                            position:         'absolute'
                            },

                            // styles for the overlay
                            overlayCSS:  {
                            backgroundColor:'#000',
                            opacity:        '0.6'
                            },

                            // z-index for the blocking overlay
                            baseZ: 1000,

                            // set these to true to have the message automatically centered
                            centerX: true, // <-- only effects element blocking (page block controlled via css above)
                            centerY: true,

                            // allow body element to be stetched in ie6; this makes blocking look better
                            // on "short" pages.  disable if you wish to prevent changes to the body height
                            allowBodyStretch: true,

                            // be default blockUI will supress tab navigation from leaving blocking content;
                            constrainTabKey: true,

                            // fadeOut time in millis; set to 0 to disable fadeout on unblock
                            fadeOut:  400,

                            // suppresses the use of overlay styles on FF/Linux (due to significant performance issues with opacity)
                            applyPlatformOpacityRules: true
                            };

                            $.each( pageRealLink, function(title, link){
                                var pageEmailTitle = title;
                                var pageEmailLink = link;
                            });

                            $.blockUI({ message: $('#bel2-shader-pagetool'), css: { width: '630px' ,height:'430px', cursor: 'pointer'}});

                            //$.blockUI({ message: $('#bel2-shader'), css: { width: '630px' ,height:'430px'}});

                        });

                        $(".subpagetool-trash").bind("click", function(e){
                            var getlang_mark = document.getElementById('marklist_text').innerHTML;
                            var markerCookie = $.cookieJar('pagemarker');
                            var markerCookieName = 'Marker';
                            //counts = fillHistory(getlang_mark);

                            $('#container').empty();
                            var elementAttr = $(this).attr('delete');
                            var mCookie = markerCookie.get(markerCookieName);
                            delete mCookie[elementAttr];

                            if(mCookie != {}){
                                markerCookie.set(markerCookieName, mCookie);
                            }
                            else{
                                markerCookie.set(markerCookieName, {});
                            }

                            var counts = fillHistory(getlang_mark);
                            if(counts == 0){
                                 $('#marklist2').slideUp(200);
                                 $('#slideBtn').hide();
                                 clicked = 'no';
                            }
                        });

}

// Fenster berechnen...

function Fensterweite () {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 0;
  }
}

function Fensterhoehe () {
  if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }
}

