// JavaScript Document


function js_loading(ruta, id_capa){
	var capa = document.getElementById(id_capa);	
	if(capa){
		capa.innerHTML += "<p id='loading_img' style='text-align:center'><img src='"+ruta+"' alt='Cargando...' /></p>";
	}
}

function js_stoploading(id_capa){
	var eliminar = document.getElementById("loading_img");	
	var capa = document.getElementById(id_capa);	
	capa.removeChild(eliminar);
}

function dar_valor(id_campo, valor){
	var campo = document.getElementById(id_campo);	
	if(campo) campo.value = valor;
	
}

function submitar(name_form){
	var form = document.forms[name_form];
	if(form) form.submit();
}


 
 
function ocultar(id){
	var elem = document.getElementById(id);
	if(elem){
		elem.style.display = "none";	
	}
}

function mostrar(id){
	var elem = document.getElementById(id);
	if(elem){
		elem.style.display = "block";	
	}
}
function limpiar(id){
	var elem = document.getElementById(id);
	if(elem){
		elem.value = "";	
	}
}


// JavaScript Document
// CREAR UNA COOKIE CON TIEMPO DE EXPIRACION
function setCookie(name, value, expires, path, domain, secure)
{	
  document.cookie = name+"="+escape(value)+(expires ? "; expires="+expires.toGMTString() : "")+ (path    ? "; path="   +path   : "")+ (domain  ? "; domain=" +domain : "")+    (secure  ? "; secure" : "");
}


// CREAR UNA COOKIE CON LIFETIME
function setCookieLT(name, value, lifetime, path, domain, secure)
{
  if (lifetime)
    lifetime = new Date(Date.parse(new Date())+lifetime*1000);
  setCookie(name, value, lifetime, path, domain, secure);
}

// OBTIENE EL VALOR DE UNA COOKIE
function getCookie(name)
{
  var cookie = " "+document.cookie;
  var offset = cookie.indexOf(" "+name+"=");
  var end;
  
  if (offset == -1) return undefined;

  offset += name.length+2;
  end     = cookie.indexOf(";", offset)

  if (end == -1) end = cookie.length;

  return unescape(cookie.substring(offset, end));
}

// BORRA UNA COOKIE
function delCookie(name, path, domain)
{
  if (getCookie(name))
  {
    var date = new Date("January 01, 2000 00:00:01");
    setCookie(name, "", date, path, domain);
  }
}



function comprobar_cookie_textos(nombre){
	//alert(getCookie(nombre));	
	//alert(getCookie(nombre));
	if(getCookie(nombre)!=undefined){
		cambiar_tamano(getCookie(nombre));
	}
	
}

function cambiar_tamano(tamano){
	var cuerpo = document.getElementsByTagName("body");
	
	for(var i = 0; i < cuerpo.length; i++){
		cuerpo[i].style.fontSize = tamano + "%";
		setCookie("tamano_texto", tamano);		
	}
	
}

function cambiar_tamano_cookie(){
	var cuerpo = document.getElementsByTagName("body");
	
	for(var i = 0; i < cuerpo.length; i++){
		cuerpo[i].style.fontSize = getCookie("tamano_texto") + "%";
		setCookie("tamano_texto", tamano);		
	}
	
}

function cambiar_texto(accion){
	var cuerpo = document.getElementsByTagName("body");
	
	for(var i = 0; i < cuerpo.length; i++){
		var actual = cuerpo[i].style.fontSize.replace("%","");		
		var final = 0;
		
		if(accion == '+'){
			final = parseInt(actual)+10;
			cuerpo[i].style.fontSize = (final) + "%";	
			
		}else{
			final = parseInt(actual)-10;
			cuerpo[i].style.fontSize = (final) + "%";		
		}

		setCookie("tamano_texto", final);
		
		alert(getCookie("tamano_texto"));
	}
	
}
