//////////////////////////////////////////////////////////////////////
// Direitos Autorais sobre: startup01.js
//
// Este banco de funções é protegido pela lei de direitos autorais
// e marcas internacionais. A reprodução ou distribuição não autorizada,
// ou qualquer parte dele, resultará na imposição de rigorosas penas
// civis e criminais e os infratores serão objeto de ação judicial
// promovida na máxima extensão possível nos termos da lei.
//
// © Copyright 2002-2003, StartUp Informática Ltda.
// Todos os direitos reservados. (All rights reserved.)
//////////////////////////////////////////////////////////////////////
//
// AVISO
//
// Este arquivo é monitorado.
// Qualquer tentativa de cópia ou acesso externo será rastreada.
// O infrator será objeto de ação judicial com base na lei de direitos
// autorais.
//
//////////////////////////////////////////////////////////////////////

var ns6=document.getElementById&&!document.all
var ie=document.all

if(!Array.indexOf)
{
	Array.prototype.indexOf=function(obj)
	{
		for(var i=0; i < this.length; i++)
			if(this[i]==obj)
				return i;
		return -1;
	}
}

function getobjecthandle(whichid)
{
	var obj;
	for(var x=0; x < document.all.length; x++)
	{
		if(document.all[x].id==whichid)
		{
			obj=document.all[x];
			break;
		}
	}
	return obj;
}

function getframehandle(whichid)
{
	var frm;

	if(ie)
	{
		for(var x=0; x < window.parent.frames.length; x++) 
		{
			if(window.parent.frames(x).name==whichid)
			{
				frm=window.parent.frames(x);
				break;
			}
		}
	}
	else if(ns6)
		frm=window.parent.frames[whichid];

	return frm;
}

//////////////////////////////////////////////////////////////////////
// Height & Width Functions

var pageheight=screen.height;

function setpageheight(height)
{
	pageheight=height;
}

function getpageheight()
{
	return pageheight;
}

function getscreenwidth()
{
	if(screen.width < 800)
		return 780;
	return (screen.width-20);
}

function getscreenheight()
{
	if(document.body.clientHeight < pageheight)
		return pageheight;
	return document.body.clientHeight;
}

function getbodywidth()
{
	if(getbodyclientWidth() < 780)
		return 780;
	return getbodyclientWidth();
}

function getbodyheight()
{
	if(document.body.clientHeight < pageheight)
		return pageheight;
	return document.body.clientHeight;
}

function getbodyclientWidth()
{
	if(ie)
		return document.body.clientWidth;
	else if(ns6)
		return (document.body.clientWidth - 2);
}


//////////////////////////////////////////////////////////////////////
// Write Lines Functions

function writeverticalline(top, left, height, color)
{
	document.writeln("<div style=\"position: absolute; top: "+top+"; left: "+left+"; width: 1; height: "+height+"; z-index: 1\">");
	document.writeln("	<table cellpadding=\"0\" cellspacing=\"0\" width=\"1\" height=\""+height+"\" bgcolor=\""+color+"\"><tr><td></td></tr></table>");
	document.writeln("</div>");
}

function writehorizontalline(top, left, width, color)
{
	document.writeln("<div style=\"position: absolute; top: "+top+"; left: "+left+"; width: "+width+"; height: 1; z-index: 1\">");
	document.writeln("	<table cellpadding=\"0\" cellspacing=\"0\" width=\""+width+"\" height=\"1\" bgcolor=\""+color+"\"><tr><td></td></tr></table>");
	document.writeln("</div>");
}

//////////////////////////////////////////////////////////////////////
// Div Functions

function writediv(id, top, left, width, height, plus)
{
	document.writeln("<div "+((id != "") ? "id=\""+id+"\"" : "")+" style=\"position: absolute; top: "+top+"; left: "+left+"; width: "+width+"; height: "+height+((plus!="") ? "; "+plus : "")+"\">");
}

function writedivend()
{
	document.writeln("</div>");
}

function showtext(thetext, whichdiv)
{
	if(ie)
		eval("document.all."+whichdiv).innerHTML=thetext;
	else if(ns6)
		document.getElementById(whichdiv).innerHTML=thetext;
}

function reset(whichdiv)
{
	if(ie)
		eval("document.all."+whichdiv).innerHTML=" ";
	else if(ns6)
		document.getElementById(whichdiv).innerHTML=" ";
}

