function centerPopup(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}
function abrePopup(url,width,height){
	window.open(''+url+'','','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height+'');
}
function excluirImagemProduto(produto,pg,imagem){
	
confirma = confirm('Tem certeza que deseja excluir esta imagem?');
	if(confirma){
	location.href='produtos_modificar.php?remover=imagem&codProduto='+produto+'&pg='+pg+'&imagem='+imagem;

		}else{
			return false;
}
}
function validaImagem(id){
	var obj = document.getElementById(id);
	
	if (document.form1.image[0].checked == true){
		obj.style.display = "";
		return;
	} 
		
	if (document.form1.image[1].checked == true){
	 	obj.style.display = "none";
		return;
	}
}
function excluirLink(codLink,tituloLink){
	
confirma = confirm('Tem certeza que deseja excluir o link '+tituloLink+' ?');
	if(confirma){
	location.href='links_visualizar.php?codLink='+codLink+'&acao=remover';

		}else{
			return false;
}
}
function excluirEmail(codigo,nome,codCategoria){
	
confirma = confirm('Tem certeza que deseja excluir o email de '+nome+' ?');
	if(confirma){
	location.href='news_cadastros_visualizar.php?codEmail='+codigo+'&acao=remover&codCategoria='+codCategoria;

		}else{
			return false;
}
}

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
/////////////////funcao p/ jump menu//////////////////////
//////////////////////////////////////////////////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//funcao p/ abrir popup no centro do navegador
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll;
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

function bloqueia_alfa(e){
navegador = /msie/i.test(navigator.userAgent);
if (navegador)
	var tecla = event.keyCode;
else
	var tecla = e.which;
	if(tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else{
	if (tecla != 8) // tab
		return false;
	else
		return true;    
	}
}
function formataCampos(e,src, mask) {
	

	evt = /msie/i.test(navigator.userAgent);
	bloqueia_alfa(evt);
		
		var i = src.value.length;
		var saida = mask.substring(0,1);
		var texto = mask.substring(i)
		
		if (texto.substring(0,1) != saida)
		{
		src.value += texto.substring(0,1);
		}
		{
		if (evt < 45 || evt > 57) evt.returnValue = false;
		}
		
}
//////////////////////////////////////////////////////////
////////////////função para as divs///////////////////////
//////////////////////////////////////////////////////////
function MM_reloadPage(init){
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)){
			document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
		}
	} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH){
		location.reload();
	}
}
MM_reloadPage(true);


// ---------------- 
// ---------------- função para exibir/esconder divs
// ---------------- 
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->


////////////////////////////////////////////////
//Função preload das imagens (rollover e rollout)
////////////////////////////////////////////////
//botao etapa carrinho
etp_carr_on = new Image(34,34)
etp_carr_on.src = "imgs/etapa_carrinho_on.jpg"
etp_carr_off = new Image(34,34)
etp_carr_off.src = "imgs/etapa_carrinho_off.jpg"

//botao etapa cadastro
etp_cadt_on = new Image(34,34)
etp_cadt_on.src = "imgs/etapa_cadastro_on.jpg"
etp_cadt_off = new Image(34,34)
etp_cadt_off.src = "imgs/etapa_cadastro_off.jpg"

//botao etapa pagamento
etp_pgto_on = new Image(34,34)
etp_pgto_on.src = "imgs/etapa_pgto_on.jpg"
etp_pgto_off = new Image(34,34)
etp_pgto_off.src = "imgs/etapa_pgto_off.jpg"

//botao etapa confirmar
etp_conf_on = new Image(34,34)
etp_conf_on.src = "imgs/etapa_confirmar_on.jpg"
etp_conf_off = new Image(34,34)
etp_conf_off.src = "imgs/etapa_confirmar_off.jpg"

//botao etapa concluido
etp_conc_on = new Image(34,34)
etp_conc_on.src = "imgs/etapa_concluido_on.jpg"
etp_conc_off = new Image(34,34)
etp_conc_off.src = "imgs/etapa_concluido_off.jpg"



//////////////////////////////
//////////////////////////////
function validaUpload(id){
	var obj = document.getElementById(id);
	
	if (document.form1.sem_imagem[0].checked == true){
		obj.style.display = "none";
		return;
	} 
		
	if (document.form1.sem_imagem[1].checked == true){
	 	obj.style.display = "";
		return;
	}
}
function validaInserir(){
if (document.inserir.email.value==""){
	alert("Por favor, informe o e-mail.");
	document.inserir.email.focus();
	return false; 
	}
if (document.inserir.email.value.indexOf("@") < 0){
	alert("Preencha o campo E-Mail no formato seu@email.com.br")
	document.inserir.email.focus();
	return false;
	}
if (document.inserir.email.value.indexOf(".") < 0){
	alert("Preencha o campo E-Mail no formato seu@email.com.br")
	document.inserir.email.focus();
	return false;
	}
}
function validaModificar(){
if (document.modificar.email.value==""){
	alert("Por favor, informe o e-mail.");
	document.modificar.email.focus();
	return false; 
	}
if (document.modificar.email.value.indexOf("@") < 0){
	alert("Preencha o campo E-Mail no formato seu@email.com.br")
	document.modificar.email.focus();
	return false;
	}
if (document.modificar.email.value.indexOf(".") < 0){
	alert("Preencha o campo E-Mail no formato seu@email.com.br")
	document.modificar.email.focus();
	return false;
	}
}
///////////////////////////////////////////
///funcao para mascara/////////////////////
///////////////////////////////////////////
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}
function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}
function numOnly(v){
    v=v.replace(/\D/g,"")//Remove tudo o que não é dígito
    return v
}
function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}
function Formata(campo,tammax,teclapres,decimal) {
	
	navegador = /msie/i.test(navigator.userAgent);
	
	if (navegador)
		var tecla = teclapres.keyCode;
	else{
		var tecla = teclapres.which;
	}
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
} 

}
//////////////////CONTATO
////////////////////////

