//*****************************************************************************************************************	
function cerrar_ventana() { 
		window.close();
   }
//*****************************************************************************************************************
function validar_email(){
	with(document.frm_recuperar_clave)
	{
		if(txt_email.value == ""){
			alert('¡Ingrese su Email'); txt_email.focus(); txt_email.style.background="#92ADDA"; return; }
		else 
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt_email.value))
			{} 
			else 
			{	alert ('La dirección de email es incorrecta.');	txt_email.focus(); txt_email.style.background="#92ADDA"; return;
			}
		} 
				btn_recuperar_clave.disabled = true;		
				action="olvido_email_verificar.php";
				submit();
   }
}
//*****************************************************************************************************************
function popup_clave() { 
	window.open('Acceso/olvido_clave.php','','width=600,height=260,scrollbars=no,resizable=no,status=yes,menubar=no,location=no');
   }
  
//*****************************************************************************************************************
function validar_email_compra(codigo){
	with(document.frm_recuperar_clave)
	{
		if(txt_email.value == ""){
			alert('¡Ingrese su Email'); txt_email.focus(); txt_email.style.background="#92ADDA"; return; }
		else 
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt_email.value))
			{} 
			else 
			{	alert ('La dirección de email es incorrecta.');	txt_email.focus(); txt_email.style.background="#92ADDA"; return;
			}
		} 
				btn_recuperar_clave.disabled = true;		
				action='olvidocc_email_verificar.php?cod='+codigo;
				submit();
   }
}

//*****************************************************************************************************************
function calc() { 
vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms[0].submit();
}
//*****************************************************************************************************************
function UpdateQty(item)
			{
				itemId = item.name;
				newQty = item.options[item.selectedIndex].text;
				
				document.location.href = 'cesta.php?action=update_item&id='+itemId+'&qty='+newQty;
			}
//*****************************************************************************************************************
//*****************************************************************************************************************
//*****************************************************************************************************************
function nuevo_index(){
	with(document.frmClientes)
	{
				action="Ventas/alta_nuevo_cliente.php";
				submit();
	}
}
/* --------------------------------------------------------------------------------------------------------------*/
function valida_clientes_index(){
	with(document.frmClientes)
	{
				if(txt_usuario.value == ""){ // Falta Nombre
					alert('¡Ingrese Nombre de Usuario'); txt_usuario.focus(); 		return ; }
					
				if(txt_clave.value == ""){ // Falta Nombre
					alert('¡Ingrese Clave del Usuario'); txt_clave.focus();			return; }

				action="Acceso/segur_autentificar.php";
				submit();
		   }
		   
}
//*****************************************************************************************************************
//*****************************************************************************************************************
//*****************************************************************************************************************
function nuevo_ventas(){
	with(document.frmClientes)
	{
				action="alta_nuevo_cliente.php";
				submit();
	}
}
/* --------------------------------------------------------------------------------------------------------------*/
function valida_clientes_ventas(){
	with(document.frmClientes)
	{
				if(txt_usuario.value == ""){ // Falta Nombre
					alert('¡Ingrese Nombre de Usuario'); txt_usuario.focus(); 		return ; }
					
				if(txt_clave.value == ""){ // Falta Nombre
					alert('¡Ingrese Clave del Usuario'); txt_clave.focus();			return; }
					
				// Desabilito el boton de envio para evitar reenvios
				btn_ingresar.disabled = true;		
				action="../Acceso/segur_autentificar.php";
				submit();
		   }
		   
}
//*****************************************************************************************************************
//*****************************************************************************************************************
//*****************************************************************************************************************
function nuevo_acceso(){
	with(document.frmClientes)
	{
				action="../Ventas/alta_nuevo_cliente.php";
				submit();
	}
}
/* --------------------------------------------------------------------------------------------------------------*/
function valida_clientes_acceso(){
	with(document.frmClientes)
	{
				if(txt_usuario.value == ""){ // Falta Nombre
					alert('¡Ingrese Nombre de Usuario'); txt_usuario.focus(); 		return ; }
					
				if(txt_clave.value == ""){ // Falta Nombre
					alert('¡Ingrese Clave del Usuario'); txt_clave.focus();			return; }
					
				// Desabilito el boton de envio para evitar reenvios
				btn_ingresar.disabled = true;		
				action="segur_autentificar.php";
				submit();
		   }
		   
}
//*****************************************************************************************************************
//*****************************************************************************************************************
//*****************************************************************************************************************
function nuevo_informacion(){
	with(document.frmClientes)
	{
				action="../Ventas/alta_nuevo_cliente.php";
				submit();
	}
}
/* --------------------------------------------------------------------------------------------------------------*/
function valida_clientes_informacion(){
	with(document.frmClientes)
	{
				if(txt_usuario.value == ""){ // Falta Nombre
					alert('¡Ingrese Nombre de Usuario'); txt_usuario.focus(); 		return ; }
					
				if(txt_clave.value == ""){ // Falta Nombre
					alert('¡Ingrese Clave del Usuario'); txt_clave.focus();			return; }
					
				// Desabilito el boton de envio para evitar reenvios
				btn_ingresar.disabled = true;		
				action="../Acceso/segur_autentificar.php";
				submit();
		   }
		   
}
//*****************************************************************************************************************
//*****************************************************************************************************************
//*****************************************************************************************************************
//*********************************************************************************************************************
function Validar_Numeros() 
{
	var key=window.event.keyCode;//codigo de tecla. 
	if (key < 48 || key > 57)
	{//si no es numero 
	alert('Solo se Admiten Números'); 
	window.event.keyCode=0;//anula la entrada 	
	}
}
//***********************************************************************************************************************
function valida_informacion()
{	var mensaje = "";
	with(document.frmInformacion)
	{
		//************NOMBRE***********************************************************	
		if(txt_nomb.value == "")
		{	mensaje = '¡Por Favor ingrese su Nombre!\n';
			txt_nomb.focus();
		}
		//************APELLIDO***********************************************************	
		if(txt_apel.value == "")
		{	mensaje+= '\n¡Por Favor ingrese su Apellido!\n';
			txt_apel.focus();
		}
		//************EMAIL***********************************************************	
		if(txt_email.value == "")
		{	mensaje += '\n¡Escriba su Dirección de Correo Electrónico!\n';
			txt_email.focus(); 
		}
		else 
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt_email.value))
			{} 
			else 
			{	mensaje +="\nLa dirección de email es incorrecta.\n";
				txt_email.focus();
			}
		} 
		//************TELEFONO***********************************************************
		if(txt_tele.value == "")
		{ 	mensaje +='\n¡Ingrese un Teléfono de Referencia!\n';
		 	txt_tele.focus();
		}
		
		if (mensaje=="") 
		{		btnOk.disabled = true;
				action="enviar_correo.php";
				submit();
		}
		else 
		{ alert(mensaje);return false;}
	}
}
//***********************************************************************************************************************
function valida_autentificacion(){
	with(document.frmAutentificar){
		if(txt_usuario.value == ""){ // Falta Nombre
			alert('¡Ingrese Nombre de Usuario'); txt_usuario.focus(); return; }
			
		if(txt_clave.value == ""){ // Falta Nombre
			alert('¡Ingrese Clave del Usuario'); txt_clave.focus(); return; }
			
		// Desabilito el boton de envio para evitar reenvios
		btnOk1.disabled = true;
		action="segur_autentificar.php";
		submit();
	}
}

