
/**************************************
    Webutler V3.0 - www.webutler.de
    Copyright (c) 2008 - 2014
    Autor: Sven Zinke
    Free for any use
    Lizenz: GPL
**************************************/


function WBeditbox_requestdelete(txt) {
	if(confirm(txt)) {
        return true;
	}
    return false;
}

function WBeditbox_copyfrom() {
    if(document.getElementById('webutler_newfrom').checked == true) {
    	document.getElementById('webutler_copyrow').style.display = '';
    	document.getElementById('webutler_layoutrow').style.display = 'none';
    }
    else {
    	document.getElementById('webutler_layoutrow').style.display = '';
    	document.getElementById('webutler_copyrow').style.display = 'none';
    }
}

function WBeditbox_changeblockedpage(from, to) {
    var item, newitem;
	if(document.getElementById(from).value != '') {
        item = document.getElementById(from).options[document.getElementById(from).selectedIndex];
        newitem = new Option(item.value, item.value, false, true);
        document.getElementById(from).removeChild(item);
		document.getElementById(to).options[document.getElementById(to).options.length] = newitem;
	}
}

function WBeditbox_savelistedpages(list, temp) {
    var pages = new Array();
    for(var i = 0; i < document.getElementById(list).options.length; i++) {
        pages.push(document.getElementById(list).options[i].value);
    }
    document.getElementById(temp).value = pages.join(',');
	return true;
}

function WBeditbox_vorschau(url, txt) {
	if(url.substring(parseInt(url.lastIndexOf('=')+1), url.length) == "") {
        alert(txt);
	}
	else {
		var show = window.open('index.php?' + url, 'vorschau', 'width=800, height=500, top=50, left=50, status=1, toolbar=1, menubar=1, location=0, scrollbars=1, resizable=1');	
		show.focus();
	}
}

function WBeditbox_dopublic(page) {
    $('#webutler_loadingscreen').css('display', 'block');
    $.ajax({
        type: 'post',
        url: 'admin/system/save.php',
        data: 'dopublicpage=' + page,
        success: function(datas) {
			if(datas != '') {
				var data = datas.split('###');
				alert(data[1]);
				if(data[0] == 'ok') {
					window.location = 'index.php?page=' + page;
				}
				else {
					$('#webutler_loadingscreen').css('display', 'none');
				}
			}
        }
    });
    return false;
}

function WBeditbox_deltemp(page, txt) {
	if(confirm(txt)) {
		$('#webutler_loadingscreen').css('display', 'block');
		$.ajax({
			type: 'post',
			url: 'admin/system/save.php',
			data: 'deltemppage=' + page,
			success: function(datas) {
				if(datas != '') {
					var data = datas.split('###');
					if(data[0] == 'ok') {
						window.location = 'index.php?page=' + page;
					}
					else {
						alert(data[1]);
						$('#webutler_loadingscreen').css('display', 'none');
					}
				}
			}
		});
	}
    return false;
}

function WBeditbox_checkbak(folder) {
    var file = $('#webutler_' + folder + 'box').val();
    $.ajax({
        type: 'post',
        url: 'admin/system/boxes.php',
        data: 'webutler_checkbak=1&folder=' + folder + '&file=' + file,
        success: function(datas) {
            var data = datas.split('###');
            $('#webutler_' + folder + 'bakbutton').val(data[2]);
            $('.webutler_boxesform').attr('action', 'index.php?page=' + locationPage);
            $('#webutler_' + folder + 'bakcheck').attr('checked', false).attr('disabled', (data[0] == 'exists') ? false : true);
            $('#webutler_' + folder + 'baklabel').html(data[1]);
            $('#webutler_' + folder + 'bakpreview').click(function() {
                if($('#webutler_' + folder + 'bakcheck').is(':checked'))
                    WBeditbox_vorschau(folder + 'file=' + file + '.bak', '');
                else
                    WBeditbox_vorschau(folder + 'file=' + file, '');
            });
            $('#webutler_' + folder + 'bakcheck').click(function() {
                if($(this).is(':checked')) {
                    $('.webutler_boxesform').removeAttr('action');
                    $('#webutler_' + folder + 'bakbutton').val(data[3]);
                }
                else {
                    $('.webutler_boxesform').attr('action', 'index.php?page=' + locationPage);
                    $('#webutler_' + folder + 'bakbutton').val(data[2]);
                }
            });
        }
    });
}

