//########################################################
//##													##
//##	Autor: DM Tecnologia de Informacao				##
//##													##
//##		Validação de campos gererica				##
//##													##
//########################################################

function FormOk(formulario) {
   var mensagem = '';
   var primeiro = 0;
   for (var i = 0; i < formulario.length; i++) {
       if (formulario.elements[i].getAttribute('erro')) {
          if ((formulario.elements[i].value == '') ||
             (formulario.elements[i].value.length == 0) ||
             (formulario.elements[i].selectedIndex <= 0)
             ) {
             mensagem = mensagem + formulario.elements[i].getAttribute('erro') + "\n";
             // troca a cor da borda do campo
             formulario.elements[i].style.border = '2px solid #f00';
             if (primeiro == 0) { var primeiro = i; }
          }
      }
   }
   if (mensagem != '') {
      formulario.elements[primeiro].focus();
      alert(mensagem);
      return false;
   } else {
       return true;
   }
} 

//########################################################
//##													##
//##	Autor: DM Tecnologia de Informacao				##
//##													##
//##				Ajax gererica						##
//##													##
//########################################################

function get(tI) { // Esta funcao paga o elemento pelo ID
  if (document.getElementById) { return document.getElementById(tI); }
  else if (document.all) { return document.all[tI]; } else return false;
}

function ajax(valor,url,div){ 
	req = null; 
	if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = function() {
			if(req.readyState == 4){
				if (req.status == 200){
					get(div).innerHTML = "Carregando....";
					get(div).innerHTML = req.responseText;
				} else{ 
					alert("Houve um problema ao obter os dados:\n" + req.statusText);
				}
			}
		}
		req.open("GET", url+'?valor='+valor, true); 
		req.send(null);
	} else if (window.ActiveXObject){ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (req){ 
					req.onreadystatechange = function() {
						if(req.readyState == 4){
							if (req.status == 200){
								get(div).innerHTML = "Carregando....";
								get(div).innerHTML = req.responseText;
							} else{ 
								alert("Houve um problema ao obter os dados:\n" + req.statusText);
							}
						}
					}
					req.open("GET", url+'?valor='+valor, true); 
					req.send();
				}
		}
}

///////////////////////////////////////////////////////
//                                                   //
//           By DM Tecnologia de Informação          //
//   												 //
//     Função Para Fazer Filtragem na Listagem       //
//													 //
//			     Area Administratica				 //
///////////////////////////////////////////////////////
function loadXMLDoc6(url,nome,valor){
	req = null; 
	if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange6; 
		req.open("GET", url+'?'+nome+'='+valor, true); 
		req.send(null);
	} else if (window.ActiveXObject){ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (req){ 
					req.onreadystatechange = processReqChange6; 
					req.open("GET", url+'?'+nome+'='+valor, true); 
					req.send();
				}
		}
}

function processReqChange6(){
	if(req.readyState == 4){
		if (req.status == 200){
			document.getElementById('listagem_sub').innerHTML = req.responseText;
		} else{ 
			alert("Houve um problema ao obter os dados:\n" + req.statusText);
		}
	}
}


function listagem_sub(nome,valor){
		loadXMLDoc6("categoria_combo.php",nome,valor);
}

///////////////////////////////////////////////////////
//                                                   //
//           By DM Tecnologia de Informação          //
//   												 //
//     Função Para Fazer Filtragem na Listagem       //
//													 //
//			     Area Administratica				 //
///////////////////////////////////////////////////////
function loadXMLDoc3(url,valor){
	req = null; 
	if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange3; 
		req.open("GET", url+'?id_categoria='+valor, true); 
		req.send(null);
	} else if (window.ActiveXObject){ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (req){ 
					req.onreadystatechange = processReqChange3; 
					req.open("GET", url+'?id_categoria='+valor, true); 
					req.send();
				}
		}
}

function processReqChange3(){
	if(req.readyState == 4){
		if (req.status == 200){
			document.getElementById('listagem').innerHTML = req.responseText;
		} else{ 
			alert("Houve um problema ao obter os dados:\n" + req.statusText);
		}
	}
}


function listagem(valor){
		loadXMLDoc3("subcategoria_combo.php",valor);
}


///////////////////////////////////////////////////////
//                                                   //
//           By DM Tecnologia de Informação          //
//   												 //
//     Função Para Fazer Filtragem na Listagem       //
//													 //
//			     Area Administratica				 //
///////////////////////////////////////////////////////

function loadXMLDoc(url,valor){
	req = null; 
	if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange; 
		req.open("GET", url+'?qtd='+valor, true); 
		req.send(null);
	} else if (window.ActiveXObject){ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (req){ 
					req.onreadystatechange = processReqChange; 
					req.open("GET", url+'?qtd='+valor, true); 
					req.send();
				}
		}
}

function processReqChange(){
	if(req.readyState == 4){
		if (req.status == 200){
			document.getElementById('imagens').innerHTML = req.responseText;
		} else{ 
			alert("Houve um problema ao obter os dados:\n" + req.statusText);
		}
	}
}


