function getXMLHttp()
{
  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("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}
 

//-- Seguir evento
function event_follow(eid,uid) {
  var xmlHttp = getXMLHttp();
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
      //HandleResponse(eid, xmlHttp.responseText);
      //updateuserlist(eid); 
      FollowingEvent(eid, xmlHttp.responseText);  
      }
    }
  //var dividname = eid;   
  //document.getElementById(dividname).innerHTML = "<img src='"+getAppPath()+"img/spinner.gif' />";

  xmlHttp.open("GET", getAppPath()+"actions.php?eid="+eid+"&uid="+uid+"&do=evfollow", true); 
  xmlHttp.send(null);
}

//-- Mo seguir evento
function event_unfollow(eid,uid) {
  var xmlHttp = getXMLHttp();                   
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
      //HandleResponse(eid, xmlHttp.responseText);
      //updateuserlist(eid);
      FollowingEvent(eid, xmlHttp.responseText);  
      }
    }  
  //var dividname = eid;   
  //document.getElementById(dividname).innerHTML = "<img src='"+getAppPath()+"img/spinner.gif' />";

  xmlHttp.open("GET", getAppPath()+"actions.php?eid="+eid+"&uid="+uid+"&do=evunfollow", true);  
  xmlHttp.send(null);  
}



function HandleResponse(eid,response) {
  document.getElementById(eid).innerHTML = response;
  }
  

function updateuserlist(eid) {
  var xmlHttp = getXMLHttp();

  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
     setTimeout( function() { document.getElementById('wholist').innerHTML = xmlHttp.responseText },100); 
      }
    }

  xmlHttp.open("GET", getAppPath()+"actions.php?eid="+eid+"&do=updateuserlist", true); 
  xmlHttp.send(null);

}


//-- Seguir USUARIO
function followuser(uid) {
  var xmlHttp = getXMLHttp();
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
      FollowingUser(uid, xmlHttp.responseText);
      }
    }

  var dividname = "user"+uid;   
  document.getElementById(dividname).innerHTML = "<img src='"+getAppPath()+"img/spinner.gif' />";

  xmlHttp.open("GET", getAppPath()+"actions.php?uid="+uid+"&do=followuser", true); 
  xmlHttp.send(null);
}

//-- NO Seguir USUARIO
function unfollowuser(uid) {
  var xmlHttp = getXMLHttp();                   
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
      FollowingUser(uid, xmlHttp.responseText);
      }
    }

  var dividname = "user"+uid;   
  document.getElementById(dividname).innerHTML = "<img src='"+getAppPath()+"img/spinner.gif' />";

  xmlHttp.open("GET", getAppPath()+"actions.php?uid="+uid+"&do=unfollowuser", true);   
  xmlHttp.send(null);  
}

function FollowingUser(uid,response) {
  var dividname = "user"+uid;
  document.getElementById(dividname).innerHTML = response;
  }

function FollowingEvent(eid,response) {
  var dividname = "event"+eid;
  document.getElementById(dividname).innerHTML = response;
  }



//-- Buscar persona en resultados
function search_results(eid) {
  var xmlHttp = getXMLHttp();
  var txtname = document.getElementById('txt_name');
  var search = txtname.value;
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
     document.getElementById('datacontainer').innerHTML = xmlHttp.responseText; 
      }
    }
  document.getElementById('contenido').style.display = "none";
  document.getElementById('datacontainer').style.display = "";
  xmlHttp.open("GET", getAppPath()+"actions.php?s="+search+"&eid="+eid+"&do=searchresults", true);
  xmlHttp.send(null);
}

//-- Buscar inscriptos
function search_registered(eid) {
  var xmlHttp = getXMLHttp();
  var txtname = document.getElementById('txt_name');
  var search = txtname.value;
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
     document.getElementById('datacontainer').innerHTML = xmlHttp.responseText; 
      }
    }
  document.getElementById('contenido').style.display = "none";
  document.getElementById('datacontainer').style.display = "";
  xmlHttp.open("GET", getAppPath()+"actions.php?s="+search+"&eid="+eid+"&do=searchregistered", true);
  xmlHttp.send(null);
}