function WBeditbox_opennewwin(url) {
	if(url != "") {
    	var showwin = window.open(url, 'fenster', 'width=900,height=500,top=50,left=50,status=1,toolbar=1,menubar=1,location=0,scrollbars=1,resizable=1');
    	showwin.focus();
	}
}

function WBeditbox_checkfile(file) {
    $.ajax({
        type: 'post',
        url: 'admin/system/save.php',
        data: 'checkfileexists=' + file,
        success: function(data) {
            if(file != 'offline') {
                if(data != '') {
                    alert(data);
                }
                else {
                    if(file == 'forms')
                        WBeditbox_open('webutler_forms');
                    if(file == 'langs')
                        WBeditbox_open('webutler_langs', 'langtrcodes=1');
                    if(file == 'categories')
                        WBeditbox_open('webutler_categories');
                    if(file == 'linkhighlite')
                        WBeditbox_open('webutler_linkhighlite', 'highfilestr=1');
                }
            }
        }
    });
    return false;
}

function WBeditbox_open(win, sub, posts) {
    if(win == 'webutler_newpage') {
        $.ajax({
            type: 'post',
            url: 'admin/system/save.php',
            data: 'checkfileexists=offline'
        });
    }
    
	var blockerbg = $('#webutler_blockerbackground');
	var blockerdiv = $('#webutler_blockerdiv');
	var sliderdiv = $('#webutler_sliderdiv');
	var boxwindow = $('#webutler_boxwindow');
	
    if(blockerbg.is(':hidden'))
        blockerbg.animate({ opacity: 0.6 }, 50).fadeIn('fast');
    if(blockerdiv.is(':hidden'))
    	blockerdiv.fadeIn('fast');
    
    var ajaxurl, ajaxpost;
    
    if(win == 'webutler_access') {
	    ajaxurl = 'admin/system/boxuser.php';
        if(sub != '' && sub != undefined) ajaxurl += '?' + sub;
        ajaxpost = win + '=1&locationpage=' + locationPage;
        if(posts != '' && posts != undefined) ajaxpost += '&' + posts;
    }
    else if(win == 'webutler_langs' && sub == '') {
        WBeditbox_open(win, 'langtrcodes=1');
        return false;
    }
    else if(win == 'webutler_linkhighlite' && sub == '') {
        WBeditbox_open(win, 'highfilestr=1');
        return false;
    }
    else {
        ajaxurl = 'admin/system/boxes.php';
        ajaxpost = win + '=1&locationpage=' + locationPage;
        if(sub != '' && sub != undefined) ajaxpost += '&' + sub;
    }
    
    $.ajax({
        type: 'post',
        url: ajaxurl,
        data: ajaxpost,
        success: function(data) {
            boxwindow.html(data);
            boxwindow.show(function() {
                if(win == 'webutler_categories' && !$('#webutler_showeditcat').is(':visible')) {
                    $('#webutler_showeditcat').removeAttr('style');
            	}
                if(win == 'webutler_langs' && !$('#webutler_showeditlang').is(':visible')) {
                    $('#webutler_showeditlang').removeAttr('style');
            	}
                if(win == 'webutler_pagecats') {
                    $('#webutler_oldcategorie').val($('#webutler_newcategorie').val());
                }
                $('.langposup').bind('click', function() {
                    $.ajax({
                        type: 'post',
                        url: 'admin/system/save.php',
                        data: 'langposup=' + $(this).attr('name'),
                        success: function() {
                            WBeditbox_open(win, 'langtrcodes=1');
                        }
                    });
                    return false;
                });
                $('.langposdown').bind('click', function() {
                    $.ajax({
                        type: 'post',
                        url: 'admin/system/save.php',
                        data: 'langposdown=' + $(this).attr('name'),
                        success: function() {
                            WBeditbox_open(win, 'langtrcodes=1');
                        }
                    });
                    return false;
                });
                $('.webutler_delhighlitefile').bind('click', function() {
                    $.ajax({
                        type: 'post',
                        url: 'admin/system/save.php',
                        data: 'delhighlitefile=' + $(this).attr('name'),
                        success: function(data) {
                            $('#' + win).find('.webutler_winmeldung').html(data).fadeIn(200).delay(2000).fadeOut(200, function() {
                                WBeditbox_open(win, 'highfilestr=1');
                            });
                        }
                    });
                    return false;
                });
                $('.webutler_delhighlitefolder').bind('click', function() {
                    $.ajax({
                        type: 'post',
                        url: 'admin/system/save.php',
                        data: 'delhighlitefolder=' + $(this).attr('name'),
                        success: function(data) {
                            $('#' + win).find('.webutler_winmeldung').html(data).fadeIn(200).delay(2000).fadeOut(200, function() {
                                WBeditbox_open(win, 'highfoldertr=1');
                            });
                        }
                    });
                    return false;
                });
                $('.webutler_boxesform').bind('submit', function() {
                    var form = $(this);
                    var fact = form.attr('action');
                    if(typeof fact == 'undefined') {
                        var items = new Array();
                        var submitname = $(form).find('input[type="submit"]').attr('name');
                        items.push(submitname + '=1');
                        
                        items.push('locationpage=' + locationPage);
                        $.each($(form).find(':input').serializeArray(), function(i, field) {
                            if(field.type == 'radio' || field.type == 'checkbox') {
                                /*
                                var fieldval = '';
                                if(field.value == '') fieldval = $(field).attr('checked');
                                else fieldval = field.value;
                                items.push(field.name + '=' + fieldval);
                                */
                                items.push(field.name + '=' + $(field).attr('checked'));
                            }
                            else
                                items.push(field.name + '=' + field.value);
                        });
                        
                        var submititems = items.join('&');
                        
                        if(win == 'webutler_access') {
                            if(submitname == 'makeuserconfig')
                            	WBeditbox_open(win, '', submititems);
                            else if(submitname == 'update_blocked_pages')
                            	WBeditbox_open(win, 'showtr=blocks', submititems);
                            else if(submitname == 'make_update_group' || submitname == 'make_new_group' || submitname == 'update_edit_group')
                            	WBeditbox_open(win, 'showtr=gruppen', submititems);
                            else if(submitname == 'make_new_user')
                            	WBeditbox_open(win, 'showtr=zugang&subtr=newuser', submititems);
                            else if(submitname == 'update_newregs_user' || submitname == 'update_newreg_user')
                            	WBeditbox_open(win, 'showtr=zugang&subtr=newregs', submititems);
                            else if(submitname == 'make_update_user' || submitname == 'update_edit_user')
                            	WBeditbox_open(win, 'showtr=zugang&subtr=edituser', submititems);
                            else if(submitname == 'update_config_file')
                            	WBeditbox_open(win, 'showtr=usersets', submititems);
                            
                            return false;
                        }
                        else {
							if(submitname == 'savelangcode' && !WBeditbox_requestlangdelete()) {
	                            return false;
	                        }
	                        else if(submitname == 'openformnew' || submitname == 'openformedit') {
	                            WBeditbox_open(win, submititems);
	                            return false;
	                        }
	                        else {
	                            $.ajax({
	                                type: 'post',
	                                url: 'admin/system/save.php',
	                                data: submititems,
	                                success: function(datas) {
	                                    var data = datas.split('###');
	                                    var thisform;
	                                    if(win == 'webutler_forms')
	                                        thisform = $('.webutler_winmeldung');
	                                    else
	                                        thisform = $(form).find('.webutler_winmeldung');
										
                                        /*
                                        thisform.html(data[0]).fadeIn(200);
										return false;
                                        */
	                                    thisform.html(data[0]).fadeIn(200).delay(2000).fadeOut(200, function() {
                                            /*
	                                        if(win == 'webutler_categories' && !$('#webutler_showeditcat').is(':visible')) {
                                                    $('#webutler_showeditcat').removeAttr('style');
                                        	}
	                                        if(win == 'webutler_langs' && !$('#webutler_showeditlang').is(':visible')) {
                                                    $('#webutler_showeditlang').removeAttr('style');
                                        	}
                                            */
                                            
	                                    	if(win == 'webutler_newpage' && typeof(data[1]) != 'undefined') {
	                                        	if(confirm(data[1]))
	                                                window.location = data[2];
	                                        }
	                                        else if((win == 'webutler_pagecats' || win == 'webutler_delpage' || win == 'webutler_rename') && typeof(data[1]) != 'undefined') {
                                                alert(data[1]);
                                                window.location = data[2];
                                        	}
	                                        else if(win == 'webutler_pagelang' && typeof(data[1]) != 'undefined') {
                                                alert(data[1]);
                                                window.location = window.location;
                                        	}
                                        	else {
                                                if((submitname == 'savenewform' || submitname == 'saveeditform') && data[1] == 'error')
                                                    return false;
                                                else if(submitname == 'savelangcode')
                                                    WBeditbox_open(win, 'langtrcodes=1');
                                                else if(submitname == 'savelanghomes')
                                                    WBeditbox_open(win, 'langtrfronts=1');
                                                else if(submitname == 'savehighlitefile')
                                                    WBeditbox_open(win, 'highfilestr=1');
                                                else if(submitname == 'savehighlitefolder')
                                                    WBeditbox_open(win, 'highfoldertr=1');
                                                else
                                                    WBeditbox_open(win);
                                        	}
	                                    });
	                                }
	                            });
	                            return false;
	                        }
	                    }
                    }
                });
            	if(win == 'webutler_newmenu') {
                    WBeditbox_checkbak('menu');
                }
            	if(win == 'webutler_newblock') {
                    WBeditbox_checkbak('block');
                }
            	if(win == 'webutler_advanced') {
                    var winheight = $(window).height();
                    var boxheight = $(this).height();
                    var checkheight = parseInt(winheight-200);
                    $('#webutler_advancedscroller').css({ 'height': checkheight + 'px' });
                    $('#webutler_advancedscrollarea').css({ 'height': checkheight + 'px' });
                    $('#webutler_advancedviewport').css({ 'height': checkheight + 'px' });
                    $('#webutler_advancedscrollbar').css({ 'height': checkheight + 'px', 'opacity': '0' });
					var opened = false;
                    $('#webutler_advanced').hover(
                        function() {
							if(!opened)
								opened = WBadvancedbox_scrollbar('advanced');
                            $('#webutler_advancedscrollbar').animate({
                                opacity: 1.0
                            }, 500);
                        }, 
                        function() {
                            $('#webutler_advancedscrollbar').animate({
                                opacity: 0.5
                            }, 500);
                        }
                    );
            	}
            	if(win == 'webutler_gridcolumns') {
                    var winheight = $(window).height();
                    var boxheight = $(this).height();
                    var checkheight = parseInt(winheight-250);
                    $('#webutler_gridscroller').css({ 'height': checkheight + 'px' });
                    $('#webutler_gridscrollarea').css({ 'height': checkheight + 'px' });
                    $('#webutler_gridviewport').css({ 'height': checkheight + 'px' });
                    $('#webutler_gridscrollbar').css({ 'height': checkheight + 'px', 'opacity': '0' });
					var opened = false;
                    $('#webutler_gridcolumns').hover(
                        function() {
							if(!opened)
								opened = WBadvancedbox_scrollbar('grid');
                            $('#webutler_gridscrollbar').animate({
                                opacity: 1.0
                            }, 500);
                        },
                        function() {
                            $('#webutler_gridscrollbar').animate({
                                opacity: 0.5
                            }, 500);
                        }
                    );
					
					$('.webutler_gridhover').click(function() {
						WBeditbox_close();
						var gridname = $(this).attr('rel');
						var filename = gridname.split('###');
						$('#webutler_insertgridbefore, #webutler_insertgridafter').find('.webutler_gridname').attr('rel', filename[1]).text('| ' + filename[0] + ' |');
						$('#webutler_logo').fadeOut(200);
						$('#webutler_editbox').fadeOut(200);
						$('#webutler_hidebox').fadeOut(200);
						WBgrids_hoverbodydivs();
					});
					
					$('.webutler_cancelgrid').click(function() {
						$('.wb_gridelement, .wb_contentelement').off('mouseenter');
						if(insertGridOnElements == 'full')
							$('.wb_menuelement, .wb_blockelement').off('mouseenter');
						$('#webutler_logo').fadeIn(200);
						$('#webutler_editbox').fadeIn(200);
						$('#webutler_hidebox').fadeIn(200);
						$('#webutler_insertgridbefore').css('display', 'none');
						$('#webutler_insertgridafter').css('display', 'none');
					});
            	}
            });
            if(sliderdiv.is(':hidden'))
            	sliderdiv.fadeIn('slow');
            $('.webutler_winmeldung').hide();
        }
    });
    return false;
}

