function isValidCarater(evento)
{

//	var key;
//	
//	if (window.event) 
//	{
//		key = event.keyCode;
//	}
//	else
//	{ 
//		key = evento.which;
//	}
//	
//	if ((key == 32 || key == 46 || key == 44 || key == 130 || key == 40 || key == 41 || key == 13 || key == 47) // ponto, barra de espaço, vírgula, parênteses, Tecla Enter, Barra normal '/'  
//	|| (key > 47 && key < 58)    // 0-9
//	|| (key > 63 && key < 91)    // A-Z
//	|| (key > 96 && key < 123)   // a-z
//	|| (key > 191 && key < 196)  // À , Á ,Â Ã 
//	|| (key > 198 && key < 208)  // Ç, È, É, Ê, Ë, Ì, Í, Î, Ï
//	|| (key > 209 && key < 215)  // Ò, Ó, Ô, Õ, Ö  
//	|| (key > 216 && key < 221)  // Ù, Ú, Û, Ü 
//	|| (key > 223 && key < 229)  // à, á, â, ã, ä 
//	|| (key > 230 && key < 240)  // ç, è, é, ê, ë, ì, í, î, ï
//	|| (key > 241 && key < 247)  // ò, ó, ô, õ, ö
//	|| (key > 248 && key < 253)  // ù, ú, û, ü
//	)
//	{
//	    return true;
//	}

    return true;
}

/*Função criada para ativar ou desativar o copy paste*/
function enableCopyPaste() {
    return true;
}


function WebMethodFailed(exc, ctx, methodName)
{
    window.location = exc.get_message();
}

function SubmitEnter(e)
{
	var key;

	if (window.event)
	{
		key = event.keyCode;
	}
	else
	{
		key = e.which;
	}

	if(key == 13)
	{
		CalcularFrete();
	}
	else
	{
		if(window.event)
		{
			window.event.returnValue = null;
		}
		else
		{
			e.preventDefault();
		}
	}
}

function SomenteNumero(e)
{
	var key;

	if (window.event)
	{
		key = event.keyCode;
	}
	else
	{
		key = e.which;
	}

	if(key > 47 && key < 58 || key == 8 || key == 0)
	{
		return;
	}
	else
	{
		if(window.event)
		{
			window.event.returnValue = null;
		}
		else
		{
			e.preventDefault();
		}
	}
}

function SomenteNumero2(e, src, mask)
{
	SomenteNumero(e);

	var key;

	if (window.event)
	{
		key = event.keyCode;
	}
	else
	{
		key = e.which;
	}


	if(	key != 8)
	{
		Mascara(src,mask);
	}
}

function SomenteNumero_Mascara(e, src, mask)
{
	SomenteNumero(e);
	
	var key;

	if (window.event) 
	{
		key = event.keyCode;
	}
	else
	{ 
		key = e.which;
	}
	
	if (key != 8)
	{
		Mascara(src, mask);
	}
}

function Mascara(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 Mascara2(e, src, mask)
{
	var key;

	if (window.event)
	{
		key = event.keyCode;
	}
	else
	{
		key = e.which;
	}

	if (key != 8)
	{
		Mascara(src, mask);
	}
}

function AbrirPopUP(URL,nmPagina)
{
    try
    {
        void(window.open(URL, nmPagina, 'status = 1, height = 700, width = 600, resizable = 1,scrollbars=1'));
    }
    catch(err)
    {
        alert(err.description);
    }
}

function AbrirPopUPTamanho(URL, nmPagina, largura, altura)
{
    try
    {
	    void(window.open(URL, nmPagina,'status = 1, height = ' + altura + ', width = ' + largura + ', resizable = 1,scrollbars=1'));
    }
    catch(err)
    {
	    alert(err.description);
    }
}
    
    

var ObjetoGlobal;
var FuncaoGlobal;

function AplicarMascara(Objeto,Funcao)
{
    ObjetoGlobal    =   Objeto;
    FuncaoGlobal    =   Funcao;
    ExecutarMascara();
    setTimeout("ExecutarMascara()",1);
} 

function ExecutarMascara()
{
    ObjetoGlobal.value = FuncaoGlobal(ObjetoGlobal.value);
}

function MascaraNumeros(Value)
{
  Value = Value.replace(/\D/g,"")
  return Value;
}

function _isinteger(test_string)
{
	var i;
	var non_nums = 0;

	for (i = 1; i < test_string.length; i++)
	{
		if ((test_string.substring(i-1,i) < '0') || (test_string.substring(i-1,i) > '9'))
		{
			non_nums++;
		}
	}

	if (non_nums == 0)
		return true;
	else
		return false;
}

function validaCNPJ(cnpj)
{
	var retorno = true;
	
	CNPJ = Trim(cnpj);
	
	erro = new String;
	
	CNPJ = CNPJ. replace (".","");
	CNPJ = CNPJ. replace (".","");
	CNPJ = CNPJ. replace ("-","");
	CNPJ = CNPJ. replace ("/","");
			
			
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! "; 
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++)
	{
			a[i] = CNPJ.charAt(i);
			b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	b = 0;
	for (y=0; y<13; y++) {
			b += (a[y] * c[y]); 
	}
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
			erro +="Dígito verificador com problema!";
	}
	
	if (erro.length > 0)
	{
		retorno = false;
	}
				
    return retorno;				
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return "";
	}
	if ( start == -1 ) return "";
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	var valuePlus = document.cookie.substring( len, end );
	while(valuePlus.indexOf('+') > -1)
	{
		valuePlus = valuePlus.replace('+', ' ');
	}
	return decodeURIComponent(valuePlus);
}