function upQtdFotos(valor){
		document.getElementById('imagens').innerHTML = "Carregando...";
		loadXMLDoc("imagem.php",valor);
}

///////////////////////////////////////////////////////
//                                                   //
//           By DM Tecnologia de Informação          //
//   												 //
//     Função Listagem de Quantidade de Imagens      //
//													 //
//			     Area Administratica				 //
///////////////////////////////////////////////////////

function loadXMLDoc5(url,valor){
	req = null; 
	if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange5; 
		req.open("GET", url+'?qtd='+valor, true); 
		req.send(null);
	} else if (window.ActiveXObject){ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (req){ 
					req.onreadystatechange = processReqChange5; 
					req.open("GET", url+'?qtd='+valor, true); 
					req.send();
				}
		}
}

function processReqChange5(){
	if(req.readyState == 4){
		if (req.status == 200){
			document.getElementById('img_conteudo').innerHTML = req.responseText;
		} else{ 
			alert("Houve um problema ao obter os dados:\n" + req.statusText);
		}
	}
}


function upQtdimg(valor){
		document.getElementById('img_conteudo').innerHTML = "Carregando...";
		loadXMLDoc5("imagem_conteudo.php",valor);
}



// Função para cadastro na lista do phplist

function loadXMLDoc2(url,valor){
	req = null; 
	if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange2; 
		req.open("GET", url+'?email='+valor, true); 
		req.send(null);
	} else if (window.ActiveXObject){ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (req){ 
					req.onreadystatechange = processReqChange2; 
					req.open("GET", url+'?email='+valor, true); 
					req.send();
				}
		}
}

function processReqChange2(){
	if(req.readyState == 4){
		if (req.status == 200){
			document.getElementById('newsletter').innerHTML = req.responseText;
		} else{ 
			alert("Houve um problema ao obter os dados:\n" + req.statusText);
		}
	}
}


function phpList(valor){
		document.getElementById('newsletter').innerHTML = "Enviando...";
		loadXMLDoc2("phplist.php",valor);
}

//////////////////////////////////////////////////
//												//
//			  Desenvolvido por DMTI				//
//												//
//		Função de Verificação de CHECKEBOX		//
//												//
//				    Para APAGAR					//
//												//
//////////////////////////////////////////////////

function checkbox() {

	// Pega todos os campos do formulário
    campos = document.form.elements;

	// Verifica se o checkbox "todos" esta checado
	if(document.form.todos.checked == true){
    for (x=0; x<campos.length; x++)
      if (campos[x].type == "checkbox") campos[x].checked = true;
	}
	// Se o checkbox "todos" não tiver checado
	else{
	for (x=0; x<campos.length; x++)
      if (campos[x].type == "checkbox") campos[x].checked = false;	
	}

}

//////////////////////////////////////////////////
//												//
//			  Desenvolvido por DMTI				//
//												//
//		Função de JUMP MENU com REFRESH na		//
//												//
//				       PAGINA					//
//												//
//////////////////////////////////////////////////

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

//////////////////////////////////////////////////
//												//
//			  Desenvolvido por DMTI				//
//												//
//				Função de POPUP					//
//												//
//////////////////////////////////////////////////

function popup(popup_url,name,Xlargura,Xaltura,Xbarra,bstatus,Xbarramenu,Xdimensao) {
 size = 'status=' + bstatus + ',menubar=' + Xbarramenu + ',resizable=' + Xdimensao + ',width=' + Xlargura + ',height=' + Xaltura + ',scrollbars=' + Xbarra;
 window.open(popup_url,name,'directories=no, location=no, toolbar=no, ' + size);
}

//////////////////////////////////////////////////
//												//
//			  Desenvolvido por DMTI				//
//												//
//				Função de POPUP					//
//												//
//////////////////////////////////////////////////

function fecha(valor){
	this.opener.location="conteudo_editar.php?conteudo="+valor;
	window.setInterval("close();window.opener.focus();",1000);
}

///////////////////////////////////////////////////////
//                                                   //
//           By DM Tecnologia de Informação          //
//   												 //
//     Função Para Fazer Filtragem na Listagem       //
//													 //
//			     Area Administratica				 //
///////////////////////////////////////////////////////
function loadXMLDoc4(url,valor){
	req = null; 
	if (window.XMLHttpRequest){ 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange4(); 
		req.open("GET", url+'?faq='+valor, true); 
		req.send(null);
	} else if (window.ActiveXObject){ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				if (req){ 
					req.onreadystatechange = processReqChange4(); 
					req.open("GET", url+'?faq='+valor, true); 
					req.send();
				}
		}
}

function processReqChange4(){
	if(req.readyState == 4){
		if (req.status == 200){
			document.getElementById('resposta').innerHTML = req.responseText;
		} else{ 
			alert("Houve um problema ao obter os dados:\n" + req.statusText);
		}
	}
}


function resp(valor){
		loadXMLDoc4("respostas.php",valor);
}
