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 validar_usuario_clave()
{	
      if(document.getElementById("param1").value == 1)
        {
          
            if(document.getElementById("txt_usuario").value == "") // Falta Nombre
            { 
			    alert('¡Ingrese Nombre de Usuario');
                document.getElementById("txt_usuario").focus();
                document.getElementById("txt_usuario").style.background="#FFF0F0";
                return false;
            }
		    if(document.getElementById("txt_clave").value == "")// Falta Clave
            { 
			    alert('¡Ingrese Clave del Usuario');
                document.getElementById("txt_clave").focus();
                document.getElementById("txt_clave").style.background="#FFF0F0";
                return false;
            }
            //Si los datos son correctos nos vamos al panel de control
            if (document.getElementById("txt_usuario").value!='' && document.getElementById("txt_clave").value!='' )
            {
                document.getElementById("frm_usuario_clave").action = "Panel_control/validaciones.php";
                document.getElementById("frm_usuario_clave").submit();
            }
        }
}
/*********************************************************************************************************************************
*
**********************************************************************************************************************************/
function cliente_recordar_clave()
{ 
    if(document.getElementById("param2").value == 2)
    {
        //action="index.php?mod=clientes&accion=recordar_clave";
        document.getElementById("frm_recuperar_datos").action = "clientes/recordar_clave.html";
        document.getElementById("frm_recuperar_datos").submit();
    }    
}
/*********************************************************************************************************************************
*
**********************************************************************************************************************************/
function cliente_registro()
{
    if(document.getElementById("param3").value == 3)
    {
		//action="index.php?mod=clientes&accion=alta_cliente";
        document.getElementById("frm_nuevo_cliente").action = "clientes/alta_cliente.html";
        document.getElementById("frm_nuevo_cliente").submit();
	}
}
/*********************************************************************************************************************************
*
**********************************************************************************************************************************/
function validar_email()
{
	with(document.frm_recuperar_clave)
	{
		if(txt_email.value == ""){
			alert('¡Ingrese su Email'); txt_email.focus(); txt_email.style.background="#FFF0F0"; 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="#FFF0F0"; return;
			}
		} 
				btn_recuperar_clave.disabled = true;		
				//action="olvido_clave.php?mod=verificar_correo";
                action="clientes/verificar_email.html";
				submit();
   }
}
/*********************************************************************************************************************************
*
**********************************************************************************************************************************/
function enviar_cantidad()
{
    with(document.frm_cesta)
	{
		if(txt_cantidad.value<=0)
		{ 
			alert('¡Ingrese una cantidad correcta');
			txt_cantidad.focus();
			return; 
		}
  
        if(tmptxt.value == '')
        { 
            alert('¡Ingrese la clave de seguridad ');
            tmptxt.focus();
            return; 
        }
        submit();        
			
//		Submit.disabled = true;				
//		action="index.php?mod=cesta&accion=agregar&id_arti="+var_id_arti+"&cantidad="+txt_cantidad.value;
//        action="cesta/agregar/"+var_id_arti+".html";
//        submit();
	}
}
/*********************************************************************************************************************************
*
**********************************************************************************************************************************/
function enviar_cantidad_tallas()
{
    with(document.frm_cesta)
    {
        if(tmptxt.value == '')
        { 
            alert('¡Ingrese la clave de seguridad ');
            tmptxt.focus();
            return; 
        }
        submit();        
            
//        Submit.disabled = true;                
//        action="index.php?mod=cesta&accion=agregar&id_arti="+var_id_arti+"&cantidad="+txt_cantidad.value;
//        action="cesta/agregar/"+var_id_arti+".html";
//        submit();
    }
}   
/*********************************************************************************************************************************
*
**********************************************************************************************************************************/
function popup_cofidis(pagina)
{
	window.open(pagina,"Fisioterapia","width=368, height=550, scrollbars=no, menubar=no, location=no, resizable=no, left=300, top=120");
}
/*********************************************************************************************************************************
*
**********************************************************************************************************************************/
function popup_cofidis_informacion(pagina)
{
	window.open(pagina,"Fisioterapia","width=620, height=550, scrollbars=yes, location=no, resizable=no, left=100, top=120");
}
/*********************************************************************************************************************************
* Funcion para revisar los datos de envio antes de realizar una actualizacion dentro del PANEL DE CONTROL DEL USUARIO
**********************************************************************************************************************************/
function validar_modificacion_cliente(par) //se puede mandar como parametro el modulo
{	
	with(document.frm_informacion)
	{
		if(txt_nombre.value == ""){ 
			alert('¡Ingrese su Razón Social');  txt_nombre.focus(); txt_nombre.style.background="#FFF0F0"; return; }
		if(txt_nif.value == ""){ 
			alert('¡Ingrese su NIF');  txt_nif.focus(); txt_nif.style.background="#FFF0F0"; return; }
		if(txt_direccion.value == ""){ 
			alert('¡Ingrese su Dirección');  txt_direccion.focus(); txt_direccion.style.background="#FFF0F0"; return; }
		if(txt_codigo_postal.value == ""){ 
			alert('¡Ingrese su Código Postal');  txt_codigo_postal.focus(); txt_codigo_postal.style.background="#FFF0F0"; return; }
		if(txt_poblacion.value == ""){ 
			alert('¡Ingrese su Población');  txt_poblacion.focus(); txt_poblacion.style.background="#FFF0F0"; return; }
		if(txt_provincia.value == ""){ 
			alert('¡Ingrese su provincia');  txt_provincia.focus(); txt_provincia.style.background="#FFF0F0"; return; }
		if(txt_telefono.value == ""){ 
			alert('¡Ingrese su teléfono');  txt_telefono.focus(); txt_telefono.style.background="#FFF0F0"; return; }
		btn_enviar.disabled = true;
		action="index.php?mod=modificacion&tipo=actualizacion";
		submit();
	}	
}
/*********************************************************************************************************************************
* Funcion para pasar los datos que estan el los textbox a la dirección de envio del cliente en el PANEL DE CONTROL DEL USUARIO
**********************************************************************************************************************************/
function seleccionar_empresa()
{
if (document.frm_informacion.slt_empresa.value==1)  	
	{
		 document.frm_informacion.txt_direccion_entrega.value="";
		 document.frm_informacion.txt_poblacion_entrega.value="";
		 document.frm_informacion.txt_provincia_entrega.value="";
		 document.frm_informacion.txt_codigo_postal_entrega.value="";
		 document.frm_informacion.txt_telefono_entrega.value="";
 	 	 document.frm_informacion.txt_direccion_entrega.focus();
	}
if (document.frm_informacion.slt_empresa.value==2)  
   { 
     document.frm_informacion.txt_direccion_entrega.value= document.frm_informacion.txt_direccion.value;
     document.frm_informacion.txt_poblacion_entrega.value= document.frm_informacion.txt_poblacion.value;
     document.frm_informacion.txt_provincia_entrega.value= document.frm_informacion.txt_provincia.value;
     document.frm_informacion.txt_codigo_postal_entrega.value= document.frm_informacion.txt_codigo_postal.value;
     document.frm_informacion.txt_telefono_entrega.value= document.frm_informacion.txt_telefono.value;
   }
}
/*********************************************************************************************************************************
* Funcion para revisar los datos de usuario y clave antes de realizar una actualizacion dentro del PANEL DE CONTROL DEL USUARIO
**********************************************************************************************************************************/
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="#FFF0F0"; return; }						
		if(txt_clave1.value == ""){ 
			alert('¡Ingrese su Clave '); txt_clave1.focus(); txt_clave1.style.background="#FFF0F0"; 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="#FFF0F0"; return; }
		if(txt_clave2.value == ""){
			alert('¡Ingrese Nuevamente su Clave'); txt_clave2.focus(); txt_clave2.style.background="#FFF0F0"; 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="#FFF0F0"; 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="#FFF0F0"; 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="#FFF0F0"; return;
			}
		} 
		btn_enviar.disabled = true;
