function showlevel(level){
 //alert(level);
 //alert(document.getElementById(level).style.display);
 if(document.getElementById(level).style.display=='none') document.getElementById(level).style.display = "block";
 else document.getElementById(level).style.display = "none";
}

$(document).ready( function(){
    if($(".main_level_new").val()>0)
    {
            $('select[name="newitem[id_country]"]').html(make_string($(".main_level_new").val()));
            $('select[name="newitem[id_city]"]').html('<option value=""></option><option value="0">-все города-</option>');
            $('select[name="newitem[sch]"]').html('<option value=""></option><option value="0">-все школы-</option>'); 
            $('#cats').val(''); 
    }
    $(".main_level_new").live('change',function() {
            $('select[name="newitem[id_country]"]').html(make_string($(this).val()));
            $('select[name="newitem[id_city]"]').html('<option value="0">-все города-</option>');
            $('select[name="newitem[sch]"]').html('<option value="0">-все школы-</option>');
            $('#cats').val(''); 
    });
    $(".sub1_new").live('change',function() {
            $('select[name="newitem[id_city]"]').html(make_string($(this).val()));
            $('select[name="newitem[sch]"]').html('<option value="0">-все школы-</option>');
            $('#cats').val(''); 
    });
    $(".sub2_new").live('change',function() {
            $('select[name="newitem[sch]"]').html('<option value="0">-все школы-</option>');
            $('#cats').val(''); 
            if($(this).val()>0){
            $.ajax({
                    type: "POST",
                    data: "task=find_school&city="+$(this).val(),
                    url: "/search_school.php",
                    success: function(msg){
//                       alert(msg);
                       $('select[name="newitem[sch]"]').html(msg);      
                    }
                    });
            }
    });
    $(".sub3_new").live('change',function() {
            $('#cats').val(''); 
            $('select[name="newitem[id_age]"]').html('<option value="0">-любой возраст-</option>');
            $('select[name="newitem[id_cours]"]').html('<option value="0">-все курсы-</option>');
            $('select[name="newitem[pr_family]"]').html('<option value="0">-все типы проживания-</option>');
            $('select[name="newitem[pr_rezed]"]').html('<option value="0">-все типы питания-</option>');
            $.ajax({
                    type: "POST",
                    data: "task=find_all&city="+$(this).val(),
                    url: "/search_school.php",
                    success: function(msg){
//                       alert(msg);
                       $('#script').html(msg);      
                    }
                    });
    });
    $('select[name="newitem[id_age]"]').live('change',function() {
            if($('#cats').val() == '') return ; 
            $('select[name="newitem[id_cours]"]').html('<option value="0">-все курсы-</option>');
            $('select[name="newitem[pr_family]"]').html('<option value="0">-все типы проживания-</option>');
            $('select[name="newitem[pr_rezed]"]').html('<option value="0">-все типы питания-</option>');
            $.ajax({
                    type: "POST",
                    data: "task=find_age&city="+$(this).val()+"&list="+$('#cats').val(),
                    url: "/search_school.php",
                    success: function(msg){
//                       alert(msg);
                       $('#script').html(msg);      
                    }
                    });
    });
    $('select[name="newitem[id_cours]"]').live('change',function() {
            if($('#cats').val() == '') return ; 
            $('select[name="newitem[pr_family]"]').html('<option value="0">-все типы проживания-</option>');
            $('select[name="newitem[pr_rezed]"]').html('<option value="0">-все типы питания-</option>');
            $.ajax({
                    type: "POST",
                    data: "task=find_cours&city="+$(this).val()+"&list="+$('#cats').val()+"&age="+$('select[name="newitem[id_age]"] :selected').val(),
                    url: "/search_school.php",
                    success: function(msg){
//                       alert(msg);
                       $('#script').html(msg);      
                    }
                    });
    });
    $('select[name="newitem[pr_family]"]').live('change',function() {
            if($('#cats').val() == '') return ; 
            $('select[name="newitem[pr_rezed]"]').html('<option value="0">-все типы питания-</option>');
            $.ajax({
                    type: "POST",
                    data: "task=find_live&city="+$(this).val()+"&list="+$('#cats').val()+"&age="+$('select[name="newitem[id_age]"] :selected').val()+"&cours="+$('select[name="newitem[id_cours]"] :selected').val(),
                    url: "/search_school.php",
                    success: function(msg){
//                       alert(msg);
                       $('#script').html(msg);      
                    }
                    });
    });
    $('select[name="newitem[pr_rezed]"]').live('change',function() {
            if($('#cats').val() == '') return ; 
            $('select[name="newitem[price1]"]').html('<option value="0">-любое количество недель-</option>');
            $.ajax({
                    type: "POST",
                    data: "task=find_num&city="+$(this).val()+"&list="+$('#cats').val()+"&fam="+$('select[name="newitem[pr_family]"] :selected').val()+"&age="+$('select[name="newitem[id_age]"] :selected').val()+"&cours="+$('select[name="newitem[id_cours]"] :selected').val(),
                    url: "/search_school.php",
                    success: function(msg){
                       //alert(msg);
                       $('#script').html(msg);      
                    }
                    });
    });
    $("#nums").live("click",function() {
        if($("#nums").val()==1) $("#nums").val('');
    });
    $("#nums").live("keyup",function() {
        var val =  $("#nums").val();
        var newVal = parseInt(val);
        if (val.length > 1)  newVal = val;
        if (isNaN(newVal)) newVal = "";
        if (newVal < 1) newVal = "";
        $("#nums").val(newVal); 
    });
    function make_string(k)
    {
        var str = '<option value="0">-все-</option>';
        if (c[k]!=undefined){
            var count = c[k].length;
            for(i1=0;i1<count;i1++)
               {    
                  var key = c[k][i1]; 
                   str += '<option value="'+key+'">'+x[key]+'</option>';
               }
            }
        return str;
    }
});


