function objetoAjax(){
	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;
}

//////////////////////////////////////////////////////
// --> Funciones Generales de Wajax

function ActualizarDiv(div,url){
	
	ajax=objetoAjax();

	ajax.open("GET", url, true);
	document.getElementById(div).innerHTML= '<center><img src="Wajax/anim.gif"></center>';
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			document.getElementById(div).innerHTML = ajax.responseText;
			//SetContainerHTML(div, ajax.responseText, true);
		}
	}

	ajax.send(null);
}

var xmlHttp;

function AgregarCasting(modid,casting){
	
	 xmlHttp=GetXmlHttpObject2();
	 if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	 } 
	 var url="http://www.civiles.com/Agregar.php?addto=" + modid+"&sid="+Math.random() + "&casting="+casting;
 	 xmlHttp.onreadystatechange=stateChanged;
	 xmlHttp.open("GET",url,true);
	 xmlHttp.send(null);	 
	 
	 if (casting==1){
		if (modid<0)
			modid=-modid;
		removeWho ('people'+ modid);
	 }
	
}
function stateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")		//NO ENTRA AC�
	{
		var resultado=xmlHttp.responseText;
		var divnombre="";
		var result=parseInt(resultado);
		if (result>0){
			divnombre= "cast" + resultado;
			document.getElementById(divnombre).innerHTML="<a href='javascript:AgregarCasting("+-result+");' class='link_small' '>Remover del Casting.</a>";				
		}
		if (result<0){
			divnombre= "cast" + -resultado;
			document.getElementById(divnombre).innerHTML="<a href='javascript:AgregarCasting("+-result+");' class='link_small' '>Agregar al Casting.</a>";				
		}
	}
} 

function GetXmlHttpObject(){ 
	var xmlHttp=null;
	try
	 {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
		 //Internet Explorer
		 try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 }catch (e)
		 {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		 }
	 }
	return xmlHttp;
}

function GetXmlHttpObject2()
 { 
 var objXMLHttp=null;
 if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest();
  }
 else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 return objXMLHttp;
 }
 
function removeWho(who) {
    if(typeof who== 'string') who=document.getElementById(who);
    if(who && who.parentNode)who.parentNode.removeChild(who);
}


