//<![CDATA[ 

function getObj(name) {
  if (document.getElementById) { return document.getElementById(name); }
  else if (document.all) { return document.all[name]; }
  else if (document.layers) { return document.layers[name]; }
  return null;
}

function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
}

function vote_AJAX(item) {
  
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
         oXMLHttp = new XMLHttpRequest();
         if (oXMLHttp.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //oXMLHttp.overrideMimeType('text/xml');
            oXMLHttp.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            oXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               oXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!oXMLHttp) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

  
    // creamos el objeto
    //oXMLHttp = new XMLHttpRequest();

    // pedimos la página en modo síncrono
    ruta='/js/cherokee/AjaxVoting.php?itemVoted=' + item + '&targetAction=vote';

    oXMLHttp.open('GET', ruta,true);

    oXMLHttp.onreadystatechange=function() {
        if (oXMLHttp.readyState==4) {
            retorno = trim(oXMLHttp.responseText);
            if (retorno.substr(0,22)=='<!-- ACCEPTED_VOTE -->') {
                document.getElementById('mensaje-' + item).innerHTML='Gracias por tu voto';
                document.getElementById('votos-' + item).innerHTML='Votos: ' + retorno.substr(22);
            } else {
                if (retorno=='<!-- ALREADY_VOTED -->') {
                    document.getElementById('mensaje-' + item).innerHTML='Lo sentimos, ya has votado por esta foto en las últimas 24 horas.';
                } else {
                    if (retorno=='<!-- VOTES_LIMIT -->') {
                        document.getElementById('mensaje-' + item).innerHTML='Lo sentimos, ya has votado 3 veces en las últimas 24 horas.';
                    }
                }
            }
        }
    }

    oXMLHttp.send(null)
    
}

//]]> 

