// JavaScript Document

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

oXML = nuevoAjax(); 
///////////////////////////////////////


function leerDatos()
{
  // Comprobamos que se han recibido los datos
  if (oXML.readyState == 4) 
  {      
    var xml  = oXML.responseText;
	
    if (oXML.status==200)
	{
	  contecen.innerHTML =xml;
	  //postx();
	}
    else
      alert(oXML.statusText);
  }
  else 
  {
    contecen.innerHTML = '<img src="img/cargando.gif">';
  }  
}   

function menuconte()
{
  if (oXML.readyState == 4) 
  {      
    var xml  = oXML.responseText;
    if (oXML.status==200)
	{
	  contecen.innerHTML=xml;
	}
    else
      alert(oXML.statusText);
  }
  else 
  {
    contecen.innerHTML = '<img src="img/cargando.gif">';
  }  
}
 // funciones


function menu(x)
{
  if(x=="a")
  {
	window.open('../kids/index.html','popop','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=955, height=600');	  
  }
  else
  {
  oXML = nuevoAjax();  
  oXML.open('post', 'procesact.php');  
  oXML.onreadystatechange = menuconte;
  oXML.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXML.send('var='+x);
  }
}

function actualizar(x)
{
  //miDiv.innerHTML = 'Refrescando';
  oXML = nuevoAjax();  
  oXML.open('post', 'procesos.php');  
  oXML.onreadystatechange = leerDatos;
  oXML.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  var id =document.getElementById('selec').value;
  var np =document.getElementById('np').value;
  var txt =document.getElementById('content').value;
  var left =document.getElementById('left').value;
  var top =document.getElementById('top').value;
  oXML.send('idpro='+x+"&id="+id+"&np="+np+"&txt="+txt+"&left="+left+"&top="+top);
}

function elimina(x,z)
{
  oXML = nuevoAjax();  
  oXML.open('post', 'eliminaarchivo.php');  
  /*oXML.onreadystatechange = leerDatos;*/
  oXML.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXML.send("cod="+x+"&id="+z);
}

function txr()
{
  im.innerHTML = document.getElementById('content').value;
}

function postx()
{
  im.style.left = document.getElementById('left').value;
  im.style.top = document.getElementById('top').value;
}

function popup(url)
{
 window.open('popup.php?img='+url,'popop','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=382, height=600,');
}





// FIN funciones





 

		function startCallback(id,idx) 
		{

			document.getElementById(idx).innerHTML = '<img src="img/cargando.gif" width="18" height="18">';			
			return true;
		}
 
		function completeCallback(response,idx) 
		{
			
			nxx=Math.random();
			document.getElementById(idx).innerHTML = '<a href="img/'+idx+'g.png?n='+nxx+'" target="_blank"><img src="img/'+idx+'.png?n='+nxx+'"/></a>';

		}



AIM = 
{
 
	frame : function(c,idx) 
	{
 		//alert(c);
		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe  src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\','+idx+')"></iframe>';
		
		document.body.appendChild(d);
 
		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}
 
		return n;
	},
 
	form : function(f, name) {
		//alert(name);
		f.setAttribute('target', name);
	},
 
	submit : function(f, c, idx) {
		//alert(c);
		AIM.form(f, AIM.frame(c,idx));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart(f.id, idx);
		} else {
			return true;
		}
	},
 
	loaded : function(id,idx) {
		var i = document.getElementById(id);
		//alert(idx+'loaded');
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}
 
		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML,idx);
		}
	}
 
}

