/*	Unobtrusive Flash Objects (UFO) v3.21 <http://www.bobbyvandersluis.com/ufo/>
	Copyright 2005, 2006 Bobby van der Sluis
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

var UFO = {
	req: ["movie", "width", "height", "majorversion", "build"],
	opt: ["play", "loop", "menu", "quality", "scale", "salign", "wmode", "bgcolor", "base", "flashvars", "devicefont", "allowscriptaccess", "seamlesstabbing", "allowfullscreen"],
	optAtt: ["id", "name", "align"],
	optExc: ["swliveconnect"],
	ximovie: "ufo.swf",
	xiwidth: "215",
	xiheight: "138",
	ua: navigator.userAgent.toLowerCase(),
	pluginType: "",
	fv: [0,0],
	foList: [],
		
	create: function(FO, id) {
		if (!UFO.uaHas("w3cdom") || UFO.uaHas("ieMac")) return;
		UFO.getFlashVersion();
		UFO.foList[id] = UFO.updateFO(FO);
		UFO.createCSS("#" + id, "visibility:hidden;");
		UFO.domLoad(id);
	},

	updateFO: function(FO) {
		if (typeof FO.xi != "undefined" && FO.xi == "true") {
			if (typeof FO.ximovie == "undefined") FO.ximovie = UFO.ximovie;
			if (typeof FO.xiwidth == "undefined") FO.xiwidth = UFO.xiwidth;
			if (typeof FO.xiheight == "undefined") FO.xiheight = UFO.xiheight;
		}
		FO.mainCalled = false;
		return FO;
	},

	domLoad: function(id) {
		var _t = setInterval(function() {
			if ((document.getElementsByTagName("body")[0] != null || document.body != null) && document.getElementById(id) != null) {
				UFO.main(id);
				clearInterval(_t);
			}
		}, 250);
		if (typeof document.addEventListener != "undefined") {
			document.addEventListener("DOMContentLoaded", function() { UFO.main(id); clearInterval(_t); } , null); // Gecko, Opera 9+
		}
	},

	main: function(id) {
		var _fo = UFO.foList[id];
		if (_fo.mainCalled) return;
		UFO.foList[id].mainCalled = true;
		document.getElementById(id).style.visibility = "hidden";
		if (UFO.hasRequired(id)) {
			if (UFO.hasFlashVersion(parseInt(_fo.majorversion, 10), parseInt(_fo.build, 10))) {
				if (typeof _fo.setcontainercss != "undefined" && _fo.setcontainercss == "true") UFO.setContainerCSS(id);
				UFO.writeSWF(id);
			}
			else if (_fo.xi == "true" && UFO.hasFlashVersion(6, 65)) {
				UFO.createDialog(id);
			}
		}
		document.getElementById(id).style.visibility = "visible";
	},
	
	createCSS: function(selector, declaration) {
		var _h = document.getElementsByTagName("head")[0]; 
		var _s = UFO.createElement("style");
		if (!UFO.uaHas("ieWin")) _s.appendChild(document.createTextNode(selector + " {" + declaration + "}")); // bugs in IE/Win
		_s.setAttribute("type", "text/css");
		_s.setAttribute("media", "screen"); 
		_h.appendChild(_s);
		if (UFO.uaHas("ieWin") && document.styleSheets && document.styleSheets.length > 0) {
			var _ls = document.styleSheets[document.styleSheets.length - 1];
			if (typeof _ls.addRule == "object") _ls.addRule(selector, declaration);
		}
	},
	
	setContainerCSS: function(id) {
		var _fo = UFO.foList[id];
		var _w = /%/.test(_fo.width) ? "" : "px";
		var _h = /%/.test(_fo.height) ? "" : "px";
		UFO.createCSS("#" + id, "width:" + _fo.width + _w +"; height:" + _fo.height + _h +";");
		if (_fo.width == "100%") {
			UFO.createCSS("body", "margin-left:0; margin-right:0; padding-left:0; padding-right:0;");
		}
		if (_fo.height == "100%") {
			UFO.createCSS("html", "height:100%; overflow:hidden;");
			UFO.createCSS("body", "margin-top:0; margin-bottom:0; padding-top:0; padding-bottom:0; height:100%;");
		}
	},

	createElement: function(el) {
		return (UFO.uaHas("xml") && typeof document.createElementNS != "undefined") ?  document.createElementNS("http://www.w3.org/1999/xhtml", el) : document.createElement(el);
	},

	createObjParam: function(el, aName, aValue) {
		var _p = UFO.createElement("param");
		_p.setAttribute("name", aName);	
		_p.setAttribute("value", aValue);
		el.appendChild(_p);
	},

	uaHas: function(ft) {
		var _u = UFO.ua;
		switch(ft) {
			case "w3cdom":
				return (typeof document.getElementById != "undefined" && typeof document.getElementsByTagName != "undefined" && (typeof document.createElement != "undefined" || typeof document.createElementNS != "undefined"));
			case "xml":
				var _m = document.getElementsByTagName("meta");
				var _l = _m.length;
				for (var i = 0; i < _l; i++) {
					if (/content-type/i.test(_m[i].getAttribute("http-equiv")) && /xml/i.test(_m[i].getAttribute("content"))) return true;
				}
				return false;
			case "ieMac":
				return /msie/.test(_u) && !/opera/.test(_u) && /mac/.test(_u);
			case "ieWin":
				return /msie/.test(_u) && !/opera/.test(_u) && /win/.test(_u);
			case "gecko":
				return /gecko/.test(_u) && !/applewebkit/.test(_u);
			case "opera":
				return /opera/.test(_u);
			case "safari":
				return /applewebkit/.test(_u);
			default:
				return false;
		}
	},
	
	getFlashVersion: function() {
		if (UFO.fv[0] != 0) return;  
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			UFO.pluginType = "npapi";
			var _d = navigator.plugins["Shockwave Flash"].description;
			if (typeof _d != "undefined") {
				_d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
				var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10);
				var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
				UFO.fv = [_m, _r];
			}
		}
		else if (window.ActiveXObject) {
			UFO.pluginType = "ax";
			try { // avoid fp 6 crashes
				var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			}
			catch(e) {
				try { 
					var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					UFO.fv = [6, 0];
					_a.AllowScriptAccess = "always"; // throws if fp < 6.47 
				}
				catch(e) {
					if (UFO.fv[0] == 6) return;
				}
				try {
					var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				}
				catch(e) {}
			}
			if (typeof _a == "object") {
				var _d = _a.GetVariable("$version"); // bugs in fp 6.21/6.23
				if (typeof _d != "undefined") {
					_d = _d.replace(/^\S+\s+(.*)$/, "$1").split(",");
					UFO.fv = [parseInt(_d[0], 10), parseInt(_d[2], 10)];
				}
			}
		}
	},

	hasRequired: function(id) {
		var _l = UFO.req.length;
		for (var i = 0; i < _l; i++) {
			if (typeof UFO.foList[id][UFO.req[i]] == "undefined") return false;
		}
		return true;
	},
	
	hasFlashVersion: function(major, release) {
		return (UFO.fv[0] > major || (UFO.fv[0] == major && UFO.fv[1] >= release)) ? true : false;
	},

	writeSWF: function(id) {
		var _fo = UFO.foList[id];
		var _e = document.getElementById(id);
		if (UFO.pluginType == "npapi") {
			if (UFO.uaHas("gecko") || UFO.uaHas("xml")) {
				while(_e.hasChildNodes()) {
					_e.removeChild(_e.firstChild);
				}
				var _obj = UFO.createElement("object");
				_obj.setAttribute("type", "application/x-shockwave-flash");
				_obj.setAttribute("data", _fo.movie);
				_obj.setAttribute("width", _fo.width);
				_obj.setAttribute("height", _fo.height);
				var _l = UFO.optAtt.length;
				for (var i = 0; i < _l; i++) {
					if (typeof _fo[UFO.optAtt[i]] != "undefined") _obj.setAttribute(UFO.optAtt[i], _fo[UFO.optAtt[i]]);
				}
				var _o = UFO.opt.concat(UFO.optExc);
				var _l = _o.length;
				for (var i = 0; i < _l; i++) {
					if (typeof _fo[_o[i]] != "undefined") UFO.createObjParam(_obj, _o[i], _fo[_o[i]]);
				}
				_e.appendChild(_obj);
			}
			else {
				var _emb = "";
				var _o = UFO.opt.concat(UFO.optAtt).concat(UFO.optExc);
				var _l = _o.length;
				for (var i = 0; i < _l; i++) {
					if (typeof _fo[_o[i]] != "undefined") _emb += ' ' + _o[i] + '="' + _fo[_o[i]] + '"';
				}
				_e.innerHTML = '<embed type="application/x-shockwave-flash" src="' + _fo.movie + '" width="' + _fo.width + '" height="' + _fo.height + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' + _emb + '></embed>';
			}
		}
		else if (UFO.pluginType == "ax") {
			var _objAtt = "";
			var _l = UFO.optAtt.length;
			for (var i = 0; i < _l; i++) {
				if (typeof _fo[UFO.optAtt[i]] != "undefined") _objAtt += ' ' + UFO.optAtt[i] + '="' + _fo[UFO.optAtt[i]] + '"';
			}
			var _objPar = "";
			var _l = UFO.opt.length;
			for (var i = 0; i < _l; i++) {
				if (typeof _fo[UFO.opt[i]] != "undefined") _objPar += '<param name="' + UFO.opt[i] + '" value="' + _fo[UFO.opt[i]] + '" />';
			}
			var _p = window.location.protocol == "https:" ? "https:" : "http:";
			_e.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + _objAtt + ' width="' + _fo.width + '" height="' + _fo.height + '" codebase="' + _p + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + _fo.majorversion + ',0,' + _fo.build + ',0"><param name="movie" value="' + _fo.movie + '" />' + _objPar + '</object>';
		}
	},
		
	createDialog: function(id) {
		var _fo = UFO.foList[id];
		UFO.createCSS("html", "height:100%; overflow:hidden;");
		UFO.createCSS("body", "height:100%; overflow:hidden;");
		UFO.createCSS("#xi-con", "position:absolute; left:0; top:0; z-index:1000; width:100%; height:100%; background-color:#fff; filter:alpha(opacity:75); opacity:0.75;");
		UFO.createCSS("#xi-dia", "position:absolute; left:50%; top:50%; margin-left: -" + Math.round(parseInt(_fo.xiwidth, 10) / 2) + "px; margin-top: -" + Math.round(parseInt(_fo.xiheight, 10) / 2) + "px; width:" + _fo.xiwidth + "px; height:" + _fo.xiheight + "px;");
		var _b = document.getElementsByTagName("body")[0];
		var _c = UFO.createElement("div");
		_c.setAttribute("id", "xi-con");
		var _d = UFO.createElement("div");
		_d.setAttribute("id", "xi-dia");
		_c.appendChild(_d);
		_b.appendChild(_c);
		var _mmu = window.location;
		if (UFO.uaHas("xml") && UFO.uaHas("safari")) {
			var _mmd = document.getElementsByTagName("title")[0].firstChild.nodeValue = document.getElementsByTagName("title")[0].firstChild.nodeValue.slice(0, 47) + " - Flash Player Installation";
		}
		else {
			var _mmd = document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		}
		var _mmp = UFO.pluginType == "ax" ? "ActiveX" : "PlugIn";
		var _uc = typeof _fo.xiurlcancel != "undefined" ? "&xiUrlCancel=" + _fo.xiurlcancel : "";
		var _uf = typeof _fo.xiurlfailed != "undefined" ? "&xiUrlFailed=" + _fo.xiurlfailed : "";
		var _ecoLogo = "&logo=/imagenes/logos/economista-video.png";
		var _ecoAutostart = "&autostart=false";
		var _ecoRepeat = "&repeat=false";
		var _ecoShowfsbutton = "&shofsbutton=false";

		UFO.foList["xi-dia"] = { movie:_fo.ximovie, width:_fo.xiwidth, height:_fo.xiheight, majorversion:"6", build:"65", flashvars:"MMredirectURL=" + _mmu + "&MMplayerType=" + _mmp + "&MMdoctitle=" + _mmd + _uc + _uf };

/*
		UFO.foList["xi-dia"] = { movie:_fo.ximovie, width:_fo.xiwidth, height:_fo.xiheight, majorversion:"6", build:"65", flashvars:"MMredirectURL=" + _mmu + "&MMplayerType=" + _mmp + "&MMdoctitle=" + _mmd + _uc + _uf + _ecoLogo + _ecoAutostart + _ecoRepeat + _ecoShowfsbutton};
*/
		UFO.writeSWF("xi-dia");
	},

	expressInstallCallback: function() {
		var _b = document.getElementsByTagName("body")[0];
		var _c = document.getElementById("xi-con");
		_b.removeChild(_c);
		UFO.createCSS("body", "height:auto; overflow:auto;");
		UFO.createCSS("html", "height:auto; overflow:auto;");
	},

	cleanupIELeaks: function() {
		var _o = document.getElementsByTagName("object");
		var _l = _o.length
		for (var i = 0; i < _l; i++) {
			_o[i].style.display = "none";
			for (var x in _o[i]) {
				if (typeof _o[i][x] == "function") {
					_o[i][x] = null;
				}
			}
		}
	}

};

