var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false

//function formataData(campo,evento){
//	alert("oi");
//}
function popup(url,largura,altura) {
	window.open(url,'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no,width='+largura+',height='+altura);
}
function popupMax (url, nome, largura, altura, pos, barras) {
	if (pos == 0) {
		posleft = 20;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (pos == 1) {
		posleft = (screen.width) ? (screen.width - largura) / 2 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (pos == 2) {
		posleft = (screen.width) ? (screen.width - largura) - 28 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	}
	if (barras == true) opbarras = "yes"; else opbarras = "no";

	settings = 'width=' + largura + ', height=' + altura + ', top=' + postop + ', left=' + posleft + ', scrollbars=' + opbarras + ', location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=no';
	window.open(url, nome, settings);
}
function hide(id) {
	if (ns4) document.layers[id].visibility = "hide"
	else document.getElementById(id).style.display="none";
}
function show(id) {
	if (ns4) document.layers[id].visibility = "show"
	else document.getElementById(id).style.display="";
}
function redireciona (obj) {
	if (obj[obj.selectedIndex].value != "") {
		var url = obj[obj.selectedIndex].value;
		self.location = url;
	}
}
function escreve(id,txt) {
    if (ns4) {
        var lyr = document.layers[id].document
        lyr.write(txt)
        lyr.close()
    }
    else document.getElementById(id).innerHTML = txt
}

function im(url) {
	window.open(url, 'im', 'channelmode=no, directories=no, fullscreen=no, height=350, left=100, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, top=100, width=180');
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


