function calendarioF(calendarioId, template, uf, local, site){
	//site: http://www.clicrbs.com.br/planeta
	var urlSite = site;
	var pagina = escape(site+"/jsp/default.jsp?section=Calendário eleitoral&uf="+uf+"&local="+local+"&calendarioid="+calendarioId+"&template="+template);
	document.location.href=site+"/jsp/default.jsp?section=Calendário eleitoral&uf="+uf+"&local="+local+"&template=1740.dwt&pagina_calendario="+pagina+"&urlSite="+urlSite;
}

function optionPartido()
{
	document.formDetalhe.partidoid.value= document.formDetalhe.selpart.options[document.formDetalhe.selpart.selectedIndex].value;
	document.formDetalhe.submit();
}

function optionGuia()
{
	oValue = document.formGuia.selitem.options[document.formGuia.selpart.selectedIndex].value;
    document.formGuia.template.value=oValue.substring(oValue.indexOf(',')+1)+'.dwt';
	if ( document.formGuia.template.value == '.dwt' || document.formGuia.template.value == '0.dwt')
		document.formGuia.template.value = '1575.dwt';
//    document.formGuia.itemid.value=);	
    document.formGuia.itemid.value=oValue.substring(0,oValue.indexOf(',') );	
	document.formGuia.submit();
}

function doCartorios()
{
	ok = true;
	if (document.formGuia.selitemmun.selectedIndex== 0 && document.formGuia.zona.value.length==0)
		alert('Você tem que informar a zona ou selecionar o município');
	else {
	if (document.formGuia.zona.value.length > 0	) {
	  if (isNaN(document.formGuia.zona.value)) {
	   	 alert("Você não preencheu o campo Zona corretamente. Por favor, revise-o.");
		 document.formGuia.zona.focus();
		 ok = false;
	 }
	 document.formGuia.munid.value = ''; 
 	 document.formGuia.newsID.value= "DYNAMIC,rbs.eleicoes.CartoriosDataServer,getCartorioporZona";	
	} else {
	  document.formGuia.munid.value = document.formGuia.selitemmun.options[document.formGuia.selitemmun.selectedIndex].value; 
 	  document.formGuia.newsID.value= "DYNAMIC,rbs.eleicoes.CartoriosDataServer,getCartorioporMunicipio";
	} 
	 document.formGuia.template.value= "3253.dwt";	
	 if (ok) document.formGuia.submit();
	 
	} 
}

function abrecanal(url,uf) {
	top.location.href = "/clicstation/jsp/expanded_sites.jsp?canal="+ url +"&uf="+ uf;
}

function abrecsPorCanal(nCanal,uf,rev){
	top.location.href = "/clicstation/jsp/expanded_sites.jsp?canal="+nCanal+"&uf="+uf+"&rev="+escape(rev);
}
function playersr(nomeVideo, uf) { //v2.0
      var theURL ="/clicstation/jsp/player_compact_mode.jsp?nomeVideo=video/"+nomeVideo+"&uf="+uf;
	  var winName ="clicRBS";
	  var features ="scrollbars=no,width=250,height=300";
	  window.open(theURL,winName,features);
}
function canal(nCanal, nUf){ 
 window.open("/clicstation/jsp/player_compact.jsp?canal="+nCanal+"&uf=RS&nomeVideo=http://www.clicrbs.com.br/clicstation/videos/" +nUf+ "/"+nCanal+".smil","clicStation","width=253,height=326"); 
}
function canal2(nCanal, nUf){ 
 window.open("/clicstation/jsp/player_compact_sr.jsp?canal="+nCanal+"&uf=RS&nomeVideo=http://www.clicrbs.com.br/clicstation/videos/" +nUf+ "/"+nCanal+".smil","clicStation","width=250,height=300"); 
}
function abrecs(video,uf){
  location.href = "/clicstation/jsp/player_compact_sr.jsp?canal=nenhum&uf="+ uf +"&previousurl=http://www.clicrbs.com.br/";
}

function abrecs2(video,uf,nCanal){
 window.open("/clicstation/jsp/player_compact_sr.jsp?canal="+nCanal+"&nomeVideo="+video+"&uf="+uf,"clicStation","width=250,height=300");
}

