function Utils() {
	this.hideContainerShowChild = function(idContainer, idChild) {
		var _idContainer = "#" + idContainer;
		var _idChild = "#" + idChild;
		//Agafem tots els fills de tipus div del idContainer i els fem un hide
		$(_idContainer + ' > div').each(function(i) {
			$(this).hide();
		});

		//Agafo el idChild i el mostro
		$(_idChild).show();
	};
	
	this.showContainerHideChild = function(idContainer, idChild) {
		var _idContainer = "#" + idContainer;
		var _idChild = "#" + idChild;
		//Agafem tots els fills de tipus div del idContainer i els fem i els mostro
		$(_idContainer + ' > a').each(function(i) {
			$(this).show();
		});

		//Agafo el idChild i ho trec
		$(_idChild).hide();
	};

/*	
	this.clickThumb = function(idContainer, idChild) {
		hideContainerShowChild("imagen");
		hideContainerShowChild("caption");
		showContainerHideChild("thumb");
	};
*/
	
	this.selectMenu = function(idContainer, idChild) {
		alert("DEPRECATED");
		/*
		$("#menu li[@class='first select']").each(function() {
				var titulo = $(this).text();
				id = $(this).attr("id");
				var a = document.createElement("a");
				$(this).text("");
//				a.setAttribute("id",titulo);
				a.setAttribute("href","#");
				a.setAttribute("onclick","Utils.hideContainerShowChild('padre','" + id + "Div');Utils.selectMenu('padre','" + id + "'); return false;");
				a.appendChild(document.createTextNode(titulo));
				this.appendChild(a);

		});
		
		
		
		var _idContainer = "#menu";
		var _idChild = "#" + idChild;
		//Agafem tots els fills de tipus div del idContainer i els fem un hide
		$(_idContainer + ' li').each(function(i) {
			$(this).removeClass();
		});

		//Agafo el idChild i el mostro
		$(_idChild).addClass("first select");
		var texto = $(_idChild + " a").text();
		$(_idChild).html(texto);
		*/
	};
	
	this.selectPestanya = function(idPestanya, idOpcion, classSelected) {
		/*
		var liselect = "#menu" + idPestanya + " li[@class='" + classSelected + "']";
		$(liselect).each(function() {
				var titulo = $(this).text();
				id = $(this).attr("id");
				var a = document.createElement("a");
				$(this).text("");
				a.setAttribute("href","#");
				var onclick = "Utils.selectPestanya(" + idPestanya + ", '" + id + "', '"+ classSelected + "');";
				a.setAttribute("onclick",onclick);
				a.appendChild(document.createTextNode(titulo));
				this.appendChild(a);
		});
		*/
		
		var _idContainer = "#menu" + idPestanya;
		var _idChild = "#" + idOpcion;
		//Agafem tots els fills de tipus div del idContainer i els fem un hide
		$(_idContainer + ' li').each(function(i) {
			$(this).removeClass();
		});

		//Agafo el idChild i el mostro
		$(_idChild).addClass(classSelected);
		//var texto = $(_idChild + " a").text();
		//$(_idChild).html(texto);
		
		this.hideContainerShowChild("padre" + idPestanya, idOpcion + "Div");
		return false;
	};	
}

var Utils = new Utils();

// UTILITATS DE CRIDES AJAX DE LA VERSIO ANTIGA


