function delete_it(url) {
    confirmation=confirm('Are you sure you want to delete this item and all related info (i.e child nodes, images etc.)? ','');
    if (confirmation) {
        window.location=url;
    }
    else {
        alert("Deletion cancelled.");
    }
}

if( $('Inputskin_collectionSID') ){
    /*/////////////////////////////////////////////////////////////////////////////////////////////
    // Dynamic Template / Layout Toggling
    /*/////////////////////////////////////////////////////////////////////////////////////////////
    $('Inputskin_collectionSID').addEvent('change',function(){
        var pars = 'page_type_sid='+$('InputPageTypeSID').options[$('InputPageTypeSID').selectedIndex].value
        +'&skin_collection_sid='+$('Inputskin_collectionSID').options[$('Inputskin_collectionSID').selectedIndex].value
        +'&page_sid='+$('PageSID').value;
        if ($('Inputskin_collectionSID').options[$('Inputskin_collectionSID').selectedIndex].value != ""){
            new Ajax( '/ajax/select_layout.php', {
                method: 'post',
                postBody: pars,
                onComplete: LayoutPreview,
                update: $('InputSkinSIDDiv')
            } ).request();
        }
    });
    $('InputPageTypeSID').addEvent('change',function(){
        var pars = 'page_type_sid='+$('InputPageTypeSID').options[$('InputPageTypeSID').selectedIndex].value
        +'&skin_collection_sid='+$('Inputskin_collectionSID').options[$('Inputskin_collectionSID').selectedIndex].value
        +'&page_sid='+$('PageSID').value;
        if ($('Inputskin_collectionSID').options[$('Inputskin_collectionSID').selectedIndex].value != ""){
            new Ajax( '/ajax/select_layout.php', {
                method: 'post',
                postBody: pars,
                onComplete: LayoutPreview,
                update: $('InputSkinSIDDiv')
            } ).request();
        }
    });
}

function LayoutPreview(){
    $$('div#InputSkinSIDDiv img').each(function(el){
        $(el).style.cursor = 'pointer';
        $(el).addEvent('click',function(){
            //give all layout previews a pointer, then inject large image into prompt preview and close after 5 seconds.
            var image = new Element('img');
            image.src = el.src.replace("thumb_s_","thumb_l_");
            image.setStyle('padding-left','10px');
            var closeLabel = new Element('img').setProperties({
            'src': '/skin/shared/images/closelabel.gif'
            }).setStyle('cursor','pointer');
            var imgButton = new Element('img').setProperties({
            'src': '/skin/shared/images/closelabel.gif',
            'class': 'closeButton'
            });
            var boxHtml = new MooPrompt('Layout Preview - Click close to return to the admin section.', image, {
                buttons: 2,
                button1: closeLabel,
                button2: imgButton,
                width: 525,
                height: 550
            });
        });
    });
}

function pagePreview(){
    $$('.Preview').each(function(el){
        $(el).style.cursor = 'pointer';

        $(el).addEvent('click',function(evt){
            var e = new Event(evt).stop();
            var iframe = new Element('iframe').setProperties({'src': el.href+'?preview=true', 'frameborder':'0'}).setStyles({'width':window.getWidth()+'px','height':eval(window.getHeight()-50)+'px'});
            var closeLabel = new Element('img').setProperties({
            'src': '/skin/shared/images/closelabel.gif'
            }).setStyle('cursor','pointer');
            var imgButton = new Element('img').setProperties({
            'src': '/skin/shared/images/closelabel.gif',
            'class': 'closeButton'
            });
            var boxHtml = new MooPrompt('Page Preview - Click close to return to the admin section.', iframe, {
                buttons: 2,
                button1: closeLabel,
                button2: imgButton,
                width: window.getWidth(),
                height: window.getHeight()
            });
        });
    });
}

/*/////////////////////////////////////////////////////////////////////////////////////////////
// 	Add remove input Fields for multiple file uploads.
/*/////////////////////////////////////////////////////////////////////////////////////////////
function updateCount(){
    var count = $$('.fileUploads').length;
    $('count').value = count;
    //	alert(count);
}

function removeInput(el){ el.remove() }

if($('add')){
    $('add').addEvent('click',function(){
        if( $$('.fileUploads').length < 5){
            var clone = $('uploadInnerContainer').clone();
            clone.setOpacity(0);
            clone.injectAfter( $('uploadInnerContainer') );
            var clonefx = new Fx.Styles(clone, {'duration': 500, 'wait': false});
            clonefx.start({'opacity': 1, transition: Fx.Transitions.quartOut});
            updateCount();
        }else{
            alert('Sorry, you can only add up to 5 upload fields.');
        }

    });
    $('remove').addEvent('click',function(){
        if( $$('.fileUploads').length > 1){
            var clonefx = new Fx.Styles( $('uploadOuterContainer').getLast(), {'duration': 500, 'wait': false});
            clonefx.start({'opacity': 0, transition: Fx.Transitions.quartOut});
            updateCount(); removeInput.delay(500, null, [ $(  $('uploadOuterContainer').getLast() ) ]);
        }else{
            alert('Sorry, you have atleast 1 upload field.');
        }
    });
}
/*/////////////////////////////////////////////////////////////////////////////////////////////
// 	Add remove input Fields for multiple file uploads. _pdf
/*/////////////////////////////////////////////////////////////////////////////////////////////
function updateCount(){
    var countFile = $$('.fileUploadsFile').length;
    $('countFile').value = countFile;
    //	alert(count);
}