function linkImagem(p_width,p_height,p_file,p_author,p_copyright,p_legend){
 var popup=null;
  popup=openModal("/jsp/rt.jsp?rootdir=/shared&width="+p_width+"&height="+p_height+"&file="+p_file+"&author="+escape(p_author)+"&copyright="+escape(p_copyright)+"&legend="+escape(p_legend)+"&template=24.dwt",p_width+100,p_height+100,"Imagem");
 }

function linkImagemNoticia(p_width,p_height,p_file,p_author,p_copyright,p_legend){
 var popup=null;
 if(!p_file.elements){
  popup=openModal("/jsp/rt.jsp?rootdir=/shared&width="+p_width+"&height="+p_height+"&file="+p_file+"&author="+escape(p_author)+"&copyright="+escape(p_copyright)+"&legend="+escape(p_legend)+"&template=24.dwt",p_width+100,p_height+100,"Imagem");
 }
 else{
  document.joker.p_comp.value=p_file.p_comp.value;
  document.joker.p_width.value=p_file.p_width.value;
  document.joker.p_height.value=p_file.p_height.value;
  document.joker.p_legend.value=p_file.p_legend.value;
  document.joker.p_author.value=p_file.p_author.value;
  document.joker.p_copyright.value=p_file.p_copyright.value;
  document.joker.p_type.value="I";
  var v_width=p_width+60;
  var v_height=p_height+100;
  popup = window.open("/rbs/html/popup.htm","RBS","resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=no,width="+v_width+",height="+v_height);
 }
}

function linkImagemOriginal(p_width,p_height,p_file,p_author,p_copyright,p_legend){
if(p_width==''){
p_width=250;}

if(p_height==''){
p_height=250;}

 var popup=null;
 if(!p_file.elements){
  popup=openModal("/jsp/rt.jsp?rootdir=/shared&width="+p_width+"&height="+p_height+"&file="+p_file+"&author="+escape(p_author)+"&copyright="+escape(p_copyright)+"&legend="+escape(p_legend)+"&template=24.dwt",p_width+100,p_height+100,"Imagem");
 }
 else{
  document.joker.p_comp.value=p_file.p_comp.value;
  document.joker.p_width.value=p_file.p_width.value;
  document.joker.p_height.value=p_file.p_height.value;
  document.joker.p_legend.value=p_file.p_legend.value;
  document.joker.p_author.value=p_file.p_author.value;
  document.joker.p_copyright.value=p_file.p_copyright.value;
  document.joker.p_type.value="I";
  var v_width=p_width+60;
  var v_height=p_height+100;
  popup = window.open("/rbs/html/popup.htm","RBS","resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=no,width="+v_width+",height="+v_height);
 }
}

function linkFlash(p_width,p_height,p_file,p_author,p_copyright,p_legend){
 var popup=null;
 if(!p_file.elements){
  popup = openModal('/clicstation/jsp/map.jsp?pfile=http://www.clicrbs.com.br/flash/'+p_file+'&pwidth='+p_width+'&pheight='+p_height,p_width,p_height,p_legend);
 }
 else{
  document.joker.p_comp.value=p_form.p_comp.value;
  document.joker.p_width.value=p_form.p_width.value;
  document.joker.p_height.value=p_form.p_height.value;
  document.joker.p_legend.value=p_form.p_legend.value;
  document.joker.p_author.value=p_form.p_author.value;
  document.joker.p_copyright.value=p_form.p_copyright.value;
  document.joker.p_type.value="F";
  var v_width=p_width+60;
  var v_heigh=p_height+100;
  popup=window.open("/rbs/html/popup.htm","RBS","resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=no,width="+v_width+",height="+v_height);
 }
}

