// JavaScript Document
function limpapesq(){
	if(document.getElementById("pesquisa").value == "PESQUISAR ANIMAIS"){
		document.getElementById("pesquisa").value = "";
	}
}
function verificapesq(){
	if(document.getElementById("pesquisa").value == ""){
		document.getElementById("pesquisa").value = "PESQUISAR ANIMAIS";
	}
}

String.prototype.trim = function () {
		return this.replace(/^\s+|\s+$/g,"");
} 

function limpanews(campo){
	if(campo.value == "digite seu e-mail" || campo.value == "e-mail cadastrado" || campo.value == "erro") campo.value = "";
}
function dicanews(campo){
	if(campo.value.trim() == "") campo.value = "digite seu e-mail";
}

function maisresposta(){
	var destino = document.getElementById("maisrespostas");
	var valor = document.getElementById("cont").value;
	if(valor < 20){
		var tr = document.createElement("tr");
		valor++;
		document.getElementById("cont").value = valor;
		var trid = 'tr' + valor;
		tr.setAttribute('id', trid);
		tr.innerHTML = '<tr><td class="_14pxcinza" align="right">'+valor+' - </td><td><input class="inputtext" value="" id="resp'+valor+'" name="resp'+valor+'" style="width:600px"/></td></tr>';
		destino.appendChild(tr);
	}
	else{
		alert("Máximo de 20 respostas.");
	}
	
	
}


function menosresposta(){
	var d = document.getElementById("cont").value;
	if(d-1 != 0){
		var div = document.getElementById("maisrespostas");
		var rm = document.getElementById('tr'+d);
		d--;
		
		document.getElementById("cont").value = d;
		div.removeChild(rm);
	}	
}

function limpaemail(){
	if(document.getElementById("email").value == "E-mail já cadastrado"){
		document.getElementById("email").value = "";
		document.getElementById("email").className = "inputtext";
	}
}

function linha(idlinha){
	if(document.getElementById(idlinha).bgColor == "#007337"){
		document.getElementById(idlinha).bgColor = "#FFF";
		document.getElementById(idlinha).style.color = "#000";
	}
	else{
		document.getElementById(idlinha).bgColor = "#007337";
		document.getElementById(idlinha).style.color = "#FFF";
	}
	
}

function datanascimento(option){
	if(option){
		if(document.getElementById("dataproduto").value == ""){
			document.getElementById("dataproduto").value = "Preencha a data no formato 01/01/2000";			
		}
	}
	else{
		if(document.getElementById("dataproduto").value == "Preencha a data no formato 01/01/2000"){
			document.getElementById("dataproduto").value = "";			
		}
	}
}

function peso_produto(option){
	if(option){
		if(document.getElementById("pesoproduto").value == ""){
			document.getElementById("pesoproduto").value = "Coloque somente números. Medida em kilogramas (Kg).";			
		}
	}
	else{
		if(document.getElementById("pesoproduto").value == "Coloque somente números. Medida em kilogramas (Kg)."){
			document.getElementById("pesoproduto").value = "";			
		}
	}
}

function pe_produto(option){
	if(option){
		if(document.getElementById("peproduto").value == ""){
			document.getElementById("peproduto").value = "Coloque somente números. Medida em centímetros (cm).";			
		}
	}
	else{
		if(document.getElementById("peproduto").value == "Coloque somente números. Medida em centímetros (cm)."){
			document.getElementById("peproduto").value = "";			
		}
	}
}

function top_produto(option){
	if(option){
		if(document.getElementById("topproduto").value == ""){
			document.getElementById("topproduto").value = "Coloque somente números. Medida em porcentagem (%).";			
		}
	}
	else{
		if(document.getElementById("topproduto").value == "Coloque somente números. Medida em porcentagem (%)."){
			document.getElementById("topproduto").value = "";			
		}
	}
}

function tabelaprodutos(option, id, color){
	if(option){
		document.getElementById(id).bgColor = "#007337";
		document.getElementById(id).style.color = "#FFF";
	}
	else{
		document.getElementById(id).bgColor = color;
		document.getElementById(id).style.color = "#808080";
	}
}

function sh_banner(opt, aux){
	if(opt){
		if(aux != "r"){
			document.getElementById("imgbannernao").style.display = "block";
			document.getElementById("imgbannersim").style.display = "none";
		}else{
			document.getElementById("imgbannernao").style.display = "none";
			document.getElementById("imgbannersim").style.display = "none";
		}
	}
	else{
		if(aux == "r"){
			document.getElementById("imgbannernao").style.display = "block";
		}
		else{
			document.getElementById("imgbannersim").style.display = "block";
			document.getElementById("imgbannernao").style.display = "none";
		}
	}
}

function show_file(){
	document.getElementById("btnalterar").style.display = "none";
	document.getElementById("imgup").style.display = "inline";
	document.getElementById("btnsubmit").style.display = "inline";
	document.getElementById("sugestaoformat").style.display = "inline";
}

