// evitar parpadeo de las imagenes de fondo 
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function ValidarEnviarAmigo ()
{
    var enviar = true;
    //Debemos de hacer un split por ; de los datos metidos en el input para los correos destino:
    mails =  document.getElementById("UcEnviarAmigo1_txtMailCorreoDestinatario").value.split(";")
    
    //Asignamos la clase de error:
    document.getElementById('UcEnviarAmigo1_spnError').style.color='';
    document.getElementById('UcEnviarAmigo1_spnError').className="error";
    //Campo de control de envio ok:
    document.getElementById('UcEnviarAmigo1_hdnOperacionOk').value='0';
    
    if ( mails.length > 0 )
    {        
        for (j = 0; j < mails.length; j++)
        {
            //alert(mails[j]);
        
            if ( !validaMail (mails[j], 'UcEnviarAmigo1_txtMailCorreoDestinatario','UcEnviarAmigo1_lblCorreoDestinatario') )
            {
                enviar = false;
                j = mails.length;
            }
        }
    }
    else
    {
        enviar = false;
        validaMail ('', 'UcEnviarAmigo1_txtMailCorreoDestinatario','UcEnviarAmigo1_lblCorreoDestinatario');
    }
   
   if (enviar)
   {
        if (!validaMail(document.getElementById('UcEnviarAmigo1_txtTuCorreo').value, 'UcEnviarAmigo1_txtTuCorreo','UcEnviarAmigo1_lblTuCorreo')) 
        {
           enviar = false;
      
        }
   }
   if (enviar)
   {
        if (!validaTexto('UcEnviarAmigo1_txtTuNombre', 'UcEnviarAmigo1_txtTuNombre','UcEnviarAmigo1_lblTuNombre')) 
        {
           enviar = false;
        }
   }
   if (enviar)
   {
        if (!validaTexto('UcEnviarAmigo1_txtComentario', 'UcEnviarAmigo1_txtComentario','UcEnviarAmigo1_lblTuComentario')) 
        {
           enviar = false;
        }
   }
        
   if (enviar)
   {    
    if ( !document.getElementById( "UcEnviarAmigo1_chkLeido" ).checked )
    {
       enviar = false;
       document.getElementById("UcEnviarAmigo1_spnError").innerHTML = document.getElementById('UcEnviarAmigo1_hdnError').value;
    }
   }
    
   if (enviar)
       document.getElementById("UcEnviarAmigo1_spnError").innerHTML = '';
    
    return enviar;
}

function ValidarFormularioEnviarAmigo()
{
 
}
    
function validaTexto(campo, campoError,labelError)
{
    
    if (document.getElementById(campo).value.length > 0)
    {
        document.getElementById(campoError).className = document.getElementById(campoError).className.replace(' error','');
        //document.getElementById(labelError).className = ''
        return true;
    }
    else
    {   
        document.getElementById(campoError).className = document.getElementById(campoError).className.replace(' error','');
        document.getElementById('UcEnviarAmigo1_spnError').innerHTML = document.getElementById('UcEnviarAmigo1_hdnErrorTexto').value;
        document.getElementById(campoError).className = document.getElementById(campoError).className + " error";
        //document.getElementById(labelError).className = 'error';
        return false;
    }
    
}

function validaMail(valorMail, campoError,labelError)
{

    if (!esMailValor(valorMail))
    {
        document.getElementById(campoError).className = document.getElementById(campoError).className.replace(' error','');
        document.getElementById('UcEnviarAmigo1_spnError').innerHTML = document.getElementById('UcEnviarAmigo1_hdnErrorMail').value;
        document.getElementById(campoError).className = document.getElementById(campoError).className + " error";
        //document.getElementById(labelError).className = 'error';
        return false;    
    }
    else
    {
        document.getElementById(campoError).className = document.getElementById(campoError).className.replace(' error','');
        //document.getElementById(labelError).className = ''
        return true;
    }
 

}

var timeOut;

function mostrarMenu(nodo)
{
    clearTimeout(timeOut);
    var i =0;
    var nodoRecorrido = document.getElementById('ulCapaMenu' + i);
    var linkRecorrido = document.getElementById('lnkCapaMenu' + i);
    var nodoActual = document.getElementById(nodo);
    var linkActual = document.getElementById(nodo.replace('ul','lnk'));
    
    while (nodoRecorrido != null)
    {
        if ( nodoRecorrido != nodoActual)
        {
            nodoRecorrido.style.display='none';
            if ( linkRecorrido.getAttribute('ModuloActual') == null)
                linkRecorrido.className = 'principal';
        }   
        
            
        
        i++;
        linkRecorrido = document.getElementById('lnkCapaMenu' + i);
        nodoRecorrido = document.getElementById('ulCapaMenu' + i);
        

    }
    nodoActual.style.display='block';
    linkActual.className = 'principal activo'
}

function cancelarNodo()
{
   clearTimeout(timeOut);
}

function ocultarMenu(nodo)
{
    timeOut = setTimeout("document.getElementById('" + nodo + "').style.display='none';if ( document.getElementById('" + nodo.replace('ul','lnk') + "').getAttribute('ModuloActual') == null)document.getElementById('" + nodo.replace('ul','lnk') + "').className='principal'",500);
}

function ComprobarCamposSolicitudInfo( campo )
{

    var campoError = document.getElementById('UcSolicitudInformacion1_spnError' + campo);
    var campoTexto = document.getElementById('UcSolicitudInformacion1_txtMensaje' + campo);
    var campoCheck = document.getElementById('UcSolicitudInformacion1_chkleidoAcepto' + campo);
    var lValido = true;
    campoTexto.className = '';
    
    if ( campoTexto.value.length == 0 )
    {
        campoError.innerHTML = cMsgTexto;
        campoError.className = 'error';
        campoTexto.className = 'error';
        lValido=false;
    }
    else
    {
        if (!campoCheck.checked)
        {
            campoError.innerHTML = cMsgLopd;
            campoError.className = 'error';
            campoTexto.className = 'error';
            lValido=false;
        }
        else
        {
            campoError.className = 'oculto';
        }
    }
    
    return lValido;
}

//--26/03/2007
//MIKEL

//Funciones para mostrar/ocultar capas


//Función que muestra u oculta la capa idcapa en función del parametro pasado como visible
	/*Params:
	    idCapa: id de la capa
	    visible: true/false
	 */  
	 
function ComprobarContrasena ( )
{
    debugger;
    var contrasena = document.getElementById('txtContrasena');
    var repetirContrasena = document.getElementById('txtRepetirContrasena');
    var contrasenaValida = true;
    
    
    if ( contrasena.value == repetirContrasena.value &&
         contrasena.value.length > 0 )
    {
        document.getElementById('spnError').className='oculto';
        contrasenaValida= true;
    }
    else
    {
        document.getElementById('spnError').className='error';
        contrasenaValida= false;
    }
    
    document.getElementById('spnErrorLOPD').className='oculto';
    
    if (contrasenaValida && !document.getElementById('chkLOPD').checked)
    {
        document.getElementById('spnErrorLOPD').className='error';
        contrasenaValida=false;
    }
    
    return contrasenaValida;
    
}
	 
function MostrarOcultarCapa ( idCapa, visible )
{
    //LOS COMENTARIOS SIGUIENTES SON SOBRE LAS DIFERENTES POSIBILIDADES DE IMPLEMENTAR LA VISIBILIDAD DE LAS CAPAS	
    
    /*
	//Opcion 1 -- Asignandole una clase --Problema no reserva el espacio de la capa  -- solo si la capa tiene una posicion realtive (contenida en otra capa)
	if (!visible) document.getElementById(idCapa).className="oculto"
	else document.getElementById(idCapa).className=""+idCapa;
    */
    /*
	//Opcion 2 -- Cambiando directamente la visibilidad --  la capa continua esta en su sitio pero no se ve
	if (!visible) document.getElementById(idCapa).style.visibility="hidden";
	else document.getElementById(idCapa).style.visibility="visible";
    */


	//Opcion3 -- cambiando directamente el display -- es similar a la primera (la direncia en la primear el display se asignaba por css) -- mismo problema primera
	if (!visible) document.getElementById(idCapa).style.display="none"
	else document.getElementById(idCapa).style.display="block";

}

//Función que muestra u oculta la capa (asignandole la clase oculto) en funcion de la clase de la capa pasada como parametro
	/*Params:
	    idCapa: id de la capa
	    clase: nombre de la clase visible
	 */ 
function MostrarOcultarCapaClase ( idCapa, clase )
{
    //LOS COMENTARIOS SIGUIENTES SON SOBRE LAS DIFERENTES POSIBILIDADES DE IMPLEMENTAR LA VISIBILIDAD DE LAS CAPAS	
    
    
	//Opcion 1 -- Asignandole una clase --Problema no reserva el espacio de la capa  -- solo si la capa tiene una posicion realtive (contenida en otra capa)
	visible = document.getElementById(idCapa).className;
	if (visible == "oculto") document.getElementById(idCapa).className=clase
	else document.getElementById(idCapa).className="oculto"

  
 }

//Función que muestra u oculta la capa idcapa en función del estado de la capa
	/*Params:
	    idCapa: id de la capa
	 */
function CambiarEstadoCapa ( idCapa )
{
	
	
	// A la hora de mostrar/ocultar las capas tenemos las mismas posibilidades que en el caso anterior -- utilizamos la opción 3
	
	var visibilidadCapa = document.getElementById(idCapa).style.display;
	
	if (visibilidadCapa == "none")
		document.getElementById(idCapa).style.display="block";
	else
		document.getElementById(idCapa).style.display="none";
	
	
}


//Funcion que muestra u oculta una capa mediante una clase
    /*Params:
        idCapa: id de la capa
        nuevaClase: clase que le asignamos a la capa
    */
var claseVisible='';
function CambiaClase(id, nuevaClase) {
		objeto = document.getElementById(id);
		if (claseVisible=='')
		{
		    if (objeto.className == 'oculto'){
			    document.getElementById(id).className = nuevaClase;
			    claseVisible=id;
		    }
		    else 
		    {
			    document.getElementById(id).className = 'oculto';
		    }
		}
		else
		{
		    if (claseVisible!=id)
		    {
		        document.getElementById(claseVisible).className='oculto';
		        document.getElementById(id).className =nuevaClase;
		        claseVisible=id;
		    }
		    else
		    {
		        if (document.getElementById(id).className=='oculto')
		        {
		            document.getElementById(id).className =nuevaClase;
		            claseVisible=id;
		        }
		        else
		        {
		            document.getElementById(id).className ='oculto';
		        }
		    }
		}
		
}

//Funcion que cambia las propiedades a un capa pasada como parametro
	/*Params:
	    idCapa: id de la capa
	    posicion: absolute/relative
	    alto: top en pixeles
	    izquierda: left en pixeles
	    zindex: z-index
	 */
function CambiarPropiedadesCapa ( idCapa, posicion, alto, izquierda, zindex )
{
	
	
	//Para ver el efecto -- al final mostramos la capa
	
	if (posicion != -1 )
		document.getElementById(idCapa).style.position=posicion;
		
	if (alto != -1 )           
		document.getElementById(idCapa).style.top=alto;
		
	if (izquierda != -1 )
		document.getElementById(idCapa).style.left=izquierda;
		
	if (zindex != -1 )
		document.getElementById(idCapa).style.zindex=zindex;
		
		
	//Mostramos la capa
	document.getElementById(idCapa).style.visibility="visible";
}


//FUNCIONES DE VALIDACION DE DATOS:

//Funcion que comprueba si se han introducido datos en un campo
	/*Params:
	    campo:campo a validar si contiene datos
	 */
function esCampoRelleno(campo)
{
    
    var cCampo = document.getElementById( campo );
    
    
    //Preguntamos si el contenido seleccionado esta relleno a traves de su longitud
   
    if (cCampo.value.length > 0)
    {
        return true;
    }
    else
    {
        alert('Campo Obligatorio');
        if (!cCampo.disabled)
        {
             cCampo.focus()
        }
        event.returnValue = null;
        return false;

    }      
  
}

//Funcion que comprueba si se ha seleccionado una opcion en un combo
	/*Params:
	    campo:combo a validar si se ha seleccionado una opcion
	 */
function esComboRelleno(Campo)
{
    
    var cCampo = document.getElementById( Campo );
    
    //Preguntamos si el contenido seleccionado esta relleno a traves de su longitud
    if (cCampo.length > 0 )
    {
        if (cCampo[cCampo.selectedIndex].value.length > 0)
        {
            return true;
        }
        else
        {
            alert('Obligatory Field');
            if (!cCampo.disabled){cCampo.focus()}
            event.returnValue = null;
            return false;
        }
    }
    else
    {
        alert('Obligatory Field');
        if (!cCampo.disabled){cCampo.focus()}
        event.returnValue = null;
        return false;
     }
    
}	


//Funcion que comprueba si el contenido de un campo es numérico
	/*Params:
	    campo:combo a validar si su contenido es numérico
	 */
