prefix = "";

function Status(id, status)
{
    if ($(prefix + id))
    {
        $(prefix + id).childElements().each(function (i) { 
            if (i.className == prefix + status) i.show('block'); else i.hide(); });
    }
}

String.prototype.trim = function () {
    return (this.replace(/\s+$/,"").replace(/^\s+/,""));
};

String.prototype.compareTo = function (v) {
    return this.toLowerCase() == v.toLowerCase();
}

var elementUtilities = {
    selectedValue : function(e){
        return e.options[e.selectedIndex].value;
    },    
    setText : function(e, value){
        if (e.firstChild) e.firstChild.nodeValue = value;
    },
    show : function(e, display){
        e.style.display = display;
    },
    removeChilds : function(e){
        e.childElements().each(function(i){i.remove();});
    },
    selectValue : function(e, v){
        for (var i = 0; i < e.options.length; i++)
            e.options[i].selected = e.options[i].value == v;
    },
    center : function(e) {
        var height = document.viewport.getHeight();
        var width = document.viewport.getWidth();
        
        if (isIE && browserVersion < 7)
        {
            height = document.body.clientHeight;
            width = document.body.clientWidth;
        }
        
        e.style.top = ((height - e.getHeight()) / 2) + 'px';
        e.style.left = ((width - e.getWidth()) / 2) + 'px';    
    },
    moveToMouse : function(e, ev, offset) {
        if (!ev) ev = window.event;
        var scroll = Element.cumulativeScrollOffset(e);  
        
        os = offset != null ? Element.cumulativeOffset(offset) : {'left':0,'top':0};

        e.style.position = 'absolute';
        e.style.left = (Event.pointerX(ev) - scroll.left + os.left) + 'px';
        e.style.top = (Event.pointerY(ev) - scroll.top + os.top - 20) + 'px';
        
        return e;
    },
    parentByTagName : function(e, tagName) {
        if (!e.parentNode)
            return null;
        
        if (e.parentNode.tagName.compareTo(tagName))
            return e.parentNode;
        
        return e.parentNode.parentByTagName(tagName);
    }
}

Element.addMethods(elementUtilities);

var isIE = document.compatMode && document.all;

var currentEntityId = 0;

function GetUrl(url)
{
    document.location.href = url;
}

function GetModeUrl(mode)
{
    GetUrl('index.php?mode=' + mode);
}

function PostAction(action, params)
{
    document.getElementById("__action").value = action;
    document.getElementById("__params").value = params;

    document.getElementById("pageForm").submit();
}

function OpenDialog(url, name, width, height)
{
    options = '';
    
    if (width > 0 && height > 0)
    {
        if (isIE)
        {
            width += 15;
        }
        options = 'height=' + height + ',width=' + width + ',';
    }
    
    pleft = (screen.width - width) / 2;
    ptop = (screen.height - height) / 2;
    
    options += 'top=' + ptop + ',left=' + pleft + ',';
    options += 'scrollbars=yes,status=yes,location=no,toolbar=no,menubar=no';
    
    window.open(url, name, options);
}

function SwitchPosition(first, second)
{
    PostAction("switchModuleInstancePosition", first + ";" + second);
}

function SelectRadioButton(id, key)
{
   document.getElementById(id).checked = 'checked';
}

function UncheckInput(id)
{
    document.getElementById(id).checked = '';
}

function ShowFormView(listId, formViewId, loadAction, id)
{
    HideById(listId);
    ShowById(formViewId, 'block');
    
    if (loadAction != '')
        AjaxCall(loadAction, "id=" + id);
    else
        currentEntityId = 0;
}

function SaveEntity(command)
{
    PostAction(command, currentEntityId)
}

function SaveUser()
{
    PostAction('saveUser', currentEntityId);
}

function Show(target, style)
{
    target.style.display = style;
}

function Hide(target)
{
    target.style.display = 'none';
}

function ShowById(id, style)
{
    document.getElementById(id).style.display = style;
}

function HideById(id)
{
    document.getElementById(id).style.display = 'none';
}

function SetSrcBySelectedValue(dropdown, target, module, mediaPath)
{
    var filename = $F(dropdown);
    $(target).src = mediaPath + filename;
    AjaxCall("image.setFilename", "module=" + module + "&filename=" + filename);
}

var currentModuleID = '';

function ShowLoadingInfo(text)
{
    $('loadingInfoText').innerHTML = text;
    $('loadingInfo').show('block');
}

function HideLoadingInfo()
{
    $('loadingInfoText').innerHTML = '';
    $('loadingInfo').hide();
}

function ShowMultiContent(cnt, miid, id)
{
    for (var i = 0; i < cnt; i++)
    {
        var item = document.getElementById(miid + '_' + i);
        item.style.display = i == id ? 'block' : 'none';
        
        item = document.getElementById(miid + "_" + i + "_title");
        item.className = i == id ? 
            'multiContent_item_active' : 'multiContent_item_inactive';
    }    
}

function SetDownloadListPath(id, list)
{
    PostAction('updateDownloadListPath', id + 
        ';' + list.options[list.selectedIndex].value);
}

function DeleteMCC(miid, cnt, id)
{
    HideById(miid + '_' + cnt);
    HideById(miid + '_' + cnt + '_title');

    AjaxCall('multiContent.delete','content=' + id);
}

function ValidateForm(f)
{
    for (var i = 1; i < arguments.length; i++)
    {            
        var element = f[arguments[i]];
        
        if (!ValidateRequired(element, "Dieses Feld muss ausgefüllt sein!"))
        {
            element.focus();
            return false;
        }
    }
}

function ValidateRequired(element, message)
{
    with (element)
    {
        if (value == null || value == "")
        {
            alert(message);
            return false;
        }
    }
    
    return true;
}







