    function reQuery(func){setTimeout(func,1000);}
    function refreshPage(){window.location.href=window.location.href;}

    function ajaxQuery(params) {
        if (typeof(params.query)=='undefined') return false;
        $.post('/ajax.php',params,function(data){
            if (data==''){reQuery(function(){ajaxQuery(params)}); return false;}
            if (data=='empty') data = '';
            eval('response_'+params.query+'(data,params);');
        });
    }



    function getSelect_country(parent_id) {
        $('#field_country').animate({opacity:0.01},'fast');
        $('#field_region').animate({opacity:0.01},'fast',function(){$('#field_region').html('');});
        $('#field_city').animate({opacity:0.01},'fast',function(){$('#field_city').html('');});
        if (parent_id) ajaxQuery({query:"getSelect_country",parent_id:parent_id});
        else $('#field_country').html('');
    }
    function response_getSelect_country(data){$('#field_country').html(data).animate({opacity:1},'slow',function(){$('#field_country .form_row').css('position', 'relative');});}



    function getSelect_region(parent_id) {
        var country_id=$('#counId option:selected').val();
        $('#field_region').animate({opacity:0.01},'fast');
        $('#field_city').animate({opacity:0.01},'fast',function(){$('#field_city').html('');});
        if (parent_id || 1) ajaxQuery({query:"getSelect_region",parent_id:parent_id, country_id:country_id});
        else $('#field_region').html('');
    }
    function response_getSelect_region(data){
        $('#field_region').html(data).animate({opacity:1},'slow',
        function(){$('#field_region .form_row').css('position', 'relative');});}



    function getSelect_city(parent_id) {
        var country_id=$('#counId option:selected').val();
        $('#field_city').animate({opacity:0.01},'fast');
        if (parent_id || 1) ajaxQuery({query:"getSelect_city",parent_id:parent_id, country_id:country_id});
        else $('#field_city').html('');
    }
    function response_getSelect_city(data){
        $('#field_city').html(data).animate({opacity:1},'slow',
        function(){$('#field_city .form_row').css('position', 'relative');});}



    function getPaths(path) {
        $('#fields_paths').animate({opacity:0.01},'fast');
        if (path) ajaxQuery({query:"getPaths",path:path});
        else $('#fields_paths').html('');
    }
    function response_getPaths(data){$('#fields_paths').html(data).animate({opacity:1},'slow',function(){$('#fields_paths .form_row').css('position', 'relative');});}



    function getAdvanced(path) {
        $('#field_advanced').animate({opacity:0.01},'fast');
        if (path) ajaxQuery({query:"getAdvanced",path:path});
        else $('#field_advanced').html('');
    }
    function response_getAdvanced(data){$('#field_advanced').html(data).animate({opacity:1},'slow',function(){$('#field_advanced .form_row').css('position', 'relative');});}



    function reating(group,id,vote) {ajaxQuery({query:"reating",group:group,id:id,vote:vote});}
    function response_reating(data,params){$('div.reating_'+params.group+'_'+params.id).html(data)}
    function showImage(id,typ) {$('#singleImg').fadeTo(100,0.01) ;ajaxQuery({query:"showImage",id:id,typ:typ});}
    function response_showImage(data,params){$('#singleImg').html(data).fadeTo(500,1)}
    function showImageOnMain(id) {$('#imgOnMain').fadeTo(100,0.01) ;ajaxQuery({query:"showImageOnMain",id:id});}
    function response_showImageOnMain(data,params){$('#imgOnMain').html(data).fadeTo(500,1)}
    function showVideoOnMain(id) {$('#vidOnMain').fadeTo(100,0.01) ;ajaxQuery({query:"showVideoOnMain",id:id});}
    function response_showVideoOnMain(data,params){$('#vidOnMain').html(data).fadeTo(500,1)}
    function loadAddToBlog(url, typ, id) {$('#insCode').fadeTo(100,0.01) ;ajaxQuery(
    {query:"loadAddToBlog",url:url,typ:typ,id:id});}
    function response_loadAddToBlog(data,params){$('#insCode').html(data).fadeTo(500,1)}
    //var rFltState=0;
    function ReviewFlt(name,findBy, postArr) {
        $('#fltHeadButton').remove();
        ajaxQuery({query:"ReviewFlt",name:name,findBy:findBy,postArr:postArr});   }    
    function ReviewFltOff() { $('#filterPlace').html("").fadeTo(100,0.01);  $("#fltForm").submit();}    
    function response_ReviewFlt(data,params){$('#filterPlace').html(data).fadeTo(500,1);}

    function VideoFlt(name,findBy, postArr) {
        $('#fltHeadButton').remove();
        ajaxQuery({query:"VideoFlt",name:name,findBy:findBy,postArr:postArr});   }    
    function VideoFltOff() { $('#filterPlace').html("").fadeTo(100,0.01);  $("#fltForm").submit();}    
    function response_VideoFlt(data,params){$('#filterPlace').html(data).fadeTo(500,1);}
   
    function resetRewievFilter(){
            $('#filterPlace').html("").fadeTo(100,0.01);
            $("#fltForm").submit();        
    }
    