function cridajax(p_div, p_url, p_pars) {
	if (p_pars == null || p_pars == "") {
		$("#" + p_div).load(p_url);
	} else {
		$("#" + p_div).load(p_url + "?" + p_pars);
	}
}
function cridajaxdetall(p_div, p_url, p_pars, p_method, p_eff) {
	cridajax(p_div, p_url, p_pars);
}
function nuvoltags(p_collection) {
	var params = "p_action=get_hot&p_collection=" + p_collection;
	cridajaxdetall("NuvolTag", "/cercadorgg/Cercador", params, "get", " ");
}
/** calendari busqueda*/
function pintaDies(selected) {
	if (selected == 0) {
		var d = new Date();
		selected = d.getDate();
	}
	for (var i = 1; i <= 31; i++) {
		if (selected == i) {
			document.write("<option value='" + pad(i) + "' selected='selected'>" + i + "</option>");
		} else {
			document.write("<option value='" + pad(i) + "'>" + i + "</option>");
		}
	}
}
function pintaMesos(selected) {
	if (selected == 0) {
		var d = new Date();
		selected = d.getMonth() + 1;
	}
	var mes = new Array("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");
	for (var i = 1; i <= 12; i++) {
		if (selected == i) {
			document.write("<option value='" + pad(i) + "' selected='selected'>" + mes[i - 1] + "</option>");
		} else {
			document.write("<option value='" + pad(i) + "'>" + mes[i - 1] + "</option>");
		}
	}
}
function pintaAnys(selected) {
	if (selected == 0) {
		var d = new Date();
		selected = d.getFullYear();
	}
	var d = new Date();
	for (var i = 1996; i <= d.getFullYear(); i++) {
		if (selected == i) {
			document.write("<option value='" + i + "' selected='selected'>" + i + "</option>");
		} else {
			document.write("<option value='" + i + "'>" + i + "</option>");
		}
	}
}
function pad(s) {
	return (("" + s).length > 1) ? s : "0" + s;
}
function putform(p_div, p_form, url) {
	if (url == null) {
		url = "/ajax/PublicAjax";
		//url = "http://www.lavanguardia.es/ajax/PublicAjax";
	} else {
		if (url == "action") {
			url = p_form.action;
		}
	}
	pars = "";
	var l_form = document.getElementById(p_form);
	if (l_form == null || l_form == "undefined") {
		l_form = p_form;
	}
	pars = getFormParameters(l_form);
	cridajax(p_div, url, pars);
}
function getFormParameters(p_form) {
	var p_pars = "";
	var e = $(p_form).get(0);
	var a = new Array();
	$(p_form).find("input[@checked], input[@type='hidden'],input[@type='text'], input[@type='password'], option[@selected], textarea").each(function () {
		o = {};
		o["name"] = this.name || this.id || this.parentNode.name || this.parentNode.id;
		o["value"] = $(this).val();
		p_pars = p_pars + o["name"] + "=" + escape(o["value"]) + "&";
	});
	return p_pars;
}

function publicaajax(p_div, p_capsa_id, p_cate_id, p_comp_id, p_pagi_id, p_form_id, p_urlback, p_pars)
{
 //url = "http://wwwd.lavanguardia.es/ajax/PublicAjax";
 url = "/ajax/PublicAjax";

 pars="";
 pars = pars+"p_capsa_id="+p_capsa_id;
 pars = pars+"&p_cate_id="+p_cate_id;
 pars = pars+"&p_comp_id="+p_comp_id;
 pars = pars+"&p_pagi_id="+p_pagi_id;
 pars = pars+"&p_form_id="+p_form_id;
 
 if (p_urlback!=null)
 {
  pars = pars+"&p_urlback="+p_urlback;
 }
 else
 {
  pars=pars+"&p_urlback="+escape(document.location);
 }
 if (p_pars!=null)
 {
   pars = pars+p_pars;
 }

 cridajax(p_div, url, pars);
}

function resetopcional (p_element, p_prefix)
{
  if (p_element.value.substr(0, p_prefix.length)==p_prefix)
  {
    p_element.value='';
  }
}


////////////////////CODI FONT-SIZE ///////////////////////////
var tamanyoBody = 1;

function fijarTamanyo(tamanyo) {
  setCookie( "tamanyoLetra", tamanyo, 100, "/" );
  tamanyoTexto=tamanyo+'em';
  document.body.style.fontSize=tamanyoTexto;
}

function aumentarTamanyo() {
  var tamanyo=getCookie("tamanyoLetra");
  if (tamanyo==null)
	tamanyo=tamanyoBody+0.1;
  else if (tamanyo<1.4)
	tamanyo=eval(tamanyo)+0.1;
  fijarTamanyo(tamanyo);
}
function disminuirTamanyo() {
  var tamanyo=getCookie("tamanyoLetra");
  if (tamanyo==null)
	tamanyo=tamanyoBody-0.1;
  else if (tamanyo>0.4)
	tamanyo=eval(tamanyo)-0.1;
  fijarTamanyo(tamanyo);
}
function iniciarTamanyo() {  
  var tamanyo=getCookie("tamanyoLetra");
  if (tamanyo==null)
	tamanyo=tamanyoBody;
  fijarTamanyo(tamanyo);

}
function reestablecerTamanyo() {
  var tamanyo=tamanyoBody;
  fijarTamanyo(tamanyo);

}

