//Bloco de código para esconder e mostra form - formatadadosie
var Ver4 = parseInt(navigator.appVersion) >= 4
var IE4 = ((navigator.userAgent.indexOf("MSIE") != -1) && Ver4)
var block = "formulario";
function esconde() {document.form.style.visibility = "hidden" }
function mostra() {document.form.style.visibility = "visible" }
//Bloco de código para esconder e mostra form

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}


//***********************************
//
function MouseNormal()
{
	document.body.style.cursor = 'default';
}

function MouseAmpulheta()
{		
	document.body.style.cursor = 'wait';
}
 
//Funcao para abertura de popup
function winpop( strPagina, intLargura, intAltura, booRolagem )
	
{
    strJanela = "pop" + (intLargura+intAltura);
    var objjan = window.open( strPagina, strJanela, 'width=' + intLargura + ',height=' + intAltura +',menubar=no,location=no,scrollbars=' + booRolagem + ',status=no,toolbar=no,resizable=no,top=100,left=100' ); 
    objjan.focus();
}

//Funcao para abertura de popup do tipo modal
function winpopmodal( strPagina, intLargura, intAltura, strArg )
{
	strPagina = strPagina + "?" + strArg;
	var strParametros = "dialogHeight: " + intAltura + "px; dialogWidth: " + intLargura + "px; dialogTop: 100px; dialogLeft: 100px; edge: Raised; center: Yes; help: No; resizable: No; status: No;";
	var objjan = window.showModalDialog(strPagina, "", strParametros);
}
    
    
function currencyFormat(fld, e) {
	var milSep = '.';
	var decSep = ',';
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++) if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++) if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--) fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}		

function currencyFormatPeso(fld, e) {
	var milSep = '.';
	var decSep = ',';
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++) if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++) if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + aux;
	//if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 1) {
		aux2 = '';
		for (j = 0, i = len - 2; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 ; i >= 0; i--) fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 1, len);
	}
	return false;
}		

//-->





function FormataHora(objCampo,intKeyCode){
	if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
		return false
	}
	else
	{
		if(objCampo.value == ''){
			objCampo.value = '00:00'
		}
		if(objCampo.value.substr(0,1) == '0' || objCampo.value.length == 5){
			objCampo.value = objCampo.value.substr(1, objCampo.value.length)
		}
		strValor = Substitui(objCampo.value, ':', '') + (intKeyCode - 48).toString();
		strHora = strValor.substr(0, strValor.length - 2)
		strMinuto = strValor.substr(strValor.length - 2, strValor.length)
		objCampo.value = strHora + ':' + strMinuto
		return false
	}
}


function FormataNumero(objCampo,intKeyCode){
		
		if(parseInt(intKeyCode) != 13){
			if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
				return false
				}
			else
				{
				return true
				}
			}
		else
			{
				return true
			}
		}

function FormataTele(tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	vr = vr.replace( "+", "" );
	vr = vr.replace( "(", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( " ", "" );
	tam = vr.length;

	if (document.selection){ 
		txt = document.selection.createRange().text;
		if (txt.length > 0){
			document.selection.clear();
			vr = '';
			event.srcElement.value = '';
		}
	}
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		event.srcElement.value = vr ; }
	 	if ( (tam > 4) && (tam <= 8) ){
	 		event.srcElement.value = vr.substr( 0, tam - 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 10) ){
	 		event.srcElement.value = vr.substr( 0, tam - 8 ) + ') ' + vr.substr( tam - 8, 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	 	if ( (tam >= 11) && (tam <= 11) ){
	 		event.srcElement.value = vr.substr( 0, tam - 10 ) + '(' + vr.substr( tam - 10, 2 ) + ') ' + vr.substr( tam - 8, 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 12) ){
	 		event.srcElement.value = vr.substr( 0, tam - 12 ) + '+' + vr.substr( tam - 12, 2 ) + '(' + vr.substr( tam - 10, 2 ) + ') ' + vr.substr( tam - 8, 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	 }
}

function FormataValor(tammax,teclapres)	 {
	var tecla = teclapres.keyCode;
	var vr = event.srcElement.value;
	var txt;
	
	if(parseInt(tecla) != 13){
		if((parseInt(tecla) < 48) || (parseInt(tecla) > 57)){
			event.returnValue = false;
			return false;
		}
	}

	if (document.selection){ 
		txt = document.selection.createRange().text;
		if (txt.length > 0){
			document.selection.clear();
			vr = '';
			event.srcElement.value = '';
		}
	}
	
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );


	if (vr.length > 0){ vr = parseInt(vr,10); }
	vr = '' + vr

	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
			if (tam == 1){ 
				event.srcElement.value = "0,0" + vr ; 
			}else if (tam == 2){ 
				event.srcElement.value = "0," + vr ; 
			}else{
				event.srcElement.value = "" ; 
			}
		}
	 	if ( (tam > 2) && (tam <= 5) ){
	 		event.srcElement.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		event.srcElement.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		event.srcElement.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		event.srcElement.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
		}
	}		
}