var ajaxGif="<img src='/design/site/images/ajax.gif' width=16>";
function unsubsUserComm(userId, itemId, path) { $('#subsStatus').html(ajaxGif+" отмена подписки");
    ajaxQuery({query:"unsubsUserComm",userId:userId, itemId:itemId, path:path}); }
    function response_unsubsUserComm(data,params){$('#subsStatus').html(data);}
function subsUserComm(userId, itemId, path) { $('#subsStatus').html(ajaxGif+" подписка на новые коментарии.");
    ajaxQuery({query:"subsUserComm",userId:userId, itemId:itemId, path:path}); }
    function response_subsUserComm(data,params){$('#subsStatus').html(data);}
function showAnonSubs(itemId, path) { $('#subsStatus').html(ajaxGif+" загрузка формы.");
    ajaxQuery({query:"showAnonSubs", itemId:itemId, path:path}); }
    function response_showAnonSubs(data,params){$('#subsStatus').html(data);}
function addAnonSubs(email, itemId, path) { $('#subsStatus').html(ajaxGif+" подписка на новые коментарии.");
    ajaxQuery({query:"addAnonSubs", email:email, itemId:itemId, path:path}); }
    function response_addAnonSubs(data,params){$('#subsStatus').html(data);}
function showComm(group, id, start) { $('#commPlace').html(ajaxGif+" загрузка коментариев");
   document.getElementById('start').value=start;//что бы при "посте" не терялась, какая страница открыта
    ajaxQuery({query:"showComm", group:group, id:id, start:start});
}
    function response_showComm(data,params){$('#commPlace').html(data);}
    
function editComm(id) { $('#comm_'+id).html(ajaxGif+" загрузка коментария");
    ajaxQuery({query:"editComm", id:id}); }
    function response_editComm(data,params){$('#comm_'+params.id).html(data);}
function cancelComm(id) { $('#comm_'+id).html(ajaxGif+" отмена");
    ajaxQuery({query:"cancelComm", id:id}); }
    function response_cancelComm(data,params){$('#comm_'+params.id).html(data);}
function postComm(id, txt) { $('#comm_'+id).html(ajaxGif+" сохранение");
    ajaxQuery({query:"postComm", id:id, txt:txt}); }
    function response_postComm(data,params){$('#comm_'+params.id).html(data);}
function checkLoginAvailable(login) { $('#check_login').html(ajaxGif+" проверка");
    ajaxQuery({query:"checkLoginAvailable", login:login}); }
    function response_checkLoginAvailable(data,params){$('#check_login').html(data);}
function checkEmailAvailable(login) { $('#check_email').html(ajaxGif+" проверка");
    ajaxQuery({query:"checkEmailAvailable", login:login}); }
    function response_checkEmailAvailable(data,params){$('#check_email').html(data);}
function postChangeModStatus(id, mode, param, reason) { $('#adminPanelProgress'+id).html(ajaxGif+" изменяем...");
    ajaxQuery({query:"postChangeModStatus", id:id, mode:mode, param:param, reason:reason }); }
    function response_postChangeModStatus(data,params){$('#adminPanel'+params.id).html(data);}
function postGetReasonModStatus(id, mode, param) { $('#reasonPlace'+id).html(ajaxGif+" укажите причину");
    ajaxQuery({query:"postGetReasonModStatus", id:id, mode:mode, param:param }); }
    function response_postGetReasonModStatus(data,params){$('#reasonPlace'+params.id).html(data);}
function postDelete(id, reason) { 
    ajaxQuery({query:"postDelete", id:id, reason:reason }); }
    function response_postDelete(data,params){$('#reasonPlace'+params.id).html('Удалено.');}
function toggleCommEnable(id) { 
    ajaxQuery({query:"toggleCommEnable", id:id}); }
    function response_toggleCommEnable(data,params){
        obj=eval("("+data+")");
        $('#comm_'+params.id).html(obj.txt);
        $('#commHead_'+params.id).html(obj.head);
    }
function getListOfModers(id) { $('#moderChange'+id).html(ajaxGif+" генерация списка");
    ajaxQuery({query:"getListOfModers", id:id}); }
    function response_getListOfModers(data,params){$('#moderChange'+params.id).html(data);}
function setNewModerator(id, userId) { 
    ajaxQuery({query:"setNewModerator", id:id, userId:userId}); }
    function response_setNewModerator(data,params){$('#adminPanel'+params.id).html(data);}
function AllPostAToB(id, userA, userB) { 
    ajaxQuery({query:"AllPostAToB", id:id, userA:userA, userB:userB}); }
    function response_AllPostAToB(data,params){$('#adminPanel'+params.id).html(data);}
