function debug(aMsg){if(!dbg)return;var d=dg("imtheone");d.innerText+="\r\n"+aMsg;d.doScroll('scrollbarDown');}
function debugEx(aMsg){return;dbg=true;debug(aMsg);dbg=false;}
function debugAlways(aMsg){dbg=true;debug(aMsg);dbg=false;}
function dwln(s){document.writeln(s);}
function dg(i){return document.getElementById(i);}
function dgN(i){return document.getElementsByName(i);}
function dw(s){document.write(s);}
function IsNill(p){return p==null||(typeof(p)=="undefined")||String(p)=="";}
function LZ(n){n=parseInt(n,10);if( n < 10) return '0' + n;return n;}
var dontUseWizard = true;
// ------------- LIST FUNCTIONS -------------
function highlightLine(id, idx){
	var line = document.getElementById(id);
	if(line!=null){
		clearSelection();
		for(var i=0; i < line.children.length; i++)
			line.children(i).className='gfc';
		currentLine=line;
		currentLineIdx=idx;
	}
	else
		clearSelection();
}

function clearSelection(){
	if(currentLine!=null){
		var className;
		if(currentLineIdx==0)
			className='grdAl';
		else 
			className='';
		for(var i=0; i < currentLine.children.length; i++)
			currentLine.children(i).className=className;
	}
}
var currentLine=null;
var currentLineIdx=null;

function OnClickHandler(aLink,isPU,aTg)
{
//alert("aLink=" + aLink + ", isPU=" + isPU + ", aTg=" + aTg);
	if(!IsNill(aLink))
	{
		if(!IsNill(isPU) && isPU)
		{
			open(aLink);
		}
		else 
		{
			if ( !IsNill(aTg) && aTg!= "main" && !IsNill(frames[aTg]) )
				frames[aTg].location.href = aLink;
			else 
				location.href = aLink;
		}
	}
}
function SwapColors(o){var s=o.style.backgroundColor;o.style.backgroundColor=o.style.color;o.style.color=s;}
function WritePlusBtn(oid,cl,bgcl,tgUrl,imgPlus){
	var o = document.createElement('<span class=BtCross onMouseOver="SwapColors(this);" onMouseOut="SwapColors(this);" onClick="window.location=\''+tgUrl+'\';">');
	//o.innerText='+';
	var os=o.style;
	os.backgroundColor=bgcl;os.color=cl;
	os.borderRightColor=cl;os.borderTopColor=cl;os.borderLeftColor=cl;os.borderBottomColor=cl;
	document.getElementById(oid).appendChild(o);
	var otx = document.createElement('<img src="'+imgPlus+'" />');
	o.appendChild(otx);
}
		function findAppFrame(parentFrame)
		{
			try { if (parentFrame.AppWorkingFrameset != null) return parentFrame; } catch (e) {}
			var fr = null;
			for (var f=0;f<parentFrame.frames.length;f++)
			{
				fr = findAppFrame(parentFrame.frames[f]);
				if (fr != null) return fr;
			}
			return null;
		}
		function top_fs()
		{
			var fr = findAppFrame(top);
			if (fr == null) 
			{
				fr = window;
				window.AppWorkingFrameset = true;
			}
			return fr;
		}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
		return pair[1];
		}
	} 
	return "";
}

function showItem(idtab)
{
	var f1 = document.getElementById("td_"+tabs[idtab]);
	if(!f1)
		return 0;

	if( document.getElementById( "td_"+tabs[idtab] ) ) 
		document.getElementById( "td_"+tabs[idtab] ).className = 'tHnsc';
		
	for( var i=0; i < tabs.length; i++ )
	{
		if( i!=idtab )
			if( document.getElementById( "td_"+tabs[i] ) )
				document.getElementById( "td_"+tabs[i] ).className = 'tHsc';
	}
	return 1;
}


function CheckDate( ctrl ) {
	var d = ctrl.value;
	if( d != '' ) {
		var _day = d.substr(0, 2);
		var _month = d.substr(3, 2);
		var _year = d.substr(6, 4);
		if( !checkFullDate(_year, _month, _day, "00", "00") ) {
			ctrl.className = 'incorrecto';
			return false;
		}else
			ctrl.className = 'texto';
	}else
		ctrl.className = 'texto';
	return true;
}


