/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

/************************************************************************************************/

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

/************************************************************************************************/

var MyBoxImg = 'imagenes/loading.gif';

function MyHideBox() {
	document.getElementById('MyframeI').style.display='none';
	document.getElementById('MyframeO').style.display='none';
}

function MyClosetBox() {
	var keycode = 0;
	document.onkeyup = function(e){ 	
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
	}

	if(keycode == 27){ 
		MyHideBox();
	}
	
}


function MyBoxLoad(x) {
 
	var e  = document.getElementById('MyBoxImg');
	var i  = document.getElementById('MyBoxFile');

	if(x)  {
		e.style.display = 'none'
		i.style.display = 'block';
		UnFrame = x;
	} else	{
		e.style.display = 'block';
		i.style.display = 'none';		
		UnFrame = x;
		if(!UnFrame) 
			setTimeout("MyBoxLoad(true)",5555);
	}
}

function MyShowBox(MyIdFile) {
	document.onkeypress = MyClosetBox;
            if (window.pageYOffset)
            {
                topup = window.pageYOffset;
            }
            else
            {
                topup = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
            }

			var MyBody = ("<div id='MyframeI'><div id='MyHideBox'><a href='javascript:void(0);' onclick='MyHideBox()'>Cerrar</a></div><div id='MyframeU'>" 
			+ "<div id='MyBoxImg'><img src='" + MyBoxImg + "'></div><iframe id='MyBoxFile' name='MyBoxFile' onload='MyBoxLoad(true)'></iframe>" 
			+ "</div></div><div id='MyframeO' onclick='MyHideBox();'></div>");

	document.getElementById('MyBoxFrame').innerHTML = (MyBody);
	document.getElementById('MyframeI').style.top = (topup + 150) + "px";  //(screen.height / 2)
	document.getElementById('MyframeO').style.top = (topup) + "px";  //(screen.height / 2)

	MyBoxLoad(false);
	document.getElementById('MyframeI').style.display='block';
	document.getElementById('MyframeO').style.display='block';
	window.open(MyIdFile,'MyBoxFile');
	return false;
//	window.location = "#";
}

