// using replacement for latin symbols to georgian
function str_replace(f, r, s){
    var ra = r instanceof Array,
    sa = s instanceof Array,
    l = (f = [].concat(f)).length,
    r = [].concat(r),
    i = (s = [].concat(s)).length;
    while(j = 0, i--)
        while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j < l);
    return sa ? s : s[0];
}
//---
function ka(str){
    str = str_replace('R', 'ღ', str);
    str = str_replace("j","ჯ",str);
    str = str_replace("u","უ",str);
    str = str_replace("k","კ",str);
    str = str_replace("e","ე",str);
    str = str_replace("n","ნ",str);
    str = str_replace("g","გ",str);
    str = str_replace("S","შ",str);
    str = str_replace("w","წ",str);
    str = str_replace("z","ზ",str);
    str = str_replace("f","ფ",str);
    str = str_replace("Z","ძ",str);
    str = str_replace("v","ვ",str);
    str = str_replace("a","ა",str);
    str = str_replace("p","პ",str);
    str = str_replace("r","რ",str);
    str = str_replace("o","ო",str);
    str = str_replace("l","ლ",str);
    str = str_replace("W","ჭ",str);
    str = str_replace("C","ჩ",str);
    str = str_replace("y","ყ",str);
    str = str_replace("s","ს",str);
    str = str_replace("m","მ",str);
    str = str_replace("i","ი",str);
    str = str_replace("t","ტ",str);
    str = str_replace("q","ქ",str);
    str = str_replace("b","ბ",str);
    str = str_replace("h","ჰ",str);
    str = str_replace("d","დ",str);
    str = str_replace("J","ჟ",str);
    str = str_replace("x","ხ",str);
    str = str_replace("c","ც",str);
    str = str_replace("T","თ",str);
    return str;
}

// status manipulation - loader show/hide
function statusAD(){
    $.ajaxSetup({
            success: $(function(){
                    $('#dv_loader').show()
            })
    });
    $('#dv_loader').ajaxComplete(function(){
            $('#dv_loader').hide();
    });
}
$(function() {
        $( "#dialog:ui-dialog" ).dialog( "destroy" );
        //---
        $( ".helpMenu > button" ).button({
                icons: {
                    primary: "ui-icon-locked"
                }
        })
        //---
        $(".helpMenu > button").bind('click', function(){
                var obj = $( "#dialog-confirm" );
                obj.find('span:last').html('' + ka('daadastureT programidan gamosvla!') + '');
                obj.dialog({
                        resizable: false,
                        width: 340,
                        height:160,
                        modal: true,
                        buttons: {
                            OK: function(){
                                $( this ).dialog( "close" );
                                document.location.href='?page=default&log=tr';
                            },
                            Cancel: function(){
                                $( this ).dialog( "close" );           
                            }
                        }
                });
        });
        //---
        $('#checkact').bind('click', function(event){
                var obj = $( "#dialog-confirm" );
                var el = $(event.target);
                var priv_object_id = el.attr('data-priv_object_id');
                var applicant_obl_status = '';
                if(el.is(':checked')){
                    var str = ka('darwmunebuli xarT daafiqsiroT gadaxda?');
                    applicant_obl_status = 'Y';
                }else{
                    applicant_obl_status = 'N';
                    var str = ka('darwmunebuli xarT gaauqmoT gadaxda?');
                }
                obj.find('span:last').html('' + str + '');
                obj.dialog({
                        resizable: false,
                        height:160,
                        modal: true,
                        buttons: {
                            Yes: function(){
                                $( this ).dialog( "close" );
                                $.post(
                                    "actions/choblstatus.php",
                                    {
                                        applicant_obl_status:   applicant_obl_status,
                                        priv_object_id:         priv_object_id
                                    },
                                    function(data){
                                        obj.find('span:last').html('' + data.msg + '');
                                        obj.dialog({
                                                resizable: false,
                                                width: 420,
                                                height:160,
                                                modal: true,
                                                buttons: {
                                                    OK: function(){
                                                        $( this ).dialog( "close" );                             
                                                    }
                                                }
                                        });
                                    },
                                    "json"
                                );                                
                            },
                            No: function() {
                                el.attr('checked', !el.attr('checked'));
                                $( this ).dialog( "close" );
                            }
                        }
                });
        });
});
