//abre o site com efeito

$(document).ready(function(){

	//$("#lateralEsquerda").fadeIn(800);

	//$("#conteudo").fadeIn(800);

});

//verifica o navegador

var IE = (navigator.userAgent.indexOf('MSIE') > -1);



//marcarMenuUrl(): marca um item do menu do topo de acordo com a pasta indicada na url

// - indiceURL: nº da pasta da url que contem o mesmo nome da Id a marcar

var itemMarcado;

function marcarMenuUrl(indiceURL){

	//itemMarcado = location.href.split('/')[indiceURL];

	itemMarcado = location.href.substring(location.href.lastIndexOf('/')+1, location.href.lastIndexOf('.'));

	if(itemMarcado == '' || itemMarcado == 'index.php')

		itemMarcado = 'home';

	var m = document.getElementById(itemMarcado);

	if(m)

		m.className = 'menuMarcado';

}



function enviarAmigo(){

	/*var f = document.getElementById('envieAmigo');

	if (document.title.indexOf('#') > - 1)

		f.linkNome.value = document.title.substring(document.title.lastIndexOf("- ") + 1, document.title.indexOf('#'));

	else

		f.linkNome.value = document.title.substring(document.title.lastIndexOf("- ") + 1);

	

	f.url.value = location.href.substr(location.href.indexOf('.br') + 3);

	f.submit();*/

	if (document.title.indexOf('#') > - 1)

		var linkNome = document.title.substring(document.title.lastIndexOf("- ") + 1, document.title.indexOf('#'));

	else

		var linkNome = document.title.substring(document.title.lastIndexOf("- ") + 1);

	

	var url = location.href.substr(location.href.indexOf('.br') + 3);

		

	

	abrirPopup('/envie_amigo/envie_amigo.php?linkNome='+linkNome+'&url='+url+'',500,600, 'yes');

}



//amplia uma foto com efeito

//	- nome: nome da foto a monstrar

//	- legenda: legenda da foto a monstrar

function ampliarFoto(nome, legenda){

	var foto;

	foto = new Image();			

	foto.src = '/aplicacoes/fotos/medias/'+nome;

	$("#fotoAmpliada").css('width', '100px');

	if(foto.complete)

	{

		$("#fotoAmpliada").css('width', foto.width);

		$("#fotoAmpliada").html('<a href="javascript:void(0);" onclick="fecharFotoAmpliada();" class="floatRight">X - Fechar</a><br class="clear" /><br /><img src="'+foto.src+'" alt="" /><br />'+legenda);

		$("#fotoAmpliada").fadeIn("600");

	}

	else

	{

		$("#fotoAmpliada").html('<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;Carregando..<br /><br /><br />');

		foto.onload = function(){

			$("#fotoAmpliada").css('width', foto.width);

			$("#fotoAmpliada").html('<a href="javascript:void(0);" onclick="fecharFotoAmpliada();" class="floatRight"><img src="/images/fechar.gif" alt="X - Fechar" ></a><br class="clear" /><br /><img src="'+foto.src+'" alt="" /><br />'+legenda);

			$("#fotoAmpliada").fadeIn("600");

		}

	}

}



function fecharFotoAmpliada(){

	$("#fotoAmpliada").fadeOut('600')

	$("#fotoAmpliada").html('');

}



//mostrarConteudo(): torna um conteudo visível

//	- id: id do conteudo a monstrar

function mostrarConteudo(id){			

	$("#"+id).slideDown(600);

}



//esconderConteudo(): esconde um conteudo

//	- id: id do conteudo a esconder

function esconderConteudo(id){

	$("#"+id).slideUp(600);

}





//trocarConteudo(): troca um conteudo visível por outro

//	-id: id do conteudo a trocar

var visivel = '';

function trocarConteudo(id){

	if(id != visivel){

		if(visivel.length > 0) 

			esconderConteudo(visivel);

	}

	mostrarConteudo(id);

	visivel = id;

}



