/*
	FUN??ES PARA SEREM CARREGADAS PELA INDEX
*/
var paramSession = "";

function setParamSession(id){
	paramSession = id;
}

function replaceAll(str, from, to) {
	from = from + "";
	str = str + "";
	var idx = str.indexOf(from);
	while(idx>-1) {
		str = str.replace(from, to);
		idx = str.indexOf(from);
	}
	return str;
}

function BrowserCheck() {
	//verifica qual browser est? sendo utilizado
	var b = navigator.appName;
	if (b == "Netscape") {
		window.browser = "NS";
	} else if ((b == "Microsoft Internet Explorer") && (navigator.userAgent.indexOf('Opera')>0)) {
		window.browser = "OP";
	} else if (b == "Microsoft Internet Explorer") {
		window.browser = "IE";
	} else {
		window.browser = b;
	}
	window.version = parseInt(navigator.appVersion);
	window.NS = (window.browser == "NS" && window.version>=4);
	window.IE = (window.browser == "IE" && window.version>=4);
	window.OP = (window.browser == "OP" && window.version>=4);
}
BrowserCheck();
function regulaAlturaIFrame(obj_IFrame){
	//atualiza dimens?es do iframe informado (para n?o exibir rolagem)
	//(obj_IFrame) == objeto iframe
	try {
		if(obj_IFrame != null) {
			var oBody = null;
			if (window.OP) {
				oBody = obj_IFrame.document.body;
			} else {
				oBody = obj_IFrame.contentWindow.document.body;
			}
			var oFrame = obj_IFrame;
			//regula largura do iframe conteudo
			if (obj_IFrame.id=="conteudo") {
				min_width = 580;
				if (obj_IFrame.offsetWidth<min_width) {
					width = min_width;
				} else {
					width = '100%';
				}
				oFrame.style.width = width;
			}

			//alert(obj_IFrame.document.body.scrollHeight + " - " + oBody.scrollHeight);

			//aplica dimens?es
			if(window.IE) { //Internet Explorer
				oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
			} else if(window.NS) { //Netscape e FireFox
				oFrame.style.height = oBody.offsetHeight;
			} else if(window.OP) { //Opera
				oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
			} else {
				oFrame.style.height = oBody.offsetHeight;
			}
		}
	}
	catch(e) {
		//window.status =	'Error: ' + e.number + '; ' + e.description;
	}
}
function start() {
	//configura dimens?es do IFrame com scroll
	//fun??o presente no onLoad e onResize da index
	mn_obj = document.getElementById("cabecalho");
	iframeCtt_obj = document.getElementById("area");
	iframeCtt_obj.height = "100%";
	if(mn_obj != null)
		iframeCtt_obj.height = iframeCtt_obj.offsetHeight - mn_obj.offsetHeight;
}
var popupUrl = "";
var popupType= "";
function popup_redraw() {
	//HACK para IE apenas - recarrega o objeto POPUP no evento scroll da "area"
	if (popupUrl!="")  {
		popup_open(popupUrl,popupType);
	}
}
function popup_open(url,type,idDiv,idIframe) {
	//exibe popup
	//(url)! == p?gina a ser carregada
	//(type)! == parametro para configura??o de dimens?es e posi??o dos layers
	//(idDiv)? == id do div que contem o iframe ->se n?o informado == 'popup'
	//(idIframe)? == id do iFrame que ser? alterado ->se n?o informado == 'winpopup'
	if (type!="produto_zoom") {
		popup_close();
	}
	popup_close_privacidade();
	popupUrl = url;
	popupType = type;

	popupIdDiv = (idDiv!=null)? idDiv : 'popup';
	popupIdIframe = (idIframe!=null)? idIframe : 'winpopup';
	//div com iFrames
	//iframe com bot?o fechar e documento
	if (popupType=="detalhe_reclamacoes" || popupType=="detalhe_troca" || popupType=="detalhe_privacidade") {
		objPopup = document.getElementById('popupPrivacidade');
		objWinPopup = document.getElementById('winpopupPrivacidade');
	} else if (popupType=="detalhe_popup_2") {
		objPopup = document.getElementById('popup_2');
		objWinPopup = document.getElementById('winpopup_2');
	} else {
		objPopup = document.getElementById(popupIdDiv);
		objWinPopup = document.getElementById(popupIdIframe);
	}
	if (window.IE) {
		objWinPopupDoc = objWinPopup.contentWindow.document.getElementById("winpopupdoc");
	} else if(window.NS) { //O Firefox entra aqui tamb?m
		objWinPopupDoc = objWinPopup.contentWindow.document.getElementById("winpopupdoc");
	} else if(window.OP) { //O Opera entra aqui tamb?m
		objWinPopupDoc = objWinPopup.document.getElementById("winpopupdoc");
	} else {
		objWinPopupDoc = objWinPopup.contentWindow.document.getElementById("winpopupdoc");
	}

	//config. posicionamento layer
	switch (type) {
		case 'detalhe_produto':
			var width = 530;
			var height = 525;
			var top = 44;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
		case 'detalhe_mapa':
			var width = 530;
			var height = 470;
			var top = 24;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
		case 'produto_zoom':
			var width = 530;
			var height = 525;
			var top = 44;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
		case 'detalhe_orcamento':
			//alerta que aparece quando:
			//ao clicar sobre um produto para visualizar detalhes/foto maior
			var width = 632;
			var height = 370;
			var top = 55;
			var left = 87;
			break;
		case 'esqueci_senha':
			var width = 500;
			var height = 400;
			var top = 44;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
			break;
		case 'responsavel_revenda':
			var width = 500;
			var height = 400;
			var top = 44;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
		case 'termo_uso_responsabilidade':
			var width = 600;
			var height = 500;
			var top = 44;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
		case 'condicoes_comerciais':
			var width = 600;
			var height = 500;
			var top = 44;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
		case 'aviso':
			var width = 600;
			var height = 500;
			var top = 44;
			var left = 50;
			// | > centraliza < |
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
		default:
			var width = 525;
			var height = 500;
			var top = 55;
			var left = 50;
			largura = document.body.clientWidth;
			altura = document.body.clientHeight;
			left = (largura - width) / 2;
			break;
	}
	//privacidade alta
	if(url.toUpperCase().indexOf("jsessionid") == - 1){
		if(url.toUpperCase().indexOf("?") >= 0){
			url = url.substring(0, url.toUpperCase().indexOf("?")) + paramSession + url.substring(url.toUpperCase().indexOf("?"));
		} else {
			url = url + paramSession;
		}
	}
	//privacidade alta

	//config dimens?es
	objWinPopup.width = width;
	objWinPopup.height = height;
	if(objWinPopupDoc != null){
		objWinPopupDoc.width = width-6;
		objWinPopupDoc.height = height-28;
		//load layer
		objWinPopupDoc.src = url;
	}else{
		objWinPopupDoc = parent.document.getElementById("winpopup");
		objWinPopupDoc.width = width-6;
		objWinPopupDoc.height = height-28;
		//load layer
		objWinPopupDoc.src = url;
	}
	//show layer
	objPopup.style.top = top;
	objPopup.style.left = left;
	objPopup.style.visibility = 'visible';

	document.body.scrollTop = 0;
}

