// Instancia XMLHttpRequest
function nuevoAjax()
{ 
	var xmlhttp=false; 
	try 
	{ 
		// No IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp; 
}


function gradient(id, level)
{
	var box = document.getElementById(id);
	box.style.opacity = level;
	box.style.MozOpacity = level;
	box.style.KhtmlOpacity = level;
	box.style.filter = "alpha(opacity=" + level * 100 + ")";
	box.style.display="block";
	return;
}


function fadein(id) 
{
	var level = 0;
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
		level += 0.01;
	}
}


// Open the lightbox


function openbox(formtitle, fadin, ruta, id)
{
  var box = document.getElementById('popup'); 
  document.getElementById('filter').style.display='block';
  
  var btitle = document.getElementById('boxtitle');
  //btitle.innerHTML = formtitle;
  
  cargar_datos(ruta,id);
  gradient(formtitle, 0);
  fadein(formtitle);
  box.style.display='block';
  box.style.position="absolute";
}

function openbox2(formtitle, fadin, ruta, id)
{
  var box = document.getElementById('popup'); 
  document.getElementById('filter').style.display='block';
  
  var btitle = document.getElementById('boxtitle');
  //btitle.innerHTML = formtitle;
  
  cargar_datos2(ruta,id);
  gradient(formtitle, 0);
  fadein(formtitle);
  box.style.display='block';
  box.style.position="fixed";
	
}

// Close the lightbox

function closebox()
{
   document.getElementById('popup').style.display='none';
   document.getElementById('filter').style.display='none';
}

//Cargar datos

function cargar_datos(ruta,id){
	
	var ajax=nuevoAjax();
	ajax.open("POST", ruta+"php_ajax/alianzas.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+id);
	ajax.onreadystatechange=function(){
	   if (ajax.readyState==4){
		 var respuesta=ajax.responseText;
		 var btitle = document.getElementById('popup');
  		 btitle.innerHTML = respuesta;
		 if(respuesta=="OK")	{
			//location.reload(true);
		 }else{  
		 	//muestraMensaje("hola","resp_login")
		 }
	  }
	}
	 
	 
}


function cargar_datos2(ruta,id){
	
	var ajax=nuevoAjax();
	ajax.open("POST", ruta+"php_ajax/descuentos.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+id);
	ajax.onreadystatechange=function(){
	   if (ajax.readyState==4){
		 var respuesta=ajax.responseText;
		 var btitle = document.getElementById('popup');
  		 btitle.innerHTML = respuesta;
		 if(respuesta=="OK")	{
			//location.reload(true);
		 }else{  
		 	//muestraMensaje("hola","resp_login")
		 }
	  }
	}
	 
	 
}