//***********************************************************************************************************************
var valor; 
function valida_autentificacion_cliente(){
	with(document.frmAutentificar){
		if(txt_razon.value == ""){ 
			alert('¡Ingrese su Nombre o Razón Social');  txt_razon.focus(); txt_razon.style.background="#92ADDA"; return; }
			
		if(txt_cifnif.value == ""){ 
			alert('¡Ingrese su NIF/CIF '); txt_cifnif.focus(); txt_cifnif.style.background="#92ADDA"; return; }

		if(txt_contacto.value == ""){ 
			alert('¡Ingrese datos de la persona de contacto ');  txt_contacto.focus(); txt_contacto.style.background="#92ADDA"; return; }

		if(txt_dire.value == ""){ 
			alert('¡Ingrese su Direccion '); txt_dire.focus(); txt_dire.style.background="#92ADDA"; return; }						

		if(txt_pobla1.value == ""){ 
			alert('¡Ingrese su Población '); txt_pobla1.focus(); txt_pobla1.style.background="#92ADDA"; return; }
			
		if(txt_provi1.value == ""){
			alert('¡Ingrese su Provincia '); txt_provi1.focus(); txt_provi1.style.background="#92ADDA"; return; }

		if(txt_codipostal1.value == ""){
			alert('¡Ingrese su Código Postal'); txt_codipostal1.focus(); txt_codipostal1.style.background="#92ADDA"; return; }
		else 
		{
		  if (txt_codipostal1.value.length <5 )
			{alert('¡Recuerde el Código Postal deber ser de 5 caracteres. Gracias '); txt_codipostal1.focus(); txt_codipostal1.style.background="#92ADDA"; return; }
		}

		if (!/^(ad[0-9]{3}|[0-9]{5})$/i.test(document.getElementById('txt_codipostal1').value))
			{
				alert('El código postal que ha ingresado no está permitido!'); txt_codipostal1.focus(); txt_codipostal1.style.background="#92ADDA"; return; 
			}
		

		if(txt_email.value == ""){
			alert('¡Ingrese su Email'); txt_email.focus(); txt_email.style.background="#92ADDA"; return; }
		else 
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt_email.value))
			{} 
			else 
			{	alert ('La dirección de email es incorrecta.');	txt_email.focus(); txt_email.style.background="#92ADDA"; return;
			}
		} 


		if(txt_fono1.value == "" ){
			alert('¡Ingrese su Teléfono '); txt_fono1.focus(); txt_fono1.style.background="#92ADDA"; return; }
		else 
		{
		  if (txt_fono1.value.length <9 )
			{alert('¡Recuerde el Teléfono consta de 9 números. Gracias '); txt_fono1.focus(); txt_fono1.style.background="#92ADDA"; return; }
		}

		if(txt_usuario.value == ""){ 
			alert('¡Ingrese su Nombre de Usuario '); txt_usuario.focus(); txt_usuario.style.background="#92ADDA"; return; }						

		if(txt_clave.value == ""){ 
			alert('¡Ingrese su Clave '); txt_clave.focus(); txt_clave.style.background="#92ADDA"; return; }

		if(txt_clave.value.length < 6){ 
		alert("Escriba por lo menos 6 caracteres en el campo CLAVE"); txt_clave.focus(); txt_clave.style.background="#92ADDA"; return; }

						
		if(txt_clave_rep.value == ""){
			alert('¡Ingrese Nuevamente su Clave'); txt_clave_rep.focus(); txt_clave_rep.style.background="#92ADDA"; return; }
			
		if(txt_clave_rep.value.length < 6){ 
		alert("Escriba por lo menos 6 caracteres en el campo REESCRIBIR CLAVE"); txt_clave_rep.focus(); txt_clave_rep.style.background="#92ADDA"; return; }
			
		
		if(txt_clave.value != txt_clave_rep.value){ 
			alert('¡Las Claves NO son iguales'); txt_clave.focus(); return; }			
			

		if(txt_domi_entrega.value == ""){
			alert('¡Ingrese su Domicilio de Entrega'); txt_domi_entrega.focus(); txt_domi_entrega.style.background="#92ADDA"; return; }


		if(txt_pobla2.value == ""){ 
			alert('¡Ingrese su Población de Entrega'); txt_pobla2.focus(); txt_pobla2.style.background="#92ADDA"; return; }
			
		if(txt_provi2.value == ""){
			alert('¡Ingrese su Provincia de Entrega'); txt_provi2.focus(); txt_provi2.style.background="#92ADDA"; return; }

		if(txt_codipostal2.value == ""){
			alert('¡Ingrese su Código Postal de Entrega'); txt_codipostal2.focus(); txt_codipostal2.style.background="#92ADDA"; return; }
		else 
		{
		  if (txt_codipostal2.value.length <5 )
			{alert('¡Recuerde el Código Postal del Entrega deber ser de 5 caracteres. Gracias '); txt_codipostal2.focus(); txt_codipostal2.style.background="#92ADDA"; return; }
		}
		
		if (!/^(ad[0-9]{3}|[0-9]{5})$/i.test(document.getElementById('txt_codipostal2').value))
		{
			alert('El código postal de entrega que ha ingresado no está permitido!'); txt_codipostal2.focus(); txt_codipostal2.style.background="#92ADDA"; return; 
		}
	

		if(txt_fono2.value == ""){
			alert('¡Ingrese su Teléfono de Entrega '); txt_fono2.focus();  txt_fono2.style.background="#92ADDA"; return; }						
		else 
		{
		  if (txt_fono2.value.length <9 )
			{alert('¡Recuerde el Teléfono consta de 9 números. Gracias '); txt_fono2.focus(); txt_fono2.style.background="#92ADDA"; return; }
		}
	
