

function OnClientDragEnd(dockObj, eventArgs){

    //var dock = document.getElementById(dockObj.id);

    //DisplayPropertyNames(dockObj);			
    //DisplayWebpartAttributes(dockObj);   
    //window.setTimeout("OnClientDragEndTick(" + dock.getAttribute("webpartid") + ")",1000);
}

function OnClientDragEndTick(webpartid){

    //dockObj.GetRect().height
    //dockObj.GetRect().width
    
    var dock = document.getElementById(dockObj.id);
    
    var obj = new Object();
    
    obj.url = config_WebServiceUrl() + '/webpart_SaveSize';
    obj.WebPartID = webpartid;
    obj.Height = 0;
    obj.Width = 0;
    obj.onSuccess = OnClientDragEndCallback;
    
    window.status = "Saving WebPart Size";
    
    AjaxRequest.post(obj);
}

function OnClientDragEndCallback(request){

    window.status = " Webpart Resized " + request.parameters.Width + "," + request.parameters.Height;
    
}

function OnClientDock(dockObj, eventArgs){
    //var ajaxManager = GetAjaxManager();
    //ajaxManager.AjaxRequest("webpart");
    
    var dock = document.getElementById(dockObj.id);
    var obj = null;
    var docks = null;
    
    // Save Location ***************	
    obj = new Object();
    obj.url = config_WebServiceUrl() + '/webpart_SaveLocation';
    obj.WebPartID = dock.getAttribute("webpartid");
    obj.ColumnID = dockObj.ParentDockingZone.id.split("_")[1];
    obj.onSuccess = OnClientDockCallback;
    
    window.status = "Saving WebPart Location";
    
    AjaxRequest.post(obj);
    
    // Save Order ***************
    obj = new Object();
    dock = null;
    //var manager = GetDockManager();
    var zone = dockObj.ParentDockingZone;
    docks = zone.GetDockedObjects();
    
    if (docks.length > 0) {
    
        for (i = 0; i < docks.length; i++) {
        
            dock = document.getElementById(docks[i].id);
            
            obj.url = config_WebServiceUrl() + '/webpart_SaveOrder';
            obj.WebPartID = dock.getAttribute("webpartid");
            obj.WebPartOrder = i + 1;
            obj.onSuccess = OnClientDockSaveOrderCallback;
            
            window.status = "Saving WebPart Order";
            
            //alert(docks[i].id + " " + obj.WebPartOrder)
            AjaxRequest.post(obj);
        }
    }
}

function OnClientDockCallback(request){

    window.status = "WebPart Location Saved";
    
}

function OnClientDockSaveOrderCallback(request){

    window.status = "WebPart Order Saved";
}

function OnClientDockDelete(dockObj, command){
    var answer = confirm('Are you sure you want to DELETE this web part?');
    
    if (answer) {
		
        dockObj.Hide();
        
        var dock = document.getElementById(dockObj.id);
        
        var obj = new Object();
        
        obj.url = config_WebServiceUrl() + '/webpart_Delete';
        obj.WebPartID = dock.getAttribute("webpartid");
        obj.onSuccess = OnClientDockDeleteCallback;
        
        window.status = "Deleting WebPart";
        
        AjaxRequest.post(obj);
    }
    else {
    
    
    }
    
}

function OnClientDockDeleteCallback(request){
    window.status = "WebPart Deleted";
}

function OnClientDockSettings(dockObj, command){
    var url = "Forms/WebPartDetails.aspx?id=" + dockObj.webpartid;
    
    var oWindow = window.radopen(url, null);
    oWindow.SetSize(600, 370);
    oWindow.SetTitle("WebPart Settings");
    oWindow.Center();
    
}

function OnClientDockEdit(dockObj, command){
    var dock = document.getElementById(dockObj.id);
    var editurl = dock.getAttribute("editurl");

    var url = editurl + "?id=" + dockObj.webpartid;
    
    var oWindow = window.radopen(url, null);
    oWindow.SetSize(760, 600);
    oWindow.SetTitle("Module Options");
    oWindow.Center();
    
}

function OnClientDockRSS(dockObj, command){
	alert('Coming Soon!');
}

function OnClientDockAlerts(dockObj, command){
	alert('Coming Soon!');
}

function GetDockAttribute(dockObj, attribute){

    var dock = document.getElementById(dockObj.id);
    return dock.getAttribute(attribute);
}

function DisplayPropertyNames(obj){

    var debugDiv = document.getElementById("divDebug");
    var names = "";
    
    for (var name in obj) {
        names += "<li>" + name + "</li>";
    }
    debugDiv.innerHTML = names;
    
}

function DisplayWebpartAttributes(obj){

    var debugDiv = document.getElementById("divDebug");
    var names = "";
    
    for (var name in obj.attributes) {
        names += "<li>" + name + "</li>";
    }
    debugDiv.innerHTML = names;
    
}
