////////////////////////// Voting procedure //////////////////////////

function votarEncuesta(val){
	var el = document.getElementById("formEncuesta");
	var op;
	for (var intCounter = 0; intCounter < el.length; intCounter++)  {  
		if(el[intCounter].checked){
			op = el[intCounter].value;
		}
	}
	try {
	   	httpEnc = new XMLHttpRequest();
	    } catch(e) {
    	  try {
	    	  httpEnc = new ActiveXObject("Msxml2.XMLHTTP");
    	  } catch (e) {
	        try {
        		httpEnc = new ActiveXObject("Microsoft.XMLHTTP");
    	    } catch (E) {
		         httpEnc = false;
        	}
    	}
    }
	myRand = parseInt(Math.random()*999999999999999);
	var url = "misc/MRS2_val.php?mr2_id=" + op + "&mr2_back="+val+"&rand="+myRand;
    httpEnc.onreadystatechange = function() { respuestahttpEnc("divEncuesta"); };
    httpEnc.open("GET",url,true);
    httpEnc.send(null);
}



function respuestahttpEnc(elementoPag) {
   var resultado = '';
   if(httpEnc.readyState == 4) {
	  	if(httpEnc.status == 200) {
	        resultado = httpEnc.responseText;
    	    document.getElementById(elementoPag).innerHTML = resultado;
      	} else { 
//			alert(httpEnc.status);
		}
   } else {
	    document.getElementById(elementoPag).innerHTML = '<img src="be/wait_16.gif" />';
   }
}