/*		for(a=0;a<btn_pago.length;a++)
		{ 
			if(btn_pago[a].checked)
				{ valor = btn_pago[a].value; } 
	    }
		if (!valor){ 
			alert("¡Seleccione el TIPO DE FORMA DE PAGO"); 
			return; 
			}
*/

/*		if(btn_pago.checked)
				{ valor = btn_pago.value; } 
		else
		{	alert("¡Seleccione el TIPO DE FORMA DE PAGO"); 
			return; 
		}
*/		
		if(!chk_acepto.checked){
						chk_acepto.focus();
						alert("Para darse de alta como usuario registrado debe marcar la casilla aceptando las Condiciones de uso.");	   
						return;
		}

		btnOk1.disabled = true;
		action="alta_nuevo_cliente_enviar.php";
		submit();
	}	
}
//*****************************************************************************************************************
function seleccionar_empresa()
{
if (document.frmAutentificar.slt_empresa.value==1)  	
	{
		 document.frmAutentificar.txt_domi_entrega.value="";
		 document.frmAutentificar.txt_pobla2.value="";
		 document.frmAutentificar.txt_provi2.value="";
		 document.frmAutentificar.txt_codipostal2.value="";
		 document.frmAutentificar.txt_fono2.value="";
 	 	 document.frmAutentificar.txt_domi_entrega.focus();
	}
	
if (document.frmAutentificar.slt_empresa.value==2)  
   { 
     document.frmAutentificar.txt_domi_entrega.value= document.frmAutentificar.txt_dire.value ;
     document.frmAutentificar.txt_pobla2.value= document.frmAutentificar.txt_pobla1.value ;	 
     document.frmAutentificar.txt_provi2.value= document.frmAutentificar.txt_provi1.value ;
     document.frmAutentificar.txt_codipostal2.value= document.frmAutentificar.txt_codipostal1.value ;
     document.frmAutentificar.txt_fono2.value= document.frmAutentificar.txt_fono1.value ;	 
   }
}
//*****************************************************************************************************************
function hora_castellano()
{
meses = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Setiembre","Octubre","Noviembre","Diciembre");
dias = new Array ("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
data = new Date();
index = data.getMonth();
dia = data.getDay();
	var an=data.getYear();
	if (an<1000)
	{
		an = 1900+an;
	}
    document.write( dias[dia] + ", " + data.getDate()+ " de " + meses[index] +" del " + an );
}

//*****************************************************************************************************************
function valida_contactenos(){
	with(document.frm_contactenos)
	{
		if((txt_empresa.value == "")  && (txt_contacto.value == "")){
			alert('¡Ingrese Nombre de Empresa o Persona de Contacto.'); txt_contacto.focus(); txt_contacto.style.background="#92ADDA"; return; }

		if(txt_email.value == ""){
			alert('¡Ingrese su Email'); txt_email.focus(); txt_email.style.background="#92ADDA"; return; }
		else 
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt_email.value))
			{} 
			else 
			{	alert ('La dirección de email es incorrecta.');	txt_email.focus(); txt_email.style.background="#92ADDA"; return;
			}
		} 
		if(txt_telefono.value == ""){
			alert('¡Ingrese Teléfono de Empresa o Contacto.'); txt_telefono.focus(); txt_telefono.style.background="#92ADDA"; return; }

		if(txt_mensaje.value == ""){
			alert('¡Ingrese el mensaje o texto de consulta y/o sugerencias.'); txt_mensaje.focus(); txt_mensaje.style.background="#92ADDA"; return; }
			
				btn_enviar.disabled = true;		
				action="enviar_email_contactenos.php";
				submit();
		   }
}
//***********************************************************************************************************************
function valida_cambiar_datos(){
	with(document.frm_cambiar)
	{
		if(txt_usuario.value == ""){ 
			alert('¡Ingrese su Nombre de Usuario '); txt_usuario.focus(); txt_usuario.style.background="#92ADDA"; return; }						

		if(txt_clave1.value == ""){ 
			alert('¡Ingrese su Clave '); txt_clave1.focus(); txt_clave1.style.background="#92ADDA"; return; }

		if(txt_clave1.value.length < 6){ 
		alert("Escriba por lo menos 6 caracteres en el campo CLAVE"); txt_clave1.focus(); txt_clave1.style.background="#92ADDA"; return; }
						
		if(txt_clave2.value == ""){
			alert('¡Ingrese Nuevamente su Clave'); txt_clave2.focus(); txt_clave2.style.background="#92ADDA"; return; }
			
		if(txt_clave2.value.length < 6){ 
		alert("Escriba por lo menos 6 caracteres en el campo REESCRIBIR CLAVE"); txt_clave2.focus(); txt_clave2.style.background="#92ADDA"; return; }
		
		if(txt_clave1.value != txt_clave2.value){ 
			alert('¡Las Claves NO son iguales'); txt_clave1.focus(); return; }			

		if(txt_email.value == ""){
			alert('¡Ingrese su Email'); txt_email.focus(); txt_email.style.background="#92ADDA"; return; }
		else 
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt_email.value))
			{} 
			else 
			{	alert ('La dirección de email es incorrecta.');	txt_email.focus(); txt_email.style.background="#92ADDA"; return;
			}
		} 

		btn_enviar.disabled = true;
		action="air_cambiar_usuario_clave_actualizar.php";
		submit();
	}	
}
//*******************************************************************************************************************************
