
	function comparar(codpro) {
		document.getElementById('codprocom').value = codpro;
		document.getElementById('formComparar').submit();
	}

	function GuardarDireccion(pCodDir) {
		alert(pCodDir);    
	}

    function openAjaxDirec() {
	Dialog.confirm({url: "solicitud.php?opcion=C", options: {method: 'get'}}, 
		       {top: 5,height: 650, width: 900, className: "alphacube", okLabel: "Volver", cancelLabel: "Cancelar"})    
    }

    function zoomText(Accion,Elemento){
	//inicializaciones
	obj = document.getElementById(Elemento);
	if ( obj.style.fontSize == "" ) {
            obj.style.fontSize = "100%";
	}
	actual = parseInt(obj.style.fontSize); //valor actual del tamaño del texto
	incremento = 10; // el valor del incremento o decremento en el tamaño
		
	//accion sobre el texto
	if ( Accion == "reestablecer" ) {
            obj.style.fontSize = "100%"
	}
	if ( Accion == "aumentar" ) {
            valor = actual+incremento;
            obj.style.fontSize = valor + "%"
	}
	if ( Accion == "disminuir" ) {
            valor = actual - incremento;
            obj.style.fontSize = valor + "%"
	}
    }

    function menuAyuda(objeto,td,imagen) {
	if ( objeto.style.display == 'none' ) {
            objeto.style.display = '';
	} else {
            objeto.style.display = 'none';
	}
    }

    function menuError(objeto) {
	if ( objeto.style.display == 'none' ) {
            objeto.style.display = '';
	} else {
            objeto.style.display = 'none';
	}
    }

    function Entrar() {
	lEmailUsu = document.getElementById("emailusu").value;
	lClaUsu = document.getElementById("clausu").value;
	  
	if ( lEmailUsu == "" ) {
            alert('Debe indicar su dirección de Email');
            return;
	}
	if ( lClaUsu == "" ) {
            alert('Debe indicar una Clave');
            return;
	}
	document.forms.frmFormulario.submit();
    }

	function RegistrarCliente() {
		var hayerror = false;
		prodat = document.getElementById("prodat").checked;
		lNomCli = document.getElementById("nomcli").value;
		lCifDni = document.getElementById("cifdni").value;
		lDomCli = document.getElementById("domcli").value;
		lPobCli = document.getElementById("pobcli").value;
		lCPCli = document.getElementById("cpcli").value;
		document.getElementById("cboPaises_fac").disabled = false;
		lNumPais = document.getElementById("cboPaises_fac").value;
		document.getElementById("cboProvincias_fac").disabled = false;
		lProvCli = document.getElementById("cboProvincias_fac").value;
		lTelCli = document.getElementById("telcli").value;
		lEmailCli = document.getElementById("emailcli").value;
		lClaUsu1 = document.getElementById("clausu1").value;
		lClaUsu2 = document.getElementById("clausu2").value;
		lCombo = document.getElementById("combotipodocumento").value;

		if ( ! prodat ) {
			alert('Debe leer la información sobre Protección de datos');
			return;
		}

		if ( lNomCli == "" ) {
			alert('Debe indicar el Nombre completo.');
			return;
		}

		if ( lCifDni == "" ) {
			alert('Debe indicar el CIF/DNI u otro documento.');						
			return;		
		} else {
			if ( lCombo == 1 ) {
				hayerror = false;
				caracter = lCifDni.charAt(0);
				if ( isNaN(caracter) ) {
					if ( ! ValidarCIF(lCifDni) ) {
						hayerror = true;
					}
				}
				if ( ! isNaN(caracter) ) {
					if ( ! ValidarDNI(lCifDni) ) {
						hayerror = true;
					}
				}
			}
		}

		if ( hayerror ) {
			return;
		}

		if ( lDomCli == "" ) {
			alert('Debe indicar un Domicilio.');
			return;
		}
		if ( lPobCli == "" ) {
			alert('Debe indicar una Población.');
			return;
		}
		if ( lCPCli == "" ) {
			alert('Debe indicar un Código Postal.');
			return;
		}
		if ( lNumPais == "" || lNumPais == 0 ) {
			alert('Debe indicar un País.');
			return;
		}
		if ( lProvCli == "" || lProvCli == 0 ) {
			alert('Debe indicar una Provincia.');
			return;
		}
		if ( lTelCli == "" ) {
			alert('Debe indicar un Teléfono de Contacto.');
			document.getElementById("cboPaises_fac").disabled = true;
			document.getElementById("cboProvincias_fac").disabled = true;
			return;
		}
		if ( lEmailCli == "" ) {
			alert('Debe indicar un Email.');
			return;
		} else {
			if( ! ValidarEmail(lEmailCli) ) {
				return;
			}
		}
		if ( lClaUsu1 == "" ) {
			alert('Debe indicar una Clave.');
			return;
		}
		if ( lClaUsu1 != lClaUsu2 ) {
			alert('Debe coincidir la Clave en las dos casillas.');
			return;
		}

		document.forms.frmFormulario.submit();
	}

	function Paso1Cliente() {
		var hayerror = false;
		lNomCli = document.getElementById("nomcli").value;
		lCifDni = document.getElementById("cifdni").value;
		lDomCli = document.getElementById("domcli").value;
		lPobCli = document.getElementById("pobcli").value;
		lCPCli = document.getElementById("cpcli").value;
		document.getElementById("cboPaises_fac").disabled = false;
		lNumPais = document.getElementById("cboPaises_fac").value;
		document.getElementById("cboProvincias_fac").disabled = false;
		lProvCli = document.getElementById("cboProvincias_fac").value;
		lTelCli = document.getElementById("telcli").value;
		lEmailCli = document.getElementById("emailcli").value;
		lCodDirEntrega = document.getElementById("cboDirecciones").value;
		lCombo = document.getElementById("combotipodocumento").value;

		if ( lNomCli == "" ) {
			alert('Debe indicar el Nombre completo en la Dirección de Facturación.');
			return;
		}
		if ( lCifDni == "" ) {	
			alert('Debe indicar el CIF o el DNI en la Dirección de Facturación.');						
			return;		
		} else {
			if ( lCombo == 1 ) {
				hayerror = false;
				caracter = lCifDni.charAt(0);
				if ( isNaN(caracter) ) {
					if ( ! ValidarCIF(lCifDni) ) {
						hayerror = true;
					}
				}
				if ( ! isNaN(caracter) ) {
					if ( ! ValidarDNI(lCifDni) ) {
						hayerror = true;
					}
				}
			}
		}
		if ( hayerror ) {
			return;
		}
		if ( lDomCli == "" ) {
			alert('Debe indicar un Domicilio en la Dirección de Facturación.');
			return;
		}
		if ( lPobCli == "" ) {
			alert('Debe indicar una Población en la Dirección de Facturación.');
			return;
		}
		if ( lCPCli == "" ) {
			alert('Debe indicar un Código Postal en la Dirección de Facturación.');
			return;
		}
		if ( lNumPais == "" || lNumPais == 0 ) {
			alert('Debe indicar un País en la Dirección de Facturación.');
			return;
		}
		if ( lProvCli == "" || lProvCli == 0 ) {
			alert('Debe indicar una Provincia en la Dirección de Facturación.');
			return;
		}
		if ( lTelCli == "" ) {
			alert('Debe indicar un Teléfono de Contacto.');
			document.getElementById("cboPaises_fac").disabled = true;
			document.getElementById("cboProvincias_fac").disabled = true;
			return;
		}
		if ( lEmailCli == "" ) {
			alert('Debe indicar un Email en la Dirección de Facturación.');
			return;
		} else {
			if ( ! ValidarEmail(lEmailCli) ) {
				return;
			}
		}
		document.forms.frmFormulario.submit();
	}

    function PasarEmail() {
	lEmailUsu = document.getElementById("emailusu").value;

	if ( lEmailUsu == "" ) {
            lURL = "/igonline/tienda.php?seccion=recordar";
	} else {
            lURL = "/igonline/tienda.php?seccion=recordar&email=" + lEmailUsu;
	}

	window.location.href = lURL;
    }

    function ValidarPaso1() {
	lCodDirEntrega = document.getElementById("coddirent").value;
	lPasRec = document.getElementById("pasrec").value;

	if ( lCodDirEntrega == "" ) {
            alert('Debe indicar la Dirección de Entrega.');
            return;
	}

	lURL = "/igonline/tienda.php?seccion=pedido2&coddirent=" + lCodDirEntrega + "&pasrec=" + lPasRec;
	window.location.href = lURL;
    }

    function ValidarPaso2() {
	lCodDirEntrega = document.getElementById("coddirent").value;
	lForPag = document.getElementById("formapago").value;

	if ( lForPag == 0 || lForPag == "" ) {
            alert('Debe indicar una Forma de Pago.');
            return;
	}

	document.forms.frmFormulario.submit();
    }

	function ValidarPaso3() {
		lCodDirEntrega = document.getElementById("coddirent").value;
		lForPag = document.getElementById("formapago").value;
		lNumCli = document.getElementById("numcli").value;
		lCondiciones = document.getElementById("chkCondiciones").checked;
		
		if ( lCondiciones == false || lCondiciones == "" ) {
			cond = document.getElementById("condiciones");
			if ( cond ) {
				cond.style.backgroundColor = '#ffcece';
				cond.style.color = '#333';
			}
            alert('Para poder hacer un pedido, debe aceptar nuestras condiciones.');
            return;
		}

		if ( lCodDirEntrega == "" ) {
            alert('Debe indicar la Dirección de Entrega.');
            return;
		}

		if ( lForPag == 0 || lForPag == "" ) {
            alert('Debe indicar una Forma de Pago.');
            return;
		}

		if ( lNumCli == "" && lNumCli == 0 ) {
            alert('Debe indentificarse como Cliente.');
            return;
		}

		document.forms.frmFormuConfirmar.submit();
    }

    function ValidarPaso4(){
	document.forms.frmFormuPagar.submit();
    }

    function CerrarSesion(){
	window.location.href = "/igonline/tienda.php?accion=CERRAR";
    }

    function menuCapa(objeto,td,imagen,empresa) {
	if ( objeto.style.display == 'none' ) {
            objeto.style.display = '';
            imagen.src = '/igonline/template/' + empresa + '/img/menos.gif';
	} else {
            objeto.style.display = 'none';
            imagen.src = '/igonline/template/' + empresa + '/img/mas.gif';
	}
    }

    function BuscarProducto() {
	lTtxtBuscar = document.getElementById("txtbuscar").value;

	if ( lTtxtBuscar == "" ) {
            alert('No ha indicado ninguna palabra a buscar.');
            return;
	}
	window.location.href="/igonline/tienda.php?seccion=buscar&pag=1&txtbuscar=" + lTtxtBuscar;
    }

    function AnadirCarrito(pCodPro, pOrigen) {
        pOrigen = encodeURIComponent(pOrigen);

        lURL = "/igonline/tienda.php?seccion=carrito&addCarrito=1&codpro=" + pCodPro + "&origen=" + pOrigen;
        window.location.href = lURL;
    }
	
    function AnadirFavoritos(pCodPro, pOrigen) {
	lURL = "/igonline/tienda.php?seccion=favoritos&addFavorito=1&codpro=" + pCodPro;
	window.location.href = lURL;
    }

    function QuitarFavoritos(pCodPro, pOrigen) {
	lURL = "/igonline/tienda.php?seccion=favoritos&supFavorito=1&codpro=" + pCodPro;
	window.location.href = lURL;
    }

    function QuitarCarrito(pCodPro) {
	lURL = "/igonline/tienda.php?seccion=carrito&supCarrito=1&codpro=" + pCodPro;
	window.location.href = lURL;
    }

    function VaciarCarrito(pOrigen) {
        lResp = window.confirm('¿Desea vaciar la Cesta de la compra?');
        if ( lResp != true ) {
            return;
        }

        pOrigen = encodeURIComponent(pOrigen);

        lURL = "/igonline/tienda.php?seccion=carrito&vaciarCarrito=1&origen=" + pOrigen;
        window.location.href = lURL;
    }

    function CambiarCantidad(pTipo, pCodPro, pCant, pvFic, pOrigen) {
	if ( pTipo == '0' ) {
            lURL = "/igonline/tienda.php?seccion=carrito&increCarrito=1&codpro=" + pCodPro + "&vfic=" + pvFic + "&origen=" + encodeURIComponent(pOrigen);
	} else {
            if ( pCant == '1' ) {
		return;
            }
            lURL = "/igonline/tienda.php?seccion=carrito&decreCarrito=1&codpro=" + pCodPro + "&vfic=" + pvFic + "&origen=" + encodeURIComponent(pOrigen);
	}
	window.location.href = lURL;
    }

	function Identificar() {
		lEmailUsu = document.getElementById("emailusu").value;
		lClaUsu = document.getElementById("clausu").value;

		if ( lEmailUsu == "" ) {
			alert('Debe indicar su dirección de Email');
			return;
		}
		if ( lClaUsu == "" ) {
			alert('Debe indicar una Clave');
			return;
		}
		document.forms.frmLogin.submit();
	}

    function RecordarEmail() {
	lEmail = document.getElementById("email").value;
	  
	if ( lEmail == "" ) {
            alert('Debe indicar el email con el que se registró');
            return;
	}
	lURL = "/igonline/tienda.php?seccion=recordar&email=" + lEmail;
	window.location.href = lURL;
    }

    function MostrarDirecEntrega(pTipo) {
	document.getElementById("tipentrega").value = pTipo;

	if ( pTipo == 1 ) {
            document.getElementById("divDirecEntrega").style.display = 'none';
	} else if ( pTipo == 2 ) {
            document.getElementById("divDirecEntrega").style.display = '';
	}
    }

    function cargarSubFamilias() {
	var d1, contenedor;
	contenedor = document.getElementById('contenedor_subfamilias');
	pValor = document.getElementById("cboFamilias").value;
	
	ajax = nuevoAjax();
	
	/*lURL = "/igonline/plataforma/comun/lib/procesos_ajax.php?AccionAjax=CARGAR_SUBFAMILIAS&codfam="+pValor+"&EMPRESA_PLATAFORMA=elasun";*/
	lURL = "/igonline/lib/procesos_ajax.php?AccionAjax=CARGAR_SUBFAMILIAS&codfam=" + pValor + "&EMPRESA_PLATAFORMA=elasun";

	ajax.open("GET", lURL, true);
	ajax.onreadystatechange = function() {
            if ( ajax.readyState == 4 ) {
		contenedor.innerHTML = ajax.responseText
            }
	}
	ajax.send(null) 
    }

	function BusquedaAvanzadaProducto() {
		lCodFam = document.getElementById("cboFamilias").value;
		lCodSubFam = document.getElementById("cboSubFamilias").value;
		lCodMar = document.getElementById("cboMarcas").value;
		lTtxtBuscar = document.getElementById("txtbuscar2").value;

		if ( (lCodFam == 0 || lCodFam == "") && lCodSubFam == "" && (lCodMar == 0 || lCodMar == "") && lTtxtBuscar == "" ) {
			alert('No se ha indicado ningún criterio de búsqueda.');
			return;
		}

		lURL = "/igonline/tienda.php?seccion=buscar&tipo=avd&pag=1&codfam=" + lCodFam + "&codsfa=" + lCodSubFam + "&codmar=" + lCodMar + "&txtbuscar=" + lTtxtBuscar;
		window.location.href = lURL;
	}

    function BusquedaPorMarca() {
	lCodMar = document.getElementById("cboMarcas").value;

	if ( lCodMar == 0 || lCodMar == "" ) {
            alert('No se ha indicado ninuna marca de búsqueda.');
            return;
	}

	lURL = "/igonline/tienda.php?seccion=buscar&tipo=avd&pag=1&codmar=" + lCodMar;
	window.location.href = lURL;
    }

    function BusquedaPorFamilia() {
	lCodFam = document.getElementById("cboFamilias").value;

	if ( lCodFam == 0 || lCodFam == "" ) {
            alert('No se ha indicado ninguna familia de búsqueda.');
            return;
	}

	lURL = "/igonline/tienda.php?seccion=buscar&tipo=avd&pag=1&codfam=" + lCodFam;
	window.location.href = lURL;
    }

    function cargarProvincias(pNombre) {
		var d1, contenedor;
		
		eval("contenedor = document.getElementById('contenedor_provincias" + pNombre + "');");
		eval("pValor = document.getElementById('cboPaises" + pNombre + "').value;");
	
		ajax = nuevoAjax();
		
		/*lURL = "/var/www/vhosts/elasun.com/httpdocs/igonline/plataforma/comun/lib/procesos_ajax.php?AccionAjax=CARGAR_PROVINCIAS&nombreinput=cboProvincias"+pNombre+"&numpais="+pValor+"&EMPRESA_PLATAFORMA=elasun";	*/
		lURL = "lib/procesos_ajax.php?AccionAjax=CARGAR_PROVINCIAS&nombreinput=cboProvincias" + pNombre + "&numpais=" + pValor + "&EMPRESA_PLATAFORMA=elasun";

		ajax.open("GET", lURL, true);
		ajax.onreadystatechange = function() {
            if ( ajax.readyState == 4 ) {
				contenedor.innerHTML = ajax.responseText;

				if ( ! /msi/.test(navigator.userAgent.toLowerCase()) ) {
					document.getElementById("cboProvincias" + pNombre).focus();
				}
            }
		}
		ajax.send(null) 
    }

    function cargarGruposTransporte() {
	var d1, contenedor;
		
	eval("contenedor = document.getElementById('contenedor_grupos');");
	eval("pValor = document.getElementById('codtae').value;");

	ajax = nuevoAjax();

	/*lURL = "/var/www/vhosts/elasun.com/httpdocs/igonline/plataforma/comun/lib/procesos_ajax.php?AccionAjax=CARGAR_PROVINCIAS&nombreinput=cboProvincias"+pNombre+"&numpais="+pValor+"&EMPRESA_PLATAFORMA=elasun";	*/
	lURL = "/igonline/lib/procesos_ajax.php?AccionAjax=CARGAR_GRUPOS_TRANSPORTE&nombreinput=cboGrupos&codtae=" + pValor + "&EMPRESA_PLATAFORMA=elasun";

	ajax.open("GET", lURL, true);
	ajax.onreadystatechange = function() {
            if ( ajax.readyState == 4 ) {
		contenedor.innerHTML = ajax.responseText
            }
	}
	ajax.send(null) 
    }
	
    function ValidarDecimal(e, pValor) {
	var keynum;
	var keychar;
	var numcheck;
	var r, re;

	if ( window.event ) { // IE
            keynum = e.keyCode;
	} else if ( e.which ) { // Netscape/Firefox/Opera
            keynum = e.which;
	}
		
	if ( keynum == 46 ) {        // Convierte la coma (,) en un punto(.)
            keynum = 44;
	}
	if ( keynum == 44 ) {        // Si es una coma compruebo que no haya ya una puesta.
            re = /,/i;	// valor que busca en forma de expresión regular
            r = pValor.match(re);   // busca en el pValor el valor de re
            if ( r != null ) {
                keynum = 0;
            }
	}

	if( (keynum < 48 || keynum > 57) && keynum != 44 ) {        // Deja escribir números (0-9) y la coma(,)
            keynum = 0;
	}
		
	if ( window.event ) { // IE
            e.keyCode = keynum;
            return true;
	} else if ( e.which ) { // Netscape/Firefox/Opera
            // Si la tecla no era la de Borrar comprobamos, sino dejamos borrar.
            if ( e.which != 8 ) {
		// Si es número deja escribir.
		keychar = String.fromCharCode(keynum);
		numcheck = /\d/
				
		if ( keychar != "," ) {
                    return numcheck.test(keychar);
		} else {
                    return true;
		}
            } else {
		return true;
            }
	}
    }

    function SoloNumero(e) {
	var keynum;
	var keychar;
	var numcheck;
	var r, re;

	if ( window.event ) { // IE
            keynum = e.keyCode;
	} else if ( e.which ) { // Netscape/Firefox/Opera
            keynum = e.which;
	}

	if ( keynum < 48 || keynum > 57 ) {        // Deja escribir números (0-9)
            keynum = 0;
	}

	if ( window.event ) { // IE
            e.keyCode = keynum;
            return true;
	} else if ( e.which ) { // Netscape/Firefox/Opera
            // Si la tecla no era la de Borrar comprobamos, sino dejamos borrar.
            if ( e.which != 8 ) {
		// Si es número deja escribir.
		keychar = String.fromCharCode(keynum);
		numcheck = /\d/

		return numcheck.test(keychar);
            } else {
		return true;
            }
	}
    }

    function ValidarEmail(emailStr) {
	/* The following pattern is used to check if the entered e-mail address fits the user@domain format.  It also is used to separate the username from the domain. */
	var emailPat = /^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special characters.  We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a username or domainname.  It really states which chars aren't allowed. */
	var validChars = "\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com is a legal e-mail address. */
	var quotedUser = "(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses, rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom = validChars + '+'
	/* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */
	var word = "(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$")
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into different ??4??pieces that are easy to analyze. */
	var matchArray = emailStr.match(emailPat)
	if ( matchArray == null ) {
            /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */
            alert("La dirección de email introducida es incorrecta. Verifique si es de la forma: usuario@dominio.com")
            return false
	}
	var user = matchArray[1]
	var domain = matchArray[2]
	
	// See if "user" is valid 
	if ( user.match(userPat) == null ) {
            // user is not valid
            alert("El nombre de usuario en la dirección de email es incorrecto.")
            return false
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */
	var IPArray = domain.match(ipDomainPat)
	if ( IPArray != null ) {
            // this is an IP address
            for ( var i = 1; i <= 4 ; i++ ) {
		if ( IPArray[i] > 255 ) {
                    alert("Direccion IP no válida en la dirección de email.")
                    return false
		}
            }
            return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if ( domainArray == null ) {
            alert("El nombre de dominio en la dirección de email es incorrecto.")
            return false
	}
	
	/* domain name seems valid, but now make sure that it ends in a three-letter word (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms it consists of. */
	var atomPat = new RegExp(atom, "g")
	var domArr = domain.match(atomPat)
	var len = domArr.length
	if ( domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 3 ) {
            // the address must end in a two letter or three letter word.
            alert("La dirección de email debe acabar en 3 letras de dominio o 2 de un país.")
            return false
	}
	
	// Make sure there's a host name preceding the domain.
	if ( len < 2 ) {
            var errStr = "El dominio introducido en la dirección de email es incorrecto."
            alert(errStr)
            return false
	}
	
	// If we've gotten this far, everything's valid!
	return true
    }
	
	//Funcion para validar el DNI
	function ValidarDNI (pDNI) {
		var pNum, pLetra, cadena, posicion, letra;

		if ( pDNI.length != 9 ) {
//			document.getElementById('avisodni').style.display = '';
			alert("El DNI no es correcto, la longitud no es valida");
			return false
		}

		pNum = pDNI.substring(0, 8);
		pLetra = pDNI.substring(8, 9);
		pLetra = pLetra.toUpperCase();

		cadena = "TRWAGMYFPDXBNJZSQVHLCKET";
		posicion = parseFloat(pDNI) % 23;
		letra = cadena.substring(posicion, posicion + 1);

		if ( letra != pLetra ) {
//			document.getElementById('avisodni').style.display = '';
			alert("El DNI no es correcto, la letra no es la que corresponde");
			return false
		} else {
			return true
		}
	}

	//Funcion para validar el CIF
	function ValidarCIF(texto) {
		try {
			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 =/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g; 
			if ( ! regular.exec(texto) ) {
//				document.getElementById('avisocif').style.display = '';
				alert("El CIF no es correcto");
				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 {
//				document.getElementById('avisocif').style.display = '';
				alert("El CIF no es correcto");
				return false;
			}
		} catch(e) {
//			document.getElementById('avisocif').style.display = '';
			alert("El CIF no es correcto");
			return false;
		}
	}

    // Función para comprobar si un año es bisiesto.
    function anyoBisiesto(anyo)	{
	// Si el año introducido es de dos cifras lo pasamos al periodo de 1900. Ejemplo: 25 > 1925
	if ( anyo < 100 ) {
            var fin = anyo + 1900;
	} else {
            var fin = anyo;
	}
	
	// Primera condicion: si el resto de dividir el año entre 4 no es cero > el año no es bisiesto
	// es decir, obtenemos año modulo 4, teniendo que cumplirse anyo mod(4)=0 para bisiesto
	if ( fin % 4 != 0 ) {
            return false;
	} else {
            if ( fin % 100 == 0 ) {
                // Si el año es divisible por 4 y por 100 y divisible por 400 > es bisiesto
	        if ( fin % 400 == 0 ) {
	            return true;
	            // Si es divisible por 4 y por 100 pero no lo es por 400 > no es bisiesto
	         } else {
                    return false;
	         }
	        
	        // Si es divisible por 4 y no es divisible por 100 > el año es bisiesto
            }else{
                return true;
	    }
	}
    }

    // Función principal de validación de la fecha.
    function ValidarFecha(pFecha) {
	// Varables globales que van a contener la fecha completa
	var dia, mes, anyo, febrero;
		
	// Obtenemos la fecha introducida y la separamos en dia, mes y año
	dia = pFecha.split("/")[0];
	mes = pFecha.split("/")[1];
	anyo = pFecha.split("/")[2];
		
	if( (isNaN(dia)==true) || (isNaN(mes)==true) || (isNaN(anyo)==true) ){
            alert("La fecha introducida debe tener la forma: dd/mm/aaaa");
            return;
	}
	if( anyoBisiesto(anyo) ) {
            febrero = 29;
	} else {
            febrero = 28;
	}
	// Si el mes introducido es negativo, 0 o mayor que 12 > alertamos y detenemos ejecución.
	if ( mes < 1 || mes > 12 ) {
            alert("El mes introducido no es válido. Por favor, introduzca un mes correcto.");
            return;
	}
	// Si el mes introducido es febrero y el día es mayor que el correspondiente al año
	// introducido > alertamos y detenemos ejecución.
	if ( mes == 2 && ( dia < 1 || dia > febrero) ) {
            alert("El día introducido no es válido. Por favor, introduzca un día correcto.");
            return;
	}
	// Si el mes introducido es de 31 días y el día introducido es mayor de 31 > alertamos y detenemos ejecución.
	if ( (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12) && (dia < 1 || dia > 31) ) {
	    alert("El día introducido no es válido. Por favor, introduzca un día correcto.");
            return;
	}
	// Si el mes introducido es de 30 días y el día introducido es mayor de 301 > alertamos y detenemos ejecución.
	if ( (mes == 4 || mes == 6 || mes == 9 || mes == 11) && (dia < 1 || dia > 30) ) {
	       alert("El día introducido no es válido. Por favor, introduzca un día correcto.");
	       return;
	}
	// Si el mes año introducido es menor que 1990 o mayor que 2500 > alertamos y detenemos ejecución.
	if ( anyo < 1900 || anyo > 2010 ) {
            alert("El año introducido no es válido. Por favor, introduzca un año correcto.");
	    return;
	}
	   
	return true;
    }
	
    function AbreCentrada(url, nombre, ancho, alto) {
	mgtop = ((screen.height / 2) - (alto / 2)) - 10;
	mgleft = (screen.width / 2) - (ancho / 2);

        if ( url.substring(0, 7) != 'http://' ) {
            url = '/igonline/' + url;
        }

	window.open(url,nombre,'width=' + ancho + ',height=' + alto + ',top=' + mgtop + ',left=' + mgleft + ',scrollbars=yes,status=no');
    }

    function ConsultarPrecio(url, nombre, ancho, alto) {
	mgtop = ((screen.height / 2) - (alto / 2)) - 10;
	mgleft = (screen.width / 2) - (ancho / 2);

	window.open('/igonline/' + url,nombre,'width=' + ancho + ',height=' + alto + ',top=' + mgtop + ',left=' + mgleft + ',scrollbars=no,status=no');
    }

    function ValidarCodigo() {
	Codigo = document.getElementById("descuentopromo").value;
	var str = new String(Codigo);
	var c = str.length;
				
	document.forms.frmFormuValidarCodigo.opcionpromo.value = "v";
	document.forms.frmFormuValidarCodigo.submit();
    }

    function BorrarPedido(pNumReg) {
        lResp= window.confirm("¿Está seguro de que desea Borrar el Pedido?");
        if ( lResp != true ) {
            return;
        }

        lURL = "/igonline/tienda.php?seccion=pedidoabierto&opcion=B&numped=" + pNumReg;
        window.location.href = lURL;
    }