////////////////////////// Menus control //////////////////////////
function SwitchMenu(obj){
	if(document.getElementById){
		var i = 1;
		var el = document.getElementById(obj);
		while(ar=document.getElementById("sub" + i)){
			if(obj != "sub" + i){
				$("#sub" + i).hide("slow");
			}
			i++;
		}
		if(el.style.display == "none"){
			$("#" + obj).show();
//			$("#" + obj).show("slow");
			//el.style.display = "block";
		} else {
			
		}
	}
}
/*function SwitchMenu(obj){
	if(document.getElementById){
		for (var i=1; i<9; i++){
			ar=document.getElementById("sub" + i);
			ar.style.display = "none";
		}
		var el = document.getElementById(obj);
		if(el.style.display == "none"){
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}*/
function ChangeClass(menu, newClass) { 
	 if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 
function ChangeClass2(menu, submenu, newClass) { 
	 if (document.getElementById) { 
		document.getElementById(menu).className = newClass;
		if(document.getElementById(menu).className=='menuOut'){
			$("#" + submenu).hide();
//			$("#" + submenu).hide("slow");
		}
	 } 
/* 	if(newClass=='menuOut'){
		var i = 1;
		while(ar=document.getElementById("sub" + i)){
			$("#sub" + i).hide("slow");			
			i++;
		}
	}
*/
} 

/*function SwitchMenu(obj){
	if(document.getElementById){
		for (var i=1; i<6; i++){
			if("divMenu" + i != obj) {
				ar=document.getElementById("divMenu" + i);
				ar.style.display = "none";
			}
		}
		$("#"+obj).fadeIn(500);
	}
}*/
function TopSwitchMenu(obj){
	if(document.getElementById){
		for (var i=1; i<4; i++){
			if("divMenu" + i != obj) {
				ar=document.getElementById("topDivMenu" + i);
				ar.style.display = "none";
			}
		}
		$("#"+obj).fadeIn(500);
	}
}

function hideMenu(menu){
	document.getElementById(menu).style.display="none";
	for (var i=1; i<6; i++){
		ar=document.getElementById("divMenu" + i);
		ar.style.display = "none";
	}
}
function TopHideMenus(max){
	for (var i=1; i<=max; i++){
		
		var ar=document.getElementById("topDivMenu" + i);
		var obj1 = document.getElementById("topBkOp"+ i +"_1");
		var obj2 = document.getElementById("topBkOp"+ i +"_2");
		var obj3 = document.getElementById("topBkOp"+ i +"_3");
		
		ar.style.display = "none";
		
		obj1.style.background ="none";
		obj2.style.background ="none";
		obj3.style.background ="none";
	}
	var div1 = document.getElementById("mennTop");
	var div1Paras = div1.getElementsByTagName("a");
  	var num = div1Paras.length;
}
function showMenuIz(menu) {
	document.getElementById(menu).style.display="block";
}
function showMenu(menu) {
	var menuStyle=document.getElementById("topDivMenu" + menu).style;

	var obj1 = document.getElementById("topBkOp"+ menu +"_1");
	var obj2 = document.getElementById("topBkOp"+ menu +"_2");
	var obj3 = document.getElementById("topBkOp"+ menu +"_3");
	obj1.style.background ="url(be/men02.jpg) no-repeat";
	obj2.style.background ="url(be/men03.jpg) repeat-x";
	obj3.style.background ="url(be/men04.jpg) no-repeat";
	menuStyle.display="block";
}

////////////////////////// AJAX //////////////////////////

function inContActP(id,funcion,fecha) {
	try {
    	http = new XMLHttpRequest();
	    } catch(e) {
    	  try {
	    	  http = new ActiveXObject("Msxml2.XMLHTTP");
    	  } catch (e) {
	        try {
        		http = new ActiveXObject("Microsoft.XMLHTTP");
    	    } catch (E) {
		         http = false;
        	}
    	}
    }
	 myRand = parseInt(Math.random()*999999999999999);
	 var url = "misc/MRS2_val.php?mr2_id=" + id + "&mr2_back="+funcion+"&rand="+myRand;
     http.onreadystatechange = function() { respuestaICont_ttl("infoShowTtl"); };
     http.open("GET",url,true);
     http.send(null);
	 inContActP2(id, funcion+1,fecha);
}
function inContActP2(id, funcion,fecha) {
	try {
    	http2 = new XMLHttpRequest();
	    } catch(e) {
    	  try {
	    	  http2 = new ActiveXObject("Msxml2.XMLHTTP");
    	  } catch (e) {
	        try {
        		http2 = new ActiveXObject("Microsoft.XMLHTTP");
    	    } catch (E) {
		         http2 = false;
        	}
    	}
    }
	 myRand = parseInt(Math.random()*999999999999999);
	 fecha = "&mr2_fecha="+fecha;
	 var url = "misc/MRS2_val.php?mr2_id=" + id + "&mr2_back="+funcion+"&rand="+myRand+fecha;
     http2.onreadystatechange = function() { respuestaICont("infoShow"); };
     http2.open("GET",url,true);
     http2.send(null);
}
function inCont(id,funcion) {
	try {
    	http = new XMLHttpRequest();
	    } catch(e) {
    	  try {
	    	  http = new ActiveXObject("Msxml2.XMLHTTP");
    	  } catch (e) {
	        try {
        		http = new ActiveXObject("Microsoft.XMLHTTP");
    	    } catch (E) {
		         http = false;
        	}
    	}
    }
	 myRand = parseInt(Math.random()*999999999999999);
	 var url = "misc/MRS2_val.php?mr2_id=" + id + "&mr2_back="+funcion+"&rand="+myRand;
     http.onreadystatechange = function() { respuestaICont_ttl("infoShowTtl"); };
     http.open("GET",url,true);
     http.send(null);
	 inCont2(id, funcion+1);
}
function inCont2(id, funcion) {
	try {
    	http2 = new XMLHttpRequest();
	    } catch(e) {
    	  try {
	    	  http2 = new ActiveXObject("Msxml2.XMLHTTP");
    	  } catch (e) {
	        try {
        		http2 = new ActiveXObject("Microsoft.XMLHTTP");
    	    } catch (E) {
		         http2 = false;
        	}
    	}
    }
	 myRand = parseInt(Math.random()*999999999999999);
	 var url = "misc/MRS2_val.php?mr2_id=" + id + "&mr2_back=" + funcion + "&rand="+myRand;
     http2.onreadystatechange = function() { respuestaICont("infoShow"); };
     http2.open("GET",url,true);
     http2.send(null);
}

function respuestaICont(elementoPag) {
   var resultado = '';
   if(http2.readyState == 4) {
	  	if(http2.status == 200) {
	        resultado = http2.responseText;
    	    document.getElementById(elementoPag).innerHTML = resultado;
      	} else { 
			alert(http2.status);
		}
   } else {
	    document.getElementById(elementoPag).innerHTML = '<img src="be/wait_16.gif" />';
   }
}
function respuestaICont_ttl(elementoPag) {
   var resultado = '';
   if(http.readyState == 4) {
	  	if(http.status == 200) {
	        resultado = http.responseText;
    	    document.getElementById(elementoPag).innerHTML = resultado;
      	} else { 
			alert(http.status);
		}
   } else {
	    document.getElementById(elementoPag).innerHTML = '<img src="be/wait_16.gif" />';
   }
}