function popup_close(idToHide) {
	//hide layer
	if (idToHide!=null && idToHide!="") {
		objPopup = document.getElementById(idToHide);
		if (objPopup!= null) {
			objPopup.style.visibility = 'hidden';
		}
	} else {
		popupUrl = "";
		objPopup = document.getElementById('popup');
		if (objPopup!= null) {
			objPopup.style.visibility = 'hidden';
		}
		objPopup = document.getElementById('popupZoom');
		if (objPopup!= null) {
			objPopup.style.visibility = 'hidden';
		}
	}
}

function setWindowTitle(txt) {
	// altera o t?tulo da janela pai (file:popup.jsp)
	objDiv = parent.document.getElementById('windowTitle');
	if(objDiv != null){
		objDiv.innerHTML = txt;
	}
}

function popup_2_close() {
	//hide layer
	popupUrl = "";
	objPopup = document.getElementById('popup_2');
	if (objPopup!= null) {
		objPopup.style.visibility = 'hidden';
	}
}

function popup_close_privacidade() {
	//hide layer
	popupUrl = "";
	objPopup = document.getElementById('popupPrivacidade');
	if (objPopup!= null) {
		objPopup.style.visibility = 'hidden';
	}
}

function PopupCentralizado(pagina,nome,width,height,parametros) {
	largura = screen.width;
	altura = screen.height;
	posX = (largura - width) / 2;
	posY = (altura - height) / 2;
	var janela = null;

	//privacidade alta
	if(pagina.toUpperCase().indexOf("jsessionid") == - 1){
		if(pagina.toUpperCase().indexOf("?") >= 0){
			pagina = pagina.substring(0, pagina.toUpperCase().indexOf("?")) + paramSession + pagina.substring(pagina.toUpperCase().indexOf("?"));
		} else {
			pagina = pagina + paramSession;
		}
	}
	//privacidade alta


	if (parametros=='') {
		janela = window.open(pagina, nome,'left='+posX+',top='+posY+',height='+height+',width='+width);
	} else {
		janela = window.open(pagina, nome,parametros+',left='+posX+',top='+posY+',height='+height+',width='+width);
	}
	janela.focus();
	return false;
}