function getdivheight(whichdiv)
{
	return document.getElementById(whichdiv).scrollHeight;
}

function setdivheight(whichdiv, newheight)
{
	document.getElementById(whichdiv).style.height=newheight;
}

function setdivvisible(whichdiv, visible)
{
	document.getElementById(whichdiv).style.visibility=(visible ? "visible" : "hidden");
}


//////////////////////////////////////////////////////////////////////
// Flash Movie Functions

function flashRewind(nameID)
{
	if(ie)
		document.getElementById(nameID).Rewind();
}

function flashPlay(nameID)
{
	if(ie)
		document.getElementById(nameID).Play();
}

function flashStopPlay(nameID)
{
	if(ie)
		document.getElementById(nameID).StopPlay();
}

function flashIsPlaying(nameID)
{
	if(ie)
		return document.getElementById(nameID).IsPlaying();
}

function flashGetPercentLoaded(nameID)
{
	if(ie)
		return document.getElementById(nameID).PercentLoaded();
}


//////////////////////////////////////////////////////////////////////
// Scroll Bar Functions

function scrollBar(line, face)
{
	with(document.body.style)
	{
		scrollbarDarkShadowColor=line;
		scrollbar3dLightColor=line;
		scrollbarArrowColor=line;
		scrollbarBaseColor=face;
		scrollbarFaceColor=face;
		scrollbarHighlightColor=face;
		scrollbarShadowColor=face;
		scrollbarTrackColor=face;
	}
}

function colorBar(vlineon, vfaceon, vlineoff, vfaceoff)
{
	var w=document.body.clientWidth;
	var h=document.body.clientHeight;
	var x=event.clientX;
	var y=event.clientY;
	if(x > w || y-3 > h)
		scrollBar(vlineon,vfaceon);
	else
		scrollBar(vlineoff,vfaceoff);
}


//////////////////////////////////////////////////////////////////////
// Status Bar Functions

function setstatus(text)
{
	window.status=text;
	return true;
}

function clearstatus()
{
	return setstatus("");
}

//////////////////////////////////////////////////////////////////////
// Link Functions

function showlink(idLink, colorLink, underlineLink)
{
	var thisLink;
	if(ie)
		thisLink=eval("document.all."+idLink);
	else if(ns6)
		thisLink=document.getElementById(idLink);

	thisLink=thisLink.style;
	thisLink.color=colorLink;
	if(underlineLink)
		thisLink.textDecoration="underline";
	else
		thisLink.textDecoration="none";
}

function showglowlink(idLink, colorLink, glowLink, colorglowLink)
{
	var thisLink;
	if(ie)
		thisLink=eval("document.all."+idLink);
	else if(ns6)
		thisLink=document.getElementById(idLink);

	thisLink=thisLink.style;
	thisLink.color=colorLink;
	if(glowLink)
	{
		thisLink.width="100%";
		thisLink.filter="Glow(Color="+colorglowLink+", Strength=1)";
	}
	else
		thisLink.filter="none";
}

var idblinklink=new Array(100);
function showblinklink(idLink, colorLink, blinkLink)
{
	var thisLink;
	if(ie)
		thisLink=eval("document.all."+idLink);
	else if(ns6)
		thisLink=document.getElementById(idLink);

	thisLink=thisLink.style;
	thisLink.color=colorLink;
	if(blinkLink)
	{
		if(idblinklink.indexOf(idLink)==-1)
		{
			var id=window.setInterval("controlblinklink('"+idLink+"');", 1000);
			for(var pos=0; pos < idblinklink.length; pos++)
				if(idblinklink[pos]==undefined)
					break;
			idblinklink[pos]=new Array(2);
			idblinklink[pos][0]=idLink;
			idblinklink[pos][1]=id;
		}
	}
	else
	{
		for(var pos=0; pos < 100; pos++)
		{
			if(idblinklink[pos][0]==idLink)
			{
				window.clearInterval(idblinklink[pos][1]);
				thisLink.visibility="visible";
				idblinklink.splice(pos,1);
				break;
			}
		}
	}
}