function ask_page(task,where,id){
$.ajax({
        type: "POST",
        data: "task="+task+"&id="+id+"&where="+where,
        url: "/page.php",
        success: function(msg){
        $("#"+where).html( msg );
        },
        beforeSend : function(){ $("#"+where).html( '<img src="/images/design/ajax-loader.gif"/>' ); if(where=='el-1') $("#el-2").html('<select onchange="" name="geogr[]"></select>'); if(where=='el-11') $("#el-21").html('<select onchange="" name="geogr[]"></select>');}  
        });
}
function count_price(){
    $.ajax({
        type: "POST",
        data: "task=rtete&hotel="+document.order.hotel.value+"&transf="+document.order.transf.value+"&arr_date="+document.order.arr_date.value+"&night="+document.order.fax.value+"&question="+document.order.question.value,
        url: "/find_price.php",
        success: function(msg){
        $("#price").html( msg );
        },
        beforeSend : function(){ $("#price").html( '<img src="/images/design/ajax-loader.gif"/>' ); }  
    });
}
function count_price2(){
    $.ajax({
        type: "POST",
        data: "task=rtete2&hotel="+document.order.hotel.value+"&night="+document.order.fax.value+"&question="+document.order.question.value,
        url: "/find_price.php",
        success: function(msg){
        $("#price").html( msg );
        },
        beforeSend : function(){ $("#price").html( '<img src="/images/design/ajax-loader.gif"/>' ); }  
    });
}
function check_g1() {
if($(".main_level_new").val()==0 || $(".main_level_new").val()=='' || $(".main_level_new").val()==' ')
 {
    alert('Поле "язык обучения" является обязательным для выбора!');
    return false;
 } 
}
function check_g() {
 if (document.search_by_params.geogrC=='undefined')
 {
    alert('Необходимо выбрать все поля!');
    return false;
 }
 if  (document.search_by_params.geogrC.value=='')
 {
    alert('Необходимо выбрать все поля!');
    return false;
 } 
}
function verify2() {
var err;

var themessage = "Проверте правильность заполнения данных: \nИсправте следующие ошибки :\n";
if (document.forms.order.name.value=="") {
themessage = themessage + " - Вы незаполнили поле : ФИО\n";
}
if ((!emailCheck(document.forms.order.e_mail.value))||(document.forms.order.e_mail.value=='')) {
themessage = themessage + " - Неправильный e-mail адрес\n";
}
if (document.forms.order.tel.value=="") {
themessage = themessage + " - Вы не указали контактный телефон\n";
}
if (themessage == "Проверте правильность заполнения данных: \nИсправте следующие ошибки :\n")
{
save_order()
return true;
}
 else 
alert(themessage);
return false;
}
function save_order(){
$.ajax({
        type: "POST",
        data: "task=send&"+$("#order").serialize() ,
//        data: "task=send&price="+$("#price").html()+"&"+$("#order").serialize() ,
        url: "/order.php",
        success: function(msg){
//            alert(msg);
        $("#make_order").html( msg );
        },
        beforeSend : function(){$("#make_order").html( '<center><img src="/images/design/ajax-loader.gif" align="middle"/></center>' );}  
        });
}   
function emailCheck (emailStr) {
if (emailStr=="") return true;
var emailPat=/^(.+)@(.+)$/;
var matchArray=emailStr.match(emailPat);
if (matchArray==null) 
 {
   return false;
 }
return true;
}
$("document").ready( function() {
        $(".tab_header li").click(function() {
            $(".tab_header li").removeClass("select");
            $(this).addClass("select");            
            $(".tab_content span").css("display", "none");
            var tab = $(this).attr("target");            
            $(".tab_content ."+tab).css("display", "block");            
        });
  
});
