function troca_cortinas(idTeste) {
	for(i=1; i<=9; i++) {
		var fuck = document.getElementById(i);
		if (idTeste == i) {
			if (fuck.style.display == "none") {
				fuck.style.display = "block";
			} else {
				fuck.style.display = "none";
			}
		} else {
			fuck.style.display = "none";
		}
	}
}

////JCAROUSEL
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        // Configuration goes here
		scroll: 5,
		wrap: 'both'
    });
	
	jQuery('.nyroSwf').nyroModal({
		type: 'swf',
		forceType: 'swf',
		width: 640,
		height:520,
		url: $(this).attr('href')	
		
	})
	
	jQuery("#album_carousel ul").jcarousel({
			scroll: 3,
			animation: 1000
			
		})

jQuery("#album_carousel .nyroModal").live('click',function(){
			
			var imagem = $(this).attr("href");
			var titulo = $(this).attr("title");
			
			jQuery.nyroModalManual({
				url: imagem,
				title: titulo
			})	
			return false;
		})

	    
});

//validacao

//função para remover espaços do início e fim das strings
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,"");
}

//envia os forms de alteração como excluir ou alterar um ítem da lista.
function submitAlterar(nomeForm, id)
{
	var f = document.forms[nomeForm];
	f.id.value = id;
	f.submit();
}

function buscaMenu(numero) {       

	var menuProd = document.getElementById("menuProd");
	var menuProd2 = document.getElementById("menuProd2");
	var menuLinha = document.getElementById("menuLinha");
	var menuLinha2 = document.getElementById("menuLinha2");
	
	if (numero == 0) {
		menuProd.style.position = "static";
		menuProd2.style.display = "none";
		menuLinha.style.position = "static";
		menuLinha2.style.display = "none";
	} else {
                
                if(document.getElementById("ulAuto").style.display == "none") {
                    menuProd.style.position = "relative";
                    menuProd2.style.display = "";
                    menuLinha.style.position = "relative";
                    menuLinha2.style.display = "";
                }
	}
}

function validaLogin() {

	var form = document.login

	if (trim(form.login.value) == "" || form.login.value == 'E-mail'){
		alert("Digite seu E-mail");
		return false
	}
	if (form.login.value.indexOf('@',0)==-1 || form.login.value.indexOf('.',0)==-1){
		alert("E-mail inválido");
		return false
	}
	if (form.senha.value.length < 6) {
		alert("A senha deve conter no mínimo 6 caracteres");
		return false;
	}
}

function validaEspecificacao() {

	var form = document.especificacao

	if (trim(form.email.value) == "" || form.email.value == 'e-mail'){
		alert("Digite seu E-mail");
		return false
	}
	if (form.email.value.indexOf('@',0)==-1 || form.email.value.indexOf('.',0)==-1){
		alert("E-mail inválido");
		return false
	}
}

function validaIndiqueAmigo() {

	var form = document.indiqueAmigo

	if (trim(form.nome.value) == "" || form.nome.value == "seu nome"){
		alert("Digite seu nome");
		return false
	}
	if (trim(form.email.value) == "" || form.email.value == 'seu e-mail'){
		alert("Digite seu E-mail");
		return false
	}
	if (form.email.value.indexOf('@',0)==-1 || form.email.value.indexOf('.',0)==-1){
		alert("E-mail inválido");
		return false
	}
	if (trim(form.nomeAmigo.value) == "" || form.nomeAmigo.value == "nome do amigo"){
		alert("Digite o nome do seu amigo");
		return false
	}
	if (trim(form.emailAmigo.value) == "" || form.emailAmigo.value == 'e-mail do amigo'){
		alert("Digite o email do seu amigo");
		return false
	}
	if (form.emailAmigo.value.indexOf('@',0)==-1 || form.emailAmigo.value.indexOf('.',0)==-1){
		alert("E-mail inválido");
		return false
	}
}

function validaEsqueciSenha() {

	var form = document.esqueciSenha

	if (trim(form.email.value) == ""){
		alert("Digite seu E-mail");
		return false
	}
	if (form.email.value.indexOf('@',0)==-1 || form.email.value.indexOf('.',0)==-1){
		alert("E-mail inválido");
		return false
	}
}

function validaBuscaProdutos() {

	var form = document.buscaProdutos

	if (form.categoria.value == "" && form.linha.value == ""){
		alert("Selecione ao menos um dos campos de busca");
		return false
	}
}

function validaBusca() {

	var form = document.busca

	if (trim(form.palavra.value) == "" || form.palavra.value == 'Palavra-Chave'){
		alert("Digite uma palavra-chave");
		return false
	}
}


