// JavaScript Document
var idioma="esp"

function objAjax()
	{
		var peticion;
		if (window.XMLHttpRequest) {
			peticion = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) {
			peticion = new ActiveXObject("Microsoft.XMLHTTP");
		}
	
		return peticion;
	}
	
function stopya(){
		ajax = objAjax(); 
		ajax.open("POST","../musica_off.asp",true)
		ajax.onreadystatechange = function(){
			if (ajax.readyState==4) {
				//alert(ajax.responseText)				
			}
		
		}; 
		
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1"); 	
		ajax.send("&musica=1")

}

function playya(){
		ajax = objAjax(); 
		ajax.open("POST","../musica_on.asp",true)
		ajax.onreadystatechange = function(){
			if (ajax.readyState==4) {
				//alert(ajax.responseText)				
			}		
		}; 
		
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1"); 	
		ajax.send("&musica=1")

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function addBookMark(idN, titulo, seccion, idioma){
		if(window.sidebar)
		{
			window.sidebar.addPanel(titulo, "http://www.grupobribones.com/index.asp?" + seccion, "");
		}
		else if (window.external){
			window.external.AddFavorite ("http://www.grupobribones.com/index.asp?" + seccion, titulo);
		}
		else
		{
			alert("Para guardar esta pagina en los favoritos pulse CTR+D");
		}
	}

function valorDe(id){

	return document.getElementById(id).value;
	}
	
function validaEmail(valor){
		if (/(^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$/.test(valor)){
			return true;
		}
		else{
			alert("La dirección de email es incorrecta.");
			window.document.getElementById("email").focus();
			window.document.getElementById("email").select();
			return false;
		} 
	}


function checkNIF(valorNif) {
	
	var temp_num;
	var valorNifSinX
	var temp_letra;
	var tam;
	var nifnie = /X?Y?[0-9]{8}[A-Z]$/


	try{
			if  (valorNif.length < 9) {
				alert("El formato del DNI debe ser nnnnnnnnL o XnnnnnnnnL/YnnnnnnnnL (extranjeros)")
				return (false)
			}
			else {	
				tam=valorNif.length;
				if (!nifnie.test(valorNif.toUpperCase())) {
					alert("El formato del DNI debe ser nnnnnnnnL o XnnnnnnnnL/YnnnnnnnnL (extranjeros)")
					window.document.getElementById("dni").focus();
					window.document.getElementById("dni").select();
					return (false)
				}
			
			valorNif = valorNif.toUpperCase()
			
			if ((valorNif.substr(0,1)=="X") || (valorNif.substr(0,1)=="Y")) {
				valorNifSinX = valorNif.substr(1,tam-1)		
			} else {
				valorNifSinX = valorNif
			}
			tam = valorNifSinX.length;
			
			temp_num=valorNifSinX.substr(0,tam-1);
			temp_letra=valorNifSinX.substr(tam-1,1);
		}
		
		
		var letra=letraNif(temp_num);
		if (letra.toUpperCase() != temp_letra.toUpperCase()) {
			alert('La letra del DNI no es correcta')
			window.document.getElementById("dni").focus();
			window.document.getElementById("dni").select();
			return (false)
		}
	}catch(err){
		alert("El formato del DNI debe ser nnnnnnnnL o XnnnnnnnnL/YnnnnnnnnL (extranjeros)")
		window.document.getElementById("dni").focus();
		window.document.getElementById("dni").select();
		return(false)
	}
	return(true)
	
}

function letraNif(dni)
{
	cadena="TRWAGMYFPDXBNJZSQVHLCKET"
	posicion = dni % 23
	return(cadena.substring(posicion,posicion+1))
}

