﻿// Copyright (c) Omar AL Zabir. All rights reserved.
// For continued development and updates, visit http://msmvps.com/omar

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;
  Dashboard.WebServices.WidgetService.MoveWidgetInstance( instanceId, columnNo, row );
}

function $hide(id)
{
  document.getElementById(id).style.display="none";
}

function pageUnload()
{
}

function showHelp()
{
  var request = new Sys.Net.WebRequest();
  request.set_httpVerb("GET");
  request.set_url('help.aspx');
  request.add_completed( function( executor )
  {
		if (executor.get_responseAvailable()) 
		{
			var helpDiv = $get('HelpDiv');
			var helpLink = $get('HelpLink');
	    
			var helpLinkBounds = Sys.UI.DomElement.getBounds(helpLink);
	    
			helpDiv.style.top = (helpLinkBounds.y + helpLinkBounds.height) + "px";
	    
			var content = executor.get_responseData();
			helpDiv.innerHTML = content;
			helpDiv.style.display = "block";                       
    }
  });
    
  var executor = new Sys.Net.XMLHttpExecutor();
  request.set_executor(executor); 
  executor.executeRequest();
}

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');
  }
};

var DeleteWarning =
{
  yesCallback : null,
  noCallback : null,
  _initialized : false,
  
  init : function()
  {
    if( DeleteWarning._initialized ) return;

    DeleteWarning._initialized = true;
  },
  
  show : function( yesCallback, noCallback )
  {
    var showButton = $get('ShowDeleteConfirmPopupButton');

		showButton.click();
        
    DeleteWarning.yesCallback = yesCallback;
    DeleteWarning.noCallback = noCallback;
    
    $addHandler( $get("DeleteConfirmPopup_Yes"), 'click', DeleteWarning._yesHandler );
    $addHandler( $get("DeleteConfirmPopup_No"), 'click', DeleteWarning._noHandler );
  },

  hide : function()
  {
    DeleteWarning.init();
        
    var hideButton = $get('HideDeleteConfirmPopupButton');
    
    $clearHandlers( $get('DeleteConfirmPopup_Yes') );

    hideButton.click();
  },
  
  _yesHandler : function()
  {
    DeleteWarning.hide();
    DeleteWarning.yesCallback();    
	},
	
	_noHandler : function()
	{
    DeleteWarning.hide();
    DeleteWarning.noCallback();
  }
};