﻿// DataHolder 

$(document).ready(function() {

    var llRootloc = $("[id='TheRootLoc']").html();

    $("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:absolute;display:none;'><table 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^='B4¬'],[id^='After¬'],[id^='First¬']").each(function() {
        $(this).css('height', '1px');

        if ($("#ctrlPageControlEditDiv").css('display') != "block") {
            $("body").css('margin-top', '37px');
            $("#ctrlPageControlEditDiv").css('display', 'block');
            Poplist();
        }
    });

    $("[id^='B4¬'],[id^='After¬'],[id^='First¬']").mouseover(function() {
        $(this).addClass('ViewBorder');
        $(this).css('height', '5px');
    });

    $("[id^='B4¬'],[id^='After¬'],[id^='First¬']").mouseout(function() {
        $(this).removeClass('ViewBorder');
        if ($("[id='Followme']").css("display") != "block") {
            $(this).css('height', '1px');
        }
    });

    // 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();

    $("#CMSHideAll").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(/CIOBS_SDK/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='<%=IRIS.CMS.Core.clsCommon.GetRootLocation() %>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='/CIOBS_SDK/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;
        });

    });

}
    
    
    