function Tecla(e){
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}
	if(key > 47 && key < 58) // numeros de 0 a 9
		return true;
	else {
		if (key == 8 || key == 58) // backspace
			return true;
		else
			return false;
	}
}

function TeclaCNPJ(e){
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}
	//alert(key);
	if((key > 47 && key < 58) || (key == 8) || (key == 45) || (key == 46) || (key == 47)){ // numeros de 0 a 9 OU BACKSPACE OU PONTO OU TRA?O OU BARRA
		return true;
	}else {
		return false;
	}
}

function TeclaInteiro(e){
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}
	if((key > 47 && key < 58) || (key == 8)) // numeros de 0 a 9 OU BACKSPACE
		return true;
	else {
		return false;
	}
}

function TeclaInscEst(e){
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}
	if((key > 47 && key < 58) || (key == 8) || (key > 96 && key < 123) || (key > 64 && key < 90)) // numeros de 0 a 9 OU BACKSPACE
		return true;
	else {
		return false;
	}
}

function TeclaDecimal(e){
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}
	if(key > 47 && key < 58) // numeros de 0 a 9
		return true;
	else {
		if (key == 8 || key == 44) // backspace
			return true;
		else
			return false;
	}
}

function TeclaDecimalComPonto(e){
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}
	if(key > 47 && key < 58) // numeros de 0 a 9
		return true;
	else {
		if (key == 8 || key == 46) // backspace
			return true;
		else
			return false;
	}
}

function countChars(num_chars, obj_mostrador, obj_texto, msg) {
	campo=obj_texto.value;
	obj_mostrador.value=campo.length;
	if (campo.length>parseInt(num_chars)) {
		alert(msg+" "+num_chars);
		obj_texto.value=campo.substring(0,parseInt(num_chars));
		obj_mostrador.value=num_chars;
		return false;
	}
	return true;
}

//in?cio das fun??es de valida??o de HORAS
function verificahora(hora) {
  if ((aux = isTime(hora.value)) != false) {
		if (aux == "vazio")
			return;
		hora.value = aux;
	} else {
		alert("Digite uma hora correta.");
		hora.focus();
	}
}

