$(function() {

//add comentariu
$(".comanda_submit").click(function() {


//alert ("ceva");


var agent  = $('select[name=agent] option:selected').val();
var judet  = $("#judet").val();
var produs  = $("#produs").val();
var id_produs  = $("#id_produs").val();
var prenume  = $("#prenume").val();
var observ  = $("#observ").val();
var mailul  = $("#mailul").val();
var datefct = $("#datefct").val();
var tip = $("#tip").val();
var coco = $("#coco").val();




		$(".error").hide();
		var hasError = false;

   	var nume  = $("#nume").val();
		if(nume  == '') {
		$("#nume").after('<font color="#FF0000" size="-3">Acest camp este obligatoriu!</font>');
			hasError = true;
		}


   	var telefon = $("#telefon").val();
		if(telefon == '') {
		$("#telefon").after('<font color="#FF0000" size="-3">Acest camp este obligatoriu!</font>');
			hasError = true;
		}

	
    var adresalivr = $("#adresalivr").val();
		if(adresalivr == '') {
		$("#adresalivr").after('<font color="#FF0000" size="-3">Acest camp este obligatoriu!</span>');
			hasError = true;
		}
		

var varianta = 1;


  if(hasError == true) {
		  $("#erori").fadeIn("600").html('<font color="#FF0000" size="-2">Nu ati completat toate campurile obligatorii</font>');
		
		} else {


var dataString ='agent=' +  agent  + '&judet=' + judet + '&prenume=' + prenume + '&observ=' + observ + '&mailul=' + mailul + '&datefct=' + datefct + '&nume=' + nume + '&telefon=' + telefon + '&adresalivr=' + adresalivr + '&id_produs=' + id_produs  + '&produs=' + produs  + '&tip=' + tip + '&varianta=' + varianta + '&coco=' + coco;
//alert ("se adauga!");
 $('.incarcare').show();
  	$.ajax({
	type: "POST",
	url: "ajax-all.php",
	data: dataString,
	success: function() {
	 	 $('.success').fadeIn(5000).show();
		 $('.incarcare').fadeOut(4000);	
		 $('#inregistrare').slideUp("slow", function () {
        $("#msg").html("<br/>Comanda a fost trimisa!. Va multumim <img src='succes.gif' width='16' height='16' /> <a href='index.php'>Inapoi</a><br/>");
    });

		 
	}
});
	
 $('.success').hide();	
 
 //paranteza if
}

 return false;
  })

//-----------------------------------------------------------------------------end function---------------------------------------------------------------
});