/*******************************
 Validación del nif. Por Carlitos. carlosbernad@teleline.es
 Si usas este script, deja intactas estas líneas (créditos). Vale?
 También te agradecería un e-mail con tus comentarios.
*******************************/

function display_capas (capa,a) {
	if (a==1) {
		document.getElementById(capa).style.display="block";
	} else {
		document.getElementById(capa).style.display="none";
	}
}

function validarNIF(nif)
{
abc=nif;
dni=abc.substring(0,abc.length-1);
dni = dni.replace('X','0');
dni = dni.replace('Y','1');
let=abc.charAt(abc.length-1);
if (!isNaN(let))
 {
  return false;
 }
else
 {
  cadena="TRWAGMYFPDXBNJZSQVHLCKET";
  posicion = dni % 23;
  letra = cadena.substring(posicion,posicion+1);
  if (letra!=let.toUpperCase())
   {
    return false;
   }
 }
return true;
}

function esCuentaValida(cuenta)
{
	if (cuenta=="")
		return false;
	if (cuenta.length!=20)
		return false;
	for (i=0; i<cuenta.length; i++)
		if (isNaN(cuenta.charAt(i)))
			return false;
	ops = new Array(1,2,4,8,5,10,9,7,3,6);
	initialProduct = new Array(10);
	suma = 0;
	control = cuenta.substr(9,1);
	num = cuenta.substr(10,10);
	for (qq=0; qq<ops.length;qq++)
		suma = suma + eval(num.charAt(qq))*ops[qq];
	finalValue = 11 - (suma%11);
	if (finalValue == 10) finalValue=1;
	if (finalValue == 11) finalValue=0;
	if (finalValue != eval(control)) return false;
	return true;
}
function tamanoCorrecto(campo, tamano, exacto)
{
	//exacto==1 -> lg de campo tiene que ser igual a tamano
	//exacto==0 -> lg de campo tiene que ser inferior o igual a tamano
	if (exacto && campo.length == tamano)
		return true;
	if (!exacto && campo.length <= tamano)
		return true;
	return false;
}

function activarNIB(form, value)
{
	if (value == "04")
	{
		form.cb1.disabled=true;
		form.cb2.disabled=true;
		form.cb3.disabled=true;
		form.cb4.disabled=true;
	}
	if (value == "02")
	{
		form.cb1.disabled=false;
		form.cb2.disabled=false;
		form.cb3.disabled=false;
		form.cb4.disabled=false;
	}
		
}

function isEmail(email) {
//Modificación basada en el ejemplo de Bit Bucket Heaven
//Updated to be used with MAC-OS
var boolSalida = true;
    var invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";
    // Checkea valor nulo "null"
    if (email == "")boolSalida=false;
    // Checkea caracteres inválidos definidos en "invalidChars"
    for (var i=0; i<invalidChars.length; i++) {
        var badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1)boolSalida=false;
    }
    var lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == "."))boolSalida=false;
    var Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".")boolSalida=false;
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".")boolSalida=false;
        if (Pos != -1)Pos++;
    }
    // Por lo menos debe haber una @
    var atPos = email.indexOf("@",1);
    if (atPos == -1)boolSalida=false;
    // Pero solo una @
    if (email.indexOf("@",atPos+1) != -1)boolSalida=false;
    // Tambien checkea para al menos un punto "." despues de la @
    var periodPos = email.indexOf(".",atPos);
    if (periodPos == -1)boolSalida=false;
    if (periodPos+3 > email.length)boolSalida=false;
    return boolSalida;
}

function selectRadio(form, valor)
{
	form.hid_pago.value=valor;
}
function formatMesODia(i)
{
	if (i<10)
		return "0"+i+"";
	else
		return ""+i+"";
}
function getMonthName(i)
{
	switch(i)
	{
	 case  1: return "enero";
	 case  2: return "febrero";
	 case  3: return "marzo";
	 case  4: return "abril";
	 case  5: return "mayo";
	 case  6: return "junio";
	 case  7: return "julio";
	 case  8: return "agosto";
	 case  9: return "septiembre";
	 case 10: return "octubre";
	 case 11: return "noviembre";
	 case 12: return "diciembre";
	 defalut: return "";
	}
}

function compruebaFechaNacimiento()
{
	d = new Date();
	d1 = new Date();
	control=true;
	if (document.forms[0].mesHijo.value==0 || document.forms[0].mesHijo.value==0 || document.forms[0].mesHijo.value==0)
		control=false;
	d.setMonth(document.forms[0].mesHijo.value-1);
	d.setDate(document.forms[0].diaHijo.value);
	d.setYear(document.forms[0].anioHijo.value);
	diferencia=d1-d;
	diferencia=diferencia/24/60/60/1000;
	if (diferencia<eval("-244")) //275
		control=false;
	if ((eval(document.forms[0].mesHijo.value)==2 || eval(document.forms[0].mesHijo.value)==4 || eval(document.forms[0].mesHijo.value)==6 || eval(document.forms[0].mesHijo.value)==9 || eval(document.forms[0].mesHijo.value)==11) && eval(document.forms[0].diaHijo.value)==31)
		control=false;
	if (eval(document.forms[0].mesHijo.value)==2 && eval(document.forms[0].diaHijo.value)==30)
		control=false;
	if (eval(document.forms[0].mesHijo.value)==2 && eval(document.forms[0].diaHijo.value)==29 && ((eval(document.forms[0].anioHijo.value)%4) || (!(eval(document.forms[0].anioHijo.value)%4) && !(eval(document.forms[0].anioHijo.value)%400))))
		control=false;
	if (control)
	{
		return true;
	}
	return false;
}


