
/*** Temporary text filler function. Remove when deploying template. ***/
var gibberish=[
 "Isso e apenas um preenchimento de texto", 
 "Hotmedia Multmedia Solution Provider", 
 "Demo e Piloto TV Web."
]
function filltext(words){
  for (var i=0; i<words; i++)
   document.write(gibberish[Math.floor(Math.random()*3)]+" ")
}
function URLencode(sStr) {
   return escape(sStr).
      replace(/\+/g, '%2B').
         replace(/\"/g,'%22').
            replace(/\'/g, '%27').
               replace(/\//g,'%2F');
}
function imprimir() {
   var url = 'printPage.php';
   window.open(url, 'wnd', 'width=672, height=450, toolbar=no, copyhistory=no, location=no, status=yes, menubar=no, scrollbars=yes, resizable=no, top=0, left=0');
// ifrmHidden.location.href = 'printPage.php';
}
var itemsel = "";
function trocaFundoAg(ide, cor,v) {
   document.getElementById(ide).style.background=cor;
   document.getElementById(ide).style.color=v;
}
function trocaFonte(obj, cor) {
   obj.style.color=cor;	
}
function trocaFundo(ide,classe, eh_radio) {
   if(itemsel != ide){ // se selecionado for atual nao faz nada
     $(ide).className=classe;		
   }
   if(classe == 'item'){
 		 changeImg('play'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_play1.gif');
		 changeImg('sinopse'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_maisinfo1.gif');
		 if(eh_radio == null){
		  changeImg('download'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_baixar1.gif');		
		 }else if(eh_radio){
		  changeImg('download'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_radio1.gif');
		 }else{ 		
		  changeImg('download'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_tv1.gif');
		 }
		 changeImg('visualizar'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_visualizar1.gif');
		 changeImg('imprimir'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_imprimir1.gif'); 
   }else{
 		 changeImg('play'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_play2.gif');
		 changeImg('sinopse'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_maisinfo2.gif');
		 if(eh_radio == null){
		  changeImg('download'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_baixar2.gif');			
		 }else if(eh_radio){
		  changeImg('download'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_radio2.gif');		  
		 }else{
		  changeImg('download'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_tv2.gif');
		 }		
		 changeImg('visualizar'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_visualizar2.gif');
		 changeImg('imprimir'+ide, 'http://sas-origin.OnstreamMedia.com/origin/2vtsis/tvmi/img/bt_imprimir2.gif');		 
   }
}
function download(id1, id2, eh_audio, forcetype){
 var url = null;
 if (id1 == '406') {
	 url = 'download/Apresentação_PISF_Relatorio_Progresso_Agosto_2008_para_internet.ppt';
	 window.open(url, 'wnd', 'width=100, height=100, toolbar=no, copyhistory=no, location=no, status=yes, menubar=no, scrollbars=no, resizable=yes, top=0, left=0');
	 return;
 } else {
  if(eh_audio == null) {
	 url = "http://zion.hotmedia.com.br:8080/zion/base/sys/flowplayer/images/getInstitImgStream/?id="+id1+"&id2="+id2;
  } else if(eh_audio) {
	 url = "http://zion.hotmedia.com.br:8080/zion/base/sys/flowplayer/audio/getPodcastStream/?id="+id1+"&cod="+id2;
  } else {
   url = "http://zion.hotmedia.com.br:8080/zion/base/sys/flowplayer/video/getPontoExecStream/?id="+id1+"&id2="+id2+"&tp=2"+"&ftype="+forcetype;
  }
 } 
 ifrmHidden.location.href = url;
}
function changeImg(imgName,imgSrc) {
 try {
	document[imgName].src = imgSrc;
 }catch(e){}
}
function itemSet(ide){
 if(itemsel != ide){ // se nao for selecionado continua
  if(itemsel != ""){ // se nao for a primeira vez troca
     $(itemsel).className="itemvid";
	 $('bt'+itemsel).className = "btplayitemvid";
  }
  itemsel = ide; // seta que o atual eh esse.
 }
}

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 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 EscreveDados2(local, val){
    if (local == "zdebug" && debugMode == true)
	dDiv = document.getElementById(local);
	dDiv.innerHTML = dDiv.innerHTML+"<br />"+val;
}
function EscreveDebug(local, val){
    if (debugMode){
 	 dDiv = document.getElementById(local);
	 dDiv.innerHTML = dDiv.innerHTML+"<br />"+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;
}

/*
	Bloco Extra
*/
function LeExtrasXML(ponto){
	var url = '../getBlocoExtra/';
	var pars = 'id=' + ponto;
	var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: processaExtrasXML});
}
function processaExtrasXML(originalRequest){
	tree = originalRequest.responseXML;
	var v = tree.getElementsByTagName("item");
	for(i=0; i < v.length; i++) {
		x = "";
		for (j=0;j<v[i].childNodes.length;j++) {
			if (v[i].childNodes[j].nodeType != 1) continue;
			if (v[i].childNodes[j].nodeName == "blocoid") {
				try{
				  var blocoid = v[i].childNodes[j].firstChild.nodeValue
				  x += v[i].childNodes[j].nodeName + ": " + v[i].childNodes[j].firstChild.nodeValue + "\r";
				} catch(e) {
				  var blocoid = "";
				}
			}
			if (v[i].childNodes[j].nodeName == "blocotipo") {
				try{
				  var blocotipo = v[i].childNodes[j].firstChild.nodeValue
				  x += v[i].childNodes[j].nodeName + ": " + v[i].childNodes[j].firstChild.nodeValue + "\r";
				}catch(e){
				  var blocotipo = "";
				}
			}			
			if (v[i].childNodes[j].nodeName == "urlstreaming") {
				try{
				  var urlstreaming = v[i].childNodes[j].firstChild.nodeValue
				  x += v[i].childNodes[j].nodeName + ": " + v[i].childNodes[j].firstChild.nodeValue + "\r";
				} catch(e){
				  var urlstreaming = "";
				}
			}			
		}
//		alert(x)
	} 
	if (blocoid != "") { // tem extra. vou verificar ...
		EscreveDebug("zdebug", "atual: "+blocoidAtual+" - blocoid: "+blocoid);		
		if(blocoid != blocoidAtual){ // se bloco diferente do atual, troca...
			blocoidAtual = blocoid;
			if(blocotipo == "3"){
				EscreveDebug("zdebug", "extra live: atual: "+blocoidAtual+" - blocoid: "+blocoid);
//				alert("tem extra, vou trocar: "+urlstreaming)
				zPlayExtra(urlstreaming);
			} else if (blocotipo == "2") { //
				EscreveDebug("zdebug", "video - buscando playlist...NAO IMPLEMENTADO");
			} else if (blocotipo == "1") { //
				EscreveDebug("zdebug", "audio - buscando playlist...NAO IMPLEMENTADO");
			}
		}
	} else if (blocoidAtual != "0"){
		EscreveDebug("zdebug", "Bloco normal");
		blocoidAtual = "0";	
		extra = false;
		zPlayBaseStream();
	} else {
		extra = false;
		EscreveDebug("zdebug", "sem alteracoes: "+blocoidAtual);	
	}	
}
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","Quarta","Quinta","Sexta","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]+" , "+year;
}