/* Funções para colapsar e expandir conteudos - tipo FAQ */
function toggleAllBlocks(bExpand)
{
	var o, n;	
	
	n = 0;
	while (true)
	{
		o = document.getElementById("bloco" + n + "_detail");
		if (o == null) break;
		o.style.display = bExpand ? "" : "none";
		n+=1;
	}

	n = 0;
	while (true)
	{
		o = document.getElementById("bloco" + n + "_img");
		if (o == null) break;
		o.src = "appImages/seta_" + (bExpand ? "bott" : "dta") + ".gif";
		n+=1;
	}
	
	
	n = 0;
	while (true)
	{
		o = document.getElementById("bloco" + n + "_a");
		if (o == null) break;
		if (bExpand)
		{
	        o.title = "Fechar conteúdo";
	        o.onmouseover = function(){document.getElementById(this.id.replace("_a","_img")).src='appImages/seta_bott_on.gif';return true;};
	        o.onmouseout = function(){document.getElementById(this.id.replace("_a","_img")).src='appImages/seta_bott.gif';return true;};
		}
		else
		{
	        o.title = "Abrir conteúdo";
		    o.onmouseover = function(){document.getElementById(this.id.replace("_a","_img")).src='appImages/seta_dta_on.gif';return true;};
		    o.onmouseout = function(){document.getElementById(this.id.replace("_a","_img")).src='appImages/seta_dta.gif';return true;};
		}
		n+=1;
	}
	
	document.getElementById("collapseAll1").style.display = bExpand ? "" : "none";
	document.getElementById("expandAll1").style.display = bExpand ? "none" : "";

}


function toggleBlock(id)
{
	//alert('toggleBlock ' + id);
	var oBlockDetail = document.getElementById(id + "_detail");
	var oBlockImg = document.getElementById(id + "_img");
	var oBlockA = document.getElementById(id + "_a");
	
	if (oBlockDetail.style.display == "none")
	{
		oBlockDetail.style.display = "";		
		oBlockImg.src = "appImages/seta_bott_on.gif";	
		oBlockA.title = "Fechar conteúdo";
		oBlockA.onmouseover = function(){document.getElementById(id + "_img").src='appImages/seta_bott_on.gif';return true;};
		oBlockA.onmouseout = function(){document.getElementById(id + "_img").src='appImages/seta_bott.gif';return true;};
	}
	else
	{
		oBlockDetail.style.display = "none";
		oBlockImg.src = "appImages/seta_dta_on.gif";
		oBlockA.title = "Abrir conteúdo";
		oBlockA.onmouseover = function(){document.getElementById(id + "_img").src='appImages/seta_dta_on.gif';return true;};
		oBlockA.onmouseout = function(){document.getElementById(id + "_img").src='appImages/seta_dta.gif';return true;};	 
	}
		
	oBlockImg.scrollIntoView(true);	
}



function swapImage(imgTag, imgName)
{
	var i = document.getElementById(imgTag);
	if(i != null)
	{
		i.src=imgName;
	}
}

//Print Page Content
function doEmailPage(SNUrl, SectionName, SectionUrl) 
{	
	var destUrl = SNUrl + "?PageTitle=" + SectionName + "&FileUrl=" + SectionUrl;
	window.open(destUrl,"","status=0,toolbar=0, width=700, height=550, resizable=yes, scrollbars=yes"); 	
}

function encodeSTRING2URL(aStr)
{
	return escape(String(aStr).replace(/ /g,"+"));
}
		
		function encodeHREF2URL(aHref)
{
	var segment = null, query = null;
	var i = String(aHref).lastIndexOf("?");
	if(i==-1)
	{
		return escape(String(aHref)).replace(/\+/g,"%2B");
	}
	else
	{
		segment = escape(
			String(aHref).substring(0,i+1).replace(/\+/g,"%2B")
		);
		query = encodeSTRING2URL(
			String(aHref).substring(i+1,String(aHref).length)
		);
		return segment + query;
	}
}