if (typeof window.attachEvent != "undefined" && UFO.uaHas("ieWin")) {
	window.attachEvent("onunload", UFO.cleanupIELeaks);
}
function getCookie( name ) {
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
    return null;
  }
  if ( start == -1 ) return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}
function setCookie( name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name+"="+escape( value ) +
    ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}
function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
miListaValores = Class.create();
miListaValores.prototype = {
	initialize : function() {
		this.idDiv_Reducido = 'mis_favoritos_reducido';
		this.idDiv_Reducido_Visitadas = 'mis_favoritos_reducido_visitadas';
		this.url_miLista_Reducido = '/mi-lista-cotizaciones/index.php';
		this.idDiv_Ampliado = 'mis_favoritos_ampliado';
		this.url_miLista_Ampliado = '/mi-lista-cotizaciones/index_Completo.php';
		this.url_miLista_JSON = '/mi-lista-cotizaciones/index_JSON.php';
		this.url_miLista_Individual = '/mi-lista-cotizaciones/index_Individual.php';
	
		this.miLista_Reducido_Cargada = false;
		
		this.idIndividual_Reducido = 'mini_';
		this.idIndividual_Completo = 'individual_';
		this.idIndividual_Completo_Tabla = 'tabla_';
		this.idIndividual_Listado = 'Quote_';
		this.idIndividual_Listado_Grafico = 'Quote_Grafico_';
		this.idIndividual_Listado_Link = 'Quote_Link_';
		this.idDiv_Quote_Activar_Modo_Automatico='Quote_Activar_Modo_Automatico';
		this.idDiv_Quote_Activar_Modo_Manual='Quote_Activar_Modo_Manual';
		this.idDiv_Quote_Texto_Mini='Quote_Texto_Mini';
		
		this.temp_Quote= '';
		this.cookies_quotes_fecha = 'cot_visitadas_fecha';
		this.cookies_quotes = 'cot_visitadas';
		this.cookies_quotes_rastreo = 'rastreo_automatico';
		this.LeerLista_Reducido();
	},
	
	LeerLista_Reducido: function() {
		miAjax = new Ajax.Request(
						this.url_miLista_Reducido,
						{
							method: 'get',
							onComplete: this.escribirListaReducido.bind(this)
						}
					);
		
	},
	LeerLista_Ampliado: function() {
		miAjax = new Ajax.Request(
						this.url_miLista_Ampliado,
						{
							method: 'get',
							onComplete: this.escribirListaAmpliado.bind(this)
						}
					);
	},
	
	LeerLista_JSON: function() {
		miAjax = new Ajax.Request(
						this.url_miLista_JSON,
						{
							method: 'get',
							onComplete: this.escribirListaJSON.bind(this)
						}
					);
	},
	LeerLista_Individual: function() {
		var pars = '';
		
		pars = 'quote='+this.temp_Quote;
		miAjax = new Ajax.Request(
						this.url_miLista_Individual,
						{
							method: 'get',
							parameters: pars, 
							onComplete: this.escribirListaIndividual.bind(this)
						}
					);
	},
	LeerLista_Individual_Reducido: function() {
		var pars = '';
		
		pars = 'quote='+this.temp_Quote;
		miAjax = new Ajax.Request(
						this.url_miLista_Individual,
						{
							method: 'get',
							parameters: pars, 
							onComplete: this.escribirListaIndividual_Reducido.bind(this)
						}
					);
	},
	ReservarEspacio: function() {
		new Insertion.Top(this.idDiv_Ampliado, '<div id="'+this.idIndividual_Completo+this.temp_Quote+'" style="text-align:center; height: 230px; overflow: hidden;"><img src="/imag/ajax-loader.gif" width="220" height="19" style="margin-top: 115px;"></img></div>');
	},
	escribirListaReducido: function(originalRequest) {
		$(this.idDiv_Reducido).innerHTML = originalRequest.responseText;
		this.Ajustar_Cotizaciones_Reducido(5);	
		this.miLista_Reducido_Cargada = true;
		
		if (this.temp_Quote!='')
			this.Visitar_Quote(this.temp_Quote);
		rastreo_automatico = getCookie(this.cookies_quotes_rastreo);
		if (rastreo_automatico==null)  rastreo_automatico='1';
		if (rastreo_automatico=='1') 
			$(this.idDiv_Quote_Texto_Mini).innerHTML = 'VISITADAS: ';
		else
			$(this.idDiv_Quote_Texto_Mini).innerHTML = 'FAVORITOS: ';		
	},
	escribirListaAmpliado: function(originalRequest) {
		$(this.idDiv_Ampliado).innerHTML = originalRequest.responseText;
	},
	escribirListaJSON: function(originalRequest) {
		var cotizaciones_JSON = originalRequest.responseText;
		
		var Quotes = eval('(' + cotizaciones_JSON + ')');
	
		Quotes.Quote.each(function(s) {
								   miVar = $('Quote_'+s.nombreQuote);
								   if (miVar) {
										$('Quote_'+s.nombreQuote).innerHTML = '&nbsp;';
									   
								   }
									miVar = $('Quote_Grafico_'+s.nombreQuote);
								   if (miVar)
										Effect.Fade('Quote_Grafico_'+s.nombreQuote, { to: "0.25"});																		
									miVar = $('Quote_Link_'+s.nombreQuote);
									if (miVar)
										miVar.setAttribute('onclick','');
										
								   });
		
	},
	
	escribirListaIndividual: function(originalRequest) {
		mDatos = originalRequest.responseText.split("#####");
		
		Datos_Quote_Completo = mDatos[0];
		Datos_Quote_Individual = mDatos[1];
		Datos_Quote_JSON = eval('(' + mDatos[2] + ')');
		
		Quote = Datos_Quote_JSON.Quote[0].nombreQuote;
		$(this.idIndividual_Completo+Quote).innerHTML = mDatos[0];
		new Insertion.Top(this.idDiv_Reducido_Visitadas, mDatos[1]);
		new Effect.Highlight(this.idIndividual_Completo_Tabla+Quote, {duration:1.0, startcolor:'#ffff99', endcolor:'#ffffff'});
		new Effect.Highlight(this.idIndividual_Reducido+Quote, {duration:1.0, startcolor:'#ffff99', endcolor:'#ffffff'});
	},
	
	escribirListaIndividual_Reducido : function(originalRequest) {
		mDatos = originalRequest.responseText.split("#####");
		
		new Insertion.Top(this.idDiv_Reducido_Visitadas, mDatos[1]);
	
		new Effect.Highlight(this.idIndividual_Reducido+this.temp_Quote, {duration:1.0, startcolor:'#ffff99', endcolor:'#ffffff'});
	
	},
	Anadir_Quote :function (nombre_quote)  {
		this.temp_Quote = nombre_quote;
		this.Cookie_Rastreo_Automatico_Detener();
		this.Cookie_Anadir_Cotizacion();
		
		this.ReservarEspacio();
		this.LeerLista_Individual();
	
		$(this.idIndividual_Listado+this.temp_Quote).innerHTML = '&nbsp;';
		if ($(this.idIndividual_Listado_Link+nombre_quote))
			$(this.idIndividual_Listado_Link+nombre_quote).setAttribute('onclick','');
		
		if ($(this.idIndividual_Listado_Grafico+this.temp_Quote))
			Effect.Fade(this.idIndividual_Listado_Grafico+this.temp_Quote, { to: "0.25"});
		
		this.Ajustar_Cotizaciones_Reducido(4);
		this.Ajustar_Cotizaciones_Completo(9);
	},
	Quitar_Quote : function(nombre_quote) {
		this.temp_Quote = nombre_quote;
		
		this.Cookie_Eliminar_Cotizacion();
		
		if ($(this.idIndividual_Listado+this.temp_Quote)) {
			$(this.idIndividual_Listado+this.temp_Quote).innerHTML = '<a href="#" class="poner" onClick="miLista.Anadir_Quote(\''+this.temp_Quote+'\');return false">A&ntilde;adir favorito</a>';
		}
		if ($(this.idIndividual_Listado_Grafico+this.temp_Quote)) {
			Effect.Appear(this.idIndividual_Listado_Grafico+nombre_quote, {to:"1.0"});
		}
		if ($(this.idIndividual_Listado_Link+this.temp_Quote)) {
			$(this.idIndividual_Listado_Link+this.temp_Quote).setAttribute('onclick','miLista.Anadir_Quote(\''+this.temp_Quote+'\');return false');
		}
		if ($(this.idIndividual_Completo+this.temp_Quote))
			Element.remove(this.idIndividual_Completo+this.temp_Quote);
		if ($(this.idIndividual_Reducido+this.temp_Quote))
			Element.remove(this.idIndividual_Reducido+this.temp_Quote);
		this.Ajustar_Cotizaciones_Reducido(5);
		this.Ajustar_Cotizaciones_Completo(10);
	},
	Visitar_Quote: function(nombre_quote)
	{
		rastreo_automatico = getCookie(this.cookies_quotes_rastreo);
		if (rastreo_automatico==null)  rastreo_automatico='1';
		if (rastreo_automatico=='1') {
			this.temp_Quote = nombre_quote;
	
			if (this.miLista_Reducido_Cargada) {
				if ($(this.idIndividual_Reducido+this.temp_Quote)) {
					Element.remove(this.idIndividual_Reducido+this.temp_Quote);
				}
				
				this.Cookie_Anadir_Cotizacion();
				this.LeerLista_Individual_Reducido();
				
				this.Ajustar_Cotizaciones_Reducido(4);
				this.Visitar_Quote_Realizado = true;
			}
			else {
				this.Visitar_Quote_Realizado = false;
			}
		}
	},
	
	Ajustar_Cotizaciones_Reducido : function (numero) {
		var paras = $A(document.getElementsByClassName('val'));
		paras.each(
			function(s,index) 
			{
				if (index>=numero) 
					Element.hide(s);
				else 
			   		Element.show(s);
			}
		);
	},
	
	Ajustar_Cotizaciones_Completo : function (numero) {
		var paras = $A(document.getElementsByClassName('tablaper'));
		paras.each(
			function(s,index) 
			{
				vQuote = s.readAttribute('quote');
				temp_Completo = 'individual_'+vQuote;
				if (index<numero) {
					if ($(temp_Completo)){
						Element.show(temp_Completo);
					}
				}
				else {
					nombre_listado = 'Quote_'+vQuote;
					if ($(nombre_listado)) {
						$(nombre_listado).innerHTML = '<a href="#" class="poner" onClick="miLista.Anadir_Quote(\''+vQuote+'\');return false">A&ntilde;adir favorito</a>';						
					}
					nombre_listado = 'Quote_Grafico_'+vQuote;
					if ($(nombre_listado)) {
						Effect.Appear(nombre_listado, {to:"1.0"});
					}
					nombre_listado = 'Quote_Link_'+vQuote;
					if ($(nombre_listado)) {
						$(nombre_listado).setAttribute('onclick','miLista.Anadir_Quote(\''+vQuote+'\');return false');
					}
					if ($(temp_Completo)){
						Element.remove(temp_Completo);
					}
					
					if ($('mini_'+vQuote)) {
						Element.remove('mini_'+vQuote);
					}
				}
			}
		);
	},
	Cookie_ordenarFecha:function (a, b)
	{
		var fecha_a = new Date();
		var fecha_b = new Date();
	
		var valores_a = a.split("#");
		var valores_b = b.split("#");
	
	
		array_fecha_a = valores_a[1].split("-");
			fecha_a.setDate(array_fecha_a[2]);
			fecha_a.setMonth(array_fecha_a[1]-1);
			fecha_a.setYear(array_fecha_a[0]);
			
			fecha_a.setHours(array_fecha_a[3]);
			fecha_a.setMinutes(array_fecha_a[4]);
			fecha_a.setSeconds(array_fecha_a[5]);
			
	
		array_fecha_b = valores_b[1].split("-");
			fecha_b.setDate(array_fecha_b[2]);
			fecha_b.setMonth(array_fecha_b[1]-1);
			fecha_b.setYear(array_fecha_b[0]);
	
			fecha_b.setHours(array_fecha_b[3]);
			fecha_b.setMinutes(array_fecha_b[4]);
			fecha_b.setSeconds(array_fecha_b[5]);
	
		if (fecha_a>fecha_b) 
			return -1;
		else if (fecha_a==fecha_b) 
			return 0;
		else 
			return 1;
	},
	Cookie_Eliminar_Cotizacion: function() 
	{
		var cadena_inicializada;
		var nombre_corto = this.temp_Quote.toUpperCase();
		
		cValue = getCookie(this.cookies_quotes_fecha);
		cValue_Solo = getCookie(this.cookies_quotes);
			
		cValue_Solo = cValue_Solo.replace(","+nombre_corto, "");	
		cValue_Solo = cValue_Solo.replace(nombre_corto+",", "");	
		cValue_Solo = cValue_Solo.replace(nombre_corto, "");	
	
		cadena_texto="";
		mArray = cValue.split(",");
		
		cadena_inicializada = false;
		
		for (i=0;i<mArray.length;i++){
			if (mArray[i]!='') {
				valores = mArray[i].split("#");
		
				if (valores[0]!=nombre_corto) {
					if (valores[0]!='')
						if (cadena_texto!='') cadena_texto+=',';
					cadena_texto+=valores[0]+"#"+valores[1];
				}
			}
		}
	
		cValue=cadena_texto;
	
		setCookie (this.cookies_quotes_fecha, cValue, 365,'/', null, null);
		setCookie (this.cookies_quotes, cValue_Solo, 365,'/', null, null);
	},
	Cookie_Anadir_Cotizacion : function (){
		var pars = '';
		var cValue = '';	
		var cValue_Solo = '';	
		var cadena_texto = '';
		var cadena_texto_copia = '';
		var nextDay = new Date();
		var num_maximo = 10;
		var numero_elementos;
		var eliminado;
		var mArray;
		var mArray_Copia;
		var valor;
		var valores;
		var nombre_corto;
		
		nombre_corto = this.temp_Quote.toUpperCase();
		nextDay.setDate(nextDay.getDate()+30);
	
		cValue = getCookie(this.cookies_quotes_fecha);
		cValue_Solo = getCookie(this.cookies_quotes);
		if (cValue==null) cValue='';
		if (cValue_Solo==null) cValue_Solo='';
			
		strNextDate = nextDay.getFullYear()+'-'+(nextDay.getMonth()+1)+'-'+nextDay.getDate()+'-'+nextDay.getHours()+'-'+nextDay.getMinutes()+'-'+nextDay.getSeconds();
		
	
		if 	(cValue.indexOf(nombre_corto.toUpperCase()+"#")==-1) {
			/*
				El valor no existe en la cadena : 
				Se pone al final y se ordena 
			*/
			
			if (cValue!='')
				cValue+=',';
			if (cValue_Solo!='')
				cValue_Solo+=',';
			cValue+=nombre_corto.toUpperCase()+'#'+strNextDate;
			cValue_Solo+=nombre_corto.toUpperCase();
			mArray = cValue.split(",");
			mArray_Copia = cValue_Solo.split(",");
	
			numero_elementos = mArray.length;
			if (numero_elementos>num_maximo) {
				mArray.sort(this.Cookie_ordenarFecha);
				mArray_Copia.sort();
				cValue_Solo=mArray_Copia.toString();
	
				for(i=0;i<numero_elementos-num_maximo;i++){
					eliminado = mArray.pop();
					valor = eliminado.split("#");
					cValue_Solo = cValue_Solo.replace(valor[0]+",", "");	
					cValue_Solo = cValue_Solo.replace(valor[0], "");	
				}		
				mArray.sort();
				cValue=mArray.toString();
				if (cValue[0]==',') cValue[0]="";
			}
			else {
				mArray.sort();
				mArray_Copia.sort();
				cValue=mArray.toString();
				cValue_Solo=mArray_Copia.toString();
			}
		}
		else {
			/* 
				El valor existe en la cadena
			*/
			hoy = new Date();
			fecha = new Date();
	
			mArray = cValue.split(",");
			
			for (i=0;i<mArray.length;i++){
				valores = mArray[i].split("#");
				array_fecha = valores[1].split("-");
	
	
				if (valores[0]!=nombre_corto){
					// No es el valor que se esta visitando 
					// Si la fecha de hoy es mayor que la fecha de validez, se quita el valor 
					fecha.setDate(array_fecha[2]);
					fecha.setMonth(array_fecha[1]-1);
					fecha.setYear(array_fecha[0]);
					
					if (hoy>fecha){
						// Se quita el valor 
						valores[0]="";
						valores[1]="";
					}
					else {
						if (cadena_texto!="") 
							cadena_texto += ",";
						if (cadena_texto_copia!="")
							cadena_texto_copia += ",";
						cadena_texto+=valores[0]+"#"+valores[1];
						cadena_texto_copia+=valores[0];
					}
				}
				else {
					//	Es el valor :
					//	Se actualiza la fecha de validez 
					valores[1] = strNextDate;
					if (cadena_texto!="") 
						cadena_texto += ",";
					if (cadena_texto_copia!="")
						cadena_texto_copia += ",";
					cadena_texto+=valores[0]+"#"+valores[1];
					cadena_texto_copia+=valores[0];
				}
				
				mArray[i]=valores[0]+valores[1];
			}
			cValue=cadena_texto;
			cValue_Solo = cadena_texto_copia;
		}
			
		setCookie (this.cookies_quotes_fecha, cValue, 365,'/', null, null);
		setCookie (this.cookies_quotes, cValue_Solo, 365,'/', null, null);
	},
	Cookie_Rastreo_Automatico_Detener : function() {
		rastreo_automatico = getCookie(this.cookies_quotes_rastreo);
		if (rastreo_automatico==null)  rastreo_automatico='1';
		setCookie (this.cookies_quotes_rastreo, '0', 365,'/', null, null);		
		$(this.idDiv_Quote_Activar_Modo_Automatico).removeClassName('select');
		$(this.idDiv_Quote_Activar_Modo_Manual).addClassName('select');
		$(this.idDiv_Quote_Texto_Mini).innerHTML = 'FAVORITOS: ';		
		if (rastreo_automatico=='1') {
		new Effect.Highlight(this.idDiv_Quote_Texto_Mini, {duration:1.0, startcolor:'#ffff99', endcolor:'#ffffff'});
		}
	},
	Cookie_Rastreo_Automatico_Activar : function() {
		rastreo_automatico = getCookie(this.cookies_quotes_rastreo);
		if (rastreo_automatico==null)  rastreo_automatico='1';
		setCookie (this.cookies_quotes_rastreo, '1', 365,'/', null, null);		
		$(this.idDiv_Quote_Activar_Modo_Manual).removeClassName('select');
		$(this.idDiv_Quote_Activar_Modo_Automatico).addClassName('select');
		$(this.idDiv_Quote_Texto_Mini).innerHTML = 'VISITADAS: ';
		
		if (rastreo_automatico=='0') {
			new Effect.Highlight(this.idDiv_Quote_Texto_Mini, {duration:1.0, startcolor:'#ffff99', endcolor:'#ffffff'});		
		}
	},
	Cookie_Rastreo_Automatico_Decidir : function() {
		rastreo_automatico = getCookie(this.cookies_quotes_rastreo);
		if (rastreo_automatico==null)  rastreo_automatico='1';
		if (rastreo_automatico=='1') {
			$(this.idDiv_Quote_Activar_Modo_Automatico).addClassName('select');
		}
		else {
			$(this.idDiv_Quote_Activar_Modo_Manual).addClassName('select');
		}
	}
}
var idDivSondeo;
function LeerSondeo(identificador, url){
	var pars = '';
	
	idDivSondeo= identificador;
	var myAjax = new Ajax.Updater(identificador, url, {method: 'get', parameters: pars});
/*
	var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: escribirRespuesta
			});
*/	
}
function escribirRespuesta_Sondeos(originalRequest)
{
	$(idDivSondeo).innerHTML = originalRequest.responseText;
}
function enviarDatos(poll_id, identificador, form_Name_from, variable_name_from)
{
	var opcion_seleccionada = -1;
	var URL = '/sondeos/index.php';
	
	var i;
	
	var total = document.forms[form_Name_from][variable_name_from].length;
	if (isNaN(total)) {
		if (document.forms[form_Name_from][variable_name_from].checked){
			opcion_seleccionada = document.forms[form_Name_from][variable_name_from].value;
		}
	}
	for (i=0;i < total;i++){
		if (document.forms[form_Name_from][variable_name_from][i].checked) {
			opcion_seleccionada = document.forms[form_Name_from][variable_name_from][i].value;
		}
	}
	
	if (opcion_seleccionada==-1) {
		alert("Selecciona una opcion");
		return false;
	}
	var pars = 'poll_id='+poll_id;
	pars += '&poll_ident='+poll_id;
	pars += '&action=vote';
	pars += '&option_id=' + opcion_seleccionada;
		
	var target = identificador; 
	var myAjax = new Ajax.Updater(target, URL, {method: 'get', parameters: pars});
	
	return false;
}
function enviarDatos_Titulo(poll_id, identificador, form_Name_from, variable_name_from)
{
        var opcion_seleccionada = -1;
        var URL = '/sondeos/index_Titulo.php';
        var i;
        var total = document.forms[form_Name_from][variable_name_from].length;
        if (isNaN(total)) {
                if (document.forms[form_Name_from][variable_name_from].checked){
                        opcion_seleccionada = document.forms[form_Name_from][variable_name_from].value;
                }
        }
        for (i=0;i < total;i++){
                if (document.forms[form_Name_from][variable_name_from][i].checked) {
                        opcion_seleccionada = document.forms[form_Name_from][variable_name_from][i].value;
                }
        }
        if (opcion_seleccionada==-1) {
                alert("Selecciona una opcion");
                return false;
        }
        var pars = 'poll_id='+poll_id;
        pars += '&poll_ident='+poll_id;
        pars += '&action=vote';
        pars += '&option_id=' + opcion_seleccionada;
        var target = identificador;
        var myAjax = new Ajax.Updater(target, URL, {method: 'get', parameters: pars});
        return false;
}
function verResultados(poll_id, identificador)
{
	var URL = '/sondeos/index.php';
	
	var pars = 'poll_id='+poll_id
	
	pars += '&poll_ident='+poll_id;
	pars += '&action=results';
		
	var target = identificador; 
	var myAjax = new Ajax.Updater(target, URL, {method: 'get', parameters: pars});
	
	return false;
}
function verResultados_Completo(poll_id, identificador)
{
        var URL = '/sondeos/index_Completo.php';
        var pars = 'poll_id='+poll_id
        pars += '&poll_ident='+poll_id;
        pars += '&action=results';
        var target = identificador;
        var myAjax = new Ajax.Updater(target, URL, {method: 'get', parameters: pars});
        return false;
}
function verResultados_Titulo(poll_id, identificador)
{
	var URL = '/sondeos/index_Titulo.php';
	
	var pars = 'poll_id='+poll_id
	
	pars += '&poll_ident='+poll_id;
	pars += '&action=results';
		
	var target = identificador; 
	var myAjax = new Ajax.Updater(target, URL, {method: 'get', parameters: pars});
	
	return false;
}
masNoticias = Class.create();
masNoticias.prototype = {
	initialize: function(idDivMostrar, idDivTagMostrar) {
		this.idDivMostrar = idDivMostrar;
		this.idDivTagMostrar = idDivTagMostrar;
	},
	
	ocultar: function(id) {
		Element.hide(id);
	},
	
	mostrar: function(idTag, id) {
		//this.ocultar(this.idDivMostrar);
		
		Element.hide(this.idDivMostrar);
		Element.removeClassName(this.idDivTagMostrar, 'select');
		Element.show(id);
		Element.addClassName(idTag, 'select');
		
		this.idDivMostrar = id;
		this.idDivTagMostrar = idTag;
	}
}
function enviarNoticiaLeida(idNoticia){
     var url = '/noticias-categoria/noticia_leida.php';
	 var pars = 'id='+idNoticia;
	var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars});
	return false;
}
/*
* Really easy field validation with Prototype
* http://tetlaw.id.au/view/javascript/really-easy-field-validation
* Andrew Tetlaw
* Version 1.5.4.1 (2007-01-05)
* 
* Copyright (c) 2007 Andrew Tetlaw
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* 
*/
var Validator = Class.create();

