<!-- 
//--------------------------------------------------------------------------------------
function iif(psdStr, trueStr, falseStr){
  if (psdStr){
    return trueStr
  }
  else {
    return falseStr
  }
}
//--------------------------------------------------------------------------------------
function Menu(blnAcao)
{
	if (typeof(MenuPrincipal) == 'object')
	{
		if(blnAcao == true)
		{
			MenuPrincipal.style.visibility = '';
			MenuPrincipal.style.position = '';
		}
		else
		{
			MenuPrincipal.style.visibility = 'hidden';
			MenuPrincipal.style.position = 'absolute';			
		}
	}		
}
//--------------------------------------------------------------------------------------
function checkCtrl() 
{
  var ch = String.fromCharCode(event.keyCode)
  if ((event.ctrlLeft || event.CtrlRight) && (ch == "n" || ch == "N"))
    return false;
}
//--------------------------------------------------------------------------------------
function Excluir(blnAcao)
{
	if (typeof(colExcluir) == 'object')
	{
		if(blnAcao == true)
		{
			for (i=0;i<colExcluir.length;i++)
			{
		
				colExcluir[i].style.visibility = '';
				colExcluir[i].style.position = '';		
			}
		}
		else
		{
			for (i=0;i<colExcluir.length;i++)
			{
		
				colExcluir[i].style.visibility = 'hidden';
				colExcluir[i].style.position = 'absolute';		
			}	
		}
	}	
}
//--------------------------------------------------------------------------------------
function Editar(blnAcao)
{
	if (typeof(colEditar) == 'object')
	{
		if(blnAcao == true)
		{
			for (i=0;i<colEditar.length;i++)
			{
		
				colEditar[i].style.visibility = '';
				colEditar[i].style.position = '';		
			}
		}
		else
		{
			for (i=0;i<colEditar.length;i++)
			{
		
				colEditar[i].style.visibility = 'hidden';
				colEditar[i].style.position = 'absolute';		
			}	
		}
	}	
}
//--------------------------------------------------------------------------------------
function Titulo(strTitulo)
{
	MenuInfo(true, strTitulo)
}
//--------------------------------------------------------------------------------------
function Titulo2(strTitulo)
{
	InfoTop2.innerHTML = '<font size="2" face="Arial, Verdana" color="#000000"><b>' + strTitulo + '</b></font>';
}
//--------------------------------------------------------------------------------------
function Titulo3(strTitulo)
{
	TituloUsuario.innerHTML = '<font size="1" face="Arial, Verdana" color="#FFFFFF"><b>' + strTitulo + '</b> &nbsp;</font>';
}
//--------------------------------------------------------------------------------------
function MenuAcoes(blnAcao)
{
	if (blnAcao == true)
	{
//		AcoesTop.style.position = '';		
//		AcoesTop.style.visibility = '';	
		AcoesBottom.style.position = '';		
		AcoesBottom.style.visibility = '';	
	}
	else
	{
//		AcoesTop.style.position = 'absolute';		
//		AcoesTop.style.visibility = 'hidden';	
		AcoesBottom.style.position = 'absolute';		
		AcoesBottom.style.visibility = 'hidden';	
	}
}
//--------------------------------------------------------------------------------------
function MenuInfo(blnAcao, strInfo)
{
	if (blnAcao == true)
	{
		AcoesTop.style.position = '';		
		AcoesTop.style.visibility = '';	
		InfoTop.innerHTML = '<font size="2" face="Arial, Verdana" color="#000000"><b>' + strInfo + '</b></font>';
	}
	else
	{
		AcoesTop.style.position = 'absolute';		
		AcoesTop.style.visibility = 'hidden';	
		InfoTop.innerHTML = '';					
	}
}
//--------------------------------------------------------------------------------------
function SelectAll(sel)
{
	for (var x=0; x<sel.length; x++){sel.options[x].selected=true;}
}
//--------------------------------------------------------------------------------------
function uCase(campo){

	
	var valor_atual = campo.value;
	var valor_uCase = valor_atual.toUpperCase();
	campo.value = valor_uCase;

}
//--------------------------------------------------------------------------------------
function lCase(campo){

	
	var valor_atual = campo.value;
	var valor_uCase = valor_atual.toLowerCase();
	campo.value = valor_uCase;
}
//--------------------------------------------------------------------------------------
function formata_somadata(vstrcampo)
{

	Dia = vstrcampo.substring(0,2);
	Mes = vstrcampo.substring(3,5);
	Ano = vstrcampo.substring(6,10);
	
	somadata = Ano+Mes+Dia;
		
	return somadata;
	
}
//--------------------------------------------------------------------------------------
function adicionaValor(objeto,aTexto,aValor){
	var objetoInt = eval(objeto);
	var opt = document.createElement('OPTION');
	opt.text = String(aTexto);
	opt.value = aValor;
	objetoInt.add(opt);
}
//--------------------------------------------------------------------------------------
function adicionaValorMarcado(objeto,aTexto,aValor){
	var objetoInt = eval(objeto);
	var opt = document.createElement('OPTION');
	opt.text = String(aTexto);
	opt.value = aValor;
	opt.selected = true;
	objetoInt.add(opt);
}	
//--------------------------------------------------------------------------------------
function adicionaValorExtra(objeto,aTexto,aValor,aExtra){
	var objetoInt = eval(objeto);
	var opt = document.createElement('OPTION');
	opt.text = String(aTexto);
	opt.value = aValor;
	opt.extra = aExtra;
	objetoInt.add(opt);
}	
//--------------------------------------------------------------------------------------
function removeValor(objeto,indice){
	var objetoInt = eval(objeto);
	var opt = document.createElement('OPTION');
	objetoInt.remove(indice);
}	
//--------------------------------------------------------------------------------------
function replace(string,text,by) 
{
// Replaces text with by in string
		var strLength = string.length, txtLength = text.length;
		if ((strLength == 0) || (txtLength == 0)) return string;

		var i = string.indexOf(text);
		if ((!i) && (text != string.substring(0,txtLength))) return string;
		if (i == -1) return string;

		var newstr = string.substring(0,i) + by;

		if (i+txtLength < strLength)
				newstr += replace(string.substring(i+txtLength,strLength),text,by);

		return newstr;
}
//--------------------------------------------------------------------------------------
function compl_espacos(str,value){
	for(p=str.length; p < value; p++)
	{
		str = str + ' ';
	}	
	return str;							
}
//--------------------------------------------------------------------------------------
function compl_underline(str,value){
	for(p=str.length; p < value; p++)
	{
		str = str + '_';
	}	
	return str;						
}
//--------------------------------------------------------------------------------------
function isCep(cep){

	if (cep.length < 8)
		return false;		
	if (!isNumeric(cep))
		return false;
	if (cep == "")
		return false;		
	
	return true;						
		
}
//--------------------------------------------------------------------------------------
function isCPF (CPF) {

   var number, soma, i, ok;

	ok = false;
	number = trim(CPF);
	soma = 0;
	
	if (number == '') {
	   return true;
	}
	
	if (number.length == 11) { //typenumber == 0) {            // CPF
		if(number.length == 11) {
			for (i=0; i < 9; i++)   //Cálculo do primeiro dígito
				soma += (10 - i) * (number.charAt(i) - 0);
			soma = 11 - (soma % 11);
			if (soma > 9) soma = 0;
			if (soma == (number.charAt(9) - 0)) {
				soma = 0;
				for (i=0; i < 10; i++)   //Cálculo do segundo dígito
					soma += (11 - i) * (number.charAt(i) - 0);
				soma = 11 - (soma % 11);
				if (soma > 9) soma = 0;
				if (soma == (number.charAt(10) - 0)) {
					ok = true;
				}
			}
		}
	}
	return ok;
}
//--------------------------------------------------------------------------------------
function isNumeric(ptexto) 
{
	if (trim(ptexto) == '')
	{
		return false;
	}
	else
	{	
		var numeric = true;
		for (i=0; i < ptexto.length; i++) {
			if (!isDigit(ptexto.charAt(i)) ) {
				numeric = false;
				break;
			}
		}
		return numeric;
	}			
}
//--------------------------------------------------------------------------------------
function isNumericInt(campo) 
{

	if (trim(campo) == '')
	{
		return false;
	}
	else
	{	
		var t = 0;
		for(cont=0;cont<campo.length;cont++)
		{
			if(campo.charAt(cont) != "0" && campo.charAt(cont) != "1" && campo.charAt(cont) != "2" && campo.charAt(cont) != "3" && campo.charAt(cont) != "4" && campo.charAt(cont) != "5" && campo.charAt(cont) != "6" && campo.charAt(cont) != "7" && campo.charAt(cont) != "8" && campo.charAt(cont) != "9" )
				{
				return (false);
				}
		}
		return (true);
	}
}
//--------------------------------------------------------------------------------------
function isDigit(pchar) {
    return ("0123456789,.".indexOf(pchar)>=0);
}
//--------------------------------------------------------------------------------------
function isEmail(mail) {
	var ponto = 0;
	var arroba = 0;
	var letraAntes = 0;
	var letraDepois = 0;
	var i = 0;
	var l = mail.length;
	var ch = 0;
	if (l < 10)	return (false);
	for (i = 0; i < l; i++) {
		ch = mail.charCodeAt(i);
		if (ch == 46) {
			if (arroba > 0)	ponto += 1;
		} else {
			if (ch == 64) {
				arroba += 1;
			} else {
				if (((ch >= 65) && (ch <= 90)) || ((ch >= 97) && (ch <= 122))) {
					if (arroba > 0)
						letraDepois += 1;
					else
						letraAntes += 1;
				} else {
					if ((ch != 45) && (ch != 95)) {
						if ((ch < 48) || (ch > 57)) {
							return (false);
						}
					}
				}
			}
		}
	}
	if ((arroba == 1) && (ponto > 0) && (letraAntes > 1) && (letraDepois > 5)) {
		return (true);
	} else {
		return (false);
	}
}
//--------------------------------------------------------------------------------------
function isHora(vTexto)
{

	var vCampo = vTexto;
 	var vTexto = vTexto.value;
	var sepDec = ",";
	var csDec = inStr(vTexto,sepDec);
	var minutos = "";

	if ((csDec == 0) && (vTexto != ''))
	{
		 vTexto = vTexto+sepDec+"00";
		 csDec = inStr(vTexto,sepDec);
	}
	if (!csDec>0 || csDec+2!=vTexto.length) return false;
	if (inStr(vTexto,"+")>0 || inStr(vTexto,"-")>0 || inStr(vTexto,".")>0) return false;
	if (isNaN(vTexto.substr(0,csDec-1)) || isNaN(vTexto.substr(csDec,2))) return false;
	
	csDec = inStr(vTexto,sepDec);
	
	if ((csDec != 0) && (vTexto != ''))
	{
		minutos = vTexto.substr(csDec,vTexto.length);
		if (minutos > 59)
		{
			alert('Informe corretamente os minutos!');
			return false;
		}
	}

	vCampo.value = vTexto;	
	return true;
}
//--------------------------------------------------------------------------------------
function isHoraReal(myObj) 
{
	var H, M;
	if (trim(myObj) != '')
	{
		H = myObj.substring(0,2);
		M = myObj.substring(3,5);
		
		if(!isNumericInt(H))
		{
			return(false);		
		}
		else if (!isNumericInt(M)) 
		{ 
			return(false);
		} 
		else if ((H < 0) || (H > 23)) 
		{ 
			return(false);
		} 
		else if ((M < 0) || (M > 59))
		{ 
			return(false);
		}
		else if ((myObj != '') && (myObj.length < 5))
		{ 
			return(false);
		}
		return(true);	
	}	
}
//--------------------------------------------------------------------------------------
function isDate(campo) {
	if (campo != ""){
		if(campo.charAt(2) != "/" || campo.charAt(5) != "/" || campo.length != 10){
			return(false);
		}
		for(i=0;i<10;i++){
			if(i != 2 && i != 5){
				if(campo.charAt(i) != 0 && campo.charAt(i) != 1 && campo.charAt(i) != 2 && campo.charAt(i) != 3 && campo.charAt(i) != 4 && campo.charAt(i) != 5 && campo.charAt(i) != 6 && campo.charAt(i) != 7 && campo.charAt(i) != 8 && campo.charAt(i) != 9 || campo.charAt(i) == " "){
					return(false);
				}
			}
		}
		var Dia = 0;
		var Mes = 0;
		var Ano = 0;
		var Resto = 0;
		Dia = campo.substring(0,2);
		Mes = campo.substring(3,5);
		Ano = campo.substring(6,10);
		if (Ano < 1900) {
			return(false);
		}
		if (Ano > 2099) {
			return(false);
		}		
		if ((Mes < 1) || (Mes > 12)) {
			return(false);
		}
		if ((Dia < 1) || (Dia > 31)) {
			return(false);
		}
		if ((Mes == "01") && (Dia <= 31)) {
			return(true);
		}
		if (Mes == "02") {
			Resto = Ano % 4;
			if ((Resto == 0) && (Dia <= 29)) {
				return(true);
			}
			if ((Resto != 0) && (Dia <= 28)) {
				return(true);
			}
		}
		if ((Mes == "03") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "04") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "05") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "06") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "07") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "08") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "09") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "10") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "11") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "12") && (Dia <= 31)) {
			return(true);
		}
	}
	
	return(false);	
}
//--------------------------------------------------------------------------------------
function ltrim(ptexto) {
    var i = 0;
    while (i<ptexto.length && (ptexto.charAt(i)== " " || ptexto.charAt(i)=="'")) {
        i++;
    }
    return (ptexto.substring(i,ptexto.length));
}
//--------------------------------------------------------------------------------------
function rtrim(ptexto) {
    var i = ptexto.length-1;
    while (i>0 && (ptexto.charAt(i) == " " || ptexto.charAt(i)=="'")) {
        i--;
    }
    return (ptexto.substring(0,i+1));
}
//--------------------------------------------------------------------------------------
function trim(ptexto) {
    return ltrim(rtrim(ptexto));
}
//--------------------------------------------------------------------------------------
function isMoney(vTexto){

	var vCampo = vTexto;
 	var vTexto = vTexto.value;
	var sepDec = ",";
	var csDec = inStr(vTexto,sepDec);

	if ((csDec == 0) && (vTexto != ''))
	{
		 vTexto = vTexto+sepDec+"00";
		 csDec = inStr(vTexto,sepDec);
	}
	
 
	if (!csDec>0 || csDec+2!=vTexto.length) return false;
	if (inStr(vTexto,"+")>0 || inStr(vTexto,"-")>0 || inStr(vTexto,".")>0) return false;
	if (isNaN(vTexto.substr(0,csDec-1)) || isNaN(vTexto.substr(csDec,2))) return false;

	vCampo.value = vTexto;	
	return true;
}
//--------------------------------------------------------------------------------------
function inStr(vString,vString2){
	if (vString.length>0 && vString2.length>0){
		for(x=0;x<vString.length;x++){
			if (vString.substr(x,vString2.length)==vString2)return x+1;
		}
		return 0;
	}
	else return 0;
}
//--------------------------------------------------------------------------------------
// Função para contagem de caracteres em campo TEXTAREA 
function limita (campo, tamanhomaximo)
{
	var tamanho = (campo.value.length);
	var tex = campo.value;
	if (tamanho >= tamanhomaximo) 
	{
		campo.value=tex.substring(0,tamanhomaximo-1); 
	}
		return true;
}
//--------------------------------------------------------------------------------------
function contacampo(campoIN, campoOUT, tamanhomaximo) 
{
	var campoIN = campoIN;
	var campoOUT = campoOUT;	
	campoOUT.value = tamanhomaximo - campoIN.value.length;
	
}			
//--------------------------------------------------------------------------------------
function  isPorcentagem(vTexto){
	sepDec = ",";
	var csDec = inStr(vTexto,sepDec);
	if (!csDec>0 || csDec+2!=vTexto.length)return false;
	if (inStr(vTexto,"+")>0 || inStr(vTexto,"-")>0)return false;
	if (isNaN(vTexto.substr(0,csDec-1)) || isNaN(vTexto.substr(csDec,2))) return false;
	ok = true;
	for(i=0; i < vTexto.length; i++)
	{
		pos = vTexto.substring(i, i+1);
		if (pos == '.')
		{
			ok = false;
		}
	}	
	if (ok == false){
		return false;	
	}
	else
	{
		return true;
	}	
}
//--------------------------------------------------------------------------------------
// Função para contagem de caracteres em campo TEXTAREA 
// Modo de Usar:

