/*
*	readyState: estado en el que se encuentra el objeto
*		0 : iniciada
*		1 : cargando
*		2 : cargado
*		3 : interactivo
*		4 : completado
*
* status: codigo regresado por el servidor	
*		200 : correcto 
*/
function createAjaxObj(){
	var req = false;
	try{
	    req = new XMLHttpRequest(); /* p.e. Firefox */
	}catch(err1){
		try{
	     req = new ActiveXObject("Msxml2.XMLHTTP");
	  /* algunas versiones IE */
	  }catch(err2){
	    try{
	       req = new ActiveXObject("Microsoft.XMLHTTP");
	  	/* algunas versiones IE */
	    }catch(err3){
				req = false;
	     }
	  }
	}
	return req;
	alert('hola1');
}
//news
var news = "";
function showNews(tagViewer){
	document.getElementById(tagViewer).innerHTML = news;
	document.getElementById('verMas').innerHTML="";
}

function showNew(resp,tagViewer){
	news = document.getElementById(tagViewer).innerHTML;
	document.getElementById(tagViewer).innerHTML = resp;
	document.getElementById('verMas').innerHTML = "<a href=\"javascript:showNews('noticia')\" class='link'>&laquo; ver mas</a>";
}

//voto
var temp='';
function showSource(tagViewer){
	document.getElementById(tagViewer).innerHTML = temp;
	//document.getElementById('verMas').innerHTML="";
}

function showResp(resp,tagViewer){
	news = document.getElementById(tagViewer).innerHTML;
	document.getElementById(tagViewer).innerHTML = resp;
	//mostrar el ranking de votos
	
	//document.getElementById('viwVotes').innerHTML = "<a href=\"javascript:showNews('noticia')\" class='link'>&laquo; ver mas</a>";
}

/*
*	url							: 'serverFile.php'
*	params 					: readNoticia=1
*	handlerfunction : showFunction,  only put the function name, ejm. showFunction(content,tagViewer)
*	tagViewer				: the tag that show the content
*	getXML 					: true or false  .  if you want a resposponse XML
*/
function requestAjax(url,methodType,params,handlerFunction,tagViewer,getXML) {
	//alert('call');
	var ajaxObj = new createAjaxObj();	
	if(methodType.toUpperCase() =="POST"){
		ajaxObj.open(methodType,url,true);
		ajaxObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");		
	}else if(methodType.toUpperCase() =="GET"){
			ajaxObj.open(methodType,url+'?'+params,true);
		 	params = null;
		}
	
	ajaxObj.onreadystatechange = function(){
		if(ajaxObj.readyState == 4) {
	   	if(ajaxObj.status == 200) {
		  var resp = (getXML) ? ajaxObj.responseXML : ajaxObj.responseText ;
		  showNew(resp,'noticia')
		  //alert(resp);
		  //eval("handlerFunciton(resp,tagViewer)");
		  //var func = handlerFunction+"('"+resp+"','"+tagViewer+"')";
		  //alert(func);
		  //eval("'"+func+"'");
	      //handlerFunction+'('+resp+','+tagViewer+")'";
	    }
	  }
	}
	ajaxObj.send(params);
}


function checkPollOption(actionTagId, page, pollId, pollOptionId){
	//pasar mas paramentros por json para parametrizar la funcion
	inpt = document.getElementById(actionTagId);
	//alert(inpt.onclick);
	inpt.onclick = "requestAjax('"+page+"','GET','pollId="+pollId+"&pollOptionId="+pollOptionId+"','showResp','divEncusta',false);";		
	//alert(inpt.onclick);
}

function procesarVoto(){
	
}