var BROWSER_VERSION = 0;
var BROWSER_NAME = "";
var nBody, nWindow;
var tmScrollSplash = null;

nWindow = window;

nBody = nWindow.document.getElementsByTagName('body')[0];

if (navigator.userAgent.indexOf("Firefox") != -1){
	var versionindex=navigator.userAgent.indexOf("Firefox") + 8;
	BROWSER_VERSION = parseInt(navigator.userAgent.charAt(versionindex));
	BROWSER_NAME = "Firefox";
//}else if (navigator.appVersion.indexOf("MSIE")!=-1){
}else{
	temp = navigator.appVersion.split("MSIE")
	BROWSER_VERSION = parseFloat(temp[1]);
	BROWSER_NAME = "IE";
}

function AJAX(){}

AJAX.prototype.OnData				= null;
AJAX.prototype.Response				= '';
AJAX.prototype.URL					= '';
AJAX.prototype.StatusCod			= '';
AJAX.prototype.StatusText			= '';
AJAX.prototype.XMLHttp				= '';
AJAX.prototype.Ocupado				= false;
AJAX.prototype.OnError = function(){
	with (this){
		alert("Erro! \nC&oacute;digo: " + StatusCod + "\nDescri&ccedil;&atilde;o: '" + StatusText + "'\nP&aacute;gina: '" + URL + "'");
	}
};

AJAX.prototype.Load = function(strPagina){
	with (this){
		URL = strPagina;
		XMLHttp = novo_xmlhttp();
		XMLHttp.open("get", URL, true);
		Ocupado = true;

		XMLHttp.onreadystatechange = function(){
			with (this){
				if (XMLHttp.readyState != 4)
					return;

				StatusCod = XMLHttp.status;
				StatusText = XMLHttp.statusText;
				Response = XMLHttp.responseText;

				if (StatusCod != 200){
					OnError();
					return;
				}
				
				if (OnData)
					OnData();

				Ocupado = false;
			}
		};

		XMLHttp.send(null);
	}
}

function Cidade(cod, nome){
	this.CidCod = cod;
	this.CidNome = nome;
}

function PopularCidades(txt, sel, estado, QntCabecalho){
	var aj = new AJAX();

	if (!QntCabecalho)
		QntCabecalho = 0;

	aj.QntCabecalho = QntCabecalho;
	aj.SelectElement = sel;
	aj.EstCod = estado * 1;
	aj.TextElement = txt;
	if (!window.Estados)
		window.Estados = Array();
	else if (window.Estados[aj.EstCod]){
		aj.TextElement.Estado = window.Estados[aj.EstCod];
		return;
	}

	aj.OnData = function(){
		var arrCidades, cid, len, x, sel, est, txt;

		sel = this.SelectElement;
		sel.disabled = false;

		if (!this.Response)
			return;

		arrCidades = this.Response.split("\n");
			
			for( l=0;l<sel.length;l++){
				sel.options[l] = null;
			}

			for( c=0;c<arrCidades.length;c++){
				sp = arrCidades[c].split("|");
					 var y=document.createElement('option'); //cria um novo elemento option
       				 y.text  =unescape(sp[1]); //seta o texto do elemento option
        			 y.value =sp[0]; //seta o valor do elemento option
        			 try
        			 {
            		 sel.add(y,null); // adiciona um novo option no fim da lista para navegadores complacentes
        			 }
            		 catch(ex)
        			 {
            		 sel.add(y); // adiciona um novo option no fim da lista para o IE
       				 }
			}
	};

	sel.disabled = true;
	aj.Load('../src/pegarcidades.asp?c='+estado);
}

function replaceChar(str,oldChar, newChar) {
    arrStr = str.split(oldChar);
    alert(arrStr.length)
    strNew = "";
    if (arrStr.length > 0 ) {
        strNew = arrStr[0];
        for(i=0;i<arrStr.length;i++) {
            strNew += newChar + arrStr[i];
        }
    }
    else {
        strNew = str;
    }
    return strNew;
}