function abrecs1(video,uf){
window.open("/clicstation/jsp/player_compact_sr.jsp?nomeVideo="+video+"&uf="+uf,"clicStation","width=250,height=300");
}
function linkAudio(p_audio,uf){abrecs1('audio/'+p_audio,uf);}
function linkVideo(p_video,uf){abrecs1('video/'+p_video,uf);}
function linkEncode(p_video,uf){if(uf==null) uf='RS'; abrecs1(p_video,uf);}
function linkPopup(p_cat,p_tem,p_width,p_height,p_url){
	 if (p_width==0 && p_height==0){
        popup=window.open('/jsp/popup.jsp?catgid='+p_cat+'&template='+p_tem+'.dwt&p_url='+p_url, 'PopUP');
     }else{
        popup=window.open('/jsp/popup.jsp?catgid='+p_cat+'&template='+p_tem+'.dwt&p_url='+p_url, 'PopUP', 'resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=yes,width='+p_width+',height='+p_height);
	}
}
function linkPdf(p_arq,p_width,p_height){
 popup=window.open('/pdf/'+p_arq, 'Pdf', 'resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=no,width='+p_width+',height='+p_height); 
}

function doSubmit(t,n,s,tplt,c){
	document.formDefault.tab.value=t;
	document.formDefault.newsID.value=n;
	document.formDefault.subTab.value=s;
	document.formDefault.action="/eleicoes2006/jsp/default.jsp";
	document.formDefault.submit();
}

function linkRelacionadas(p_tab,p_fsname,p_subtab){
 if(p_tab!=null & p_fsname!=null){doSubmit(p_tab,p_fsname,p_subtab);}
 else{doSubmit('inc/ultimas_detalhe.jsp','html/'+p_tab,'200');}
}
function changeColumn(columnId){
 if(columnId!=''){
  document.formDefault.newsID.value='a'+columnId+'.htm';
  document.formDefault.submit();
 }
}
var oWindow = null;
function openModal(poUrl,poWidth,poHeight,poWindowName,poScroll){
 var oLeft,oTop,oAttr,oWindowName;
 var Nav4=((navigator.appName=="Netscape") && (parseInt(navigator.appVersion)==4));
 var Nav4plus=((navigator.appName=="Netscape") && (parseFloat(navigator.appVersion)>4.04));
 var Nav5=((navigator.appName=="Netscape") && (parseInt(navigator.appVersion)==5));
 var Nav6=((navigator.appName=="Netscape") && (parseInt(navigator.appVersion)==6));
 var IE4=((navigator.appName.indexOf("Microsoft")>-1)) && (parseInt(navigator.appVersion)==4);
 var IE5=((navigator.appName.indexOf("Microsoft")>-1)) && (parseInt(navigator.appVersion)==5);
 var IE6=((navigator.appName.indexOf("Microsoft")>-1)) && (parseInt(navigator.appVersion)==6);
 var anyIE=(IE4||IE5||IE6);
 var anyNav=(Nav4||Nav4plus||Nav5||Nav6);
 var oScroll=false;
 if(poScroll!= null) oScroll=poScroll;
 if(Nav4){
  oLeft=window.screenX+((window.outerWidth-poWidth)/2);
  oTop=window.screenY+((window.outerHeight-poHeight)/2);
  oAttr="screenX="+oLeft+",screenY="+oTop+",location=no,toolbar=no,directories=no,status=no,resizable=no,dependent=yes,width="+poWidth+",height="+poHeight;
 }else{
  oLeft=(screen.width-poWidth)/2;
  oTop=(screen.height-poHeight)/2;
  oAttr="left="+oLeft+",top="+oTop+",location=no,toolbar=no,directories=no,status=no,resizable=no,width="+poWidth+",height="+poHeight;
 }
 if(oScroll)oAttr+=",scrollbars=yes"
 if(poWindowName==null)oWindowName="modal";
 else oWindowName=poWindowName;
 if(oWindow && oWindow.open)closeModal();
 oWindow=window.open(poUrl,oWindowName,oAttr );
 oWindow.focus();
}
function closeModal(){
 oWindow.close();
 oWindow=null;
}
function doPops(uf,l,tab,tplt){openModal("/jsp/rt.jsp?template="+tplt+"&rootdir=/shared&uf="+uf+"&l="+l+"&tab="+tab,550,565,"POP" ,true);}
function  doFale(uf,l,tab,tplt){openModal("/jsp/rt.jsp?template="+tplt+"&rootdir=/shared&uf="+uf+"&l="+l+"&tab="+tab,570,570,"POP" ,true);}
function doFaq(uf,l,tab,tplt){openModal("/jsp/rt.jsp?template="+tplt+"&rootdir=/shared&uf="+uf+"&l="+l+"&tab="+tab,550,500,"FAQ" ,true);}
function doPrint(newsId,chanID){openModal("/jsp/print.jsp?newsID="+newsId+"&chanID="+chanID+"&tab=00000",565,500,"PRINT",true);}
function doFriend(){openModal("/jsp/send_friend.jsp?url="+escape(document.location),550,350,"FRIEND",true);}

