// JavaScript Document
function ob_ajax()
 { 
 var objXMLHttp=null
 if (window.XMLHttpRequest)
  {
  	 objXMLHttp=new XMLHttpRequest()
  }
 else if (window.ActiveXObject)
  {
 	 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  ajax = objXMLHttp
 return ajax;
}
function getCatalogo(strUrl,destino)
{
	ajax = ob_ajax();
	ajax.open("get", strUrl, true);
  //ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // somente para POST
    ajax.onreadystatechange = function() {
    //enquanto estiver processando...emite a msg de carregando
		   document.getElementById("mostraProduto").style.display = 'none';
		if(ajax.readyState == 1) {
			
			document.getElementById(destino).innerHTML= 'Aguarde, localizando o produto....';
		   document.getElementById("mostraProduto").style.display = 'block';
		}
        if(ajax.readyState == 4 ) {
	       document.getElementById(destino).innerHTML = ajax.responseText;
		   document.getElementById("mostraProduto").style.display = 'block';
		}
        else {
        	document.getElementById(destino).innerHTML = "";
        }
    }

    var params = null;
    ajax.send(params);
}
function mostra(id)
{
	if(document.getElementById(id).style.display == 'block')
	{
		document.getElementById(id).style.display = 'none';
	}
	else
	{
		document.getElementById(id).style.display  = 'block'
	}

}
function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
                    return true;
                }
    }else{
        return false;
        }
}
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function validaNews()
{
	nome = document.getElementById('nome');
	email = document.getElementById('email');
	if(Trim(nome.value) == '')
	{
		alert("Por favor digite seu nome.");
		nome.focus();
		return false;
	}
	if(!checkMail(email))
	{
		alert("Por favor digite seu e-mail.");
		email.focus();
		return false;
	}
	return true;	
}
function enviarNews(id,enviado)
{
	if(enviado == true)
	{
		if(confirm("Essa Newsletter já foi enviada. Deseja Enviar novamente?"))
		{
			window.location="enviar/"+id;
		}
	}
	else
	{
		if(confirm("Deseja Enviar agora a Newsletter?"))
		{
			window.location= "enviar/"+id;
		}
	}
}
function apagarNews(url)
{
	if(confirm("Tem certesa que deseja apagar essa newsletter?"))
	{
		window.location=url;
	}
}