function WBgrids_hoverbodydivs() {
	var insertpoints = '.wb_gridelement, .wb_contentelement';
	if(insertGridOnElements == 'full')
		insertpoints += ', .wb_menuelement, .wb_blockelement';
	
	$(insertpoints).on('mouseenter', function() {
		$('.webutler_insertgrid').unbind('click');
		
		var $elem;
		if($(this).closest('.wb_gridelement').length > 0) {
			$elem = $(this).closest('.wb_gridelement');
		}
		else if($(this).closest('.wb_contentelement').length > 0) {
			$elem = $(this).closest('.wb_contentelement');
		}
		else if(insertGridOnElements == 'full' && $(this).closest('.wb_menuelement').length > 0) {
			$elem = $(this).closest('.wb_menuelement');
		}
		else if(insertGridOnElements == 'full' && $(this).closest('.wb_blockelement').length > 0) {
			$elem = $(this).closest('.wb_blockelement').first();
		}
		else {
			$elem = $(this);
		}

		var position = $elem.position();
		var top = parseInt(position.top + parseInt($elem.css('marginTop')));
		var left = parseInt(position.left + parseInt($elem.css('marginLeft')));
		var height = $elem.height();
		var width = $elem.width();
		
		$('#webutler_insertgridbefore').css({
			'display': 'block',
			'left': left + 'px',
			'top': (top-7 < 5 ? 5 : top-7) + 'px',
			'width': width + 'px'
		});
		$('#webutler_insertgridafter').css({
			'display': 'block',
			'left': left + 'px',
			'top': parseInt(top+height-7) + 'px',
			'width': width + 'px'
		});
		
		$('#webutler_insertgridbefore').find('.webutler_insertgrid').bind('click', function() {
			$('#webutler_loadingscreen').css('display', 'block');
			var gridindex = $elem.index(insertpoints);
			var gridname = $('#webutler_insertgridbefore').find('.webutler_gridname').attr('rel');
			WBgrids_insertnew(gridindex, encodeURIComponent(gridname), 'before');
		});
		
		$('#webutler_insertgridafter').find('.webutler_insertgrid').bind('click', function() {
			$('#webutler_loadingscreen').css('display', 'block');
			var gridindex = $elem.index(insertpoints);
			var gridname = $('#webutler_insertgridafter').find('.webutler_gridname').attr('rel');
			WBgrids_insertnew(gridindex, encodeURIComponent(gridname), 'after');
		});
	});
}