function validaTrocarSenha() {

	var form = document.trocarSenha

	if (trim(form.senha.value) == "") {
		alert("Preencha a senha atual");
		return false;
	}
	if (form.senha.value.length < 6) {
		alert("A senha atual possui no mínimo 6 caracteres");
		return false;
	}
	if (trim(form.novaSenha.value) == "") {
		alert("Preencha a nova senha");
		return false;
	}
	if (form.novaSenha.value.length < 6) {
		alert("A nova senha deve conter no mínimo 6 caracteres");
		return false;
	}
	if (trim(form.repSenha.value) == "") {
		alert("Repita a senha");
		return false;
	}
	if (form.novaSenha.value != form.repSenha.value) {
		alert("As senhas digitadas não coincidem");
		return false;
	}
}

function validaAssistencia() {

	var form = document.assistencia

	if (trim(form.nome.value) == "") {
		alert("Preencha o nome");
		return false;
	}
	if (trim(form.email.value) == ""){
		alert("Digite seu E-mail");
		return false
	}
	if (form.email.value.indexOf('@',0)==-1 || form.email.value.indexOf('.',0)==-1){
		alert("E-mail inválido");
		return false
	}
	if (form.telefone.value.length < 12) {
		if(form.telefone.value.length != 0){
		  alert("Telefone inválido");
		}
		return false;
	}
	if (trim(form.descricao.value) == "") {
		alert("Preencha a descrição");
		return false;
	}
}

function validaContato() {

	var form = document.contato

	if (trim(form.nome.value) == "") {
		alert("Preencha o nome");
		return false;
	}
	if (trim(form.empresa.value) == "") {
		alert("Preencha o nome da empresa");
		return false;
	}
	if (trim(form.email.value) == ""){
		alert("Digite seu E-mail");
		return false
	}
	if (form.email.value.indexOf('@',0)==-1 || form.email.value.indexOf('.',0)==-1){
		alert("E-mail inválido");
		return false
	}
	if (trim(form.telefone.value) == "" || form.telefone.value == "55 5555-5555") {
		alert("Preencha o telefone");
		return false;
	}
	if (form.telefone.value.length < 12) {
		alert("Telefone inválido");
		return false;
	}
	if (trim(form.departamento.value) == ""){
		alert("Selecione o departamento");
		return false
	}
	if (trim(form.mensagem.value) == "") {
		alert("Preencha a mensagem");
		return false;
	}
}

function validaPessoa_fisica() {

	var form = document.pessoa_fisica

	if (trim(form.nome.value) == "") {
		alert("Preencha o nome");
		return false;
	}
	if (trim(form.email.value) == ""){
		alert("Digite seu E-mail");
		return false
	}
	if (form.email.value.indexOf('@',0)==-1 || form.email.value.indexOf('.',0)==-1){
		alert("E-mail inv&aacute;lido");
		return false
	}
	if (trim(form.telefone.value) == "" || form.telefone.value == "55 5555-5555") {
		alert("Preencha o telefone");
		return false;
	}
	if (form.telefone.value.length < 12) {
		alert("Telefone inválido");
		return false;
	}
	if (trim(form.endereco.value) == "") {
		alert("Preencha o endereço");
		return false;
	}
	if (trim(form.numero.value) == "") {
		alert("Preencha o número");
		return false;
	}
	if (trim(form.bairro.value) == "") {
		alert("Preencha o bairro");
		return false;
	}
	if (trim(form.cep.value) == "") {
		alert("Preencha o CEP");
		return false;
	}
	if (trim(form.cep.value).length < 9) {
		alert("CEP inválido");
		return false;
	}
	if (trim(form.cidade.value) == "") {
		alert("Preencha a cidade");
		return false;
	}
	if (trim(form.estado.value) == "") {
		alert("Selecione o estado");
		return false;
	}
	if (form.acesso.checked == true) {

		if (trim(form.senha.value) == "") {
			alert("Preencha a senha");
			return false;
		}
		if (form.senha.value.length < 6) {
			alert("A senha deve conter no mínimo 6 caracteres");
			return false;
		}
		if (trim(form.repSenha.value) == "") {
			alert("Repita a senha");
			return false;
		}
		if (form.senha.value != form.repSenha.value) {
			alert("As senhas digitadas não coincidem");
			return false;
		}
	}
}

