

var ns = document.layers;

var ie = document.all;

var ns6 = (document.getElementById && !document.all);



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_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_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];}

}

function submenu(num) {

	document.getElementById("submenu_quemsomos").style.display = 'none';

	document.getElementById("submenu_servicos").style.display = 'none';

	document.getElementById("submenu_entreemcontato").style.display = 'none';

	if(num==1) {

		document.getElementById("submenu_quemsomos").style.display = 'block';

	} else if(num==2) {

		document.getElementById("submenu_servicos").style.display = 'block';

	} else if(num==3) {

		document.getElementById("submenu_entreemcontato").style.display = 'block';

	}

}

function volta_submenu(num) {

	timmerID=setTimeout("submenu("+num+")",9000);

}

function ampliar(figura,texto,creditos) {

	url = "janfiguras.php?figura="+figura+"&texto="+texto+"&creditos="+creditos

	window.open(url ,"imagem","resizable,width=500px,height=450px,scrollbars=no")

}

function indique() {

	endereço = escape(window.document.location.href);

	window.open("indique.php?urlpagina="+endereço,"indique","width=380,height=302")

}

function addSWF (URL, WIDTH, HEIGHT, TRANSPARENT) {

	document.write (' <object classid="clsid:27CDB6E-AE6D-11cf-96B8-444553540000" ');

	document.write (' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ');

	document.write (' width="'+ WIDTH +'" height="'+ HEIGHT +'">');

	document.write (' <param name="movie" value="'+ URL +'" />');

	document.write (' <param name="quality" value="high" />');

	if ( TRANSPARENT ) {

		document.write (' <param name="Wmode" value="Transparent" />'); 

	}

	document.write (' <embed src="'+ URL +'" quality="high" ');

	if ( TRANSPARENT ) {

		document.write (' Wmode = "transparent" ');

	}

	document.write (' pluginspage="http://www.macromedia.com/go/getflashplayer" ');

	document.write (' type="application/x-shockwave-flash" width="'+ WIDTH +'" height="'+ HEIGHT +'"></embed> ');

	document.write (' </object>');

}



function centraliza_menu() {

	largura_da_tela = document.body.clientWidth;

	document.all.menu.style.left = parseInt(largura_da_tela / 2)-380;

	if(largura_da_tela<780) {document.all.menu.style.left = "10px";}

	document.all.menu.style.top = "10px";

}



//validação de formulário

function existe(nome_do_campo,f) {  

	if(f=="") { f = document.formulario; }

	for (i=0; i<f.elements.length; i++) {    //faz um loop por todos os campos do formulário

		if (f.elements.item(i).name == nome_do_campo) {  //verifica se o nome do campo é bla bla bla

			return true;

		} 

	}

	return false;

}



function preenchido(campo,f) {

	if(f==null) { f = eval(document.formulario); }

	if(existe(campo,f)) {
		obj = eval("document."+f.name+"."+campo);
		valor = obj.value;

		if(obj.type == "text" || obj.type == "textarea" ) {
			if (valor==""||valor=="Escreva sua mensagem"||valor=="Seu nome"||valor=="Seu email"||valor=="Pesquisar") {
				if(obj.title != "") { nome = obj.title; } else { nome = campo; }
				alert("O campo "+nome+" deve ser preenchido.");
				obj.style.backgroundColor = "#F9F7E3";
				obj.focus();
				return false;

			} 

		}

		if(obj.length > 0) {
			if(obj[0].type == "radio" || obj[0].type == "checkbox") {
				//faz um loop por todos os filhos do elemento e verifica se está preenchido
				for (i=0; i<obj.length; i++) { if (obj.item(i).checked) { return true; } } 
			}
			if(obj.tagName == "SELECT") {		
				if(obj.options[obj.options.selectedIndex].value!="") { return true; }
			}
			if(obj[0].title != null) {
				if(obj[0].title != "") { nome = obj[0].title; } else { nome = campo; }
			} else {
				nome = campo;
			}
			alert("O campo "+nome+" deve ser preenchido.");
			for (i=0; i<obj.length; i++) { obj[i].style.backgroundColor = "#F9F7E3"; }  			
			obj[0].focus();
			return false;
		}

		return true;

	}

}



function validanumero(campo,f) {

	if(f==null) { f = document.formulario; }

	if(existe(campo,f)) {

		obj = eval("document.formulario."+campo);

		valor = obj.value;

		str = "0123456789";	

		result = true;

		for (var i=0;i<valor.length;i++)

			if (str.indexOf(valor.substr(i,1))<0) {

				result = false;

				break;

			}

		if (result==false) {

			alert("Este campo só aceita números!");

			obj.value = "";

			obj.style.backgroundColor = "#F9F7E3";

			obj.focus();

			return false;

		} else {

			return true;

		}

	}

}

