// Abrir Janela
function fotosVeiculo(idVeiculo,modVeiculo,revVeiculo) { 
	newJanela = window.open ("fotoscarro.php?idVeiculo=" + idVeiculo + "&modVeiculo=" + modVeiculo + "&revVeiculo=" + revVeiculo, "fotoscarro", "left=10,top=10,width=625,height=372,resizable=0")
	newJanela.focus()
} 

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// MENU LATERAL
function MLovr(src) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = "#ff9900";
//		src.bgColor = "#999999";
		src.style.color = "#ffffff";
	}
}

function MLovr3(src) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = "#E9E9E9";
//		src.bgColor = "#999999";
		src.style.color = "#ff9900";
//		src.style.color = "#ffffff";
	}
}

function MLovr2	(src) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
//		src.bgColor = "#FFDFCE";
		src.bgColor = "#E9E9E9";
		src.style.color = "#ff9900";
	}
}

function MLout(src) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = "#f6f6f6";
		src.style.color = "#333333";
	}
}
function ML_goToURL() {
	var i, args=ML_goToURL.arguments; document.ML_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

// Formulários

function valida_form() {
	if (document.fmbusca.fbusca_preco.selectedIndex != 0) {
		return true;	
	} else {
		if (document.fmbusca.fbusca_marca.selectedIndex == 0) {
			alert('Escolha uma marca por favor!');
			return false;
		} else if (document.fmbusca.fbusca_modelo.selectedIndex == 0) {
			alert('Escolha um modelo por favor!');
			return false;
		}
	}
}

function validacpf (CPF) {
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999"|| CPF == "12345678909") {
		return false;
	}
	soma = 0;
	for (i=0; i < 9; i ++) {
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	}
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11) {
		resto = 0;
	}
	if (resto != parseInt(CPF.charAt(9))) {
		return false;
	}
	soma = 0;
	for (i = 0; i < 10; i ++) {
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	}
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11) {
		resto = 0;
	}
	if (resto != parseInt(CPF.charAt(10))) {
		return false;
	}
	return true;
}

function validaemail(obj) {
	var strMail = new String(obj.value);
	var strValidos = new String("1234567890abcdefghijklmnopqrstuvxwyzABCDEFGHIJKLMNOPQRSTUVXWYZ_-@.");
	var mailOk = 1;
	var kont = 0;

	// Verifica se o e-mail tem no MÍNIMO 5 caracteres (a@b.c)
    if (strMail.length < 5) {
		mailOk = 0;
	}

	// Verificar a existencia de arrobas (@) no e-mail
	kont = 0;
	for (i = 0; i < strMail.length; i++) {
		if (strMail.charAt(i) == "@" ) {
			kont++;
		}
	}
	if (kont != 1 || strMail.charAt(0) == "@" || strMail.charAt(strMail.length-1) == "@") {
		mailOk = 0;
	}
	
	// Verifica a existencia de pontos (.) no e-mail 
	kont = 0;
	for (i = 0; i < strMail.length; i++) {
		if (strMail.charAt(i) == "." ) {
			kont++;
		}
	}
	if (kont < 1 || strMail.charAt(0) == "." || strMail.charAt(strMail.length-1) == ".") {
		mailOk = 0;
	}

	// Verifica se o e-mail tem caracteres inválidos
	kont = 0;
	for (i = 0; i < strMail.length; i++) {
		for (j = 0; j < strValidos.length; j++ ) {
			if (strMail.charAt(i) == strValidos.charAt(j) ) {
				kont++;
			}
		}
	}
	if (kont != strMail.length) {
		mailOk = 0;
	}

	if (mailOk == 0) {
		return false;
	}
	return true;
}

function validanum(obj){
	var str = new String(obj.value);
	var bOk = 1;
	for (i = 0; i < str.length; i++) {
		if ( str.substring(i,i+1) < "0" ||  "9" < str.substring(i,i+1) ) {
			i = str.length;
			bOk = 0;
		}
	}
	if (bOk == 0) {
		return false;
	}
	return true;
}