Validator.prototype = {
	initialize : function(className, error, test, options) {
		if(typeof test == 'function'){
			this.options = $H(options);
			this._test = test;
		} else {
			this.options = $H(test);
			this._test = function(){return true};
		}
		this.error = error || 'Validation failed.';
		this.className = className;
	},
	test : function(v, elm) {
		return (this._test(v,elm) && this.options.all(function(p){
			return Validator.methods[p.key] ? Validator.methods[p.key](v,elm,p.value) : true;
		}));
	}
}
Validator.methods = {
	pattern : function(v,elm,opt) {return Validation.get('IsEmpty').test(v) || opt.test(v)},
	minLength : function(v,elm,opt) {return v.length >= opt},
	maxLength : function(v,elm,opt) {return v.length <= opt},
	min : function(v,elm,opt) {return v >= parseFloat(opt)}, 
	max : function(v,elm,opt) {return v <= parseFloat(opt)},
	notOneOf : function(v,elm,opt) {return $A(opt).all(function(value) {
		return v != value;
	})},
	oneOf : function(v,elm,opt) {return $A(opt).any(function(value) {
		return v == value;
	})},
	is : function(v,elm,opt) {return v == opt},
	isNot : function(v,elm,opt) {return v != opt},
	equalToField : function(v,elm,opt) {return v == $F(opt)},
	notEqualToField : function(v,elm,opt) {return v != $F(opt)},
	include : function(v,elm,opt) {return $A(opt).all(function(value) {
		return Validation.get(value).test(v,elm);
	})}
}