function CPProvincia(CP, provincia)
{
	if (CP.substr(0,2) != formatMesODia(provincia))
		return false;
	return true;
}

function esNIB(nib1, nib2, nib3, nib4)
{
	if (nib1=="" || nib2=="" || nib3=="" || nib4=="")
		return false;
	if (isNaN(nib1)) return false;
	if (isNaN(nib2)) return false;
	if (isNaN(nib3)) return false;
	if (isNaN(nib4)) return false;
	if (!tamanoCorrecto(nib1,  4, 1)) return false;
	if (!tamanoCorrecto(nib2,  4, 1)) return false;
	if (!tamanoCorrecto(nib3,  2, 1)) return false;
	if (!tamanoCorrecto(nib4, 10, 1)) return false;
	return true;
}

function tieneCifra(campo)
{
	for (i=0; i<campo.length; i++)
		if (!isNaN(campo.charAt(i)))
			return true;
	return false;
}

function numInvalido(tel)
{
	for (i=0; i<tel.length; i++)
		if (i==0)
			tmp=tel.charAt(i);
		else
			if (tmp!=tel.charAt(i))
				return false;
			else return true;
	return true;
}

function esTelEspanol(tel)
{
	if (!tamanoCorrecto(tel, 9, 1))
		return false;
	if (isNaN(tel))
		return false;
	if (tel.charAt(0) != '9' && tel.charAt(0) != '8' && tel.charAt(0) != '7' && tel.charAt(0) != '6')
		return false;
	return true;
}

function contieneSoloLetras(str)
{
	for (i=0; i<str.length; i++)
		if (str.charCodeAt(i)<65 && str.charCodeAt(i)>90 || str.charCodeAt(i)<97 || str.charCodeAt(i)>122)
			return false;
	return true;
}

function contieneLetra(str)
{
	for (i=0; i<str.length; i++)
		if ((str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122))
			return true;
	return false;
}

function esComplONumValido(str)
{
	for (i=0; i<str.length; i++)
		if (!((str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122) || str.charCodeAt(i)==44 || str.charCodeAt(i)==32 || str.charCodeAt(i)==45 || (str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57)))
			return false
	return true;
}

function cambiarDatos(valor)
{
	if ( (valor=="WEB06S") || (valor=="EMMC06W") || (valor=="WTP06W") )
	{
		document.getElementById("s1").innerHTML="Servicio de Atención al Cliente:<br><b>902 388 488</b> o <b>clublibrodisney@salvatkids.com</b>";
	}
	else
	{
		if (valor=="")
		{
			document.getElementById("s1").innerHTML="";
		}
		else
		{
			document.getElementById("s1").innerHTML="Servicio de Atención al Cliente:<br><b>902 27 27 26</b> o <b>info@salvat.com</b>";
		}
	}
}

function creditos()
{
	if (navigator.appName == 'Microsoft Internet Explorer')
		window.open('creditos.html', '_new','resizable=0,toolbar=0,location=0,directories=0,status=3,menubar=0,scrollbars=1,width=235,height=55,left=250,top=250,screenLeft=250,screenTop=250');
	else
		window.open('creditos.html', '_new','resizable=0,toolbar=0,location=0,directories=0,status=3,menubar=0,scrollbars=1,width=212,height=50,left=250,top=250,screenLeft=250,screenTop=250');
}
function contacto()
{
	if (navigator.appName == 'Microsoft Internet Explorer')
		window.open('contacto_es.asp', '_new','resizable=0,toolbar=0,location=0,directories=0,status=3,menubar=0,scrollbars=1,width=420,height=700,left=250,top=0,screenLeft=250,screenTop=0');
	else
		window.open('contacto_es.asp', '_new','resizable=0,toolbar=0,location=0,directories=0,status=3,menubar=0,scrollbars=1,width=422,height=700,left=250,top=0,screenLeft=250,screenTop=0');
}
function politica()
{
	if (navigator.appName == 'Microsoft Internet Explorer')
		window.open('politica_es.asp', '_new','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=455,height=550,left=250,top=0,screenLeft=250,screenTop=0');
	else
		window.open('politica_es.asp', '_new','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=455,height=550,left=250,top=0,screenLeft=250,screenTop=0');
}

function abrir_ayuda(a)
{
	//556 278 w
	// 510 255 h
	izq=(screen.width/2) - 278;
	arriba=(screen.height/2) - 340;

	if (navigator.appName == 'Microsoft Internet Explorer')
		window.open('ayuda.asp?accion='+a, '_new','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=556,height=750,left='+izq+',top='+arriba+',screenLeft=250,screenTop=0');
	else
		window.open('ayuda.asp?accion='+a, '_new','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=3,width=556,height=750,left=250,top=0,screenLeft=250,screenTop=0');

}

function abrir_condiciones()
{
	if (navigator.appName == 'Microsoft Internet Explorer')
		window.open('condiciones_es.asp?accion=DWEB08OP', '_new','resizable=0,toolbar=0,location=0,directories=0,status=3,menubar=0,scrollbars=1,width=440,height=700,left=250,top=0,screenLeft=250,screenTop=0');
	else
		window.open('condiciones_es.asp?accion=DWEB08OP', '_new','resizable=0,toolbar=0,location=0,directories=0,status=3,menubar=0,scrollbars=1,width=435,height=750,left=250,top=0,screenLeft=250,screenTop=0');
}