// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
//
// nifty StyleSwitcher scripts modified by Aaron Jones 10/10/2002
// ----------------------------------------------

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);



// ----------------------------------------------
// Activa una hoja de estilos en función de la
// resolución de la pantalla del usuario
// ----------------------------------------------

function resolucion() {
	var ancho=window.screen.width ;
	switch(ancho){
		case 1280:
			setActiveStyleSheet('r1280');
			break;

		case 800:
			setActiveStyleSheet('r800');
			break;

		case 1024:
			setActiveStyleSheet('r1024');
			break;

		case 1088:
			setActiveStyleSheet('r1088');
			break;

		case 1152:
			setActiveStyleSheet('r1152');
			break;

	}
}





// Scarlet Blaze Article Tool 
// By: Jose Mulia
// http://www.scarletblaze.com
// Version: 1.1

ns4 = document.layers;
ie = document.all;
moz = document.getElementById && !document.all;
	 
function changeFontSize (id, isIncrease) {
	// 1 = increase
	// 0 = decrease
	var obj;
	var size; 

	if (ns4) {
		alert ("Sorry, but NS4 does not allow font changes.");
		return false;

	} else if (ie) { 
	 	// tested on ie6
		// the font value is increased/decreased in em;

		if (window.opera){
		 	// only tested on firefox
		 	// The next 2 lines work, but only return font size in px!
		 	// So the font value is increased/decreased in px;
			obj = window.getComputedStyle(document.getElementById(id), ''); 
			size = obj.getPropertyValue('font-size') ;  // value only in px

			if (isIncrease) {
				size = size = parseFloat(size) + 1; // increase 	
			} else {
				size = size = parseFloat(size) - 1; // decrease
			}
			document.getElementById(id).style['fontSize'] = size + "px";

		}else{
			obj = window.parent.document.getElementById(id);
			size = obj.currentStyle.fontSize;

			if (isIncrease) {
				size = parseFloat(size) + .1;	// increase 
			} else {
				size = parseFloat(size) - .1;  // decrease 
			}  
			obj.style.fontSize = size + "em";
		}

	} else if (moz) {
	 	// only tested on firefox
	 	// The next 2 lines work, but only return font size in px!
	 	// So the font value is increased/decreased in px;
		obj = window.getComputedStyle(document.getElementById(id), ''); 
		size = obj.getPropertyValue('font-size');  // value only in px

		 if (isIncrease) {
			size = size = parseFloat(size) + 1; // increase 	
		 } else {
			size = size = parseFloat(size) - 1; // decrease
		 }

		document.getElementById(id).style['fontSize'] = size + "px";
	}

	if (!obj) {
		alert("unrecognized ID");
		return false;
	}
   
	return true;
}

function changeAlignment (id, alignment) {
	// align: "right", "left", "justify"	
	var obj;

	if (ns4) {
		alert ("Sorry, but NS4 does not allow alignment change.");
		return false;
	} else if (ie) {
	 	// tested on ie6
		// the font value is increased/decreased in em;
		obj = document.getElementById(id);
		obj.style.textAlign = alignment;
	} else if (moz) {
	 	// only tested on firefox
		obj = window.getComputedStyle(document.getElementById(id), ''); 
		document.getElementById(id).style['textAlign'] = alignment;
	}

	if (!obj) {
		alert("unrecognized ID");
		return false;
	}
 
	return true;
}


function Favoritos(url, title){
	// Variable para distinguir si es el navegador Opera
	var ident = navigator.userAgent.toLowerCase();

	if(ident.indexOf("opera") != -1) {
		alert("Puse [Ctrl] + T");
	}else{ 
		if (document.all){
			window.external.AddFavorite(url, title);
		}else if(window.sidebar){
			window.sidebar.addPanel(title, url, "_top")
		}

	}
}

function toPrint() {
	window.print();
}



// ------------------------------------------------------------
// Script para correo: validar, ocultar y mostrar formulario
// de correo, correo webmaster y dar fecha actual.
// ------------------------------------------------------------



function dame_correo(){
	nombre="Contacta";
	usuario="corpus";
	dominio="segundarepublica.com";
	conector="@";
	correo = usuario + conector + dominio;
	document.write("<a href='mailto:" + correo + "' >" + nombre + "</a>");
}


function dame_fecha(){
	mesarray=new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio","Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
	diaarray=new Array( "Domingo","Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
	hoy = new Date();
	dias = hoy.getDate();
	dia = hoy.getDay();
	mes = hoy.getMonth();
	mes=mesarray[mes];
	dia =diaarray[dia];
	anno = hoy.getFullYear();
	document.write(dia+", "+dias+" "+" de "+mes+" de "+anno);
}



function mostrar(nombreCapa){
	if(document.getElementById(nombreCapa).style.visibility=="visible"){
		document.getElementById(nombreCapa).style.visibility="hidden";
		document.getElementById(nombreCapa).style.display="none";	
	}else{
		document.getElementById(nombreCapa).style.visibility="visible"; 
		document.getElementById(nombreCapa).style.display="";
	}		
}

function ValidarEmail(){
	valor=document.formulariocorreo.email.value;
	if (document.formulariocorreo.minombre.value==''){
		alert("Indique su nombre");
		document.formulariocorreo.minombre.focus();
	}else{
		if (document.formulariocorreo.sunombre.value==''){
			alert("Debe introducir el nombre de la persona a la que envía el artículo");
			document.formulariocorreo.sunombre.focus();
		}else{
       			if (document.formulariocorreo.email.value==''){
				alert("La dirección de correo no puede estar vacía");
				document.formulariocorreo.email.focus();
	               	}else{
	                	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
					document.formulariocorreo.submit();
				}else{
					document.formulariocorreo.email.focus();
					alert("La dirección de email es incorrecta.");
				}
			}
		}
	}
}