function get_obj_by_id(name) {
     var obj;

     if (document.getElementById)
     {
           obj = document.getElementById(name);
     } else if (document.all)
     {
           obj = document.all[name];
     } else if (document.layers)
     {
           if (document.layers[name])
           {
            obj = document.layers[name];
           }
           else
           {
            obj = document.layers.testP.layers[name];
           }
     }

     return obj;
}

function solicitarRecargarFlash() {
    var divFlash = get_obj_by_id('flashcontent');
    if (divFlash != undefined) {
        divFlash.innerHTML = 
	        '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">' +
			'  <tr><td align="center" bgcolor="#6A0000">' +
			'	<img src="imgs/juegos/recargar_juego.jpg" width="406" height="169">' +
			'</td></tr>' +
			'</table>';
    }
}

var xmlHttp;// global instance of XMLHttpRequest
function createXmlHttpRequest()
{
	if(window.ActiveXObject) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	} else if(window.XMLHttpRequest) {
        xmlHttp=new XMLHttpRequest();
    }
}

function startRequest(idContenido, seccion, puntos, tipo)
{
    if (seccion == 21) {
        solicitarRecargarFlash();
    } else {
        createXmlHttpRequest();
    
        xmlHttp.open("GET","PuntoAjax?action=mandaPuntos&idContenido=" + idContenido + 
            "&seccion=" + seccion + "&puntos=" + puntos + "&tipo=" + tipo,true);
        xmlHttp.onreadystatechange=handleStateChange;
        xmlHttp.send(null);
    }
}

function startRequestJuegos(idContenido, seccion, puntos, tipo, est)
{
  if (est > 0) {
	  createXmlHttpRequest();
	
	  xmlHttp.open("GET","PuntoAjax?action=mandaPuntos&idContenido=" + idContenido + 
	  	"&seccion=" + seccion + "&puntos=" + puntos + "&tipo=" + tipo + "&est=" + est,true);
	  xmlHttp.onreadystatechange=handleStateChange;
	  xmlHttp.send(null);
  }
}

function handleStateChange()
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
            {
          var res =  
             xmlHttp.responseXML
                    .getElementsByTagName("res")[0]
                    .childNodes[0].nodeValue;
          var msg =  
             xmlHttp.responseXML
                    .getElementsByTagName("msg")[0]
                    .childNodes[0].nodeValue;
            	if (res == 'error') {
            		alert(msg);
            	}
            }
        else
        {
           alert("Error al cargar la página: "+ xmlHttp.status + ":"+xmlHttp.statusText);
        }
    }
}