//		action="cambiar_usuario_clave_email.php";
		action="index.php?mod=modificacion_uc&tipo=actualizacion_uc";
		submit();
	}	
}
//************************************************************************************************************************************
//Funcion añadida el 16/04/2008
// Funcion que es llamada desde LA IDENTIFICACION DEL CLIENTE despues de haber presionado el boton "CONFIRMAR COMPRA"
//************************************************************************************************************************************
function validar_datos_cliente() //se puede mandar como parametro el modulo
{
	with(document.frm_datos_cliente)
	{
		if(txt_usuario.value == ""){ alert('¡Ingrese el usuario de acceso');  txt_usuario.focus(); txt_usuario.style.background="#FFF0F0"; return; }
		if(txt_clave.value == "")  { alert('¡Ingrese su Contraseña'); txt_clave.focus(); txt_clave.style.background="#FFF0F0"; return; }
		//action="index.php?mod=verificar_logueo&v_sesion=ok";
        
        action="verificar_logueo/ok.html";
        
		submit();
	}	
}
//************************************************************************************************************************************
//Funcion añadida el 17/04/2008
// Funcion que es llamada al momento que se presiona sobre el boton "PAGAR CON TARJETA DE CREDITO"
//************************************************************************************************************************************
function pasarela_tarjeta_credito() 
{
   vent = window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
   document.frm_compra.submit();   
}

