
$(document).ready(function(){

	var com_txt = "";
	var tipo_user = "";
	var ced_txt = "";
	var nom_txt = "";
	var telf_txt = "";
	var dir_txt = "";
	var mail_txt = ""; 
	//$("#formulario").hide();
	//$("#consulta_ticket").hide();
	//$("#tabla_resul").hide();
	$("#formulario").show();
	$("#mjs").hide();
	$("#btn_atras_genero").hide();

	/*$("#btn_atras_busqueda").click(function(){
		$("#consulta_ticket").hide();
		$("#tck_txt").val("");
		$("#buscar").show();
		$("#ingreso").show();
		$("#tabla_resul").hide();
		$("#titulo").show();
	});*/

	

	/*$("#btn_atras_ingreso").click(function(){
			 $("#consulta_ticket").hide();
			 $("#tck_txt").val("");
			 $("#buscar").show();
			 $("#ingreso").show();
			 $("#formulario").hide();
			 $("#titulo").show();
	});*/

	

	/*$("#buscar").click(function(){	
	    $("#buscar").hide();
		$("#ingreso").hide();
		$("#consulta_ticket").show();
		$("#titulo").hide();
	});*/

	

	/*$("#buscar_btn").click(function(){
	    EliminarTodoBusqueda();
	   $.post('buscar.php',{ codigo:$('#tck_txt').val()}, function(data){ 
				    if(data) {
				         $('#loading2').show();
				         codigo2 = $('#tck_txt').val();
				         var resultado = data;
			 	         fecha = resultado.substring(0, 10);
                         status = resultado.substring(11, resultado.length);
                         $("#item_fecha").append(fecha);
                         $("#item_codigo").append(codigo2); 
                         $("#item_status").append(status);
						 $("#porta_estado").append('<img src="img/luz/'+status+'.png" alt="" />');
						 $('#loading2').hide();				  
						} else {  } 		
				});	
		$("#tabla_resul").show();
   	});*/

   	

/*	$("#ingreso").click(function(){
		$("#titulo").hide();
		EliminarTodo();
		$("#formulario").show();	
	    $("#buscar").hide();
	    $("#ingreso").hide();	
	});*/

	$("#btn_atras_genero").click(function(){
	    $("#mjs").hide();
		$("#btn_atras_genero").hide();
		EliminarTodo();
		$("#formulario").show();
	    //$("#titulo").show();
	    //$("#buscar").show();
	    //$("#ingreso").show();
	});

$("#form1").validate({

		rules: {

			comentario:{required: true,
				minlength: 10},
			/*cedula: {minlength: 10,
				maxlength: 10,
				number:true},
			nombre: {minlength: 3,
				number:false},
			telefono: {minlength: 6,
				maxlength: 9,
				number:true},
			domicilio: {minlength: 6},
			tipo:{required:true}*/
			email: {
				required:true,		
				email: true			
			}
				},
		messages: {
					comentario: {minlength: "Por farvor ingrese un comentario valido",
						required: "Por favor ingrese un comentario"},
					/*cedula: {minlength: "Ingrese un cedula con más números",
					    maxlength: "Ingrese un cedula con menos números",
						number: "Ingrese un cedula con solo numeros"},
					nombre: {minlength: "Ingrese un nombre con más caracteres.",
						number: "Ingrese un nombre sin números."},
					telefono: {number: "Ingrese un telefono con solo numeros",
						minlength: "Ingrese un telefono con más numeros",
						maxlength: "Ingrese un telefono con menos numeros"},					
					domicilio: {minlength: "Ingrese un domicilio valido"}*/
					email: {
						email: "Ingrese un email valido",
						minlength: "Ingrese un email valido"
					}
			 },	

		submitHandler: function() {

					$('#loading').show();

					$('#formulario').hide();

				    if($("#tipo_0").is(':checked')){ tipo_user="Cliente"; }
					if($("#tipo_1").is(':checked')){ tipo_user="Concesionario"; }
					if($("#tipo_2").is(':checked')){ tipo_user="Proveedor"; }
					if($("#tipo_3").is(':checked')){ tipo_user="Empleado"; }
					/*if($("#tipo_0").attr("checked") != "undefined" && $("#tipo_1").attr("checked") != "undefined" && $("#tipo_2").attr("checked") != "undefined" && $("#tipo_3").attr("checked") != "undefined" ){ tipo_user="vacio"; }*/

					

					/*if($('#cedula').val() == "undefined"){ ced_txt = "0"; }else{ ced_txt = $('#cedula').val();}								
					if($('#cedula').val() == ""){ ced_txt = "0"; }else{ ced_txt = $('#cedula').val();}
					if($('#nombre').val() == ""){ nom_txt ="vacio"; }else{ nom_txt = $('#nombre').val(); }
					if($('#telefono').val() == ""){ telf_txt = "0"; }else{ telf_txt = $('#telefono').val(); }
					if($('#email').val() == ""){ mail_txt = "vacio"; }else{ mail_txt = $('#email').val();}
					if($('#domicilio').val() == ""){ dir_txt = "vacio"; }else{ dir_txt = $('#domicilio').val(); }*/

					$.post('http://malldelsol.com.ec/wpcontent/themes/malldelsol/guardar.php',{ comentario:$('#comentario').val(), cedula:$('#cedula').val(), tipo:tipo_user, nombre:$('#nombre').val(),  telefono:$('#telefono').val(), email:$('#email').val(), direccion:$('#direccion').val()}, function(data){ 

				    if(data != "error") {			   
						$.post('http://malldelsol.com.ec/wpcontent/themes/malldelsol/mail2.php',{email:$('#email').val(), name:$('#nombre').val()}, function(data2){
					if(data2!="error"){
					    $('#loading').hide();$("#btn_atras_genero").show(); $('#mjs').show().append('<p style=" width:320px; font-family:Arial, Helvetica, sans-serif; font-size:12px; padding-top:20px; padding-bottom:20px; margin-left:auto; margin-right:auto; text-align:center; color:#b00b2b; padding-left:5px; padding-right:5px; background:#e1e3e3; border:1px solid #b00b2b;">Tu comentario fue enviado, gracias por ayudarnos a mejorar</p><br  />');
					}
					else{
					alert("error al enviar datos por mail");	
					}
																																																					 						});

						} else { 

						alert("error en formulario");

						} 

				

				});	

					

						}

					

		});

//function EliminarTodoBusqueda(){

//$('#tck_txt').val("");

//$("#item_fecha").empty();

//$("#item_codigo").empty();

//$("#item_status").empty();

//$("#porta_estado").empty();

						

//}

				

function EliminarTodo(){

	$('#comentario').val("");
	$('#cedula').val("");
	$("#tipo_0").val("unchecked");
	$("#tipo_1").val("unchecked");
	$("#tipo_2").val("unchecked");
	$("#tipo_3").val("unchecked");
	$('#nombre').val("");
	$('#telefono').val("") ;
	$('#email').val("");
	$('#direccion').val("");
	}			
});
