
function createXMLHTTP() 
{
   if(window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    } 
	else if(window.ActiveXObject)
    {
        var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
        
        for(var i = 0; i < prefixes.length; i++)
        {
            try
            {
                return new ActiveXObject(prefixes[i] + ".XMLHTTP");
            } catch (e) {}
        }
    }
}


//Função para abertura de pop-up

var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)

{

  if(popUpWin)

  {

    if(!popUpWin.closed) popUpWin.close();

  }

  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}

//Menu Central de Atendimento:

function centralAtendimento(param){
document.getElementById("linksCentral").style.visibility = param; 
}

String.prototype.trim = function()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function formatar(src, mask){
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida)
  {
    src.value += texto.substring(0,1);
  }
}

function limpa_string(S){
var Digitos = "0123456789";
var temp = "";
var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
    }
    return temp
}

function is_num(e,name_field)
{
	var tecla = event.keyCode;
	if (tecla > 47 && tecla < 58)// numeros de 0 a 9
		return true;
	else
	{
		document.getElementById(name_field+"Msg").innerHTML = 'Permitido somente números.';
		if (tecla != 8) // backspace
			event.keyCode = 0;
		else
			return true;
	}
}

function limpa_NomeCadNews(limpar)
{
	if(document.getElementById("campoCadNewsNome").value == 'nome')
	{
   		document.getElementById("campoCadNewsNome").value = '';
	} else if (limpar == 1 && document.getElementById("campoCadNewsNome").value == '')
	{
		document.getElementById("campoCadNewsNome").value = 'nome';
	}
}

function limpa_EmailCadNews(limpar)
{
	if(document.getElementById("campoCadNewsEmail").value == 'e-mail')
	{
   		document.getElementById("campoCadNewsEmail").value = '';
	} else if ( limpar == 1 && document.getElementById("campoCadNewsEmail").value == '')
	{
		document.getElementById("campoCadNewsEmail").value = 'e-mail';
	}
}

function limpa_cadLateralNewsNome(limpar)
{
	if(document.getElementById("cadLateralNewsNome").value == 'nome')
	{
   		document.getElementById("cadLateralNewsNome").value = '';
	} else if (limpar == 1 && document.getElementById("cadLateralNewsNome").value == '')
	{
		document.getElementById("cadLateralNewsNome").value = 'nome';
	}
}

function limpa_cadLateralNewsEmail(limpar)
{
	if(document.getElementById("cadLateralNewsEmail").value == 'e-mail')
	{
   		document.getElementById("cadLateralNewsEmail").value = '';
	} else if ( limpar == 1 && document.getElementById("cadLateralNewsEmail").value == '')
	{
		document.getElementById("cadLateralNewsEmail").value = 'e-mail';
	}
}

function AbreCadastroNews(param,url)
{     
    document.getElementById("frameCadastroNews").src = url;
    
    if(param == 1)
    {
        document.getElementById("divCadastroNews").style.display = "block";
       
    }
    else
    {
         document.getElementById("divCadastroNews").style.display = "none";
    }
}

function valida_news(codLoja,valor_nome,valor_email,id_produto,news,campanha)
{
   if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor_email)))
    {
    	alert(valor_email+" não é um e-mail válido.") ;
    	return false;
    }
   var oHTTPRequest = createXMLHTTP(); 
   oHTTPRequest.open("post", "../Scripts/script_news.asp", true);
   oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   oHTTPRequest.onreadystatechange=function(){
	   if (oHTTPRequest.readyState==4){
		var r = oHTTPRequest.responseXML;
		//alert(r.getElementsByTagName('alert_news')[0].childNodes[0].nodeValue);
		//popUpWindow("FormularioCadastroNews.aspx?" + r.getElementsByTagName('alert_news')[0].childNodes[0].nodeValue,  200, 150, 450, 465);
		//window.open("FormularioCadastroNews.aspx?" + r.getElementsByTagName('alert_news')[0].childNodes[0].nodeValue, "_blank");
		AbreCadastroNews(1,r.getElementsByTagName('alert_news')[0].childNodes[0].nodeValue);
	   }}
	   oHTTPRequest.send("nome=" + valor_nome + "&email=" + valor_email + "&id_loja=" + codLoja + "&id_produto=" + id_produto + "&news=" + news + "&camp=" + campanha);
}

function siteSeguro(dominio,page)
{
	window.location.href = 'http://'+dominio+'/'+page;	
}

function Busca(dominio)
{
	document.getElementById("buscaNews").action = 'http://'+dominio+'/resultado_busca.asp?q='+document.getElementById('campoBuscar').value;
	document.getElementById("buscaNews").submit();
}