function WBgrids_insertnew(divindex, gridname, position) {
	if(insertGridPromtText == 'disabled')
		var margin = false;
	else
		margin = prompt(insertGridPromtText, '');
	
	if(!margin || margin == '' || margin != '')
	{
		$.ajax({
			type: 'post',
			url: 'admin/system/save.php',
			data: 'insertgridatposition=1&divindex=' + divindex + '&gridname=' + gridname + '&margin=' + margin + '&position=' + position + '&getpage=' + locationPage,
			success: function(datas) {
				var data = datas.split('###');
				alert(data[1]);
				if(data[0] == 'ok') {
					location.reload(true);
				}
			}
		});
	}
}

function WBgrids_checkgroupname(groupval, groups) {
	if(groupval == '' || groupval.indexOf('_') == -1)
	{
		document.getElementById('webutler_gridgroup').style.display = 'none';
		return false;
	}
	var group = groupval.substring(0, groupval.indexOf('_'));
	var avail = groups.split('|');
	var hasname = false;
	for(var i = 0; i < avail.length; i++)
	{
		if(avail[i] == group)
		{
			document.getElementById('webutler_gridgroup').style.display = 'none';
			hasname = true;
			break;
		}
	}
	if(!hasname)
		document.getElementById('webutler_gridgroup').style.display = '';
}