var Validation = Class.create();

Validation.prototype = {
	initialize : function(form, options){
		this.options = Object.extend({
			onSubmit : true,
			stopOnFirst : false,
			immediate : false,
			focusOnError : true,
			useTitles : false,
			onFormValidate : function(result, form) {},
			onElementValidate : function(result, elm) {}
		}, options || {});
		this.form = $(form);
		if(this.options.onSubmit) Event.observe(this.form,'submit',this.onSubmit.bind(this),false);
		if(this.options.immediate) {
			var useTitles = this.options.useTitles;
			var callback = this.options.onElementValidate;
			Form.getElements(this.form).each(function(input) { // Thanks Mike!
				Event.observe(input, 'blur', function(ev) { Validation.validate(Event.element(ev),{useTitle : useTitles, onElementValidate : callback}); });
			});
		}
	},
	onSubmit :  function(ev){
		if(!this.validate()) Event.stop(ev);
	},
	validate : function() {
		var result = false;
		var useTitles = this.options.useTitles;
		var callback = this.options.onElementValidate;
		if(this.options.stopOnFirst) {
			result = Form.getElements(this.form).all(function(elm) { return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback}); });
		} else {
			result = Form.getElements(this.form).collect(function(elm) { return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback}); }).all();
		}
		if(!result && this.options.focusOnError) {
			Form.getElements(this.form).findAll(function(elm){return $(elm).hasClassName('validation-failed')}).first().focus()
		}
		this.options.onFormValidate(result, this.form);
		return result;
	},
	reset : function() {
		Form.getElements(this.form).each(Validation.reset);
	}
}

