
function MascaraHora(objeto){
	if (objeto.value.indexOf(":") == -1 && objeto.value.length > 2){ 
		objeto.value = ""; 
	}
	if (objeto.value.length == 2){
		objeto.value += ":";
	}
}
// onKeyPress="javascript:MascaraHora(this);"

// Somente Numeros
function v_NR(tecla,flg){
	if(typeof(tecla) == 'undefined')
		var tecla = window.event;
	var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);
	var teste;

	//flg == 1 - Quantidade = aceita numeros,pontos e virgulas
	//flg == 2 - Valor monetário, so aceita numeros
	if (flg == 2){
		teste = "(codigo >= 48 && codigo <= 57) || (codigo >= 96 && codigo <= 105) || codigo == 8 || codigo == 46 || codigo == 9";
	}else{
		teste = "(codigo >= 48 && codigo <= 57) || (codigo >= 96 && codigo <= 105) || codigo == 8 || codigo == 46 || codigo == 9 || codigo == 110 || codigo == 190 || codigo == 44 || codigo == 188 || codigo == 194";
	}
	
	// permite números, 8=backspace, 46=del e 9=tab
	if ( eval(teste) ){ 
		return true; 
	}	
	else{ 
		//alert("Apenas números são permitidos !"); 
		return false; 
	}

}




//-----> máscara hora:

function m_HORA(campo,tammax,tecla) {
	if(typeof(tecla) == 'undefined')
		var tecla = window.event;
	var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);
	var vr = campo.value;
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	var tam = vr.length;
	if (tam < tammax) { 
		tam = vr.length + 1; 
	}
	if (codigo == 8) {
		tam = tam - 1; 
	}
	tam = tam - 1;
	if ( (tam >= 2) && (tam < 3) ) {
		vr = vr.substr( 0, tam - 0 ) + ':' + vr.substr( tam - 0, 2 ); 
	}
	if ( (tam >= 3) && (tam < 4) ) {
		vr = vr.substr( 0, tam - 1 ) + ':' + vr.substr( tam - 1, 2 ); 
	}
	if (tam == 4) {
		vr = vr.substr( 0, tam - 2 ) + ':' + vr.substr( tam - 2, 2 ) + ':' + vr.substr( tam - 0, 5 ); 
	}
	if (tam == 5) {
		vr = vr.substr( 0, tam - 3 ) + ':' + vr.substr( tam - 3, 2 ) + ':' + vr.substr( tam - 1, 6 ); 
	}	
	campo.value = vr;
}

function valida_hora(valor,form,name){
	if (form[name].value == ""){
		return true;
	}
	var hora = valor.substr(0,2);
	var minuto = valor.substr(3,2);
	
	if (hora > 24 || hora < 0 ){
		alert("Hora inválida");
		form[name].value = "";
		return false;
	}
	else{
		if (minuto > 60 || minuto < 0 ){
			alert("Hora inválida");
			form[name].value = "";
			form[name].focus();
			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 -> 99.999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999
* Tel Resid -> (99) 9999-9999
* Tel Cel -> (99) 9999-9999
* Processo -> 99.999999999/999-99
* C/C -> 999999-!
* E por aí vai...
***/

function mascara(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

sValue = objForm[strField].value;
if (sValue.length == 0)
	return;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
// toString().replace [transforma em sring e troca elementos por ""]
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( " ", "" );
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) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == "."))

//Se for true utiliza elementos especiais aumenta a máscara
if (bolMask) {
    sCod += sMask.charAt(i);
    mskLen++;
//Caso false mostra o sValue(o q foi digitado)
} 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(digData,form,name)
{	if (form[name].value == ""){
		return true;
	}
    var bissexto = 0;
    var data = digData;
    var tam = data.length;
    if (tam == 10)
    {
        var dia = data.substr(0,2)
        var mes = data.substr(3,2)
        var ano = data.substr(6,4)
        if ((ano > 1900)||(ano < 2100))
        {
            switch (mes)
            {
                case '01':
                case '03':
                case '05':
                case '07':
                case '08':
                case '10':
                case '12':
                    if  (dia <= 31)
                    {
                        return true;
                    }
                    break
                
                case '04':        
                case '06':
                case '09':
                case '11':
                    if  (dia <= 30)
                    {
                        return true;
                    }
                    break
                case '02':
                    /* Validando ano Bissexto / fevereiro / dia */
                    if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0))
                    {
                        bissexto = 1;
                    }
                    if ((bissexto == 1) && (dia <= 29))
                    {
                        return true;                
                    }
                    if ((bissexto != 1) && (dia <= 28))
                    {
                        return true;
                    }            
                    break                        
            }
        }
    }
    	alert("A Data "+data+" é inválida!");
		form[name].value = ""
		form[name].focus();
    	return false;
}