function FormataValorSemMilhar(tammax,teclapres)	 {
	var tecla = teclapres.keyCode;
		
	if(parseInt(tecla) != 13){
		if((parseInt(tecla) < 48) || (parseInt(tecla) > 57))
		{
			if ((parseInt(tecla) != 44) && (parseInt(tecla) != 46))
			{
				event.returnValue = false;
				return false;
			}
		}
	}
	
	
}

function FormataNumero2(teclapres)	 {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	
	if(parseInt(tecla) != 13){
		if((parseInt(tecla) < 48) || (parseInt(tecla) > 57)){
			event.returnValue = false;
			return false;
		}
	}
	return true;
}


function Substitui(vr,oldChar,newChar){
    var newString;
    var re = new RegExp(oldChar,"gi");
  	newString = vr.replace(re,newChar);
  	return newString;
}
        
//Limitador de tamanho de texto para campos do tipo Textarea	
function LimitaTextArea(tammax,teclapres){
	vr = event.srcElement.value;
	tam = vr.length;
	
	if (document.selection){ 
		txt = document.selection.createRange().text;
		if (txt.length > 0){
			document.selection.clear();
			vr = '';
			event.srcElement.value = '';
		}
	}	
	
	if (tam >= tammax){
		event.srcElement.value = event.srcElement.value.substr(0,tammax);
		return false;
	}
	return true;
}


function FormataCgc(tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (document.selection){ 
		txt = document.selection.createRange().text;
		if (txt.length > 0){
			document.selection.clear();
			vr = '';
			event.srcElement.value = '';
		}
	}
		
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		event.srcElement.value = vr ; }
	 	if ( (tam > 2) && (tam <= 6) ){
	 		event.srcElement.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		event.srcElement.value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		event.srcElement.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 13) && (tam <= 14) ){
	 		event.srcElement.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		event.srcElement.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}		
}




function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else
	countfield.value = maxlimit - field.value.length;
}
		

// Formata o CEP enquanto o usuário está digitando
function FormataCEP(objCampo,intKeyCode){
	if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
		return false
	}
	else
	{
		strValor = objCampo.value
		intLengthValor = parseInt(strValor.length)
		if(intLengthValor == 5){
			objCampo.value = strValor + "-"
		}
		return true
	}
}

// Formata o CPF enquanto o usuário está digitando
function FormataCPF(objCampo,intKeyCode){
	if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
		return false
	}
	else
	{
		strValor = objCampo.value
		intLengthValor = parseInt(strValor.length)
		if(intLengthValor == 3){
			objCampo.value = strValor + "."
		}
		if(intLengthValor == 7){
			objCampo.value = strValor + "."
		}
		if(intLengthValor == 11){
			objCampo.value = strValor + "-"
		}
		return true
	}
}

// Substitui caracteres de um determinado valor informado
function Substitui(strValor, strCaracterAntigo, strCaracterNovo){

	// Inicializa a variável
	strValorRetorno = ""

	// Percorre a string e utiliza seus caracteres
	for(x = 0; x < strValor.toString().length; x++){

		// Armazena o caracter corrente
		strCaracter = strValor.toString().substring(x, x + 1)

		// Verifica se o caracter corrente é igual ao caracter que deverá ser substituído e realiza as devidas manutenções
		if(strCaracter == strCaracterAntigo){
			strValorRetorno = strValorRetorno + strCaracterNovo
		}
		else
		{
			strValorRetorno = strValorRetorno + strCaracter
		}

	}

	// Retorna a string com os devidos caracteres substituídos, conforme a necessidade
	return strValorRetorno

}



// Função para máscara de CNPJ - Está função foi desenvolvida pelo João Paulo.

