function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
		return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);	
		} 
	} 
}

function popupform(myform, windowname, largura, altura) {
	if (! window.focus)return true;
	window.open('', windowname, 'height=' + altura + ',width=' + largura + ',scrollbars=no');
	myform.target=windowname;
	return true;
}

function defineVerField() {
	if (document.images && ver4 == 'L')
	document.forms['Params'].elements['Ver'].value = 'M';	// js1.1 enabled browser
	else document.forms['Params'].elements['Ver'].value = ver4;
}

function check_contato(f) {
	if(f.realname.value.length < 1 ){
		alert("Favor escrever seu nome");
		f.realname.focus(); // put the prompt in the name field 
		return false;
	}
	
	if(f.email.value.length < 1 ){
		alert("Favor informar seu email");
		f.email.focus(); // put the prompt in the name field 
		return false;
	}
	
	if(!check_email(f.email.value)){
		alert("E-mail inválido");
		f.email.focus();
		return false;
	}
	
	if(f.mensagem.value.length < 1 ){
		alert("Favor escrever sua mensagem");
		f.mensagem.focus(); // put the prompt in the name field 
		return false;
	}	
	alert("Email enviado com sucesso! Obrigado!");
}
function troca(over, obj){
	obj.src='/imagem/menu_'+over+'_over.gif';	
}

function voltaTroca(over, obj){
	obj.src='/imagem/menu_'+over+'.gif';	
}
function imgdestaque(foto){
	document.getElementById("foto_destaque").src='/imagem/cases/'+foto+'_grande.jpg';
}

function formataString(campo, mask, event) {
	key = event.keyCode;
	if(key=='0')
	key = event.which;


	if(key==8 || key==39 || key==37 || key==46 || key==9)
		return true;
	string = campo.value;
	i = string.length;

	var maskAux = '';
	k=0;
	for(a=0;a<mask.length;a++) {
		if(mask.charAt(a) == '§' || mask.charAt(a) == '!') {
			if(campo.value.charAt(a)) {
				maskAux += campo.value.charAt(k);
			}
		}
		else if(mask.charAt(a) == '#') {
			if(campo.value.charAt(a) && verificaNumero(campo.value.charAt(a))) {
				maskAux += campo.value.charAt(k);
			}
		}
		else {

			if(campo.value.charAt(a) && campo.value.charAt(a) == mask.charAt(a)) {
				maskAux += mask.charAt(a);
			}
			else if(campo.value.charAt(a)) {
				maskAux += mask.charAt(a);
				k--;
			}
		}
		k++;
	}
	if (i < mask.length) {
		if (mask.charAt(i) == '#') {
			if(!verificaNumeroPress(campo,event))
			{
				return false;
			}
			maskAux += String.fromCharCode(key);
			if(mask.charAt(i+1) != '!' && mask.charAt(i+1) != '§' && mask.charAt(i+1) != '#') {
			  maskAux += mask.charAt(i+1);
			} 
		}
		else if(mask.charAt(i) == '!' || mask.charAt(i) == '§') {

			maskAux += String.fromCharCode(key);
			if(mask.charAt(i+1) != '!' && mask.charAt(i+1) != '§' && mask.charAt(i+1) != '#') {
			  maskAux += mask.charAt(i+1);
			} 
		}
		else {
			if(mask.charAt(i)==String.fromCharCode(key)) {
				maskAux += String.fromCharCode(key);
			}
			else if((i+1)<mask.length && mask.charAt(i+1) == "#") {
				if(verificaNumeroPress(campo,event)) {
					maskAux += mask.charAt(i) + String.fromCharCode(key);
				}
			}
			else if((i+1)<mask.length && (mask.charAt(i+1) == "§" ||mask.charAt(i+1) == "!" )) {
				maskAux += mask.charAt(i) + String.fromCharCode(key);
			}
		}
		campo.value=maskAux;
		try {
///event.keyCode = 0;
			event.preventDefault();
		}
		catch (e) {
//event.charCode = 0;
			event.returnValue = false;
		}

	}
	else return false;
}

function verificaNumeroPress(campo,event) {
code = event.keyCode;
if(code=='0') {
code = event.charCode;
}

codeAux = 0;
if(arguments[2]) {
codeAux = arguments[2].charCodeAt(0);
}

if ( (code < 48 && code != codeAux && code != 8 && code!=39 && code!=37 && code != 9 && code != 46) || (code > 57 ) ) {
try {
///event.keyCode = 0;
event.preventDefault();
}
catch (e) {
//event.charCode = 0;
event.returnValue = false;
}
return false;

}
else {
return true;
}
}
function verificaNumero(valor) {
code = valor.charCodeAt(0);
if ( (code < 48 ) || (code > 57 ) ) {
return false;
}
return true;
}