function WBadvancedbox_scrollbar(scrollerwin)
{
	var $scrollarea = $('#webutler_' + scrollerwin + 'scrollarea');
	var $viewport = $('#webutler_' + scrollerwin + 'viewport');
	var $viewcontent = $('#webutler_' + scrollerwin + 'viewcontent');
	var $scrollbar = $('#webutler_' + scrollerwin + 'scrollbar');
	var $track = $('#webutler_' + scrollerwin + 'track');
	var scroller = document.getElementById('webutler_' + scrollerwin + 'viewport');
	var tracker = document.getElementById('webutler_' + scrollerwin + 'track');
	var height = $viewport.height();
	var cntHeight = $viewcontent.height();
	var trcHeight = $scrollbar.height();
	var mean = 35; //faster or slower
	var current = 0;
	var dragit = '_false';
	
	$track.css({
		'height': Math.round(height / cntHeight * trcHeight) + 'px',
		'top': ($viewport.scrollTop() / cntHeight * trcHeight) + 'px'
	});
	
	var doScroll = function(e)
	{
		e = window.event || e; //cross-browser wheel delta
		var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
		
		var scrolltop = $viewport.scrollTop();
		$viewport.scrollTop(scrolltop - delta * mean);
		$track.css({
			'top': ($viewport.scrollTop() / cntHeight * trcHeight) + 'px'
		});

		e.preventDefault();
	};
	
	var moveDrag = function(divY) {
		var minY = 0;
		var maxY = $scrollbar.height() - parseInt($track.height() - 2);
		
		if(divY >= minY && divY < maxY) {
			var scrolltop = parseInt(divY + 2) * (cntHeight / trcHeight);
			$viewport.scrollTop(scrolltop);
			$track.css({
				'top': divY + 'px'
			});
		}
	}
	var startDrag = function(e) {
		e = e || window.event;
		dragit = '_true';
		$scrollarea.addClass('noSelect');
		var div = document.getElementById('webutler_' + scrollerwin + 'track');
		var posY = e.clientY;
		var divTop = parseInt(div.style.top);
		var diffY = posY - divTop;
		document.onmousemove = function(e) {
			if(dragit == '_true') {
				e = e || window.event;
				var posY = e.clientY;
				var divY = posY - diffY;
				moveDrag(divY);
			}
		}
	}
	var stopDrag = function() {
		dragit = '_false';
		$scrollarea.removeClass('noSelect');
	}
	
	if(scroller.addEventListener) {
		scroller.addEventListener('mousewheel', doScroll, false);
		scroller.addEventListener('DOMMouseScroll', doScroll, false);
	}
	else {
		scroller.attachEvent('onmousewheel', doScroll);
	}
	
	if(tracker.addEventListener) {
		tracker.addEventListener('mousedown', startDrag, false);
		document.addEventListener('mouseup', stopDrag, false);
	}
	else {
		tracker.attachEvent('onmousedown', startDrag);
		document.attachEvent('onmouseup', stopDrag);
	}
	
	return true;
}