function FormataCNPJ(objCampo,intKeyCode){
	if(parseInt(intKeyCode) != 13){
		if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
			return false
		}
		else
		{
			strValor = objCampo.value
			intLengthValor = parseInt(strValor.length)
			if(intLengthValor == 2){
				objCampo.value = strValor + "."
			}
			if(intLengthValor == 6){
				objCampo.value = strValor + "."
			}
			if(intLengthValor == 10){
				objCampo.value = strValor + "/"
			}
			if(intLengthValor == 15){
				objCampo.value = strValor + "-"
			}
			return true
		}
	}
	else
	{
		return true
	}
}

//Mascara para formatar data enquanto digita
function FormataData(objCampo,intKeyCode){
      if(parseInt(intKeyCode) != 13){
          if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
              return false
          }
          else
          {
              strValor = objCampo.value
              intLengthValor = parseInt(strValor.length)
              if(intLengthValor == 2){
                  objCampo.value = strValor + "/"
              }
              if(intLengthValor == 5){
                  objCampo.value = strValor + "/"
              }
              return true
          }
  }
  else
  {
      return true
  }
}

function FormataNro(objCampo,intKeyCode){
	if(parseInt(intKeyCode) != 13){
		if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
			return false
		}
		else
		{
			return true
		}
	}
	else
	{
		return true
	}
}

/*ValidaQtde
Usada nos campos de qtde, ele garante que o valor
digitado não é maior que o estoque e que está ajustado ao fator
Para implementar: onBlur="ValidaQtde(this,this.value,fator.value,estoque.value)"
*/
function ValidaQtde(txtQtde, qtde, fator, estoque, aviso, intTipoProduto){

	//CHECA SE NAO É NULO
	if(qtde != '')
	{

		//TRATA CAMPOS
		qtde = qtde.replace(",", ".");
		fator = fator.replace(",", ".");
		estoque = estoque.replace(",", ".");
		if(parseFloat(fator) == 0)
		{
			fator = 1;
		}
		
		if(aviso == undefined)
		{
			aviso='';
		} 
		
		//VALIDA CAMPOS
		if (isNaN(qtde))
		{
			alert("caracter inválido!!")
			txtQtde.focus();
			txtQtde.value = '';
		}
		else
		{
			//VERIFICA FATOR
			qtde = parseFloat(qtde);
			r = qtde / fator;
			if(eval(parseInt(r)) == eval(r))
			{
				//resultado deu valor exato
				qtde = eval(r * fator).toFixed(2);
			}
			else
			{
				//resulatdo deu decimal
				qtde = eval(fator * (parseInt(r)+1)).toFixed(2);
				alert("A quantidade será ajustada para "+ qtde+".\n"+aviso);
			}
			
			
			if (!intTipoProduto || intTipoProduto == 1)
			{
				//VERIFICA ESTOQUE
				if (parseFloat(qtde) > parseFloat(estoque))
				{
					alert("No momento temos apenas "+estoque+" disponíveis.\n"+aviso)
					//txtQtde.focus();
					qtde=estoque;
				}
			}	
			
			//RE-TRATA CAMPO
			var n = qtde.toString();
			n = n.replace(".", ",");
			txtQtde.value = n;			
			
			return true
		}
	}
}

/*ValidaSomenteFator
Usada nos campos de qtde quando NAO PRECISA VALIDAR ESTOQUE(produtos encomenda offline), ele garante que o valor
digitado está ajustado ao fator
Para implementar: onBlur="ValidaSomenteFator(this,this.value,fator.value)"
*/
function ValidaSomenteFator(txtQtde, qtde, fator){

	//CHECA SE NAO É NULO
	if(qtde != '')
	{

		//TRATA CAMPOS
		qtde = qtde.replace(",", ".");
		fator = fator.replace(",", ".");
		if(parseFloat(fator) == 0)
		{
			fator = 1;
		}
		
		//VALIDA CAMPOS
		if (isNaN(qtde))
		{
			alert("caracter inválido!!")
			txtQtde.focus();
			txtQtde.value = '';
		}
		else
		{
			//VERIFICA FATOR
			qtde = parseFloat(qtde);
			r = qtde / fator;
			if(eval(parseInt(r)) == eval(r))
			{
				//resultado deu valor exato
				qtde = r * fator;
			}
			else
			{
				//resulatdo deu decimal
				qtde = eval(fator * (parseInt(r)+1));
				
				//chummers!!..isto é usado qdo o calculo sai errado.
				var decimais = new String(qtde)
				decimais = decimais.slice(eval(decimais.indexOf('.')+1), decimais.length);
				if(decimais.length > 2)
				{
					decimais = eval(parseInt(decimais.slice(0,2)) + 1);
					qtde = parseInt(qtde) + "," + decimais;
				}
				alert("A quantidade será ajustada para "+ qtde+".\n");
			}
			
			//RE-TRATA CAMPO
			var n = qtde.toString();
			n = n.replace(".", ",");
			txtQtde.value = n;
			
			return true
		}
	}
}