function isTime(hora) {
  if (hora == "")
    return "vazio"
  var horac, e, d;
  horac = "";
  ido = hora.indexOf(":");
  tam = hora.length;
  if (ido >= 0) {
	e = hora.substr(0, ido);
	d = hora.substr(ido+1);
	if (isNaN(e) && e | isNaN(d) && d | ido == 0 | ido >= 3 | d.length >= 3)
	  return false;
    if (ido == 1)
	   horac = "0"+ e +":";
	else horac = e +":";
    horac += d;
  } else {
	if (isNaN(hora) | tam == 0 | tam >= 5)
	  return false;
	if (tam == 1)
	  horac = "0"+ hora +":";
	else if (tam == 2)
      horac = hora +":";
	else if (tam == 3)
	  horac = "0"+ hora.substr(0, 1) +":"+ hora.substr(1);
	else
	  horac = hora.substr(0, 2) +":"+ hora.substr(2);
  }
  ido = horac.indexOf(":");
  d = horac.substr(ido + 1);
  while (d.length <= 1) {
	horac += "0";
    d = horac.substr(ido + 1);
  }
  if (horac.substr(0, 2) == 24)
    horac = "00:"+ horac.substr(3);
  if (horac.substr(0, 2) >= 25 | horac.substr(3) >= 60)
       return false;
  else return horac;
}
//fim Horas

function linkBanner(codigo){
	var objIframe = parent.parent.document.getElementById("salvarInformacoes");
	if(objIframe != null){
		objIframe.src = "lib/link_banner.jsp?cod="+codigo;
	}
}

function verificaCPF(numcpf) {
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;

	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}

	// % retorna o resto da divis?o por 11
	dig1 = 11 - (soma % 11);

	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;

	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;

	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);

	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;

	if(numcpf == "00000000000" || numcpf == "11111111111" || numcpf == "22222222222") {
		alert("ERRO. CPF inv?lido. Digite Novamente.");
		return true;
	}else if(numcpf == "33333333333" || numcpf == "44444444444" || numcpf == "55555555555") {
		alert("ERRO. CPF inv?lido. Digite Novamente.");
		return true;
	}else if(numcpf == "66666666666" || numcpf == "77777777777" || numcpf == "88888888888" || numcpf == "99999999999"){
		alert("ERRO. CPF inv?lido. Digite Novamente.");
		return false;
	}else if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}else if(numcpf == ""){
		return true;
	}else{
		alert("ERRO. CPF inv?lido. Digite Novamente.");
		return false;
	}
}

function getValorAtributo(obj, nome_atributo){
	var valor = "";
	if(obj != null && obj.attributes != null && obj.attributes.length > 0){
		var objAtr = obj.attributes[nome_atributo];
		if(objAtr != null){
				valor = objAtr.value;
		}
	}
	return valor;
}

function setValorAtributo(obj, nome_atributo, valor){
	if(obj != null && obj.attributes != null && obj.attributes.length > 0){
		var objAtr = obj.attributes[nome_atributo];
		if(objAtr != null){
				objAtr.value = valor;
		}
	}
}

function LimpaCampoInteiro(campo){
	var i;
	var strCampo = "";
	var CHAR;
	var str = campo.value;
	for (i=0; i < str.length; i++){
		CHAR = str.substring(i, i+1).charCodeAt();
		if(CHAR > 47 && CHAR < 58){
			strCampo += str.substring(i, i+1);
		}
	}
	campo.value = strCampo;
}

function LimpaCampoRma(campo){
	var i;
	var strCampo = "";
	var CHAR;
	var str = campo.value;
	for (i=0; i < str.length; i++){
		CHAR = str.substring(i, i+1).charCodeAt();
		if((CHAR > 47 && CHAR < 58) || (CHAR > 96 && CHAR < 123) || (CHAR > 64 && CHAR < 90)){
			strCampo += str.substring(i, i+1);
		}
	}
	campo.value = strCampo;
}

function LimpaCampoDecimal(campo){
	var i;
	var strCampo = "";
	var CHAR;
	var str = campo.value;
	for (i=0; i < str.length; i++){
		CHAR = str.substring(i, i+1).charCodeAt();
		if((CHAR > 47 && CHAR < 58) || (CHAR == 44)){
			strCampo += str.substring(i, i+1);
		}
	}
	campo.value = strCampo;
}