function WBeditbox_close() {
	$('#webutler_blockerbackground').fadeOut('medium');
	$('#webutler_blockerdiv').fadeOut('medium');
	$('#webutler_sliderdiv').fadeOut('medium', function() {
        $(this).css({
            'width': '502px',
            'left': '50%',
            'top': '40px'
        });
    });
}

function WBeditbox_auto_check() {
	if(document.getElementById('webutler_check_auto').checked == true) {
		document.getElementById('webutler_sub_auto').style.display = 'block';
	}
	else {
		document.getElementById('webutler_sub_auto').style.display = 'none';
	}
}

function WBeditbox_switch(on, off) {
	document.getElementById(on).style.display = 'block';
	document.getElementById(off).style.display = 'none';
}

function WBeditbox_setpagemodus(txt, datei, modus, isoff) {
    if(modus == 'off')
        WBeditbox_checkfile('offline');
    
	if(confirm(txt)) {
        $.ajax({
            type: 'post',
            url: 'admin/system/save.php',
            data: 'setmodus=' + modus + '&filename=' + datei,
            success: function(data) {
                if(modus == 'on') {
                    $('#webutler_hidegetpage').removeAttr('style');
                    $('#webutler_showgetpage').css({'display': 'none'});
					if(isoff != '') {
						if(data == 'noaccess')
							$('#webutler_pageisoff').fadeOut( 200, function() { $(this).text(isoff).fadeIn(200); } );
						else
							$('#webutler_pageisoff').fadeOut( 500, function() { $(this).remove(); } );
					}
                }
                else if(modus == 'off') {
                    $('#webutler_hidegetpage').css({'display': 'none'});
                    $('#webutler_showgetpage').removeAttr('style');
					if(isoff != '') {
						if($('#webutler_pageisoff').length > 0)
							$('#webutler_pageisoff').fadeOut( 200, function() { $(this).text(isoff).fadeIn(200); } );
						else
							$('body').prepend($('<div id="webutler_pageisoff">' + isoff + '</div>\n').fadeIn(500));
					}
                }
            }
        });
        return false;
	}
}

