var xmlHttp = null;

function getObject(objectId) {
	if (document.all && !document.getElementById) 
		return document.all(objectId)
	 else 
		return document.getElementById(objectId)
}

function createXmlHttp() {
   xmlHttp = null;
   try {
      if (window.XMLHttpRequest) {
         // If IE7, Mozilla, Safari, etc: Use native object
         xmlHttp = new XMLHttpRequest();
      }
      else {
         if (window.ActiveXObject) {
            // ...otherwise, use the ActiveX control for IE5.x and IE6
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
         }
      }
   }
   catch (e) {
   }      
}   

function getNodeValue(xmlData, tag) {
   try {
      var posStart, posEnd, tagSize, startTag, endTag;
      
      startTag = "<" + tag + ">";
      endTag = "</" + tag + ">";
   
      if ((posStart = xmlData.indexOf(startTag)) != -1) {
         posEnd = xmlData.indexOf(endTag);
         tagSize = startTag.length;
   
         return xmlData.substr(posStart + tagSize, posEnd - posStart - tagSize);
      }
      else
         return "";
   }
   catch (e) {
      return "ERROR en getTagValue.";
   }      
}

function getInt(numero) {
   numero = "" + numero;
   var entero = parseInt(numero, 10);
   return isNaN(entero) ? 0 : entero;
}

function getFloat(numero) {
   numero = "" + numero;
   var real = parseFloat(numero, 10);
   return isNaN(real) ? 0 : real;
}

function editToPretty(numero, formato) { 
   if ((!numero) || (numero == "")) { return ""; }
   
   var retolno = '', negatifo = false;
   
   numero = numero.replace(/\s/g, ""); 
   numero = numero.replace(/,/g, "."); 
   
   if (numero.charAt(0) == "-") { 
      negatifo = true; 
      numero = numero.substr(1); 
   } 
   numero = getFloat(numero); 
   
   var numDecimales = getInt(formato.charAt(1)); 
   var temp = (numDecimales == 0) ? 1 : Math.pow(10, numDecimales); 
   
   numero *= temp; 
   numero = Math.round(numero); 
   numero /= temp; 
   numero += ""; 
   
   var digitos, decimales; 
   if (numero.indexOf('.') != -1) { 
      digitos = numero.slice(0,numero.indexOf('.')); 
      decimales = numero.slice(numero.indexOf('.') + 1); 
   } 
   else { 
      digitos = numero; 
      decimales = ""; 
   } 
   
   while (digitos.length > 3) { 
      retolno = '.' + digitos.slice(digitos.length - 3, digitos.length) + retolno; 
      digitos = digitos.slice(0, digitos.length - 3); 
   } 
   
   retolno = (digitos.length == 0) ? retolno.slice(1) : digitos + retolno;
   
   if (numDecimales == 0) { return (negatifo) ? "-" + retolno : retolno; }
   
   if (decimales != "") { decimales = decimales.substr(0,numDecimales); }

   while (decimales.length < numDecimales) { decimales += "0"; }
   retolno += "," + decimales; 
   
   return (negatifo) ? "-" + retolno : retolno; 
   
} 

function formatSize(size) {
   var numSize = parseFloat(size);
   
   if (numSize < 1024)
      return numSize + " B&nbsp;&nbsp;";
   else if (numSize < 1024*1024)
      return editToPretty(Math.round(numSize / 1024).toString(), "n0") + " KB";
   else if (numSize < 1024*1024*1024)
      return editToPretty((numSize / (1024*1024)).toString(), "n2") + " MB";
   else
      return editToPretty(Math.round(numSize / (1024*1024*1024)).toString()) + " GB";
}

