
function rendeles_adatok(){
    $.ajax({
       type: "POST",
       url: "ajax.php",
       cache: false,
       data: "page=rendeles_adatok",
       success: function(msg){
       $("#kosar_tartalom").html(msg);
           rendeles_adatok_init();
       }
    });	
}

function rendeles_adatok_init(){
    $(document).ready(function(){
        if ($("#ajax_page_name").val() == "rendeles_adatok" ){   
            
            user_tartalom_zar();
            $("#user_tartalom").html("");
            
            ch_szall_mod();
            rendel_ajax_submit_add();
            szall_mod();
            szall_cim();
            orszag_betolt();
            cimek_select();
            
            $(".szallito_id").click(function (){
                cimek_select();
            });
        }
    });
}

function ch_szall_mod(){
    
	$(".szallito_id").click(function () {
        szall_mod();
	});

	$(".szallitas_cim").click(function () {
        szall_cim();
	});  
}

function szall_mod(){
    var szallito_helyben = $("input[name=szallito_id]:checked").attr("szallito_helyben");
    if (szallito_helyben == "I"){
   	    $("#szall_select").slideUp("normal"); // zár
    } else {
        $("#szall_select").slideDown("normal"); // nyit
    }
}

function szall_cim(){
	var cim = $("input[name=szallitas_cim]:checked").attr("value");
    if (cim == "szamla"){
   	    $("#szallitas_cim_elter").slideUp("normal"); // zár
    } else {
        $("#szallitas_cim_elter").slideDown("normal"); // nyit
    }
}

function rendel_ajax_submit_add(){
 $(".form_megrendelo").submit(function() {
    $(this).ajaxSubmit({
        target: "#kosar_tartalom",
        beforeSubmit: rendel_ell,
        success: megrenel_gomb
    });
    return false;
});
}
 
function szallitasi_mod_ell(){
    // szállítási mód
   	var val = $("input[name=szallito_id]:checked").val(); 
	if (val>0){
	    return true; 
	}else{
		return false;
	}
}

function rendel_ell(){
    
    back = true;
    
    return true;
    
    /*
    if( szallitasi_mod_ell() === false){
        	alert("Az átvétel helyét ki kell választani");
		back = false;
    }
    
    
    $(".nemures").each(function(){ 
        if ($(this).attr("value").length>1){
          $(this).css({'background-color' : 'white'});   
        } else {
          $(this).css({'background-color' : '#FF9B9B'});
          back = false;
        }
     });
     
     
    
     var szall = $("input[name=szallitas_cim]:checked").val(); 
     if (szall== "posta"){
     $(".nemures2").each(function(){ 
        if ($(this).attr("value").length>1){
          $(this).css({'background-color' : 'white'});   
        } else {
          $(this).css({'background-color' : '#FF9B9B'});
          back = false;
        }
      });
      }
      
    return back;
    */    
}  

function cimek_select(){
    if( szallitasi_mod_ell() === false){
        $("#cimek_select").slideUp("normal"); // zár
    }else{
        $("#cimek_select").slideDown("normal"); // nyit
    }    
}

function megrenel_gomb(){
    $("#megrendel_gomb").click(function () {    
        if($("#tobb_mint_egy").attr("value")=="igen"){
            $("#tobb_mint_egy_text").dialog("open");
        }
        megrendeles();
    });
    
    
    rendeles_adatok_init();
    document.location.href="#kosar";
}

function feliratkozok(){
    $("#form_feliratkozas").ajaxSubmit({
        type: "POST",
        url: "ajax.php?page=rendeles_feliratkozas",
        cache: false,        
        target: "#kosar_tartalom",
        success: function(msg){
       	    $("#kosar_tartalom").html(msg);
       }
    });
    
}

function megrendeles(){
    if($("#tobb_mint_egy_ok").attr("value")=="igen"){
        $.ajax({
           type: "POST",
           url: "ajax.php",
           cache: false,
           data: "page=rendeles_megrendel" ,
           success: function(msg){
           	$("#kosar_tartalom").html(msg);
           }
        });
        $("#kosar_tartalom_display").html("A kosár üres.");  
    }
}