//Função de escrita do Banner em flash sem Mouse over.
function writeFlash (id, width, height, flashUrl)
{
	var aSpan = document.getElementById(id);
	if( !aSpan )
		return;
		
	// show banner
	if (aSpan.innerHTML == '')
	{
		aSpan.innerHTML = "<OBJECT WIDTH='"+width+"' HEIGHT='"+height+"' " +
			"codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 " +
			"classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 VIEWASTEXT> " +
			"<PARAM NAME='WMode' VALUE='transparent'> " +
			"<PARAM NAME='FlashVars' VALUE=''> " +
			"<PARAM NAME='Movie' VALUE='"+flashUrl+"'> " +
			"<PARAM NAME='Src' VALUE='"+flashUrl+"'> " +
			"<PARAM NAME='WMode' VALUE='Window'> " +
			"<PARAM NAME='Play' VALUE='-1'> " +
			"<PARAM NAME='Loop' VALUE='-1'> " +
			"<PARAM NAME='Quality' VALUE='High'> " +
			"<PARAM NAME='SAlign' VALUE=''> " +
			"<PARAM NAME='Menu' VALUE='-1'> " +
			"<PARAM NAME='Base' VALUE=''> " +
			"<PARAM NAME='AllowScriptAccess' VALUE='always'> " +
			"<PARAM NAME='Scale' VALUE='ShowAll'> " +
			"<PARAM NAME='DeviceFont' VALUE='0'> " +
			"<PARAM NAME='EmbedMovie' VALUE='0'> " +
			"<PARAM NAME='BGColor' VALUE='FFFFFF'> " +
			"<PARAM NAME='SWRemote' VALUE=''> " +
			"<PARAM NAME='MovieData' VALUE=''> " +
			"<PARAM NAME='SeamlessTabbing' VALUE='1'> " +
			"<EMBED src='"+flashUrl+"'  " +
			"WIDTH='"+width+"' HEIGHT='"+height+"' " +
			"quality='high' wmode='transparent' bgcolor='#FFFFFF' TYPE='application/x-shockwave-flash'  " +
			"PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'> " +
			"</EMBED><NOEMBED> " +
			"</NOEMBED> " +
			"</OBJECT>";
	}
	else
	{
		if (aSpan.childNodes.length > 0)
		{
			var oSWF = aSpan.childNodes[0];
			if (oSWF.tagName.toLowerCase() == 'object')
			{
				try
				{
					oSWF.stop();
					oSWF.rewind();
					oSWF.play();
				}
				catch (e) {}
			}
		}
	}
	
	if (document.all == null)
	{
		aSpan.style.visibility = 'visible';
		aSpan.style.position = 'relative';
		aSpan.style.left = '0px';
		aSpan.style.top = '0px';
	}
	else
	{
		aSpan.style.display = 'inline';
	}			
}

function HideFloat() {
	var d=top_fs().document;var dph=d.getElementById('floatph');if (dph!=null) dph.innerHTML='';
	/*
	MM_showHideLayers('Layer1','','hide');
	var iHeight = 440;
    if (parent) if (parent.document) if (parent.document.getElementById("main")) 
	{
		if (document.body.scrollHeight + 10 > iHeight)
			iHeight = document.body.scrollHeight + 10
	
		if (iHeight>parent.document.getElementById("main").height) { 
				parent.document.getElementById("main").height=iHeight;
				}
		else {
				parent.document.getElementById("main").height=441;
		}
	}
*/
}

// Search Functions - Start
function getNextQuote ( s, lastIndexQuoteFound ) {
	return String(s).indexOf('"',lastIndexQuoteFound);
}
function getQuotedTerms(s) {
	var v = new Array();
	var n = 0;
	var i=-1, j=-1;
	do {
		i = getNextQuote( s, j + 1 );
		if( i > -1 ) {
			j = getNextQuote( s, i + 1 );
			v[n] = s.substring( i+1, j );
			++n;
		}
	}
	while( i > -1 && j > -1 );
	return v;
}

function getUnQuotedTerms(s) {
	var v = new Array();
	var n=0, i=0;
	var a = s.split('"');
	for( i = 0 ; i < a.length ; ++i ) 
	{
		if(i==0)
			v[n++] = a[i];
		else if( i == a.length - 1 )
			v[n++] = a[i];
		else if( n%2 == 0 )
			v[n++] = a[i];
	}
	return v;
}

function ValidateFullTextSearchExpression(s) {
	var quoted = getQuotedTerms(s);
	var unquoted = getUnQuotedTerms(s);
	// Tamanho total do texto entre aspas
	var quotedCharSum = 0;
	var success = true;
	// Tamanho das expressões entre aspas
	for(var i = 0 ; i < quoted.length ; i++) {
		if( quoted[i].length < 2 ) {
			success = false;
			break;
		}
	}

	if( success ) {
		// Tamanho das palavras no texto fora de aspas
		for(var j = 0 ; j < unquoted.length ; j++) {
			var unquotedWords = unquoted[j].split(' ');
			for(var k = 0; k <unquotedWords.length; ++k ) {
				if( String(unquotedWords[k]).replace(' ', '').length > 0 && unquotedWords[k].length < 3 ) {
					success = false;
					break;
				}
			}
		}
	}
	return success;
}	


// Search Functions - End