/* 	14 / 6 / 2011 -  */
	
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	function validateEmail(email){
	var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
	if (!regEx.test(email)) {
		return false;
	} 
	return true;
}
	function sorteo(){
		aux=document.getElementById('mailSorteo').value;
		if (!validateEmail(aux))  { 
			alert("La dirección de email es incorrecta.");
			document.getElementById('mailSorteo').focus();
		} else location.href = 'sorteo.php?mail='+aux;
	}


function getValue(element){
	switch(element.type){
		case 'select-one':
		case 'select':
			return element.options[element.selectedIndex].value;
		break;
		case 'checkbox':
			if (element.checked) return 1;
			else return 0;
		default:
			if (element.value) return element.value;
			else return 0;
		break;
		
	}
	return 0;
}

function validate(z){

	for (var x=0; x < z.length; x++) {

 		if (z[x].getAttribute('required')){
 		
 			if ( z[x].getAttribute('required') == 'required'  && getValue(z[x]) == "" || getValue(z[x]) == 0){
				var ncampo = z[x].getAttribute('name');
 				alert("El campo "+ncampo+" es obligatorio ");
	 			z[x].style.background='#ffff66';
				z[x].focus();
 				return false;	
 			} else z[x].style.background='#ffffff';
 		} 
 	}
	z.submit(); 	
}

/* ------ fin ------ */
function rollOver(noticia){
    document.getElementById(noticia).style.background = 'url(../img/degradado_noticias.png) 0 0 no-repeat';
    document.getElementById(noticia).style.cursor = "pointer";
    var noti = document.getElementById(noticia);
    var as = noti.getElementsByTagName('a');
    as[0].style.color= "#000000";

}

function rollOver2(noticia){
    document.getElementById(noticia).style.background = 'url(img/degradado_noticias.png) 0 0 no-repeat';
    document.getElementById(noticia).style.cursor = "pointer";
    var noti = document.getElementById(noticia);
    var as = noti.getElementsByTagName('a');
    as[0].style.color= "#000000";

}

function rollOut(noticia){
    document.getElementById(noticia).style.background = '#fff';
    var noti = document.getElementById(noticia);
    var as = noti.getElementsByTagName('a');
    as[0].style.color= "#575656";
}

function rollOverNoticiaDetalle(noticia){
    document.getElementById(noticia).style.background = 'url(../img/degradado_listado_noticias.png) 0 0 no-repeat';
    document.getElementById(noticia).style.cursor = "pointer";
    var noti = document.getElementById(noticia);
    var as = noti.getElementsByTagName('a');
    as[0].style.color= "#000000";
}
    
function rollOutNoticiaDetalle(noticia){
    document.getElementById(noticia).style.background = '#fff';
    var noti = document.getElementById(noticia);
    var as = noti.getElementsByTagName('a');
    as[0].style.color= "#575656";
}

/*function irNoticia(noticia){
    var noti = document.getElementById(noticia);
    var as = noti.getElementsByTagName('a');
    document.location.href=as[0].href
}*/

function rollOverGaleria(img){
    document.getElementById(img).style.opacity = '0.60';
    document.getElementById(img).style.cursor = "pointer";
}

function rollOutGaleria(img){
    var principal = document.getElementById("galeria_principal").src;
    var p_barra = principal.lastIndexOf("/",principal.length);
    var num_img_principal = principal.substring(p_barra+1,principal.lastIndexOf("."));
    var num_img_img = img.substring(7,9);

    if(num_img_principal != num_img_img){
       document.getElementById(img).style.opacity = '1'; 
    }
     
}

function irNoticia(noticia){
    var noti = document.getElementById(noticia);
    var as = noti.getElementsByTagName('a');
    document.location.href=as[0].href
}

function cambiaFoto(foto){
    document.getElementById("galeria_principal").src=document.getElementById(foto).src;
    capaFotos();
}

function capaFotos(){
    var principal = document.getElementById("galeria_principal");
        var p_barra = principal.src.lastIndexOf("/",principal.src.length);
        var s_barra = principal.src.lastIndexOf("/",p_barra-1);
    var num_img = principal.src.substring(p_barra+1,principal.src.lastIndexOf("."));
    var anno = principal.src.substring(s_barra+1,p_barra);

    for(var c=1; c<=20; c++){
        if(c<10){
            c="0"+c;
        }
        var cadena_img2 = "g_"+anno+"_"+c;
        document.getElementById(cadena_img2).style.opacity = '1';
    }
    var cadena_img = "g_"+anno+"_"+num_img;
    document.getElementById(cadena_img).style.opacity = '0.60';
    
}

function rollFoto(ano,orden){
    var foto_anterior="";
    var foto_siguiente="";
    var principal = document.getElementById("galeria_principal");
    var valor_principal = document.getElementById("galeria_principal").src;
    var pos_punto = valor_principal.lastIndexOf('.');
    var num_foto = new Number (valor_principal.substring((pos_punto)-2,pos_punto));
    var foto_anterior_roll = "";
    
    if(orden==1){1
        if(num_foto== 01){//Anterior
            foto_anterior= "20";
        }else{
            foto_anterior = (num_foto)-1;
            if(foto_anterior<10){
                foto_anterior = "0"+foto_anterior;
            }
        }
        principal.src= "img/galeria/"+ano+"/"+foto_anterior+".jpg";
        capaFotos();
    }else if(orden==2){//Siguiente
        if(num_foto == 20){
            foto_siguiente = "01";
        }else{
            foto_siguiente = (num_foto)+1;
            if(foto_siguiente<10){
                foto_siguiente = "0"+foto_siguiente;
            }
        }
        principal.src= "img/galeria/"+ano+"/"+foto_siguiente+".jpg";
        capaFotos();
        }
}

function cargaNoticiasValorSelect2(){
    var v_select = document.getElementById("mes_ano").value;
    if(v_select != 00){
        document.location="noticias.php?v_select="+v_select;
    }else{
        document.location="noticias.php";
    }
}

function cargaNoticiasValorSelect3(id_noticia){
    var v_select = document.getElementById("annos_noticias").value;
    if(v_select != 00){
        document.location="noticia_detalle.php?id_noticia="+id_noticia+"&v_select="+v_select;
    }else{
        document.location="noticia_detalle.php?id_noticia="+id_noticia;
    }
}

function cambiaValorSelects(valor){
    document.getElementById("mes_ano").value=valor;
}

function cambiaValorSelects2(valor){
    document.getElementById("annos_noticias").value=valor;
}

function prueba2(ln){
            //alert("asd");
    var ln_cambiar = document.getElementById(ln);
    ln_cambiar.style.display = 'block';
    document.getElementById("ln_1").style.display = 'none';
}