function valida_cpf(cpf,form,name,flg){
	if (form[name].value == ""){
		return true;
	}
	var i;
	//s = document.form1.cpf.value; 
	cpf = cpf.replace(".","");
	cpf = cpf.replace(".","");
	cpf = cpf.replace("-","");
	c = cpf.substr(0,9); 
	var dv = cpf.substr(9,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++){ 
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0){
		alert("CPF Invalido")
		form[name].value = "";
		form[name].focus();
		return false; 
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) 
		d1 = 0;
	if (dv.charAt(0) != d1){
		alert("CPF Invalido")
		form[name].value = "";
		form[name].focus();
		return false;
	} 
	d1 *= 2;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) 
		d1 = 0;
	if (dv.charAt(1) != d1){
		alert("CPF Invalido")
		form[name].value = "";
		form[name].focus();
		return false;
	}
	if (flg == true)
		MandaID(form[name].value,8,0);
	return true;
}

function valida_cnpj(cnpj,form,name,flg,flg2){
	if (form[name].value == ""){
		return true;
	}
	cnpj = cnpj.replace(".","");
	cnpj = cnpj.replace(".","");
	cnpj = cnpj.replace("/","");
	cnpj = cnpj.replace("-","");
	var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
	digitos_iguais = 1;
	if (cnpj.length < 14 && cnpj.length < 15){
		alert("CNPJ Invalido")
		form[name].value = "";
		form[name].focus();
		return false;
	}
	for (i = 0; i < cnpj.length - 1; i++)
		if (cnpj.charAt(i) != cnpj.charAt(i + 1)){
			  digitos_iguais = 0;
			  break;
		}
	if (!digitos_iguais){
		tamanho = cnpj.length - 2
		numeros = cnpj.substring(0,tamanho);
		digitos = cnpj.substring(tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--){
			  soma += numeros.charAt(tamanho - i) * pos--;
			  if (pos < 2)
					pos = 9;
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0)){
			alert("CNPJ Invalido")
			form[name].value = "";
		form[name].focus();
			return false;
		}
		tamanho = tamanho + 1;
		numeros = cnpj.substring(0,tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--){
			  soma += numeros.charAt(tamanho - i) * pos--;
			  if (pos < 2)
					pos = 9;
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1)){
			alert("CNPJ Invalido")
			form[name].value = "";
		form[name].focus();
			return false;
		}
		if (flg == true){
			if (flg2 == 0){
				MandaID(form[name].value,9,0);
			}else{
				MandaID(form[name].value,14,0);
			}
		}
		return true;
	}
	else{
		alert("CNPJ Invalido")
		form[name].value = "";
		form[name].focus();
		return false;
	}
} 