Object.extend(Validation, {
	validate : function(elm, options){
		options = Object.extend({
			useTitle : false,
			onElementValidate : function(result, elm) {}
		}, options || {});
		elm = $(elm);
		var cn = elm.classNames();
		return result = cn.all(function(value) {
			var test = Validation.test(value,elm,options.useTitle);
			options.onElementValidate(test, elm);
			return test;
		});
	},
	test : function(name, elm, useTitle) {
		var v = Validation.get(name);
		var prop = '__advice'+name.camelize();
		try {
		if(Validation.isVisible(elm) && !v.test($F(elm), elm)) {
			if(!elm[prop]) {
				var advice = Validation.getAdvice(name, elm);
				if(advice == null) {
					var errorMsg = useTitle ? ((elm && elm.title) ? elm.title : v.error) : v.error;
					advice = '<div class="validation-advice" id="advice-' + name + '-' + Validation.getElmID(elm) +'" style="display:none">' + errorMsg + '</div>'
					switch (elm.type.toLowerCase()) {
						case 'checkbox':
						case 'radio':
							var p = elm.parentNode;
							if(p) {
								new Insertion.Bottom(p, advice);
							} else {
								new Insertion.After(elm, advice);
							}
							break;
						default:
							new Insertion.After(elm, advice);
				    }
					advice = Validation.getAdvice(name, elm);
				}
				if(typeof Effect == 'undefined') {
					advice.style.display = 'block';
				} else {
					new Effect.Appear(advice, {duration : 1 });
				}
			}
			elm[prop] = true;
			elm.removeClassName('validation-passed');
			elm.addClassName('validation-failed');
			return false;
		} else {
			var advice = Validation.getAdvice(name, elm);
			if(advice != null) advice.hide();
			elm[prop] = '';
			elm.removeClassName('validation-failed');
			elm.addClassName('validation-passed');
			return true;
		}
		} catch(e) {
			throw(e)
		}
	},
	isVisible : function(elm) {
		while(elm.tagName != 'BODY') {
			if(!$(elm).visible()) return false;
			elm = elm.parentNode;
		}
		return true;
	},
	getAdvice : function(name, elm) {
		return $('advice-' + name + '-' + Validation.getElmID(elm)) || $('advice-' + Validation.getElmID(elm));
	},
	getElmID : function(elm) {
		return elm.id ? elm.id : elm.name;
	},
	reset : function(elm) {
		elm = $(elm);
		var cn = elm.classNames();
		cn.each(function(value) {
			var prop = '__advice'+value.camelize();
			if(elm[prop]) {
				var advice = Validation.getAdvice(value, elm);
				advice.hide();
				elm[prop] = '';
			}
			elm.removeClassName('validation-failed');
			elm.removeClassName('validation-passed');
		});
	},
	add : function(className, error, test, options) {
		var nv = {};
		nv[className] = new Validator(className, error, test, options);
		Object.extend(Validation.methods, nv);
	},
	addAllThese : function(validators) {
		var nv = {};
		$A(validators).each(function(value) {
				nv[value[0]] = new Validator(value[0], value[1], value[2], (value.length > 3 ? value[3] : {}));
			});
		Object.extend(Validation.methods, nv);
	},
	get : function(name) {
		return  Validation.methods[name] ? Validation.methods[name] : Validation.methods['_LikeNoIDIEverSaw_'];
	},
	methods : {
		'_LikeNoIDIEverSaw_' : new Validator('_LikeNoIDIEverSaw_','',{})
	}
});