function MM_preloadImages(){
 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_swapimgRestore(){
 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){
 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 && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage(){
 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 OpenPopup(p_url,p_window,p_width,p_height){window.open(p_url,p_window,'resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=no,width='+p_width+',height='+p_height);}

function getSplit(poTokenized,poDelimiter,poPosition){
 var oTokens=new Array(4);
 var i = 0;
 var oTokenized = poTokenized;
 while( oTokenized.length > 0 ){
  var oToken = null;
  if( oTokenized.indexOf(poDelimiter) != -1 ){
   oToken = oTokenized.substring(0,oTokenized.indexOf(poDelimiter));
   oTokenized = oTokenized.substring(oTokenized.indexOf(poDelimiter)+1);
  }else{
   oToken = oTokenized;
   oTokenized = "";
  }
  oTokens[i] = oToken;
  i++;
 }
 return oTokens[poPosition];
}

function open_chat(){
 var user=document.chat.user.value;
 var screen=document.chat.screen.value;
 var room=document.chat.room.options[document.chat.room.selectedIndex].value;
 var chatter=document.chat.chatter.value;
 user=escape(user);
 var URL ="http://clicpapo.clicrbs.com.br/cgi-bin/inchat/inchat.pl?login=1&user="+user+"&screen="+screen+"&room="+room+"&chatter="+chatter;
 window.open(URL,"OpenInchat","width=710,height=525,top=0,left=0");
 return false;
}
function doChat(){
 if(document.chat.user.value.length==0){alert("Por favor, informe o seu apelido.");}
  else{
   if(document.chat.room.options[document.chat.room.selectedIndex].value==''){alert("Por favor, escolha uma sala.");}
   else{open_chat();}
  }
}

function doChatCapa(room_id) {
 if (room_id != null)
	window.open('/jsp/popup_ingresso_chat.jsp?room='+room_id, 'ingresso', 'toolbar=no,menubar=no,resizable=no,scrollbars=no,width=250,height=200');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
 window.open(theURL,winName,features);
 }

function navigate(start){
 document.navigation.start.value = start;
 document.navigation.submit();
}

function popupEnvie(){
//alert(escape(NewsURL));
 var NewsURL = document.URL;
 popup=window.open("http://www.clicrbs.com.br/copadomundo/jsp/send_friend.jsp?url="+escape(NewsURL), "PopUP", "resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=no,width=430,height=370");
 }			 

function popupImpressao(newsID,template){			  
	window.open( 'print.jsp?newsID='+newsID+'&template='+template, 'PopUP', 'resizable=yes,location=no,directories=no,status=no,toolbar=no,menubar=no,scrollbars=yes,width=600,height=500');
}

	function setCookie(sName, sValue){
		var date = new Date();
  		document.cookie = sName + "=" + escape(sValue) + ";path=/;";
	}

	function logout(){
  		setCookie("cdmuser", "-none");
		document.loginform.op.value = "3";
		document.loginform.action = "/servlet/LogonServlet";
		document.loginform.submit();
	}
	function update(){
		document.loginform.action = "/servlet/SignUpServlet";
		document.loginform.submit();
	}

function openNews(tab, newsid, subtab, site, espid, uf, local){
//	var uf = "1";
//	var local = "1";
	var canal = tab;
	var materia = newsid;
	var cartola = subtab;
	if (site == " ") site = "http://www.clicrbs.com.br";
	document.location.href=site+"jsp/default.jsp?uf="+uf+"&local="+local+"&tab="+canal+"&newsID="+materia+"&subTab="+cartola+"&espid="+espid+"&uf="+uf+"&local"+local;
}

 function link_gallery(p_type, p_path, p_template, p_gallery_id, p_group_id, p_popup_width, p_popup_height, p_parameters_site, p_uf, p_local){
 	if (p_uf == ' ') p_uf = "1";
	if (p_local == ' ') p_local = "1";
	
	var tam = p_path.length;
	if (tam > 0){
		var position = p_path.indexOf("/",0);
		if (position == 0) p_path = p_path.substring(1, tam);
		tam = p_path.length;
		position = p_path.lastIndexOf("/", tam);
		if (position == (tam - 1)) p_path = p_path.substring(0, position);
	}
 	//p_type = 1 (galeria), p_type = 2 (sequencia de fotos)
 	if (p_type == "1"){
		document.location.href = "http://www.clicrbs.com.br/"+p_path+"/jsp/default.jsp?newsID=DYNAMIC%2Cgaleria.GalleryDelivery%2CphotosGalleryXml&pg=1&template="+p_template+"&groupid="+p_group_id+"&galeriaid="+p_gallery_id+"&uf="+p_uf+"&local="+p_local+p_parameters_site;
	}else{
		var pagina = "http://www.clicrbs.com.br/"+p_path+"/jsp/default.jsp?template=1552.dwt&ids=null&initial=null&playsshow=false&b=1&arquivo_xml=galeria_"+p_gallery_id+"_"+p_group_id+".xml&uf="+p_uf+"&local="+p_local+p_parameters_site;
 		MM_openBrWindow(pagina,'Galeria','scrollbars=auto,resizable=yes,width='+p_popup_width+',height='+p_popup_height);
 	}
}

function linkLsb(pSpevId){
  var url = "http://www.clicrbs.com.br/clicesportes/jsp/lsb.jsp?chanid=2&tab=00003&spevid="+pSpevId;
  openModal( url, 750, 504,'lsbce',false );
}

function popupFormArq(title,mailTo){
  var url = "http://www.clicrbs.com.br/formulario/jsp/pop_formulario_arq.jsp?titulo=" + title + "&emailAlvo=" + mailTo; 
  window.open(url,'popup','width=590,height=540,scrollbars=1');

}
function popupFormMsg(title,mailTo){
  var url = "http://www.clicrbs.com.br/formulario/jsp/pop_formulario_msg.jsp?titulo=" + title + "&emailAlvo=" + mailTo; 
  window.open(url,'popup','width=590,height=540,scrollbars=1');

}



/** Retorna um elemento HTML a aprtir de seu ID.
 */
function $( elementoId ) {
	return document.getElementById( elementoId );
}

/** Exibe um elemento.
 */
function mostra( elemento ) {
	$( elemento ).style.display = 'block';
}
/** Oculta um elemento.
 */
function esconde( elemento ) {
	$( elemento ).style.display = 'none';
}

/** Exibe uma mensagem em um 'alert' e seta o foco para um determinado campo.
 * Geralmente, a mensagem serah uma mensagem de validacao indicando que o campo deve ser
 * preenchido/selecionado ou que estah preenchido com um valor invalido.
 */
function alertFocus( msg, campo ) {
	alert( msg );
	campo.focus();
	return false;
}
/** Verifica se um SELECT estah selecionado em alguma opcao que nao seja a primeira.
 */
function naoSelecionado( s ) {
	return s.selectedIndex == 0;
}

/** Verifica se um algum RADIOBUTTOM de um conjunto estah selecionado.
 */
function nenhumSelecionado( r ) {
	for ( i=0 ; i<r.length ; i++ )
		if ( r[i].checked )
			return false;
	return true;
}

/** Verifica se um INPUT TEXT (ou TEXTAREA) estah vazio.
 */
function vazio( str ) {
	return trim( str ) == "";
}
function trim( str ) {
	return str.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

function somenteNumeros( str ) {
	return str.match( /^\d+$/g ) ? true : false;
}

function emailValido( str ) {
	return str.match( /^(([^\W]([\w_\.\-])*[^\W])|(\w))@(([\w_\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ) ? true : false;
}