function askNchangeRate(group, id) { 
    rate=prompt('Какой рейтинг установить?','');
    if (rate!="") ajaxQuery({query:"askNchangeRate", id:id, group:group, rate:rate}); }
    function response_askNchangeRate(data,params){$('a.rate_'+params.group+params.id).html(data);}
function makeCross(id, mode, dest) { $('#adminPanelProgress'+id).html(ajaxGif+" изменяем...");
    ajaxQuery({query:"makeCross", id:id, mode:mode, dest:dest}); }
    function response_makeCross(data,params){$('#adminPanel'+params.id).html(data);}

function getProfilePage(pageName, userId, params) { $('#profTxt').html(ajaxGif+" загружается").fadeTo(100,0.2);
    ajaxQuery({query:"getProfilePage", pageName:pageName, userId:userId, params:params}); }
    function response_getProfilePage(data,params){$('#profTxt').html(data).fadeTo(500,1);}
function postProfilePage(userId) { $('#profTxt').fadeTo(100,0.01);
    ajaxQuery({query:"postProfilePage", data:$("#fn").serialize(), userId:userId}); }
    function response_postProfilePage(data,params){$('#profTxt').html(data).fadeTo(500,1);}
    
    //a=prompt('dd?','');alert(a)
        
    function jWysiwyg_start(id) {
        (function($)
        {
            $('#'+id).wysiwyg({
                controls: {
                    strikeThrough : { visible : false },
                    underline     : { visible : false },

                    separator00 : { visible : false },

                    justifyLeft   : { visible : false },
                    justifyCenter : { visible : false },
                    justifyRight  : { visible : false },
                    justifyFull   : { visible : false },

                    separator01 : { visible : false },

                    indent  : { visible : false },
                    outdent : { visible : false },

                    separator02 : { visible : false },

                    subscript   : { visible : false },
                    superscript : { visible : false },

                    separator03 : { visible : false },

                    undo : { visible : true },
                    redo : { visible : true },

                    separator04 : { visible : true },

                    insertOrderedList    : { visible : true },
                    insertUnorderedList  : { visible : true },
                    insertHorizontalRule : { visible : true },

                    h4mozilla : { visible : true && $.browser.mozilla, className : 'h4', command : 'heading', arguments : ['h4'], tags : ['h4'], tooltip : "Header 4" },
                    h5mozilla : { visible : true && $.browser.mozilla, className : 'h5', command : 'heading', arguments : ['h5'], tags : ['h5'], tooltip : "Header 5" },
                    h6mozilla : { visible : true && $.browser.mozilla, className : 'h6', command : 'heading', arguments : ['h6'], tags : ['h6'], tooltip : "Header 6" },

                    h4 : { visible : true && !( $.browser.mozilla ), className : 'h4', command : 'formatBlock', arguments : ['<H4>'], tags : ['h4'], tooltip : "Header 4" },
                    h5 : { visible : true && !( $.browser.mozilla ), className : 'h5', command : 'formatBlock', arguments : ['<H5>'], tags : ['h5'], tooltip : "Header 5" },
                    h6 : { visible : true && !( $.browser.mozilla ), className : 'h6', command : 'formatBlock', arguments : ['<H6>'], tags : ['h6'], tooltip : "Header 6" },

                    separator07 : { visible : true },

                    cut   : { visible : true },
                    copy  : { visible : true },
                    paste : { visible : true }
                }
            });
        })(jQuery);
    }







    $(document).ready(function() {
        $("a.fancy").fancybox({
/*
            'easingIn'                : 'easeOutBack',
            'easingOut'                : 'easeInBack',
*/
            'zoomOpacity'            : true,
            'overlayShow'            : true,
            'zoomSpeedIn'            : 400,
            'zoomSpeedOut'        : 500,
            'padding'                    : 0
        });
    });


    function getRadioGroupValue(el_name) {
        var radioGroupObj=document.getElementsByName(el_name);
      for (var i=0; i < radioGroupObj.length; i++) if (radioGroupObj[i].checked) return radioGroupObj[i].value;
      return null;
    }


    function VisOrHide(el_name) {
        var obj=document.getElementById(el_name);
        obj.style.display=obj.style.display=='block'?'none':'block';
        return false;
    }


    function explode(delimiter,string) {
        var emptyArray={0:''};

        if (
            arguments.length!=2
            || typeof arguments[0]=='undefined'
            || typeof arguments[1]=='undefined'
        ) {return null;}

        if (
            delimiter===''
            || delimiter===false
            || delimiter===null
        ) {return false;}

        if (
            typeof delimiter=='function'
            || typeof delimiter=='object'
            || typeof string=='function'
            || typeof string=='object'
        ) {return emptyArray;}

        if (delimiter===true) {delimiter='1';}

        return string.toString().split(delimiter.toString());
    }

function deletePost(id, user) { 
    if (confirm("Вы действительно хотите удалить статью в корзину?"))
        ajaxQuery({query:"deletePost", id:id, user:user}); }
    function response_deletePost(data,params){ 
        //alert(data);
        document.location.href="/community/"+params.user+"/materials/"; 
    }
