//-------------------------------------------------------------------------------------------------------
function ad(obj,qtde){
	var i=0;
	var msg=0;
	var id='';
	var desc='';
	if(qtde==1){
		while(i<qtde){
			if(obj.not_cod.checked==true){
				msg=1;
				var flag=0;
				var j=0;
				while(j<=opener.document.form1.noticia.length-1){
					if(opener.document.form1.noticia[j].value==obj.not_cod.value){	flag=1;	}
					j=j+1;
				}
				if(flag==0){
					if(id==''){
						id=obj.not_cod.value;
						desc=obj.not_titulo.value ;
					}else{
						id=id + '|' + obj.not_cod.value;
						desc=desc + '|' + obj.not_titulo.value;
					}
				}
			}
			i++;
		}
	}else{
		while(i<qtde){
			if(obj.not_cod[i].checked==true){
				msg=1;
				var flag=0;
				var j=0;
				while(j<=opener.document.form1.noticia.length-1){
					if (opener.document.form1.noticia[j].value==obj.not_cod[i].value){ 
						flag = 1;	
					}
					j=j+1;
				}
					if(id==''){
						id=obj.not_cod[i].value;
						desc=obj.not_titulo[i].value ;
					}else{
						id=id + '|' + obj.not_cod[i].value;
						desc=desc + '|' + obj.not_titulo[i].value;
					}
			}
			i++;
		}
	}
	if(msg==0){
		alert('É necessário selecionar pelo menos uma opção!!!');
	}else{
		if(id!='') 
			opener.adiciona(id,desc,'noticia');
		self.close();
	}
}

//-----------------------------------------------------------------------------------------------------
function remove(obj,nomeselect,del){
	var flag=false;
	for(var i=0;i<document.getElementById(nomeselect).length;i++){
		if(document.getElementById(nomeselect).options[i].selected==true){
			document.getElementById(nomeselect).options[i] = null;
			flag=true;
			break;
		}
	}
	if(flag) return remove(obj,nomeselect,1);
	if(!flag && del!=1) alert('É necessário selecionar pelo menos um registro para Remover!');
}
//----------------------------------------------------------------------------------------------------
function AtualizaCombo(cod,nome,formulario,campo){
	opener.insere(cod,nome,formulario,campo);
	SetSelect(opener.document.getElementById(campo),cod); 
	self.close();
}
//-----------------------------------------------------------------------------------------------------
function AtualizaComboEdicao(cod,nome,formulario,campo){
	opener.edit(cod,nome,formulario,campo);
	SetSelect(opener.document.getElementById(campo),cod); 
	self.close();
}
//----------------------------------------------------------------------------------------------------
function SetSelect(sel,strOpt){
	if(strOpt=="") return;
	for(var i=0;i<sel.length;i++){
		if(sel.options[i].value==strOpt){
			sel.options[i].selected=true;
			return;
		}
	}
}
// ---------------------------------------------------------------------------------------------------------
function limpar(cp){
	str=cp.value;
	cp.value='';
}
// ---------------------------------------------------------------------------------------------------------
function label(cp){
	if(cp.value==''){ cp.value=str; }
}
// ---------------------------------------------------------------------------------------------------------
function valida(obj){
	mail=obj.email.value;
	if(mail != ""){
		var er=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,3})+$/;
		if(!er.test(mail.toLowerCase())){
			alert('E-mail preenchido de forma inválida!');
			return;
		}
	}
	cad_email(mail);
}
// ---------------------------------------------------------------------------------------------------------
function cad_email(email){
	url="admin/cad_email.php?email="+email;
	popup=window.open(url ,'cad_email', 'width=300, height=150, top=400, left=199, scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
   popup.focus();
}
// ---------------------------------------------------------------------------------------------------------
function deleta(cod,tabela,campo){
	var dir=location.href.substring(0,location.href.lastIndexOf('/')+1);
	var url=location.href.substring(dir.length,location.href.length+1);
	if(confirm("Deseja realmente excluir o Registro?")){
		window.document.location=('../admin/del.php?codg='+cod+'&tabela='+tabela+'&campo='+campo+'&url='+dir+url);
	}
}
// ---------------------------------------------------------------------------------------------------------
function deleta_noticia(cod,tabela,campo){
	var dir=location.href.substring(0,location.href.lastIndexOf('/')+1);
	var url=location.href.substring(dir.length,location.href.length+1);
	if(confirm("Deseja realmente excluir a Noticia?")){
		window.document.location=('../admin/del_not.php?codg='+cod+'&tabela='+tabela+'&campo='+campo+'&url='+dir+url);
	}
}
// ---------------------------------------------------------------------------------------------------------
function deleta_menu(cod,tabela,campo){
	var dir=location.href.substring(0,location.href.lastIndexOf('/')+1);
	var url=location.href.substring(dir.length,location.href.length+1);
	if(confirm("Deseja realmente excluir o Menu?")){
		window.document.location=('../admin/del_menu.php?codg='+cod+'&tabela='+tabela+'&campo='+campo+'&url='+dir+url);
	}
}
// ---------------------------------------------------------------------------------------------------------
function deleta_col(cod,tabela,campo){
	var dir=location.href.substring(0,location.href.lastIndexOf('/')+1);
	var url=location.href.substring(dir.length,location.href.length+1);
	if(confirm("Deseja realmente excluir o Colunista?")){
		window.document.location=('../admin/del_col.php?codg='+cod+'&tabela='+tabela+'&campo='+campo+'&url='+dir+url);
	}
}
// ---------------------------------------------------------------------------------------------------------
function deleta_art(cod,tabela,campo){
	var dir=location.href.substring(0,location.href.lastIndexOf('/')+1);
	var url=location.href.substring(dir.length,location.href.length+1);
	if(confirm("Deseja realmente excluir o Artigo?")){
		window.document.location=('../admin/del_art.php?codg='+cod+'&tabela='+tabela+'&campo='+campo+'&url='+dir+url);
	}
}
// ---------------------------------------------------------------------------------------------------------
function deleta_cid(cod,tabela,campo){
	var dir=location.href.substring(0,location.href.lastIndexOf('/')+1);
	var url=location.href.substring(dir.length,location.href.length+1);
	if(confirm("Deseja realmente excluir a Cidade?")){
		window.document.location=('../admin/del_cid.php?codg='+cod+'&tabela='+tabela+'&campo='+campo+'&url='+dir+url);
	}
}