function FmascTempoReal(ConteudoCampo){
	if (((event.keyCode) > 47) && ((event.keyCode) < 58)){
		NumDig = ConteudoCampo.value;
		TamDig = NumDig.length;
		Contador = 0;
		if (TamDig > 1)	{
			numer = "";
			for (i = TamDig; (i >= 0); i--){
				if ((parseInt(NumDig.substr(i,1))>=0) &&(parseInt(NumDig.substr(i, 1))<=9))	{
					Contador++;
					if ((Contador == 2) && ((TamDig -i) < 4)){
						numer = ","+numer;

						Contador = 0;
					}
					else if (Contador == 3){
						numer = "."+numer;
						Contador = 0;
					}
					numer = NumDig.substr(i, 1)+numer;
				}
			}
			ConteudoCampo.value = numer;
		};
		return(true)
	}
	else return(false)
}

function FmascTR(ConteudoCampo, _evt){
	var flag = false;

	if(window.event){
		if (((_evt.keyCode) > 47 && (_evt.keyCode) < 58)){
			flag = true;
		}
	}else{
		if((_evt.which) > 47 && (_evt.which) < 58){
			flag = true;
		}
	}

	if(flag){
		NumDig = ConteudoCampo.value;
		TamDig = NumDig.length;
		Contador = 0;
		if (TamDig > 1)	{
			numer = "";
			for (i = TamDig; (i >= 0); i--){
				if ((parseInt(NumDig.substr(i,1))>=0) &&(parseInt(NumDig.substr(i, 1))<=9))	{
					Contador++;
					if ((Contador == 2) && ((TamDig -i) < 4)){
						numer = ","+numer;

						Contador = 0;
					}
					else if (Contador == 3){
						numer = "."+numer;
						Contador = 0;
					}
					numer = NumDig.substr(i, 1)+numer;
				}
			}
			ConteudoCampo.value = numer;
		}
		return true;
	}
	return false;
}
/***
* Descri??o.: formata um campo do formul?rio de
* acordo com a m?scara informada...
* Par?metros: - objForm (o Objeto Form)
* - strField (string contendo o nome
* do textbox)
* - sMask (mascara que define o
* formato que o dado ser? apresentado,
* usando o algarismo "9" para
* definir n?meros e o s?mbolo "!" para
* qualquer caracter...
* - evtKeyPress (evento)
*
* Uso.......: <input type="textbox"
* name="xxx".....
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
* Observa??o: As m?scaras podem ser representadas
* como os exemplos abaixo:
* CEP -> 99999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* C/C -> 999999-!
* Tel -> (99) 9999-9999
***/
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
  var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

  if(window.event) {
	// for IE, e.keyCode or window.event.keyCode can be used
	nTecla = evtKeyPress.keyCode;
  }
  else if(evtKeyPress.which) {
	// netscape or firefox
	nTecla = evtKeyPress.which;
  }
  else {
	// no event, so pass through
	return true;
  }

  /*if(document.all) { // Internet Explorer
	nTecla = evtKeyPress.keyCode;
	 }
  else if(document.layers) { // Nestcape
	nTecla = evtKeyPress.which;
  }*/

  sValue = objForm[strField].value;

  if (sMask == '(99) 999-9999') {
	 if (sValue.length > 12) {
		sMask = '(99) 9999-9999';
	 }
  }

  // Limpa todos os caracteres de formata??o que
  // j? estiverem no campo.
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( " ", "" );
  sValue = sValue.toString().replace( " ", "" );
  fldLen = sValue.length;
  mskLen = sMask.length;

  i = 0;
  nCount = 0;
  sCod = "";
  mskLen = fldLen;

  while (i <= mskLen) {
	bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
	bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

	if (bolMask) {
	  sCod += sMask.charAt(i);
	  mskLen++; }
	else {
	  sCod += sValue.charAt(nCount);
	  nCount++;
	}

	i++;
  }

  objForm[strField].value = sCod;

  if (nTecla != 8) { // backspace
	if (sMask.charAt(i-1) == "9") { // apenas n?meros...
	  return ((nTecla > 47) && (nTecla < 58)); } // n?meros de 0 a 9
	else { // qualquer caracter...
	  return true;
	} }
  else {
	return true;
  }
}

