//window.addListener('load', changeHeight);
//window.addListener('resize', changeHeight);
//function changeHeight(){$('main').setStyle('height', (this.getHeight()-$('top').getHeight()-$('bottom').getHeight()));}

function pageThis(file, action, id, page, container, module, moduleId){
    $(container).innerHTML = '';
    //alert('/utils/ajax/'+file+'.php?action='+action+'&id='+id+'&page='+page+'&container='+container+'&module='+module+'&moduleId='+moduleId);
    var json_request = new Request.JSON({url: '/utils/ajax/'+file+'.php?action='+action+'&id='+id+'&page='+page+'&container='+container+'&module='+module+'&moduleId='+moduleId, onSuccess: changeGroupOut}).get();
}

function changeGroupOut(responseJSON, responseText){
    $(responseJSON.container).innerHTML = responseJSON.value;
    Cookie.write(responseJSON.id+'PageClient', responseJSON.page, {path:'/'});
    if(responseJSON.module!='' && responseJSON.module!='undefined' && responseJSON.moduleId!=0){
        if(Cookie.read('module')!=null && Cookie.read('moduleId')!=null){
            var toRemoveValue = Cookie.read('module')+Cookie.read('moduleId');
            if(Cookie.read('module')!='search' && $(toRemoveValue)!=null){
                $(toRemoveValue).removeClass('active');
            }
        }
        var toSetValue = responseJSON.module+responseJSON.moduleId;
        Cookie.write('module', responseJSON.module, {path:'/'});
        Cookie.write('moduleId', responseJSON.moduleId, {path:'/'});
        if(Cookie.read('module')!='search' && $(toSetValue)!=null){
            $(toSetValue).addClass('active');
        }
    }
    $('pages').innerHTML = responseJSON.pager;
    //Slimbox.scanPage();
}

function removeCookie(){
    Cookie.dispose('objectsPageClient', {path:'/'})
    Cookie.dispose('module', {path:'/'})
    Cookie.dispose('moduleId', {path:'/'})
}

function setnewgroup(module, moduleId, page){
    if(module!=null) Cookie.write('module', module, {path:'/'});
    if(moduleId!=null) Cookie.write('moduleId', moduleId, {path:'/'});
    if(moduleId!=null) Cookie.write('objectsPageClient', page, {path:'/'});
}

function rememberUser(){
    if($('savepass').checked==true){
        Cookie.write('username', $('auth_login').value, {path:'/'});
        Cookie.write('userpass', hex_md5($('auth_pass').value), {path:'/'});
    }
    else
    {
        clearUserRemember();
    }
}

function clearUserRemember(){
    if(Cookie.read('username')!=null && Cookie.read('userpass')!=null){Cookie.dispose('username', {path:'/'}); Cookie.dispose('userpass', {path:'/'});}
}

function chgImage(photo, name, photoTh){
    $('photoMain').src = photo;
    $('photoMain').getParent().title = name;
    $('photoMain').getParent().onclick = function(){hiddenClick(photoTh, this); return false;}
}

function hiddenClick(value, el){
    if($('imagebox')!=null){
        var els = $('imagebox').getElements('a');
        for(i=0;i<els.length;i++){
            if(value==els[i].href){
                h = els[i];
                break;
            }
        }
        h.fireEvent('click');
    }
}

function getMasters(action){
    Cookie.write('module', 'master', {path:'/'});
    Cookie.dispose('moduleId', {path:'/'})
    //alert('/utils/ajax/module.php?action='+action);
    var json_request = new Request.JSON({url: '/utils/ajax/module.php?action='+action, onSuccess: outGetMasters}).get();
}

function outGetMasters(responseJSON, responseText){
    $('pages').innerHTML = '';
    $('catalog').innerHTML = '';
    $('catalog').innerHTML = responseJSON.value;
}

function checkMaster(){
    Cookie.read('module', 'master', {path:'/'});
}

function favorites(){
    $('favorites').setStyle('display', 'none');
    $('newpositions').setStyle('display', 'block');
    Cookie.write('module', 'favorites', {path:'/'});
    Cookie.write('moduleId', '1', {path:'/'});
    pageThis('module', 'chunkPage', 'objects', '0', 'catalog', 'favorites', '1');
}

function newpositions(){
    $('favorites').setStyle('display', 'block');
    $('newpositions').setStyle('display', 'none');
    Cookie.write('module', 'left', {path:'/'});
    Cookie.write('moduleId', '0', {path:'/'});
    pageThis('module', 'chunkPage', 'objects', '0', 'catalog', 'left', '0');
}

    if(Cookie.read('module')=='master' && Cookie.read('moduleId')==null){
        getMasters('getMasters');
    }
    else
    {
        Cookie.dispose('truemaster', {path:'/'})
    }


