function show_form(class_hide,id_show,thi_s){
    $('.'+class_hide).hide();
    $('#'+id_show).show();
}
function edit_class(class_old,id_new){
    $(class_old).attr('class','');
    $('#'+id_new).attr('class','active');
}
function show_form2(_show,thi_s){
    if($(thi_s).css('text-decoration')=='none'){
        $(thi_s).css('text-decoration','underline');
    }
    else{
        $(thi_s).css('text-decoration','none');
    }
    boss_li=$(thi_s).parent('li');
    boss_ul=boss_li.parent('ul');
    each_boss=boss_ul.children('li');
    parent_ul=boss_li.children('ul');
    $.each(each_boss,function(key,value){
        $(value).children('ul').hide('fast');
        $(value).find('a.plus').html('+');
    })
    $(_show).animate({
        "height":"toggle",
        "opacity":"toggle"
    },"normal",function(){
        $this=$(thi_s);
        parent_li=$this.parent('li');
        children_ul=parent_li.children('ul').css('display');
        children_a=parent_li.find('a.plus');
        if(children_ul=='block'){
            children_a.html('<span style="padding:0 2px 0 1px">-</span>');
        }
        else{
            children_a.html('+');
        }
    });
}
function show_form3(_show,thi_s){
    $this=$(thi_s);
    parent_tbody=$this.parent('td').parent('tr').parent('tbody');
    children_tr=parent_tbody.children('tr');
    $.each(children_tr,function(key,value){
        $(value).find('td.right-td').css('display','none');
    });
    $(_show).animate({
        "height":"toggle",
        "opacity":"toggle"
    },"normal");
    parent_tr=parent_tbody.children('tr');
    $.each(parent_tr,function(key,value){
        $(value).children('td').children('a').attr('class','');
    });
    $this.attr('class','active');
}
function show_form4(_show){
    $(_show).toggle();
}
var i,j;
function send_ajax(a_id,a_url,a_data,a_val,id_showhide){
    $.ajax({
        url:a_url,
        dataType:'html',
        data:a_data,
        cache:true,
        type:'POST',
        async:false,
        success:function(html){
            $('#'+a_id).html(html);
            if(a_val){
                $('#'+a_id).val(a_val);
            }
            if(id_showhide){
                if(html){
                    $('#'+id_showhide).show();
                }else{
                    $('#'+id_showhide).hide();
                }
            }
            if(html){
                $('#'+a_id).parent().find('.newListSelected').remove();
                $('#'+a_id).sSelect();
                $('#'+a_id).resetSS();
                if(a_val){
                    $('#'+a_id).getSetSSValue(a_val);
                }
                else{
                    $('#'+a_id).getSetSSValue();
                }
            }
            return true;
        }
    });
}
function change_list(a_url,id,a_id,a_val,a_cat,id_showhide){
    $('#'+a_id).find('option').remove();
    var id_list=$('#'+id).val();
    if(id_list){
        send_ajax(a_id,a_url,{
            action:'get_list',
            id_list:id_list,
            cat:a_cat
        },a_val,id_showhide);
    }else{
        $('#'+a_id).parent().find('.newListSelected').remove();
        $('#'+a_id).sSelect();
        $('#'+a_id).resetSS();
    }
}
function limitText(limitField,limitCount,limitNum){
    if(limitField.value.length>limitNum){
        limitField.value=limitField.value.substring(0,limitNum);
    }else{
        limitCount.value=limitNum-limitField.value.length;
    }
}
function update_mark(id,id_mark){
    var q=$('#'+id+' option:selected').text();
    var text=$('#'+id_mark).val();
    if(text)text+=', ';
    $('#'+id_mark).val(q);
}
$(document).ready(function(){
    $("input[type=file]").live('change',function(){
        var text_file=$(this).val();
        $('.faketext').text(text_file);
    });
    if($(window).width()<1050) {
        $('#usermenu ul li').css('margin','0 12px');
        $('.bloginpadd').css('width','72%');
    }
    
    $('span.small').live('click',function(){
        $(this).parent().children('input').focus();
        $(this).hide();
    })
    $('.reg input').live('focusin',function(){
        $(this).parent().children('span.small').hide();
    });
    $('.reg input').each(function(){
        if ($(this).val())
            $(this).parent().children('span.small').hide();
    })
});
function changeLogin(_this){
    _this.value = translit(_this.value);
}
function translit(str) {
    str = str.toLowerCase();
    var re = / /g;
    str = str.replace(re, "_");


    var LettersFrom = "àáâãäåçèêëìíîïðñòóôöû".split('');
    var LettersTo   = "abvgdeziklmnoprstufcy".split('');

    var BiLetters =  {
        "é" : "jj",
        "¸" : "jo",
        "æ" : "zh",
        "õ" : "kh",
        "÷" : "ch",
        "ø" : "sh",
        "ù" : "shh",
        "ý" : "je",
        "þ" : "ju",
        "ÿ" : "ja",
        "ú" : "",
        "ü" : ""
    };

    var Caps  = "ÀÁÂÃÄÅ¨ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÛÝÞß";
    var Small = "àáâãäå¸æçèéêëìíîïðñòóôõö÷øùüúûýþÿ";

    for(var key in Caps) {
        re = new RegExp(Caps[key], "g")
        str = str.replace(re, Small[key]);
    }
    for(var key in BiLetters) {
        re = new RegExp(key, "g")
        str = str.replace(re, BiLetters[key]);
    }
    for(var key in LettersFrom) {
        re = new RegExp(LettersFrom[key], "g")
        str = str.replace(re, LettersTo[key]);
    }

    str = str.replace(/[^a-z0-9_]+/mi, "");

    return str;
}

function addphone(){
    count_phone++;
    $('input[name=phone'+count_phone+']').show();
    $('input[name=phone'+count_phone+']').css('margin-top','10px');
    if (count_phone == 5){
        $('#addPhone').hide();
    }
    return false;
}
