/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function getXmlHttp(){
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function changeOwenshipForm() {
    if ($('#owenship_form_individual').attr('checked')){
        $('#owenship_legal').hide();
        $('#owenship_individual').show();
    } else {
        $('#owenship_legal').show();
        $('#owenship_individual').hide();
    }
}

function checkShippingMethod() {
    if ($('#select_shipping_method_1').attr('checked') || $('#select_shipping_method_2').attr('checked')) {
        $('#shipping_address').show();
        var country = document.getElementById('contry');
        var city = document.getElementById('city');
        if ($('#select_shipping_method_1').attr('checked')){
            country.disabled = true;
            city.disabled = true;
            $('#contry option:contains("Россия")').attr('selected', 'yes');;
            $('#city option:contains("Москва")').attr('selected', 'yes');;
        } else {
            country.disabled = false;
            city.disabled = false;
        }
    } else {
        $('#shipping_address').hide();
    }
}

function getCitys() {
    var country_id = $('#contry option:selected').val();
    var url = '/index.php?order2_shipping_quick=yes&get_citys=1&country_id='+country_id;
    var req = getXmlHttp();
    req.open('GET', url, false);
    req.send(null); 
    if (req.readyState == 4){
        var jsonData = $.parseJSON(req.responseText);
        $('#city').empty();
        for(var i = 0; i < jsonData.length; ++i){
            $('#city').append($('<option value="'+jsonData[i].Id+'">'+jsonData[i].Name+'</option>'));
        }
    }
}