function validaemail(campo,f) {

	if(f==null) { f = document.formulario; }

	if(existe(campo,f)) {
		obj = eval("document.formulario."+campo);
		valor = obj.value;
		if (preenchido(campo)) { 
			if ( (valor.length<=5) || (valor.substr(valor.indexOf('@')).indexOf('.') < 3) ) {
				alert("Escreva corretamente seu email.");
				obj.style.backgroundColor = "#F9F7E3";
				obj.focus();
				return false;
	
			} else {
				return true;
			}
		} else {
			return false;
		}
	}
}

function validar(){

	if((preenchido('nome')) &&

	(validaemail('email')) &&

	(preenchido('mensagem'))) {

		document.formulario.submit();

	}

}



function validar_busca(formulario){

	if(formulario==null) { formulario = document.fm_busca; }

	if(preenchido('buscar', formulario)) {

		endereco = formulario.action+"&buscar="+formulario.buscar.value;

		document.location.href=endereco;

	}

}



function validar_indique(){

	if((preenchido('nome')) &&

	(validaemail('email')) &&

	(preenchido('nomeamigo')) &&

	(validaemail('emailamigo'))

	) {

		document.formulario.submit();

	}

}



function limpa_texto (texto,objeto) {

	if(objeto.value==texto){objeto.value='';}

}

function volta_texto (texto,objeto) {

	if(objeto.value==''){objeto.value=texto;}

}

function mostradorflutuante(mostrador,exibe) {

	// define o objeto mostrador

	if (mostrador != "") {

		if (document.layers){mostrador = document.layers[mostrador]; //nn

		} else {

			if (document.all){mostrador = document.all[mostrador]; 

			} else {

				if (document.getElementById){mostrador = document.getElementById(mostrador)}

			}

		}

	}

	if(exibe) {

		mostrador.style.display = "block";

	} else {

		mostrador.style.display = "none";

	}

}

function validar_forum(){

	f=document.formulario;

	email=f.email.value;

	nome=f.nome.value;

	mensagem=f.mensagem.value;

	valido=true;

	if((mensagem == '') || (mensagem == "Escreva sua mensagem")){

		valido=false;

		msg='Você precisa escrever a mensagem!';

		f.mensagem.focus();

	}

	if((email.length<=5) || (email.substr(email.indexOf('@')).indexOf('.') < 2)){

		valido=false;

		msg='Confira o endereço de email!';

		f.email.focus();

	}

	if(nome == '' || (nome == "Seu nome")){

		valido=false;

		msg='Você precisa preencher o nome!';

		f.nome.focus();

	}

	if(valido) {

		f.submit();

	} else { 

		alert(msg);

	}

}





function validar_depoimento(){

	f=document.formulario;

	email=f.email.value;

	nome=f.nome.value;

	mensagem=f.mensagem.value;

	autoriza=f.autoriza.checked;

	valido=true;

	if(autoriza == false){

		valido=false;

		msg='Sem a sua autorização para publicação a mensagem não poderá ser enviada!';

		f.autoriza.focus();

	}

	if((mensagem == '') || (mensagem == "Escreva sua mensagem")){

		valido=false;

		msg='Você precisa escrever a mensagem!';

		f.mensagem.focus();

	}

	if((email.length<=5)|| (email.substr(email.indexOf('@')).indexOf('.') < 2)){

		valido=false;

		msg='Confira o endereço de email!';

		f.email.focus();

	}

	if(nome == '' || (nome == "Seu nome")){

		valido=false;

		msg='Você precisa preencher o nome!';

		f.nome.focus();

	}

	if(valido) {

		f.submit();

	} else { 

		alert(msg);

	}

}

function validar_receba(){

	f=document.formulario;

	email=f.email.value;

	nome=f.nome.value;

	endereco=f.endereco.checked;

	valido=true;

	msg = "";

	if((email.length<=5) || (email.substr(email.indexOf('@')).indexOf('.') < 2)){

		valido=false;

		msg='Confira o endereço de email!';

		f.email.focus();

	}

	if(nome == '' || (nome == "Seu nome")){

		valido=false;

		msg='Você precisa preencher o nome!';

		f.nome.focus();

	}

	if(endereco){

		if(!preenchido(f.rua) || !preenchido(f.numero) || !preenchido(f.bairro) || !preenchido(f.municipio) || !preenchido(f.estado) || !preenchido(f.cep)) {

		valido=false;

		}

	}

	if(valido) {

		f.submit();

	} else { 

		if(msg != "")

		alert(msg);

	}

}