function WBeditbox_lastversion(datum, datei) {
	if(confirm(datum)) {
		window.location = "admin/system/save.php?page=" + datei + "&version=getlast"; 
	}
}

function setimgfromcode(value) {
    document.getElementById('imgfromcode').style.backgroundImage = 'url(includes/language/icons/' + value + '.png)';
}

function WBeditbox_hidesubtrs(show, hide) {
	var hides = hide.split('|');
	for(var i = 0; i < hides.length; i++) {
		document.getElementById(hides[i]).style.display = 'none';
	}
	document.getElementById(show).style.display = '';
}

function WBeditbox_hidecattrs(show, hide) {
	$('#webutler_categories').find('.webutler_select').each(function() {
        $(this).prop('selectedIndex', 0);
    });
	$('#webutler_categories').find('.webutler_input').each(function() {
        $(this).val('');
    });
	$('.webutler_tr' + hide + 'cat').css({'display': 'none'});
	$('.webutler_tr' + show + 'cat').css({'display': ''});
	$('#savecategoriesbutton').attr('name', 'save' + show + 'categories');
	$('#savecategoriesbutton').val($('#webutler_txt' + show + 'button').text());
}

function WBeditbox_hidehighlitetrs(show, hide) {
	$('.webutler_trhigh' + hide).css({'display': 'none'});
	$('.webutler_trhigh' + show).css({'display': ''});
}

/*
function WBeditbox_hidealertcells() {
	if(document.getElementById('webutler_errorcell') && document.getElementById('webutler_errorcell').style.display != 'none')
        document.getElementById('webutler_errorcell').style.display = 'none';
    
	if(document.getElementById('webutler_alertcell') && document.getElementById('webutler_alertcell').style.display != 'none')
        document.getElementById('webutler_alertcell').style.display = 'none';
}
*/

function WBeditbox_enableforcer() {
    if((document.getElementById('config_regby2') && document.getElementById('config_regby2').checked == false) || document.getElementById('config_regon').checked == false)
        document.getElementById('config_regtouser').disabled = true;
    else
        document.getElementById('config_regtouser').disabled = false;
}

function WBeditbox_showdeclaration(text) {
    if(!document.getElementById('webutler_declarationtext')) {
        var newDiv = document.createElement('div');
        var addDiv = document.getElementById('webutler_access').appendChild(newDiv);
        addDiv.id = 'webutler_declarationtext';
        addDiv.innerHTML = text;
    }
    else {
        document.getElementById('webutler_declarationtext').innerHTML = text;
    }

	document.getElementById('webutler_declarationtext').onclick = function () {
        document.getElementById('webutler_access').removeChild(document.getElementById('webutler_declarationtext'));
	};
}

