function cNumber(n) {
	
	if (n.indexOf(",") >=0) {
		n = replaceSubstring(n, ",", ".");
		n = n * 1;
	}
	return n;
}



Array.prototype.max = function(){
	return Math.max.apply({},this)
}
Array.prototype.min = function(){
	return Math.min.apply({},this)
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.prototype.linkTarget = function(url, target) {
	var s = '';
	s = '<A HREF="'+url.trim()+'" ';
	if (target == '_self' || target == '_blank' || target == '_parent' || target == '_top') {
		s += 'target="'+target+'"';
	}
	s += '>'+this.trim()+'</A>';
	return s;
}


function transferItemToFlash()
{
	
}
/// <author>Chbeir Elias</author>
/// <summary>
/// Show the content of a HTML string in a DIV whatever is the browser
/// </summary>
/// <returns>Nothing</returns>
function DisplayList(monthsString, _layer, _secLayer)
{
	var NS  = navigator.appName == "Netscape";
	var NS5 = (NS && parseInt(navigator.appVersion) > 4);
	var NS4 = (document.layers) ? true : false;
	var IE4 = (document.all) ? true : false;

	if (NS4)
	{
		listToDisplay = "<span>" + monthsString + "</span>";
		
		eval("document." + _layer + ".document." + _secLayer + ".document.write(monthsString)"); 
		eval("document." + _layer + ".document." + _secLayer + ".document.close()");
		//alert("NS4");
	}
	else 
	{
		if (NS5) 
		{
			eval("document.getElementById('" + _secLayer + "').innerHTML = monthsString");
			//alert("NS5");
		}
		else
		{
			// IE4+
			eval(_secLayer + ".innerHTML = monthsString");
		}
	}
}
/* Begin BuildQueryString */
  function BuildQueryString_old(formName)
   {
   var theForm = eval("document." + formName);
   var action = theForm.url; 

   // if action's url has a querystring
   if (action.indexOf("?") > 0)
   {
      // get the Querystring from the action url
      var querystr = action.split("?")[1]; 
      // reset the action of the url without the querystring
      action = action.split("?")[0]; 
      // split the querystring into its parts (separated by the "&")
      var parts = querystr.split("&");
      var partName = "";

      for (var part = 0; part < parts.length; part++)
      {
         partName = parts[part].split("=")[0];
         // check the query part's names and add to the action url 
         // querystring only what is needed for the .Net page
         if ((partName.toLowerCase() == "show")||(partName.toLowerCase() == "asp_page")
            ||(partName.toLowerCase() == "src"))
         {
            action += (action.indexOf("?") < 0) ? "?" : "&";
            action += parts[part];
         }
      }
   }

   // add the form elements to the action url querystring 
   for (var i = 0; i < theForm.elements.length; i++) {
      var name = escape(theForm.elements[i].name);
      if (name != "") {
         action += (action.indexOf("?") < 0) ? "?" : "&"; 
         var str = name + "=" + escape(theForm.elements[i].value);
         action += str;
      }
   }

   theForm.action = action;
   return true;
   }

/* Begin BuildQueryString */
function BuildQueryString(formName)
{
	var theForm 	= eval("document." + formName);
	var action 		= theForm.action; 
	//var src 		= GetPrmFromQString(action, "src");
	//var show 		= GetPrmFromQString(action, "show");
	var src 		= __src;
	var show 		= __show;

	var asp_page 	= GetPrmFromQString(action, "asp_page");
	var resultUrl = "/default.aspx?show=" + show + "&src=" + src + "&asp_page=" + asp_page;
	
	// add the form elements to the action url querystring 
	for (var i = 0; i < theForm.elements.length; i++) {
	  var name = escape(theForm.elements[i].name);
	  if (name != "") {
		 var str = "&" + name + "=" + escape(theForm.elements[i].value);
		 resultUrl += str;
	  }
	}
	theForm.action = resultUrl;
	return true;
}

function GetPrmFromQString(url,prm) {

	if (((url.length - url.indexOf(".htm")) == 4) || ((url.length - url.indexOf(".html")) == 5)) {

	var haveSRC = url.indexOf("/"+prm+"/");
		if (haveSRC > 0) {
			var subS = url.substring(haveSRC+prm.length+2, url.length);
			if (subS.indexOf("/") > 0) {
				subS = subS.substring(0,subS.indexOf("/"));
			}
			else if (subS.indexOf(".htm") > 0) {
				subS = subS.substring(0,subS.indexOf(".htm"));
			}
			else if (subS.indexOf(".") > 0) {
				subS = subS.substring(0,subS.indexOf("."));
			}
			else {
			 	subS = '';
			}
			return subS;
		}
		else {
			return '';	
		}
	}
	else if (url.indexOf(".aspx?") > 0) {
		var haveSRC  = url.indexOf(prm+"=");
		if (haveSRC > 0) {
			var subS = url.substring(haveSRC+prm.length+1, url.length);
			if (subS.indexOf("&") > 0) {
				subS = subS.substring(0,subS.indexOf("&"));
			}
			else {
				subS = subS.substring(0,url.length);
			}
			return subS;
		}
		else {
			return '';
		}
	}
	else {
		return '';
	}
}





/* Show date */
function show_date () {
	var now = new Date(); var year = now.getUTCFullYear();
	var month = now.getMonth();	var day = now.getDate(); var ar = new Array(12);
	ar[0] = "Janeiro"; ar[1] = "Fevereiro"; ar[2] = 'Mar\347o';	ar[3] = "Abril";
	ar[4] = "Maio";	ar[5] = "Junho"; ar[6] = "Julho"; ar[7] = "Agosto";
	ar[8] = "Setembro";	ar[9] = "Outubro"; ar[10] = "Novembro";	ar[11] = "Dezembro";
	var totalDate = day + " " + ar[month] + " " + year;	document.write(totalDate);
}

function eventTrigger (evt) {
if (!evt) { var e= (window.event) ? window.event : evt } return e;
}
function MO(e) {
if (!e) {var e = eventTrigger(e);}
var S = (e.target) ? e.target : e.srcElement;
while (S.tagName!="TD") {S=S.parentNode;}
S.className="generic_module_text_hover";
}
function MU(e) {
if (!e) {var e = eventTrigger(e);}
var S = (e.target) ? e.target : e.srcElement;
while (S.tagName!="TD") {S=S.parentNode;}
S.className="generic_module_text";
}
function HO(e) {
	if (!e) { var e = eventTrigger(e); }
	var S = (e.target) ? e.target : e.srcElement;
	while (S.tagName!="TD") {S=S.parentElement;}
	S.className="header_menu_background_hover";

}
function HU(e) {
if (!e) { var e = eventTrigger(e); }
var S = (e.target) ? e.target : e.srcElement;
while (S.tagName!="TD") {S=S.parentElement;}
S.className="header_menu_background";
}
function FO(e) {
if (!e) { var e = eventTrigger(e); }
var S = (e.target) ? e.target : e.srcElement;
while (S.tagName!="TD") {S=S.parentElement;}
S.className="celllightblue";
}
function FU(e) {
if (!e) { var e = eventTrigger(e); }
var S = (e.target) ? e.target : e.srcElement;
while (S.tagName!="TD") {S=S.parentElement;}
S.className="celldarkblue";
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function OpenWindow(url) {
	window.open(url,"","resizable=yes,width=520,height=465");
}
function OpenWindowResize(url, width, height){
	var props = "toolbar=no,menubar=no,scrollbars=yes,top=100,left=100,height=" + height + ",width=" + width;
	window.open(url,"",props)
}
// Description: Used for the Search functionality
function setFirstSubmit(frm, PageFirst) {
	frm.first.value = PageFirst;
	frm.submit();
}
function setFirstZero(frm) {
	frm.first.value = 0;
}
function setFirstZeroSubmit(frm) {
	setFirstSubmit(frm, 0);
}
function setShowAndSubmit(frm, show) {
	frm.show.value = show;	
	setFirstZeroSubmit(frm);
}
// Begin of Banner section
function Random(array) {
	var maxi = 0; var len = array.length;
	for (i=0; i < len; i++) { maxi = maxi + array[i][1];}
	var rnd = Math.floor(Math.random()*maxi); var counter = 0; i=0;
	while ((counter + array[i][1]) < rnd) {	counter = (counter + array[i][1]); i++;}
	return new Array(array[i], i);
}
function GetUrlBanner(arrPos) {
	var pos = sIN(arrPos);
	var arrayA = eval(rIN(arrPos));
	var array = arrayA[pos];
	if (array[9] == "mainFrame") {document.location.href = array[7];}
	else if (array[9] == "newWindow") {
	window.open(array[7],"",'height='+array[2]+',width='+array[3]+',location, resizable, menubar, toolbar,left=30,top=30,scrollbars, status');}


	function rIN(s) {
		var a = '_'; 
		var u = '';
		var i = s.lastIndexOf(a);
		if (i >= 0) {u = s.substring(i+1);}
		else {u = s;}; return u;	
	}
	function sIN(s) {
		var a = '_'; 
		var u = '';
		var i = s.lastIndexOf(a);
		if (i >= 0) {u = s.substring(0,i);}
		else {u = s;}; return u;	
	}

}
function GetUrlAnim(arrPos, type) {
	var array = "";	array = rFlash[arrPos];
	if (array[9] == "mainFrame") { document.location.href = array[7];}
	else if (array[9] == "newWindow") {
	window.open(array[7],"",'height="'+array[4]+'",width="'+array[5]+'",location, resizable, menubar, toolbar,left=30,top=30,scrollbars, status');
	}
}
function GetBanner(rBanner, arrName) {

	var arrayA = Random(rBanner);
	var array = arrayA[0];
	var pos = arrayA[1];
	var bannerHTML = '';
	if (array[6] == "flash") {
		bannerHTML +='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="468" height="60">';
		bannerHTML +='<param name="movie" value="/images/'+array[0]+'?clickTAG='+pos+'_'+arrName+'">';
		bannerHTML +='<param name="quality" value="high">';
		bannerHTML +='<embed src="/images/'+array[0]+'?clickTAG='+pos+'_'+arrName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="468" height="60"></embed>';
		bannerHTML +='</object>';
		document.write(bannerHTML);
	}
	else if (array[6] == "image") {
		document.write('<A HREF="javascript:GetUrlBanner(\''+pos+'_'+arrName+'\');"><IMG SRC="/images/'+array[0]+'" ALT="'+array[8]+'" WIDTH="'+array[4]+'" HEIGHT="'+array[5]+'" BORDER=0 TARGET="'+array[9]+'"></A>');
	}	


}

function GetFlash() {
	var ShockMode = 0; 
	var cWidth = document.body.clientWidth;
	var cHeight = document.body.clientHeight;

	var ShockMode = 1;

	if (ShockMode ==1) { 
	//set document cookie
		if ((get_cookie("transAnimation")!="True") || (repeat == "on")) {
			document.cookie="transAnimation="+"True";
			var arrayA = Random(rFlash);
			var array = arrayA[0];
			var pos = arrayA[1];
			var transHTML = '';
			//transHTML += '<div id="TransAds" style="position:fixed; left:0px; top:150px; width:'+cWidth+'px; height:'+cHeight+'px; z-index:4" align="center">';
transHTML += '<div id="TransAds" style="position:absolute; left:0px; top:100px;  width:'+cWidth+'px; height:'+cHeight+'px; z-index:4" align="center">';			
			transHTML += '<object ID=TransAdsMovie classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="336" height="280">';
			transHTML += '<param name=movie value="/images/'+array[0]+'?clickTAG='+pos+'"> ';
			transHTML += '<param name="wmode" value="transparent"> ';
			transHTML += '<param name=quality value=high> ';
			transHTML += '<param name=scale value=showall> ';
			transHTML += '<embed NAME=TransAdsMovie  swliveconnect="true"  src="/images/'+array[0]+'?clickTAG='+pos+'" quality=high pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="336" height="280" wmode="transparent" allowScriptAccess="sameDomain">';
			transHTML += '</embed></object></div>';
			document.write(transHTML);
			
		}
	} 

}





function get_cookie(Name) {
	var search = Name + "="; var returnvalue = "";
	if (document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length; 
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
		returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
} 
function removeDiv() {

		document.getElementById("TransAds").style.display = 'none';

}
function popUpWH(URL, m_W, m_H)	{
	var H, W; W = m_W; H = m_H;
	var intScrWidth=(window.screen.width/2) - ((W/2)+10);
	var intScrHeight=(window.screen.height/2) - ((H/2)+60);
	memFenetre=window.open(URL, "artikels", "height=" + H + ",width=" + W + ",scrollbars=no,resizable=yes,screenX=" + intScrWidth + ",screenY=" + intScrHeight + ",left=" + intScrWidth + ",top=" +intScrHeight);
}
function getFlashMovieObject() {
   if (navigator.appName.indexOf("Microsoft Internet")!=-1) { return window.TransAdsMovie; }
   else { return window.document.TransAdsMovie; }     
}
// End of Banner Section

// Begin of Themes section

//Images
var imgSeeMoreItems = new Image();
imgSeeMoreItems.src = '/site_images/b_restantes.jpg';
var imgSeeLessItems = new Image();
imgSeeLessItems.src = '/site_images/b_restantes2.jpg';

//	Show/Hide related functions

var prefixHidden = 'div_';
var prefixButton = 'butt_';
var defaultShown = 3;
var currentItemType = '';
var currentTypeShown = 0;
var itemsCounter = 0;

function SetItemType(typeName, itemsToBeShown)
{
	if(itemsToBeShown == null) 	currentTypeShown = defaultShown;
	else currentTypeShown = itemsToBeShown;
	currentItemType = typeName;
	itemsCounter = 0;
}

function AddItem()
{
	var strItem = '';
	if(itemsCounter == currentTypeShown) {
		strItem += '<div id="' + prefixHidden + currentItemType + '" style="DISPLAY: none;">';
	}
	document.write(strItem);
	itemsCounter++;
}

function Finalize()
{
	if(itemsCounter > currentTypeShown)
	{
		if((itemsCounter - currentTypeShown) == 0)
		{
			document.write('</div><scr' + 'ipt>ShowHide(\'' + currentItemType + '\');</scr' + 'ipt>');
			document.write('<p></p>');
		}
		else
		{
			
			document.write('<div class="viewSome"><a href="javascript:ShowHide(\'' + currentItemType + '\', false);">Esconder</a></div>');
			document.write('<p></p>');
			document.write('</div>');
			document.write('<div class="viewAll" id="' + prefixButton + currentItemType + '"><a href="javascript:ShowHide(\'' + currentItemType + '\', true);" >Ver restante' + (((itemsCounter - currentTypeShown) == 1)?' ':'s ')  + (itemsCounter - currentTypeShown) + '</a></div>');
			document.write('<p></p>');
		}
	}
	else {
		document.write('<p></p>');
	}
}

function ShowHide(localItemType, forceVisible)
{
	var myObj = document.getElementById(prefixHidden + localItemType);
	var myButton = document.getElementById(prefixButton + localItemType);
	if(myObj == null) return;

	var display = new Boolean();
	if(forceVisible != null) display = forceVisible;	// if visibility/invisibility required by parameter
	else display = (myObj.style.display != '');			// if not required, behaviour is to toggle visibility

	if (display)
	{
		myObj.style.display = '';
		if(myButton != null) myButton.style.display = 'none';
	}else{
		myObj.style.display = 'none';
		if(myButton != null) myButton.style.display = '';
	}
}

//Begin of Dossier module functions

// Dossier specific functions used for roll-over fx on menu items
var highlightedTheme;
var highlightedThemeColor;
var themeMenuPrefix = 't_';
var highlightedMenuItem;
var highlightedDosMenuItem;
var menuItemPrefix = 'm_';
// onMouseOver
function DosMenuItemOn(obj) {
	obj.style.color = '#7AA736';
	obj.style.cursor='hand';
}
// onMouseOut
function DosMenuItemOff(obj) {
	if(highlightedDosMenuItem != obj) {	obj.style.backgroundPosition='left top'; }
}
function HighlightDosMenuItem(NodeId)
{
	var obj; 
	if(document.all) {obj = document.all(menuItemPrefix + NodeId);}
	if(document.getElementById)	{obj = document.getElementById(menuItemPrefix + NodeId);}
	if(obj != null)	{highlightedDosMenuItem = obj; DosMenuItemOn(obj);}
}
// this function returns the NodeId taken from the URL
function ReturnUrlNodeId()
{
	var urlNodeId = '';	var temp = document.URL;
	var p = temp.indexOf(".htm");
	if (p >= 0)	{temp = temp.substring(0, p);}
	p = temp.lastIndexOf("/");
	if (p >= 0)	{temp = temp.substr(p + 1);}
	urlNodeId = temp; return urlNodeId;
}
// End of dossier module functions

// Begin of zebra tables functions
function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   
function loopStripe(obj) {
	var tables = document.body.getElementsByTagName("TABLE");
	for (i=0; i < tables.length; i++) {
			var table = tables[i].id;
			if (table.indexOf("decozebra_") >= 0) {
				stripe(table, '#fff', '#f5f5f5');
			}			
	}
}
function stripe(id) {
    var even = false;
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
    var table = document.getElementById(id);
    if (! table) { return; }
    var tbodies = table.getElementsByTagName("tbody");
    for (var h = 0; h < tbodies.length; h++) {
      var trs = tbodies[h].getElementsByTagName("tr");
      for (var i = 0; i < trs.length; i++) {
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
          var tds = trs[i].getElementsByTagName("td");
          for (var j = 0; j < tds.length; j++) {
            var mytd = tds[j];
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            }
          }
        }
        even =  ! even;
      }
    }
}
// End of zebra tables functions

// features panel
function hideFriend(){
	document.getElementById("friendhide").style.display = "none";
	document.getElementById("friendshow").style.display = "block";
	document.getElementById("commenthide").style.display = "none";
	document.getElementById("commentshow").style.display = "block";
	document.getElementById("dAmigo").style.display = "none";
	document.getElementById("escreva").style.display = "none";
}
function showFriend(){
	document.getElementById("commenthide").style.display = "none";
	document.getElementById("commentshow").style.display = "block";
	document.getElementById("friendhide").style.display = "block";
	document.getElementById("friendshow").style.display = "none";
	document.getElementById("dAmigo").style.display = "block";
	document.getElementById("escreva").style.display = "none";
}
function hideWrite(){
	document.getElementById("commenthide").style.display = "none";
	document.getElementById("commentshow").style.display = "block";
	document.getElementById("dAmigo").style.display = "none";
	document.getElementById("escreva").style.display = "none";
}
function showWrite(){
	document.getElementById("friendhide").style.display = "none";
	document.getElementById("friendshow").style.display = "block";
	document.getElementById("commenthide").style.display = "block";
	document.getElementById("commentshow").style.display = "none";
	document.getElementById("dAmigo").style.display = "none";
	document.getElementById("escreva").style.display = "block";
}
// end features panel

//begin calculations functions
function CCA(CB,noHL){
if (!noHL)
{
if (CB.value != "")
hL(CB);
else
dL(CB);
}
}
function hL(E){
while (E.tagName!="TR")
{E=E.parentElement;}
E.className="calc_tr_hover";
}
function dL(E){
while (E.tagName!="TR")
{E=E.parentElement;}
E.className="";
}
//end calculations functions

//generic validation
function checkEmail(wbaddr) {
	var atpos = wbaddr.indexOf("@");
	var lastat = wbaddr.lastIndexOf("@");
	var lastdot = wbaddr.lastIndexOf(".");
	var length = wbaddr.length-1;
	var networkaddr = wbaddr.substring( (lastat+1) , wbaddr.length );
	networkaddr = networkaddr.toLowerCase();
	var notld = wbaddr.substring( (lastat+1) , lastdot );
	var domain = notld.substring( (notld.lastIndexOf(".")+1), notld.length);
	var legalchars = "abcdefghijklmnopqrstuvwxyz1234567890-.";
	var networkerror = 0;
	var dotpos = -1;
	if((domain.length < 2) || (domain.length > (26 - (length - lastdot)))) {return false;}
	for(var i=0 ; i < networkaddr.length ; i++) {
		if(legalchars.indexOf(networkaddr.charAt(i)) == -1) {return false;}
		if((networkaddr.charAt(i) == ".") && ((dotpos+1) == i)) {doterror = 1; dotpos = i;}
	}
	if (lastdot <= atpos) {return false;}
	if (((length - lastdot) > 3) || ((length - lastdot) < 2)) {return false};
	if ((atpos <= 0) || (lastat != atpos)) {return false;}
	return true;
}
function removeLeadingZeros(str) {
	if ((str.substring(0,1) == '0') && (str.length > 1)) {
		str = str.substring(1, str.length)
		str = removeLeadingZeros(str)
	}
	return str;
}
function IsCorrectMemberNr(frmval)
{
	var subscr_number = frmval;
	var subscr_number_length = subscr_number.length;
	var i = null;
	var counter = 0;
	var leftdigit = null;
	var rightdigit = null;
	var ind = 0;
	var oke = 1;
	for(i=0;i<subscr_number_length;i++) {
		var character = null;
		character = subscr_number.charAt(i);
		if(character == "-") {
			counter++;
			ind = parseInt(i);
		}
		else {
			if (character == " ") {oke = 0;}
		}
	}
	if ((counter == 1) && (oke == 1)) {
		leftdigit = subscr_number.substring(0,ind);
		rightdigit = subscr_number.substring((ind+1),subscr_number_length);
		leftdigit = removeLeadingZeros(leftdigit);
		rightdigit = removeLeadingZeros(rightdigit);
		if(parseInt(leftdigit)%97 == parseInt(rightdigit)%97) {return (true);}
		else {return (false);}
	}
	else {return (false);}
}
function isSpace(val) {
	if ((val == ' ') || (val == '\t') || (val == '\n') || (val == '\r')) {return true;}
	else {return false;}
}
function LTrim(val){
	var c, i, j = -1;
	for(i=0;i<val.length;++i) {
		c = val.charAt(i);
		if(!isSpace(c)) {j = i;break;}
	}
	if(j != -1) {return val.substring(j, val.length);}
	else {return '';}
}
function RTrim(val){
	var c, i, j = -1;
	for(i=val.length-1;i>=0;--i){
		c = val.charAt(i);
		if(!isSpace(c)){j = i; break;}
	}
	if(j != -1) {return val.substring(0, j + 1);}
	else {return '';}
}
function Trim(val){
	return LTrim(RTrim(val));
}
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<br>Restam <b><span id="'+theform.toString()+'">'+thelimit+'</span></b> caracteres para atingir o limite da sua mensagem.'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}
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



//-------------------------------------------------------------------------------------------//

var GetScroll = {
	x: function () {
		return getScrollXY("X");
	},
	y: function () {
		return getScrollXY("Y");
	}
}


var GetScreenSize = {
	width: function() {
			 return document.body.clientWidth;
	},

	height: function() {	
			return document.body.clientHeight;
	}
}
var GetElementSize = {
	width: function(objid) {
			return document.getElementById(objid).offsetWidth;
	},
	height: function(objid) {	
			return document.getElementById(objid).offsetHeight;
	}
}

var GetCenterCoords = {
	x: function(objid) {
		return Math.round((GetScreenSize.width()/2)-(GetElementSize.width(objid)/2));	
	},
	y: function(objid) {
		return Math.round((GetScreenSize.height()/2)-(GetElementSize.height(objid)/2))	
	} 	
}
function MoveElementToScreenCenter(objid) {
	var o = document.getElementById(objid).style;
	o.left = GetCenterCoords.x(objid);
	o.top = GetCenterCoords.y(objid);
}
function findPosition( oLink ) {
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oLink.x, oLink.y ];
  }
}
function getScrollXY(xy) {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	if (xy == "X") {
		return scrOfX;
	}
	else {
		return scrOfY;
	};
}
/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */

