// JavaScript Document
// JavaScript Document
var req;
var txt;

function loadXMLDoccom(url,valor, valor2, valor3, valor4)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangecom;
        req.open("GET", url+'?nome='+valor+'&email='+valor2+'&mensagem='+valor3+'&id='+valor4, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangecom;
            req.open("GET", url+'?nome='+valor+'&email='+valor2+'&mensagem='+valor3+'&id='+valor4, true);
            req.send();
        }
    }
	
}


function processReqChangecom()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
			txt = req.responseText.split("|");
			document.getElementById('mensagem').innerHTML = txt[1];
			if(txt[0] == 1)
			{
				document.frmComentario.txtNome.value = "";
				document.frmComentario.txtEmail.value = "";
				document.frmComentario.txtMensagem.value = "";
				document.getElementById('comentarios').innerHTML = txt[2];
			}
			//alert(req.responseText);
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function comentario(valor, valor2, valor3, valor4)
{
	loadXMLDoccom("includes/ajaxComentario.php",valor, valor2, valor3, valor4);
}





function loadXMLDoc(url,valor)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url+'?email='+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url+'?email='+valor, true);
            req.send();
        }
    }
	
}


function processReqChange()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
			document.getElementById('retorno').innerHTML = req.responseText;
			
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function Atualizar()
{
	valor = document.newsletter.email.value;
	//alert("valor");
	if(valor != "")
	loadXMLDoc("ajaxNewsletter.php",valor);
	else
	alert("O e-mail deve ser preenchido");
}



function loadXMLDoc2(url,valor)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange2;
        req.open("GET", url+'?uf='+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange2;
            req.open("GET", url+'?uf='+valor, true);
            req.send();
        }
    }
	
}


function processReqChange2()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
			document.getElementById('atualizar2').innerHTML = req.responseText;
			
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function Atualizar2()
{
	valor = document.getElementById("estado").value;
	//alert("valor");
	if(valor != "")
	loadXMLDoc2("ajaxCidade.php",valor);
}


function loadXMLDoc3(url,valor, valor2)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange3;
        req.open("GET", url+'?uf='+valor+'&cidade='+valor2, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange3;
            req.open("GET", url+'?uf='+valor+'&cidade='+valor2, true);
            req.send();
        }
    }
	
}


function processReqChange3()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
			document.getElementById('atualizar3f').innerHTML = req.responseText;
			
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function Atualizar3(estado)
{
	if(estado == "")
	{
		valor = document.getElementById("estado").value;
		valor2 = document.getElementById("cidade").value;
	}
	else
	{
		valor = estado;
		valor2 = '';
	}
	//alert("valor");
	if(valor != "")
	{
		//document.getElementById('atualizarN').innerHTML = '<div align="center"><img src="images/loading.gif"></div>';
		document.getElementById('atualizar3f').innerHTML = '<table width="650" border="0" cellpadding="0" cellspacing="0" style="margin-bottom:10px; border-bottom:3px solid #CCCCCC;">  <tr>    <td align="center" valign="top" style="padding-bottom:8px;"><p>&nbsp;</p>    <p><img src="images/loading.gif" width="32" height="32"></p>    <p>&nbsp;</p></td>  </tr></table>';
		loadXMLDoc3("ajaxBusca.php",valor, valor2);
	}
}


function loadXMLDocN(url,valor)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangeN;
        req.open("GET", url+'?email='+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangeN;
            req.open("GET", url+'?email='+valor, true);
            req.send();
        }
    }
}