//---------------------------------------------------------------------------------
/*NaoPermiteNuloOuZero
Usada para validar um campo que nao pode ter valor = 0 ou '' 
Para implementar num botao: onBlur="ValidaQtde(document.all['" & txtNomeDaCaixa.ClientID & "'].value,'mensagem desejada de alerta')"
Para implementar na propria caixa: onBlur="ValidaQtde(this.value,'mensagem desejada de alerta')"
*/
function NaoPermiteNuloOuZero(valor, mensagem){
	if (valor == '' || valor < 0){
		alert(mensagem);
		return false;
	}
}
//---------------------------------------------------------------------------------
		
/*FormataNumeroDecimal
Aceita somente numeros e virgulas, mas 
não controla qtde de virgulas
Para implementar: onKeyPress="return FormataNumeroDecimal(this,event.keyCode);"
*/
function FormataNumeroDecimal(objCampo,intKeyCode){
	if(parseInt(intKeyCode) != 13){
		if(parseInt(intKeyCode) == 44){return true;}
		if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
			return false
		}
		else
		{
			return true
		}
	}
	else
	{
		return true
	}
}

/*Carrega Cliente
Carrega cliente de uma Pop Up para uma tela pai.
*/
function ValidaDadosEndereco(TipoLogradouro, Endereco, Bairro, Cidade, CEP, TipoEndereco, UF, DDDTel, Telefone){
	if (CEP == ''){
			alert('Digite o CEP!');
			return false;
	}
	if (CEP.length < 9){
			alert('CEP invalido!');
			return false;
	}
	if (TipoLogradouro == 0){
			alert('Selecione o Tipo de Logradouro!');
			return false;
	}
	if (Endereco == ''){
			alert('Digite o Endereco!');
			return false;
	}
	if (Bairro == ''){
			alert('Digite o Bairro!');
			return false;
	}
	if (Cidade == ''){
			alert('Digite a Cidade!');
			return false;
	}	
	if (TipoEndereco == 0){
			alert("Selecione o Tipo de Endereco!");
			return false;
	}
	if (UF == -1){
			alert('Selecione o Estado!');
			return false;
	}
	if (DDDTel == ''){
			alert('Digite o DDD Telefone!');
			return false;
	}
	if (Telefone == ''){
			alert('Digite o Telefone!');
			return false;
	}
}
	
function VerificaCampoBuscaProdutos(objCampo){
	if(objCampo.value == 'digite o produto...'){
	  objCampo.value="";
    return false;
    }
		
}

function IsNumerico(sText){

	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
 
	if (sText == ''){
		IsNumber = false
	}
	else{
		for (i = 0; i < sText.length && IsNumber == true; i++){ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1){
				IsNumber = false;
			}
		}
	}
	return IsNumber;
}

function ValidaBusca(txtBusca){

	var strCaracteres = new Array('%','_','<','>','[',']');
	var intTamanhoOriginal = txtBusca.value.length

	for (i = 0; i < strCaracteres.length; i++)
		txtBusca.value = Substitui(txtBusca.value, strCaracteres[i], '');
	
	if ((txtBusca.value.length < 2) && !(IsNumerico(txtBusca.value))){
		if (txtBusca.value.length == intTamanhoOriginal)
			alert('M\u00EDnimo 2 caracteres!');
		else
			alert('M\u00EDnimo 2 caracteres!\nN\u00E3o \u00E9 permitido buscas utilizando caracteres especiais!');
			
		return false;
	}
	return true;
}

function ValidaBuscaEnter(txtBusca, intKeyCode){

	if (intKeyCode == 13)
	{
		var strCaracteres = new Array('%','_','<','>','[',']');
		var intTamanhoOriginal = txtBusca.value.length

		for (i = 0; i < strCaracteres.length; i++)
			txtBusca.value = Substitui(txtBusca.value, strCaracteres[i], '');
	
		if ((txtBusca.value.length < 2) && !(IsNumerico(txtBusca.value))){
			if (txtBusca.value.length == intTamanhoOriginal)
				alert('M\u00EDnimo 2 caracteres!');
			else
				alert('M\u00EDnimo 2 caracteres!\nN\u00E3o \u00E9 permitido buscas utilizando caracteres especiais!');
				
			return false;
		}
		return true;
	}
	else
		return true;	
}

