$(document).ready(function()
{	
			$("#envsolic").click(function(){
				var nm=$("#nm").val();
				var ed=$("#ed").val();
				var dom=$("#do").val();
				var tel=$("#te").val();
				var em=$("#em").val();
				var folio=$("#folio").val();
				var est=document.getElementById("es").value;
				var pues=document.getElementById("listavh").value;
				var hot=document.getElementById("listaHHV").value;
				var arch=$("#archivo").val();
				var expe=$("#ex").val();
				var com=$("#co").val();
				if(ed >=18)
				{$("#ed").css({"border":"2px","border-color":"#060","border-style":"solid"});
					}
				else{$("#ed").css({"border":"2px","border-color":"#F00","border-style":"solid"});
					document.getElementById("ed").value="";}			
				valida("nm");valida("do");valida("es");valida("ex");valida("pu");
				
				if(nm=="" || ed=="" || dom=="" || est=="" || pues=="" || expe=="" || ed<18)
				{
					alert("Algunos campos son necesarios");
				}
				else
				{
					$.ajax({
							type: "POST",
							url: 'control.php',
						data:"&opc=1&nm="+nm+"&ed="+ed+"&do="+dom+"&te="+tel+"&em="+em+"&es="+est+"&pu="+pues+"&curr="+arch+"&ex="+expe+"&co="+com+"&hotel="+hot+"&folio="+folio,
							success: function(datos){
							$("#frsolicitud").html(datos);
								   }
							});
				}
				
			});//termina enviar
	
		 $("#vstat").click(function(){
	   			var ht=document.getElementById("listah").value;	
							$.ajax({
							type: "POST",
							url: 'control.php',
							data:"&opc=6&hh="+ht,
							success: function(datos){
							$("#rstat").html(datos);
								   }
							});
			});
		
		$("#vedit").click(function(){
	   			var ht=document.getElementById("listah").value;
							$.ajax({
							type: "POST",
							url: 'control.php',
							data:"&opc=7&hh="+ht,
							success: function(datos){
							$("#opedith").html(datos);
								   }
							});
			});
	
	   $("#loading").ajaxStart(function(){
	   			$(this).show();
		});
	   
		$("#loading").ajaxStop(function(){
		   $(this).hide();
		});
		
		$(".hotelesD").ready(function(){
		   $.ajax({
			type: "POST",
			url: 'control.php',
			data:"&opc=21",
			success: function(datos){
				$(".hotelesD").html(datos); }
			});
		});
		
		
		
	$("#saveh").click(function(){ //GUARDA UN NUEVO HOTEL A LA LISTA
								
						var nm=$("#nmh").val();
						var dir=$("#dirh").val();
						var tel=$("#telh").val();
						var mail=$("#emh").val();
						
						if(valEmail(mail) && nm !="" && dir !="" && tel !="")
						{
							$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=2&nom="+nm+"&direc="+dir+"&tele="+tel+"&email="+mail,
								success: function(datos){
								$("#msg").fadeIn(500,function(){$("#msg").html(datos);});
									document.getElementById("nmh").value="";
									document.getElementById("dirh").value="";
									document.getElementById("telh").value="";
									document.getElementById("emh").value="";
									$("#msg").fadeOut(5000); }
								});
						}
						else
						{
							$("#msg").fadeIn(500);
							$("#msg").html("Verifique los campos");
							$("#msg").fadeOut(2500);
						}			  
				});
	
		$("#saveV").click(function(){ //GUARDA UNA VACANTE NUEVA A LA LISTA
								
						var nm=document.getElementById("nmv").value;
						if(nm !="")
						{
							$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=9&nom="+nm,
								success: function(datos){
								$("#msg").fadeIn(500,function(){$("#msg").html(datos);});
									document.getElementById("nmv").value="";
									$("#msg").fadeOut(5000); }
								});
						}
						else
						{
							$("#msg").fadeIn(500);
							$("#msg").html("Verifique los campos");
							$("#msg").fadeOut(2500);
						}
				});
		
		$("#actReq").click(function(){ //GUARDA UNA VACANTE NUEVA A LA LISTA
								
						var requis=$("#requiVac2").val();
						var hotel=document.getElementById("listahv").value;
						var vacante=document.getElementById("listavh").value;
						if(hotel !="" && vacante !="")
						{
							$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=20&vacante="+vacante+"&requisito="+requis,
								success: function(datos){
								$("#msg").fadeIn(500,function(){$("#msg").html(datos);});
									$("#reh").html("");
									$("#rev").html("");
									$("#reqq").html("");
									$("#msg").fadeOut(5000); }
								});
						}
						else
						{
							$("#msg").fadeIn(500);
							$("#msg").html("Verifique los campos");
							$("#msg").fadeOut(2500);
						}
				});
	
	$("#btedit").click(function(){
						var nnm=$("#nnmh").val();
						var ndir=$("#ndirh").val();
						var ntel=$("#ntelh").val();
						var nmail=$("#nemh").val();
						var iddh=$("#nh").val();
						var hh=document.getElementById("listah").value;						
						if(valEmail(nmail) && nnm !="" && ndir !="" && ntel !="")
						{
							if(iddh==hh)
							{
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=8&nom="+nnm+"&direc="+ndir+"&tele="+ntel+"&email="+nmail+"&id="+hh,
								success: function(datos){
								$("#msg").fadeIn(500,function(){$("#msg").html(datos);});
									$("#opedit").html("");
									$("#msg").fadeOut(5000);
									}
								});
							}
							else
							{
								$("#msg").fadeIn(500,function(){$("#msg").html("El nombre del hotel no coincide.");});
							}
						}
						else
						{
							$("#msg").fadeIn(500);
							$("#msg").html("Verifique los campos");
							$("#msg").fadeOut(2500);
						}			  
				});
	
		$("#bteditV").click(function(){
						var nnv=$("#nnmv").val();
						var iddv=$("#nv").val();
						var vv=document.getElementById("listaVV").value;						
						if(nnv !="" && vv !="")
						{
							if(iddv==vv)
							{
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=18&nom="+nnv+"&id="+vv,
								success: function(datos){
								$("#msg").fadeIn(500,function(){$("#msg").html(datos);});
									$("#listaV4").html("");
									$("#msg").fadeOut(5000);
									}
								});
							}
							else
							{
								$("#msg").fadeIn(500,function(){$("#msg").html("Las vacantes no coinciden.");});
								$("#listaV4").html("");
							}
						}
						else
						{
							$("#msg").fadeIn(500);
							$("#msg").html("Verifique los campos");
							$("#msg").fadeOut(2500);
							$("#listaV4").html("");
						}			  
				});
	
	
	$("#deleth").click(function()
	{
						var hotel=document.getElementById("listah").value;
					if(confirm("Confirme eliminar hotel de la lista"))
					{
						if(hotel !="")
						{$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=4&idh="+hotel,
								success: function(datos){
									$("#msg").fadeIn(500,function(){$("#msg").html(datos);});
									$("#msg").fadeOut(3000);
									}
																   
							   });
						}
						else
						{$("#msg").fadeIn(500,function(){$("#msg").html("Seleccione un hotel");});}
					}
					else
					{}
		});

 $("#btver").click(function()
	{
					var hotel=document.getElementById("listah").value;
					var vis=document.getElementById("verOc").value;
						if(hotel !="" && vis !="")
						{$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=5&idh="+hotel+"&vi="+vis,
								success: function(datos){
									$("#msg").fadeIn(500,function(){$("#msg").html(datos);});
									$("#msg").fadeOut(3000);
									
									}
																   
							   });
						}
						else
						{$("#msg").fadeIn(500,function(){$("#msg").html("No deje opciones en blanco");});}
		});


	$("#pagrega").click(function()
	{
		$("#elimina").hide("Fast");
		$("#ver").hide("Fast");
		$("#editar").hide("Fast");
		$("#agrega").show("Fast");
		
	});
	$("#pagregaV").click(function()
	{
		$("#eliminaV").hide("Fast");
		$("#verV").hide("Fast");
		$("#editarV").hide("Fast");
		$("#asignarV").hide("Fast");
		$("#agregaV").show("Fast");
		$("#asigVac").html("");
		$("#listaV").html("");
		$("#listaV4").html("");
		$("#listaVA").html("");
		$("#listaV2").html("");
		$("#listaV3").html("");
		
	});
	$("#pelimina").click(function()
	{
		$("#agrega").hide("Fast");
		$("#ver").hide("Fast");
		$("#editar").hide("Fast");
		$("#elimina").show("Fast");
		$("#lista3").html("");
		$("#lista2").html("");
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=3",
								success: function(datos){
								$("#lista").html(datos);
									$("#msg").fadeOut(3000); }
								});
		
	});
	$("#peliminaV").click(function()
	{
		$("#agregaV").hide("Fast");
		$("#verV").hide("Fast");
		$("#asignarV").hide("Fast");
		$("#editarV").hide("Fast");
		$("#eliminaV").show("Fast");
		$("#listaVA").html("");
		$("#asigVac").html("");
		$("#listaV2").html("");
		$("#listaV4").html("");
		$("#listaV3").html("");
							$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=10",
								success: function(datos){
								$("#listaV").html(datos);
									$("#msg").fadeOut(3000); }
								});
		
	});
	
	$("#pasignaV").click(function()
	{
		$("#agregaV").hide("Fast");
		$("#verV").hide("Fast");
		$("#editarV").hide("Fast");
		$("#asignarV").hide("Fast");
		$("#eliminaV").hide("Fast");
		$("#asignarV").show("Fast");
		$("#listaV").html("");
		$("#listaV4").html("");
		$("#listaV2").html("");
		$("#listaV3").html("");
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=10",
								success: function(datos){
								$("#asigVac").html(datos);
									$("#msg").fadeOut(3000); }
								});
		
							$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=3",
								success: function(datos){
								$("#listaVA").html(datos);
									}
								});
		
	});	
	
	$("#asignaV").click(function()// guarda la relacion de hoteles - vacantes. asignadas.
	{
		var hot=document.getElementById("listah").value;
		var vac=document.getElementById("listaVV").value;
		var visible=document.getElementById("statAsigna").value;
		var requisitos=document.getElementById("requiVac").value;	
		if(hot !="" && vac !="" && visible !="")
		{
				$.ajax({
				type: "POST",
				url: 'control.php',
				data:"&opc=11&hotel="+hot+"&vacante="+vac+"&visible="+visible+"&requi="+requisitos,
				success: function(datos){
				$("#msg").show("Fast");
				$("#msg").html(datos);
				$("#asigVac").html("");
				document.getElementById("requiVac").value="";	
				$("#msg").fadeOut(3000); 
					 }
				});
		}
		else
		 {
			 $("#msg").show("Fast");
				$("#msg").html("Hay campos vacios");
				$("#msg").fadeOut(3000); 
		 }
			

		
	});	
	
	
	$("#pver").click(function()
	{
		$("#agrega").hide("Fast");
		$("#elimina").hide("Fast");
		$("#editar").hide("Fast");
		$("#ver").show("Fast");
		$("#lista").html("");
		$("#lista3").html("");
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=3",
								success: function(datos){
								$("#lista2").html(datos);
									$("#msg").fadeOut(3000); }
								});
		
	});
	
	$("#pverV").click(function()// PENDIENTE PARA VER/OCULTAR VACANTES A HOTELES.
	{   $("#editarV").hide("Fast");
		$("#eliminaV").hide("Fast");
		$("#asignarV").hide("Fast");
		$("#agregaV").hide("Fast");
		$("#listaV").html("");
		$("#listaVA").html("");
		$("#listaV4").html("");
		$("#listaV3").html("");
		$("#asigVac").html("");
		$("#verV").show("Fast");
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=13&subopt=1",
								success: function(datos){
								$("#listaV2").html(datos);
									$("#msg").fadeOut(3000); }
								});
								
	});// PENDIENTE PARA VER/OCULTAR VACANTES A HOTELES.
	
	$("#pedita").click(function()
	{
		$("#agrega").hide("Fast");
		$("#ver").hide("Fast");
		$("#elimina").hide("Fast");
		$("#editar").show("Fast");
		$("#lista").html("");
		$("#lista2").html("");
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=3",
								success: function(datos){
								$("#lista3").html(datos);
									$("#msg").fadeOut(3000); }
								});
		
	});
	
	$("#peditaV").click(function()
	{
		$("#agregaV").hide("Fast");
		$("#verV").hide("Fast");
		$("#asignarV").hide("Fast");
		$("#eliminaV").hide("Fast");
		$("#listaV").html("");
		$("#listaVA").html("");
		$("#listaV2").html("");
		$("#asigVac").html("");
		$("#editarV").show("Fast");
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=10",
								success: function(datos){
								$("#listaV3").html(datos);
									$("#msg").fadeOut(3000); }
								});
								
								$.ajax({
								type: "POST",
								url: 'control.php',
								data:"&opc=13&subopt=2",
								success: function(datos){
								$("#reh").html(datos);
									$("#msg").fadeOut(3000); }
								});
		
	});
	$("#veditV").click(function()
	{
		var idvac=document.getElementById("listaVV").value;
		if(idvac !="")
		{	$.ajax({
			type: "POST",
			url: 'control.php',
			data:"&opc=17&idvac="+idvac,
			success: function(datos){
			$("#listaV4").html(datos);
			$("#msg").fadeOut(3000); }
			});
		}
		else
		{
			$("#msg").show("Fast");
				$("#msg").html("Seleccione una vacante");
				$("#msg").fadeOut(3000); 
				$("#listaV4").html("");
		}
		
	});
	
	$("#deletV").click(function()
	{
		var vac=document.getElementById("listaVV").value;
								
		if(confirm("Esta seguro que desea eliminar la vacante?"))
		{
			$.ajax({
			type: "POST",
			url: 'control.php',
			data:"&opc=12&vacante="+vac,
			success: function(datos){
			$("#msg").show("Fast");
			$("#msg").html(datos);
			$("#msg").fadeOut(3000); }
			});
		}
		else
		{
			$("#msg").show("Fast");
				$("#msg").html("Seleccione vacante");
				$("#msg").fadeOut(3000); 
		}
		
		
	});
	
	
	$("#editStatus").click(function()
	{
		var stat=document.getElementById("edstatusV").value;
		var asig=document.getElementById("listavh").value;
								
		if(stat !="" && asig !="")
		{
			$.ajax({
			type: "POST",
			url: 'control.php',
			data:"&opc=16&nstatus="+stat+"&idasign="+asig,
			success: function(datos){
			$("#msg").show("Fast");
			$("#msg").html(datos);
			$("#msg").fadeOut(3000);
				$("#hotVacante").html("");
				$("#vacStatus").html("");
			}
			});
		}
		else
		{
			$("#msg").show("Fast");
				$("#msg").html("Seleccione opcion para mostrar/ocultar");
				$("#msg").fadeOut(3000); 
						$("#hotVacante").html("");
						$("#vacStatus").html("");
		}
		
		
		
	});
	
	
	
	
	$("#vopH").click(function()
	{
		$(".opVacantes").slideUp("Fast");
		$(".opHoteles").slideDown("Fast");
		
	});
	
	$("#vopV").click(function()
	{
		$(".opHoteles").slideUp("Fast");
		$(".opVacantes").slideDown("Fast");
		
	});
