
function linhaOver(obj){
	for(i=0;i<=obj.length;i++){
		if(obj[i] !=null){
			obj[i].style.backgroundColor='#F9F9F9';
		}
	}
}

function linhaOut(obj){
	for(i=0;i<=obj.length;i++){
		if(obj[i] !=null){
			obj[i].style.backgroundColor='#DFEDF2';
		}
	}
}
function ver_telefone(idRevenda,idVeiculo){
	ajax = ajaxInit();
	
	if(ajax) {
			document.getElementById("id_telefone").innerHTML = "<img src='loading/loading1.gif' />";
			ajax.open("GET","ver_telefone.php?idRevenda=" + idRevenda + "&idVeiculo=" + idVeiculo, true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {
						
						document.getElementById("id_telefone").innerHTML = ajax.responseText;
						
					}else{	
						alert(ajax.statusText)
					}
				}
			}
			ajax.send(null);
		
	}
	
	}

image = new Image();
image.src = "loading/loading.gif";
function carregaCombo(url, parametro, destino) {
	
	ajax = ajaxInit();
	
	if(ajax) {

			document.getElementById(destino).innerHTML = "<img src='loading/loading.gif' />";
			ajax.open("GET",url + "?codigo=" + parametro, true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {
						
						document.getElementById(destino).innerHTML = ajax.responseText;
						
					}else{	
						alert(ajax.statusText)
					}
				}
			}
			ajax.send(null);
		
	}
}
function collectionToArray(col) {
	a = new Array();
	for (i = 0; i < col.length; i++)
		a[a.length] = col[i];
	return a;
}
function validaGeral(obj){
	
	cinp = obj.getElementsByTagName("input");
	csel = obj.getElementsByTagName("select");
	inp = collectionToArray(cinp);
	sel = collectionToArray(csel);
	inp = inp.concat(sel);
	
	for(i = 0;i<inp.length;i++){
		if(inp[i]){
		
		if (inp[i].className=="obrigatorio"){
			
			if(inp[i].value == "" || inp[i].value == "0"){
				alert("Preencha todos os campos que tenham \"(*)\"!");
				inp[i].focus();
				return false;
			}
		}
		}
	}
	
	return true;

}
function validaCNPJ(val) {

var cnpj = document.getElementById(val).value;

var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;

digitos_iguais = 1;

for (var 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 (var 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)) {

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)) {

return false;
}

return true;
}

else
return false;

}
//Javascript
function checkForm() {
if(validaCNPJ('cnpj') == false ) {
window.alert('CNPJ inválido');
return false;
}
return true;
}


function checaPlanos(nform) {
	//validacao de radio buttons sem saber quantos sao
	marcado = -1
	for (i=0; i<nform.plano.length; i++) {
		if (nform.plano[i].checked) {
			marcado = i
			resposta = nform.plano[i].value
		}
	}
	
	if (marcado == -1) {
		alert("Selecione um plano.");
		nform.plano[0].focus();
		return false;
	} 
		return true;
}