function validaPessoa_juridica() {

	var form = document.pessoa_juridica

	if (trim(form.razao_social.value) == "") {
		alert("Preencha a razão social");
		return false;
	}
	if (trim(form.nome.value) == "") {
		alert("Preencha o nome");
		return false;
	}
	if (trim(form.cnpj.value) == "") {
		alert("Preencha o CNPJ");
		return false;
	}
	if (form.cnpj.value.length < 18) {
		alert("CNPJ inválido");
		return false;
	}
	if (trim(form.email.value) == ""){
		alert("Digite seu E-mail");
		return false
	}
	if (form.email.value.indexOf('@',0)==-1 || form.email.value.indexOf('.',0)==-1){
		alert("E-mail inv&aacute;lido");
		return false
	}
	if (trim(form.endereco.value) == "") {
		alert("Preencha o endereço");
		return false;
	}
	if (trim(form.numero.value) == "") {
		alert("Preencha o número");
		return false;
	}
	if (trim(form.bairro.value) == "") {
		alert("Preencha o bairro");
		return false;
	}
	if (trim(form.cep.value) == "") {
		alert("Preencha o CEP");
		return false;
	}
	if (form.cep.value.length < 9) {
		alert("CEP inválido");
		return false;
	}
	if (trim(form.telefone.value) == "" || form.telefone.value == "55 5555-5555") {
		alert("Preencha o telefone");
		return false;
	}
	if (form.telefone.value.length < 12) {
		alert("Telefone inválido");
		return false;
	}
	if (trim(form.fax.value) == "" || form.fax.value == "55 5555-5555") {
		alert("Preencha o fax");
		return false;
	}
	if (form.fax.value.length < 12) {
		alert("Fax inválido");
		return false;
	}
	if (trim(form.site.value) == "") {
		alert("Preencha o site");
		return false;
	}
	if (trim(form.cidade.value) == "") {
		alert("Preencha a cidade");
		return false;
	}
	if (trim(form.estado.value) == "") {
		alert("Selecione o estado");
		return false;
	}
	if (form.acesso.checked == true) {

		if (trim(form.senha.value) == "") {
			alert("Preencha a senha");
			return false;
		}
		if (form.senha.value.length < 6) {
			alert("A senha deve conter no mínimo 6 caracteres");
			return false;
		}
		if (trim(form.repSenha.value) == "") {
			alert("Repita a senha");
			return false;
		}
		if (form.senha.value != form.repSenha.value) {
			alert("As senhas digitadas não coincidem");
			return false;
		}
	}
}



















function Mascara(tipo, campo, teclaPress) {

	if (window.event) {

		var tecla = teclaPress.keyCode;

	} else {

		tecla = teclaPress.which;

	}



	var s = new String(campo.value);

	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.

	s = s.replace(/(\.|\(|\)|\/|\-| )+/g, '');



	tam = s.length + 1;



	if (tecla != 9 && tecla != 8) {

		switch (tipo) {

			case 'CPF':

				if (tam > 3 && tam < 7)

					campo.value = s.substr(0, 3) + '.' + s.substr(3, tam);

				if (tam >= 7 && tam < 10)

					campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, tam - 6);

				if (tam >= 10 && tam < 12)

					campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, 3) + '-' + s.substr(9, tam - 9);

				break;



			case 'CNPJ':



				if (!(tecla >= 48 && tecla <= 57)) {

					if (tecla != 0) {

						return false

					}

				} else {



					if (tam > 2 && tam < 6)

						campo.value = s.substr(0, 2) + '.' + s.substr(2, tam);

					if (tam >= 6 && tam < 9)

						campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, tam - 5);

					if (tam >= 9 && tam < 13)

						campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/' + s.substr(8, tam - 8);

					if (tam >= 13 && tam < 15)

						campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/' + s.substr(8, 4) + '-' + s.substr(12, tam - 12);

				}



				break;



			case 'TEL':



				if (!(tecla >= 48 && tecla <= 57)) {

					if (tecla != 0) {

						return false

					}

				} else {

					if (tam > 2 && tam < 4)

						campo.value = s.substr(0, 2) + ' ' + s.substr(2, tam);

					if (tam >= 7 && tam < 11)

						campo.value = s.substr(0, 2) + ' ' + s.substr(2, 4) + '-' + s.substr(6, tam - 6);

				}



				break;



			case 'CEP':



				if (!(tecla >= 48 && tecla <= 57)) {

					if (tecla != 0) {

						return false

					}

				} else {

					if (tam >= 6 && tam < 8)

						campo.value = s.substr(0, 5) + '-' + s.substr(5, tam - 5);

				}



				break;



			case 'DATA':

				if (!(tecla >= 48 && tecla <= 57)) {

					if (tecla != 0) {

						return false

					}

				} else {

					if (tam > 2 && tam < 4)

						campo.value = s.substr(0, 2) + '/' + s.substr(2, tam);

					if (tam > 4 && tam < 11)

						campo.value = s.substr(0, 2) + '/' + s.substr(2, 2) + '/' + s.substr(4, tam - 4);

				}

				break;

		}

	}

}

// funcao que abre as tabelas
function sub1_abre(tabela) {
	tabela = document.getElementById(tabela);
	if (tabela.style.display == "none") {
		tabela.style.display = "block";
	} else {
		tabela.style.display = "none";
	}
}

