$ddj = jQuery.noConflict();

var count = 0;
var arrItems = new Array()
/***********************************************************************
Purpose : Drag and Drop panel using jQuery
Created By : SAKTHI GOPINATH S
Created Date : 25-May-2011
***********************************************************************/
$ddj(function(){
   $ddj('.hdrTooltip').attr("title", "Drag the panel");
   $ddj('.form-box').each(function(){  
   $ddj('h1').mouseover(function() {title :'Drag and Drop';});
   $ddj(this).find('h1').hover(function(){  
       $ddj(this).find('#configure').css('visibility', 'visible');  
   }, function(){  
       $ddj(this).find('#configure').css('visibility', 'hidden');  
   })
   .click(function(){  
       $ddj(this).siblings('.form-tbl').toggle();  
   })  
   .end()
   .find('#configure').css('visibility', 'hidden');    
   });   
   
   $ddj(window).unload( function (){onWindowsUnload();});
   
   $ddj('.column').sortable({  
   connectWith: '.column',  
   handle: 'h1',  
   cursor: 'move',  
   placeholder: 'placeholder',  
   forcePlaceholderSize: true,  
   opacity: 0.4,  
   stop: function(event, ui){  
   $ddj(ui.item).find('h1').click(); 
   updateWidgetData();   
   count = 0;
   } }).disableSelection();  
   
});
/***********************************************************************
Function Name : updateWidgetData
Purpose : To store the details of orders of panel
Created By : SAKTHI GOPINATH S
Created Date : 25-May-2011
***********************************************************************/
function updateWidgetData() {
 //var items = [];
 $ddj('.column').each(function() {
 var columnId = $ddj(this).attr('id');
 $ddj('.form-box', this).each(function(i) {
 var collapsed = 0;
 if ($ddj(this).find('.form-tbl').css('display') == "none")
 collapsed = 1;
 arrItems[count]='id=' + $ddj(this).attr('id') +'&collapsed=' + collapsed + '&order=' + i + '&column=' + columnId;
 count++;
 //$ddj.post('../Forms/Widgets.aspx', 'id=' + $ddj(this).attr('id') +
 //'&collapsed=' + collapsed + '&order=' + i + '&column=' + columnId, function(response) {});
 });
 });
 }
/***********************************************************************
Function Name : onWindowsUnload
Purpose : To check whether panel changes or not in Unload
Created By : SAKTHI GOPINATH S
Created Date : 25-May-2011
***********************************************************************/
function onWindowsUnload()
{
    if(arrItems.length != 0)
    {
        if(confirm("Are you sure you want to save the settings?"))
        {
            for(var j=0;j<arrItems.length;j=j+1)
            {
                var dataString = arrItems[j].toString();
                $ddj.post('../Forms/Widgets.aspx?'+dataString);
            }
        }
    }
}

//window.onbeforeunload = function (e) {
//    e = e || window.event;
//    e.preventDefault = true;
//    e.cancelBubble = true;
//    e.returnValue = 'test';
//    //onWindowsUnload();
//}