var url = window.location.host;  
var first_toggle= true;

function switchLang(lang)
{
    //alert('dd');
    if (typeof($.post)=="function")
    {
    $.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "switchLang",
            id: lang
        },
        function( data )
        {
            //alert(data);
            document.location.href = data;
        }
     );   
    }
    else
    {
    jQuery.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "switchLang",
            id: lang
        },
        function( data )
        {
            //alert(data);
            document.location.href = data;
        }
     );   
    }
}


function changeCountriesFront(cont_id)
{
    $.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "changeCountries",
            id: cont_id
        },
        function( data )
        {
            $('#country').html(data);
        }
    );   
    return false; 
}


function changeTownsFront(country_id)
{
    $.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "changeTowns",
            id: country_id
        },
        function( data )
        {
            $('#town').html(data);
        }
    );   
    return false; 
}

function changeDistrictsFront(town_id)
{
    $.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "changeDistricts",
            id: town_id
        },
        function( data )
        {
            $('#district').html(data);
        }
    );   
    return false; 
}

function changeCountriesFrontBest(cont_id)
{
    $.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "changeCountries",
            id: cont_id,
            is_best: 1
        },
        function( data )
        {
            $('#country1').html(data);
        }
    );   
    return false; 
}

function changeTownsFrontBest(country_id)
{
    $.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "changeTowns",
            id: country_id,
            is_best: 1
        },
        function( data )
        {
            $('#town1').html(data);
        }
    );   
    return false; 
}

function changeDistrictsFrontBest(town_id)
{
    $.post(
        "http://"+url+"/index.php",
        {
            s:  "ajax", 
            ev: "changeDistricts",
            id: town_id,
            is_best: 1
        },
        function( data )
        {
            $('#district1').html(data);
        }
    );   
    return false; 
}

function constructUrl(mapp)
{
    new_url = '';
    if (mapp=='map1')
        add = '1';
    else
        add= '';
    var continent = $("#continent" + add + " option:selected").attr('title');
    var country = $("#country" + add + " option:selected").attr('title');      
    var region = $("#town" + add + " option:selected").attr('title');      
    var city = $("#district" + add + " option:selected").attr('title');      
    //alert(continent+" "+country+" "+region+" "+city+"nu "+new_url);
    if (continent && continent!='')
    {
        //alert('q1');
        new_url = new_url + "/" + continent;
        if (country && country!='')
        {
            new_url = new_url + "/" + country;
            if (region && region!='')
            {
                new_url = new_url + "/" + region;
                if (city && city!='')
                {
                    new_url = new_url + "/" + city;
                }
            }
        }    
    }   
    //alert("--"+new_url); 
    if (new_url!='')
    {
        new_url = mapp + new_url + '.htm';
    }
    else
    {
        //alert(mapp);
        new_url = mapp + '.htm';
         
    }
    //alert(new_url);
    
    window.location = new_url;
    
    return false;
}

function toggleBlocks(type)
{
    if (first_toggle)
    {
        $("#"+type+"1").toggle("slow");
        $("#"+type+"2").toggle("slow");
        first_toggle = false;
    }
    else
    {
        //$(".toggle").toggle("explode", { pieces: 25 }, 1000);
        $(".toggle").toggle("slow");
    }
}

function firstShow(type)
{
    alert(type);
    //$(".toggle").toggle("explode", { pieces: 25 }, 1000);
    $("#"+type+"1").toggle("slow");
    $("#"+type+"2").toggle("slow");
}


function verify_address(address,id)
{
    geocoder = new GClientGeocoder();
    geocoder.getLatLng(
            address,
            function(point)
            {    
            //alert("point "+point + "x "+point.x); 
                if (point)  
                {
                    $.post(
                        "http://"+url+"/index.php",
                        {
                            s:  "ajax", 
                            ev: "changeCoords",
                            x: point.x,
                            y: point.y,
                            z: 14,
                            id: id
                        },
                        function( data )
                        {
                            $('#result_'+id).html('x: ' + point.x + 'y: ' + point.y + 'z: 14');
                        }
                    ); 
                }
                else
                {
                    $('#result_'+id).html('not found');    
                }
            }
        ); 
    return false;   
}