// Campo de Entrada
// <textarea name="nometextarea" rows="8" cols="70" WRAP 
// onKeyPress="javascript:limita(document.nomeformulario.nometextarea, 1500);"
// onKeyUp="javascript:contacampo(document.nomeformulario.nometextarea, 
// document.nomeformulario.tamanho, 1500)"> </textarea>

// Campo de Saída - Mostra a quantidade atual de caracteres
// <input type="text" name="tamanho" size="4" value="1500" READONLY 
// onKeyUp="javascript:contacampo(document.respcotacao.RES_DSCPROD, 
// document.respcotacao.tamanho, 1500);" style="font-size:Verdana; border-color: 
// #000000; border-style: double; border-width: 0px; background-color: #FFFFFF">
function limita (campo, tamanhomaximo)
{
	var tamanho = (campo.value.length);
	var tex = campo.value;
	if (tamanho >= tamanhomaximo) 
	{
		campo.value=tex.substring(0,tamanhomaximo-1); 
	}
		return true;
}
//--------------------------------------------------------------------------------------
function contacampo(campoIN, campoOUT, tamanhomaximo) 
{
	var campoIN = campoIN;
	var campoOUT = campoOUT;	
	campoOUT.value = tamanhomaximo - campoIN.value.length;
	
}			
//--------------------------------------------------------------------------------------
function popupsimples(pagina,altura,largura) 
{
	var nome = 'xxx';
	var top = 0;
	var left = 0;
	var scroll = 1;
	var toolbar = 0;
	var location = 0;
	var menu = 0;
	var resize = 0;
	var fullscreen = 0;
	var janela;
	var top2 = (screen.height - altura) / 2;
	var left2 = (screen.width  - largura) / 2;
	janela = window.open(pagina,nome,'status=1;width='+largura+',height='+altura+',top='+top+',left='+left+',scrollbars='+scroll+',toolbar='+toolbar+',location='+location+',menubar='+menu+',resizable='+resize+',fullscreen='+fullscreen);
	janela.focus();
}
//--------------------------------------------------------------------------------------
function popupSmartPag(pagina,altura,largura,nome) 
{
	var top = 0;
	var left = 0;
	var scroll = 1;
	var toolbar = 0;
	var location = 0;
	var menu = 0;
	var resize = 1;
	var fullscreen = 0;
	var janela;
	var top = (screen.height - altura) / 2;
	var left = (screen.width  - largura) / 2;
	janela = window.open(pagina,nome,'width='+largura+',height='+altura+',top='+top+',left='+left+',scrollbars='+scroll+',toolbar='+toolbar+',location='+location+',menubar='+menu+',resizable='+resize+',fullscreen='+fullscreen);
	janela.focus();
}
//--------------------------------------------------------------------------------------
function popup(pagina,nome,altura,largura,top,left,scroll,toolbar,location,menu,resize,fullscreen) 
{
	var janela;
	var top2 = (screen.height - altura) / 2;
	var left2 = (screen.width  - largura) / 2;
	janela = window.open(pagina,nome,'width='+largura+',height='+altura+',top='+top+',left='+left+',scrollbars='+scroll+',toolbar='+toolbar+',location='+location+',menubar='+menu+',resizable='+resize+',fullscreen='+fullscreen);
	janela.focus();
}
//--------------------------------------------------------------------------------------
function popupF11(pagina,nome) 
{
	var janela;
	janela = window.open(pagina,nome,"channelmode=1,status=1");
	janela.focus();
}
//--------------------------------------------------------------------------------------
function popupDIALOGO(pagina) 
{
	var prop = "dialogWidth: 430px; dialogHeight: 280px; center: 1; scroll: 0; help: 1; status: 0;";
	window.showModalDialog(pagina, null, prop);
}
//--------------------------------------------------------------------------------------
//Função para mover itens de um listbox para outro ordenando depois alfabeticamente
function MoveSelectedListItems(srcCombo, destCombo, doSort, intSort, useVals)
{
	var numItems = 0;
	var curPos = destCombo.options.length;
	var srcLen = srcCombo.options.length;
	
	for (var x=0; x<srcCombo.options.length; x++)
		if (srcCombo.options[x].selected) numItems++;
	
	destCombo.options.length+=numItems;
	for (var x=0; x<srcCombo.options.length; x++)
		if (srcCombo.options[x].selected==true) 
		{
			destCombo.options[curPos].text=srcCombo.options[x].text;
			destCombo.options[curPos].value=srcCombo.options[x].value;
			curPos++;
		}
	if (doSort) SortList(destCombo, intSort, useVals);
	
	/* now remove the selected items from the source listbox */
	/* This can be very slow for big lists, but I'm not sure how else to do it */		
	for (var x=srcLen-1; x>=0; x--)
		if (srcCombo.options[x].selected) srcCombo.options[x]=null;
}
//--------------------------------------------------------------------------------------
// Compare functions used internally by the SortList routine,
function ListCompareNums(a,b)
{
	var la = parseInt(a.split("{")[0]);
	var lb = parseInt(b.split("{")[0]);
	if (la < lb) return -1;
	if (la > lb) return 1
	return 0;
}
//--------------------------------------------------------------------------------------
function ListCompareText(a,b)
{	var la = a.toLowerCase();
	var lb = b.toLowerCase();
	if (la < lb) return -1;
	if (la > lb) return 1
	return 0;
}
//--------------------------------------------------------------------------------------
// Quite Fast way of sorting big option lists
function SortList(Combo, IntSort, UseVals)
{
	var cmbText = new Array(Combo.options.length);
	var cmbItems;
	
	// get copy of	
	for (x=0; x<cmbText.length; x++)
		cmbText[x]=(UseVals)?Combo.options[x].value + "{" + Combo.options[x].text:Combo.options[x].text + "{" + Combo.options[x].value;
	
	if (IntSort)
		cmbText.sort(ListCompareNums);
	else
		cmbText.sort(ListCompareText);
			
	//rebuild main list, but don't redimension it
	for (x=0; x<cmbText.length; x++){	
		cmbItems = cmbText[x].split("{");
		Combo.options[x].text=(UseVals)?cmbItems[1]:cmbItems[0];	
		Combo.options[x].value=(UseVals)?cmbItems[0]:cmbItems[1];
	}
}
//--------------------------------------------------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
//--------------------------------------------------------------------------------------
function MM_findObj(n, d) { //v3.0
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  return x;
}
//--------------------------------------------------------------------------------------
function MM_swapImage() { //v3.0
  MM_swapImgRestore()
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
	  {
		document.MM_sr[j++]=x;
        if(!x.oSrc) x.oSrc=x.src;
        x.src=a[i+2];
      }
}