//SUBIR CURRICULUM
	var button = $('#btupload'), interval;
	var nomb=$("#nm").val();
	new AjaxUpload('#btupload',{
									action: 'control.php',
									data: {
										opc:22,
										usuario: nomb 
										},
									onSubmit : function(file , ext )
											{
												if (! (ext && /^(doc|docx|pdf)$/.test(ext)))
												{
													// extensiones permitidas
													$('#loaded').html("Solo archivos de WORD o PDF");
													// cancela upload
													return false;
												} 
												else
												{
													button.text('Espere..');
													this.disable();
												}
											},
									onComplete: function(file, response)
									{
										if(response=="success")
										{
										// enable upload button			
										// Agrega archivo a la lista
										$('#loaded').html("Curriculum cargado");
										button.text('Listo');
										this.enable();
										document.getElementById("archivo").value=file;
										}
										else
										{
											$('#loaded').html(response);
											this.enable();
											return false;
										}
									}	
								});
//SUBIR EL CURRICULUM
});// termina document

function valida(id)
{	var c=$("#"+id+"").val();
	if(c=="")
	{
		$("#"+id+"").css({"border":"2px","border-color":"#F00","border-style":"solid"});
	}
	else
	{
		$("#"+id+"").css({"border":"2px","border-color":"#060","border-style":"solid"});
	}
}

