﻿// Copyright (c) Omar AL Zabir. All rights reserved.
// For continued development and updates, visit http://msmvps.com/omar

function DeleteWidget(instanceId)
{
   Personalisation.Webservices.WidgetService.DeleteWidgetInstance(instanceId);
   var theDiv = document.getElementById("Template_homepagePods_WidgetPanelsLayout_WidgetContainer" + instanceId + "_Widget");
   
   //alert("ID of Control: " + theDiv);
   
   theDiv.style.display = "none";
}

function onDrop( sender, e )
{
    var container = e.get_container();
    var item = e.get_droppedItem();
    var position = e.get_position();
    
    //alert( String.format( "Container: {0}, Item: {1}, Position: {2}", container.id, item.id, position ) );
    
    var instanceId = parseInt(item.getAttribute("InstanceId"));
    var columnNo = parseInt(container.getAttribute("columnNo"));
    var row = position;
    
    //alert(instanceId + " " + columnNo + " " + row);
    
    Personalisation.Webservices.WidgetService.MoveWidgetInstance( instanceId, columnNo, row );
}
function $hide(id)
{
    document.getElementById(id).style.display="none";
}

function pageUnload()
{
    
}

var Utility = 
{
    // change to display:none
    nodisplay : function(e) 
    { 
        if( typeof e == "object") e.style.display = "none"; else if( $get(e) != null ) $get(e).style.display = "none"; 
    },
    // change to display:block
    display : function (e,inline) 
    { 
        if( typeof e == "object") e.style.display = (inline?"inline":"block"); else if( $get(e) != null ) $get(e).style.display = (inline?"inline":"block"); 
    },
    getContentHeight : function()
        {
        if( document.body && document.body.offsetHeight ) {
            return document.body.offsetHeight;
        }
    },


    blockUI : function()
    {
        Utility.display('blockUI');
        var blockUI = $get('blockUI');
    
        if( blockUI != null ) // it will be null if called from CompactFramework
        blockUI.style.height = Math.max( Utility.getContentHeight(), 1000) + "px";    
    },

    unblockUI : function()
    {
        Utility.nodisplay('blockUI');
    }
};

function winopen_withlocationbar(url) 
{
 var w = screen.width / 2;
 var h = screen.height /2;
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

  window.open(url, "_blank");
  
  return;
}

function winopen2(url,target, w, h) 
{
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

 if(popupWin_2[target] != null)
	if(!popupWin_2[target].closed)
		popupWin_2[target].focus();
	else
		popupWin_2[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  else
	popupWin_2[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  
  return;
}