function verificaData(objeto) {

	var data = objeto.value;
	var dia = data.substring(0, 2);
	var mes = data.substring(3, 5);
	var ano = objeto.value.substring(6,10);

	if (data == "") return;
	if (data.length > 6 && data.length <= 10) {
		if(ano.length != 4){
			alert("Digite o ano com 4 d?gitos!");
			objeto.focus();
			return false;
		}
	}else{
		alert("Digite uma data correta!");
		objeto.focus();
		return false;
	}

	objeto.value = dia + "/" + mes + "/" + ano;

	if ((retorno = isDate(objeto)) != false) {

		} else {
			alert("Digite uma data correta!");
			objeto.focus();
			return false;
	}
}

function isDate(objeto) {

//	var ano = "<%'= year(date) %>";
//	var hoje = "<%= year(date) & right("0"& month(date), 2) & right("0"& day(date), 2) %>";

	data = objeto.value;
	itens = data.split("/");
	if (itens[0] == "" || itens[1] == "" || itens[2] == "")
		return false;

	if (isNaN(itens[0]) || isNaN(itens[1]) || isNaN(itens[2]))
		return false;

	//alert(itens[0]+itens[1]+itens[2]);
		/*var temp = itens[0]
		itens[0] = itens[1]
		itens[1] = temp
*/
	/*if ((itens[2] + itens[1] + itens[0]) < strHoje)
		return "MENOR";//*/

	t0 = itens[0].length;	t1 = itens[1].length;	t2 = itens[2].length;
	if (t0 >= 3 || t1 >= 3 || t2 >= 5)
		return false;

	// valida se nunhum valor ? menor que 0
	if (itens[0] <= 00 || itens[1] <= 00 || itens[2] <= 0000)
		return false;

	// valida o ano
	if (t2 <= 3) {
		if (itens[2] > 22)
			ano = "1900";
		else ano = "2000";
		aux = "";
		for (w = 0; w < 4 - t2; w++)
			aux += ano.charAt(w);
		y = 0;
		for (; w < 4; w++)
			aux += itens[2].charAt(y++);
		itens[2] = aux;
	}

	// valida o mes
	if (itens[1] >= 13)
		return false;

	// captura o dia maximo para o mes digitado
	itens[1] = itens[1] * 1;
	if (itens[1] == 2) {
		if (itens[2]%400 == 0 || itens[2]%4 == 0 && itens[2]%100 != 0)
			vMax = 29;
		else
			vMax = 28;
	} else
	if (itens[1] == 1 || itens[1] == 3 || itens[1] == 5 || itens[1] == 7 || itens[1] == 8 || itens[1] == 10 || itens[1] == 12)
		vMax = 31;
	else vMax = 30;
	itens[1] = "0"+ itens[1]; itens[1] = itens[1].charAt(itens[1].length - 2) + itens[1].charAt(itens[1].length - 1);

	// valida o dia do mes
	if (itens[0] > vMax)
		return false;
	itens[0] = "0"+ itens[0]; itens[0] = itens[0].charAt(itens[0].length - 2) + itens[0].charAt(itens[0].length - 1);

	objeto.value = itens[0] +"/"+ itens[1] +"/"+ itens[2];
	return true;
}

//------------------------------------------------------------------------------------------------------------------------
function tira_barra(obj) {
	data = obj.value;
	dia = data.substr(0, 2);
	mes = data.substr(3, 2);
	if (data.length == 10)
		ano = data.substr(6, 4);
	else
		ano = data.substr(6, 2);
	data = dia + mes + ano;
	obj.value=data;
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}