function validar_sua_ideia(){

	f=document.formulario;

	email=f.email.value;

	nome=f.nome.value;

	ideia=f.ideia.value;

	valido=true;

	msg = "";

	if(!preenchido(f.rua) || !preenchido(f.numero) || !preenchido(f.bairro) || !preenchido(f.municipio) || !preenchido(f.estado) || !preenchido(f.cep) || !preenchido(f.telefone)) {

	valido=false;

	} else {

		if(ideia == ''){

			valido=false;

			msg='Você ainda não escreveu sua idéia';

			f.ideia.focus();

		}

	}

	if((email.length<=5) || (email.substr(email.indexOf('@')).indexOf('.') < 2)){

		valido=false;

		msg='Confira o endereço de email!';

		f.email.focus();

	}

	if(nome == '' || (nome == "Seu nome")){

		valido=false;

		msg='Você precisa preencher o nome!';

		f.nome.focus();

	}

	if(valido) {

		f.submit();

	} else { 

		if(msg != "")

		alert(msg);

	}

}

function loja_amplia_foto(cod,largura,altura) {

	window.open("loja_amplia_foto.php?cod="+cod,"loja_amplia_foto","width="+largura+",height="+altura)

}



function pega_obj(nome) {

	if (document.layers) { nome = document.layers[nome]; } //nn

	else { if (document.all) { nome = document.all[nome]; } //ie6

	else { if (document.getElementById) { nome = document.getElementById(nome) } } } //ff

	return nome;

}



function zoom(acao,estilo) {

	var isIE = (/\bmsie\b/i.test(navigator.userAgent) // é Internet Explorer?

							&& document.all && !(/\bopera\b/i.test(navigator.userAgent)));

	// propriedades que mudam de nome do IE para o Mozilla...

	var nome_da_regra = isIE ? 'rules' : 'cssRules';

	var no_dom = isIE ? 'owningElement' : 'ownerNode';

	var stl = document.styleSheets;

	for(var i = 0; i < stl.length; i++) { // para cada elemento de estilo na página

		for(var g = 0; g < stl[i][nome_da_regra].length; g++) { // para cada regra desse elemento

			if(stl[i][nome_da_regra][g].selectorText == estilo) {

				fontSize = parseInt(stl[i][nome_da_regra][g].style.fontSize);

				if(!isNaN( fontSize ) ){

					if(fontSize < 18 && acao == '+') {

						stl[i][nome_da_regra][g].style.fontSize = fontSize+1;

					}

					if(fontSize > 8 && fontSize < 20 && acao == '-') {

						stl[i][nome_da_regra][g].style.fontSize = fontSize-1;

					}

				}

			}

		}

	}

}

function altura_camada(obj,altura) {

	obj = pega_obj(obj);

	obj.style.height = altura+"px";

}



function menuContexto(e,camada) {

	if(e.button==2) {

		posMouse(e);

		pega_obj(camada).style.display='block';

		pega_obj(camada).style.left= (posx+1)+'px';

		pega_obj(camada).style.top= (posy+1)+'px';

  }

}



function posMouse(e){

  if(ie){

    posx = event.clientX;

    posy = event.clientY;

  } else if (ns) {

    posx = e.x;

    posy = e.y;

  } else if (ns6) {

    posx = e.clientX;

    posy = e.clientY;

  }

}



function urlDecode(string, overwrite){
    if(!string || !string.length){
        return {};
    }
    var obj = {};
    var pairs = string.split('&');
    var pair, name, value;
    var lsRegExp = /\+/g;
    for(var i = 0, len = pairs.length; i < len; i++){
        pair = pairs[i].split('=');
        name = unescape(pair[0]);
        value = unescape(pair[1]).replace(lsRegExp, " ");
        //value = decodeURIComponent(pair[1]).replace(lsRegExp, " ");
        if(overwrite !== true){
            if(typeof obj[name] == "undefined"){
                obj[name] = value;
            }else if(typeof obj[name] == "string"){
                obj[name] = [obj[name]];
                obj[name].push(value);
            }else{
                obj[name].push(value);
            }
        }else{
            obj[name] = value;
        }
    }
    return obj;
}


function jsGet(param)
{
	var wl = window.location.href;
	var params = urlDecode(wl.substring(wl.indexOf("?")+1));
	return(params[param]);
}