function rellena()
{
	var hotel= document.getElementById("h").value;
	var index=document.getElementById("h").selectedIndex;
	if(index !=0 && index !="")
	{
		var ch=arrv("hot_"+index);
		var numh=ch.length;		
		document.getElementById("pu").length=numh;
		
		for(i=0;i<numh;i++){
		document.getElementById("pu").options[i].value=ch[i]
		document.getElementById("pu").options[i].text=ch[i]
		}			
	}
	else
	{
	document.getElementById("pu").length = 1
	document.getElementById("pu").options[0].value = "-"
	document.getElementById("pu").options[0].text = "-"
	}
}

function arrv(hh)
{
	switch(hh)
	{
		case 'hot_1':
			var hot_1=new Array("Cocinero","Cocinera-Huevera","Mesero (a)","Camarista")
			return hot_1;
		break;
		
		case 'hot_2':
			var hot_2=new Array("Bell Boys","Cubre turno-mesero","Cocinero")
			return hot_2;

		break;
		
		case 'hot_3':
			var hot_3=new Array("Ejecutivo de ventas","Camaristas","Mozos de areas publicas","Bell Boy","Auxiliar de lavanderia","Encargado de lavanderia","Supervisor(a) de piso","Operario de mantenimiento")
			return hot_3;
		break;
		
		case 'hot_4':
			var hot_4=new Array("Mesera","Steward","Mozo de limpieza","Camarista","Operador de cuartos","Auxiliar de almacen") 
			return hot_4;
		break;
		
		default: 
		break;
	}

}