function mostra_cpf(){
	document.getElementById("cnpj").style.display = "none";
	document.getElementById("cpf").style.display = "";
}
function mostra_cnpj(){ 
	document.getElementById("cnpj").style.display = "";
	document.getElementById("cpf").style.display = "none";
}
function validaContato(){

	if (document.contatoForm.nome.value==""){
		alert("Por favor, informe o seu nome.");
		document.contatoForm.nome.focus();
		return (false); 
		}
	
	if (document.contatoForm.sou[0].checked == true){
		if (document.contatoForm.cpf.value==""){
			alert("Por favor, informe o seu CPF.");
			document.contatoForm.cpf.focus();
			return (false); 
			}
		}
	if (document.contatoForm.sou[1].checked == true){
		if (document.contatoForm.cnpj.value==""){
			alert("Por favor, informe o seu CNPJ.");
			document.contatoForm.cnpj.focus();
			return (false); 
			}
		}
	
	
	if (document.contatoForm.email.value==""){
		alert("Por favor, informe o seu e-mail.");
		document.contatoForm.email.focus();
		return (false); 
		}
	if (document.contatoForm.email.value.indexOf("@") < 0){
		alert("Preencha o campo E-Mail no formato seu@email.com.br")
		document.contatoForm.email.focus();
		return false;
		}
	if (document.contatoForm.email.value.indexOf(".") < 0){
		alert("Preencha o campo E-Mail no formato seu@email.com.br")
		document.contatoForm.email.focus();
		return false;
		}
	if (document.contatoForm.qtd.value==""){
		alert("Por favor, informe a quantidade de produtos desejada.");
		document.contatoForm.qtd.focus();
		return false;
		} 
	if (document.contatoForm.cidade.value==""){
		alert("Por favor, informe sua cidade.");
		document.contatoForm.cidade.focus();
		return (false);
		}
		
	if (document.contatoForm.estado.value=="escolha"){
		alert("Por favor, informe o seu estado.");
		document.contatoForm.estado.focus();
		return (false); 
		}
	if (document.contatoForm.mensagem.value==""){
		alert("Por favor, poste sua mensagem.");
		document.contatoForm.mensagem.focus();
		return (false); 
		}
}
/////////////////////////////////////////////////
//////////////////***************///////////////
function addImagem(){

	var totalCampos = parseInt(document.getElementById('totalAp').value);
	var idAtual = parseInt(totalCampos + 1);

	var string = '<table width="100%" cellspacing="1" cellpadding="0" id="ap'+idAtual+'" class="formulario">';
	string += 	'<tr>';
    string +=		'<th scope="row" width="120">Imagem</th>';
    string +=		'<td><input name="arquivo[]" type="file" id="arquivo[]" size="35"></td>';
    string +=    '</tr>';
    string +=	 '<tr>';
	string +=	 	'<th scope="row">Comentário</th>';
	string +=		'<td style="border-left:1px solid #FFFFFF; "><textarea name="coment[]" id="comentario" cols="52" rows="5"></textarea><a href="javascript:removerCampo(\'ap'+idAtual+'\');"><img src="images/icone_excluir2.gif" border="0" alt="Excluir Imagem" /></a></td>';
	string +=	 '</tr>';
	string += '</table>';

	document.getElementById('totalAp').value = idAtual;
	var campo = document.getElementById('ap');
	campo.innerHTML =  campo.innerHTML += string;
	//campo.insertAdjacentHTML('BeforeEnd',string);
}
function removerCampo(idCampo){

		var campo = document.getElementById(idCampo);
		var tamanho = campo.rows.length;

		for(var i=0; i < tamanho; i++){
			campo.deleteRow(0);
		}

	navegador = /msie/i.test(navigator.userAgent);

	if(navegador == false){
		campo.innerHTML = ""
	}

}
/////////////////////////////////////////////////
//////////////////***************////////////////
function excluiImagem(codImagem,codCategoria){

		confirma = confirm('Deseja excluir esta imagem?');
	if(confirma){
		location.href='galeria_visualizar.php?codCategoria='+codCategoria+'&codImagem='+codImagem+'&acao=remover';
	}else{
		return false;
	}
}
function alteraStatusS(codImagem,codCategoria,pg){

		confirma = confirm('Deseja mostrar esta imagem na tela de serviços desta categoria?');
	if(confirma){
		location.href='galeria_visualizar.php?codImagem='+codImagem+'&codCategoria='+codCategoria+'&pg='+pg+'&acao=alterarStatusS';
	}else{
		return false;
	}
}
function alteraStatusN(codImagem,codCategoria,pg){

		confirma = confirm('Deseja retirar esta imagem da tela de serviços desta categoria?');
	if(confirma){
		location.href='galeria_visualizar.php?codImagem='+codImagem+'&codCategoria='+codCategoria+'&pg='+pg+'&acao=alterarStatusN';
	}else{
		return false;
	}
}
function excluirServico(codCategoria){

		confirma = confirm('Deseja excluir esta categoria? TODAS as imagem desta categoria serão excluídas!');
	if(confirma){
		location.href='servicos_visualizar.php?&codCategoria='+codCategoria+'&acao=removerServico';
	}else{
		return false;
	}
}