//trocarConteudo2(): troca um conteudo visível por outro (função igual a anterior, utilizada para trocar conteudos um dentro do outro)

//	-id: id do conteudo a trocar

var visivel2 = '';

function trocarConteudo2(id){

	if(id != visivel2){

		if(visivel2.length > 0) 

			esconderConteudo(visivel2);

	}

	mostrarConteudo(id);

	visivel2 = id;

}



//trocarConteudoClique(): troca um conteudo visível por outro. caso clique no conteudo que ja esteje visivel, esconde ele

//	-id: id do conteudo a trocar

function trocarConteudoClique(id){	

	if(visivel.length > 0) 		

		esconderConteudo(visivel);

	if(visivel != id){

		mostrarConteudo(id);

		visivel = id;

	}else{

		visivel = '';

	}

}



//linkCombo(): linka um combo

//	- idCombo: id do combo a linkar

function linkCombo(idCombo){

	location.href = document.getElementById(idCombo).value;

}



//marcarCombo(): marca um combo, caso algum dos seus options contenham a url no seu value

//	- idCombo: id do combo a marcar

function marcarCombo(idCombo){	

	var opts = document.form[idCombo].options;	

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

		if(location.href.indexOf(opts[i].value) > -1){

			opts[i].selected = true;

			break;

		}

	}

}





//abrirPopup(): abre uma popup

//	- url: caminho da janela a abrir

//	- width: width da popup

//	- height: height da popup

//  - scroll(opcional): se a pop-up terá scroll

function abrirPopup(url, width, height,scroll){

	var parametro = 'width=' + width + ', height=' + height;

	if(scroll)

		parametro += ', scrollbars =' + scroll;	

	window.open(url, '', parametro);

}



//função para limpar o form

function resetarForm(){

	if (!confirm("Deseja realmente limpar todos os dados do formulário?")) return;

	var campos = document.getElementById('form').elements;	

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

		if((campos[i].type.toUpperCase() == "TEXT") || (campos[i].type.toUpperCase() == "TEXTAREA"))

			campos[i].value = "";

		if(campos[i].type.toUpperCase() == "CHECKBOX")

			campos[i].checked = false;

		if(campos[i].type.toUpperCase() == "SELECT-ONE")

			campos[i].value = "";

		if(campos[i].type.toUpperCase() == "PASSWORD")

			campos[i].value = "";

		if(campos[i].type.toUpperCase() == "FILE"){

			campos[i].value = "";

			if (IE)

				campos[i].outerHTML = campos[i].outerHTML

		}

	}

}



/* Retira a borda dos flashes

Copyright 2006 Adobe Systems, Inc. All rights reserved.

Versão compacta, alterada por Renato Herculano

	- src, width e height são obrigatórios

	- os demais parametros são opcionais

*/

function flash(src, width, height, id, flashVars, wmode, menu, scale){

	var ret = GetArguments(src, width, height, id, flashVars, wmode, menu, scale);

	var str = '<object ';

	for (var i in ret.objAttrs)

		str += i + '="' + ret.objAttrs[i] + '" ';

	str += '>';

	for (var i in ret.params)

		str += '<param name="' + i + '" value="' + ret.params[i] + '" /> ';

	str += '</object>';

	document.write(str);

}



//GetArguments(): função auxiliar para retirar a borda dos flashes

//	- retorna os argumentos da tag object e os parametros

function GetArguments(src, w, h, id, flashVars, wmode, menu, scale){

	var ret = new Object();

	ret.params = new Object();

	ret.objAttrs = new Object();



	ret.objAttrs['data'] = ret.params['movie'] = src;

	ret.objAttrs['width'] = w;

	ret.objAttrs['height'] = h;

	ret.params['quality'] = 'high';

	ret.objAttrs['type'] = 'application/x-shockwave-flash';

	ret.params['menu'] = 'false';

	

	if(id) ret.objAttrs['id'] = id;



	if(flashVars) ret.params['flashVars'] = flashVars;

	

	ret.params['wmode'] = (wmode)? wmode : 'transparent';

	ret.params['scale'] = (scale)? scale : 'exactfit';

	ret.params['menu'] = (menu)? menu : 'false';

	

	return ret;

}