function esNumero (Campo)
{
        var cCampo = document.getElementById( Campo );
        if (isNumeric(cCampo.value))
        {
            return true;
        }
        else
        {
            event.returnValue = null;
            return false;
        }
         
}


//Funcion auxiliar que comprueba si el valor pasado tiene un formato de numero correcto
	/*Params:
	    campo:valor a comprobar
	 */
function isNumeric(n)
{ 
    if ((n.indexOf(','))!= -1)
    {   
        n=n.replace(',','.');
    }
    else
    {
        if ((n.indexOf('.'))!= -1)
        {   
            n=n.replace('.',',');
        }
    } 

    var x=n/2;
    if ((!x)&&(x!="0")) 
        return false;
       // alert ("Incorrect numeric format.");
    else return true;
}

function esNumericoObligatorioVip(campo,label)
{
    var n= document.getElementById(campo).value;

    if ((n.indexOf(','))!= -1)
    {   
        n=n.replace(',','.');
    }
    else
    {
        if ((n.indexOf('.'))!= -1)
        {   
            n=n.replace('.',',');
        }
    } 
    
    if (n.length>0)
    {
        var x=n/2;
        if ((!x)&&(x!="0")) 
        {
            document.getElementById(label).style.display = 'inline';
            return false;
        } 
        else
        {
            document.getElementById(label).style.display = 'none';
            return true;
        }
    }
    else
    {
        document.getElementById(label).style.display = 'inline';
        return false;
    }
}

function esNumericoObligatorio(campo,label)
{ 
    var n= document.getElementById(campo).value;

    if ((n.indexOf(','))!= -1)
    {   
        n=n.replace(',','.');
    }
    else
    {
        if ((n.indexOf('.'))!= -1)
        {   
            n=n.replace('.',',');
        }
    } 
    
    if (n.length>0)
    {
        var x=n/2;
        if ((!x)&&(x!="0")) 
        {
            document.getElementById(label).style.display = 'inline';
            document.getElementById(label).innerHTML= 'Error. Valor incorrecto';
            return false;
        } 
        else
        {
            document.getElementById(label).style.display = 'none';
            document.getElementById(label).innerHTML = '';
            return true;
        }
    }
    else
    {
        document.getElementById(label).style.display = 'inline';
        document.getElementById(label).innerHTML = 'Error. Valor incorrecto';
        return false;
    }
}

function esMailValor( mail)
{

    var correcto = true ;
                      
    reMail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
                  
    if ( mail !="" )
    {
        if (reMail.test( mail ))
        { 
            correcto= true ;
        }
        else
            correcto= false ;
    }
    else
   {
         correcto= false ;
    }    
   
   return correcto;  
}
    
//Función que comprueba si un campo tiene un contiene una direccion de mail con formato correcto
    /*Params:
        campo:campo que contiene el mail a comprobar
     */
function esMail( Campo )
{
    
    
    
    var cCampo = document.getElementById( Campo );
    
    mail = cCampo.value;

    var correcto = true ;
                      
    //reMail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; //Antigua
    //reMail = /^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/; //Alternativa
    reMail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
                  
    if ( mail !="" )
    {
        if (reMail.test( mail ))
        { 
            correcto= true ;
//            return true;
        }
        else
            correcto= false ;
//            event.returnValue = null;
//            return false;
    }
    else
   {
         correcto= false ;
    
//         return false;
    }
    
    

//    if(!correcto)
//    {
//        event.returnValue = null;
//        alert('Mail format is not correct');  
//        cCampo.focus();
//    }
    
   
   return correcto;    
    
}
 
 

/*//Función que comprueba si el contenido de un campo contiene numeros enteros (0-9)
    Params:
        campo:campo a validar si su contenido es entero
     */
function esEntero(Campo) 
{
    //Compara para todos la cadena si alguno de los caracteres es distinto del 0 al 9.
    var cCampo = document.getElementById( Campo );
    cadena=cCampo.value;
    k="0123456789 ";

    for (j=0;j<cadena.length;j++) 
    {
        if (k.indexOf(cadena.charAt(j)) == -1) 
        {
//            alert('No decimal/character allowed');
//            if (!cCampo.disabled)
//                cCampo.focus()
//            event.returnValue = null;    
            return false;
        }
    }

    return true;
}

function DeshabilitarRangoPrecios()
{   
    if ( document.getElementById("txtCuotaMensual").value != "" )
        document.getElementById("ddlRangoPrecios").selectedIndex = 0;
    
}

function DeshabilitarCuotaMensual()
{
   if ( document.getElementById("ddlRangoPrecios").selectedIndex != 0 )
        document.getElementById("txtCuotaMensual").value = "";
    
   
}

function BorrarValueSiNoEsEntero( obj )
{
    //alert(esEntero( obj.id ));
    if ( esEntero( obj.id ) == false )
    {
        document.getElementById( obj.id ).value="";
    }
}


//Función encargada de cambial la propiedad backgroundColor del control pasado por parámetro.
    /*Params: 
        objeto: control al que le quiere cambiar la propiedad backgroundColor
        color: nuevo color que se le va a dar
    */
function CambiarBackgroundColor( objeto, color )
{
    //Firefox transforma automaticamente el color, a rgb
    var colorAnterior=objeto.style.backgroundColor;
    objeto.style.backgroundColor=color;
    color=objeto.style.backgroundColor;
    objeto.style.backgroundColor=colorAnterior;
    //

     if ( objeto.style.backgroundColor != color )
     {
         objeto.style.backgroundColor = color;
     }
     else
     {
         objeto.style.backgroundColor = '';
     }
}

function CambiarBackgroundColorColums( objeto, color, numColum )
{
    
    //alert( 'El color enviado es: ' + color + ' El backGround actual es: ' + objeto.style.backgroundColor + ' El color anterior es: ' + colorAnterior );
    var colorAnterior=objeto.style.backgroundColor;
    objeto.style.backgroundColor=color;
    color=objeto.style.backgroundColor;
    objeto.style.backgroundColor=colorAnterior;
    
    var aDivision = objeto.id.split('_');
    var nNumColumn = aDivision[aDivision.length - 1];
    
    var objetoId= objeto.id.substring(0,objeto.id.length-nNumColumn.length);
    
    if (objetoId + numColum != objeto.id)
    {
    
        var i=0;
     
        for (i=0;i<parseInt(numColum);i++)
        {
            var celda = document.getElementById( objetoId + i );
             
            if ( celda.style.backgroundColor != color )
            {
                
                 celda.style.backgroundColor = color;
            }
            else
            {
                celda.style.backgroundColor = '';
            }
         }
    }
    else
    {
    
        var celda = document.getElementById( objetoId + numColum );
         if ( celda.style.backgroundColor != color )
         {
             celda.style.backgroundColor = color;
         }
         else
         {
             celda.style.backgroundColor = '';
         }
    }
}
    



//Funcion Encargada de validar si el contenido de un campo contiene un nif correcto
    /*Params:
        campo: campo que contiene el valor del nif a validar
     */       
function ValidarNif(campo)
{
   //Todo el campo
   abc=document.getElementById(campo).value
   //sin letra (dni)
   dni=abc.substring(0,abc.length-1)
   //letra
   let=abc.charAt(abc.length-1)
//       if (isNumeric(dni))
//       {
             if (!isNaN(let))
             {
                    alert('Falta la letra')
                    document.getElementById(campo).focus()
                    event.returnValue = null;
                    return false;
             }
             else
             {
                   cadena="TRWAGMYFPDXBNJZSQVHLCKET"
                   posicion = dni % 23
                   letra = cadena.substring(posicion,posicion+1)

                   if (letra!=let.toUpperCase())
                   {
                         alert("Nif no válido")
                         document.getElementById(campo).focus()
                         event.returnValue = null;
                         return false;
                   }
                   else
                   return true;
                   
              }
//       }
}


/*Funcion Encargada de Comparar dos campos de contraseńa
    Params:
        password1: input que contiene la primera password
        password2: input que contiene la segunda password
     */         
function ComparaPassword ( password1, password2 )
{
 var valor1 = document.getElementById( password1 ).value;
 var valor2 = document.getElementById( password2 ).value;
     
     if (valor1!=valor2)
     {
        alert ("Password diferentes");
        document.getElementById(password1).value='';
        document.getElementById(password2).value='';
        document.getElementById(password1).focus();
        event.returnValue = null;
        return false;
        
      }
      else 
      return true;
}

function HabilitarDeshabilitarControl( nombreObj, deshabilitar )
{
    document.getElementById( nombreObj ).disabled = deshabilitar;
}

//Funcion Encargada de poner el foco en un control pasado como parametro
    /*Params:
        campo: campo al que le asignamos el foco
     */  
function ponerFoco(campo)
{
    setTimeout("document.getElementById('"+campo+"').focus();",100);
}


//Funcion encargada de validar los campos del formulario del formulario de registro de usuarios
function ValidarUsuarios()
{
    
    var lValidado=true;
    var lValidaCampo;
    //var errorGeneral= document.getElementById('lblResultados');
    //errorGeneral.innerHTML='';

    lValidaCampo=ValidoCorreo(document.getElementById('txtEmail'));
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtEmail');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCamposIguales('txtPassword','txtPasswordRepeticion');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtPassword');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtPasswordRepeticion');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtNombre');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtApellidos1');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtApellidos2');
    lValidado=lValidado==true?lValidaCampo:lValidado;
   
    lValidaCampo=ValidarNif(document.getElementById('txtNif'));
    lValidado=lValidado==true?lValidaCampo:lValidado;
   
    lValidaCampo=ValidarCampoObligatorio('txtNif');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidoTelefono(document.getElementById('txtTfno'));
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtTfno');
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidoCP(document.getElementById('txtCp'));
    lValidado=lValidado==true?lValidaCampo:lValidado;
    
    lValidaCampo=ValidarCampoObligatorio('txtCp');
    lValidado=lValidado==true?lValidaCampo:lValidado;
   
    return lValidado;
}

function ValidarCampoObligatorio(campo)
{

    var lCampoRelleno=true;
    var campoComprobar=document.getElementById(campo);
    var etiquetaError=document.getElementById(campo.replace('txt','lblError'));
    
    if (campoComprobar.value.length==0 && campoComprobar.disabled==false)
    {
        etiquetaError.innerHTML=CampoObligatorio;
        lCampoRelleno=false;
    }
    else if(etiquetaError.innerHTML==CampoObligatorio)
    {
        etiquetaError.innerHTML='';
    }
    
    return lCampoRelleno;
}

function ValidarCamposIguales(campo,campo2)
{
    var lCampoRelleno=true;
    var campoComprobar=document.getElementById(campo);
    var campoComprobar2=document.getElementById(campo2);
    var etiquetaError=document.getElementById(campo.replace('txt','lblError'));
    var etiquetaError2=document.getElementById(campo2.replace('txt','lblError'));
    etiquetaError.innerHTML='';
    etiquetaError2.innerHTML='';
    
    if (campoComprobar.value != campoComprobar2.value && campoComprobar.value.length>0 && campoComprobar2.value.length>0)
    {
        etiquetaError.innerHTML=CampoIncorrecto;
        etiquetaError2.innerHTML=CampoIncorrecto;
        lCampoRelleno=false;
    }
    
    return lCampoRelleno;
}

//Función encargada de redireccionar la página padre de un iframe o de cualquier página hija.
function RedireccionarPadre(url)
{
    if (url.length>0)
        parent.location.href=url;
}


function ValidarLogin()
{
alert('entra');
    //Para cada control validamos su contenido
    var Salir=true;
    
    //Comenzamos
    Salir=esCampoRelleno('ucLogeoUser$txtLogin');
    
    if (Salir) 
         Salir=esMail('ucLogeoUser$txtLogin');
         
    
    if (Salir)
         Salir=esCampoRelleno('ucLogeoUser$txtPassword');
    
    
    return Salir;
alert(Salir);
}

//Función para abrir un pop-up
function FNpopup(p_url,p_id,p_ancho,p_alto,p_carac){
   
    car="width="+p_ancho+",height="+p_alto+",left="+((screen.width/2)-(parseInt(p_ancho)/2))+",top="+((screen.height/2)-(parseInt(p_alto)/2))+","+p_carac
	window.open(p_url,p_id,car)
}

//funcion para validar el tamańo de un textarea
function ismaxlength(obj){

    var mlength= obj.getAttribute("maxlength");
    
    if ( mlength != null )
    {
        if ( obj.value.length>mlength )
        obj.value=obj.value.substring(0,mlength)
    }
}

var CampoObligatorio='';
var CampoIncorrecto='';

function ValidarCompradores()
{
   ValidarCompradoresConyuges();
   return esCompraValida();
}

var nTipoValida=0;

