//-- Analytics --

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
var pageTracker = _gat._getTracker("UA-1018881-4");
pageTracker._trackPageview();
} catch(err) {}

// -- Varios --

function popup(url, width, height, name) {
	if (!name) {
		name = '_popup';
	}

	window.open(url.replace(/&amp;/g, '&'), name, 'height=' + height
			+ ',resizable=yes,scrollbars=yes,width=' + width);
	return false;
}

function jumpto() {
	var page = prompt('{LA_JUMP_PAGE}:', '{ON_PAGE}');
	var perpage = '{PER_PAGE}';
	var base_url = '{A_BASE_URL}';

	if (page !== null && !isNaN(page) && page > 0) {
		document.location.href = base_url.replace(/&amp;/g, '&') + '&start='
				+ ((page - 1) * perpage);
	}
}

/**
 * Find a member
 */
function find_username(url) {
	popup(url, 760, 570, '_usersearch');
	return false;
}

/**
 * Mark/unmark checklist id = ID of parent container, name = name prefix, state =
 * state [true/false]
 */
function marklist(id, name, state) {
	var parent = document.getElementById(id);
	if (!parent) {
		eval('parent = document.' + id);
	}

	if (!parent) {
		return;
	}

	var rb = parent.getElementsByTagName('input');

	for ( var r = 0; r < rb.length; r++) {
		if (rb[r].name.substr(0, name.length) == name) {
			rb[r].checked = state;
		}
	}
}

// -- AJAX --

function nuevoAjax() {
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

// -- Votos --

function AJAX_VOTE(DIVKEY, LEVEL, KEY, TOPIC) {
	var contenedor = document.getElementById("vote_id_" + DIVKEY);
	var aleatorio = Math.random();
	ajax = nuevoAjax();
	if (KEY != '') {
		ajax.open("GET", "/includes/functions_ajax.php?function=votar&key="
				+ KEY + "&level=" + LEVEL + "&rn=" + aleatorio, true);
	} else {
		ajax.open("GET", "/includes/functions_ajax.php?function=votar&topic="
				+ TOPIC + "&level=" + LEVEL + "&rn=" + aleatorio, true);
	}
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null)
}

function light_stars(TOPIC, VOTELEVEL) {
	var i
	for (i = 1; i <= VOTELEVEL; i++) {
		document.getElementById("star_t" + TOPIC + "_r" + i).className = "vote-star vote-full";
	}
	for (i = VOTELEVEL + 1; i <= 5; i++) {
		document.getElementById("star_t" + TOPIC + "_r" + i).className = "vote-star vote-blank";
	}
}

function unlight_stars(TOPIC, LEVEL) {
	var i
	for (i = 1; i <= 5; i++) {
		if (LEVEL + 1 <= i) {
			document.getElementById("star_t" + TOPIC + "_r" + i).className = "vote-star vote-blank";
		}

		if (LEVEL >= i) {
			document.getElementById("star_t" + TOPIC + "_r" + i).className = "vote-star vote-full";
		}
		if (i == 5) {
			break;
		}
	}
}

function showname(ID) {
	if (navigator.appName != "Microsoft Internet Explorer")
		document.getElementById(ID).style.visibility = 'visible';
}

function hidename(ID) {
	if (navigator.appName != "Microsoft Internet Explorer")
		document.getElementById(ID).style.visibility = 'hidden';
}

// -- Collector --

function concat_collection(obj1, obj2) {
	var i;
	var arr = new Array();
	var len1 = obj1.length;
	var len2 = obj2.length;
	for (i = 0; i < len1; i++) {
		arr.push(obj1[i]);
	}
	for (i = 0; i < len2; i++) {
		arr.push(obj2[i]);
	}
	return arr;
}

