// JavaScript Document

function mostrarCategoria(id)

{

	if(document.getElementById('cat'+id).style.display == "none")

	{

		document.getElementById('cat'+id).style.display = "block";

	} else

	{

		document.getElementById('cat'+id).style.display = "none";

	}

}

function mostrarCategoriaSup(id)

{

	if(document.getElementById('catsup'+id).style.display == "none")

	{

		document.getElementById('catsup'+id).style.display = "block";

	} else

	{

		document.getElementById('catsup'+id).style.display = "none";

	}

}

function mostrarResposta(id)

{

	if(document.getElementById('resposta'+id).style.display == "none")

	{

		document.getElementById('resposta'+id).style.display = "block";

	} else

	{

		document.getElementById('resposta'+id).style.display = "none";

	}

}

function ampliarImagem(id, alvo, pasta)

{

	if(document.getElementById(alvo))

	{

		var objFotoGrande	= document.getElementById(alvo);

		var imagem 			= pasta + "/" + id + "g.jpg";

		objFotoGrande.src	= imagem;

	} else

	{

		alert("Imagem não encontrada!");

	}

}

function popupImagem(id)

{

	window.open("popup.php?" + id, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=50,height=50");

}

function popupImagemCaracteristica(id)

{

	window.open("produtos-caracteristicas.php?" + id, "", "resizable=yes,toolbar=no,status=no,menubar=no,maximize=yes,scrollbars=yes,width=100,height=100");

}

function popupVideo(id)

{

	window.open(id, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=380,height=290");

}

function validarFornecedores()

{

	var campos_input = new Array("razao", "cidade", "telefone", "fax", "email_vendas", "cnpj", "inscr_estadual", "ramo_atividade", "produtos");

	var campos_select = new Array("estado");

	var mensagem = "É obrigatório o preenchimento de alguns campos!";

	

	if(!isEmail(document.getElementById("email_vendas").value)) {

		alert("O campo email não está preenchido corretamente!");

		document.getElementById("email_vendas").focus();

		return false; 

	}

	for(i=0; i<campos_input.length; i++)

	{

		if(document.getElementById(campos_input[i]).value.length < 4)

		{

			alert(mensagem);

			document.getElementById(campos_input[i]).focus();

			return false;

			break;

		}

	}

	for(i=0; i<campos_select.length; i++)

	{

		if(document.getElementById(campos_select[i]).value == "")

		{

			alert(mensagem);

			document.getElementById(campos_select[i]).focus();

			return false;

			break;

		}

	}

	return true;

}

function validarAssistencia()

{

	var campos_input = new Array("empresa", "razao", "contato", "email", "telefone", "rua", "bairro", "cidade", "cod_empresa_compradora", "nota_compra", "data_aquisicao", "modelo", "num_serie", "problema");

	var campos_select = new Array("estado");

	var mensagem = "É obrigatório o preenchimento de todos campos!";

	

	if(document.getElementById("tecnico-email").value == "")

	{

		alert("Selecione um técnico!");

		document.getElementById("tecnico-email").focus();

		return false;	

	}

	if(!isEmail(document.getElementById("email").value)) {

		alert("O campo email não está preenchido corretamente!");

		document.getElementById("email").focus();

		return false; 

	}

	for(i=0; i<campos_input.length; i++)

	{

		if(document.getElementById(campos_input[i]).value.length < 4)

		{

			alert(mensagem);

			document.getElementById(campos_input[i]).focus();

			return false;

			break;

		}

	}

	for(i=0; i<campos_select.length; i++)

	{

		if(document.getElementById(campos_select[i]).value == "")

		{

			alert(mensagem);

			document.getElementById(campos_select[i]).focus();

			return false;

			break;

		}

	}

	return true;

}

function validarFaleConosco()

{

	var campos_input = new Array("nome", "email", "bairro","telefone","cidade", "mensagem");

	var campos_select = new Array("setor", "quemsou", "estado", "pais");

	var mensagem = "É obrigatório o preenchimento de alguns campos!";

	

	if(!isEmail(document.getElementById("email").value)) {

		alert("O campo email não está preenchido corretamente!");

		document.getElementById("email").focus();

		return false; 

	}

	

	var telefone = document.getElementById("telefone").value

		if (telefone='') {

		alert("O campo telefone não está preenchido corretamente!");

		document.getElementById("telefone").focus();

		return false; 

	}

	

	for(i=0; i<campos_input.length; i++)

	{

		if(document.getElementById(campos_input[i]).value.length < 4)

		{

			alert(mensagem);

			document.getElementById(campos_input[i]).focus();

			return false;

			break;

		}

	}

	for(i=0; i<campos_select.length; i++)

	{

		if(document.getElementById(campos_select[i]).value == "")

		{

			alert(mensagem);

			document.getElementById(campos_select[i]).focus();

			return false;

			break;

		}

	}

	return true;

}

function isEmail(string) {

	return (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);

}

function formatTelefone(element, evt)

{

	var separador = '-'; 

	//var sValue = element.value.toString().replace( "-", "" );

	var sValue = element.value;

		sValue = cleanString(sValue, /[!-/:-@[-`{-~]/);

		sValue = cleanString(sValue, /[a-z]/);

		sValue = cleanString(sValue, /[A-Z]/);

		sValue = cleanString(sValue, ' ');

		//sValue = cleanString(sValue, /[0-9]/);



	var sLength = sValue.length < 14 ? sValue.length : 14;

	var sCode = "";

	var i = 0;

	var nTecla = getEvent(evt);

	

	if ((nTecla >= 48 && nTecla <= 57) || nTecla == null)

	{

		sCode = '(';

		while (i < sLength) 

		{

			sCode += sValue.charAt(i);

			i++;

			switch (i)

			{

				case 2:

					sCode += ') ';

					break;

				case 5:

					if (sLength <= 8)

					{

						sCode += '-';

					}

					break;

				case 6:

					if (sLength >= 9)

					{

						sCode += '-';

					}

					break;

			}

		}

		element.value = sCode;

	} else

	{

		if (nTecla == 8)

			return true;

		else

			return false;

	}

}

function getEvent(evt)

{

	if (evt == null)

	{

		return null; // executa ao sair do campo, onBlur

	} else if (evt.which)

	{

		return evt.which; // FF

	} else 

	{

		return evt.keyCode; // Opera e IE

	}

}

function cleanString(value, pattern)

{

	var total = value.length;

	var i;

	

	for (i = 0; i <= total; i++)

	{

		value = value.toString().replace(pattern, "");

	}

	

	return value;

}