Validation.add('IsEmpty', '', function(v) {
				return  ((v == null) || (v.length == 0)); // || /^\s+$/.test(v));
			});

Validation.addAllThese([
	['required', 'Este campo es obligatorio.', function(v) {
				return !Validation.get('IsEmpty').test(v);
			}],
	['validate-number', 'Please enter a valid number in this field.', function(v) {
				return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v));
			}],
	['validate-digits', 'Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.', function(v) {
				return Validation.get('IsEmpty').test(v) ||  !/[^\d]/.test(v);
			}],
	['validate-alpha', 'Please use letters only (a-z) in this field.', function (v) {
				return Validation.get('IsEmpty').test(v) ||  /^[a-zA-Z]+$/.test(v)
			}],
	['validate-alphanum', 'Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.', function(v) {
				return Validation.get('IsEmpty').test(v) ||  !/\W/.test(v)
			}],
	['validate-date', 'Please enter a valid date.', function(v) {
				var test = new Date(v);
				return Validation.get('IsEmpty').test(v) || !isNaN(test);
			}],
	['validate-email', 'Por favor, introduce una direcci&oacute;n de email v&aacute;lida', function (v) {
				return Validation.get('IsEmpty').test(v) || /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
			}],
	['validate-url', 'Por favor, introduce una URL v&aacute;lida.', function (v) {
				return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
			}],
	['validate-date-au', 'Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.', function(v) {
				if(Validation.get('IsEmpty').test(v)) return true;
				var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
				if(!regex.test(v)) return false;
				var d = new Date(v.replace(regex, '$2/$1/$3'));
				return ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) && 
							(parseInt(RegExp.$1, 10) == d.getDate()) && 
							(parseInt(RegExp.$3, 10) == d.getFullYear() );
			}],
	['validate-currency-dollar', 'Please enter a valid $ amount. For example $100.00 .', function(v) {
				// [$]1[##][,###]+[.##]
				// [$]1###+[.##]
				// [$]0.##
				// [$].##
				return Validation.get('IsEmpty').test(v) ||  /^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v)
			}],
	['validate-selection', 'Por favor, acepta las condiciones', function(v,elm){
				return elm.options ? elm.selectedIndex > 0 : !Validation.get('IsEmpty').test(v);
			}],
	['validate-one-required', 'Please select one of the above options.', function (v,elm) {
				var p = elm.parentNode;
				var options = p.getElementsByTagName('INPUT');
				return $A(options).any(function(elm) {
					return $F(elm);
				});
			}]
]);comment_karma = Class.create();