function setaValorCombo(objCombo, valorNovo) {
	qtdOpcoes = objCombo.options.length;
	if (qtdOpcoes > 0) {
		for (i=0;i<qtdOpcoes ; i++)
		{
			if (objCombo.options[i].value == valorNovo)
			{
				objCombo.selectedIndex = i;
				return true;
			}
		}
	}
	return false;
}
function replaceChar(strSrc,charAntigo,charNovo)  {
	retorno = "";

	if (strSrc.indexOf(charAntigo) != -1)
	{
		arrDados = strSrc.split(charAntigo)
		for (i=0;i<arrDados.length -1 ;i++ )
		{
			retorno += arrDados[i] + charNovo;
		}
		retorno += arrDados[arrDados.length -1 ]
	}
	else {
		retorno = strSrc;
	}
	return retorno 
}

/*
	Edit by Joe - 12/01/2008 11:32:
	Existem RGs com n&uacute;mero e letra, n&atilde;o podemos validar no momento...

function validaRgIe(strRg, blnPessoaFisica) {
	//Verifica se o RG ou IE &eacute; num&eacute;rico
	alert(strRg + " " + isNaN(strRg) + " " + strRg.length )
	if (isNaN(strRg) || strRg == 0 || strRg.length == 0)
	{
		blnSucesso = true;
		//Separa o n&uacute;mero do digito 
		arrStrRg = strRg.split('-');
		//Se o usu&aacute;rio n&atilde;o digitou d&iacute;gito remove os pontos e seta o digito como zero pois existem RGs sem d&iacute;gito
		if (arrStrRg.length == 1)
		{
			strInicio = replaceChar(arrStrRg[0],'.','');
			if (strInicio.substring(strInicio.length -1).toLowerCase() == 'x')
			{
				strInicio = strInicio.substring(0,strInicio.length -1)
			}
			strDigito = "0";
		}
		//Se o usu&aacute;rio digitou digito remove os pontos e seta o digito 
		else if (arrStrRg.length == 2)
		{
			strInicio = replaceChar(arrStrRg[0],'.','');
			strDigito = arrStrRg[1];
		}
		//Se existe mais de um tra&ccedil;o informa rg/ie inv&aacute;lido
		else {
			blnSucesso = false;
		}
		//Se For PF valida o n&uacute;mero como numerico e o digito num&eacute;rico ou X
		if (blnSucesso)
		{
			blnSucesso = !( isNaN(strInicio) || strInicio <= 0 || strInicio.length == 0 );
		}
		if (blnPessoaFisica)
		{	
			if (blnSucesso)
			{
					 blnSucesso = (! isNaN(strDigito) || strDigito.toLowerCase() == "x")
			}

		}
		else if(strRg.toLowerCase() == "isento") {
			blnSucesso = true;
		}
		alert(blnSucesso)
		return blnSucesso;

	}
	else {


		return true;
	}
}*/

function validaBranco(strValor) {
	return ! (replaceChar(strValor,' ','') == "");
}
function validaNumeroPositivo(strNumero) {
	return  ! (isNaN(strNumero) || strNumero <= 0 || strNumero.length == 0) 
}
function validaRgIe(strRg, blnPessoaFisica) {
	//Verifica se o RG ou IE &eacute; num&eacute;rico
	if (isNaN(strRg) || strRg == 0 || strRg.length == 0)
	{
		blnSucesso = true;
		//Separa o n&uacute;mero do digito 
		arrStrRg = strRg.split('-');
		//Se o usu&aacute;rio n&atilde;o digitou d&iacute;gito remove os pontos e seta o digito como zero pois existem RGs sem d&iacute;gito
		if (arrStrRg.length == 1)
		{
			strInicio = replaceChar(arrStrRg[0],'.','');
			if (strInicio.substring(strInicio.length -1).toLowerCase() == 'x' && blnPessoaFisica)
			{
				strInicio = strInicio.substring(0,strInicio.length -1)
			}
			strDigito = "0";
		}
		//Se o usu&aacute;rio digitou digito remove os pontos e seta o digito 
		else if (arrStrRg.length == 2)
		{
			strInicio = replaceChar(arrStrRg[0],'.','');
			strDigito = arrStrRg[1];
		}
		//Se existe mais de um tra&ccedil;o informa rg/ie inv&aacute;lido
		else {
			blnSucesso = false;
		}
		//Se For PF valida o n&uacute;mero como numerico e o digito num&eacute;rico ou X
		if (blnPessoaFisica)
		{	
			if (blnSucesso)
			{
					 blnSucesso = !( isNaN(strInicio) || strInicio <= 0 || strInicio.length == 0 ) && (! isNaN(strDigito) || (strDigito.toLowerCase() == "x"));
			}

		}
		else if(strRg.toLowerCase() != "isento") {
			blnSucesso = !( isNaN(strInicio) || strInicio <= 0 || strInicio.length == 0 ) && (! isNaN(strDigito));
		}
		return blnSucesso;

	}
	else {


		return true;
	}
}