function WBeditbox_openmedia() {
    var iWidth = mediabrowserWindowWidth;
	if ( typeof iWidth == 'string' && iWidth.length > 1 && iWidth.substr( iWidth.length - 1, 1 ) == '%' )
		iWidth = parseInt( window.screen.width * parseInt( iWidth, 10 ) / 100, 10 );
    
    var iHeight = mediabrowserWindowHeight;
	if ( typeof iHeight == 'string' && iHeight.length > 1 && iHeight.substr( iHeight.length - 1, 1 ) == '%' )
		iHeight = parseInt( window.screen.height * parseInt( iHeight, 10 ) / 100, 10 );
	
	if(iWidth < 640) iWidth = 640;
	if(iHeight < 420) iHeight = 420;
	
	var iTop = parseInt( ( window.screen.height - iHeight ) / 2, 10 );
	var iLeft = parseInt( ( window.screen.width  - iWidth ) / 2, 10 );
	
	var WindowFeatures = 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes,width=' + iWidth + ',height=' + iHeight + ',left=' + iLeft + ',top=' + iTop;
	var BrowseUrl = 'admin/browser/index.php';

	var popupWindow = window.open( '', 'CKBrowseNoneDialog', WindowFeatures, true );

	if ( !popupWindow )
		return false;

	try {
		popupWindow.moveTo( iLeft, iTop );
		popupWindow.resizeTo( iWidth, iHeight );
		popupWindow.focus();
		popupWindow.location.href = BrowseUrl;
	}
	catch ( e ) {
		popupWindow = window.open( BrowseUrl, 'CKBrowseNoneDialog', WindowFeatures, true );
	}
}

$(document).ready(function()
{
    var WBboxvar_dragsliderbox = false;
    
    $('#webutler_slider').mousedown(function(e) {
    	WBboxvar_dragsliderbox = true;
		var divLeft = e.clientX - parseInt($('#webutler_sliderdiv').css('left'));
        $(document.body).mousemove(function(e) {
            //e.preventDefault();
            if(WBboxvar_dragsliderbox == true) {
                $('#webutler_sliderdiv').css({
                    opacity: 0.8,
                    top: parseInt(e.clientY - 26),
                    left: parseInt(e.clientX - divLeft)
                });
            }
        });
    }).mouseup(function() {
    	WBboxvar_dragsliderbox = false;
    	$('#webutler_sliderdiv').css({ opacity: 1.0 });
    });
    
    $('#webutler_logo').click(function() {
        $(this).animate({
            opacity: 0
        }, 500);
    });
    
    $('#webutler_showbox').click(function() {
        $(this).fadeOut(200, function() {
            $('#webutler_editbox').animate({
                marginLeft: '23px'
            }, 500, function() {
                $('#webutler_hidebox').fadeIn(200);
                $.ajax({
                    type: 'post',
                    url: 'admin/system/save.php',
                    data: 'editboxzustand=show'
                });
                return false;
            });
        });
    });
    
    $('#webutler_hidebox').click(function() {
        $(this).fadeOut(200, function() {
        	var wbeditboxleft = parseInt($('#webutler_editbox').outerWidth()+10);
            $('#webutler_editbox').animate({
                marginLeft: '-' + wbeditboxleft + 'px'
            }, 500, function() {
                $('#webutler_showbox').fadeIn(200);
                $.ajax({
                    type: 'post',
                    url: 'admin/system/save.php',
                    data: 'editboxzustand=hide'
                });
                return false;
            });
        });
    });
    
    $('#webutler_hidebox').mouseover(function () {
		$('.webutler_submenu').each(function() {
			var $menu = $(this).find('.webutler_submenudiv');
			if($menu.is(':visible')) {
				$menu.stop(true,true).fadeTo(10, 0).css({'display': 'none'});
			}
		});
    });
    
    $('.webutler_submenu').hover(
        function () {
            $(this).addClass('hasFocus');
            $(this).find('.webutler_adminicon').css('backgroundPosition', '-15px 0px');
			var $sub = $(this);
			$('.webutler_submenu').each(function() {
				var $menu = $(this).find('.webutler_submenudiv');
				if($sub != $(this) && $menu.is(':visible') && !$(this).hasClass('hasFocus')) {
					$menu.stop(true,true).fadeTo(10, 0).css({'display': 'none'});
				}
			});
            if(!$('#webutler_editbox').is(':animated')) {
				$(this).find('.webutler_submenudiv').stop(true,true).fadeTo(300, 1).css({'display': 'inline-block'});
			}
        },
        function () {
			$(this).removeClass('hasFocus');
			$(this).find('.webutler_adminicon').css('backgroundPosition', '0px 0px');
			var $menu = $(this).find('.webutler_submenudiv');
			if($menu.is(':visible') && !$(this).hasClass('hasFocus')) {
				$menu.stop(true,true).delay(400).fadeTo(300, 0, function() {
					$menu.css({'display': 'none'});
				});
			}
        }
    );
	
    $('#webutler_loadingscreen').css('display', 'none');
});