function highlightWord(node,word) {

	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function googleSearchHighlight() {

	return;

	// ..............
	
	if (!document.createElement) return;
	ref = document.referrer;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p') { 
					words = decodeURI(qsip[1]).split("+");		
	                for (w=0;w<words.length;w++) {
						highlightWord(document.getElementById("tdcenterpanel"),words[w]);
                	}
	        }
	}
}
function decoprotesteSearchHighlight() {

	return;

	// ...............

	if (!document.createElement) return;
	ref = document.URL;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'Searched') { 
			words = decodeURI(qsip[1]).split("+");			
	                for (w=0;w<words.length;w++) {
						if (words[w].length >= 3) {
							highlightWord(document.getElementById("tdcenterpanel"),words[w]);
						}
                	}
	        }
	}
}
function HighlightStart() {
	googleSearchHighlight();
	decoprotesteSearchHighlight();
}
// ie fix for "click to activate this content"
function ieupdate(){ var strBrowser = navigator.userAgent.toLowerCase(); if(strBrowser.indexOf("msie") > -1 && strBrowser.indexOf("mac") < 0){  var theObjects = document.getElementsByTagName('object');  var theObjectsLen = theObjects.length;  for (var i = 0; i < theObjectsLen; i++) {   if(theObjects[i].outerHTML){    if(theObjects[i].data){     theObjects[i].removeAttribute('data');    }    var theParams = theObjects[i].getElementsByTagName("param");    var theParamsLength = theParams.length;    for (var j = 0; j < theParamsLength; j++) {      if(theParams[j].name.toLowerCase() == 'flashvars'){        var theFlashVars = theParams[j].value;      }    }    var theOuterHTML = theObjects[i].outerHTML;    var re = /<param name="FlashVars" value="">/ig;    theOuterHTML = theOuterHTML.replace(re,"<param name='FlashVars' value='" + theFlashVars + "'>");    theObjects[i].outerHTML = theOuterHTML;   }  } }}window.onunload = function() { if (document.getElementsByTagName) {  var objs = document.getElementsByTagName("object");  for (i=0; i<objs.length; i++) {   objs[i].outerHTML = "";  } }}