function pasarela_paypal() 
{
   vent = window.open('','paypal','width=760,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
   document.frm_paypal.submit();   
}

function pasarela_contrareembolso(var_total)
{ 
    
    if (var_total<100)
    {
        var_gastos_transportista = 5;
        var_total +=var_gastos_transportista; 
    }
    else
    {
        var_gastos_transportista = var_total*0.05
        var_gastos_transportista = redondeo2decimales(var_gastos_transportista); 
        var_total += var_gastos_transportista;
        var_total = redondeo2decimales(var_total);
    }
    
    if (confirm('Para realizar este Tipo de Pago(CONTRA REEMBOLSO), tendr\u00e1 que pagar por Gastos de Gesti\u00f3n de la Agencia de Transporte un importe de '+var_gastos_transportista+' € \n\n El Total a pagar ser\u00e1 de '+var_total+' € \n\n\t\t\t ¿ Aceptar el pedido m\u00e1s los Gastos de Gesti\u00f3n del Transportista ?'))
    { 
      document.frm_documento_contra_reembolso.submit()
    } 
}
//************************************************************************************************************************************
function redondeo2decimales(numero)
{
    var original=parseFloat(numero);
    var result=Math.round(original*100)/100 ;
    return result;
}



function pasarela_domiciliacion_bancaria()
{ 
    document.frm_documento_domiciliacion_bancaria.submit();
}
//
//
//************************************************************************************************************************************
function validar_informacion_cliente(){
	with(document.frm_informacion){

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

		if(txt_clave.value == ""){ 
			alert('¡Ingrese su Clave '); txt_clave.focus(); txt_clave.style.background="#FFF0F0"; 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="#FFF0F0"; return; }

						
		if(txt_clave_rep.value == ""){
			alert('¡Ingrese Nuevamente su Clave'); txt_clave_rep.focus(); txt_clave_rep.style.background="#FFF0F0"; 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="#FFF0F0"; return; }
			
		
		if(txt_clave.value != txt_clave_rep.value){ 
			alert('¡Las Claves NO son iguales');
			txt_clave.value='';
			txt_clave_rep.value='';
			txt_clave.focus();
			return; }			
		
		
		if(txt_correo.value == ""){
			alert('¡Ingrese su Email'); txt_correo.focus(); txt_correo.style.background="#FFF0F0"; return; }
		else 
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt_correo.value))
			{} 
			else 
			{	alert ('La dirección de email es incorrecta.');	txt_correo.focus(); txt_correo.style.background="#FFF0F0"; return;
			}
		} 

		
		if(txt_nombre.value == ""){ 
		
			alert('¡Ingrese su Nombre o Razón Social');  txt_nombre.focus(); txt_nombre.style.background="#FFF0F0"; return; }
			
		if(txt_nif.value == ""){ 
			alert('¡Ingrese su NIF/CIF '); txt_nif.focus(); txt_nif.style.background="#FFF0F0"; return; }

		if(txt_contacto.value == ""){ 
			alert('¡Ingrese datos de la persona de contacto ');  txt_contacto.focus(); txt_contacto.style.background="#FFF0F0"; return; }
			
		if(txt_direccion.value == ""){ 
			alert('¡Ingrese su Dirección ');  txt_direccion.focus(); txt_direccion.style.background="#FFF0F0"; return; }

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


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

		if(txt_poblacion.value == ""){ 
			alert('¡Ingrese su Población'); txt_poblacion.focus(); txt_poblacion.style.background="#FFF0F0"; return; }
			
		if(txt_provincia.value == ""){
			alert('¡Ingrese su Provincia'); txt_provincia.focus(); txt_provincia.style.background="#FFF0F0"; return; }


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

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

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

		if(txt_poblacion_entrega.value == ""){ 
			alert('¡Ingrese su Población de Entrega'); txt_poblacion_entrega.focus(); txt_poblacion_entrega.style.background="#FFF0F0"; return; }
			
		if(txt_provincia_entrega.value == ""){
			alert('¡Ingrese su Provincia de Entrega'); txt_provincia_entrega.focus(); txt_provincia_entrega.style.background="#FFF0F0"; 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;
		}

		if(txt_pais.value != "ESPAÑA"){
			alert('¡Sólo se ACEPTAN COMPRAS en territorio español !'); txt_pais.focus(); txt_pais.style.background="#FFF0F0"; return; }

		btn_enviar.disabled = true;
	//	action="cliente_nuevo_alta_enviar.php";
	//	action="index.php?mod=clientes&accion=alta_cliente_enviar";
        action="clientes/alta_cliente_enviar.html";    
		submit();
	}	
}
//**************************************************************************************************************************************
function contar(obj,destino) {
  if (obj.value.length==obj.maxLength) destino.focus();
}
function validar(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron = /\d/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}
function validar_numeros_letras(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron = /\w/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
} 
function verifica(objeto,desti,patron){ 
	valor=objeto.value;
	if (!valor==""){
		if (patron.test(valor)){
			desti.focus();
		}else{
			alert('El valor  ' + valor + ', \nes Incorrecto \n\n Intentelo de nuevo.');
			objeto.value="";
			objeto.focus();
		}
	}
}
function validar_termino_busqueda()
{
	with(document.busca)
	{
		if (busqueda.value="")
		{
			alert("Ingrese el término o parte de el producto a buscar");
			busqueda.focus();
			busqueda.style.background = "#FFF0F0";
			return false;
		}
		return true;
	}
}
function validar_numeros(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron = /\d/; //Sola acepta numeros
    te = String.fromCharCode(tecla);
    return patron.test(te);
}
function Menu(id_Div,nombre) {
    if(id_Div.className == nombre + "Oculto") { 
        id_Div.className = nombre + "Visible";
    } else {
        id_Div.className = nombre + "Oculto";
    }
}
function validaciones__ocultarMostrarDiv(capaOcultar)
{   
 /*
    alert(capaOcultar);
    alert(sesion);
    
            str = agent.call('', 'func_varias__sesion', '', sesion);   
        alert("Aqui"+str); 
 */       
    var xOcultar = document.getElementById(capaOcultar);
    if (xOcultar.style.visibility == 'hidden')
    {
       // alert("OCULTO");
      //   xIcono.innerHTML            = '<a href="#" onclick=validaciones__ocultarMostrarDiv("'+capaOcultar+'","'+capaIcono+'")><img src="img/flecha_arriba.jpg" border="0" title="Ocultar información" /></a>';
        xOcultar.style.display      = 'block';
        xOcultar.style.visibility   = 'visible';
        //agent.call('','func_varias__sesion','call_sesion',sesion);

     
    }
    else                
    {      
        //alert("VISIBLE");
       // xIcono.innerHTML            = '<a href="#" onclick=validaciones__ocultarMostrarDiv("'+capaOcultar+'","'+capaIcono+'")><img src="img/flecha_abajo.jpg" border="0" title="Mostrar información" /></a>';
        xOcultar.style.display      = 'none';
        xOcultar.style.visibility = 'hidden';
       // sesion = false;
    }
   // return sesion; 
}
/*
function call_sesion(str)
{
    alert("Aqui"+str);
    document.getElementById("XXX").innerHTML =str; 
}
*/
function verificarCantidadArticulos()
{
    for(var i=0, ele;ele=document.getElementById("padre").getElementsByTagName("input")[i];i++)
    {
       // if (ele.value == '' || document.getElementById("padre").getElementsByTagName("input")[i].disabled = false )
         if (ele.value == 0  )   
        {
          alert("Ingrese al menos una catidad diferente de 0");
          return false;  
        }         
        return true;
    }
}
/**
*   function validar_campo(evento,patron)
*   Funcion que permite verificar la pulsacion de la tecla, capturado por el evento onkeypress(evento) y recoge el patron de la 
*   expresion regular que enviamos
*/
function validar_campo(evento,patron)
{

    tecla = (document.all) ? evento.keyCode : evento.which;

    //tecla =  8 => retroceso (para borrar) 
    //tecla =  9 y 0 =>  (para tabulador) 
    if (tecla==8 || tecla==9 || tecla==0 || tecla==13 || tecla==27) return true;  

    te = String.fromCharCode(tecla);
    if (patron.test(te))
    {
        return  true;
    }
	else
	{
		alert("\nEl dato introducido "+te+"  NO es v\u00E1lido.\n\n\tIntente de nuevo");
		return false;
	}
} 
/*
function confirmar_compra()
{
    var var_cupon = document.getElementById("txt_cupon").value;
     alert("cupon : "+var_cupon);
    if (var_cupon != '') //Si Hay algo
    {
        alert("Verdad ");
    }
    else
    {
       alert("Falso ");
       //document.location.href="cesta/confirmar_compra.html";
       
       window.open("./index.php?mod=cesta&accion=confirmar_compra","_self");
       
       
    }
    

}
*/