function esCompraValida()
{
   var CompraValida=true;
   var i=0;
   for (i=0;i<document.forms[0].length;i++)
   {
   
        if (document.forms[0][i].type=='text')
        {
        
            if (document.forms[0][i].id.indexOf('Comprador1',0)!=-1 || document.forms[0][i].id.indexOf('Conyuge1',0)!=-1 || document.forms[0][i].id.indexOf('Comprador2',0)!=-1 || document.forms[0][i].id.indexOf('Conyuge2',0)!=-1)
            {    
                if (document.getElementById(document.forms[0][i].id.replace('txt','lblError')).innerHTML!='')
                {
                    CompraValida=false;
                }
                else
                {
                    if (document.forms[0][i].id.indexOf('txtEmail',0)!=-1)
                    {
                        ValidoCorreo(document.forms[0][i]);
                    }
                    else if (document.forms[0][i].id.indexOf('txtTelefono',0)!=-1)
                    {
                        ValidoTelefono(document.forms[0][i]);
                    }
                    else if (document.forms[0][i].id.indexOf('txtCp',0)!=-1)
                    {
                        ValidoCP(document.forms[0][i]);
                    }
                    else if (document.forms[0][i].id.indexOf('txtFechaNacimiento',0)!=-1)
                    {
                        ValidoFecha(document.forms[0][i]);
                    }
                    else if (document.forms[0][i].id.indexOf('txtNif',0)!=-1)
                    {
                        if (nTipoValida==0)
                        {
                            ValidarNif(document.forms[0][i]);
                        }
                        else
                        {
                            ValidarNifExtranjero(document.forms[0][i]);
                        }
                    }
                    if (document.getElementById(document.forms[0][i].id.replace('txt','lblError')).innerHTML!='')
                    {
                        CompraValida=false;
                    }
                }
            }
        }
        else if (document.forms[0][i].type=='select-one')
        {
            if (document.forms[0][i].id.indexOf('Comprador1',0)!=-1)
            {
                if (document.getElementById(document.forms[0][i].id.replace('ddl','lblError')).innerHTML!='')
                {
                    CompraValida=false;
                }
            }
        }
   }
   return CompraValida;
}

function ValidarCompradoresConyuges()
{
   var etiquetasComprador1='';
   var etiquetasComprador2='';
   var limpiarEtiquetasComprador1='';
   var limpiarEtiquetasComprador2='';
   var hayComprador2=false;
   var i=0;

   for (i=0;i<document.forms[0].length;i++)
   {
        if (document.forms[0][i].getAttribute('noobligatorio') == null)
        {
            if (document.forms[0][i].type=='text')
            {
                if (document.forms[0][i].id.indexOf('Comprador1',0)!=-1 || document.forms[0][i].id.indexOf('Conyuge1',0)!=-1)
                {
                    if (document.forms[0][i].value.length==0)
                    {
                        if (etiquetasComprador1.length==0)
                            etiquetasComprador1=document.forms[0][i].id.replace('txt','lblError');
                        else
                            etiquetasComprador1+= ';' + document.forms[0][i].id.replace('txt','lblError');
                    }
                    else
                    {
                        if (limpiarEtiquetasComprador1.length==0)
                            limpiarEtiquetasComprador1=document.forms[0][i].id.replace('txt','lblError');
                        else
                            limpiarEtiquetasComprador1+= ';' + document.forms[0][i].id.replace('txt','lblError');
                    }
                }
                else if (document.forms[0][i].id.indexOf('Comprador2',0)!=-1 || document.forms[0][i].id.indexOf('Conyuge2',0)!=-1)
                {
                    if (document.forms[0][i].value.length==0)
                    {
                        if (etiquetasComprador2.length==0)
                            etiquetasComprador2=document.forms[0][i].id.replace('txt','lblError');
                        else
                            etiquetasComprador2+= ';' + document.forms[0][i].id.replace('txt','lblError');
                    }
                    else
                    {
                        hayComprador2=true;
                        if (limpiarEtiquetasComprador2.length==0)
                            limpiarEtiquetasComprador2=document.forms[0][i].id.replace('txt','lblError');
                        else
                            limpiarEtiquetasComprador2+= ';' + document.forms[0][i].id.replace('txt','lblError');
                    }
                }
            }
            else if (document.forms[0][i].type=='select-one')
            {
                var combo=document.forms[0][i];
                
                if (combo.id.indexOf('Comprador1',0)!=-1)
                {
                    if (combo[combo.selectedIndex].value.length==0)
                    {
                        if (etiquetasComprador1.length==0)
                            etiquetasComprador1=combo.id.replace('ddl','lblError');
                        else
                            etiquetasComprador1+= ';' + combo.id.replace('ddl','lblError');
                    }
                    else
                    {
                        if (limpiarEtiquetasComprador1.length==0)
                            limpiarEtiquetasComprador1=combo.id.replace('ddl','lblError');
                        else
                            limpiarEtiquetasComprador1+= ';' + combo.id.replace('ddl','lblError');
                    }
                }
            }
        }
   }
   if (etiquetasComprador1.length>0)
        MostrarMensajeObligatorio(etiquetasComprador1,false);
   if (etiquetasComprador2.length>0 && hayComprador2)
        MostrarMensajeObligatorio(etiquetasComprador2,false);
   if (limpiarEtiquetasComprador1.length>0)
        MostrarMensajeObligatorio(limpiarEtiquetasComprador1,true);
   if (limpiarEtiquetasComprador2.length>0)
        MostrarMensajeObligatorio(limpiarEtiquetasComprador2,true);
   if (etiquetasComprador2.length>0 && !hayComprador2)
        MostrarMensajeObligatorio(etiquetasComprador2,true);
}

function MostrarMensajeObligatorio(Labels,Limpiar)
{
    var aLabels= Labels.split(';');
    var i=0;
    
    for (i=0;i<aLabels.length;i++)
    {
        if (Limpiar)
        {
            if (document.getElementById(aLabels[i]).innerHTML==CampoObligatorio)
                document.getElementById(aLabels[i]).innerHTML='';
        }
        else
            document.getElementById(aLabels[i]).innerHTML=CampoObligatorio;
    }
}



function MostrarMensajeIncorrecto(Labels,Limpiar)
{
    var aLabels= Labels.split(';');
    var i=0;
    
    for (i=0;i<aLabels.length;i++)
    {
        if (Limpiar)
        {
            //if (document.getElementById(aLabels[i]).innerHTML==CampoObligatorio)
                document.getElementById(aLabels[i]).innerHTML='';
        }
        else
            document.getElementById(aLabels[i]).innerHTML=CampoIncorrecto;
    }
}

function ValidoFecha(text)
{
    FechaValida=true;
    MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),true); 
    //si no tiene 5 caracteres no es válido 
   if (text.value.length>0)
   {
       if (!esFecha(text.value))
       { 
        FechaValida=false;
        MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),false);
       }
   } 
   return FechaValida 
}

