
var gibberish=[
 "Isso e apenas um preenchimento de texto", 
 "Hotmedia Multmedia Solution Provider", 
 "Zion System - Z3 Webcast - Zion Web Encoder."
]
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
function filltext(words){
  for (var i=0; i<words; i++)
   document.write(gibberish[Math.floor(Math.random()*3)]+" ")
}
function URLEncode(plaintext){
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

//	var plaintext = document.URLForm.F1.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
}
function URLDecode(encoded) {
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
//   var encoded = document.URLForm.F2.value;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}
function trocaFundoAg(ide, cor,v) {
  ide.style.background=cor;
  ide.style.color=v;
}
function changeImg(imgName,imgSrc) {
	document[imgName].src = imgSrc;
}
function checkCookie() {
	setCookie("CookieTest", "OK", 1);
	var v = getCookie("CookieTest");
	setCookie("CookieTest", "");
	return (v == "OK");
}	// checkCookie() end
function getCookie(inName) {
	var search = inName + "="
	if (document.cookie.length > 0) {
		var offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			var end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
}	// getCookie(inName) end
function setCookie(inName, inVal, inTime, inPeriodInSecond) {
	if (!inPeriodInSecond) inPeriodInSecond = 86400;
	if (!inTime && (document.location.href.indexOf("localhost") > -1 ||
			document.location.href.indexOf("127.0.0.1") > -1)) {
		inTime = 30;			// on IIS localhost non expiring cookies don't seem to work?
		inPeriodInSecond = 60;	// so lets have 30 mins instead
	}
	var expire = "";
	if (inTime) {
		var today = new Date();
		today.setTime(today.getTime() + (inTime * inPeriodInSecond * 1000)); 
		expire = ";expires=" + today.toGMTString();
	}
	document.cookie = inName + "=" + escape(inVal) + expire + ";path=/;";
}	// setCookie(inName, inVal, inDays) end
function GetSessionCookieName() {
	var oStr = "";
	if (window.location.search.match(/player=([^&]*)/i)) {
		oStr = RegExp.$1;
	} else if (window.location.search.indexOf("list=on") > -1 || debugMode) {
		oStr = "list";
	}
	return "nsp2_PSC_" + oStr;
}
function MakeArray(n) {
	this.length = n
	for (var i = 1; i<=n; i++) {
		this[i] = 0
	}
	return this
}
function HasPlugin(plugin) {
	for(var i = 0; i < navigator.plugins.length; i++) {
		if(navigator.plugins[i].name.indexOf(plugin) != -1)
			return (true);
	}
	
	return (false);
}
function Trim(inString) {
	var retVal = "";
	var start = 0;
	while ((start < inString.length) && (inString.charAt(start) == ' ')) {
		++start;
	}
	var end = inString.length;
	while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
		--end;
	}
	retVal = inString.substring(start, end);
	return retVal;
}	// Trim(inString) end
function hex(n) {
	var h=parseInt(n).toString(16);
	return h.toUpperCase();
//	return (h.length%2)?"0"+h:h
}
function Truncate(inString, inMaxLen, inPad) {
	if (!inPad) inPad = "...";
	var oString = "";
	if (inString.length > inMaxLen)
		oString = inString.substr(0, inMaxLen - inPad.length) + inPad;
	else
		oString = inString;
	
	return oString;
}
function encode(str) {
	var result = "";
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	return escape(result);
}
function decode(str) {
 	var result = str.replace(/\+/g, " ");
	return unescape(result);
}
function MM_swapImgRestore() { //v3.0
  	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
   	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function findElement(n,ly) {
	d = document;
	if (browserVers < 4)		return d[n];
	// jb - Netscape 7.1 appears as version 5.0 - bizarre!
	if ((browserVers >= 5) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem && cd.all) elem=cd.all[n];	// added by JB - odd!
	if (!elem && cd.layers) {
		for (var i=0;i<cd.layers.length;i++) {
			elem = findElement(n,cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}
function TrocaImg(a,img) {
	b = document.getElementById(a);
	b.src = img;
}		
function EscreveDados(local, val){
	dDiv = document.getElementById(local);
	dDiv.innerHTML = val;
}
function reduzTexto(texto,numero) {
	if (texto.length > numero)
		texto = texto.substring(0,numero-2)+"...";
	return texto;
}
function SecondsToMinutes(val){
	minutes = 0; seconds = 0;
	while(val > 60){
		val = val - 60;
		minutes++;
	}
	seconds = Math.floor(val)+"";
	minutes = minutes+"";
	if(minutes.length < 2) minutes = "0"+minutes;
	if(seconds.length < 2) seconds = "0"+seconds;
	return minutes+":"+seconds;
}
var up;
var cmin1,csec1,cmin2,csec2;
function Minutes(data) {
	for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
	return(data.substring(0,i)); 
}
function Seconds(data) {
	for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
	return(data.substring(i+1,data.length)); 
}
function Display(min,sec) {
	var disp;
	if(min<=9) disp=" 0";
	else disp=" ";
	disp+=min+":";
	if(sec<=9) disp+="0"+sec;
	else disp+=sec;
	return(disp); 
}
CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function setClientSize(inWidth, inHeight) {
	if (this.self != this.top || (typeof debugMode != "undefined" && debugMode)) return;	// not if i'm in a frame
    if (inWidth < 0 || inHeight < 0) {	// fullscreen
		return;
		//inWidth = window.screen.width;
		//inHeight = window.screen.height;
	}
	if (!IsIE()) {
		window.innerWidth = inWidth;
		window.innerHeight = inHeight;
	
	} else {	// is IE and a right pain!
    
		// it is important to resize the window to the
		// wanted values first, even if we won't get them.
		window.resizeTo(inWidth, inHeight);
		window.scrollTo(0,0);
		// create the checkpoint element
		var cp = document.createElement("div");
		cp.style.position = "absolute";
		cp.style.width = "0px";
		cp.style.height = "0px";
		cp.style.right = "0px";
		cp.style.bottom = "0px";
		
		// we can only read it's position after we
		// insert it into the document
		document.body.appendChild(cp);
		
		// here we get the actual client size
		var current_width = cp.offsetLeft;
		var current_height = cp.offsetTop;
		
		// here we find out how much more we need
		// in order to get to the needed inWidth x inHeight size
		// (or in other words, we compute the size of
		// window decorations: border, scroll bars, title)
		var dw = inWidth - current_width;
		var dh = inHeight - current_height;
		
		// and _finally_ we get what we need
		window.resizeBy(dw, dh);
		
		// we can safely delete the checkpoint now
		document.body.removeChild(cp);
		
		// for the curious, return to see how much
		// did IE miss it
		return { missed_width: dw, missed_height: dh };
	} // if IsIE
}
function clickIE4() {
	if (event.button==2){
		alert(mymsg);
		return false;
	}
}
function clickNS4(e) {
	if (e.which==2 || e.which==3){
		alert(mymsg);
		return false;
	}
}
function contaTempo() {
	cmin1=0;
	csec1=0;
	UpRepeat(); 
}
function UpRepeat() {
	csec1++;
	if(csec1==60) { csec1=0; cmin1++; }
	EscreveDados('statusbox', EXECUTANDO+'&nbsp;&nbsp; '+Display(cmin1,csec1));
	ups=setTimeout("UpRepeat()",1000);
}
function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;

  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return false; //Here determine return if no parameter is found
  }
}

/************************
 *  StringBuffer
 ************************/
 function StringBuffer() {
   this.buffer = [];
 }
 StringBuffer.prototype.add = function add(string) {
   this.buffer.push (string);
   return this;
 };
 StringBuffer.prototype.toString = function toString() {
   return this.buffer.join('');
 };
 
 /************************
 *  ExplodeArray
 ************************/
function explodeArray(item,delimiter) {
	tempArray=new Array(1);
	var Count=0;
	var tempString=new String(item);
	while (tempString.indexOf(delimiter)>0) {
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
		Count=Count+1
	}
	tempArray[Count]=tempString;

	return tempArray;
}
function abreJanelaPlayer(nomejanela, pagina, largura, altura, barra){
    eval('janela = window.open("'+pagina+'","' + nomejanela + '","width='+largura+',height='+altura+',top=50,left=150' +
            ',scrollbars=no,hscroll=0,dependent=no,toolbar='+barra+'")');
    janela.focus();
}
function dataFormatada() {
   var mydate=new Date()
   var year=mydate.getYear()
   if (year < 1000)
   year+=1900
   var day=mydate.getDay()
   var month=mydate.getMonth()
   var daym=mydate.getDate()
   if (daym<10)
   		daym="0"+daym
   var dayarray=new Array("Domingo","Segunda","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado")
   var montharray=new
   Array("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")
   return dayarray[day]+", "+daym+" de "+montharray[month]+" de "+year;
}
/* RECEBE DATA NO FORMATO YYYY-MM-DD E MUDA PARA DD/MM/YYYY */
function dataFormatoBr(date){
	// tira a hora
	date = date.substring(0,date.indexOf(" "));

	ano = date.substring(0, date.indexOf("-"));
	date = date.substring(date.indexOf("-")+1, date.length);
	mes = date.substring(0, date.indexOf("-"));
	date = date.substring(date.indexOf("-")+1, date.length);
	dia = date.substring(0, date.length);
	return dia+"/"+mes+"/"+ano;
}