function processReqChangeN()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
			document.getElementById('atualizarN').innerHTML = req.responseText;
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function newsletter(valor)
{
	if(valor == 1)
	{
		valor = document.getElementById("email").value;
		document.getElementById('atualizarN').innerHTML = '<div align="center"><img src="images/loading.gif"></div>';
		loadXMLDocN("xtNewsletter.php",valor);
	}
	else
	{
		document.getElementById('atualizarN').innerHTML = '<p>Receba nossos informativos por <br />e-mail:</p>               <br /><table width="239" border="0" cellspacing="0" cellpadding="0">                 <tr>                   <td width="48">E-mail:</td>                   <td width="191">                     <table border="0" cellpadding="0" cellspacing="0" width="190">                       <tr>                         <td><img name="formnews1" src="imagens/form-news1.gif" width="12" height="24" border="0" id="formnews1" alt="" /></td>                       <td width="115" align="left" valign="middle" background="imagens/form-news2.gif"><span style="padding-top:2px; padding-bottom:2px;">                         <input type="text" name="email" id="email"  style="width:113px; height:14px; border:1px solid #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; background-color:#FFFFFF;"/>                         </span></td>                       <td><a href="javascript:;" onclick="newsletter(1)"><img name="formnews3" src="imagens/form-news3.gif" width="63" height="24" border="0" id="formnews3" alt="" /></a></td>                     </tr>                      </table></td>                 </tr>                </table> ';	
	}
}


function loadXMLDoc5(url,valor)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange5;
        req.open("GET", url+'?cookie='+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange5;
            req.open("GET", url+'?cookie='+valor, true);
            req.send();
        }
    }
	
}


function processReqChange5()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
		    var s = req.responseText.split('||');
			
			switch(s[0])
			{
				case "suinos":
				if(s[1] == 1)
				document.getElementById(s[0]).src = 'imagens/icon-suinos.gif';
				else
				document.getElementById(s[0]).src = 'imagens/icon-suinosOff.gif';
				break;
				case "ovinos":
				if(s[1] == 1)
				document.getElementById(s[0]).src = 'imagens/icon-ovelha.gif';
				else
				document.getElementById(s[0]).src = 'imagens/icon-ovelhaOff.gif';
				break;
				case "leite":
				if(s[1] == 1)
				document.getElementById(s[0]).src = 'imagens/icon-gadoleite.gif';
				else
				document.getElementById(s[0]).src = 'imagens/icon-gadoleiteOff.gif';
				break;
				case "caprinos":
				if(s[1] == 1)
				document.getElementById(s[0]).src = 'imagens/icon-caprinos.gif';
				else
				document.getElementById(s[0]).src = 'imagens/icon-caprinosOff.gif';
				break;
				case "equinos":
				if(s[1] == 1)
				document.getElementById(s[0]).src = 'imagens/icon-cavalo.gif';
				else
				document.getElementById(s[0]).src = 'imagens/icon-cavaloOff.gif';
				break;
				case "corte":
				if(s[1] == 1)
				document.getElementById(s[0]).src = 'imagens/icon-gadocorte.gif';
				else
				document.getElementById(s[0]).src = 'imagens/icon-gadocorteOff.gif';
				break;
			}
			
			document.getElementById('atualizar5').innerHTML = s[2];
			
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function Atualizar5(valor)
{
	/*switch($cookie)
{
	case "suinos":
	if($_COOKIE['suinos'] == 1)
	document.getElementById(valor).src = '';
	else
	document.getElementById(valor).src = '';
	break;
	case "ovinos":
	if($_COOKIE['ovinos'] == 1)
	document.getElementById(valor).src = '';
	else
	document.getElementById(valor).src = '';
	break;
	case "leite":
	if($_COOKIE['leite'] == 1)
	document.getElementById(valor).src = '';
	else
	document.getElementById(valor).src = '';
	break;
	case "caprinos":
	if($_COOKIE['caprinos'] == 1)
	document.getElementById(valor).src = 'imagens/icon-caprinosOff.gif';
	else
	document.getElementById(valor).src = 'imagens/icon-caprinosOff.gif';
	break;
	case "equinos":
	if($_COOKIE['equinos'] == 1)
	document.getElementById(valor).src = '';
	else
	document.getElementById(valor).src = '';
	break;
	case "corte":
	if($_COOKIE['corte'] == 1)
	document.getElementById(valor).src = '';
	else
	document.getElementById(valor).src = '';
	break;
}*/
	
	loadXMLDoc5("ajaxProdutos.php",valor);
}