function alt_ins_pai(id){
	if(document.getElementById("paiproduto").value == -1){
		document.getElementById("spaiins").style.display = "inline";
		document.getElementById("spaialt").style.display = "none";
	}
	else{
		document.getElementById("spaiins").style.display = "none";
		document.getElementById("spaialt").style.display = "inline";
		
		if (window.XMLHttpRequest){
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttplogin=new XMLHttpRequest();
		}
		else{
			// code for IE6, IE5
			xmlhttplogin=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var campo = "id=" + id + "&aux=" + 1;	
		xmlhttplogin.onreadystatechange=function()
		{
			if (xmlhttplogin.readyState==4 && xmlhttplogin.status==200){
				var txt = xmlhttplogin.responseText;
				
				document.getElementById("divpaialt").innerHTML = txt;
			}
		}
				  
		xmlhttplogin.open("POST","formaltfancy.php",true);
		xmlhttplogin.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttplogin.send(campo);
	}
}

function alt_ins_mae(id){
	if(document.getElementById("maeproduto").value == -1){
		document.getElementById("smaeins").style.display = "inline";
		document.getElementById("smaealt").style.display = "none";
	}
	else{
		document.getElementById("smaeins").style.display = "none";
		document.getElementById("smaealt").style.display = "inline";
		
		if (window.XMLHttpRequest){
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttplogin=new XMLHttpRequest();
		}
		else{
			// code for IE6, IE5
			xmlhttplogin=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var campo = "id=" + id + "&aux=" + 2;	
		xmlhttplogin.onreadystatechange=function()
		{
			if (xmlhttplogin.readyState==4 && xmlhttplogin.status==200){
				var txt = xmlhttplogin.responseText;
				
				document.getElementById("divmaealt").innerHTML = txt;
			}
		}
				  
		xmlhttplogin.open("POST","formaltfancy.php",true);
		xmlhttplogin.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttplogin.send(campo);
	}
}

function alt_inicia_dois(id, idmae){
	if(document.getElementById("paiproduto").value == -1){
		document.getElementById("spaiins").style.display = "inline";
		document.getElementById("spaialt").style.display = "none";
	}
	else{
		document.getElementById("spaiins").style.display = "none";
		document.getElementById("spaialt").style.display = "inline";
		
		if (window.XMLHttpRequest){
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttplogin=new XMLHttpRequest();
		}
		else{
			// code for IE6, IE5
			xmlhttplogin=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var campo = "id=" + id + "&aux=" + 1;	
		xmlhttplogin.onreadystatechange=function()
		{
			if (xmlhttplogin.readyState==4 && xmlhttplogin.status==200){
				var txt = xmlhttplogin.responseText;
				
				document.getElementById("divpaialt").innerHTML = txt;
				alt_ins_mae(idmae);
			}
		}
				  
		xmlhttplogin.open("POST","formaltfancy.php",true);
		xmlhttplogin.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttplogin.send(campo);
	}	
}

function inicia_geral(idpai, idmae){
	if(idpai != -1 && idmae != -1){
		alt_inicia_dois(idpai, idmae);
	}
	else if(idpai != -1 && idmae == -1){
		alt_ins_pai(idpai);
	}
	else if(idpai == -1 && idmae != -1){
		alt_ins_mae(idmae);
	}
}



function destinatarios(op){
	if(op == 1){
		document.getElementById("selectdestinatarios").style.display = "none";
		document.getElementById("btninserir").style.display = "none";
		document.getElementById("contshow").style.display = "none";
		document.getElementById("desttext").value = "todos";
		document.getElementById("contshow").value = "";
	}
	else{
		document.getElementById("selectdestinatarios").style.display = "inline";
		document.getElementById("btninserir").style.display = "inline";
		document.getElementById("desttext").value = "";
	}
}

function adddesc(val){
	
	document.getElementById("contshow").style.display = "inline";
	if(document.getElementById("contshow").value == "")
		document.getElementById("contshow").value = val;
	else	
		document.getElementById("contshow").value = document.getElementById("contshow").value + ", " + val;
		
	if(document.getElementById("desttext").value == "")
		document.getElementById("desttext").value = val;
	else	
		document.getElementById("desttext").value = document.getElementById("desttext").value + ", " + val;
}

function arquivo_mais(){
	var destino = document.getElementById("tablearquivos");
	var valor = document.getElementById("contarquivo").value;
	if(valor < 10){
		var tr = document.createElement("tr");
		var tr2 = document.createElement("tr");
		valor++;
		document.getElementById("contarquivo").value = valor;
		var trid = 'tr' + valor;
		tr.setAttribute('id', trid);
		tr.innerHTML = '<td class="_18pxverdebold" align="right"> Arquivo '+valor+':</td><td><input type="file" id="arquivo'+valor+'" name="arquivo'+valor+'" /></td>';
		tr2.setAttribute('id', trid + trid);
		tr2.innerHTML = '<tr><td align="right" class="_18pxverdebold" width="150" >Título '+valor+':</td><td><input type="text" id="titulo'+valor+'" name="titulo'+valor+'" /> </td></tr>';
		destino.appendChild(tr);
		destino.appendChild(tr2);
	}
	else{
		alert("Máximo de 10 arquivos.");
	}
}


function arquivo_menos(){
	var d = parseInt(document.getElementById("contarquivo").value);
	if(d-1 != 0){
		var div = document.getElementById("tablearquivos");
		var rm = document.getElementById('tr'+d);
		var rm2 = document.getElementById('tr'+d+'tr'+d);
		d--;
		
		document.getElementById("contarquivo").value = d;
		div.removeChild(rm);
		div.removeChild(rm2);
	}	
}

function arquivo_menos_alterar(){
	var d = parseInt(document.getElementById("contarquivo").value);
	var df = parseInt(document.getElementById("contarquivofixo").value);
	if(d > df){
		var div = document.getElementById("tablearquivos");
		var rm = document.getElementById('tr'+d);
		d--;
		
		document.getElementById("contarquivo").value = d;
		div.removeChild(rm);
	}
}

function filt(nome){
	if(nome == "nome" || nome == "sobrenome" || nome == "email" || nome == "cidade"){
		document.getElementById("filt").innerHTML = '<input type="text" id="filtcont" name="filtcont" class="inputtext" style="font-size:12px;width:200px" /></span>';
	}
	else if(nome == "estado"){
		document.getElementById("filt").innerHTML = '<select id="filtcont" name="filtcont" class="inputtext" style="height:30px;font-size:12px"><option value="AC">AC</option><option value="AL">AL</option><option value="AM">AM</option><option value="AP">AP</option><option value="BA">BA</option><option value="CE">CE</option><option value="DF">DF</option><option value="ES">ES</option><option value="GO">GO</option><option value="MA">MA</option><option value="MG">MG</option><option value="MS">MS</option><option value="MT">MT</option><option value="PA">PA</option><option value="PB">PB</option><option value="PE">PE</option><option value="PI">PI</option><option value="PR">PR</option><option value="RJ">RJ</option><option value="RN">RN</option><option value="RO">RO</option><option value="RR">RR</option><option value="RS">RS</option><option value="SC">SC</option><option value="SE">SE</option><option value="SP">SP</option><option value="TO">TO</option></select>';
	}
	else if(nome == "categoria"){
		if (window.XMLHttpRequest){
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttplogin=new XMLHttpRequest();
		}
		else{
			// code for IE6, IE5
			xmlhttplogin=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var campo = "";	
		xmlhttplogin.onreadystatechange=function()
		{
			if (xmlhttplogin.readyState==4 && xmlhttplogin.status==200){
				var txt = xmlhttplogin.responseText;
				
				document.getElementById("filt").innerHTML = txt;
			}
		}
				  
		xmlhttplogin.open("POST","catajax.php",true);
		xmlhttplogin.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttplogin.send(campo);
	}
}

function filtb(nome){
	if(nome == "nomeb" || nome == "sobrenomeb" || nome == "emailb" || nome == "cidadeb"){
		document.getElementById("filtb").innerHTML = '<input type="text" id="filtcontb" name="filtcontb" class="inputtext" style="font-size:12px;width:200px" /></span>';
	}
	else if(nome == "estadob"){
		document.getElementById("filtb").innerHTML = '<select id="filtcontb" name="filtcontb" class="inputtext" style="height:30px;font-size:12px"><option value="AC">AC</option><option value="AL">AL</option><option value="AM">AM</option><option value="AP">AP</option><option value="BA">BA</option><option value="CE">CE</option><option value="DF">DF</option><option value="ES">ES</option><option value="GO">GO</option><option value="MA">MA</option><option value="MG">MG</option><option value="MS">MS</option><option value="MT">MT</option><option value="PA">PA</option><option value="PB">PB</option><option value="PE">PE</option><option value="PI">PI</option><option value="PR">PR</option><option value="RJ">RJ</option><option value="RN">RN</option><option value="RO">RO</option><option value="RR">RR</option><option value="RS">RS</option><option value="SC">SC</option><option value="SE">SE</option><option value="SP">SP</option><option value="TO">TO</option></select>';
	}
	else if(nome == "categoriab"){
		if (window.XMLHttpRequest){
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttplogin=new XMLHttpRequest();
		}
		else{
			// code for IE6, IE5
			xmlhttplogin=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var campo = "";	
		xmlhttplogin.onreadystatechange=function()
		{
			if (xmlhttplogin.readyState==4 && xmlhttplogin.status==200){
				var txt = xmlhttplogin.responseText;
				
				document.getElementById("filtb").innerHTML = txt;
			}
		}
				  
		xmlhttplogin.open("POST","catajaxb.php",true);
		xmlhttplogin.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttplogin.send(campo);
	}
}

function got(qtd, ordem, filtcont, ordemb, filtcontb){
	document.location.href = 'cadastro.php?qtd=' + qtd + '&ord=' + ordem + '&filtcont=' + filtcont + '&ordb=' + ordemb + '&filtcontb=' + filtcontb;
}