function FormataTexto(objCampo,intKeyCode){
	if(parseInt(intKeyCode) != 13){
		if(((parseInt(intKeyCode) > 64) && (parseInt(intKeyCode) < 91)) || ((parseInt(intKeyCode) > 96) && (parseInt(intKeyCode) < 123)) || ((parseInt(intKeyCode) == 32))){
	        return true
        }
        else{
	        return false
        }
    }
    else{
	    return true
	}
}

function ValidaDadosObter(CodProduto){
	if (CodProduto == ''){
			alert('Digite o Codigo do Produto!');
			return false;
	}
}

function ValidaDadosProduto(CodProduto, Quantidade, Descricao){
	if (CodProduto == ''){
			alert('Digite o Codigo do Produto!');
			return false;
	}
	if (Quantidade == ''){
			alert('Digite a Quantidade!');
			return false;
	}
	if (Descricao == ''){
			alert('Descrição não encontrada!');
			return false;
	}
}

function Redireciona(Ancora){
	window.location.hash = Ancora;
}

function RetornaDadosEndereco(pstrNomeCliente, pintCodigoCliente, pdecLimiteCreditohdn, pdecLimiteCredito, pstrOpcao){
	if (pstrNomeCliente != ""){
			if (pstrOpcao == ""){  						
				window.opener.document.getElementById('txtClientes').value = pstrNomeCliente; 
			}
			else{
				window.opener.document.getElementById('txtGrupoCliente').value = pstrNomeCliente; 
			}
	}
	if (pintCodigoCliente != 0){ 
		if (pstrOpcao == ""){  					
			window.opener.document.getElementById('hdnCodcliente').value = pintCodigoCliente;
		}
		else{
			window.opener.document.getElementById('hdnCodGrupoCliente').value = pintCodigoCliente; 
		}
	} 
	if (pdecLimiteCreditohdn != 0){	
		if (pstrOpcao == ""){
			window.opener.document.getElementById('hdnLimiteCredito').value = pdecLimiteCreditohdn;
		}
	}
	if (pdecLimiteCredito != 0){
		if (pstrOpcao == ""){
			window.opener.document.getElementById('txtLimite').value = pdecLimiteCredito;
		}
	}  
	window.close(); 
}

//Utilizada no cadastro de produtos ao se trocar o status do produto, exibe janela modal para justificativa do motivo da alteração
function alteraStatusProduto(codigoProduto)
{			
	var pobjSubmit = null
	
	window.Form1.document.all('stAntigo').value = window.Form1.document.all('stAnterior').value
	
	if (window.Form1.document.all('ddlStatus').value != "-1")
	{	
		pobjSubmit = window.showModalDialog('GravaLogAlteracao.aspx?stAnterior=' +
					                        window.Form1.document.all('stAnterior').value + 
					                        '&stPosterior=' +
					                        window.Form1.document.all('ddlStatus').value + 
					                        '&CodigoProduto=' +
											codigoProduto +
											'',self,'dialogHeight:328px;dialogWidth:515px;edge:Raised;center:Yes;scrollbars=no;help:No;resizable:No;status:No');
	}
}

function gravaStatusAnterior()
{
	window.Form1.document.all('stAnterior').value = window.Form1.document.all('ddlStatus').value
}	
//---------------------------------------------------------------------------------

function JuntaScriptsDeValidarQtde(caixaqtde, qtde, multembalagem, estoque, intTipoProduto)
{


	passo1 = NaoPermiteNuloOuZero(qtde, 'digite a quantidade');
	if(passo1 != false)
	{
		return ValidaQtde(caixaqtde, qtde, multembalagem, estoque, '', intTipoProduto);
	}
	else
	{
		return false;
	}
}

//------------------------------------------------------------------------------------------

function opencartaocec()
{
	strPagina = "/Ecommerce/CartaoVisa/CartaoVisa.aspx"
	intLargura = 700
	intAltura = 510
	booRolagem = "yes"
	winpop( strPagina, intLargura, intAltura, booRolagem )
}

function opencomandatuba()
{
	strPagina = "Ecommerce/Promocao/CadPromocao.aspx"
	intLargura = 760
	intAltura = 530
	booRolagem = "no"
	winpop( strPagina, intLargura, intAltura, booRolagem )
}

//------------------------------------------------------------------------------------------

