// JavaScript Document

function LoginCliente(hash){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=login";
	datos+="&hash="+hash;
	datos+="&"+$('#frmLoginCliente').serialize();
	
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			if(html!=""){
				MostrarAviso(html, "Acceder Usuario");	
			}else{
				AreaCliente(hash);	
			}
		}
	});	
}

function CerrarSesion(hash){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=cerrarsesion";
	datos+="&hash="+hash;
	
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			if(html!=""){
				MostrarAviso(html, "Cerrar Sesi&oacute;n");	
			}else{
				AreaCliente(hash);	
			}
		}
	});	
}

function AreaCliente(hash){
	$('#form').toggleClass('oculto');
	$('#enviando').toggleClass('oculto');
		
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=area2";
	datos+="&hash="+hash;
	
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			$('#areacliente').html(html);
		}
	});	
}

function MostrarRecordarPass(){
	MostrarDialogo('recordar', 'Recordar Contrase\xF1a', 320, 250);
}; 
function RecordarPassCliente(){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=recordar";
	datos+="&"+$('#frmRecordarPass').serialize();
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			MostrarAviso("<p align=\"center\">"+html+"</p>", "Recordar Contrase&ntilde;a");
			CerrarDialogoWeb('recordar');
		}
	});	
}

function CuentaCliente(hash){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=cuenta";
	datos+="&hash="+hash;
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			MostrarDialogoWeb('divcuenta', 'Cuenta de Usuario', 900, 470);
			$('#divcuenta').html(html);
		}
	});	
}

function AlmacenarCuentaCliente(hash){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=almacenarcuenta";
	datos+="&hash="+hash;
	datos+="&"+$('#frmCuenta').serialize();
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			if(html!=""){
				MostrarAvisoWeb(html, "Almacenar Datos");
			}else{
			 	CerrarDialogoWeb('divcuenta');	
			}
		}
	});	
}

function TramitarBajaCuenta(hash){
	if(confirm("Se dispone a dar de Baja su cuenta de Usuario.\n\xBFEsta completamente seguro?")){
		var datos="pagajax=paginas/estructura/ajax_clientes.php";
		datos+="&accion=bajacuenta";
		datos+="&hash="+hash;
		$.ajax({
			url: "paginas/ajax.php",
			data: datos,      
			global: false,
			type: "POST",
			async: false,
			success: function(html){
				if(html!=""){
					MostrarAvisoWeb(html, "Baja de Cuenta");
				}else{
					MostrarAvisoWeb('<h5 style="text-align:center;">Su cuenta ha sido desactivada.<br/>Gracias</h5>','Cuenta desactivada');
					CerrarDialogoWeb('divcuenta');
					$('#divaviso').dialog({beforeClose:function(event,ui){window.location='index.php';}});
				}
			}
		});
	}
}

function InscribirContacto(){
	MostrarDialogoWeb('inscripcioncontacto','Inscripci&oacute;n a Boletines', 450, 300);
}

function AlmacenarContactoWeb(){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=altacontacto";
	datos+="&hash=";
	datos+="&"+$('#frmContacto').serialize();
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
		type: "POST",
		async: false,
		success: function(html){
			if(html!=""){
				MostrarAvisoWeb(html, 'Error Alta Boletines');	
			}else{
				MostrarAvisoWeb('<h5 style="text-align:center;">Se ha suscrito correctamente al Sistema de Boletines.<br/>Muchas Gracias</h5>','Alta Sistema Boletines');
				CerrarDialogoWeb('inscripcioncontacto');				
			}
		}
	});	
}


function BajaContacto(cadena){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=bajacontacto";
	datos+="&hash=";
	datos+="&cadena="+cadena;
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
		type: "POST",
		async: false,
		success: function(html){
			if(html!=""){
				MostrarAvisoWeb(html,'Baja Sistema Boletines');
			}
		}
	});	
}

function SelectSectoresWeb(id, sector){
	var datos="pagajax=paginas/clientes/ajax_sectores.php";
	datos+="&accion=selectsectores"+"&idsec="+sector+"&gestor=1";
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
		type: "POST",
		async: false,
		success: function(html){
			$('#'+id).html(html);
		}
	});	
}

function SelectActividadWeb(id, sector, actividad){
	if(actividad==null) actividad="";
	var datos="pagajax=paginas/clientes/ajax_sectores.php";
	datos+="&accion=selectactividades"+"&idsec="+sector+"&idact="+actividad+"&gestor=1";
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
		type: "POST",
		async: false,
		success: function(html){
			$('#'+id).html(html);
			if(sector!="" && sector!="NULL"){
				$("#"+id).attr('disabled','');
			}else{
				$("#"+id).attr('disabled','disabled');
			}
		}
	});	
}

function RegistroCliente(hash){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=inscribir";
	datos+="&hash="+hash;
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			MostrarDialogoWeb('divcuenta', 'Formulario de Inscripci&oacute;n', 550, 470);
			$('#divcuenta').html(html);
		}
	});	
}

function AlmacenarInscripcion(hash){
	var txt="";
	var ok=true;
	
	if(validarEmail('email_registro')!=""){
		txt+=validarEmail('email')+"<br/>";
		ok=false;	
	}	
	if($('#cliente').val()==""){
		txt+="No ha indicado su nombre<br/>";
		ok=false;	
	}	
	if($('#nif').val()=="" || ($('#nif').val()).length<9){
		txt+="No ha indicado su DNI / NIF o est&aacute; incompleto<br/>";
		ok=false;	
	}		
	if($('#provincia').val()==""){
		txt+="Debe indicar una Provincia<br/>";
		ok=false;	
	}		
	if($('#poblacion').val()==""){
		txt+="Debe indicar su Poblaci&oacute;n<br/>";
		ok=false;	
	}			
	if($('#tipocontacto').val()==""){
		txt+="Debe indicar un Sector<br/>";
		ok=false;	
	}		
	if($('#actividades').val()==""){
		txt+="Debe indicar una Actividad<br/>";
		ok=false;	
	}
	if(ok){
		var datos="pagajax=paginas/estructura/ajax_clientes.php";
		datos+="&accion=almacenarinscripcion";
		datos+="&hash="+hash;
		datos+="&"+$('#frmInscribir').serialize();
		$.ajax({
			url: "paginas/ajax.php",
			data: datos,      
			global: false,
			type: "POST",
			async: false,
			success: function(html){
				MostrarAvisoWeb(html, "Registro de Usuario");
				CerrarDialogoWeb('divcuenta');
			}
		});	
	}else{
		MostrarAvisoWeb(txt, "Complete la siguiente Informaci&oacute;n");	
	}
}

function ValidarRegistro(cadena){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=validarinscripcion";
	datos+="&hash="+cadena
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			MostrarAvisoWeb(html, "Validar Registro de Usuario");
			$('#divaviso').dialog({beforeClose:function(event,ui){window.location='index.php';}});
		}
	});	
}

function MostrarPedidos(hash){
	var datos="pagajax=paginas/estructura/ajax_clientes.php";
	datos+="&accion=mostrarpedidos";
	datos+="&hash="+hash;
	$.ajax({
		url: "paginas/ajax.php",
		data: datos,      
		global: false,
      	type: "POST",
		async: false,
		success: function(html){
			MostrarDialogoWeb('divcuenta', 'Sus Pedidos', 600, 450);
			$('#divcuenta').html(html);
		}
	});
}
