﻿// DataHolder

$(document).ready(function() {

    $("body").append("<div id='Followme' style='position:absolute;display:none'></div>");
    $("body").append("<div id='ContentIDData' style='position:absolute;display:none'></div>");
    $("body").append("<div id='CMSHideAll' style='position:fixed;display:none;'><table width='100%' height='100%' style=\"width:100%;height:100%;\"><tr><td style='text-align:center;vertical-align:middle;'></td></tr></table></div>");
    $("body").append("<div id='CMSHideAllBar' style='position:absolute;display:none;'><table width='100%' height='100%' style=\"width:100%;height:100%;\"><tr><td style='text-align:center;vertical-align:middle;'><img  src='" + llRootloc + "Images/ajax-loaderBar1.gif' /></td></tr></table></div>");


    $("[id^='First¬']").each(function() {
        $(this).css('height', '20px');

        if ($("#ctrlPageControlEditDiv").css('display') != "block") {
            $("body").css('margin-top', '37px');
            $("#ctrlPageControlEditDiv").css('display', 'block');
            Poplist();
        }
    });

    $("[id^='First¬']").click(function() {
        var a_First = $(this).attr('id').split('¬');

        $("[id^='B4¬'],[id^='After¬'],[id^='First¬']").mouseout(function() {
            $(this).removeClass('ViewBorder');
            if ($("[id='Followme']").css("display") != "block") {
                $(this).css('background', '');
            }
        });

        $("[id$='" + a_First[3] + "']").each(function() {
            $(this).css('height', '20px');
            $(this).css('padding', '2px');
            $(this).css('border', 'solid 1px blue');

        });

    });

    $("[id^='B4¬'],[id^='After¬'],[id^='First¬']").mouseover(function() {
        $(this).addClass('ViewBorder');
        $(this).css('background', '#fff url(\'' + llRootloc + 'images/snake_transparent.gif\') left top no-repeat');
    });

    $("[id^='B4¬'],[id^='After¬'],[id^='First¬']").mouseout(function() {
        $(this).removeClass('ViewBorder');
        if ($("[id='Followme']").css("display") != "block") {
            $(this).css('background', '');
        }
    });

    // Control Hover 
    $("[id^='Content¬'] [id$='divlblHeader']").mouseover(function() {
        if ($("[id='Followme']").css("display") != "block") {
            $(this).addClass('ViewBorder');
        }
    });

    $("[id^='Content¬'] [id$='divlblHeader']").mouseout(function() {
        $(this).removeClass('ViewBorder');
    });

    // Drag Drop 
    //drag    
    $("[id^='Content¬']").mouseup(function() {
        var ContentHtml = $(this).html();
        $(this).html("");

        $("[id='ContentIDData']").html($(this).attr("id"));

        $("[id='Followme']").html(ContentHtml);
        $("[id='Followme']").css("display", "block");

        $("body").mouseover(function(e) {
            $("[id='Followme']").css("top", e.pageY + 15 + "px")
                                                 .css("left", e.pageX + 15 + "px");
        });
        return false;
    });
    // Drop 
    $("[id^='B4¬'],[id^='After¬'],[id^='First¬']").click(function() {
        if ($("[id='Followme']").css("display") == "block") {
            $("body").unbind("mouseover");

            $(this).html($("[id='Followme']").html());

            $("[id='Followme']").html("")
                                        .css("display", "none")
                                        .css("top", "-1px")
                                        .css("left", "-1px");

            //$(this).css('height','none');

            var drap = $("[id='ContentIDData']").html();
            var drop = $(this).attr("id");

            MoveControlTo(drap, drop);

        }
        return false;
    });
});