// funcao usada na criacao dos campos datas, usado principalmente quando cria-se campos por meio de innerHMTL
function formata_data(val)
{
   	var pass = val.value;
	var expr = /[0123456789]/;
		
	for(i=0; i<pass.length; i++){
		// charAt -> retorna o caractere posicionado no índice especificado
		var lchar = val.value.charAt(i);
		var nchar = val.value.charAt(i+1);
	
		if(i==0){
		   // search -> retorna um valor inteiro, indicando a posição do inicio da primeira
		   // ocorrência de expReg dentro de instStr. Se nenhuma ocorrencia for encontrada o método retornara -1
		   // instStr.search(expReg);
		   if ((lchar.search(expr) != 0) || (lchar>3)){
			  val.value = "";
		   }
		   
		}else if(i==1){
			   
			   if(lchar.search(expr) != 0){
				  // substring(indice1,indice2)
				  // indice1, indice2 -> será usado para delimitar a string
				  var tst1 = val.value.substring(0,(i));
				  val.value = tst1;				
 				  continue;			
			   }
			   
			   if ((nchar != '/') && (nchar != '')){
				 	var tst1 = val.value.substring(0, (i)+1);
				
					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '/' + tst2;
			   }

		 }else if(i==4){
			
				if(lchar.search(expr) != 0){
					var tst1 = val.value.substring(0, (i));
					val.value = tst1;
					continue;			
				}
		
				if	((nchar != '/') && (nchar != '')){
					var tst1 = val.value.substring(0, (i)+1);

					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '/' + tst2;
				}
   		  }
		
		  if(i>=6){
			  if(lchar.search(expr) != 0) {
					var tst1 = val.value.substring(0, (i));
					val.value = tst1;			
			  }
		  }
	 }
	
     if(pass.length>10)
		val.value = val.value.substring(0, 10);
	 	return true;
}




function FormataValor(id,tammax,teclapres) {
	if(window.event) { // Internet Explorer
		var tecla = teclapres.keyCode; }
		else if(teclapres.which) { // Nestcape / firefox
			var tecla = teclapres.which;
		}	
    vr = document.getElementById(id).value;
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( ",", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	tam = vr.length;
	
	if (tam < tammax && tecla != 8){ 
		tam = vr.length + 1; 
	}	
	if (tecla == 8 ){ 
		tam = tam - 1; 
	}	
	if ( tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
			document.getElementById(id).value = vr; 
		}	
		if ( (tam > 2) && (tam <= 5) ){
			document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); 
		}
		if ( (tam >= 6) && (tam <= 8) ){
			document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
		}
		if ( (tam >= 9) && (tam <= 11) ){
			document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
		}
		if ( (tam >= 12) && (tam <= 14) ){
			document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
		}
		if ( (tam >= 15) && (tam <= 17) ){
			document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
		}
	}
}