function controlblinklink(idLink)
{
	var thisLink;
	if(ie)
		thisLink=eval("document.all."+idLink);
	else if(ns6)
		thisLink=document.getElementById(idLink);

	thisLink.style.visibility=(thisLink.style.visibility=="hidden" ? "visible" : "hidden");
}

var idblinkcolorlink=new Array(100);
function showblinkcolorlink(idLink, colorLink, blinkcolorlink, colorblinkLink)
{
	var thisLink;
	if(ie)
		thisLink=eval("document.all."+idLink);
	else if(ns6)
		thisLink=document.getElementById(idLink);

	thisLink=thisLink.style;
	thisLink.color=colorLink;
	if(blinkcolorlink)
	{
		if(idblinkcolorlink.indexOf(idLink)==-1)
		{
			var id=window.setInterval("controlblinkcolorlink('"+idLink+"','"+colorLink+"','"+colorblinkLink+"');", 1000);
			for(var pos=0; pos < idblinkcolorlink.length; pos++)
				if(idblinkcolorlink[pos]==undefined)
					break;
			idblinkcolorlink[pos]=new Array(2);
			idblinkcolorlink[pos][0]=idLink;
			idblinkcolorlink[pos][1]=id;
		}
	}
	else
	{
		for(var pos=0; pos < 100; pos++)
		{
			if(idblinkcolorlink[pos][0]==idLink)
			{
				window.clearInterval(idblinkcolorlink[pos][1]);
				thisLink.color=colorLink;
				idblinkcolorlink.splice(pos,1);
				break;
			}
		}
	}
}

function controlblinkcolorlink(idLink, colorLink, colorblinkLink)
{
	var thisLink;
	if(ie)
		thisLink=eval("document.all."+idLink);
	else if(ns6)
		thisLink=document.getElementById(idLink);

	thisLink.style.color=(thisLink.style.color==colorLink ? colorblinkLink : colorLink);
}

//////////////////////////////////////////////////////////////////////
// Print Functions

function doprint()
{
	if(!window.print)
	{
		alert("Use o Netscape ou Internet Explorer\n nas versões 4.0 ou superior.");
		return;
	}
	window.print()
}

//////////////////////////////////////////////////////////////////////
// Array Functions

function StringArray(n)
{
	return Array(n);
}

//////////////////////////////////////////////////////////////////////
// Date/Time Functions

function Date_Get_Day()
{
	var hoje=new Date();
	return hoje.getDate();
}

function Date_Get_Day_2()
{
	var hoje=new Date();
	return pad(hoje.getDate(), 2);
}

