// The source code packaged with this file is Free Software, Copyright (C) 2007 by
// Luis Gonzalez konimaki[AT]gmail.com.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here: http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "LICENSE.TXT"
var xmlhttp = getXmlHttpRequestObject();
var outp;

function proper(id, value, tip) {
object = document.getElementById(id).style
	switch (tip) {
		case "margin-left":
		object.marginLeft = value + "px";
		break;
		case "height":
		object.height = value + "px";
		break;
		case "width":
		object.width = value + "px";
		break;
		case "opacity":
		object.opacity = (value / 100);
		object.MozOpacity = (value / 100);
		object.KhtmlOpacity = (value / 100);
		object.filter = "alpha(opacity=" + value + ")";
		break;
		case "visibility":
		object.visibility = value;
		break;
		}
}

function opacity(id, opacStart, opacEnd, millisec) {
var speed = Math.round(millisec / 100);
var timer = 0;
if(opacStart > opacEnd) {
    for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("proper('" + id + "', '" + i + "', 'opacity')",(timer * speed));
            timer++;
        }
	setTimeout("proper('" + id + "', 'hidden', 'visibility')", millisec);
} else if(opacStart < opacEnd) {
	proper(id, opacStart, "opacity");
	proper(id, "visible", "visibility");
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("proper('" + id + "', '" + i + "', 'opacity')",(timer * speed));
            timer++;
        }
    }
}

function anima(id, value, ms, tip) {
var speed = Math.round(ms / 100);
var timer = 0;
var object = document.getElementById(id);
var valuestart = object.offsetHeight;
for(i = valuestart; i <= value; i++) {
            setTimeout("proper('" + id + "', '" + i + "', '" + tip + "')",(timer * speed));
            timer++;
       }
}

function getQueryVariable(variable) {
query = window.location.search.substring(1);
vars = query.split("&");
for (i=0;i<vars.length;i++) {
	pair = vars[i].split("=");
	if (pair[0] == variable) {
		return pair[1];
		}
	} 
return(0);
}

function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {return new XMLHttpRequest(); }
else if(window.ActiveXObject) {	return new ActiveXObject("Microsoft.XMLHTTP");}
else {alert("Navegador incompatible con XmlHttpRequest.  Actualice a Firefox.");}
}

function connect(url) {
if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
	xmlhttp.open("GET", url , true);
	xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
	xmlhttp.onreadystatechange = ajaxx;
	xmlhttp.send(null);
	}
}

function ajaxx() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	switch (outp) {
		case 1:
		document.getElementById("xttp").innerHTML = xmlhttp.responseText;
		new_captcha();
		document.getElementById("captcha").value = '';
		proper("cloud", "300", "width");
		proper("cloud", "-150", "margin-left");
		opacity("framediv", 0, 65, 1000);
		proper("cloud", "visible", "visibility");
		break;
		case 2:
		switch (xmlhttp.responseText) {
			case "1":
			alert("No abuses.");
			break;
			case "2":
			alert("Ya has calificado este enlace.");
			break;
			case "3":
			alert("Enlace calificado.");
			break;
			case "4":
			alert("Se ha producido un error.");
			break;
			default:
			return;
		}
		break;
		case 3:
		document.getElementById("xttp").innerHTML = xmlhttp.responseText;
		proper("cloud", "680", "width");
		proper("cloud", "-340", "margin-left");
		opacity("framediv", 0, 65, 1000);
		proper("cloud", "visible", "visibility");
		break;
		default:
		return;
	}
	}
}

function linko() {
	takeurl = document.getElementById("url").value;
	takeurl = escape(takeurl);
	takelong = document.getElementById("duration").value;
	takecath = document.getElementById("cath").value;
	taketags = document.getElementById("tags").value;
	taketags = escape(taketags);
	takeemail = document.getElementById("email").value;
	takecaptcha = document.getElementById("captcha").value;
	outp = 1;
	connect(link_url + "index.php?op=genurl&url="+takeurl+"&tags="+taketags+"&cath="+takecath+"&duration="+takelong+"&email="+takeemail+"&captcha="+takecaptcha);
}

function votelinko(val, id) {
outp = 2;
connect(link_url + "index.php?op=vota&vo="+val+"&id="+id);
}

function marks() {
document.getElementById("xttp").innerHTML = "Arrastra este enlace a la barra de marcadores de tu navegador<br /> para disponer de un acceso directo.<br /><a style=\"text-decoration: underline;color: blue;font-size: 18pt;\" href=\"javascript:takeurl=escape(location.href);void(location.href=link_url+'?url='+takeurl);\">Enlazar</a><br />";
proper("cloud", "300", "width");
proper("cloud", "-150", "margin-left");
opacity("framediv", 0, 65, 1000);
proper("cloud", "visible", "visibility");
}

function showtags() {
outp = 3;
connect(link_url + "index.php?op=tags");
}

function tags(val, lim) {
outp = 3;
val = escape(val);
connect(link_url + "index.php?op=tags&tag="+val+"&p="+lim);
}

function ini() {
if (getQueryVariable("c") == 1) {
alert("El codigo es inexistente.");
} else if (getQueryVariable("url") != 0) {
	document.getElementById("url").value = unescape(getQueryVariable("url"));
	}
}

function commentfunc() {
	namevar = document.getElementById("name").value;
	emailvar = document.getElementById("email").value;
	commentvar = document.getElementById("comment").value;
	commentvar = escape(commentvar);
	takecaptcha = document.getElementById("captcha").value;
	outp = 1;
	connect(link_url + "index.php?op=contacto&name="+namevar+"&email="+emailvar+"&comment="+commentvar+"&captcha="+takecaptcha);
}