//-----------------------
function decomakeprint()
{
	var s = document.getElementById("tdcenterpanel").innerHTML;
	document.decoprintform.printtext.value = s;
	document.decoprintform.submit();
}

//search engine related
function SubmitWhenSearchIsNotEmpty(form)
{
	if(form.first != null)
		form.first.value="0";
	
	if(form.search.value.length > 0)
	{
		Submit(form);
		return false;
	}
	else
	{
		form.search.focus();
		return true;
	}
}

function SubmitAdvancedSearchWhenSearchIsNotEmpty(form)
{
	if(form.first != null)
		form.first.value="0";
	
	if(form.search.value.length > 0)
	{
		SubmitAdvancedSearchForm(form);
	}
	else
	{
		form.search.focus();
	}
}

function Submit(frm)
{
	frm.submit();
}

function SubmitAdvancedSearchForm(frm)
{
    var categories
	categories = "";
	for (var i = 0; i < frm.elements.length; i++) 
	{
		var name = escape(frm.elements[i].name);
		var type = frm.elements[i].type;
		var alt = frm.elements[i].alt;
		if (name == "" && type == "checkbox" && alt == "category") 
		{
			//when a categorie is checked, 
			//it mean include in search
			if (frm.elements[i].checked == false)
				categories += "1";
			else
				categories += "0";
		}
		//when a checkbox is not checked on, it does not appear 
		//in the querystring.
		//if it doesn't appear, the default value is used.
		//so we will set it to off here
		else if (name == "" && type == "checkbox" && alt == "stem")
		{
			if (frm.elements[i].checked == true)
				frm.stem.value = "1";
			else
				frm.stem.value = "0";
		}
		else if (name == "" && type == "checkbox" && alt == "phonic")
		{
			if (frm.elements[i].checked == true)
				frm.phonic.value = "1";
			else
				frm.phonic.value = "0";
		}
		else if (name == "" && type == "checkbox" && alt == "fuzzy")
		{
			if (frm.elements[i].checked == true)
				frm.fuzzy.value = "1";
			else
				frm.fuzzy.value = "0";
		}		
	}
	frm.cat.value = categories;
	Submit(frm);
}