function ColocaFocus(NomeBtn, e)
{
	try
	{
		var key;

		if(window.event)
		{
			key = window.event.keyCode;
		}
		else
		{
			key = e.which;
		}
		if(key == 13)
		{
			document.getElementById(NomeBtn).focus();

			if(window.event)
			{
				window.event.keyCode = 0;
			}
		}
	}
	catch(err)
	{
		alert(err.description);
	}

	return false;
}


/* scrool fotos */
function fotos() {
    J('#fotos_ampliadas').cycle({ 
        fx:     'scrollLeft', 
        speed:  'fast', 
        timeout: 0, 
        next:   '.img_proximo', 
        prev:   '.img_anterior' 
});
}

/*CLOSE MODAL*/
function closeModal() {

    var J = jQuery.noConflict();

	/*HIDE MODAL*/
	J('.view_modal').fadeTo('fast', 0, function() {
		J(this).remove();
	});
	
	/*HIDE BACKGROUND*/
	J('.bg_modal').fadeTo('fast', 0, function() {
		J(this).remove();

		/*SHOW SELECT*/
		//J('select').css('visibility', 'visible');
		J('select,object,embed').css('visibility', 'visible'); // IKEDA
	});
}

/*MODAL*/
function openModal(url) {
try
{
	if(url == '')
	{
		return;
	}

    var J = jQuery.noConflict();

	/*CREATE ELEMENTS*/
	J('body').append(J('<img />').attr({src: "../img/load.gif", width: 88, height: 78, alt: "", className: 'load'})).append(J('<div></div>').addClass('bg_modal')).append(J('<div></div>').addClass('view_modal'));
	J('.bg_modal').width(J('html')[0].scrollWidth).height(J('html')[0].scrollHeight);

	/*OPACITY*/
	J('.view_modal').css('opacity', 0);
	J('.bg_modal').css('opacity', 0);
	
	/*SELECTS HIDE*/
	//J('select').css('visibility', 'hidden');
	J('select,object,embed').css('visibility', 'hidden'); // IKEDA

	/*SHOW BACKGROUND*/
	J('.bg_modal').fadeTo('fast', 0.5, function() {
		//J('.view_modal').load(url + '?' + (new Date()).getTime(), function() {
		J('.view_modal').load(url, function() { // IKEDA
			/*REMOVE LOAD*/
			J('.load').remove();
			
			GB_getPageScrollTop = function() {
			var yScrolltop;
			if (self.pageYOffset) {
				yScrolltop = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft) {
				yScrolltop = document.documentElement.scrollTop;
			} else if (document.body) {
				yScrolltop = document.body.scrollTop;
			}
				return yScrolltop;
			}
			
			/*CENTRALIZE MODAL*/
			
            J('.view_modal').css({marginTop: parseInt(GB_getPageScrollTop() - (J('.view_modal').height()/2)), marginLeft: -parseInt(J('.view_modal').width()/2)});
			
			/**/
			/*MODAL HIDE*/
			J('.view_modal').fadeTo('fast', 1);
            J('.view_modal').css({marginTop: parseInt(GB_getPageScrollTop() - (J('.view_modal').height()/2)), marginLeft: -parseInt(J('.view_modal').width()/2)});			
			/*CLOSE MODAL*/
			J("a[@rel~='modalclose']").click(function() {
				closeModal();
				return false;
			})

			J(".conteudo_modal dt").each(function(i) {
				J(this).find("a").click(function(){
					J('.conteudo_modal dd').hide();
					J('.conteudo_modal dd:eq('+i+')').show();
					return false;
				});
			});
		});
	});
}
catch(ex)
{
    alert(ex.description);
}
}

function ColocaFocusEnter(e, nome)
	{
		try
		{
			var key;

			if(window.event)
			{
				key = window.event.keyCode;
			}
			else
			{
				key = e.which;
			}
			if(key == 13)
			{
				document.getElementById(nome).focus();

				if(window.event)
				{
					window.event.keyCode = 0;
				}
			}
		}
		catch(err)
		{
			alert(err.description);
		}

		return false;
	}	

    function abreChat() 
    {
        window.open("http://directtalk.multibras.com.br/server/directtalk_chatr.dll/user?S=I&id_s=0370000053649000050C","janela","width=350,height=350,resizable=0,toolbar=0,location=0,directories=0,status=1,menubar=0");
    }