function listavacantes(idhotel,subop)
{
	if(idhotel !="")		
	{	
		switch(subop)
		{	
			case 1:		
						$.ajax({
						type: "POST",
						url: 'control.php',
						data:"&opc=14&hotel="+idhotel+"&subopt=1",
						success: function(datos){	
							$("#hotVacante").html(datos);
							}
						});
			break;
			case 2:		
						$.ajax({
						type: "POST",
						url: 'control.php',
						data:"&opc=14&hotel="+idhotel+"&subopt=2",
						success: function(datos){	
							$("#rev").html(datos);
							}
						});
			break;
			case 3:		
						$.ajax({
						type: "POST",
						url: 'control.php',
						data:"&opc=14&hotel="+idhotel,
						success: function(datos){	
							$(".pu").html(datos);
							}
						});
			break;
			
			default: alert("Error del sistema");
			break;
		}
	}
	else
	{
				$("#hotVacante").html("");
				$("#vacStatus").html("");
		$("#msg").show("Fast");
			$("#msg").html("Seleccione un hotel");
			$("#msg").fadeOut(3000);
	}

}

function listaVstatus(idvacante,subop2)
{
	if(idvacante !="")		
	{	
		switch(subop2)
		{	
			case 1:
					$.ajax({
					type: "POST",
					url: 'control.php',
					data:"&opc=15&vacante="+idvacante,
					success: function(datos){	
						$("#vacStatus").html(datos);
						}
					});
			break;
			case 2:
	
					$.ajax({
					type: "POST",
					url: 'control.php',
					data:"&opc=19&vacante="+idvacante,
					success: function(datos){	
						$("#reqq").html(datos);
						}
					});
			break;
			
			default: alert ("Error 2 del sistema");
			break;
		}
	}
	else
	{
		$("#msg").show("Fast");
			$("#msg").html("Seleccione una vacante");
			$("#msg").fadeOut(3000);
				$("#vacStatus").html("");
	}

}

function valEmail(valor){
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}
function salirS()
{
	$.ajax({
	type: "POST",
	url: 'control.php',
	data:"&opc=32",
	success: function(datos){	
			document.location="index.html";
	 }
	});
}