function display_object_properties(object_string) {
    // Almacenar el objeto actual
    var actual_object = eval(object_string)

    // Inicializar el mensaje
    var property_message = "Aquí tiene el valor de la propiedad del objeto " + 
                           object_string + ":\n\n"

    // Iterar a través de las propiedades del objeto
    for (var property_name in actual_object) {
        property_message += object_string + "." + property_name + " = " + 
                            actual_object[property_name] + " | "
    }
    
    // Mostrar el mensaje
    alert(property_message)

}
function setCookie(name,value,days,path,domain,secure) {
  var expires, date;
  if (typeof days == "number") {
    date = new Date();
    date.setTime( date.getTime() + (days*24*60*60*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name) {
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//Escritura bloque para videos
//archivowmv: url al archivo vmv
//ancho: dimension x
//alto: dimension y
//justificacion : alineacion del grafico : right, left, center
//autostart : true, false
function writeWindowsMedia(archivowmv, ancho, alto, justificacion, autostart, retornaCodigo)
{
	cadena= '<object CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="reproductorwmv" ' + 
		'width="' + ancho +
		'" height="' + alto +
		'" align="' + justificacion +
		'" type="application/x-oleobject">\n';
	cadena = cadena + '<param name="url" value="' + archivowmv + '" />\n'; 
	cadena = cadena + '<param name="AutoStart" value="' + autostart + '" />\n';
	cadena = cadena + '<embed type="application/x-mplayer2" src="' + archivowmv + '" width="' + ancho;
	cadena = cadena + '" height="' + alto + '" align="' + justificacion + '" autostart="' + autostart + '">\n';
	cadena = cadena + '</embed>\n';
	cadena = cadena + '</object>\n';
	
	//Escribimos el object
        if (retornaCodigo)
        {
                return cadena;

        }
        else
        {
                document.write(cadena);
        }
}

// funcio per a 'noticias en tu movil'
function mostrar(divId) {
	
	OCULTO="none";
	VISIBLE="block";

	switch (divId) {
	    case "movistar": 
			document.getElementById("orange").style.display=OCULTO;		
			document.getElementById("vodafone").style.display=OCULTO;		
			document.getElementById("movistar").style.display=VISIBLE;		
			document.getElementById("cualquiera").style.display=OCULTO;		

			document.getElementById("Opt2Orange").style.display=OCULTO;		
			document.getElementById("Opt2Vodafone").style.display=OCULTO;   
			document.getElementById("Opt2Movistar").style.display=VISIBLE;		
			document.getElementById("Opt2Cualquiera").style.display=OCULTO;
			
			document.getElementById("OptOrange").className="";
			document.getElementById("OptVodafone").className="";
			document.getElementById("OptMovistar").className="on";
			document.getElementById("OptCualquiera").className="";

			break;
		case "vodafone":
			document.getElementById("orange").style.display=OCULTO;		
			document.getElementById("vodafone").style.display=VISIBLE;		
			document.getElementById("OptVodafone").className="on";
			document.getElementById("movistar").style.display=OCULTO;		
			document.getElementById("cualquiera").style.display=OCULTO;		

			document.getElementById("Opt2Orange").style.display=OCULTO;		
			document.getElementById("Opt2Vodafone").style.display=VISIBLE;   
			document.getElementById("Opt2Movistar").style.display=OCULTO;		
			document.getElementById("Opt2Cualquiera").style.display=OCULTO;

			document.getElementById("OptOrange").className="";
			document.getElementById("OptVodafone").className="on";
			document.getElementById("OptMovistar").className="";
			document.getElementById("OptCualquiera").className="";

			break;
		case "orange":
			document.getElementById("orange").style.display=VISIBLE;		
			document.getElementById("vodafone").style.display=OCULTO;		
			document.getElementById("movistar").style.display=OCULTO;		
			document.getElementById("cualquiera").style.display=OCULTO;		

			document.getElementById("Opt2Orange").style.display=VISIBLE;		
			document.getElementById("Opt2Vodafone").style.display=OCULTO;		
			document.getElementById("Opt2Movistar").style.display=OCULTO;		
			document.getElementById("Opt2Cualquiera").style.display=OCULTO;   

			document.getElementById("OptOrange").className="on";
			document.getElementById("OptVodafone").className="";
			document.getElementById("OptMovistar").className="";
			document.getElementById("OptCualquiera").className="";

			break;
		default:
			document.getElementById("orange").style.display=OCULTO;		
			document.getElementById("vodafone").style.display=OCULTO;		
			document.getElementById("movistar").style.display=OCULTO;		
			document.getElementById("cualquiera").style.display=VISIBLE;

			document.getElementById("Opt2Orange").style.display=OCULTO;		
			document.getElementById("Opt2Vodafone").style.display=OCULTO;		
			document.getElementById("Opt2Movistar").style.display=OCULTO;		
			document.getElementById("Opt2Cualquiera").style.display=VISIBLE;   
			
			document.getElementById("OptOrange").className="";
			document.getElementById("OptVodafone").className="";
			document.getElementById("OptMovistar").className="";
			document.getElementById("OptCualquiera").className="on";

			break; 
		}
}

function calendarCapcelera(){
var mes = new Array("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");
	var d = new Date();
	document.write(d.getDate().toString() +" de "+mes[d.getMonth()]+" "+d.getFullYear().toString()+" ");
}
