$(document).ready(function(){
        setGeoLoaders();
        $('textarea[limit]').limit({leftChars:'Осталось'});  
        if ($("span.link-dashed a").length > 0)  
    $('span.link-dashed a').click(function(){
        var parent_tr = $(this).parents("tr");
        var cl='w-ugol';
        if (parent_tr.attr('class')=='even')
            cl='s-ugol';
        if (parent_tr.attr('class')=='top')
            cl='y-ugol';
            if($(this).attr('class')=="bm")
            {
                rotateBookmark(this.id, 'fr', this,parent_tr.children("td.foto-business").children("a").children("img"),cl);
            }
            else
            {
                rotateBookmark(this.id, 'rb', this,parent_tr.children("td.foto-business").children("a").children("img"),cl);
            }
      return false;
    }); 
  if ($('#userAvatarInput').length > 0) {
        var logo_upload = new AjaxUpload('userAvatarInput', {
            action: '/xajax/xajax_broker.php',
            autoSubmit: true,
            data: {
                func: 'brNewPhotoSave',
                responseType: 'xml'
            },
            onChange: function(file, ext){
                if (!(ext && /^(jpg|jpeg|png|gif)$/.test(ext))) {
                    
                    return false;
                }
            },
            onSubmit: function(file, ext){
                showWaitWindow();
            },
            onComplete: function(file, response){
                closeWaitWindow();
                if ($('error', response).text()) {
                    alert($('error', response).text());
                } else {
                    var fname = $('filename', response).text();
                    $("#userAvatar").attr('src',fname);
                    $("#photoDeletor").show();
                }
            }
        });
    }
    if ($("#photoDeletor").length > 0)
    $("#photoDeletor").click(function(){
        if (confirm("Удалить Вашу фотографию?")) {
            $.post("/xajax/xajax.php", {
                func: "delUserPhoto"
            }, function(xml){
                var state = $("state", xml).text();
                
                if (state = 'deleted') {
                    $("#userAvatar").attr('src', '/img/def/66x66.gif');
                    $("#photoDeletor").hide();
                }
            }, "xml");
            
        }
        return false;
    });
    if ($('#userBigPhotoInput').length > 0) {
        var big_upload = new AjaxUpload('userBigPhotoInput', {
            action: '/xajax/xajax_broker.php',
            autoSubmit: true,
            data: {
                func: 'brNewBigPhotoSave',
                responseType: 'xml'
            },
            onChange: function(file, ext){
                if (!(ext && /^(jpg|jpeg|bmp|gif|png)$/.test(ext))) {
                    return false;
                }
            },
            onSubmit: function(file, ext){
                showWaitWindow();
            },
            onComplete: function(file, response){
                closeWaitWindow();
                if ($('error', response).text()) {
                    alert($('error', response).text());
                } else {
                    var fname = $('filename', response).text();
                    $("#userBigPhoto").attr('src',fname);
                    $("#bigPhotoDeletor").show();
                }
            }
        });
    }
    if ($('#bigPhotoDeletor').length > 0)    
    $("#bigPhotoDeletor").click(function(){
        if (confirm("Удалить Вашу фотографию?")) {
            $.post("/xajax/xajax_broker.php", {
                func: "delBigPhoto"
            }, function(xml){
                var state = $("state", xml).text();
                
                if (state = 'deleted') {
                    $("#userBigPhoto").attr('src', '/img/def/200x150.gif');
                    $("#bigPhotoDeletor").hide();
                }
            }, "xml");
            
        }
        return false;
    });
    if ($('#companyLogoInput').length > 0)
    if ($('#companyLogoInput').length > 0) {
        var big_upload = new AjaxUpload('companyLogoInput', {
            action: '/xajax/xajax_broker.php',
            autoSubmit: true,
            data: {
                func: 'brNewCompanyLogoSave',
                responseType: 'xml'
            },
            onChange: function(file, ext){
                if (!(ext && /^(jpg|jpeg|bmp|gif|png)$/.test(ext))) {
                    return false;
                }
            },
            onSubmit: function(file, ext){
                showWaitWindow();
            },
            onComplete: function(file, response){
                closeWaitWindow();
                if ($('error', response).text()) {
                    alert($('error', response).text());
                } else {
                    var fname = $('filename', response).text();
                    $("#userCompanyLogo").attr('src',fname);
                    $("#companyLogoDeletor").show();
                }
            }
        });
    }
    if ($('#companyLogoDeletor').length > 0)
    $("#companyLogoDeletor").click(function(){
        if (confirm("Удалить Вашу фотографию?")) {
            $.post("/xajax/xajax_broker.php", {
                func: "delCompanyLogo"
            }, function(xml){
                var state = $("state", xml).text();
                
                if (state = 'deleted') {
                    $("#userCompanyLogo").attr('src', '/img/def/200x150.gif');
                    $("#companyLogoDeletor").hide();
                }
            }, "xml");
            
        }
        return false;
    });        
});