function changeCity( countryIdName, cityIdName)
{
    countryId = $("#" + countryIdName).val();
    
    v = $.getJSON("/directory/getCityList?vTimer=no&countryId="+countryId,
        function(data)
        {
            if ( data.error)
            {
                alert( "Ошибка: " + data.msg);
            }
            else
            {
                updateOptionList( "#" + cityIdName, data);
            }
          
        });
}

function changeSchool( cityIdName, schoolIdName)
{
    fromId = $("#" + cityIdName).val();
    
    //alert( countryId);
    
    v = $.getJSON("/directory/getSchoolList?vTimer=no&cityId="+fromId,
        function(data)
        {
            if ( data.error)
            {
                alert( "Ошибка: " + data.msg);
            }
            else
            {
                updateOptionList( "#" + schoolIdName, data);
            }
          
        });
}

function changeHigheducation( cityIdName, higheducationIdName)
{
    fromId = $("#" + cityIdName).val();
    
    //alert( countryId);
    
    v = $.getJSON("/directory/getHigheducationList?vTimer=no&cityId="+fromId,
        function(data)
        {
            if ( data.error)
            {
                alert( "Ошибка: " + data.msg);
            }
            else
            {
                updateOptionList( "#" + higheducationIdName, data);
            }
          
        });
}

function updateOptionList( id, data)
{
    o = new Object();
                
    $( id).removeOption(/./);
    $( id).addOption( "0", "--- выбрать ---");
    
    if( id == "#higheducation_higheducationId" || id == "#school_schoolId" || id == "#cityId" || id == "#siteId")
        $( id).addOption( "other", "--- другое ---");
    
        
    $.each(data, function(i,item)
    {
        $( id).addOption( item.id, item.name);
        
    });
    //$( id).addOption( o, false);
    $( id).selectOptions('0',true);
    $( id).attr("disabled", false);
}


function showAdvSearch()
{
    $("#advSearch").show();
}


function updateAddGeo( $countryId, $cityId)
{
    
}

function anotherSchool()
{
    
}

function anotherHigheducation()
{
    
}

function show(id)
{
    //hideAll();
    document.getElementById( id).style.display="block";
    //$("#" + id ).addClass("form-fact-sel");
    //$("#" + id + "Menu").addClass("sel");
}

function hide(id)
{
    document.getElementById( id).style.display="none";
}

function swap( id)
{
    if ( document.getElementById( id).style.display=="none") show(id);
    else hide(id);
}

function hideAll()
{
    arr = ["addForm"];
    for( i=0;i<arr.length; i++)
    {
        document.getElementById( arr[i]).style.display="none";
        $("#" + arr[i] ).removeClass("form-fact-sel");
        $("#" + arr[i] + "Menu").removeClass("sel");
    }
}

function showOther( id, otherId)
{
    
    val = $("#" + id).val();
    
    if( val == "other")
    {
        $("#" + otherId).show();
    }
    else
    {
        $("#" + otherId).hide();
    }
}