/* FUNCION PARA ACHICAR EL TEXTO */
/* Afecta a todas los <p>, <h1> y <h3> del DIV#artículo */
var min=11;
var mid=14; 
var max=16;
function increaseFontSize() {
	var div = document.getElementById('articulo');
	var p = div.getElementsByTagName('p');
	var h1 = div.getElementsByTagName('h1');
	var h3 = div.getElementsByTagName('h3');

	for(i=0;i<p.length;i++) {
	  if(p[i].style.fontSize) {
		 var s = parseInt(p[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 12;
	  }
	  if(s!=max) {
		 s = max;
	  }
	  p[i].style.fontSize = s+"px"
	  p[i].style.lineHeight = s + 5 + "px";
	}
	for(i=0;i<h1.length;i++) {
	  if(h1[i].style.fontSize) {
		 var s = parseInt(h1[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 18;
	  }
	  if(s!=24) {
		 s = 24;
	  }
	  h1[i].style.fontSize = s+"px"
	}
	for(i=0;i<h3.length;i++) {
	  if(h3[i].style.fontSize) {
		 var s = parseInt(h3[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 12;
	  }
	  if(s!=16) {
		 s = 16;
	  }
	  h3[i].style.fontSize = s+"px"
	}
   	SetCookie('fontSize',11,1);
}
function midFontSize() {
	var div = document.getElementById('articulo');
	var p = div.getElementsByTagName('p');
	var h1 = div.getElementsByTagName('h1');
	var h3 = div.getElementsByTagName('h3');

	for(i=0;i<p.length;i++) {
	  if(p[i].style.fontSize) {
		 var s = parseInt(p[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 12;
	  }
	  if(s!=mid) {
		 s = mid;
	  }
	  p[i].style.fontSize = s+"px"
	  p[i].style.lineHeight = s + 5 + "px";
	}
	for(i=0;i<h1.length;i++) {
	  if(h1[i].style.fontSize) {
		 var s = parseInt(h1[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 18;
	  }
	  if(s!=20) {
		 s = 20;
	  }
	  h1[i].style.fontSize = s+"px"
	}
	for(i=0;i<h3.length;i++) {
	  if(h3[i].style.fontSize) {
		 var s = parseInt(h3[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 12;
	  }
	  if(s!=14) {
		 s = 14;
	  }
	  h3[i].style.fontSize = s+"px"
	}
   	SetCookie('fontSize',14,1);
}
function decreaseFontSize() {
	var div = document.getElementById('articulo');
	var p   = div.getElementsByTagName('p');
	var h1  = div.getElementsByTagName('h1');
	var h3  = div.getElementsByTagName('h3');

	for(i=0;i<p.length;i++) {
	  if(p[i].style.fontSize) {
		 var s = parseInt(p[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 12;
	  }
	  if(s!=min) {
		 s = min;
	  }
	  p[i].style.fontSize = s+"px";
	  p[i].style.lineHeight = s + 5 + "px";
	} 
	for(i=0;i<h1.length;i++) {
	  if(h1[i].style.fontSize) {
		 var s = parseInt(h1[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 18;
	  }
	  if(s!=18) {
		 s = 18;
	  }
	  h1[i].style.fontSize = s+"px"
	}
	for(i=0;i<h3.length;i++) {
	  if(h3[i].style.fontSize) {
		 var s = parseInt(h3[i].style.fontSize.replace("px",""));
	  } else {
		 var s = 12;
	  }
	  if(s!=12) {
		 s = 12;
	  }
	  h3[i].style.fontSize = s+"px"
	}
   	SetCookie('fontSize',16,1);
}


//Funciones de Cookies

//Creacion de una Cookie
function SetCookie(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

//Funcion para obtener el valor de una cookie
function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	
	if (begin == -1) 
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else 
	{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

//Funcion para Recordar el font seleccionado
function recordarFont()
{
	//obtengo el valor de la cookie
	var cookieFont = getCookie('fontSize');
	
	//Verifico si la cookie esta seteada con un valor
	if(cookieFont != "")
	{
		switch(cookieFont)
		{
			//Ejecuto la funcion de Incremento
			case "11": increaseFontSize();
				break;
			//Ejecuto la funcion de Mid
			case "14": midFontSize();
				break;
			//Ejecuto la funcion de Decremento
			case "16": decreaseFontSize();
				break;
		}
	}
}