function Date_Get_DayOfWeek()
{
	var hoje=new Date();
	var sem=new Array("Domingo", "Segunda-feira", "Ter&ccedil;a-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "S&aacute;bado");
	return sem[hoje.getDay()];
}

function Date_Get_DayOfWeek_3()
{
	var hoje=new Date();
	var sem=new Array("Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "S&aacute;b");
	return sem[hoje.getDay()];
}

function Date_Get_Month()
{
	var hoje=new Date();
	var mes=new Array("janeiro", "fevereiro", "mar&ccedil;o", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro");
	return mes[hoje.getMonth()];
}

function Date_Get_Month_Number()
{
	var hoje=new Date();
	return (hoje.getMonth()+1);
}

function Date_Get_Month_Number_2()
{
	var hoje=new Date();
	return pad((hoje.getMonth()+1), 2);
}

function Date_Get_Year()
{
	var hoje=new Date();
	return hoje.getFullYear();
}

function Date_Get_DayFull()
{
	return Date_Get_Day_2()+"/"+Date_Get_Month_Number_2()+"/"+Date_Get_Year();
}

function Time_Get()
{
	var hoje=new Date();
	return hoje.getHours()+":"+pad(hoje.getMinutes(), 2);
}

function Time_Get_2()
{
	var hoje=new Date();
	return pad(hoje.getHours(), 2)+":"+pad(hoje.getMinutes(), 2);
}

function Time_Get_Greeting()
{
	var hoje=new Date();
	if(hoje.getHours() >= 0 && hoje.getHours() < 12)
		return "Bom dia";
	else if(hoje.getHours() >= 12 && hoje.getHours() < 18)
		return "Boa tarde";
	else if(hoje.getHours() >= 18)
		return "Boa noite";
}

function DateSubtraction(date1, date2)
{
	var vdate1=new Date(Number(date1.substr(6,4)), Number(date1.substr(3,2)), Number(date1.substr(0,2)));
	var vdate2=new Date(Number(date2.substr(6,4)), Number(date2.substr(3,2)), Number(date2.substr(0,2)));
	return String(Math.round((vdate1.getTime() - vdate2.getTime()) / (1000*60*60*24)));
}

function Date_Coutdown_Description(daystotal)
{
	var years=truncate(daystotal / 365, 0);
	var months=0;
	var days=0;
	var text="";

	if(daystotal - (years * 365) > 30)
	{
		months=truncate((daystotal - (years * 365)) / 30, 0);
		days=truncate(daystotal - ((years * 365) + (months * 30)), 0);

		var vdate;
		for(var x=Date_Get_Month_Number(); x > (Date_Get_Month_Number() - months); x--)
		{
			vdate=new Date((x > 0 ? Date_Get_Year() : Date_Get_Year() - 1), (x > 0 ? x : 12 + x) - 1, 1);
			vdate.setTime(vdate.getTime() - (1000*60*60*24));

			if(vdate.getDate()==31)
				days=days - 1;
			else if(vdate.getDate() < 30)
				days=days + (30 - vdate.getDate());
		}
	}
	else
	{
		days=truncate(daystotal - (years * 365), 0);

		var vdate=new Date(Date_Get_Year(), Date_Get_Month_Number(), 1);
		vdate.setTime(vdate.getTime() - (1000*60*60*24));

		if(vdate.getDate()==31)
			days=days - 1;
		else if(vdate.getDate() < 30)
			days=days + (30 - vdate.getDate());
	}

	if(years > 0)
	{
		if(years > 1)
			text=String(years) + " anos";
		else
			text="1 ano";

		if(months > 0 && days > 0)
			text=text + ", ";
		else if(months > 0 || days > 0)
			text=text + " e ";
	}

	if(months > 0)
	{
		if(months > 1)
			text=text + String(months) + " meses";
		else
			text=text + "1 m&ecirc;s";

		if(days > 0)
			text=text + " e ";
	}

	if(days > 0)
	{
		if(days > 1)
			text=text + String(days) + " dias";
		else
			text=text + "1 dia";
	}

	return text;
}


//////////////////////////////////////////////////////////////////////
// String Functions

function Left(string, ilength)
{
	return string.substring(0, ilength);
}

function Right(string, ilength)
{
	return string.substring(string.length - ilength, string.length);
}

function Store(sString, sChar, iLength, bRight, bForceLength)
{
	sString=((bForceLength) ? Left(sString, iLength) : sString);

	var s="";
	for(var i=0; i < (iLength - sString.length); i++)
		s+=sChar;

	sString=((bRight) ? sString+s : s+sString);

	return sString;
}

function replaceAll(str, from, to)
{
	var idx=str.indexOf(from);

	while(idx > -1)
	{
		str=str.replace(from,to);
		idx=str.indexOf(from);
    }

    return str;
}

function ReplaceChar(string, oldchar, newchar)
{
	for(var m=0; m < string.length; m++)
	{
		if(string.charAt(m)==oldchar)
			string=string.substring(0,m)+newchar+string.substring(m+1,string.length);
	}
	return string;
}

function ReplaceString(string, oldstring, newstring)
{
	b=string.indexOf(oldstring,-1);
	while(b > -1)
	{
		string=string.substring(0,b)+newstring+string.substring(b+oldstring.length,string.length);
		b=string.indexOf(oldstring,-1);
	}
	return string;
}

//////////////////////////////////////////////////////////////////////
// Mathematics Functions

function impar(valor)
{
	var result=""+(valor / 2)+"";
	if(result.indexOf(".") != -1)
		return true;
	return false;
}

var rand=1;
function random(total)
{
	var currentdate=0;
	var core=0;
	var ran=60/total;

	currentdate=new Date();
	core=currentdate.getSeconds();
	core=Math.floor(core/ran);

	if(rand==(core+1))
		core++;

	rand=core+1;

	return core;
}

function pad(string, string_size)
{
	string="00000000"+string;
	return(string.substring(string.length - string_size, string.length));
}

function round(original)
{
	return Math.round(original);
}

function truncate(value, decimals)
{
	var valor=String(value);
	var decimais="";

	if(String(value).indexOf(".") > -1)
	{
		valor=String(value).substring(0, String(value).indexOf("."));
		decimais=String(value).substring(String(value).indexOf(".") + 1, String(value).length);
		decimais=decimais.substr(0, decimals);
	}

	return parseFloat(valor + (decimais!="" ? "." + decimais : ""));
}

//////////////////////////////////////////////////////////////////////
// Window Functions

function openpopup(url, width, height, scrollbars, child)
{
	var xMax, yMax, xOffset, yOffset, newwin;
	if(document.all)
	{
		xMax=screen.width;
		yMax=screen.height;
	}
	else
	{
		if(document.layers)
		{
			xMax=window.outerWidth;
			yMax=window.outerHeight;
		}
		else
		{
			xMax=640;
			yMax=480;
		}
	}
	xOffset=(xMax - width)/2
	yOffset=(yMax - height)/2

	newwin=window.open(url,"","width="+width+",height="+height+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+(scrollbars ? "yes" : "no")+",resizable="+(scrollbars ? "yes" : "no"));

	if(child)
		newwin.creator=self;
}

//////////////////////////////////////////////////////////////////////
// Protection Functions

var protectMsg="O conteúdo deste site está protegido pela\rLei de Direitos Autorais e Marcas Internacionais.";
function protect(copyrights)
{
	if(copyrights != "" && copyrights != null)
		protectMsg+="\r\r" + copyrights;

	if(document.layers)
	{
		document.captureEvents(event.mousedown);
		document.onmousedown=protectclickNS4;
	}
	else if(document.all&&!document.getElementById)
		document.onmousedown=protectclickIE4;

	document.oncontextmenu=new Function("alert(protectMsg);return false")
}

function protectclickIE4()
{
	if(event.button==2)
	{
		alert(protectMsg);
		return false;
	}
}

function protectclickNS4(e)
{
	if(document.layers || document.getElementById && !document.all)
	{
		if(e.which==2 || e.which==3)
		{
			alert(protectMsg);
			return false;
		}
	}
}

//////////////////////////////////////////////////////////////////////
// Cookies Functions

function Cookie(document, name, hours, path, domain, secure)
{
	this.$document=document;
	this.$name=name;

	if(hours)
		this.$expiration=new Date((new Date()).getTime() + hours * 3600000);
	else
		this.$expiration=null;

	if(path)
		this.$path=path;
	else
		this.$path=null;

	if(domain)
		this.$domain=domain;
	else
		this.$domain=null;

	if(secure)
		this.$secure=true;
	else
		this.$secure=false;
}

function _Cookie_store()
{
	var cookieval="";

	for(var prop in this)
	{
		// ignore properties with names that begin with '$' and also methods
        if((prop.charAt(0)=="$") || ((typeof this[prop])=="function"))
			continue;

		if(cookieval != "")
			cookieval+="&";

		cookieval+=prop + ":" + escape(this[prop]);
	}

	var cookie=this.$name + "=" + cookieval;

	if(this.$expiration)
		cookie+="; expires=" + this.$expiration.toGMTString();

	if(this.$path)
		cookie+="; path=" + this.$path;

	if(this.$domain)
		cookie+="; domain=" + this.$domain;

	if(this.$secure)
		cookie+="; secure";

	this.$document.cookie=cookie;
}

function _Cookie_load()
{
	var allcookies=this.$document.cookie;

	if(allcookies=="")
		return false;

	var start=allcookies.indexOf(this.$name + "=");
	if(start==-1)
		return false; // cookie not defined for this page.

	start+=this.$name.length + 1;

	var end=allcookies.indexOf(";", start);
	if(end==-1)
		end=allcookies.length;

	var cookieval=allcookies.substring(start, end);

	var a=cookieval.split("&");
	for(var i=0; i < a.length; i++)
		a[i]=a[i].split(":");

	for(var i=0; i < a.length; i++)
		this[a[i][0]]=unescape(a[i][1]);

	return true;
}

function _Cookie_remove()
{
	var cookie=this.$name + "=";

	if(this.$path)
		cookie+="; path=" + this.$path;

	if(this.$domain)
		cookie+="; domain=" + this.$domain;

	cookie+="; expires=Fri, 02-Jan-1970 00:00:00 GMT";

	this.$document.cookie=cookie;
}