//--------------------------------------------------------------------------------------
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//--------------------------------------------------------------------------------------
function DateDiff( start, end, interval, rounding ) {

    var iOut = 0;
    
    // Create 2 error messages, 1 for each argument. 
    var startMsg = "Check the Start Date and End Date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
    	
    // check that the start parameter is a valid Date. 
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }
    
    var number = bufferB-bufferA ;
    
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    
    return iOut ;
}
//--------------------------------------------------------------------------------------
// The presentDate function is called on when you 
// click on the button on the form.
function presentDate(f) {
    var ierr = 1 ;
    
   // Verify whether the user wants to return only whole
   // intervals or intervals rounded to the nearest number 
   // of interval.
   var roundDays = f.chkWholeDays.checked ;
   
   // Verify that the user entered something in the
   // Start Date input box.
    if(f.startDate.value != '') {
        if(!isNaN(Date.parse( f.startDate.value ))) {
            var s = new Date(Date.parse(f.startDate.value)) ;
            ierr = 0 ;
        }
    }
    
    // Verify that the user entered something in the
   // Ending Date input box.
    if(f.endDate.value != '' && ierr != 1) {
        if(!isNaN(Date.parse( f.endDate.value ))) {
            var e = new Date(Date.parse(f.endDate.value)) ;
            
            // call the dateDiff function.
            var temp = suycDateDiff( s, e, f.selTypeOf.value, roundDays ) ;
        }else{
            ierr = 1;
        }
    }else{
        ierr = 1;
    }
    
    // update the tellTime field with our new value.
    if ( temp != null && ierr != 1 ) f.tellTime.value = temp.toString() ;
}
//--------------------------------------------------------------------------------------
function comparaHora(horaini, horafim)
{

	if ((horaini != '')&&(horafim == ''))
	{
		return false;
	}
	
	if ((horaini == '')&&(horafim != ''))
	{
		return false;	
	}	


	pospontohora = eval(inStr(horaini,":"));
	t_horaini = eval(horaini.substring(0,pospontohora-1));
	t_minutoini = eval(horaini.substring(pospontohora,5));
	minutosini = ((t_horaini) * 60) + eval(t_minutoini);

	pospontohora = eval(inStr(horafim,":"));
	t_horafim = eval(horafim.substring(0,pospontohora-1));
	t_minutofim = eval(horafim.substring(pospontohora,5));
	minutosfim = ((t_horafim) * 60) + eval(t_minutofim);

	if (minutosini > minutosfim)
	{
		return false;
	}
	else
	{
		return true;
	}
}
//--------------------------------------------------------------------------------------
function ValidaData(objeto) 
{
	var DataString	= objeto.value;
	var DataArray	= DataString.split("/");  
	var Flag=true; 

	if (DataArray.length != 3) 
		Flag=false; 
	else 
		{
			if (DataArray.length==3) 
			{
				var dia = DataArray[0], mes = DataArray[1], ano = DataArray[2]; 

				if (((Flag) && (ano<1000) || ano.length>4)) 
					Flag=false; 
				
				if (Flag) 
				{ 
					verifica_mes = new Date(mes+"/"+dia+"/"+ano); 
					if (verifica_mes.getMonth() != (mes - 1)) 
						Flag=false; 
				} 
			} 
			else 
				Flag=false; 
		} 
return Flag;
} 
//--------------------------------------------------------------------------------------
function FormataDATA(objeto, teclapress)
{
	var tecla = teclapress.keyCode;

	if(((window.event.keyCode == 13) || (window.event.keyCode == 9))&&objeto.value != "")
	{
		if(!(ValidaData(objeto)))
			{
				window.event.cancelBubble = true;
				window.event.returnValue = false;
				alert("Data Inválida");
				objeto.value = "";
				objeto.focus();
			}
	}

	if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length < (10))
    {
		vr = objeto.value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		tam = vr.length;

		if (tam < 8)
			{
				if (tecla != 8) {tam = vr.length + 1 ;}
			}
		else
			{
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
		
		if ((tecla == 8) && (tam > 1))
			{
				tam = tam - 1 ;
				objeto.value = vr.substr(0,tam);
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
				if ( tam <= 4 && tecla != 8){ 
			 		objeto.value = vr ; }

				if ( (tam >= 4) && (tam <= 6) ){
			 		objeto.value = vr.substr(0, tam - 4) + '/' + vr.substr( tam - 4, 4 ); }

				if ( (tam >= 6) && (tam <= 8) ){
					objeto.value = vr.substr(0, tam - 6 ) + '/' + vr.substr( tam - 6, 2 ) + '/' + vr.substr( tam - 4, 4 ); }

				if ((tam == (8)) && tecla != 8)
					{
						if(tecla >=96 && tecla <=105)
							{
								tecla = tecla - 48;
							}

						objeto.value = objeto.value + (String.fromCharCode(tecla));
						window.event.cancelBubble = true;
						window.event.returnValue = false;

						if (!(ValidaData(objeto)))
							{
								alert("Data Inválida");
								objeto.value = "";
								objeto.focus();
							}
					}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
	{
		event.returnValue = false;
	}
}
//--------------------------------------------------------------------------------------
function FormataCNPJ(Campo, teclapres)
{

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}
//--------------------------------------------------------------------------------------
function consistbusca(form)
{
	if (typeof(consistbusca_local) == 'function')
	{
		return consistbusca_local(form);
	}
	else
	{
		return true;
	}
}
//--------------------------------------------------------------------------------------
function comparaData(data1, data2) 
{
	var ano1 = data1.substring( 6 );
	var mes1 = data1.substring(3,5);
	var dia1 = data1.substring(0,2);
	var data1Str = ano1 + mes1 + dia1
	var ano2 = data2.substring( 6 );
	var mes2 = data2.substring(3,5);
	var dia2 = data2.substring(0,2);
	var data2Str = ano2 + mes2 + dia2;
	if( data1Str > data2Str ) 
	{
		return false;
	}
	else
	{
		return true;	
	}
}
//--------------------------------------------------------------------------------------
var tecla=0;
function verificaTecla(campo,x){

	if((x<48 || x>57))return false;
	tecla=x;
	return true;
}
//--------------------------------------------------------------------------------------
var teclaRG=0;
function verificaTeclaRG(campo,x)
{
	if ( (x>=48 && x<=57) || (x>=65 && x<=90) || (x>=97 && x<=122))
	{
		teclaRG=x;
		return true;
	}
	else
	{
		return false;
	}
}
//--------------------------------------------------------------------------------------
function preenche_barra(campo,x)
{
	if((x>=48 && x<=57)||(x==47)){	
	
		if(campo.value.length==2)
			if(campo.value.indexOf("/")==-1)
				campo.value=campo.value+'/';
			else
				if(campo.value.indexOf("/")!=0)campo.value='0'+campo.value;

		if((campo.value.length==5)&&(campo.value.indexOf("/")==2))
			if(campo.value.lastIndexOf("/")==campo.value.length-1){
				var campo_aux="";
				for(var i=0; i<=campo.value.length-1; i++){
					campo_aux=campo_aux+campo.value.charAt(i);
					if(campo_aux.length==3)campo_aux=campo_aux+'0';
				}
				campo.value=campo_aux;
			}
			else
				if(campo.value.indexOf("/")==campo.value.lastIndexOf("/"))
					campo.value=campo.value+'/';
	}
}
//--------------------------------------------------------------------------------------
function validaData(campo){

	var dateIn,DateOut;

	if (campo.value.indexOf("/")==campo.value.lastIndexOf("/")){
		alert("A data informada não é válida.");
		campo.select();
		campo.focus();
		return false;
	}

	dataIn=campo.value.split("/");

	for(i=0;i<=dataIn.length-1;i++)
		if(dataIn[i]==''){
			alert("A data informada não é válida.");
			campo.select();
			campo.focus();
			return false;
		}
	

	if(dataIn[2].length!=4){
		alert("Digite o ano com 4 dígitos.");
		campo.select();
		campo.focus();
		return false;
	}else if(dataIn[2]=='0000'){
		alert("A data informada não é válida.");
		campo.select();
		campo.focus();
		return false;
	}
		

	dataOut=new Date(dataIn[2],dataIn[1]-1,dataIn[0]);
	if((dataIn[2]!=dataOut.getFullYear())||(dataIn[1]!=dataOut.getMonth()+1)||(dataIn[0]!=dataOut.getDate())){
		alert("A data informada não é válida.");
		campo.select();
		campo.focus();
		return false;
	}
	
	return true;
}
//--------------------------------------------------------------------------------------
function preenche_barra(campo,x){

	if((x>=48 && x<=57)||(x==47)){	
		if(campo.value.length==2)
			if(campo.value.indexOf("/")==-1)
				campo.value=campo.value+'/';
			else
				if(campo.value.indexOf("/")!=0)campo.value='0'+campo.value;

		if((campo.value.length==5)&&(campo.value.indexOf("/")==2))
			if(campo.value.lastIndexOf("/")==campo.value.length-1){
				var campo_aux="";
				for(var i=0; i<=campo.value.length-1; i++){
					campo_aux=campo_aux+campo.value.charAt(i);
					if(campo_aux.length==3)campo_aux=campo_aux+'0';
				}
				campo.value=campo_aux;
			}
			else
				if(campo.value.indexOf("/")==campo.value.lastIndexOf("/"))
					campo.value=campo.value+'/';
	}
}
//--------------------------------------------------------------------------------------
function validaData(campo){

	var dateIn,DateOut;

	if (campo.value.indexOf("/")==campo.value.lastIndexOf("/")){
		alert("A data informada não é válida.");
		campo.select();
		campo.focus();
		return false;
	}

	dataIn=campo.value.split("/");

	for(i=0;i<=dataIn.length-1;i++)
		if(dataIn[i]==''){
			alert("A data informada não é válida.");
			campo.select();
			campo.focus();
			return false;
		}
	

	if(dataIn[2].length!=4){
		alert("Digite o ano com 4 dígitos.");
		campo.select();
		campo.focus();
		return false;
	}else if(dataIn[2]=='0000'){
		alert("A data informada não é válida.");
		campo.select();
		campo.focus();
		return false;
	}
		

	dataOut=new Date(dataIn[2],dataIn[1]-1,dataIn[0]);
	if((dataIn[2]!=dataOut.getFullYear())||(dataIn[1]!=dataOut.getMonth()+1)||(dataIn[0]!=dataOut.getDate())){
		alert("A data informada não é válida.");
		campo.select();
		campo.focus();
		return false;
	}
	
	return true;
}
//--------------------------------------------------------------------------------------
-->