var obj_id = 0;

function GetSubCats(divId, catId, selectId){
    var url = mainUrl+'/community/getsubcats/'+catId+'/'+divId+'/'+selectId+'/';
    PuskFramework.srvapi.invoke(url);
};

function askLocation(url, msg){
    if(confirm(msg)){
        document.location = url;
    };
};

function askDeletePhoto(url, msg){
    askAction(url, msg);
    document.location.reload();
}


function askAction(url, msg){
    if(confirm(msg)){
        GetDiv(url);
        document.location.reload();
    }
    return false;
};


function SetPhoto(url, img_id){
    var url = mainUrl+'/community/SetPhoto/'+obj_id+'/'+img_id+'/';
    PuskFramework.srvapi.invoke(url);
    document.location.reload();
};


function OpenWinResource(objId){
    obj_id=objId;
    var url = mainUrl + '/manager/getfiles/selector/0/?js_callback=SetPhoto&filter[folder]=-4';
    window.open(url, 'resource_manager', 'width=890, height=520, toolbar=no, scrollbars=yes, resizable=yes, status=no');
};



function ShowHideCss(obj_id, label_css_class_open, label_css_class_close){
    var obj = document.getElementById(obj_id);
    if(obj.className != label_css_class_open){
        obj.className = label_css_class_open;
    } else {
        obj.className = label_css_class_close;
    };
};

function sendRequestFromCommunity(community_id, div_id) {
    var obj = {
        name: '',
        sex: '',
        id: community_id,
        fvalidate_text_alt: 'length|10|200',
        fvalidate_text_emsg: 'Заявка должна быть от 10 до 200 символов',
        type: 'request',
        title: 'Заявка на вступление в сообщество',
        callback: callbackSendRequestFromCommunity
    }
    sendUserMessage(document.getElementById(div_id), obj)
}

function callbackSendRequestFromCommunity(obj) {
    var post_obj = {
        'data[community_id]': obj.id,
        'data[title]' : 'Заявка на вступление в сообщество',
        'data[text]'  : obj.value,
        'ajax': 1
    };
    submit_post_request('/mymessages/SendCommunityRequest', post_obj);
}