function VipEstaRelleno(text)
{
    var EstaRelleno=true; 
    document.getElementById(text.id.replace('txt','lblError')).className='oculto';
    text.className='';
   
    if (text.value.length==0)
    {
        EstaRelleno=false;
        document.getElementById('UcFormularioDatosPersonales1_pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContadorVip(1);
        }
    } 

    if (text.getAttribute("contador")=="1" && EstaRelleno)
    {
        ModificarContadorVip(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContadorVip()==0)
        document.getElementById('UcFormularioDatosPersonales1_pError').className='oculto';

   return EstaRelleno;
}

function EstaRellenoProcesoCompra(text)
{
    var EstaRelleno=true; 

    document.getElementById(text.id.replace('txt','lblError')).className='oculto';
    text.className='';
   
    //si no tiene 5 caracteres no es válido 
    if (text.value.length==0)
    {
        EstaRelleno=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
    } 
    if (text.getAttribute("contador")=="1" && EstaRelleno)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return EstaRelleno;
}

function ComprobarContrasenya(pass,pass2)
{
    PassValido=true; 

    document.getElementById(pass.id.replace('txt','lblError')).className='oculto';
    document.getElementById(pass2.id.replace('txt','lblError')).className='oculto';
    pass.className='psswrd';
    pass2.className='psswrd';
   
    //si no tiene 5 caracteres no es válido 
    if (pass.value.length==0 || pass.value!=pass2.value)
    {
        PassValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(pass.id.replace('txt','lblError')).className='error';
        document.getElementById(pass2.id.replace('txt','lblError')).className='error';
        pass.className='error psswrd';
        pass2.className='error psswrd';
        if (pass.getAttribute("contador")=="0")
        {
            pass.setAttribute("contador",'1');
            ModificarContador(1);
        }
    } 
    if (pass.getAttribute("contador")=="1" && PassValido)
    {
        ModificarContador(-1);
        pass.setAttribute("contador",'0');
    }
    
    
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return PassValido;
}

function ComprobarEstadoCivilProcesoCompra(combo)
{
   RelacionValida=true;
   
    if (combo[combo.selectedIndex].value.length==0)
    {
        RelacionValida=false;
        document.getElementById('pError').className='aviso_error';
        
        if (combo.getAttribute("contador")=="0")
        {
            combo.setAttribute("contador",'1');
            ModificarContador(1);
        }
    }
   
    
    if (combo.getAttribute("contador")=="1" && RelacionValida)
    {
        ModificarContador(-1);
        combo.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return RelacionValida; 
}

function ValidarProcesoCompraSimulacion( nuevoUsuario,mensajeError )
{

//    var etiquetaError= document.getElementById('lblErrorAcepto');
//    var checkboxAcepto= document.getElementById('chkAcepto');
    var ValidadoPC=true;
    var lValidaCampo;
    
//    etiquetaError.innerHTML='';
//    
//    if (checkboxAcepto.checked)
//    {

        
        lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtNombre'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=ValidarCorreoProcesoCompra(document.getElementById('txtEmail'),true);
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=ValidarTelefonoStringProcesoCompra(document.getElementById('txtTelefono'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=ValidarCpProcesoCompra(document.getElementById('txtCp'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        if (nuevoUsuario)
        {
            lValidaCampo=ComprobarContrasenya(document.getElementById('txtPass1'),document.getElementById('txtPass2'));
            ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        }
//    }
//    else
//    {
//       etiquetaError.innerHTML= mensajeError;
//       ValidadoPC=false;
//    }
    
    if (!ValidadoPC)
        location='#aError'
    
    return ValidadoPC;
}

function ValidarProcesoCompra( procesoCompra,nuevoUsuario,esPersonaJuridica,mensajeError,mensajeErrorLOPD )
{
    var checkboxAceptoLOPD= document.getElementById('chkAceptoLOPD');
    var etiquetaErrorLOPD = document.getElementById('spnErrorLOPD');
    var ValidadoPC=true;
    var lValidaCampo;
    
    document.getElementById('pError').className='oculto';

    etiquetaErrorLOPD.innerHTML= '';

    lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtNombre'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtApellidos1'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    if (!esPersonaJuridica)
    {
        lValidaCampo=ValidarNifNieProcesoCompra(document.getElementById('txtNif'),document.getElementById('ddlTipoDocumento'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        if ( !lValidaCampo )
            document.getElementById('divBocadilloNif').style.display = 'inline';
    }
    else
    {
        lValidaCampo=ValidarCifProcesoCompra(document.getElementById('txtNif'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        if ( !lValidaCampo )
            document.getElementById('divBocadilloNif').style.display = 'inline';
    }
    
    lValidaCampo=ValidarCorreoProcesoCompra(document.getElementById('txtEmail'),true);
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarFechaProcesoCompraSinObligatoriedad(document.getElementById('txtFechaNac'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    if ( nuevoUsuario ) 
    {
        lValidaCampo=ValidarTelefonoStringProcesoCompra(document.getElementById('txtTelefono'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtDireccion'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtCiudad'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=ValidarCpProcesoCompra(document.getElementById('txtCp'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtPais'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=ComprobarEstadoCivilProcesoCompra(document.getElementById('ddlEstadoCivilComprador'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    }
    else
    {
        lValidaCampo=ValidarTelefonoStringProcesoCompraSinObligatoriedad(document.getElementById('txtTelefono'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=ValidarCpProcesoCompraSinObligatoriedad(document.getElementById('txtCp'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    }
    
    
    if (!checkboxAceptoLOPD.checked && ValidadoPC )
    {
        etiquetaErrorLOPD.innerHTML= mensajeErrorLOPD;
        ValidadoPC=false;   
    }
    else if ( ValidadoPC && checkboxAceptoLOPD.checked )
    {
        if ( procesoCompra )
            abreVentana(document.getElementById('chkAcepto'),document.getElementById('rdbTarjeta'));
    }
    
    return ValidadoPC;
    
}

function VipValidarRegistroUsuario()
{

    var ValidadoPC=true;
    var lValidaCampo;
    cPrefijo = 'UcFormularioDatosPersonales1_';
    
    lValidaCampo=VipEstaRelleno(document.getElementById(cPrefijo + 'txtNombre'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=VipEstaRelleno(document.getElementById(cPrefijo +'txtApellidos1'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=VipValidarNifNieCif(document.getElementById(cPrefijo +'txtNif'),document.getElementById(cPrefijo + 'ddlTipoDocumento'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=VipValidarFecha(document.getElementById(cPrefijo +'txtFecNam'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=VipValidarCorreo(document.getElementById(cPrefijo +'txtEmail'),true);
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=VipValidarTelefonoString(document.getElementById(cPrefijo +'txtTelefono'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
//    lValidaCampo=VipEstaRelleno(document.getElementById(cPrefijo +'txtDireccion'));
//    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
//    lValidaCampo=VipEstaRelleno(document.getElementById(cPrefijo +'txtCiudad'));
//    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=VipValidarCp(document.getElementById(cPrefijo +'txtCp'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=VipEstaRelleno(document.getElementById(cPrefijo +'txtMunicipio'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    document.getElementById(cPrefijo +'spnErrorLOPD').style.display='none';
    
    if (ValidadoPC && !document.getElementById(cPrefijo + 'chkLOPD').checked)
    {
        document.getElementById(cPrefijo +'spnErrorLOPD').style.display='block';
        document.getElementById(cPrefijo +'spnErrorLOPD').className="aviso_error";
        ValidadoPC=false;
        
    }
    return ValidadoPC;
}

function ValidarRegistroUsuario( nuevoUsuario,esPersonaJuridica )
{
    var ValidadoPC=true;
    var lValidaCampo;
    lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtNombre'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtApellidos1'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    if (!esPersonaJuridica)
    {
        lValidaCampo=ValidarNifNieProcesoCompra(document.getElementById('txtNif'),document.getElementById('ddlTipoDocumento'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    }
    else
    {
        lValidaCampo=ValidarCifProcesoCompra(document.getElementById('txtNif'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    }
    
    lValidaCampo=ValidarFechaProcesoCompra(document.getElementById('txtFecNam'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreoProcesoCompra(document.getElementById('txtEmail'),true);
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarTelefonoStringProcesoCompra(document.getElementById('txtTelefono'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtDireccion'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtCiudad'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCpProcesoCompra(document.getElementById('txtCp'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EstaRellenoProcesoCompra(document.getElementById('txtPais'));
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    if (nuevoUsuario)
    {
        lValidaCampo=ComprobarContrasenya(document.getElementById('txtPass1'),document.getElementById('txtPass2'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    }
    
    document.getElementById('spnErrorLOPD').style.display='none';
    
    if (ValidadoPC && !document.getElementById('chkLOPD').checked && document.getElementById('dvPrerreservas')==null)
    {
        document.getElementById('spnErrorLOPD').style.display='block';
        ValidadoPC=false;
        
    }
    return ValidadoPC;
    
}


function EstablecerUsuario(text,usuario)
{
    usuario.innerHTML=text.value;
}

function VipValidarFecha(text)
{
   var FechaValida=true;    

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';
    
    if ( text.value.length > 0 ) 
    {
        if (!esFecha(text.value))
        { 
            FechaValida=false;
            document.getElementById('UcFormularioDatosPersonales1_pError').className='aviso_error';
            document.getElementById(text.id.replace('txt','lblError')).className='error';
            text.className='error';
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContadorVip(1);
            }
        } 
    }
    if (text.getAttribute("contador")=="1" && FechaValida)
    {
        ModificarContadorVip(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContadorVip()==0)
        document.getElementById('UcFormularioDatosPersonales1_pError').className='oculto';

   return FechaValida;
}

function ValidarFechaProcesoCompra(text)
{

   var FechaValida=true;    

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';
    
    //si no tiene 5 caracteres no es válido 
       if (!esFecha(text.value))
       { 
        FechaValida=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       } 
    
    if (text.getAttribute("contador")=="1" && FechaValida)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return FechaValida;
}

function ValidarFechaProcesoCompraSinObligatoriedad(text)
{

   var FechaValida=true;    

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';
    
    //si no tiene 5 caracteres no es válido 
    if (text.value.length > 0)
    {
       if (!esFecha(text.value))
       { 
        FechaValida=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       } 
    }
    
    if (text.getAttribute("contador")=="1" && FechaValida)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return FechaValida;
}

function ValidoCP(text)
{ 
    CPValido=true;
    MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),true); 
    //si no tiene 5 caracteres no es válido 
   if (text.value.length>0)
   {
       if (!esEntero(text.id) || text.value.length!=5)
       { 
        CPValido=false;
        MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),false);
       }
   } 
   return CPValido 
}

function VipValidarCp(text)
{
   var CPValido=true; 

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';
   
   if (!esEntero(text.id) || text.value.length!=5)
   { 
        CPValido=false;
        document.getElementById('UcFormularioDatosPersonales1_pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContadorVip(1);
        }
   }

    if (text.getAttribute("contador")=="1" && CPValido)
    {
        ModificarContadorVip(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContadorVip()==0)
        document.getElementById('UcFormularioDatosPersonales1_pError').className='oculto';
        
   return CPValido 
}

function ValidarCpProcesoCompraSinObligatoriedad(text)
{
   CPValido=true; 

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';
   
   if ( text.value.length > 0 )
   {
       if (!esEntero(text.id) || text.value.length!=5)
       { 
        CPValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
    }
    
    if (text.getAttribute("contador")=="1" && CPValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return CPValido;
}

function ValidarCpProcesoCompra(text)
{
    
   CPValido=true; 

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';
   
       if (!esEntero(text.id) || text.value.length!=5)
       { 
        CPValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
    
    if (text.getAttribute("contador")=="1" && CPValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return CPValido 
}

function ValidoCorreo(text)
{ 
    MailValido=true;
    MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),true); 
    
   if (text.value.length>0)
   {
       if (!esMail(text.id))
       { 
        MailValido=false;
        MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),false);
       }
   } 
   return MailValido 
}

function VipValidarCorreo(text,obligatorio)
{
   var MailValido=true;
   
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';

   if (obligatorio || text.value.length>0)
   {
        if (!esMail(text.id))
        { 
            MailValido=false;
            document.getElementById('UcFormularioDatosPersonales1_pError').className='aviso_error';
            document.getElementById(text.id.replace('txt','lblError')).className='error';
            text.className='error';
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContadorVip(1);
            }
        }
    }
    
   if (text.getAttribute("contador")=="1" && MailValido)
   {
        ModificarContadorVip(-1);
        text.setAttribute("contador",'0');   
   }
   if (ObtenerContadorVip()==0)
        document.getElementById('UcFormularioDatosPersonales1_pError').className='oculto';
        
   return MailValido 
}

function ValidarCorreoProcesoCompra(text,obligatorio)
{
   MailValido=true;
   
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='';

   if (obligatorio || text.value.length>0)
   {
    if (!esMail(text.id))
       { 
        MailValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContador(1);
            }
        }
    }
    if (text.getAttribute("contador")=="1" && MailValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');   
    }
   if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';
        
   return MailValido 
} 

function ValidoTelefono(text)
{ 
    TelefonoValido=true;
    MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),true); 
   
   if (text.value.length>0)
   {
       if (!esEntero(text.id) || text.value.length<7)
       { 
        TelefonoValido=false;
        MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),false);
       }
   } 
   return TelefonoValido 
}

function ValidarTelefonoProcesoCompraObligatorio(text)
{ 
    TelefonoValido=true;
    document.getElementById(text.id.replace('txt','lblError')).className='oculto'; 
    text.className='';
   
   if (text.value.length>0)
   {
       if (!esEntero(text.id) || text.value.length<7)
       { 
        TelefonoValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
   } 
   else
   {
    if (document.getElementById('chkQuieroPromocionSms').checked)
    {
        
        TelefonoValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
    }
   }
   
    if (text.getAttribute("contador")=="0")
    {
        text.setAttribute("contador",'1');
        ModificarContador(1);
    }
   
   return TelefonoValido 
}

function ValidarTelefonoMovilScoring( text )
{
    TelefonoValido=true;
    
    document.getElementById( text.id.replace( 'txt','lblError' ) ).className = 'oculto'; 
    
    text.className = 'txt';
    
    if ( text.value.length > 0 )
    {
       if (text.value.length > 0 && (!esEntero( text.id ) || text.value.length < 7))
       { 
            TelefonoValido = false;
            
            document.getElementById( 'pError' ).className = 'aviso_error';
            document.getElementById( text.id.replace( 'txt','lblError' ) ).className='error';
            
            text.className = 'txt error';
            
            if ( text.getAttribute( "contador" ) == "0" )
            {
                text.setAttribute( "contador",'1' );
                ModificarContador( 1 );
            }
       }
              
    }
    else
    {
        TelefonoValido=false;
        
        document.getElementById( 'pError' ).className = 'aviso_error';
        document.getElementById(text.id.replace( 'txt', 'lblError' ) ).className = 'error';
        
        text.className='txt error';
        
        if ( text.getAttribute( "contador" ) == "0" )
        {
            text.setAttribute( "contador", '1' );
            ModificarContador( 1 );
        }
        
    }
       
    
    if ( text.getAttribute("contador") == "1" && TelefonoValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }

    if ( ObtenerContador( ) == 0 )
        document.getElementById( 'pError' ).className = 'oculto';

   return TelefonoValido;
}

function VipValidarTelefonoString(text)
{
   var TelefonoValido=true;
   document.getElementById(text.id.replace('txt','lblError')).className='oculto'; 
   text.className='';
   
   if ( text.value.length < 9 ||
        !esEntero(text.id) )
   { 
        TelefonoValido=false;
        document.getElementById('UcFormularioDatosPersonales1_pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContadorVip(1);
        }
   } 
   
    if (text.getAttribute("contador")=="1" && TelefonoValido)
    {
        ModificarContadorVip(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContadorVip()==0)
        document.getElementById('UcFormularioDatosPersonales1_pError').className='oculto';
   
   return TelefonoValido; 
}

function ValidarTelefonoStringProcesoCompraSinObligatoriedad(text)
{
    TelefonoValido=true;
    document.getElementById(text.id.replace('txt','lblError')).className='oculto'; 
    text.className='';
   
   if ( text.value.length > 0 )
   {
       if ( text.value.length < 9 ||
            !esEntero(text.id) )
       { 
            TelefonoValido=false;
            document.getElementById('pError').className='aviso_error';
            document.getElementById(text.id.replace('txt','lblError')).className='error';
            text.className='error';
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContador(1);
            }
       } 
   }
   
   if (text.getAttribute("contador")=="0")
   {
       text.setAttribute("contador",'1');
       ModificarContador(1);
   }
   
   return TelefonoValido; 
}

function ValidarTelefonoStringProcesoCompra(text)
{
    TelefonoValido=true;
    document.getElementById(text.id.replace('txt','lblError')).className='oculto'; 
    text.className='';
   
   if ( text.value.length < 9 ||
        !esEntero(text.id) )
   { 
        TelefonoValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
   } 
   
    if (text.getAttribute("contador")=="0")
    {
        text.setAttribute("contador",'1');
        ModificarContador(1);
    }
   
   return TelefonoValido; 
}

function ValidarTelefonoProcesoCompra (text,text2)
{
    TelefonoValido=true;
    TelefonoValido2=true;
    document.getElementById(text.id.replace('txt','lblError')).className='oculto'; 
    document.getElementById(text2.id.replace('txt','lblError')).className='oculto';
    text.className='';
    text2.className='';
    if (text.value.length>0 || text2.value.length>0)
    {
       if (text.value.length>0 && (!esEntero(text.id) || text.value.length<7))
       { 
        TelefonoValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
       if (text2.value.length>0 && (!esEntero(text2.id) || text2.value.length<7))
       { 
        TelefonoValido2=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text2.id.replace('txt','lblError')).className='error';
        text2.className='error';
        if (text2.getAttribute("contador")=="0")
        {
            text2.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
    }
    else
    {
        TelefonoValido=false;
        TelefonoValido2=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        document.getElementById(text2.id.replace('txt','lblError')).className='error';
        text.className='error';
        text2.className='error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
        if (text2.getAttribute("contador")=="0")
        {
            text2.setAttribute("contador",'1');
            ModificarContador(1);
        }
    }
       

    if (text.getAttribute("contador")=="1" && TelefonoValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (text2.getAttribute("contador")=="1" && TelefonoValido2)
    {
        ModificarContador(-1);
        text2.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return TelefonoValido&&TelefonoValido2;
}

function LimitarCaracteresSoloNumeros( obj, e ) 
{ 
    //Para IE
    if ( e.which == null || e.which == "undefined" )
        var ultimoCaracter = e.keyCode;
    //Para FireFox
    else
        var ultimoCaracter = e.which;
       
    if ( (ultimoCaracter >=48 && ultimoCaracter <=57) || (ultimoCaracter==0) || (ultimoCaracter==8))   
        return true;
    else
        return false;
          
}

function LimitarCaracteresSoloLetras( obj, e ) 
{ 
    //Para IE
    if ( e.which == null || e.which == "undefined" )
        var ultimoCaracter = e.keyCode;
    //Para FireFox
    else
        var ultimoCaracter = e.which;
    
    
    if ( (ultimoCaracter < 48 || ultimoCaracter > 57))   
        return true;
    else
        return false;
        
    
}

function ModificarContador( valor )
{ 
    document.getElementById( 'hdnContadorErrores' ).value = parseInt(document.getElementById( 'hdnContadorErrores' ).value) + parseInt(valor);
    if (parseInt(document.getElementById( 'hdnContadorErrores' ).value)==-1)
        document.getElementById( 'hdnContadorErrores' ).value="0";
}

function ModificarContadorVip( valor )
{ 
    document.getElementById( 'UcFormularioDatosPersonales1_hdnContadorErrores' ).value = parseInt(document.getElementById( 'UcFormularioDatosPersonales1_hdnContadorErrores' ).value) + parseInt(valor);
    if (parseInt(document.getElementById( 'UcFormularioDatosPersonales1_hdnContadorErrores' ).value)==-1)
        document.getElementById( 'UcFormularioDatosPersonales1_hdnContadorErrores' ).value="0";
}

function ObtenerContador( )
{
    return parseInt(document.getElementById( 'hdnContadorErrores' ).value);
}

function ObtenerContadorVip( )
{
    return parseInt(document.getElementById( 'UcFormularioDatosPersonales1_hdnContadorErrores' ).value);
}

function esNifNie(nifNie)
{
    var lEsValido=true;
    
    //Vemos si es un dni o un nie:
    //Comprobamos si es un dni normal o un nie:
    if (nifNie.length > 0 && (nifNie.substring(0, 1).toUpperCase() == "X" ||
                           nifNie.substring(0, 1).toUpperCase() == "Y" ||
                           nifNie.substring(0, 1).toUpperCase() == "Z"))
    {
        lEsValido = esNie(nifNie);
    }
    else
    {
        lEsValido = esNif(nifNie);
    
    }
   
    return lEsValido;
}

function esNif (nif)
{
   var dniValido=true;
   
   if ( nif.length > 0   &&  nif.length < 10 )
   {
    abc=nif;
    dni=abc.substring(0,abc.length-1);
    let=abc.charAt(abc.length-1);

    if (!isNaN(let))
    {
        dniValido=false;
    }
    else
    {
      cadena="TRWAGMYFPDXBNJZSQVHLCKET";
      posicion = dni % 23;
      letra = cadena.substring(posicion,posicion+1);
      if (letra!=let.toUpperCase())
      {
        dniValido=false;
      }
    }
    }
    else
    {
     dniValido = false;
    }
 return dniValido;

}

function esNie (nie)
{

   var lValido = true;
   
    if (( nie.length > 0   &&  nie.length < 10 )
        && 
        (nie.substring(0, 1).toUpperCase() == "X" ||
         nie.substring(0, 1).toUpperCase() == "Y" ||
         nie.substring(0, 1).toUpperCase() == "Z") )
    {
  
           if (nie.substring(0, 1).toUpperCase() == "X")
           {
                lValido = esNif(nie.substring(1, nie.length));
           }
           else
           {
                if (isNumeric(nie.substring(1, nie.length - 1)))
                {
                    //var nNie = parseInt(nie.substring(1, nie.length - 1));
                    
                    if (nie.substring(0, 1).toUpperCase() == "Y")
                    {
                      //Reemplazamos la letra inicial por 1
                      nie = "1"+nie.substring(1, nie.length);
                    }
                    else 
                    {
                        if (nie.substring(0, 1).toUpperCase() == "Z")
                        {
                          //Reemplazamos la letra inicial por 2
                         nie ="2" + nie.substring(1, nie.length);
                        }
                                    
                    }
                   
                   
                   lValido = esNif(nie);
                    
                      
                }
                else
                {
                 lValido= false;
                }
                
                
               
                
           }    
   
   }
   else
   {
    lValido = false;
   } 
   
   return lValido;
  
}

function VipValidarNifNieCif(text,combo)
{
   var nifNieCifValido=true;
   
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='peq';
   var nTipo = combo.options[combo.selectedIndex].value;

   //if ((EsCif(text.value) && nTipo =="2"  ) || (esNifNie(text.value) && (nTipo=="1" || nTipo=="3")))
   if ( ( nTipo =="2" && EsCif(text.value) ) || 
        ( nTipo =="1" && esNif(text.value) )|| 
        ( nTipo =="3" && esNie(text.value) ) 
      )
   { 
        nifNieCifValido=true;
    }
    else
    {
        nifNieCifValido=false;
        document.getElementById('UcFormularioDatosPersonales1_pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='peq error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContadorVip(1);
        }
    }
        
    if (text.getAttribute("contador")=="1" && nifNieCifValido)
    {
        ModificarContadorVip(-1);
        text.setAttribute("contador",'0');   
    }
    if (ObtenerContadorVip()==0)
        document.getElementById('UcFormularioDatosPersonales1_pError').className='oculto';
        
   return nifNieCifValido 
}

function ValidarNifNieProcesoCompra(text,tipoDocumento)
{
    
    var lValidaCampo;
    var documento = tipoDocumento[tipoDocumento.selectedIndex].value;
    
    if (documento == '1')
        lValidaCampo=ValidarNifProcesoCompra(text);
    else
        lValidaCampo=ValidarNifExtranjeroProcesoCompra(text);

    return lValidaCampo;
}

function ValidarNifExtranjeroProcesoCompra(text)
{
 
   var nie=text.value;
   var antiguoValor = nie;
   var NieValido = true;
   
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='peq';
   
    if (!esNie(text.value))
       { 
        NieValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='peq error';
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContador(1);
            }
        }
   
    if (text.getAttribute("contador")=="1" && NieValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');   
    }
    
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';
   
   return NieValido;


}


function EsCif(texto)
{ 
         
        var pares = 0; 
        var impares = 0; 
        var suma; 
        var ultima; 
        var unumero; 
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I"); 
        var xxx; 
         
        texto = texto.toUpperCase(); 
         
        var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g); 
         if (!regular.exec(texto)) 
            return false; 
              
         ultima = texto.substr(8,1); 

         for (var cont = 1 ; cont < 7 ; cont ++)
         { 
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0"; 
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1)); 
             pares += parseInt(texto.substr(cont,1)); 
         } 
         xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0"; 
         impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1)); 
          
         suma = (pares + impares).toString(); 
         unumero = parseInt(suma.substr(suma.length - 1, 1)); 
         unumero = (10 - unumero).toString(); 
         if(unumero == 10) 
            unumero = 0; 
          
         if ((ultima == unumero) || (ultima == uletra[unumero])) 
             return true; 
         else 
             return false; 

    } 


function ValidarCifProcesoCompra(text)
{
   CifValido=true;
   
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='peq';


    if (!EsCif(text.value))
       { 
        CifValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='peq error';
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContador(1);
            }
        }
    if (text.getAttribute("contador")=="1" && CifValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');   
    }
   if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';
        
   return CifValido 
}

function ValidarNifProcesoCompra(text)
{       
    
    document.getElementById(text.id.replace('txt','lblError')).className='oculto';
    dniValido=true;
    text.className='peq';
    abc=text.value;
    dni=abc.substring(0,abc.length-1);
    let=abc.charAt(abc.length-1);

        if (!isNaN(let))
        {
            document.getElementById('pError').className='aviso_error';
            document.getElementById(text.id.replace('txt','lblError')).className='error';
            text.className='peq error';
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContador(1);
            }
            dniValido=false;
        }
        else
        {
          cadena="TRWAGMYFPDXBNJZSQVHLCKET";
          posicion = dni % 23;
          letra = cadena.substring(posicion,posicion+1);
          if (letra!=let.toUpperCase())
          {
                document.getElementById('pError').className='aviso_error';
                document.getElementById(text.id.replace('txt','lblError')).className='error';
                text.className='peq error';
                if (text.getAttribute("contador")=="0")
                {
                    text.setAttribute("contador",'1');
                    ModificarContador(1);
                }
                dniValido=false;
          }
        }
    
    if (text.getAttribute("contador")=="1" && dniValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';
 return dniValido;
}

function ValidarNif(text)
{
MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),true);
abc=text.value;
dni=abc.substring(0,abc.length-1);
let=abc.charAt(abc.length-1);
if (text.value.length>0)
{
    if (!isNaN(let))
     {
        MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),false);
        return false;
     }
    else
     {
      cadena="TRWAGMYFPDXBNJZSQVHLCKET";
      posicion = dni % 23;
      letra = cadena.substring(posicion,posicion+1);
      if (letra!=let.toUpperCase())
       {
            MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),false);
            return false;
       }
     }
 }
 return true;
}
function activarCapa(parametro1, parametro2)
{

 document.getElementById(parametro1).className="velo_iframe2";
 document.getElementById(parametro2).className="contenedor_iframe";
 
 }

function MostrarOcultarConyuge(Combo,Conyuge)
{
    var conyuge = document.getElementById( Conyuge );
    alert(Conyuge);
    alert(document.getElementById( Conyuge ));
//    if (Combo[Combo.selectedIndex].value=='2')
//    {
//        conyuge.style.visibility='inline';
//    }
//    else
//    {
//        conyuge.style.visibility='none';
//    }
}

//Funcion para cambiar el target del form donde esta metido el user control
/*function cambiaTarget ()
{
    //Cambiamos el target de la pagina donde esta el metido el uc
    //Abrimos una ventana nueva
    alert( document.forms[1].id );
    document.forms[1].target="_blank"; 
    //document.forms[0].action = "http://localhost/gestorform/recibeform.aspx";
    document.forms[1].action = "http://localhost:1701/web/default2.aspx";
    document.forms[1].submit();
    //volvemos a cambiar el action del formulario
    document.forms[1].action = "";
    //volvemos a cambiar el target:
    document.forms[1].target="";
    alert("hecho");

}*/

//Funcion a la que se pasa una cadena con la fecha y se valida para comprobar que es correcta.
function esFecha(fecha)
{
    var caja=fecha;
	if (caja!='')
	{  
	    var borrar = '';
		if ((caja.substr(2,1) == '/') && (caja.substr(5,1) == '/'))
		{      
			for (i=0; i<10; i++)
			{	
				if (((caja.substr(i,1)<'0') || (caja.substr(i,1)>'9')) && (i != 2) && (i != 5))
				{
					borrar = '/'; 
				}  
			}
			if (caja.length>10)
			{
			    borrar='/';
			}   
			if (borrar!='/')
			{ 
	    		a = caja.substr(6,4);
		    	m = caja.substr(3,2);
				d = caja.substr(0,2);
				if ((m < parseInt('1')) || (m > parseInt('12')) || (d < parseInt('1')) || (d > parseInt('31')) || a < parseInt('1900') )
				{
					borrar = '/';
				}
				else
				{
				    if((a%4 != 0) && (m == 2) && (d > 28))
					{
						borrar = '/';
					}
					else	
					{
					    if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
						{
						    borrar = '/';
						}
					}
				}
			} 
		} 		    			
		else
		{
		    borrar = '/';
		}
	}
	else
	{
	    borrar='/';
	}
	if (borrar == '/')
		return false;
	else
	{
	    return true;
	}
}

function ValidarNifExtranjero(text)
{
    NifExtranjeroValido=true;
    MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),true); 
   if (text.value.length>0)
   {
       if (text.value.substring(0,1)!='x' && text.value.substring(0,1)!='X')
       {
            NifExtranjeroValido=false;
            MostrarMensajeIncorrecto(text.id.replace('txt','lblError'),false);
       }
       else
       {
            var sAnterior=text.value;
            text.value=text.value.replace('x','0').replace('X','0');
            ValidarNif(text);
            text.value=sAnterior;
       }
   } 
   return NifExtranjeroValido 
}

function imprimir()
    {
        window.print();
    }

	function agregarFavoritos()
	{
	    var url = window.location;
	    var titulo = "METROVACESA";
	    
	   // alert(url);
	    
//	    if (document.all) 
//	        window.external.AddFavorite(url,titulo)
	    if (window.sidebar) 
	    { // Mozilla Firefox 
		    window.sidebar.addPanel(titulo, url,"");
	    } 
	    else if( window.external ) 
	    { // IE 
		    window.external.AddFavorite( url, titulo); 
		}
	    else if(window.opera && window.print) 
	    { // Opera
		    return true; 
		}
	}
	
	
// Control Clase de ejecución de archivos ShockWave Flash
// (c)2006 The Mad Pixel Factory --- http://www.madpixel.es

obj_swf=function(){
	this.salida_div=false
	this.trace=false
	this.codificarFlashVars=false
}
obj_swf.prototype.FNtrace=function(){
	this.trace=true
	return true
}
obj_swf.prototype.FNcodificarFlashVars=function(){
	this.codificarFlashVars=true
	return true
}
obj_swf.prototype.FNid_salida=function(p_id_salida){
	if(typeof(p_id_salida)!="undefined"){
		if(document.getElementById(p_id_salida)){
			this.salida_div=true
			this.obj_div=document.getElementById(p_id_salida)
		}
	}
}
obj_swf.prototype.FNborrar=function(){
	delete this
}
obj_swf.prototype.FNgfx_swf=function(){
	//Comprueba parametros básicos
	if(typeof(this.classid)=='undefined'){this.classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'}
	if(typeof(this.codebase)=='undefined'){this.codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'}
	if(typeof(this.quality)=='undefined'){this.quality='high'}
	if(typeof(this.type)=='undefined'){this.type='application/x-shockwave-flash'}
	if(typeof(this.pluginspage)=='undefined'){this.pluginspage='http://www.macromedia.com/go/getflashplayer'}
	if(typeof(this.swliveconnect)=='undefined'){this.swliveconnect="true"}
	if(typeof(this.allowscriptaccess)=='undefined'){this.allowscriptaccess="true"}
	if(typeof(this.id)=='undefined'){var nId=Math.round(Math.random()*100);this.id='swf'+nId}
	//--
	//Crea arrays de contenido
	this.a_object_propios=new Array()
	this.a_comunes=new Array()
	this.a_object_variables=new Array()
	this.a_embed_propios=new Array()
	this.a_embed_variables=new Array()
	//--
	
	//Revisa contenido adquirido
	for(parametros in this){
		var cNomParametro=parametros.toLowerCase()
		var cValorParametro=eval("this."+parametros)
		if(typeof(cValorParametro)=="string"){
			switch (cNomParametro){
				case "classid":
				case "codebase":
				case "onafterupdate":
				case "onbeforeupdate":
				case "onblur":
				case "oncellchange":
				case "onclick":
				case "ondblClick":
				case "ondrag":
				case "ondragend":
				case "ondragenter":
				case "ondragleave":
				case "ondragover":
				case "ondrop":
				case "onfinish":
				case "onfocus":
				case "onhelp":
				case "onmousedown":
				case "onmouseup":
				case "onmouseover":
				case "onmousemove":
				case "onmouseout":
				case "onkeypress":
				case "onkeydown":
				case "onkeyup":
				case "onload":
				case "onlosecapture":
				case "onpropertychange":
				case "onreadystatechange":
				case "onrowsdelete":
				case "onrowenter":
				case "onrowexit":
				case "onrowsinserted":
				case "onstart":
				case "onscroll":
				case "onbeforeeditfocus":
				case "onactivate":
				case "onbeforedeactivate":
				case "ondeactivate":
				case "type":
					this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "width":
				case "height":
				case "align":
					this.a_comunes.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "type":
				case "pluginspage":
				case "allowscriptaccess":
				case "width":
				case "height":
				case "align":
				case "vspace": 
				
				case "play": 
				case "menu":
				case "loop":
				
				case "hspace":
				case "class":
				case "title":
				
				case "salign":
				case "scale":
				case "allowFullScreen":
				
				case "devicefont":
				case "accesskey":
				case "swliveconnect":
				case "tabindex":
					this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "id":
//					this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					this.a_object_propios.push( 'name'+'="'+cValorParametro+'"'  )
					this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					this.a_embed_propios.push('name'+'="'+cValorParametro+'"' )
					break;
				case "movie":
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_propios.push('src'+'="'+cValorParametro+'"' )
					break;
				case "flashvars":
					//Revision el contenido de FlashVars para evitar problemas de comillas y caracteres especiales
					if(cValorParametro.indexOf('"')!=-1 || cValorParametro.indexOf("'")!=-1 || this.codificarFlashVars){
						//cValorParametro=escape(cValorParametro)
					}
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
					//--
					break;
				default :
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
	
			}
		}
	}
	//--
	
	this.a_object_propios=this.a_object_propios.join(" ")
	this.a_comunes=this.a_comunes.join(" ")
	this.a_embed_propios=this.a_embed_propios.join(" ")
	this.a_object_variables=this.a_object_variables.join("\n")
	this.a_embed_variables=this.a_embed_variables.join(" ")
	
	
	//Genera salida
	cad=''
	cad+=('<object '+this.a_object_propios+' '+this.a_comunes+' >'+'\n')
	cad+=(''+this.a_object_variables +'\n')
	cad+=('<embed '+this.a_embed_propios+' '+this.a_comunes+' '+this.a_embed_variables+'></embed>'+'\n')
	cad+=('</object>'+'\n')
	
	if(this.salida_div){
		this.obj_div.innerHTML=cad //Salida a etiqueta ID
	}else{
		document.write(cad) //Escritura directa sobre HTML
	}
	//--
	
	if(this.trace){alert(cad)}
	
}

//Funcion de modificación de alto del un archivo swf identificado con una ID
FNcambioAltoSWF=function(p_id,p_alto){
	document.getElementById(p_id).height=p_alto
//	document.getElementById(p_id).width=762
}
//--

function RegistrarVisita()
{
    alert('Prueba');
}
function CambiarRutaAsistente( codigo )
{
    //Establecemos la nueva ruta
    document.getElementById('frmAsistente').src = "http://customer2.q-go.net/metrovacesa/index.php?catid=" + codigo 
}


 function CambiarRutaAsistentePromocion()
   {
    if (document.getElementById('divListaEspera')!=null) 
    CambiarRutaAsistente( 18 )
    else
    CambiarRutaAsistente( 16 )
   }

//Funcione encargada de comprobar el tipo de usuario a validar. Sino encuentra la @ se le
//mandara a una página distinta

function comprobarTipoUsuario( usuario, portal )
{
    if (usuario.value.indexOf('@')>-1 || usuario.value.length==0)
    {
        return true;
    }
    else
    {
        FNpopup('https://portal.metrovacesa.es','popUpPortalMetrovacesa','1100','750','scrollbars=yes');
        return false;
    }
}



//Control Clase de ejecución de archivos ShockWave Flash
// (c)2006 The Mad Pixel Factory --- http://www.madpixel.es

obj_swf=function(){
        this.salida_div=false
        this.trace=false
        this.codificarFlashVars=false
        this.a_FlashVars=new Array()
}
obj_swf.prototype.FNtrace=function(){
        this.trace=true
        return true
}
obj_swf.prototype.FNcodificarFlashVars=function(){
        this.codificarFlashVars=true
        return true
}
obj_swf.prototype.FNid_salida=function(p_id_salida){
        if(typeof(p_id_salida)!="undefined"){
                if(document.getElementById(p_id_salida)){
                        this.salida_div=true
                        this.obj_div=document.getElementById(p_id_salida)
                }
        }
}
obj_swf.prototype.FNborrar=function(){
        delete this
}
obj_swf.prototype.FNflashvars=function(p_cad){
        this.a_FlashVars.push(p_cad);
        return true
}
obj_swf.prototype.FNgfx_swf=function(){
        //Comprueba parametros básicos
        if(typeof(this.classid)=='undefined'){this.classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'}
        if(typeof(this.codebase)=='undefined'){this.codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'}
        if(typeof(this.quality)=='undefined'){this.quality='high'}
        if(typeof(this.type)=='undefined'){this.type='application/x-shockwave-flash'}
        if(typeof(this.pluginspage)=='undefined'){this.pluginspage='http://www.macromedia.com/go/getflashplayer'}
        if(typeof(this.swliveconnect)=='undefined'){this.swliveconnect="true"}
        if(typeof(this.allowscriptaccess)=='undefined'){this.allowscriptaccess="true"}
        if(typeof(this.id)=='undefined'){var nId=Math.round(Math.random()*100);this.id='swf'+nId}
        //--
        //Crea arrays de contenido
        this.a_object_propios=new Array()
        this.a_comunes=new Array()
        this.a_object_variables=new Array()
        this.a_embed_propios=new Array()
        this.a_embed_variables=new Array()
        //--
        //Comprueba que no hay array de FlashVars - de lo contrario sobreescribe la variable flashvars
                if(this.a_FlashVars.length>0){
                        if(this.codificarFlashVars){
                                r=0;while(this.a_FlashVars[r]){
                                        var v_variable=this.a_FlashVars[r].split("=")[0]
                                        var v_valor=this.a_FlashVars[r].split("=")[1]
//                                        this.a_FlashVars[r]=v_variable+"="+escape(v_valor)
                                        this.a_FlashVars[r]=v_variable+"="+v_valor
                                        r++
                                }
                        }
                        this.flashvars=this.a_FlashVars.join("&")
                        
                }
        //--
        //Revisa contenido adquirido
        for(parametros in this){
                var cNomParametro=parametros.toLowerCase()
                var cValorParametro=eval("this."+parametros)
                if(typeof(cValorParametro)=="string"){
                        switch (cNomParametro){
                                case "classid":
                                case "codebase":
                                case "onafterupdate":
                                case "onbeforeupdate":
                                case "onblur":
                                case "oncellchange":
                                case "onclick":
                                case "ondblClick":
                                case "ondrag":
                                case "ondragend":
                                case "ondragenter":
                                case "ondragleave":
                                case "ondragover":
                                case "ondrop":
                                case "onfinish":
                                case "onfocus":


                                case "onhelp":
                                case "onmousedown":
                                case "onmouseup":
                                case "onmouseover":
                                case "onmousemove":
                                case "onmouseout":
                                case "onkeypress":
                                case "onkeydown":
                                case "onkeyup":
                                case "onload":
                                case "onlosecapture":
                                case "onpropertychange":
                                case "onreadystatechange":
                                case "onrowsdelete":
                                case "onrowenter":
                                case "onrowexit":
                                case "onrowsinserted":
                                case "onstart":
                                case "onscroll":
                                case "onbeforeeditfocus":
                                case "onactivate":
                                case "onbeforedeactivate":
                                case "ondeactivate":
                                case "type":
                                        this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
                                case "width":
                                case "height":
                                case "align":
                                        this.a_comunes.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
                                case "type":
                                case "pluginspage":
                                case "allowscriptaccess":
                                case "width":
                                case "height":
                                case "align":
                                case "vspace":
                                case "hspace":
                                case "class":
                                case "title":
                                case "accesskey":
                                case "swliveconnect":
                                case "tabindex":
                                        this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
                                case "id":
//                                      this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        this.a_object_propios.push( 'name'+'="'+cValorParametro+'"'  )
                                        this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        this.a_embed_propios.push('name'+'="'+cValorParametro+'"' )
                                        break;
                                case "movie":
                                        this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
                                        this.a_embed_propios.push('src'+'="'+cValorParametro+'"' )
                                        break;
                                case "flashvars":
                                        //Revision el contenido de FlashVars para evitar problemas de comillas y caracteres especiales
//                                      if(cValorParametro.indexOf('"')!=-1 || cValorParametro.indexOf("'")!=-1){
                                        if(cValorParametro.indexOf('"')!=-1){
                                                a_cValorParametro=cValorParametro.split('"').join('\'')
                                                cValorParametro=a_cValorParametro
                                                //cValorParametro=escape(cValorParametro)
                                        }
                                        this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
                                        this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
                                        //--
                                        break;
                                default :
                                        this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
                                        this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
        
                        }
                }
        }
        //--
        
        this.a_object_propios=this.a_object_propios.join(" ")
        this.a_comunes=this.a_comunes.join(" ")
        this.a_embed_propios=this.a_embed_propios.join(" ")
        this.a_object_variables=this.a_object_variables.join("\n")
        this.a_embed_variables=this.a_embed_variables.join(" ")
        
        
        //Genera salida
        cad=''
        cad+=('<object '+this.a_object_propios+' '+this.a_comunes+' >'+'\n')
        cad+=(''+this.a_object_variables +'\n')
        cad+=('<embed '+this.a_embed_propios+' '+this.a_comunes+' '+this.a_embed_variables+'></embed>'+'\n')
        cad+=('</object>'+'\n')
        
        if(this.salida_div){
                this.obj_div.innerHTML=cad //Salida a etiqueta ID
        }else{
                document.write(cad) //escritura directa sobre HTML
        }
        //--
        
        if(this.trace){alert(cad)}
        
}

function imprimirRecibo(){

//Cambiamos la visibilidad de los link de imprimir:
document.getElementById("lnkImprimirSuperior").style.visibility="hidden";
document.getElementById("lnkImprimirInferior").style.visibility="hidden";

window.print();

//Visualizamos
document.getElementById("lnkImprimirSuperior").style.visibility= "visible";
document.getElementById("lnkImprimirInferior").style.visibility= "visible";

}


function validacionFormaPagoHipoteca ()
{
    var esValido=true;
    
    if (document.getElementById('txtRazonAtrasarPagos') != null)
    {

        if ( document.getElementById('txtRazonAtrasarPagos').value.length==0)
            esValido=false;
            
        if (!esValido)
        {
            document.getElementById('lblErrorAtrasarPagos').className='error_formapago';
            document.getElementById('txtRazonAtrasarPagos').focus();
        }
        else
            document.getElementById('lblErrorAtrasarPagos').className='oculto';
    }
        
    return esValido;
}

function ValidarFormaPago()
{
    var contrato=document.getElementById('UcFormaPagoVip1_txtContrato');
    var recibos=document.getElementById('UcFormaPagoVip1_txtRecibos');
    var llaves=document.getElementById('UcFormaPagoVip1_txtLlaves');
    var esValido=true;
    
        
//    if (parseInt(contrato.value) + parseInt(recibos.value) < 10)
//    {
//        esValido=false;
//        document.getElementById('pErrorPorcentajes').innerHTML='Los pagos a la firma y en recibos mensuales deben sumar al menos 10%';
//    }
    if (esEntero(contrato.id) && esEntero(recibos.id) && esEntero(llaves.id))
    {
        if (parseInt(contrato.value) + parseInt(recibos.value) + parseInt(llaves.value) > 100)
        {
            esValido=false;
            document.getElementById('UcFormaPagoVip1_pErrorPorcentajes').innerHTML='La suma de los porcentajes debe ser 100%';
        }
    }
    else
    {
        esValido = false;
        document.getElementById('UcFormaPagoVip1_pErrorPorcentajes').innerHTML='Los porcentajes introducidos deben ser num&eacute;ricos';
    }
        
    if (!esValido)
        document.getElementById('UcFormaPagoVip1_pErrorPorcentajes').className='error_formapago';
    else
        document.getElementById('UcFormaPagoVip1_pErrorPorcentajes').className='oculto';
        
    return esValido;
        
}

function OcultarVelo(velo)
{
    velo.className='oculto';
}

//Funcion que comprueba si el contenido de un campo es numérico
	/*Params:
	    campo:combo a validar si su contenido es numérico
	 */
function esNumerico (Campo)
{
        var cCampo = document.getElementById( Campo );
        if (!isNumeric(cCampo.value))
        {
            cCampo.focus();
            return false;
        }
        else
        {
            return true;
        }
         
}

function ejecutarScriptEstadisticas(pagina,id,clase)
{
    try
    {
        dcsMultiTrack('DCS.dcsuri',pagina);
        pageTracker._trackPageview(pagina);
    }
    catch(err)
    {
        var aa=err;
    }
    
    CambiaClase(id,clase);
}

function ValidarAnios(text)
{
   AniosValido=true;    

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='txt';
    
    //|| parseInt( text.value , 0 )>35
   if (text.value.length==0 || !esEntero(text.id)  )
   { 
    AniosValido=false;
    document.getElementById('pError').className='aviso_error';
    document.getElementById(text.id.replace('txt','lblError')).className='error';
    text.className='txt error';
    if (text.getAttribute("contador")=="0")
    {
        text.setAttribute("contador",'1');
        ModificarContador(1);
    }
   } 
    
    if (text.getAttribute("contador")=="1" && AniosValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return AniosValido 
}

function ValidarIngresos(text)
{
   IngresosValido=true;    
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='txt';
    
   if (text.value.length==0 || !esNumero(text.id) )
   { 
    IngresosValido=false;
    document.getElementById('pError').className='aviso_error';
    document.getElementById(text.id.replace('txt','lblError')).className='error';
    text.className='txt error';
    if (text.getAttribute("contador")=="0")
    {
        text.setAttribute("contador",'1');
        ModificarContador(1);
    }
   } 
    
    if (text.getAttribute("contador")=="1" && IngresosValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return IngresosValido 
}


function EstaRellenoFormularioInscripcion(text)
{
  EstaRelleno = false;    
   
    if (text.value.length==0)
    {
        EstaRelleno=false;
        if (document.getElementById(text.id).className.indexOf("error")<0)
            document.getElementById(text.id).className += " error";
        
    } 
    else
    {
        document.getElementById(text.id).className = document.getElementById(text.id).className.replace(" error", "");
        
        EstaRelleno=true;
    }

   return EstaRelleno 
}

function ValidarCorreoFormularioInscripcion(text)
{
   MailValido=true;
   
  if (!esMail(text.id))
  { 
     MailValido=false;
     if (document.getElementById(text.id).className.indexOf("error")<0)
            document.getElementById(text.id).className += " error";
  
  }
  else
  {
    MailValido=true;
    document.getElementById(text.id).className = document.getElementById(text.id).className.replace(" error", "");
  }
          
   return MailValido 
} 

 function EstaRellenoFormularioInscripcionCombo(combo, lblError)
    {
      EstaRelleno = false;    
      
        if (combo.selectedIndex==0)
        {
            EstaRelleno=false;
            //Mostramos el label de error:
            document.getElementById(lblError.id).style.visibility= "visible";
            
        } 
        else
        {
            EstaRelleno=true;
            //Mostramos el label de error:
            document.getElementById(lblError.id).style.visibility= "hidden";
        }

       return EstaRelleno 
    }
    
    function ValidarPrescoring()
    {
        var ValidadoPC=true;
        var lValidaCampo;
    
        lValidaCampo=ValidarAnios(document.getElementById('txtPlazoAnios'));
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        lValidaCampo=ValidarIngresos(document.getElementById('txtIngresosNetos'),true);
        ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
        //Comprobamos que sea correcto para lanzar la capa de velo:
        if (ValidadoPC)
        {   
            MostrarCapaCargandoVelo(); 
            MostrarCapaCargandoImagen();
        }
    
        return ValidadoPC;
    }
    
    function ValidarScoringDatosPersonales()
    {
        var correcto = true;
        var lValidaCampo;
        
        //Primero nos aseguramos de que todos los campos estén rellenos
        lValidaCampo = EstaRellenoScoring ( document.getElementById( 'txtDireccion' ) );
               
        lValidaCampo = EstaRellenoScoring ( document.getElementById( 'txtNum' ) );
        correcto = correcto == true ? lValidaCampo : correcto;
        
        lValidaCampo = EstaRellenoScoring ( document.getElementById( 'txtLocalidad' ) );
        correcto = correcto == true ? lValidaCampo : correcto;
                
        //Hacemos otras validaciones
        lValidaCampo = ValidarCpScoring( document.getElementById( 'txtCodigoPostal' ) );
        correcto = correcto == true ? lValidaCampo : correcto;
        
        lValidaCampo = ValidarTelefonoMovilScoring( document.getElementById( 'txtMovil' ) );
        correcto = correcto == true ? lValidaCampo : correcto;
        
        //Validamos el chk de condiciones:
        if (document.getElementById('chkAcepto').checked)
        {
            correcto = correcto;
        }
        else
        {
        //Mostramos error:
         correcto=false;
         document.getElementById('pErrorAcepto').className='aviso_error';
        }
        
        correcto = correcto == true ? document.getElementById('chkAcepto').checked : correcto;
        
        if (correcto)
        { 
            MostrarCapaCargandoVelo();        
            MostrarCapaCargandoImagen();    
        }
        
                   
        return correcto;
    }
    
    function ValidarScoringDatosEconomicos( )
    {
        var ValidadoPC=true;
        var lValidaCampo;
        
        var titulares= document.getElementById('ddlNumTitulares');
        
        var numTitulares = titulares[titulares.selectedIndex].value;
        
        for (var i=1;i<=numTitulares;i++)
        {
            lValidaCampo=ValidarIngresos(document.getElementById('txtIngresosNetos' + i),true);
            ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
            
            lValidaCampo=ValidarIngresos(document.getElementById('txtGastosMensuales' + i),true);
            ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
            
            lValidaCampo=ValidarIngresos(document.getElementById('txtGastosAlquiler' + i),true);
            ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
        
            lValidaCampo=ValidarAnios(document.getElementById('txtNumPagas' + i));
            ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

            lValidaCampo=ValidarAnios(document.getElementById('txtUnidadFamiliar' + i));
            ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;  
            
            if (i>1)
            {
                lValidaCampo=ValidarFechaScoring(document.getElementById('txtFechaNac' + i));
                ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;  
                
            }          

        }
        
       //Comprobamos que sea correcto para lanzar la capa de velo:
       if(ValidadoPC)
       {
            MostrarCapaCargandoVelo(); 
            MostrarCapaCargandoImagen();
       }
        
        return ValidadoPC;
    }
    
    function EstaRellenoScoring(text)
{
    EstaRelleno=true; 

    document.getElementById(text.id.replace('txt','lblError')).className='oculto';
    text.className='txt';
   
    //si no tiene 5 caracteres no es válido 
    if (text.value.length==0)
    {
        EstaRelleno=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='txt error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
    } 
    if (text.getAttribute("contador")=="1" && EstaRelleno)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return EstaRelleno 
}

function ValidarCpScoring(text)
{
    
   CPValido=true; 

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='txt';
   
       if (!esEntero(text.id) || text.value.length!=5)
       { 
        CPValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='txt error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
    
    if (text.getAttribute("contador")=="1" && CPValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return CPValido 
}

function MostrarCapaCargando ()
{
    
    document.getElementById('veloCarga').style.visibility="visible";
    //Recorrer los combo para ocultarlos??
    
}

function MostrarCapaCargandoVelo ()
{
    
    document.getElementById('veloCarga').style.display="inline";
    //Recorrer los combo para ocultarlos??
    
}

function MostrarCapaCargandoImagen()
{
    document.getElementById('dvImagenVelo').style.display="inline";
    
}

function ValidarFechaScoring(text)
{


   FechaValida=true;    

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className='txt';
    
    //si no tiene 5 caracteres no es válido 
       if (!esFecha(text.value))
       { 
        FechaValida=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className='txt error';
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       } 
    
    if (text.getAttribute("contador")=="1" && FechaValida)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return FechaValida 
}

function ValidarContacto()
{
    var ValidadoPC=true;
    var lValidaCampo;

    lValidaCampo=EsObligatorio(document.getElementById('txtNombre'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtApellidos'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarTelefono(document.getElementById('txtTelefono'),false,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreo(document.getElementById('txtEmail'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    lValidaCampo=ValidarCp(document.getElementById('txtCp'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
 
    lValidaCampo=EsObligatorio(document.getElementById('txtTexto'),'error','');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    return ValidadoPC;
}

function ValidarContacto7()
{
    var ValidadoPC=true;
    var lValidaCampo;

    lValidaCampo=EsObligatorio(document.getElementById('txtNombre7'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtApellidos7'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarTelefono(document.getElementById('txtTelefono7'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreo(document.getElementById('txtEmail7'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    lValidaCampo=ValidarCp(document.getElementById('txtCp7'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
 
    lValidaCampo=EsObligatorio(document.getElementById('txtTexto7'),'error','');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    return ValidadoPC;
}

function ValidarContacto2()
{
    var ValidadoPC=true;
    var lValidaCampo;

    lValidaCampo=EsObligatorio(document.getElementById('txtNombre2'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtApellidos2'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarTelefonoString(document.getElementById('txtTelefono2'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreoIguales(document.getElementById('txtEmail2'),document.getElementById('txtEmailRepetir2'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    lValidaCampo=ValidarCp(document.getElementById('txtCp2'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
 
    lValidaCampo=EsObligatorio(document.getElementById('txtTexto2'),'error','');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    return ValidadoPC;
}

function ValidarContacto3()
{
    var ValidadoPC=true;
    var lValidaCampo;

    lValidaCampo=EsObligatorio(document.getElementById('txtNombre3'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtApellidos3'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarTelefono(document.getElementById('txtTelefono3'),false,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreo(document.getElementById('txtEmail3'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    lValidaCampo=ValidarCp(document.getElementById('txtCp3'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
 
    lValidaCampo=EsObligatorio(document.getElementById('txtTexto3'),'error','');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarFecha(document.getElementById('txtFechaInteres3'),false,'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsDecimal(document.getElementById('txtSuperficie3'),false,'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    

    return ValidadoPC;
}

function ValidarContacto4()
{
    var ValidadoPC=true;
    var lValidaCampo;

    lValidaCampo=EsObligatorio(document.getElementById('txtNombre4'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtApellidos4'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarTelefono(document.getElementById('txtTelefono4'),false,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreo(document.getElementById('txtEmail4'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    lValidaCampo=ValidarCp(document.getElementById('txtCp4'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
 
    lValidaCampo=EsObligatorio(document.getElementById('txtTexto4'),'error','');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarFecha(document.getElementById('txtFechaInteres4'),false,'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsDecimal(document.getElementById('txtSuperficie4'),false,'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    

    return ValidadoPC;
}

function ValidarContacto5()
{
    var ValidadoPC=true;
    var lValidaCampo;

    lValidaCampo=EsObligatorio(document.getElementById('txtNombre5'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtApellidos5'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtSituacionSuelo5'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtMunicipio5'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtEdificabilidad5'),'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsObligatorio(document.getElementById('txtTexto5'),'error','');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarTelefono(document.getElementById('txtTelefono5'),false,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreo(document.getElementById('txtEmail5'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    lValidaCampo=ValidarCp(document.getElementById('txtCp5'),true,'estrecho error','estrecho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsDecimal(document.getElementById('txtSuperficie5'),true,'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=EsDecimal(document.getElementById('txtPrecioOrientativo5'),true,'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    return ValidadoPC;
}

function ValidarContacto6()
{
    var ValidadoPC=true;
    var lValidaCampo;
 
    lValidaCampo=EsObligatorio(document.getElementById('txtTexto6'),'error','');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;
    
    lValidaCampo=ValidarCorreo(document.getElementById('txtEmail6'),true,'ancho error','ancho');
    ValidadoPC=ValidadoPC==true?lValidaCampo:ValidadoPC;

    return ValidadoPC;
}

function EsObligatorio(text,estilo,estiloNormal)
{
    EstaRelleno=true; 
    document.getElementById(text.id.replace('txt','lblError')).className='oculto';
    text.className=estiloNormal;
   
    //si no tiene 5 caracteres no es válido 
    if (text.value.length==0)
    {
        EstaRelleno=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className=estilo;
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
    } 
    if (text.getAttribute("contador")=="1" && EstaRelleno)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';


   return EstaRelleno 
}

function EsDecimal(text,obligatorio,estilo,estiloNormal)
{
    var esDecimal=true; 
    
    document.getElementById(text.id.replace('txt','lblError')).className='oculto';
    text.className=estiloNormal;
   
    if (obligatorio || text.value.length>0)
   {
    //si no tiene 5 caracteres no es válido 
       if ( !isNumeric(text.value) || (obligatorio && text.value.length==0 ))
       { 
        esDecimal=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className=estilo;
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       } 
    } 
    if (text.getAttribute("contador")=="1" && esDecimal)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return EstaRelleno 
}

function ValidarFecha(text,obligatorio,estilo,estiloNormal)
{

   FechaValida=true;    

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className=estiloNormal;
    
   if (obligatorio || text.value.length>0)
   {
    //si no tiene 5 caracteres no es válido 
       if (!esFecha(text.value))
       { 
        FechaValida=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className=estilo;
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       } 
   } 
    if (text.getAttribute("contador")=="1" && FechaValida)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';

   return FechaValida 
}

function ValidarCorreo(text,obligatorio,estilo,estiloNormal)
{
   MailValido=true;
   
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className=estiloNormal;

   if (obligatorio || text.value.length>0)
   {
    if (!esMail(text.id))
       { 
        MailValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className=estilo;
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContador(1);
            }
        }
    }
    if (text.getAttribute("contador")=="1" && MailValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');   
    }
   if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';
  
   return MailValido 
} 

function ValidarCorreoIguales(text,text2,obligatorio,estilo,estiloNormal)
{
   MailValido=true;
   
   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   document.getElementById(text2.id.replace('txt','lblError')).className='oculto';
   text.className=estiloNormal;
   text2.className=estiloNormal;

   if ( ( obligatorio || text.value.length>0) )
   {
    if (!esMail(text.id) || text.value.toLowerCase()!=text2.value.toLowerCase() )
       { 
        MailValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        document.getElementById(text2.id.replace('txt','lblError')).className='error';
        text.className=estilo;
        text2.className=estilo;
            if (text.getAttribute("contador")=="0")
            {
                text.setAttribute("contador",'1');
                ModificarContador(1);
            }
        }
    }
    if (text.getAttribute("contador")=="1" && MailValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');   
    }
   if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';
   
   return MailValido 
} 

function ValidarTelefono(text,obligatorio,estilo,estiloNormal)
{ 
    TelefonoValido=true;
    document.getElementById(text.id.replace('txt','lblError')).className='oculto'; 
    text.className=estiloNormal;
   
   if (obligatorio || text.value.length>0)
   {
       if (!esEntero(text.id) || text.value.length<7)
       { 
        TelefonoValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className=estilo;
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
   } 
   
    if (text.getAttribute("contador")=="1" && TelefonoValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    
   return TelefonoValido 
}

function ValidarTelefonoString(text,obligatorio,estilo,estiloNormal)
{ 
    TelefonoValido=true;
    document.getElementById(text.id.replace('txt','lblError')).className='oculto'; 
    text.className=estiloNormal;
   
   if (obligatorio || text.value.length>0)
   {
       if (text.value.length<9 ||
           !esEntero(text.id) )
       { 
        TelefonoValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className=estilo;
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
   } 
   
    if (text.getAttribute("contador")=="1" && TelefonoValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    
   return TelefonoValido 
}

function ValidarCp(text,obligatorio,estilo,estiloNormal)
{
    
   CPValido=true; 

   document.getElementById(text.id.replace('txt','lblError')).className='oculto';
   text.className=estiloNormal;
   
   if (obligatorio || text.id.length>0)
   {
       if (!esEntero(text.id) || text.value.length!=5)
       { 
        CPValido=false;
        document.getElementById('pError').className='aviso_error';
        document.getElementById(text.id.replace('txt','lblError')).className='error';
        text.className=estilo;
        if (text.getAttribute("contador")=="0")
        {
            text.setAttribute("contador",'1');
            ModificarContador(1);
        }
       }
    }
    
    if (text.getAttribute("contador")=="1" && CPValido)
    {
        ModificarContador(-1);
        text.setAttribute("contador",'0');
    }
    if (ObtenerContador()==0)
        document.getElementById('pError').className='oculto';
   return CPValido 
}

function CargarGoogleMaps()
{
    if (GBrowserIsCompatible()) 
					{
						//Creación del obeto GMap2 (el mapa)
						var map = new GMap2(document.getElementById("map"));
						//map.addControl(new GLargeMapControl());
						
						//Objeto de  cambio de tipo (satelite, mapa...)
						map.addControl(new GMapTypeControl());
						map.addControl(new GSmallMapControl());

						// Coordenadas en version dos, cambia latitud y longtud. El Zoom cambia tambien.
						map.setCenter(new GLatLng(coordenadaY,coordenadaX), 17 -zoom, G_HYBRID_MAP);

						// Creación de icono
						var icon = new GIcon();
						icon.image = imagen;
						icon.shadow = "./mvs.gif";
						icon.iconSize = new GSize(anchoImagen,altoImagen);
						icon.shadowSize = new GSize(anchoImagen,altoImagen);
						icon.iconAnchor = new GPoint(5, 5);
						icon.infoWindowAnchor = new GPoint(5, 1);
						
						
						
									var icon = new GIcon();
						icon.image = imagen;
						icon.shadow = "./mvs.gif";
						icon.iconSize = new GSize(anchoImagen,altoImagen);
						icon.shadowSize = new GSize(anchoImagen,altoImagen);
						icon.iconAnchor = new GPoint(5, 5);
						icon.infoWindowAnchor = new GPoint(5, 1);
						
						
						
						

						//var marker1 = new GMarker(new GPoint(-3.67266,40.44865),icon);
						var marker1 = new GMarker(new GPoint(coordenadaX,coordenadaY),icon);
						map.addOverlay(marker1);
                    }

}


function CargarGoogleMapsKML(rutaKml)
{
    if (GBrowserIsCompatible()) 
	{
	
	//Definimos el objeto mapa
			var map  = new GMap2(document.getElementById("map")); 
      
              
            //Ańadimos el control de zoom
            map.addControl(new GSmallMapControl());
            
            
            //Definimos el objeto para cargar el xml -- la url pasada carga un kml o un georrss 
            //var ruta = "'"+rutaKml+"'";
            //alert(ruta);
            
            //Establecemos la posicion donde se abrira el mapa
            map.setCenter(new GLatLng(coordenadaX,coordenadaY),parseInt(10),G_PHYSICAL_MAP);
            //alert(zoom);
            
            
            
            //alert(rutaKml);            
            var geoXml= new GGeoXml(rutaKml);
            //var geoXml= new GGeoXml("http://www.quecasaquieres.com/web/productos/kml/FabricaNova.kml");
            
            
            
            
			
			//agregamos la capa al mapa
			map.addOverlay(geoXml);
   }
 

}

function ComprobarPassword(error,campoPass,campoError)
{
    var txtPass = document.getElementById(campoPass);
    var txtError = document.getElementById(campoError);
    var spnAsterisco = document.getElementById("spErrorPass");
    var passValid = true;
    
    if (txtPass.value.length == 0 )
    {
        txtError.innerHTML = error;
        txtPass.className = txtPass.className + " error";
        spnAsterisco.style.visibility="visible";
        passValid = false;
    }
    else
    {
            txtPass.className = "pass";
            spnAsterisco.style.visibility="hidden";
            txtError.innerHTML = '';
            passValid = true;
       
    }
    
      
    return (passValid);
}

function ComprobarRecuperarPassCorreo(error,campoMail,campoError)
{
    var txtPass = document.getElementById(campoMail);
    var txtError = document.getElementById(campoError);
    var correoValido = true;
    
    if (txtPass.value.length == 0 )
    {
        txtError.innerHTML = error;
        correoValido = false;
    }
    else
    {
        if ( esMail(txtPass.id ) )
            txtError.innerHTML = '';
        else
        {
            txtError.innerHTML = error;
            correoValido = false;
        }
    }
        
    return (correoValido);
}

function ComprobarRecuperarPass(error,campoPass,campoRepitePass,campoError)
{
    var txtPass = document.getElementById(campoPass);
    var txtRepitePass = document.getElementById(campoRepitePass);
    var txtError = document.getElementById(campoError);
    var PassValido = true;
    
    if (txtPass.value.length == 0 ||
        txtPass.value != txtRepitePass.value )
    {
        txtError.innerHTML = error;
        PassValido = false;
    }
    else
    {
        txtError.innerHTML = '';
    }
        
    return (PassValido);
}

function ComprobarPass(error,campoPass,campoRepitePass,campoError, campoVacio)
{
    var txtPass = document.getElementById(campoPass);
    var txtRepitePass = document.getElementById(campoRepitePass);
    var txtError = document.getElementById(campoError);
    var PassValido= ComprobarPassword(campoVacio, campoPass, campoError);
    var spErrorRepitePass = document.getElementById("spErrorRepitePass");
   
    
    if (PassValido==true)
    {
        if (txtPass.value != txtRepitePass.value )
        {
            txtError.innerHTML = error;
            txtRepitePass.className = txtRepitePass.className + " error";
            spErrorRepitePass.style.visibility="visible";
            PassValido = false;
        }
        else
        {
            txtError.innerHTML = '';
        }
    }
    
    
    return (PassValido);


}



function ComprobarCheckBox(chkBoxAceptar,lblMsjError)
{
    var check = document.getElementById(chkBoxAceptar);
    var label = document.getElementById(lblMsjError);
    
    
    if (!check.checked)
    {
        label.className='';
        return false;
    }
    else
    {
        label.className='oculto';
        return true;
    }
}

function GLS_AgregarBusquedaLocal()
{
    //****Asegurarnos de haber metido la referencia al buscador ajax, e importar la css de google (x defecto)
    
    //1.Opciones para el primer buscador
    var optionSearchControl = {
                        //le indicamos que el contenedor de resultados va a ser el div resultados
                        resultList : document.getElementById("resultados"),
                        //anulamos el zoom al primer resultado de la busqueda
                        suppressInitialResultSelection : true,
                        //creamos un trigger, para tener el control despues de la busqueda completada
                        //onSearchCompleteCallback: searchComplete,
                        //Establecemos el hint del input de busqueda
                        searchFormHint : "Ej: colegios"
                    }
    
    //1. Instanciamos el objeto control de búsqueda de google (es el que contiene los buscadores):
        // Le pasamos las opciones que hemos definido
     searchControl = new google.maps.LocalSearch(optionSearchControl);
     //searchControl.searchFormDiv.Style.Visibility = "hidden";
     
    //2. Los agregamos al mapa:
    map.addControl(searchControl);
    
 
    
    
    //Cargamos una busqueda predefinida
    searchControl.execute(GLS_ComprobarCheckBox());
    
  
    //Lo invisibilizamos:
    //searchControl.searchFormDiv.style.visibility = "hidden";
    //searchControl.searchFormDiv.style.display =  "none";
    //Debemos invisibilizar todo el contenedor --> el contenedor es una propiedad root del searchControl ( una vez que se ha realizado una busqueda )
    //Lo podemos hacer con hidde o con display/none:
    //searchControl.root.style.display =  "none";
    searchControl.root.style.visibility = "hidden";
    
}


function GLS_ComprobarCheckBox ()
{
  var sBusqueda = "";
  
  //Vemos que check estan marcados:
  if (document.getElementById("chkCentrosComerciales").checked) { sBusqueda +=  ( sBusqueda.length > 0 ? " OR " : "" ) +  document.getElementById("chkCentrosComerciales").value; }
  if (document.getElementById("chkColegios").checked) { sBusqueda +=( sBusqueda.length > 0 ? " OR " : "" ) +  document.getElementById("chkColegios").value; }
  if (document.getElementById("chkFarmacias").checked) { sBusqueda +=( sBusqueda.length > 0 ? " OR " : "" ) +  document.getElementById("chkFarmacias").value; }
  if (document.getElementById("chkRestaurantes").checked) { sBusqueda +=( sBusqueda.length > 0 ? " OR " : "" ) +  document.getElementById("chkRestaurantes").value; }
  
  return sBusqueda;
}

function GLS_Buscar ( query )
{
    // Generamos una nueva query para el buscador:
    var sBusqueda = GLS_ComprobarCheckBox() + (query.length > 0  ? " OR " : "") + query;
    
    //Hacemos una nueva Busqueda:
    searchControl.execute(sBusqueda);
}



function cambiaFondo(objeto, valor){
    var elemento = document.getElementById(objeto);
    
    if (valor==1) {elemento.style.background='#f7f7f7';}
    if (valor==0) {elemento.style.background='#ffffff';}
}