/*
Frikichan
Copyright (c) 2009 Vicente Herrera Pérez (KrusheR)

This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
function votar(id,negative)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("¡Tu navegador no soporta AJAX!");
      return false;
      }
    }
  }
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4){
		var vid = "k" + id;
		var elemento = document.getElementById(vid)
		var tipo = xmlHttp.responseText.substr(0,1);
		switch(tipo){
			case '0':
				elemento.style.color = "#000000";
				elemento.innerHTML = "¬_¬";
				alert(xmlHttp.responseText.substr(2));
			break;
			case '1':
				elemento.innerHTML = parseInt(elemento.innerHTML) +1;
				elemento.style.color = "#00ff00";
			break;
			case '2':
				elemento.innerHTML = parseInt(elemento.innerHTML) -1;
				elemento.style.color = "#ff0000";
			break;
		}
      }
    }
  xmlHttp.open("GET",window.INS_DIR+"/inc/voto.php?id="+id+"&negative="+negative,true);
  xmlHttp.send(null);
}

function mostrarComentario(com, id)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("¡Tu navegador no soporta AJAX!");
      return false;
      }
    }
  }
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4){
		document.getElementById(com).innerHTML = xmlHttp.responseText;
	}
    }
  xmlHttp.open("GET",window.INS_DIR+"/inc/mensaje.php?id="+id,true);
  xmlHttp.send(null);
}

function contestar(replyto, id){
	document.getElementById('parent').value = replyto;
	document.getElementById('comentario').value += '#' + id + '\n';
}

function destacar(o){
	if(window.elementodestacado != null) window.elementodestacado.style.backgroundColor = '#FFCC00';
	document.getElementById(o).style.backgroundColor = '#FFDD22';
	window.elementodestacado=document.getElementById(o);
}

function nombredefecto(o){
	if(o.value=='Juan Ejemplo') {
		o.value = '';
	}
}

function toolTip(text,me) {
       window.theObj=me;
       window.theObj.onmousemove=updatePos;
       document.getElementById('toolTipBox').innerHTML=text;
       document.getElementById('toolTipBox').style.display="block";
       window.onscroll=updatePos;
}

function comToolTip(com, me) {
	if(document.getElementById('nom'+com) != null){
	   window.theObj=me;
       window.theObj.onmousemove=updatePos;
       document.getElementById('toolTipBox').innerHTML=document.getElementById('nom'+com).innerHTML + "<br />\n" + document.getElementById('com'+com).innerHTML;
       document.getElementById('toolTipBox').style.display="block";
       window.onscroll=updatePos;
	}
}

function updatePos() {

		var scrolTop = 0;
		var scrolLeft = 0;
		
		if (self.pageYOffset){
			scrolTop = self.pageYOffset;
			scrolLeft = self.pageXOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop){
			scrolTop = document.documentElement.scrollTop;
			scrolLeft = document.documentElement.scrollLeft;
		}
		else if (document.body){
			scrolTop = document.body.scrollTop;
			scrolLeft = document.body.scrollLeft
		}

       var ev=arguments[0]?arguments[0]:event;
       document.getElementById('toolTipBox').style.top  = ev.clientY+4+scrolTop+ "px";
       document.getElementById('toolTipBox').style.left = ev.clientX+20+scrolLeft+"px";
       window.theObj.onmouseout=hideMe;
}

function hideMe() {
       document.getElementById('toolTipBox').style.display="none";
}