function AddHeadLine(name, teaser, thumbnail, url) {
	this.name = name;
	this.teaser = teaser;
	this.thumbnail = thumbnail;
	this.url = url;
}
function RenderHeadLine(array, div, arrayname, idx) {
	var o = '';
	o +=	'<ul class="leitura">';
	for (var i = idx; i < array.length; i++) {
			o += '<li class="leitura2">';
			o += '<a href="'+array[i].url+'" class="hpLink"';
			if (idx == 0) {
				o += 'onmouseover="ShowHeadLine(\''+div+'\','+i+',\''+arrayname+'\');"';
			}
			o += '>';
            o += '<span>' + array[i].name + '</span>';
            o += '</a></li>';
	}
	o += '</ul>';
	if (idx > 0) {
		for (var j = 0; j < idx; j++) {
			var s = div +j;
			ShowHeadLine(s,j,arrayname);
		}
	} else {
	ShowHeadLine(div,idx,arrayname);
	}
	document.write(o);
	
}

function ShowHeadLine(divprefix, i, arrayname) {
	try {
	var array = eval(arrayname);
	
	document.getElementById(divprefix+"name").innerHTML = array[i].name;
	document.getElementById(divprefix+"teaser").innerHTML = array[i].teaser;
	document.getElementById(divprefix+"thumbnail").src = '/images/'+array[i].thumbnail;
	document.getElementById(divprefix+"thumbnail").alt = array[i].name + " - " + array[i].teaser;
	document.getElementById(divprefix+"node").href = array[i].url;
	}
	catch (e) {
		alert(e.message);
	}
	
}



