function comboChange(comoBox,usado){
  window.open( comoBox.options[comoBox.selectedIndex].value);
  if (usado) comoBox.selectedIndex=0;

}
function replace(TXT, strProc, strTroc ){
	var tamStrProc = strProc.length
	var posStrProc = 0
	var str = TXT
	while (str.indexOf(strProc) >= 0){
		posStrProc = str.indexOf(strProc)
		str = str.substring(0,posStrProc) + strTroc + str.substring(posStrProc+tamStrProc,str.length)
		}
	return str
	}


function str2num(str){
	var temp
	temp = str
	if(trim(temp) == ""){
		return 0;
		}
	else{
		temp = replace(temp,".", "")
		temp = replace(temp,",", ".")		
		if(isNaN(temp)){			
			return 0;
			}
		else{

			temp -= 0
			return temp
			}
		}
	}


function trim(str){
if (str !=  ""){
	while (str.indexOf(" ") == 0 || str.indexOf("\n") == 1 || str.lastIndexOf(" ") == str.length -1 || str.lastIndexOf("\n") == str.length-1){
	if (str !=  " "){
			if (str.lastIndexOf(" ") == str.length - 1){
				str = str.substring(0, str.length-1)
				}
			else{
				if (str.lastIndexOf("\n") == str.length-1){
					str = str.substring(0, str.length-2)
					}
				else{
					if (str.indexOf(" ") == 0){
						str = str.substring(1,str.length)
						}
					else{
						if (str.indexOf("\n") == 1){
							str = str.substring(2,str.length)
							}				
						}
					}
				}
			}
		else{
			return ""
			}
		}
	}
return str
}

function isdate(data){
var dia, mes, ano, maxDiames
if (data.length != 10){
	return false;
	}
else{
	if (data.indexOf("/")!= 2 ||  data.indexOf("/",3)!= 5){
		return false;
		}
	else{
		dia = data.substring(0,2);	mes = data.substring(3,5);	ano = data.substring(6,10)
		if (mes < 1 || mes > 12 || dia < 1 || ano < 1900){
			return false
			}
		else{
			if (mes == 1 || mes == 3  || mes == 5  || mes == 7  || mes == 8 || mes == 10 || mes == 12){
				maxDiames = 31;
				}
			if (mes == 4 || mes == 6 || mes == 9 || mes == 11){
				maxDiames = 30;
				}
			if (mes == 2){ 
				if ((ano % 4) == 0){
					maxDiames = 29;
					}
				else{
					maxDiames = 28;
					}
				}
			if (dia <= maxDiames){
				return true;
				}
			else{
				return false;
				}
			}
		}
	}
}

function validaForm(formulario){
var elemntos, contador, resposta
elementos = formulario.length
mensagem = ""

for (contador = 0; contador < elementos; contador++){//loop do primeiro ao ultimo elemento do formulário
	if(formulario.elements[contador].className.length > 1){ //verifica se pode ser vazio (tamanho >1)
		if (trim(formulario.elements[contador].value) != ""){ //verifica se o campo não está preenchido			
			if (formulario.elements[contador].className.substring(1,2) == "2"){ //verifica se o campo é numero (classe2)
				if (isNaN(formulario.elements[contador].value)){//verifica se isnan
					mensagem = mensagem + "- " +  formulario.elements[contador].id + "-  você deve preencher com valor numérico"+ "\n"
					}
				}
			if (formulario.elements[contador].className.substring(1,2) == "3"){ //verifica se o campo é Data (classe3)
				if (!isdate(formulario.elements[contador].value)){//valida o é data válida
					mensagem = mensagem + "- " +  formulario.elements[contador].id + "-  você deve preencher com uma data válida"+ "\n"
					}
				}
			}
		else{
			mensagem = mensagem + "- " +  formulario.elements[contador].id + "-  Não preenchido"+ "\n"
			}			
		}	
	else{ 
		if (trim(formulario.elements[contador].value) != ""){ //verifica se o campo não está preenchido			
			if (formulario.elements[contador].className == "2"){ //verifica se o campo é numero (classe2)
				if (isNaN(formulario.elements[contador].value)){//valida o campo
					mensagem = mensagem + "- " +  formulario.elements[contador].id + "-  você deve preencher com valor numérico"+ "\n"
					}
				}
			if (formulario.elements[contador].className == "3"){ //verifica se o campo é Data (classe3)
				if (!isdate(formulario.elements[contador].value)){//valida o campo
					mensagem = mensagem + "- " +  formulario.elements[contador].id + "-  você deve preencher com uma data válida"+ "\n"
					}
				}
			}
		}
	}
	
if (mensagem != ""){
	alert("ocorreram erros nos seguintes campos:\n\n" + mensagem + "\n\n Os dados não foram enviados!")
	return false
	}
else{
	return true
	}

}

function removeCaracter(texto, caracter){
if (texto.length > 0){
	while( texto.indexOf(caracter, 0)!= -1){
		if (texto.indexOf(caracter, 0) == 0){
			texto = texto.substring(1,texto.length)		
			} 
		else{
			texto = texto.substring(0, texto.indexOf(caracter, 0)) + texto.substring((texto.indexOf(caracter, 0)+1), texto.length)   
			}
		}
	}
return texto;
}

function IniciaMascaraInteiro(xcampo){
	var campo = eval(xcampo)
	var novoValor = "", i = 0
	var ncasas = 0
	valor = removeCaracter(campo.value, ",")
	valor = removeCaracter(valor, ".")
	
	if (valor.length > 3){
		if (valor.length > 6){
			if (valor.length > 9){
				novoValor = valor.substring(0,valor.length-9) + "." + valor.substring(valor.length-9,valor.length-6) + "." + valor.substring(valor.length-6,valor.length-3)  + "." + valor.substring(valor.length-3,valor.length)
				}
			else{
				novoValor = valor.substring(0,valor.length-6) + "." + valor.substring(valor.length-6,valor.length-3) + "." + valor.substring(valor.length-3,valor.length)
				}
			}
		else{
			novoValor = valor.substring(0,valor.length-3) + "." + valor.substring(valor.length-3,valor.length)
			}
		}
	else{
		novoValor = valor;
		}
	campo.value = novoValor
	xtmp = setTimeout("IniciaMascaraInteiro('"+xcampo+"')",10)
}


function IniciaMascaraNumero(xcampo, cDecimal){
	var campo = eval(xcampo)
	valor = removeCaracter(campo.value, ",")
	if (valor.length > cDecimal){
		valor = valor.substring(0, valor.length - cDecimal) + "," + valor.substring(valor.length - cDecimal, valor.length)
		}
	campo.value = valor
	xtmp = setTimeout("IniciaMascaraNumero('"+xcampo+"',"+cDecimal+")",10)
}


function TerminaMascara(){
	clearTimeout(xtmp)
}

function IniciaMascaraData(xcampo){
var campo = eval(xcampo)
valor = removeCaracter(campo.value, "/")
if (valor.length >= 3){
	if (valor.length >= 5){
		valor = valor.substring(0, 2) + "/" + valor.substring(2, 4) + "/" + valor.substring(4, valor.length)
		}
	else{
		valor = valor.substring(0, 2) + "/" + valor.substring(2, valor.length)
		}
	}
campo.value = valor
xtmp = setTimeout("IniciaMascaraData('"+xcampo+"')",10)
}



//classe1 texto
//classe2 numero 
//classe3 data