function FormataValor_6Decimais(id,tammax,teclapres) {
	if(window.event) { // Internet Explorer
		var tecla = teclapres.keyCode; }
		else if(teclapres.which) { // Nestcape / firefox
			var tecla = teclapres.which;
		}	
    vr = document.getElementById(id).value;
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( ",", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	tam = vr.length;
	
	if (tam < tammax && tecla != 8){ 
		tam = vr.length + 1; 
	}	
	if (tecla == 8 ){ 
		tam = tam - 1; 
	}	
	if ( tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 6 ){
			document.getElementById(id).value = vr; 
		}	
		if ( (tam > 2) && (tam <= 6) ){
			document.getElementById(id).value = vr; 
		}
		if ( (tam >= 7) && (tam <= 9) ){
			document.getElementById(id).value = vr.substr( 0, tam - 6 ) + ',' + vr.substr( tam - 6, tam ); 
		}
		if ( (tam >= 10) && (tam <= 12) ){
			document.getElementById(id).value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + ',' + vr.substr( tam - 6, tam ); 
		}
		if ( (tam >= 13) && (tam <= 15) ){
			document.getElementById(id).value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + ',' + vr.substr( tam - 6, tam ); 
		}
		if ( (tam >= 16) && (tam <= 18) ){
			document.getElementById(id).value = vr.substr( 0, tam - 15 ) + '.' + vr.substr( tam - 15, 3 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + ',' + vr.substr( tam - 6, tam );
		}
		if ( (tam >= 19) && (tam <= 21) ){
			document.getElementById(id).value = vr.substr( 0, tam - 18 ) + '.' + vr.substr( tam - 18, 3 ) + '.' + vr.substr( tam - 15, 3 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + ',' + vr.substr( tam - 6, tam );
		}
	}
}


function FormataValor2(valor) {
	vr = valor;	
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( ",", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	tam = vr.length;
	
	if ( tam <= 2 ){
		vr = vr; 
	}	
	if ( (tam > 2) && (tam <= 5) ){
		vr = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); 
	}
	if ( (tam >= 6) && (tam <= 8) ){
		vr = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
	}
	if ( (tam >= 9) && (tam <= 11) ){
		vr = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
	}
	if ( (tam >= 12) && (tam <= 14) ){
		vr = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
	}
	if ( (tam >= 15) && (tam <= 17) ){
		vr = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
	}
	
	return vr;
}

// funcao para tirar os pontos e virgulas dos numeros para poder fazer a conta
function formata(val){
	for(j=0;j<=val.length;j++)
		val = val.replace(".","");
	val = val.replace(",",".");
	return val;
}
// funcao para calcular o valor dos lotes,itens,global
function cal_lote(lote){
	var total = 0;
	var LI_VL_GLOBAL = 0;
	var LI_VL_LOTES = 0;
	if (document.getElementById('VL_LT_'+(lote))){
		if (document.getElementById('qtd_itens_'+lote)) // pegando a quantidade de itens do lote que
			// no formulário inc_lote,inc_global
			var qtd_itens = document.getElementById('qtd_itens_'+lote).value;
		else// no formulário inc_itens
			var qtd_itens = document.getElementById('qtdItens').value;
			
		for(i=1;i<=qtd_itens;i++){ // faz um for na quantidade de itens
			if (document.getElementById('IT_TOTAL_'+(lote)+'_'+i)){ // se existe o campo com o valor total do item
				valor = formata(document.getElementById('IT_TOTAL_'+lote+'_'+i).value); // pega o valor total do item
				valor = Number(valor);
				total = Number(total + valor);
			}// fim do if
		}// fim do for
		total = total.toFixed(2); // aqui colocamos só 2 casas decimais
		
		if (document.getElementById("LT_VALOR_"+lote)){
			document.getElementById("LT_VALOR_"+lote).value = FormataValor2(total);
			if (document.getElementById("LI_VL_GLOBAL")){// usado no formulário de alt_global,inc_global só existe essa campo no form da proposta global
				if (document.getElementById("qtdLotes")){// verificando se existe o campo com a quantidade de lotes
					for(y=1;y<=document.getElementById("qtdLotes").value;y++){ // faz um for até a qtd de lotes geradas
						if (document.getElementById('LT_VALOR_'+y)){ // verifica se existe o campo com o valor do lote
							valor = formata(document.getElementById('LT_VALOR_'+y).value); // pega o valor total do lote
							valor = Number(valor);
							LI_VL_GLOBAL = Number(LI_VL_GLOBAL + valor);
						}// fim do if
					}// fim do for				
					LI_VL_GLOBAL = LI_VL_GLOBAL.toFixed(2); // aqui colocamos só 2 casas decimais
					document.getElementById("LI_VL_GLOBAL").value = FormataValor2(LI_VL_GLOBAL); // atualizamos o campo com o valor global da proposta
				} // fim de if (document.getElementById("qtdLotes")){
			}// fim de if (document.getElementById("LI_VL_GLOBAL")){
			else{
				if (document.getElementById("LI_VL_LOTES")){// usado no formulário de alt_lote,inc_lote
					if (document.getElementById("qtdLotes")){ // verificando se existe o campo com a quantidade de lotes
						for(a=1;a<=document.getElementById("qtdLotes").value;a++){ // faz um for até a qtd de lotes geradas
							if (document.getElementById('LT_VALOR_'+a)){ // verifica se existe o campo com o valor do lote
								valor = formata(document.getElementById('LT_VALOR_'+a).value); // pega o valor total do lote
								valor = Number(valor);
								LI_VL_LOTES = Number(LI_VL_LOTES + valor);
							}// fim do if
						}// fim do for
						LI_VL_LOTES = LI_VL_LOTES.toFixed(2); // aqui colocamos só 2 casas decimais
						document.getElementById("LI_VL_LOTES").value = FormataValor2(LI_VL_LOTES); // atualizamos o campo com o valor total dos lotes
					}// fim de if (document.getElementById("qtdLotes")){
				}// fim de if (document.getElementById("LI_VL_LOTES")){
			}// fim do else			
		}else{
			if (document.getElementById("LI_VL_ITENS")){
				document.getElementById("LI_VL_ITENS").value = FormataValor2(total);
			}// fim do if
		}// fim do else		
	}// fim de if (document.getElementById('VL_LT_'+(lote))){
}// fim function


// FUNCAO PARA COMPARAR AS DATAS NO CADASTRO DA LICITACAO
function ComparaDatas(data1,data2,hora1,hora2){
	var ano1 = data1.split( "/" )[2].toString();
	var mes1 = data1.split( "/" )[1].toString();
	var dia1 = data1.split( "/" )[0].toString();
	
	var ano2 = data2.split( "/" )[2].toString();
	var mes2 = data2.split( "/" )[1].toString();
	var dia2 = data2.split( "/" )[0].toString();														
	
	// Verificando as datas se a data2 for maior entao nao se preocupa com a hora
	if ( parseInt(ano2+mes2+dia2) > parseInt(ano1+mes1+dia1) ){
		return true;
	}else{
		// Se as datas forem iguais entao verifica a hora
		if ( parseInt(ano2+mes2+dia2) == parseInt(ano1+mes1+dia1) ){
			if (!comparaHora(hora1,hora2)){
				return true;
			}
		}else{// A data2 é menor
			return false;			
		}// fim do else
	}// fim do else	
}

// FUNCAO PARA COMPRARA AS HORAS NO CADASTRO DA LICITACAO
function comparaHora(horaInicio, horaFim){
	//DECLARAÇÃO DE VARIÁVEIS
	var iHoraInicio, iHoraFim;
	var iMinutoInicio, iMinutoFim;
	var flg_hora;
	
	//SEPARA A HORA
	iHoraInicio = horaInicio.substring(0,2);
	iHoraFim = horaFim.substring(0,2);
	
	//SEPARA O MINUTO
	iMinutoInicio = horaInicio.substring(3,5);
	iMinutoFim = horaFim.substring(3,5);	
	
	flg_hora = false;
	
	//COMPARA OS VALORES
	//HORA
	if (iHoraInicio != iHoraFim){
		if (iHoraInicio > iHoraFim){
			return true;
		}else{
			flg_hora = true;
		}
	}else{ // Horas sao iguais
		flg_hora = false;
	}
	
	//SE NÃO RESOLVEU NA HORA, VERIFICA OS MINUTOS
	if (flg_hora == false && (iMinutoInicio != iMinutoFim)){
		if (iMinutoInicio > iMinutoFim){
			return true;
		}else{
			return false;
		}
	}else{// Minutos sao iguais ou as horas sao iguais
		return false;
	}
}

// Funcao para adicionar tabela
var NumeroCampo = 1;
function Add_Operadores() {
	NumeroCampo+=1;
	
	while (document.getElementById('OP_NOME_'+NumeroCampo)){
		NumeroCampo+=1;
	}
	
	document.getElementById("qtd_operadores").value = Number(document.getElementById("qtd_operadores").value) + 1;
	
	var tab_oper = document.getElementById('senha_operadores');
	var totLinhas = tab_oper.rows.length;
	
	var linha_nome = tab_oper.insertRow(totLinhas);
	
	// Nome
	var label_nome = linha_nome.insertCell(0);
	var campo_nome= linha_nome.insertCell(1);
	label_nome.innerHTML = "<span class='style1'>Nome:</span>";
	campo_nome.innerHTML = "<input name='OP_NOME_"+ NumeroCampo +"' id='OP_NOME_"+ NumeroCampo +"' type='text' size='60' maxlength='150' onKeyUp='this.value=this.value.toUpperCase();' >";
	campo_nome.setAttribute("colSpan",3);
	label_nome.setAttribute("align","right");
	
	totLinhas = tab_oper.rows.length;
	var linha_cpf_funcao = tab_oper.insertRow(totLinhas);
	
	// CPF E FUNCAO
	var label_cpf = linha_cpf_funcao.insertCell(0);
	var campo_cpf= linha_cpf_funcao.insertCell(1);
	var label_funcao= linha_cpf_funcao.insertCell(2);
	var campo_funcao= linha_cpf_funcao.insertCell(3);
	label_cpf.innerHTML = "<span class='style1'>CPF:</span>";
	campo_cpf.innerHTML = "<input  name='OP_CPF_"+ NumeroCampo +"' id='OP_CPF_"+ NumeroCampo +"' type='text' size='14' maxlength='14'/>";
	label_funcao.innerHTML = "<span class='style1'>Função:</span>";
	campo_funcao.innerHTML = "<input name='OP_FUNCAO_"+ NumeroCampo +"' id='OP_FUNCAO_"+ NumeroCampo +"' type='text' size='25' maxlength='50' onKeyUp='this.value=this.value.toUpperCase();' >";
	label_cpf.setAttribute("align","right");
	label_funcao.setAttribute("align","right");
	
	document.getElementById('OP_CPF_'+ NumeroCampo).onkeypress=function(){return mascara(this.form,this.name,'999.999.999-99',event);};
	document.getElementById('OP_CPF_'+ NumeroCampo).onblur=function(){valida_cpf(this.value,this.form,this.name,false);};
	
	totLinhas = tab_oper.rows.length;
	var linha_tel_cel = tab_oper.insertRow(totLinhas);
	
	// Telefone Celular
	var label_tel = linha_tel_cel.insertCell(0);
	var campo_tel= linha_tel_cel.insertCell(1);
	var label_cel= linha_tel_cel.insertCell(2);
	var campo_cel= linha_tel_cel.insertCell(3);
	label_tel.innerHTML = "<span class='style1'>Telefone:</span>";
	campo_tel.innerHTML = "<input  name='OP_TEL_"+ NumeroCampo +"' id='OP_TEL_"+ NumeroCampo +"' type='text' size='14' maxlength='14'/>";
	label_cel.innerHTML = "<span class='style1'>Celular:</span>";
	campo_cel.innerHTML = "<input name='OP_CELULAR_"+ NumeroCampo +"' id='OP_CELULAR_"+ NumeroCampo +"' type='text' size='14' maxlength='14'>";
	label_tel.setAttribute("align","right");
	label_cel.setAttribute("align","right");
	
	document.getElementById('OP_TEL_'+ NumeroCampo).onkeypress=function(){return mascara(this.form,this.name,'(99) 9999-9999',event);};
	document.getElementById('OP_TEL_'+ NumeroCampo).onblur=function(){return mascara(this.form,this.name,'(99) 9999-9999',event);};
	document.getElementById('OP_CELULAR_'+ NumeroCampo).onkeypress=function(){return mascara(this.form,this.name,'(99) 9999-9999',event);};
	document.getElementById('OP_CELULAR_'+ NumeroCampo).onblur=function(){return mascara(this.form,this.name,'(99) 9999-9999',event);};
		
	totLinhas = tab_oper.rows.length;
	var linha_fax_email = tab_oper.insertRow(totLinhas);
	
	// Fax E E-mail
	var label_fax = linha_fax_email.insertCell(0);
	var campo_fax= linha_fax_email.insertCell(1);
	var label_email= linha_fax_email.insertCell(2);
	var campo_email= linha_fax_email.insertCell(3);
	label_fax.innerHTML = "<span class='style1'>Fax:</span>";
	campo_fax.innerHTML = "<input  name='OP_FAX_"+ NumeroCampo +"' id='OP_FAX_"+ NumeroCampo +"' type='text' size='14' maxlength='14'/>";
	label_email.innerHTML = "<span class='style1'>E-mail:</span>";
	campo_email.innerHTML = "<input name='OP_EMAIL_"+ NumeroCampo +"' id='OP_EMAIL_"+ NumeroCampo +"' type='text' size='29' maxlength='50'>";
	label_fax.setAttribute("align","right");
	label_email.setAttribute("align","right");
	
	document.getElementById('OP_FAX_'+ NumeroCampo).onkeypress=function(){return mascara(this.form,this.name,'(99) 9999-9999',event);};
	document.getElementById('OP_FAX_'+ NumeroCampo).onblur=function(){return mascara(this.form,this.name,'(99) 9999-9999',event);};
	
	totLinhas = tab_oper.rows.length;
	var linha_botoes = tab_oper.insertRow(totLinhas);
	
	// Fax E E-mail
	var botoes = linha_botoes.insertCell(0);
	botoes.innerHTML = "<a href='javascript:Add_Operadores()'><img src='"+document.getElementById("http_inicial").value+"imagens/add.gif' border='0' alt='Clique aqui caso haja queira adicionar mais operadores.'/></a>&nbsp;&nbsp;<a href='javascript:void(0);' onClick='javascript:Del_Operadores(this.parentNode.parentNode.rowIndex);'><img src='"+document.getElementById("http_inicial").value+"imagens/remover.gif' border='0' alt='Clique aqui caso queira excluir este operador.' width='12' height='12'/></a>";
	botoes.setAttribute("colSpan",4);
	botoes.setAttribute("height",20);
	botoes.setAttribute("align","center");
	
}
// fim da function

// Funcao para Deletar os campos
function Del_Operadores(row) {
	// Deleta o campo
	for(i=0;i<=4;i++){
		document.getElementById('senha_operadores').deleteRow(row-i);
	}
	
	NumeroCampo--;
}


function mostra_tabela(tipo){
	if (tipo == 1){ // sim
		document.getElementById('tr_senha').style.display  = '';
		if (document.getElementById('tr_respo'))
			document.getElementById('tr_respo').style.display  = '';
	}else{ // nao
		document.getElementById('tr_senha').style.display  = 'none';
		if (document.getElementById('tr_respo'))
			document.getElementById('tr_respo').style.display  = 'none';
	}
}


// funcao para mudar o cadastro de licitacao, de acordo com tipo da licitacao
function mudaCadastroLicitacao(tipo){
	//Conab, mapa, leilao bbm e leilao BB--- só mostra a data da disputa
	if (parseInt(tipo) == 3 || parseInt(tipo) == 4 || parseInt(tipo) == 5 || parseInt(tipo) == 6){
		// escondendo os campos das datas
		document.getElementById("dataRecimentoAmostras").style.display = "none";
		document.getElementById("dataAberturaProposta").style.display = "none";
		document.getElementById("classParticipantes").style.display = "block";		
		document.getElementById("condEntrega").innerHTML = "Condi&ccedil;&otilde;es de Entrega e/ou Retirada:";
		// mudando a critica do botao
		document.getElementById("botaoEnviar").href = "javascript:criticaConab();";			
	}else{
		// mostrando os campos das datas
		document.getElementById("dataRecimentoAmostras").style.display = "block";
		document.getElementById("dataAberturaProposta").style.display = "block";
		document.getElementById("classParticipantes").style.display = "none";		
		document.getElementById("condEntrega").innerHTML = "Condi&ccedil;&otilde;es de Entrega:";
		// mudando a critica do botao
		document.getElementById("botaoEnviar").href = "javascript:critica_BBM();";
	}
	
}
	