comment_karma.prototype = {
	initialize: function(comment_id, comment_karma) {
		this.comment_id = comment_id;

		this.span_identificador = 'karma_'+comment_id;
		this.link_subir_id = 'karma_accion_subir_'+comment_id;
		this.link_bajar_id = 'karma_accion_bajar_'+comment_id;
		
		this.comment_karma = comment_karma;
		this.url_actualizar= '/noticias-categoria/noticia_comentario_karma_actualizar.php';
		
		this.sfx = this.onClick_Subir.bindAsEventListener(this);
		this.bfx = this.onClick_Bajar.bindAsEventListener(this);
		
		this.voto_pos_activado= '<img src="/imagenes/botones/mano-verde.jpg" alt="A Favor" />';
		this.voto_pos_desactivado= '<img src="/imagenes/botones/mano-verde-off.jpg" alt="A Favor" />';
		this.voto_neg_activado= '<img src="/imagenes/botones/mano-roja.jpg" alt="En Contra" />';
		this.voto_neg_desactivado= '<img src="/imagenes/botones/mano-roja-off.jpg" alt="En Contra" />';
			
	},

	isCommentVoted : function() {
		isVoted = getCookie('comment_karma_'+this.comment_id);
		if (!isVoted) 
			this.Add_Vote_Events();
		else {
			$(this.link_subir_id).update(this.voto_pos_desactivado);
			$(this.link_bajar_id).update(this.voto_neg_desactivado);			
			
		}
			
		
	},
	
	Add_Vote_Events : function() {
   	$(this.link_subir_id).observe('click', this.sfx);
		$(this.link_subir_id).setAttribute('href','#');
		$(this.link_subir_id).update(this.voto_pos_activado);

		$(this.link_bajar_id).observe('click', this.bfx);
		$(this.link_bajar_id).setAttribute('href','#');
		$(this.link_bajar_id).update(this.voto_neg_activado);			
	},

	Remove_Vote_Events : function() {
		$(this.link_subir_id).stopObserving('click', this.sfx);
		$(this.link_subir_id).removeAttribute('href');
		$(this.link_subir_id).update(this.voto_pos_desactivado);

		$(this.link_bajar_id).stopObserving('click', this.bfx);
		$(this.link_bajar_id).removeAttribute('href');
		$(this.link_bajar_id).update(this.voto_neg_desactivado);			
		
	},

	onClick_Subir : function(event) {
		setCookie('comment_karma_'+this.comment_id, 'subir', 7, '','','');
		this.Remove_Vote_Events();
		this.Vote('subir');
	},

	onClick_Bajar : function(event) {
		setCookie('comment_karma_'+this.comment_id, 'bajar', 7, '','','');		
		this.Remove_Vote_Events();
		this.Vote('bajar');
	},
	
	Vote : function(vAction){
		myAjax = new Ajax.Request(
				this.url_actualizar, 
				{
					parameters: {
							action: vAction,
							comment_id : this.comment_id
					},
					method : 'get',
					onComplete: this.recibirRespuesta.bind(this)
				});
	},
	
	recibirRespuesta: function(Response) {
			$(this.span_identificador).update(Response.responseText);
	}
	
}