function troca(tabela,tabela2) {
	tabela = document.getElementById(tabela);
	tabela2 = document.getElementById(tabela2);
	
	if (tabela.style.display == "none" && tabela2.style.display == "block") {
		tabela.style.display = "block";
		tabela2.style.display = "none";
	}
	else {
		if (tabela.style.display == "none") {
			tabela.style.display = "block";
		}
		else {
			tabela.style.display = "none";
		}
	}
}





over = function() {
	var sfEls = document.getElementById("nav").
getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.
replace(new RegExp(" over\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", over);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}
}

//flash
function flash(arquivo, largura, altura)
{
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + largura + "' height='" + altura + "' ID=flashad>")
    document.write("<param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='" + arquivo + "'>")
    document.write("<param name='quality' value='high'><param name='wmode' value='transparent' />")
    document.write("<embed src='" + arquivo + "' quality='best' wmode='transparent'  bgcolor='#ffffff' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + largura + "' height='" + altura + "'></embed>")
    document.write("</object>")
}


function cbxEnviaDados(cbxOri, cbxDest, url, dado) {
    var pars = "?" + cbxOri + "=" + dado;
    url += pars;    
    $("select[name=" + cbxDest + "]").html("<option value=\"\">Carregando...</option>");
    $("select[name=" + cbxDest + "]").load(url);
}

function enviaCep(cep, url){
    if(cep.length > 8 && cep.length < 10){
        var pars = "?cep=" + cep;
	url += pars;        
        $.get(
            url,
            function(endereco){                
                $(endereco).find("dados").each(function(){                    
                    $("input:text[name=endereco]").val($(this).attr("endereco"));
                    $("input:text[name=numero]").val($(this).attr("numero"));
                    $("input:text[name=bairro]").val($(this).attr("bairro"));
                    $("input:text[name=cidade]").val($(this).attr("cidade"));
                    $("select[name=estado]").val($(this).attr("estado"));
                })                
            }
        );
    }
}

function completar(valor, url) {    
    document.getElementById("ulAuto").style.display = "none";
    valor = valor.replace(/ /g,",");
    var pars = "?palavra=" + valor;
    var lis = "";
    url += pars;    
    $.get(
            url,
            function(endereco){                
                $(endereco).find("dados").each(function(){
                    $(this).find("dado").each(function(){
                    lis += "<li><a onClick=\"aceitarSugestao('" + $(this).attr("idItens") + "','" + $(this).attr("tabela") + "','" + $(this).attr("palavra") + "');\"><div class='floatLeft'>" + $(this).attr("palavra") + "</div><div class='floatRight local'>em " + $(this).attr("tabela") + "</div></a></li>";
                    document.getElementById("ulAuto").style.display = "block";
                    })
                })
                $("#ulAuto").html(lis); 
            }
        );
}

function aceitarSugestao(ids, tabela, sugestao) {    
    document.getElementById("ulAuto").style.display = "none";
    var f = document.forms['busca'];
    f.palavra.value = sugestao;
    f.idItens.value = ids;
    f.tabela.value = tabela;
    f.submit();
}

function desaparecerSugestao() {    
    document.getElementById("ulAuto").style.display = "none";
    buscaMenu(1);
    $("#ulAuto").html("");
}



/*function album_carousel(id_projeto) {
	
	////////////ALBUM//////////////////////////////////////////////////////////////////////////
		function album_itemload(carousel, state) {
			// Check if the requested items already exist
			if (carousel.has(carousel.first, carousel.last)) {
				return;
			}
		
			jQuery.get(
				'../xml/album_fotos.php',
				{
					first: carousel.first,
					last: carousel.last,
					projeto: id_projeto
				},
				function(xml) {
					album_additem(carousel, carousel.first, carousel.last, xml);
				},
				'xml'
			);
			
		}
		
		function album_additem(carousel, first, last, xml) {
			// Set the size of the carousel
			carousel.size(parseInt(jQuery('total', xml).text()));
		
			$('image', xml).each(function(i) {
				carousel.add(first + i, album_htmlhelper($(this).find('thumb').text(), $(this).find('imagem').text(), $(this).find('legenda').text(), $(this).find('url').text()));
			});
		};
		
		function album_htmlhelper(thumb, imagem, legenda, url) {
			
			var marcacao = '<a href="' + imagem + '" class="nyroModal" rel="gal" title="'+legenda+'"><img src="'+ thumb +'" alt="" /></a>';
			return marcacao;
			
		};
		
		function album_itemvisivel() {
			
		}
		
		$("#album_carousel ul").jcarousel({
			scroll: 3,
			animation: 1000,
			itemLoadCallback: album_itemload,
			itemFirstInCallback: album_itemvisivel
		})
		
		$("#album_carousel .nyroModal").live('click',function(){
			
			var imagem = $(this).attr("href");
			var titulo = $(this).attr("title");
			
			$.nyroModalManual({
				url: imagem,
				title: titulo
			})	
			return false;
		})
			
}
*/