function removeInput(el){ el.remove() }

if($('addFile')){
    $('addFile').addEvent('click',function(){
        if( $$('.fileUploadsFile').length < 5){
            var clone = $('uploadInnerContainerFile').clone();
            clone.setOpacity(0);
            clone.injectAfter( $('uploadInnerContainerFile') );
            var clonefx = new Fx.Styles(clone, {'duration': 500, 'wait': false});
            clonefx.start({'opacity': 1, transition: Fx.Transitions.quartOut});
            updateCount();
        }else{
            alert('Sorry, you can only add up to 5 upload fields.');
        }

    });
    $('removeFile').addEvent('click',function(){
        if( $$('.fileUploadsFile').length > 1){
            var clonefx = new Fx.Styles( $('uploadOuterContainerFile').getLast(), {'duration': 500, 'wait': false});
            clonefx.start({'opacity': 0, transition: Fx.Transitions.quartOut});
            updateCount(); removeInput.delay(500, null, [ $(  $('uploadOuterContainerFile').getLast() ) ]);
        }else{
            alert('Sorry, you have atleast 1 upload field.');
        }
    });
}

/*/////////////////////////////////////////////////////////////////////////////////////////////
// 	TinyMce Content Editor and File Browser
/*/////////////////////////////////////////////////////////////////////////////////////////////
if( $$('textarea').length > 0){

    tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        plugins : "table",
        theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink,|,image,|,code",
        theme_advanced_buttons2 : "outdent,indent,separator,sub,sup,separator,forecolor,backcolor,charmap,separator,cleanup,removeformat",
        theme_advanced_buttons3 : "tablecontrols",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_path_location : "bottom",
        extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
        file_browser_callback : "fileBrowserCallBack",
        paste_use_dialog : false,
        theme_advanced_resizing : true,
        theme_advanced_resize_horizontal : false,
        apply_source_formatting : false,
        convert_urls : true,
        relative_urls : false,
        remove_script_host : true,
        auto_resize : false,
        width: 550
    });
    /*/////////////////////////////////////////////////////////////////////////////////////////////
    // 	TinyMce Content Editor and File Browser
    /*/////////////////////////////////////////////////////////////////////////////////////////////
    function fileBrowserCallBack(field_name, url, type, win) {
        var connector = "../../filemanager/browser.html?Connector=connectors/php/connector.php";
        var enableAutoTypeSelection = true;
        var cType;
        tinymcpuk_field = field_name;
        tinymcpuk = win;
        switch (type) {
            case "image":
            cType = "Image";
            break;
            case "flash":
            cType = "Flash";
            break;
            case "file":
            cType = "File";
            break;
        }
        if (enableAutoTypeSelection && cType) {	connector += "&Type=" + cType;	}
        window.open(connector, "tinymcpuk", "modal,width=600,height=400");
    }
}


window.addEvent('resize', function() {
    $('wrapper').setStyle('height',eval(window.getHeight()-124)+'px');
});

window.addEvent('load', function() {
    if ( $('InputSkinSIDDiv') ) LayoutPreview();
    if ( $$('.Preview')[0] ) pagePreview();
    $('wrapper').setStyle('height',eval(window.getHeight()-124)+'px');
});

window.addEvent('domready', function(){
    if ( $('multyUpload') ){
        var input = $('multyUpload');
        var uplooad = new FancyUpload(input, {
            swf: '/admin/skin/skin1/js/fancyupload/Swiff.Uploader.swf',
            url: fancyUploadHref,
            queueList: 'queue',
            onAllComplete: function(){
                $('sortImage').src=$('sortImage').src+' ';
                uplooad.clearList();
            },
            container: $('FieldButton')
        });
        $('status').adopt(new Element('a', {
            href: 'javascript:void(null);',
            events: {
                click: uplooad.clearList.bind(uplooad, [false])
            }
        }).setHTML('Clear Completed'));
    }

    if ( $$('TreeRow') ){
        $$('.TreeRow').each(function(el){
            var icn = $(el).getChildren()[2];

            $(el).addEvent('mouseover',function(){
                $(el).setStyle('border-top','1px solid #CCCCCC');
                $(el).setStyle('border-right','1px solid #CCCCCC');
                icn.setOpacity(1);
            });

            $(el).addEvent('mouseout',function(){
                $(el).setStyle('border-top','1px solid #FFFFFF');
                $(el).setStyle('border-right','1px solid #FFFFFF');
                icn.setOpacity(0);
            });

            icn.setOpacity(0);
        });
    }

});