function RenderMagazines(array, idprefix, magrank) {
	var o = '';
	o +=	'<ul class="leitura">';
	for (var i = 0; i < array.length; i++) {
			if (array[i].MagRank == magrank) {
				o += '<li class="leitura2">';
				o += '<a href="/map/src/'+array[i].NodeID+'">';
				o += '<span>' + array[i].Name + '</span>';
				o += '</a></li>';
				document.getElementById(idprefix+"Illustration").src = '/images/' +array[i].Illustration;
			}
	}
	o += '</ul>';
	
	document.write(o);
}

function AddMagazineArticle(NodeID, SelectedMag, Name, Illustration, PNumber, PubMonth, PubYear, SName, MagName, MagRank) {
	this.NodeID = NodeID;
	this.SelectedMag = SelectedMag;
	this.Name = Name;
	this.Illustration = Illustration;
	this.PNumber = PNumber;
	this.PubMonth = PubMonth;
	this.PubYear = PubYear;
	this.SName = SName;
	this.MagName = MagName;
	this.MagRank = MagRank;	
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
	
	if(document.layers)	   //NN4+
    {
       document.layers[szDivID].style.display = iState ? "block" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.display = iState ? "block" : "none";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.display = iState ? "block" : "none";
    }
}

function writeLinkToArticle(path, text, type)
{
	//if(type == 'artigo')
	//{
			alert(path);
		document.write( '<a href="' + path + '" target="_self">' + text + '</a>' );
	
	//}
}