﻿/************************************************************************************************************
(C) www.dhtmlgoodies.com, January 2006
	
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
	
Thank you!
	
www.dhtmlgoodies.com
Alf Magne Kalleland
	
************************************************************************************************************/


var rectangleBorderWidth = 2; // Used to set correct size of the rectangle with red dashed border
var useRectangle = true;
var autoScrollSpeed = 5; // Autoscroll speed	- Higher = faster

/* The saveData function creates a string containing the ids of your dragable elements. 
	
The format of this string is as follow
	
id of item 1;id of item 2;id of item 3
	
i.e. a semi colon separated list. The id is something you put in as "id" attribute of your dragable elements.
	
*/

function saveData() {
    var saveString = "";
    for (var no = 0; no < dragableObjectArray.length; no++) {
        if (saveString.length > 0) saveString = saveString + ';';
        ref = dragableObjectArray[no];
        saveString = saveString + ref['obj'].id.replace('widget', '');
    }

    //alert(saveString);	// For demo only
    BlogEngine.createCallback(BlogEngine.webRoot + "admin/WidgetEditor.aspx?move=" + saveString + "&rnd=" + Math.random(), null);

    /* 	Put this item into a hidden form field and then submit the form 
		
		example:
		
		document.forms[0].itemOrder.value = saveString;
    document.forms[0].submit;
		
		On the server explode the values by use of server side script. Then update your database with the new item order
		
		*/
}


/* Don't change anything below here */



/*-----------------------------------------------------------------------------
WIDGET FRAMEWORK
-----------------------------------------------------------------------------*/

function editWidget(name, id) {
    window.scrollTo(0, 0);
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    var height = document.documentElement.clientHeight + document.documentElement.scrollTop;

    var layer = document.createElement('div');
    layer.style.zIndex = 1002;
    layer.id = 'layer';
    layer.style.position = 'absolute';
    layer.style.top = '0px';
    layer.style.left = '0px';
    layer.style.height = document.documentElement.scrollHeight + 'px';
    layer.style.width = width + 'px';
    layer.style.backgroundColor = 'black';
    layer.style.opacity = '.6';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
    document.body.style.position = 'static';
    document.body.appendChild(layer);

    var size = { 'height': 500, 'width': 750 };
    var iframe = document.createElement('iframe');
    iframe.name = 'Widget Editor';
    iframe.id = 'WidgetEditor';
    iframe.src = BlogEngine.webRoot + 'admin/WidgetEditor.aspx?widget=' + name + '&id=' + id;
    iframe.style.height = size.height + 'px';
    iframe.style.width = size.width + 'px';
    iframe.style.position = 'fixed';
    iframe.style.zIndex = 1003;
    iframe.style.backgroundColor = 'white';
    iframe.style.border = '4px solid silver';
    iframe.frameborder = '0';

    iframe.style.top = ((height + document.documentElement.scrollTop) / 2) - (size.height / 2) + 'px';
    iframe.style.left = (width / 2) - (size.width / 2) + 'px';

    document.body.appendChild(iframe);
}

function addWidget(type) {
    BlogEngine.createCallback(BlogEngine.webRoot + "admin/WidgetEditor.aspx?add=" + type + "&rnd=" + Math.random(), appendWidget);
}

function appendWidget(response) {
    if (response == "reload") {
        location.reload();
    }
    else {
        var zone = BlogEngine.$('widgetzone');
        zone.innerHTML += response;
    }
}

function removeWidget(id) {
    if (confirm('Вы действительно хотите удалить этот виджет?')) {
        BlogEngine.createCallback(BlogEngine.webRoot + "admin/WidgetEditor.aspx?remove=" + id + "&rnd=" + Math.random(), null);
        BlogEngine.$('widget' + id).style.display = 'none';
    }
}

function closeEditor() {
    document.body.removeChild(BlogEngine.$('WidgetEditor'));
    document.body.removeChild(BlogEngine.$('layer'));
    document.body.style.position = '';
}

