// JavaScript Document

function func_loadImgs() {
	imgs = new Array ("/site/_img/gif/bt_menu_top_home1.gif",
					  "/site/_img/gif/bt_menu_top_empresa1.gif",
					  "/site/_img/gif/bt_menu_top_produtos1.gif",
					  "/site/_img/gif/bt_menu_top_noticias1.gif",
					  "/site/_img/gif/bt_menu_top_newsletter1.gif",
					  "/site/_img/gif/bt_menu_top_downloads1.gif",
					  "/site/_img/gif/bt_menu_top_contato1.gif",
					  "/site/_img/gif/tit_contato_fale_conosco1.gif",
					  "/site/_img/gif/tit_contato_vendas1.gif",
					  "/site/_img/gif/tit_contato_suporte1.gif",
					  "/site/_img/gif/tit_contato_suporte1.gif");
	for (i=0; i<imgs.length; i++){
		eval ("img"+i+"= new Image();");
		eval ("img"+i+".src = '"+imgs[i]+"';");
	}
}

function func_swapImg (id, path){
	document.getElementById(id).src = path;
}

function swapTituloMenuClass (titulo){
	d = document;
	menus = Array ("menu_gravo", "menu_gravo_telecom", "menu_samsung");
	for (i=0; i<menus.length; i++){
		if ((i+1) == titulo){
			d.getElementById(menus[i]).className = "menu_tit_over";
			func_swapImg (menus[i]+"_seta", "/site/_img/gif/seta_menu_titulo1.gif")
		} else {
			d.getElementById(menus[i]).className = "menu_tit_out";
			func_swapImg (menus[i]+"_seta", "/site/_img/gif/seta_menu_titulo.gif")
		}
	}
}

function openMenu (menu){
	d = document;
	totalMenus = 3;
	for (i=1; i<=totalMenus; i++){
		if (i==menu){
			d.getElementById("submenu_gravo_"+i).style.display = '';
		} else {
			d.getElementById("submenu_gravo_"+i).style.display = 'none';
		}
	}
}

function showVendasForm (formID) {
	d = document;
	if (formID == "pf"){
		d.getElementById("pf").style.display = '';
		d.getElementById("pj").style.display = 'none';
	} else if (formID == "pj"){
		d.getElementById("pj").style.display = '';
		d.getElementById("pf").style.display = 'none';
	}
}

function func_enviaFormNews(){
	
	if(document.form1.nome.value == ""){
		
		alert('Preencha o campo Nome')
		
		document.form1.nome.focus()
		
		return false
		
	}
	
	//verifica caracteres especiais
	var t = verifica_caracteres(document.form1.nome.value)
	
	if(t == false){
		return false;
	}
	
	
	if(document.form1.email.value == ""){
		
		alert('Preencha o campo E-mail')
		
		document.form1.email.focus()
		
		return false
		
	}
	
	//valida Email
	var ss = validaEmail(document.form1.email);
	if (ss==false){
		return false;
	}
	
	//verifica caracteres especiais
	var t2 = verifica_caracteres(document.form1.email.value)
	
	if(t2 == false){
		return false;
	}
	
	if(document.form1.cmpEmail.value == ""){
		
		alert('Preencha o campo E-mail de confirmação')
		
		document.form1.cmpEmail.focus()
		
		return false
		
	}
	
	//valida Email
	var ss = validaEmail(document.form1.cmpEmail);
	if (ss==false){
		return false;
	}
	
	//verifica caracteres especiais
	var t3 = verifica_caracteres(document.form1.cmpEmail.value)
	
	if(t3 == false){
		return false;
	}
	
	if(document.form1.email.value != document.form1.cmpEmail.value){
		
		alert('Email não coincide com o Email de confirmação')
		
		return false
		
	}else{
		
		document.form1.submit()	
		
	}
	
}

function func_mudaCampo(strCampoAtual, strProximoCampo, strValor){
	
	//var tecla = event.keyCode ? event.keyCode : event.charCode ;
	//var tecla = (window.Event) ? event.charCode : event.keyCode;
	
	//alert(tecla)
	
	//if (tecla != 8 && tecla != 0){
	
		if(document.getElementById(strCampoAtual).value.length == strValor){
			
			document.getElementById(strProximoCampo).focus()
		
		}
	
	//}
		
}

function verifica_caracteres(strCampo){
	var strlogin = strCampo;
	
	var caracteres = "',;/<>:?~^]}´`[{=+-)\\\\(*&¨%$#";
	
	caracteres = caracteres + '"';
	
	var result = true;
	
	var ss=0;
	
	for (i = 0; i < caracteres.length; i++){
		
		if(strlogin.indexOf(caracteres.charAt(i)) != -1){
			
			ss=1
			
			var strerror = caracteres.substring(i,i+1);
			
			var result = false;
			
			window.alert("Você digitou o seguinte caracter invalido:" + " " + strerror + " ");
			
			break;
			
			
			
		}
	}
	
	if(ss == 1){
		
		return false;
		alert("false");
		
	}else{
		
		return true;
		alert("true");
		
	}
	
	
	
}


//Script para validacao de email
function validaEmail(email){
	if(email.value == ""){
		alert("informe seu E-mail!!")
		email.focus();
		return false;
	}
		if(email.value.indexOf("@", email.value.indexOf("@") + 1 ) != -1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		return true;
}