function MoveControlTo(DragData, DropData) {
    // alert(DragData + DropData);
    var lHeight = $("body").height();
    var lwidth = $("body").width();
    $("#CMSHideAll").css('opacity', '0.5')
                       .css('background-color', "black")
                       .css('height', "100%")
                       .css('width', "100%")
                       .css('top', "0")
                       .css('left', "0")
                       .show();
    $("#CMSHideAllBar").css('background-color', "transparent")
                       .css('height', "100%")
                       .css('width', "100%")
                       .css('top', "0")
                       .css('left', "0")
                       .show();

    $("#CMSHideAll").click(function() { return false; });
    $("#CMSHideAllBar").click(function() { return false; });

    Anthem_InvokePageMethod('MoveControlTo', [DragData, DropData], AjaxRefreshPageCallBack);
}

function AjaxRefreshPageCallBack(response) {
    //alert(response.value);
    document.location.href = document.location.href;
}

function Poplist() {
    $(document).ready(function() {

        $('#ctrlPageControlEditDiv').css('background', 'url(' + llRootloc + 'images/Background_bar.jpg) top left repeat-x');
        $('#ctrlPageCEDPleasWait').append("<span style='color:white;vertical-align:top; margin-top:1px;'>Loading Please wait</span><img  src='" + llRootloc + "Images/ajax-loaderBar1.gif' alt='Loading' />");
        $('#ctrlPageCEDPleasWait').css('z-index', '2')
                                      .css('width', '100%')
                                      .css('height', '35px')
                                      .show();

        PopulateDropDown();

        $("[id$='_ZZ_AddControlToPage']").click(function(e) {
            var drap = 'New¬' + $('[id$="_cboControlList"] option:selected').val();

            $("[id='ContentIDData']").html(drap);

            $("[id='Followme']").html("<img  src='" + llRootloc + "Images/AddNew.gif' alt='Add New'/>");
            $("[id='Followme']").css("display", "block");
            $("[id='Followme']").css("top", e.pageY + 15 + "px")
                                                 .css("left", e.pageX + 15 + "px");

            $("body").mouseover(function(e) {
                $("[id='Followme']").css("top", e.pageY + 15 + "px")
                                                 .css("left", e.pageX + 15 + "px");
            });
            return false;

        });

        $("[id$='_ZZ_lnkTrash']").click(function() {

            if (confirm("are you sure you would like to delete this Control for the page")) {
                if ($("[id='Followme']").css("display") == "block") {
                    $("body").unbind("mouseover");

                    $("[id='Followme']").html("")
                                        .css("display", "none")
                                        .css("top", "-1px")
                                        .css("left", "-1px");

                    //$(this).css('height','none');

                    var drap = $("[id='ContentIDData']").html();

                    RemoveControlFromPage(drap);

                }

            }
            return false;
        });

    });

}

function LoadData(urlData) {
    if (urlData != 'NOLOGIN') {
        showBlock();
        
        var EditLoad = window.showModalDialog(llRootloc + 'mainwebsite/ctrlEdit.aspx?Data=' + urlData, null, 'status:no;dialogWidth:545px;dialogHeight:620px;dialogHide:false;help:no;scroll:no');
        if (EditLoad) {
            if (EditLoad != "undefined") {
                if (EditLoad == "Save" || EditLoad == "SaveExit") {
                    // debug code

                    //alert(window.location.href);
                    
                    window.location.href = window.location.href;
                    
                    $(document).ready(function() {
                        // production code
                        // window.location.reload(true);
                    });
                }
            }
        }
     
    }
    else {
        alert('Your no longer logged in !!');
    }
}

function showBlock() {
   
    $("#CMSHideAll").css('opacity', '0.5')
                    .css('background-color', 'black')
                    .css('height', '100%')
                    .css('width', '100%')
                    .css('top', '0')
                    .css('left', '0')
                    .show();

    $("#CMSHideAllBar").css('background-color', 'transparent').css('height', '100%').css('width', '100%').css('top', '0').css('left', '0').show();
    $("#CMSHideAll").click(function() { return false; });
    $("#CMSHideAllBar").click(function() { return false; });

}

function clickButton(e, buttonid) {
    var bt = document.getElementById(buttonid);
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                bt.click();
                return false;
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
} 



    
    