//Funções utilizadas em formulários



//bloqueia a entrada de caracteres

//utilização no form onkeypress="return(dt(this, event))";

function dt(fld, e){

	
	var strCheck = '0123456789';// lista os caracteres que serao aceitos

	var whichCode = (window.Event) ? e.which : e.keyCode;

	if ((whichCode == 13) || (whichCode == 8) || (whichCode == 0))  return true;  // libera Enter e backspace
	
	else if (fld.id == "cnpj"){ //Se o campo for CNPJ, ele utiliza a regra de formatação específica
		formataCNPJ("cnpj");
	}
	
	else if (fld.id == "telefone"){ //Se o campo for telefone, ele utiliza a regra de formatação específica
		formataTel("telefone");
	}
	
	else if (fld.id == "telres"){ //Se o campo for telefone, ele utiliza a regra de formatação específica
		formataTel("telres");
	}
	
	else if (fld.id == "telcel"){ //Se o campo for telefone, ele utiliza a regra de formatação específica
		formataTel("telcel");
	}

	if (navigator.appName == "Microsoft Internet Explorer"){
		key = String.fromCharCode(e.keyCode);  // Get key value from key code
	}
	
	else{
		key = String.fromCharCode(whichCode);  // Get key value from key code
	}

	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function mascara(o,f){
	v_obj=o;
	//v_fun=f;
	setTimeout("execmascara()",1);
}

function execmascara(){
	v_obj.value=soDig(v_obj.value);
}

function soDig(v){
	v=v.replace(/\D/g,"");                //Remove tudo o que não é dígito
	return v;
}



//formataData(): foramata um campo input no formato 00/00/0000

// - campo: id do campo a formatar

function formataData(campo){

	if (document.getElementById(campo).value.length == 2 || document.getElementById(campo).value.length == 5){

		valorData = document.getElementById(campo).value+ "/";

		document.getElementById(campo).value= valorData;

	}

}



//formataCep(): foramata um campo input no formato 00000-000

// - campo: id do campo a formatar

function formataCep(campo){

	if (document.getElementById(campo).value.length == 5){

		valorCep = document.getElementById(campo).value+ "-";

		document.getElementById(campo).value= valorCep;

	}

}



//formataTel(): foramata um campo input no formato (00)0000-0000

// - campo: id do campo a formatar

function formataTel(campo){

	if(document.getElementById(campo).value == ''){

		valorTel = "(" + document.getElementById(campo).value;

		document.getElementById(campo).value = valorTel;

	}

	if(document.getElementById(campo).value.length == 3){

		valorTel = document.getElementById(campo).value+ ")";

		document.getElementById(campo).value = valorTel;

	}

	if(document.getElementById(campo).value.length == 8){

		valorTel = document.getElementById(campo).value+ "-";

		document.getElementById(campo).value = valorTel;

	}

	if(document.getElementById(campo).value.length == 1 && document.getElementById(campo).value.indexOf('(') < 0){

		valorTel = "(" + document.getElementById(campo).value;

		document.getElementById(campo).value = valorTel;

	}

}



//formataCep(): foramata um campo input no formato 00000-000

// - campo: id do campo a formatar

function formataCNPJ(campo){

	if(document.getElementById(campo).value.length == 2 || document.getElementById(campo).value.length == 6){

		str = document.getElementById(campo).value + ".";

		document.getElementById(campo).value = str;

	}

	if(document.getElementById(campo).value.length == 10){

		str = document.getElementById(campo).value+ "/";

		document.getElementById(campo).value = str;

	}

	if(document.getElementById(campo).value.length == 15){

		str = document.getElementById(campo).value+ "-";

		document.getElementById(campo).value = str;

	}

}