function LIMP2(c)
{
if (c == "")
{
	return ("");
}
while((cx=c.indexOf("-"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("/"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(","))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("."))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("("))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(")"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(" "))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
return(c);
}

function validaData(strDt,blnMaiorQueHj) {
	strDt = LIMP2(strDt);
	var dd = strDt.substr(0,2);
	var mm = strDt.substr(2,2);
	var aaaa = strDt.substr(4);
	var valor = new Date(aaaa, mm, dd);
	if (isNaN(valor)) 
	{
			return false;
	}	
	else if (blnMaiorQueHj) {

		dtHj = new Date().getTime();
		if (dtHj < valor)
		{
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}

}


function initBlackOption(divMainName){
	var ifr = c('div');
	var win;

	if (!nBody)
	{
		nBody = document.body;
	}

	// a transparência do quadro preto
	var opa = 6;

	with (ifr.style){
		backgroundColor		= '#000000';
		filter				= 'alpha(opacity='+(opa*10)+')';
		opacity				= (opa/10)+'';
		zIndex				= '990';
		width				= '100%';
		height				= getPageSizeWithScroll()[1];
		position			= 'absolute';
		top					= '0';
		left				= '0';
	}

	//Trecho que esconde os Selects por causa de um problema com o IE6
	var combos = document.getElementsByTagName('SELECT');
	for (i = 0; i < combos.length; i++ )
	{
		combos[i].style.display = 'none';
	}

	nBody.appendChild(ifr);
	nWindow.blackScriptDiv = ifr;
	//alert(nWindow.document.getElementById(divMainName));
	nWindow.blackScripterMainDiv = nWindow.document.getElementById(divMainName);

	nWindow.onscroll = function (){ 
				if (!tmScrollSplash) 
					verifScripterPos();
	};
	nWindow.onscroll();
	return ifr;
}

function FecharBlackScripter(blnApenasFechar){
	var campo = nWindow.blackScripterMainDiv;

	//Trecho que esconde os Selects por causa de um problema com o IE6
	var combos = document.getElementsByTagName('SELECT');
	for (i = 0; i < combos.length; i++ )
	{
		combos[i].style.display = '';
	}

	if (!blnApenasFechar)
		campo.parentNode.removeChild(campo);
	else
		campo.style.display = 'none';

	nWindow.blackScriptDiv.parentNode.removeChild(nWindow.blackScriptDiv);
	nWindow.blackScriptDiv = null;
	nWindow.onscroll = function () { };
	nWindow.blackScripterMainDiv = null;
}

function verifScripterPos(){
	var divMain = nWindow.blackScripterMainDiv;

	if (!divMain)	{
		alert("N&atilde;o foi poss&iacute;vel pegar o div principal! ");
		return;
	}

	tmScrollSplash = null;
	if (divMain){
		var blackDiff = 0;
		var blackTop = divMain.style.top;
		var blackNumTop = DBInteger(blackTop);
		var cliHeight = nBody.clientHeight;
		var mousePos = (nWindow.pageYOffset || nBody.scrollTop);
		var newBlackTop = Math.round((cliHeight - divMain.offsetHeight)/2) + mousePos;

		//alert(newBlackTop+'->'+blackNumTop);
		if ((blackDiff = newBlackTop - blackNumTop) == 0)
			return;

		if (Positivo(blackDiff) > cliHeight){
			if (blackDiff > 0)
				divMain.style.top = mousePos - DBInteger(divMain.style.height);
			else
				divMain.style.top = mousePos + cliHeight;
			verifScripterPos();
			return;
		}

		var blackMove = 10;
		var blackMerge = (blackNumTop*1)  + (1*(blackDiff > 0 ? blackMove : (blackMove * -1)));

		if ((blackDiff < blackMove && blackDiff > (blackMove*-1)) || (blackTop == null || blackTop == '')){
			divMain.style.top = newBlackTop;
			return;
		}else
			divMain.style.top = blackMerge;

		tmScrollSplash = setTimeout("verifScripterPos();", 30);
	}
}

function Positivo(num){
	if (num >= 0)
		return num;
	else
		return num*-1;
}

function getPageSizeWithScroll(){
	if (!nBody)
	{
		nBody = document.body;
	}

	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (nBody.scrollHeight > nBody.offsetHeight){ // all but Explorer Mac
		yWithScroll = nBody.scrollHeight;
		xWithScroll = nBody.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = nBody.offsetHeight;
		xWithScroll = nBody.offsetWidth;
  	}

	arrayPageSizeWithScroll = new Array(xWithScroll, yWithScroll);

	return arrayPageSizeWithScroll;
}

function numfloat(number){
	var num = number + '';
	var virg = num.lastIndexOf(',');
	var pont = num.lastIndexOf('.');

	var lt = -1;

	if (virg > pont)
		lt = virg;
	else
		lt = pont;

	if (lt < 0)
		return 0;

	var txt = '';
	for (x = 0; x < (num+'').length; x++){
		if (!masc_isnumber(num.charAt(x)) && x != lt)
			continue;
		else if (x == lt)
			txt += '.';
		else
			txt += num.charAt(x);
	}

	return txt * 1;
}

function numround(num, fix){
	if (!num)
		return 0;

	num = (num+'').replace(',', '.');
	num *= 1;

	if (!fix)
		fix = 2;

	return (num.toFixed(fix)+'').replace('.', ',');
}

function onff(campo, type){
	var td = 0;
	if (!(td = campo.parentNode.previousSibling))
		return;

	if (type)
		td.className = 'tdFormPromptHover';
	else
		td.className = 'tdFormPrompt';
}

function IS_SET(flag, bit){
	if (!flag)
		return 0;

	return (flag & bit);
}

/******** Sistema de m&aacute;scara para inputs de Joe \o/ *********/

function masc_isletter(letra){
	var tot_letras = "ABCDEFGHIJKLMNOPQRSTUVXWYZ_";

	if (tot_letras.indexOf(letra.toUpperCase()) >= 0)
		return 1;
	else
		return 0;
}

function masc_isnumber(letra){
	var tot_nums = "1234567890";

	if (tot_nums.indexOf(letra) >= 0)
		return 1;
	else
		return 0;
}

function masc_veriLetra(formato, r, y, x, opcoes){
	var ret = '';

	if ((x < 0 || y < 0) && !IS_SET(opcoes, MASC_NAOCONTRARIO))
		return '';
	else if ((x >= r.length || y >= formato.length) && IS_SET(opcoes, MASC_NAOCONTRARIO))
		return '';

	var l = r.charAt(x);
	var lfor = formato.charAt(y);

	switch (lfor){
	case '*':
		if (l == ',' || masc_isletter(l) || masc_isnumber(l))
			return l;
		break;
	case '%':
		if (l == ',' || masc_isnumber(l))
			return l;
		break;
	case '#':
		if (masc_isnumber(l))
			return l;
		break;
	case '&':
		if (masc_isnumber(l))
			return l;
		break;
	default:
		if (IS_SET(opcoes, MASC_NAOCONTRARIO)){
			y++;
			return lfor + masc_veriLetra(formato, r, y, x, opcoes);
		}else{
			y--;
			return masc_veriLetra(formato, r, y, x, opcoes) + lfor;
		}
	}

	return ret;
}
// Formato = #0A$, ex: '(##) ####-####' ou 'R$ #.###.###,##'
// * = QUALQUER LETRA E NUMERO E VIRGULA
// % = SOMENTE NUMEROS E PONTOS
// # = SOMENTE NUMEROS
// & = SOMENTE LETRAS E NUMEROS, SEM VIRGULA
var MASC_NAOCONTRARIO			= (1 << 1);
var MASC_VERIFICARZERO			= (1 << 2);

function Mascara(e, campo, formato, opcoes){
	var x, txt = '', r = '', y = 0, ponto = 0, pontoform = '';
	var forlen = formato.length, l = '', sum = 0;

	if (!campo || !campo.value)
		return '';

	if (!e)
		e = window.event;

	r = campo.value;
	rlen = r.length;
	if (IS_SET(opcoes, MASC_VERIFICARZERO)){
		for (x = 0; x < rlen; x++){
			l = r.charAt(x);
			if (l != '0' && l != '.' && l != ',')
				break;
		}
		if (x > 0)
			r = campo.value.substr(x-(e && e.keyCode == 48 ? 1 : 0));
	}

	rlen = r.length;
	if (IS_SET(opcoes, MASC_NAOCONTRARIO)){
		for (x = 0; x < forlen && x < rlen; x++){
			l = masc_veriLetra(formato, r, y, x, opcoes);
			if (l != ''){
				txt += l;
				y += l.length;
			}
		}
	}else{
		x = (rlen > forlen ? forlen : rlen) - 1;
		y = forlen - 1; txt = '';
		for (; x >= 0 && y >= 0; x--){
			l = masc_veriLetra(formato, r, y, x, opcoes);
			if (l != ''){
				txt = l + txt;
				y -= l.length;
			}
		}
		if (IS_SET(opcoes, MASC_VERIFICARZERO)){
			ponto			= txt.indexOf(',') == -1 ? txt.indexOf('.') : 1;
			pontoform		= formato.indexOf(',') > formato.indexOf('.') ? formato.indexOf(',') : formato.indexOf('.');
			if (ponto < 0 && pontoform > -1){
				sum = forlen - pontoform - rlen - 1;
				for (x = 0; x < sum; x++)
					txt = '0' + txt;
				txt = '0' + formato.charAt(pontoform) + txt;
			}
		}
	}
	campo.value = txt;
}

function getVnum(id, kind){
	if (!id)
		return;

	window.open('getvnum.php?kind='+kind+'&id='+id, null, 
		'top=40,left=40,height=300,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
}

function DBInteger(texto, ret){
	var x;
	var nums = "1234567890", buf = "", charac;

	if (!ret)
		ret = 0;

	if (!texto)
		return ret;

	for (x = 0; x < texto.length; x++)	{
		charac = texto.charAt(x);
		if (nums.indexOf(charac) >= 0)
			buf = buf + charac;
	}

	if (!buf)
		return ret;

	return buf;
}

function onlyNums(campo){
	var x;
	var nums = "1234567890", buf = "", charac;
	var texto;

	if (!campo || !campo.tagName)
		campo = this;

	if (!campo || !campo.value)
		return;
	
	texto = campo.value

	for (x = 0; x < texto.length; x++)	{
		charac = texto.charAt(x);
		if (nums.indexOf(charac) >= 0)
			buf = buf + charac;
	}
	
	campo.value = buf;
}
function c(tag){
	return document.createElement(tag);
}
function t(text){
	return document.createTextNode(text);
}
function g(nome){
	return document.getElementById(nome);
}
function mudarTDs(nome, tr){
	var x;

	for (x = 0; x < tr.childNodes.length; x++)
		tr.childNodes[x].className = nome;
}
function Colorir(txt){
	var x, buf = '';
	for ( x = 0; x < txt.length; x++)	{
		if (txt.charAt(x) == '&' && x+1 < txt.length &&
			txt.charAt(x+1) != '&'){
			x++;
			if (txt.charAt(x) == 'r')
				buf = buf + "</font><font style='color: #D70000'>";
			else if (txt.charAt(x) == 'R')
				buf = buf + "</font><font style='color: #FF4242'>";
			else if (txt.charAt(x) == 'y')
				buf = buf + "</font><font style='color: #BDB91A'>";
			else if (txt.charAt(x) == 'Y')
				buf = buf + "</font><font style='color: #F2EC6A'>";
			else if (txt.charAt(x) == 'c')
				buf = buf + "</font><font style='color: #24A8A5'>";
			else if (txt.charAt(x) == 'C')
				buf = buf + "</font><font style='color: #3AE7E2'>";
			else if (txt.charAt(x) == 'k')
				buf = buf + "</font><font style='color: #373737'>";
			else if (txt.charAt(x) == 'K')
				buf = buf + "</font><font style='color: #5F5F5F'>";
			else if (txt.charAt(x) == 'w')
				buf = buf + "</font><font style='color: #D7D7D7'>";
			else if (txt.charAt(x) == 'W')
				buf = buf + "</font><font style='color: #FFFFFF'>";
			else if (txt.charAt(x) == 'b')
				buf = buf + "</font><font style='color: #203AA6'>";
			else if (txt.charAt(x) == 'B')
				buf = buf + "</font><font style='color: #506BDC'>";
			else if (txt.charAt(x) == 'm')
				buf = buf + "</font><font style='color: #9720A4'>";
			else if (txt.charAt(x) == 'M')
				buf = buf + "</font><font style='color: #CA71CC'>";
			else if (txt.charAt(x) == 'n')
				buf = buf + "</font>";
			else if (txt.charAt(x) == 'G')
				buf = buf + "</font><font style='color: #54E257'>";
			else if (txt.charAt(x) == 'g')
				buf = buf + "</font><font style='color: #37A417'>";
			else{
				x--;
				buf = buf + txt.charAt(x);
			}
		}else if (txt.charCodeAt(x) == 10){
			buf = buf + "<br>";
		}else
			buf = buf + txt.charAt(x);
	}
	return buf;
}

// Fun&ccedil;&otilde;es de array de flags do MUD
var arrNums = new Array();
function crList(cod, txt, arr){
	var nd = document.createElement('option');
	nd.value = cod;
	nd.appendChild(document.createTextNode(txt));
	nd.choosen = false;
	
	arr[arr.length] = nd;
}

function cacList(arr, strsel){
	var x, sel = document.getElementById(strsel);
	var nd;
	
	for (x = 0; x < arr.length; x++){
		nd = arr[x].cloneNode(true);
		sel.appendChild(nd);
	}
}

function carregarListas(){
	var x;
	
	for (x = 0; x < arrNums.length; x++){
		if (!arrNums[x] || !arrNums[x].arr || !arrNums[x].strSel)
			continue;
		
		cacList(arrNums[x].arr, arrNums[x].strSel);
	}
}

function addToList(num, opt, txt){
	var arr = arrNums[num].arr;
	var sel = document.getElementById(arrNums[num].strSel);

	var elopt = 0;

	var td = document.getElementById(arrNums[num].strTd);
	var a = document.createElement('a');
	var li = document.createElement('li');

	if (!opt){
		if (sel.options[sel.selectedIndex].value < 0)
			return;

		opt = sel.options[sel.selectedIndex].value;
		txt = sel.options[sel.selectedIndex].text;
		elopt = sel.options[sel.selectedIndex];
	}else if (sel){
		for (x = 0; x < sel.options.length; x++){
			if (opt == sel.options[x].value)
				elopt = sel.options[x];
		}
	}

	for (y = 0; y < arr.length; y++){
		if (arr[y].value == opt)
			break;
	}
	if (y < arr.length)
		arr[y].choosen = true;

	a.id = opt; a.sel = sel;
	a.arr = arr;
	a.href = 'Javascript: void(0);';
	a.onclick = function (){
		var x, y, sel = this.sel, nd;

		for (y = 0; y < this.arr.length; y++){
			if (this.arr[y].value == this.id)
				break;
		}
		if (y == this.arr.length)
			return;
	
		this.arr[y].choosen = false;
		for (x = 0; x < sel.options.length; x++){
			if (sel.options[x].value >= this.id){
				sel.insertBefore(this.arr[y], sel.options[x]);
				break;
			}
		}

		if (x == sel.options.length)
			sel.appendChild(this.arr[y]);

		this.parentNode.parentNode.removeChild(this.parentNode);
	}
	a.appendChild(document.createTextNode(txt));
	li.style.marginLeft = '4';
	li.appendChild(a);
	td.appendChild(li);
	
	if (elopt && elopt.nextSibling)
		elopt.nextSibling.selected = true;
	else if (elopt && elopt.previousSibling)
		elopt.previousSibling.selected = true;

	if 	(elopt)
		sel.removeChild(elopt);
}
function arrAdd(sel, td, arr){
	this.strSel = sel;
	this.strTd = td;
	this.arr = arr;
}

function cHiddenFlagValues(nome, arr){
	var inp, x, fl;

	inp = document.createElement('input');inp.type = 'hidden';
	inp.name = nome; inp.value = ''; fl = 0;
	for (x = 0; x < arr.length; x++)
		if (arr[x].choosen)
			fl |= (1 << (arr[x].value*1));
	inp.value = fl;

	return inp;
}

function novo_xmlhttp()
{
	var xml = null;

	if (window.XMLHttpRequest) 
	{	// Mozilla
		xml=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		// IE
		xml = new ActiveXObject("Microsoft.XMLHTTP");
	}

	return xml;
}

function checarCombosData(strIdDia, strIdMes, strIdAno){
	var auxDia, auxMes, auxAno, auxData;
	if (strIdDia == "" || strIdMes == "" || strIdAno == "" ){
		return false;
	}

	var auxDia = document.getElementById(strIdDia);
	var auxMes = document.getElementById(strIdMes);
	var auxAno = document.getElementById(strIdAno);
//	alert(auxDia + ' ' + auxMes + ' ' + auxAno)
	if (!auxDia || !auxMes || !auxAno){
		return false;
	}else{
		var auxDiaVal = auxDia.options[auxDia.selectedIndex].value;
		var auxMesVal = auxMes.options[auxMes.selectedIndex].value;
		var auxAnoVal = auxAno.options[auxAno.selectedIndex].value;
//		alert(auxDiaVal + ' ' + auxMesVal + ' ' + auxAnoVal)
		var auxData = new Date(auxAnoVal, auxMesVal -1 , auxDiaVal);
//		alert(auxData)
//		alert(auxData.getDate() + ' ' + (auxData.getMonth()+1) + ' ' + auxData.getFullYear())
//				alert((auxDiaVal == auxData.getDate())+ ' ' + (auxMesVal == (auxData.getMonth()+1) )+ ' ' + (auxAnoVal == auxData.getFullYear()))
		
		if (auxDiaVal == auxData.getDate() && auxMesVal == (auxData.getMonth()+1) && auxAnoVal == auxData.getFullYear()){
			return true;
//			alert(1)
		}else{
//			alert(2)
			return false;
		}
	}
}

function formataData(strData){
	var auxArr, auxRetorno
	
	auxRetorno = ""

	if (strData == ""){
		return false
	}else{
		auxArr = strData.split("/")
		if (parseInt(auxArr[0]) < 10){
			auxRetorno = auxRetorno + "0"; 
		}

		auxRetorno = auxRetorno + auxArr[0] + "/";

		if (parseInt(auxArr[1]) < 10){
			auxRetorno = auxRetorno + "0"; 
		}

		auxRetorno = auxRetorno + auxArr[1] + "/" + auxArr[2];
		return auxRetorno;
	}
}

function extraiData(selDia, selMes, selAno){
	var intDia, intMes, intAno, strData;

	intDia = selDia.options[selDia.selectedIndex].value;
	intMes = selMes.options[selMes.selectedIndex].value;
	intAno = parseInt(selAno.options[selAno.selectedIndex].value);

	return formataData(intDia + "/" + intMes + "/" + intAno);
}