//-- Buscar TODOS los resultados de un evento
function srevent(eid,start) {
  var xmlHttp = getXMLHttp();
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
     document.getElementById('datacontainer').innerHTML = xmlHttp.responseText; 
      }
    }  
  document.getElementById('contenido').style.display = "none";
  document.getElementById('datacontainer').style.display = "";
  xmlHttp.open("GET", getAppPath()+"actions.php?eid="+eid+"&start="+start+"&do=srevent", true);
  xmlHttp.send(null);
}                                                             

//-- Reclamar un Resultado
function claimr(rid,odo) {
  var xmlHttp = getXMLHttp();

  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
	document.getElementById('claimresult').innerHTML = xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET", getAppPath()+"actions.php?rid="+rid+"&odo="+odo+"&do=claimresult", true); 
  xmlHttp.send(null);
}


//-- Buscar USUARIOS
function searchpeople() {
  var xmlHttp = getXMLHttp();
  var txtname = document.getElementById('txt_name');
  var search = txtname.value;

  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
     document.getElementById('datacontainer').innerHTML = xmlHttp.responseText; 
  	 document.getElementById('formaction').style.display = "none"; 
      }
    }
  document.getElementById('formaction').style.display = ""; 
  document.getElementById('formaction').innerHTML = "<img src='"+getAppPath()+"img/spinner.gif' />";    
  document.getElementById('contenido').style.display = "none";
  document.getElementById('datacontainer').style.display = "";
  xmlHttp.open("GET", getAppPath()+"actions.php?s="+search+"&do=searchpeople", true);
  xmlHttp.send(null);
}
  
//-- Invitar amigos x email
function invite_friend() {
  var xmlHttp = getXMLHttp();
  var email = document.getElementById('invite_email');
  var invitation = email.value;

  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
     document.getElementById('datacontainer').innerHTML = xmlHttp.responseText; 
      }
    }    
	document.getElementById('spinnerImg').style.display = "";        
	document.getElementById('contenido').style.display = "none"; 	
	document.getElementById('datacontainer').style.display = "none";
	setTimeout("Spinner('datacontainer')", 500);
	  
  xmlHttp.open("GET", getAppPath()+"actions.php?s="+invitation+"&do=invite_friend", true);
  xmlHttp.send(null);

}


//spinner
function Spinner(div) {
  document.getElementById('spinnerImg').style.display = "none";
  document.getElementById(div).style.display = "";
}


//-- Newsletter
function add_newsletter() {
  var xmlHttp = getXMLHttp();
  var txtemail = document.getElementById('txt_email');
  var email = txtemail.value;

  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
     document.getElementById('div-btn-newsletter').innerHTML = xmlHttp.responseText; 
  	 //document.getElementById('formaction').style.display = "none";
     //setTimeout("document.getElementById('div-btn-newsletter').innerHTML = '<p>Listo!</p>'",1500);	 
      }
    }
  //wait('div-btn-newsletter'); 
  //document.getElementById('contenido').style.display = "none";
  //document.getElementById('datacontainer').style.display = "";
  xmlHttp.open("GET", getAppPath()+"actions.php?s="+email+"&do=addnewsletter", true);
  xmlHttp.send(null);
}

function wait(div) {
  document.getElementById(div).innerHTML = "<img src='"+getAppPath()+"img/spinner.gif' />";
}

function authorizereg(oid,erid) {
  var xmlHttp = getXMLHttp();

	var dividname = "er"+erid;
  xmlHttp.onreadystatechange = function() {
    if(xmlHttp.readyState == 4) {
   // document.getElementById(dividname).innerHTML = response;	
	//document.getElementById('er'+erid).innerHTML = ""; 
	document.getElementById(dividname).innerHTML = xmlHttp.responseText;

      }
    }
  document.getElementById(dividname).innerHTML = "<img src='"+getAppPath()+"img/spinner.gif' />";    
  xmlHttp.open("GET", getAppPath()+"actions.php?oid="+oid+"&plus="+erid+"&do=authorizereg", true); 
  xmlHttp.send(null);
} 

