<!--

function Trim(texto)
{
	if ( texto == null || texto == "undefined")
	{
		return '';
	}

	var RE  = / /g;	
	var RE2 = /(\s)/g;
	return texto.replace(RE, '').replace(RE2, '');
}


function IsIgual(pvntParan1, pvntParan2){
  if(pvntParan1 == pvntParan2){
    return true;
  }
  return false;
}

function ValidaCPF(numero){
  dig_1 = 0;
  dig_2 = 0;
  controle_1 = 10;
  controle_2 = 11;
  lsucesso = 1;

  if ((numero.length != 12) ){
    alert("CPF inválido!");
    return false;
  }
  else {
    for (i=0 ; i < 9 ; i++){
      dig_1 = dig_1 + parseInt(numero.substring(i, i+1) * controle_1);
      controle_1 = controle_1 - 1;
    }

    resto = dig_1 % 11;
    dig_1 = 11 - resto;

    if ((resto == 0) || (resto == 1))
    dig_1 = 0;

    for ( i=0 ; i < 9 ; i++){
      dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
      controle_2 = controle_2 - 1;
    }

    dig_2 = dig_2 + 2 * dig_1;
    resto = dig_2 % 11;
    dig_2 = 11 - resto;

    if ((resto == 0) || (resto == 1))
    dig_2 = 0;

    dig_ver = (dig_1 * 10) + dig_2;

    if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))){
      alert("CPF inválido!");
      return false;
    }
  }
  return true;
} 



function iscgccpf(number, strTpPessoa) {

   var digit, cgc, i, j, b, s, numbers, replicated, tipo;
   numbers = '0123456789';
   replicated= '';
   digit = '';
   var tipo = ''   

   // Tira Pontos, Barras e Hífens do CGC //

   for (i=number.length-1; i>=0; i--) {
      if (numbers.indexOf(number.substr(i, 1)) < 0) 
         number = number.substr(0, i).concat(number.substr(i+1, number.length-i));
   }

   // Cria número de cgc/cpf repetido para teste de validade //

   for (i=0; i<number.length-2; i++)
      replicated = replicated.concat(number.substr(0, 1));
   // Testa se é cpf ou cgc //
   
   if (strTpPessoa == 'F'){
    tipo = 'CPF'
    if (number.length != 11){
      alert('O CPF deve ter no mínimo de 11 caracteres.');
      return false;
    }
   }
   else{
    tipo = 'CNPJ'
    if (number.length != 14){
      alert('O CNPJ deve ter no mínimo de 14 caracteres.');
      return false;
    }
   }
   
   
   if (number.substr(0, number.length-2) == replicated) {
      alert('Número inconsistente');
      return false;       
   }
   // Calcula Dígito //
   else {      
      cgc = number.substr(0, number.length-2);

      while (digit.length <2) {
         s = 0;
         b = 2;
         for (i=cgc.length-1; i>=0; i--) {
             s = s + b * cgc.substr(i, 1); 
             b = b + 1;
             if (number.length == 14 && b > 9)
                b = 2;
         }
         s = 11 - (s % 11);
         if (s > 9) s = 0;
         digit = digit.concat(s);
         cgc = cgc.concat(s);
      }

      // Verifica retorno //
      if (digit==number.substr(number.length-2, 2))
         return true;
      else {
         alert(tipo + ' inválido.');
         return false;
      }   
   }
}

//Nome: MoveNextField
//Parâmetros: input -- objeto que dispara o evento portando pode ser "this"
//Objetivo: mover o usuário para o proximo campo quando ele atingir o max length
//isso isso é controlado pelo tabIndex
function MoveNextField(input, e, len)
{
	var isNN    = (navigator.appName.indexOf("Netscape") != -1);
	
	if (e == null && !isNN) e = event;
	if (len == null) len = input.maxLength;	
	
	var keyCode = (isNN) ? e.which : e.keyCode; 
	
	var filter  = (isNN) ? [0,8,9,16] : [0,8,9,16,17,18,37,38,39,40,46];
	var x;

	if((input.value.length >= len) && (!containsElement(filter,keyCode)))
	{
		input.value = input.value.slice(0, len);
		if((input.form[(getIndex(input)+1) % input.form.length].disabled)== false)
		{
			input.form[(getIndex(input)+1) % input.form.length].focus();
			input.form[(getIndex(input)+1) % input.form.length].select();
		}
		else
		{
			if((input.form[(getIndex(input)+2) % input.form.length].disabled)== false)
			{
				input.form[(getIndex(input)+2) % input.form.length].focus();
				input.form[(getIndex(input)+2) % input.form.length].select();
			}
			else
			{
				input.form[(getIndex(input)+4) % input.form.length].focus();
				input.form[(getIndex(input)+4) % input.form.length].select();
			}
		}
	}
	
	function containsElement(arr, ele)
	{
		var index;
		
		for(index = 0; index < arr.length; index++)
			if(arr[index] == ele)
				return true;

		return false;
	}

	function getIndex(input)
	{
		var index = -1, i = 0, found = false;
		while ((i < input.form.length) && (index == -1))
		if (input.form[i] == input)
			index = i;
		else
			i++;
	
		return index;
	}
	return true;
}


/*
 '#DBC-2009-02-20-CMS-000038-PromocaoHP#{
 Esta função é responsável por verificar o limite de quantidade dos Sku´s 217572 e 217574
 Nota: Nesta data eu quebrei uma promessa de mais de sete anos, de nunca usar hardcode
       em programa algum, mas no caso da porcaria do código deste site não teve jeito.
       Sei que Deus vai me perdoar por isso.
*/
function ValidaPromocaoParceiro(obj,Sku,Parceiro)
{
	if (Parceiro == 'HP')
	{
		if((Sku == '217572' || Sku == '217574') && parseInt(obj) > 2)
		{
			alert('Quantidade limitada a 2 cartuchos na promoção.');
			obj.value = 2;
		}
    }
}
/*
#DBC-2009-02-20-CMS-000038-PromocaoHP#}
*/

//Nome: CalQuant
//Parâmetros: obj -- objeto que dispara o evento portando pode ser "this";
//            Acao -- Informar 'I' para aumentar ou D Diminuir.
//Objetivo: Modificar a quantidade do campo informado.
function CalQuant(obj,Acao,Sku,Parceiro)
{
	if (Acao == 'I')
	{
		if (parseInt(obj.value) < 999)
		{
		    obj.value = parseInt(obj.value) + 1;
			/*
			#DBC-2009-02-27-CMS-000038-PromocaoHP#{
			*/
			if (Parceiro == 'HP')
			{
				if((Sku == '217572' || Sku == '217574') && parseInt(obj.value) > 2)
				{
					alert('Quantidade limitada a 2 cartuchos na promoção.');
					obj.value = 2;
				}
		    }
			/*
			#DBC-2009-02-27-CMS-000038-PromocaoHP#}
			*/  
		}
	}
	else if (Acao = 'D')
	{
		if (parseInt(obj.value) > 1)
		    obj.value = parseInt(obj.value) - 1; 
	}
}

function validaOrdem(obj, saction, sWindowName)
{
    var link;
    
    if (sWindowName == null || sWindowName == "undefined")
    {
        sWindowName = "_top";
    }
    
    if (saction == null)
    {
        link = window.document.frmOrdena.action + "&sltOrdena=" + window.document.frmOrdena.sltOrdena.value;
    }
    else
    {
        if (saction.indexOf("sltOrdena") > 0)
        {
            link = saction;
        }
        else
        {
			if (window.document.frmOrdena.sltOrdena==null)
				link = saction;
			else
				link = saction + '&sltOrdena=' + window.document.frmOrdena.sltOrdena.value;
        }
    }
    window.open(link, sWindowName);
}

function VerQuants(pcampoprefix, purlAction) {
    var midx, mhid, mqty, mqtyalt;
    
    midx = 0;
    mqtyalt = 0;
    
    do{
        try{
           mhid = window.document.Produtos[pcampoprefix + '_hid_' + midx.toString()].value;
           mqty = window.document.Produtos[pcampoprefix + '_default_' + midx.toString()].value;
        }
        catch(e){
           mhid = null;
           mqty = null;
        }

        if(mhid != null && mqty != null){
            mhid = parseInt(mhid);
            mqty = parseInt(mqty);
            
            if(mhid != mqty){
               mqtyalt = 1;
               alert('Atenção! A quantidade de um ou mais produtos foi alterada. Clique sobre o botão atualizar valores.');
               break;
            };
        };
        
        midx += 1;
    }while((mhid != null || mqty != null) && mqtyalt == 0);
    
    if(mqtyalt == 0){
        window.location = purlAction;
    }
}
function EnableKey(intKeyCodeValue,strRange,strOthers)
{
   
   //Esta função impede que o usuário digite um valor que não é esperado para o campo.
   //
   //intKeyCodeValue = event *** o primeiro parâmetro desta função deve ser a palavra chave event,
   //                            para que possamos identificar qual tecla foi pressionada.
   //                            
   //strRange  *** strRange são os valores das chaves que estão habilitadas. Esta variável deve conter dois números
   //              inteiros representando o código ASCII da tecla, separados pelo sinal de ':'(dois pontos).
   //              Serão habilitadas todas as teclas que forem maiores ou iguais ao primeiro valor(valor antes dos
   //              dois pontos) e menores ou iguais ao segundo valor (valor após os dois pontos).
   //              Caso o segundo valor seja maior que o primeiro, os valores serão trocados.
   //
   //strOthers *** strOthers é dividido por ponto-e-vírgulas(;). Os valores ASCII contidos em strOthers são excessões e quando
   //              pressionados serão exibidos mesmo que não esteja no escopo do parâmetro strRange.
   //              OBS***PASSE PARA strOthers OS CARACTERS ASCII!!!
   
   
   strRange = strRange.split(":");
   var intFirst = strRange[0];
   var intEnd   = strRange[1];
   var intAux;
   
   if(strOthers.length>0)
   {
      strOthers = strOthers.split(";")
   }
   if(!(isNaN(intFirst) && isNaN(intEnd)))
   {
      if(intEnd < intFirst)
      {
         intAux   = intFirst;
         intFirst = intEnd;
         intEnd   = intAux;
      }
      if((intKeyCodeValue.keyCode < intFirst) || (intKeyCodeValue.keyCode > intEnd))
      {
         if(strOthers.length < 1)
         {
            intKeyCodeValue.keyCode = false;
         }
         
         intAux=0;
         for(var i=0; i<strOthers.length; i++)
         {
            if(!(isNaN(strOthers[i])))
            {
               if(intKeyCodeValue.keyCode == strOthers[i])
               {
                  intAux += 1;
               }
            }
         }
         if(intAux==0)
         {
            intKeyCodeValue.keyCode = false;
         }
      }
   }
}

function trim(value) {
	var result = new String(value);
	
	result = rtrim(result);
	result = ltrim(result);
	
	return result;
}

function rtrim(value) {
	var result = new String(value);	
	var index = result.length;
	var chr = result.substring(index-1,index);
	
	if (chr == ' ') {
		return rtrim(result.substring(0, result.length-1))
	} else {
		return value;
	}
}

function ltrim(value) {
	var result = new String(value);	
	var index = result.length;
	var chr = result.substring(0,1);
	
	if (chr == ' ') {
		return rtrim(result.substring(1, result.length))
	} else {
		return value;
	}
}

function validateField(field, errorMsg) {
	value = field.value;
	
	if (isEmpty(value))	{
		field.value = '';
		alert(errorMsg);
		field.focus;
		return false;
	}	
	return true;
}

function isEmpty(value) {
	return ((value == null) || (trim(value)==''));
}

function cotacao_atualizar() {
	var frmCotacao = window.document.frmCotacao;
		
	var txtAction	     = frmCotacao.hdnAction;
	var txtSearchArgs	 = frmCotacao.hdnSearchArgs;
	
	txtAction.value       = 'UPDATE';
	txtSearchArgs.value	  = document.getElementById('cotacao_Search').value;
	
	frmCotacao.submit();
}

function cotacao_deleteItem(ProductId, CategoryName, PoIndex) {
	var frmCotacao = window.document.frmCotacao;
		
	var txtProduct	     = frmCotacao.hdnProductId;
	var txtCategoryName  = '';//formProdCotacao.hdnCategoryName;
	var txtAction	     = frmCotacao.hdnAction;
	var txtPoIndex	     = frmCotacao.hdnPoIndex;
	var txtSearchArgs	 = frmCotacao.hdnSearchArgs;
	
	txtProduct.value      = ProductId;
	txtCategoryName.value = CategoryName;
	txtAction.value       = 'REMOVE';
	txtPoIndex.value      = PoIndex;
	txtSearchArgs.value	  = document.getElementById('cotacao_Search').value;
	
	frmCotacao.submit();
}

function cotacao_itemEscolhido(sender, sProductId, sCategoryName)
	{
	var objReturn = new Object();
	objReturn.ProductId    = sProductId;
	objReturn.CategoryName = sCategoryName;
	
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			window.returnValue  = objReturn;	
			window.close();
		} 
		else 
		{
			if (sProductId != "") 
			{
		 
				window.parent.opener.document.forms[1].hdnProductId.value =  sProductId;
				window.parent.opener.document.forms[1].hdnCategoryName.value = sCategoryName;
				window.parent.opener.document.forms[1].hdnAction.value  = 'INSERT';
				//window.parent.opener.document.forms[0].hdnSearchArgs.value = 'teste'; // document.getElementById('cotacao_Search').value;

				window.parent.opener.document.forms[1].submit();
				 top.window.close();	
			}
		}
	}
this.GetElementByID = function(ID)
     {
         var elemento = null;
         
         try
         {
                if( document.layers) 
                {   
                    elemento = document.layers[ID];
                }
                else if(document.all)
                {
                    elemento = document.all[ID];
                    
                }
                else if(document.getElementById)
                {
                    elemento = document.getElementById(ID);
                }
                return elemento;
            }
            catch(e)
         {
            alert('Atenção:\n\nOcorreu um no método GetElementByID.Detalhes:\n' + e.description);
             return false;
         }
     }
     


function cotacao_openSearchWindow() {
	
	if (navigator.appName == "Microsoft Internet Explorer")
		{
			var objArguments = new Object();
			var searchField = document.getElementById('cotacaoSearch');
				
			if (!validateField(searchField , 'Favor fornecer um valor para a busca.')) {		
				return;
			}

			var criteria = new String(searchField.value);
	
			objArguments.SearchCriteria = criteria;	
			var window_url = '/cotacao/cotacao_frame.asp?keyword=' + criteria;
			var windowAttributes = 'edge:Raised; resizable:no; Status:no; dialogHeight:600px; dialogWidth:800px';
     		var objReturnValues  = window.showModalDialog(window_url, objArguments, windowAttributes);
     		
     		
     		if (objReturnValues != null) 
			{
			  
				var frmCotacao  = window.document.frmCotacao;
				
				
				var txtProduct	     = frmCotacao.hdnProductId;
				var txtCategoryName  = '';//formProdCotacao.hdnCategoryName;
				var txtAction	     = frmCotacao.hdnAction;
				var txtSearchArgs	 = frmCotacao.hdnSearchArgs;
	
				txtProduct.value      = objReturnValues.ProductId;
				txtCategoryName.value = objReturnValues.CategoryName;
				
				
				txtAction.value       = 'INSERT';
				txtSearchArgs.value	  = document.getElementById('cotacao_Search').value;
				
				frmCotacao.submit();
			}
		} 
		else 
		{
			var objArguments = new Object();
			var searchField = document.getElementById('cotacaoSearch');
				
			if (!validateField(searchField , 'Favor fornecer um valor para a busca.')) {		
				return;
			}

			var criteria = new String(searchField.value);
			objArguments.SearchCriteria = criteria;	
			var window_url = '/cotacao/cotacao_frame.asp?keyword=' + criteria;
			var windowAttributes = 'edge=Raised, resizable=no, Status=no, height=600, width=850';
			
				var wint=(screen.width - 850) /2;
				var winl=(screen.height - 600) /2;
				
				winprops='height='+ 600 +', width ='+ 850 +', top='+ wint +',left='+ winl + ',location=no,status=no';
				win=window.open(window_url,objArguments,winprops);
				If (parseint(navigator.appVersion)>=4)
				{
				win.window.focus();
				}
			
			//window.open(window_url, objArguments,windowAttributes);
		
		}
	
}


function cotacao_viewDetails(CotacaoId, bImprimir) {
	windowFeatures = 'width=800,height=600,location=no,titlebar=no,status=no,toolbar=no,scrollbars=yes';
	window.open('/cotacao/cotacao_details.asp?CotacaoId=' + CotacaoId + '&VersionPrint=' + bImprimir, 'CotacaoDetails', windowFeatures);
}

function cotacao_sendMail(CotacaoId) {
	windowFeatures = 'width=450,height=350,location=no,titlebar=no,status=no,toolbar=no';
	window.open('/cotacao/cotacao_mail.asp?CotacaoId=' + CotacaoId, 'CotacaoMail', windowFeatures);
}

function cotacao_setNewSearch() {
	var txtPage = document.getElementById("hdnPage")
	txtPage.value = 1;
}
function cotacao_setActionLastPage() {
	setAction('LAST');
}

function cotacao_setActionNextPage() {
	setAction('NEXT');
}

function setAction(value) {	
	var txtAction = document.getElementById("hdnAction")
	txtAction.value=value;
}

function cotacao_efetuarCompra() {
	var txtAction = frmCotacao.hdnAction;
	txtAction.value = 'BUY';
	frmCotacao.submit();
}


function cotacaoMail_ValidateForm()
{
    var txtEmails = document.getElementById("txtEmail")
    var email     = txtEmails.value;
    var retorno   = false;
    
    if (Trim(email) == "")
    {
        alert("Informe o email ao qual deseja enviar a cotação");
        txtEmails.focus();
        return false;
    }
    
    //valida email
    retorno = emailValidate(email, 'ATENÇÃO: foram encontrados e-mails com erros de digitação ou inválidos.'); 
    
    if (!retorno)
    {
        txtEmails.focus();
        return retorno;
    }
    
    return true;
}




function estoqueLoja_openSearchWindow() 
{
	
	if (navigator.appName == "Microsoft Internet Explorer")
		{

			var objArguments = new Object();
			var searchField = document.getElementById('cotacaoSearch');
			
			var QtdProduto    = document.forms["frmCotacao"].hdnQtdProdMax;
			var QtdProdutoMax = document.forms["frmCotacao"].hdnQtdProd;
			
			if (QtdProduto.value <= QtdProdutoMax.value)
			{
			    alert("Somente é permitido consultar " + QtdProdutoMax.value + " produtos por vez\n" + 
			          "Exclua um ou mais produtos e tente novamente." );
			    return;
			}
			
			if (!validateField(searchField , 'Favor fornecer um valor para a busca.')) {		
				return;
			}
			
			var criteria = new String(searchField.value);
			objArguments.SearchCriteria = criteria;	
			
			var window_url = '/cotacao/cotacao_frame.asp?keyword=' + criteria;
			var windowAttributes = 'edge:Raised; resizable:no; Status:no; dialogHeight:600px; dialogWidth:800px';
			
			var objReturnValues  = window.showModalDialog(window_url, objArguments, windowAttributes);
			
			
			if (objReturnValues != null) {
				var frmCotacao  = window.document.frmCotacao;
				
				var txtProduct	     = frmCotacao.hdnProductId;
				var txtCategoryName  = '';//formProdCotacao.hdnCategoryName;
				var txtAction	     = frmCotacao.hdnAction;
				var txtSearchArgs	 = frmCotacao.hdnSearchArgs;
			
				txtProduct.value      = objReturnValues.ProductId;
				txtCategoryName.value = objReturnValues.CategoryName;
				txtAction.value       = 'INSERT';
				txtSearchArgs.value	  = document.getElementById('cotacao_Search').value;
				
				frmCotacao.submit();
			}
		}
		else 
		{
			var objArguments = new Object();
			var searchField = document.getElementById('cotacaoSearch');
				
			if (!validateField(searchField , 'Favor fornecer um valor para a busca.')) {		
				return;
			}

			var criteria = new String(searchField.value);
			objArguments.SearchCriteria = criteria;	
			var window_url = '/cotacao/cotacao_frame.asp?keyword=' + criteria;
			var windowAttributes = 'edge=Raised, resizable=no, Status=no, height=600, width=850';
			
				var wint=(screen.width - 850) /2;
				var winl=(screen.height - 600) /2;
				
				winprops='height='+ 600 +', width ='+ 850 +', top='+ wint +',left='+ winl + ',location=no,status=no';
				win=window.open(window_url,objArguments,winprops);
				If (parseint(navigator.appVersion)>=4)
				{
				win.window.focus();
				}
			
			//window.open(window_url, objArguments,windowAttributes);
		
		}	
}
function estoque_atualiza_loja()
{
    if ((document.frmCotacao.hdnQtdProd.value == null) || (document.frmCotacao.hdnQtdProd.value == 0))
    {
        alert("Para continuar a consulta é necessário inserir no mínimo um produto na lista.");
        //document.frmCotacao.cmbLojas.selectedIndex = 0  
        return false;
    }
    document.frmCotacao.submit();
}


function consulta_estoque_loja()
{
    frmCotacao.hdnAction.value = "estoque_result"
    //frmCotacao.submit();
}

function Estoque_loja_key_down(event)
{
    //if (event.keyCode == 13)
    //{
    //   consulta_estoque_loja();
    //}
}

function consulta_estoque_nova_consulta()
{
    frmCotacao.hdnAction.value = "NOVA_CONSULTA"
    frmCotacao.cmbLojas.selectedIndex = 0 ;
}

function checkSearchText(txtSearch){
	if (rtrim(ltrim(txtSearch.value)).length < 2){
		alert("A palavra a ser procurada deve ter no mínimo duas letras.");
		return false;
	}
	else{
		return true;
	}
}

function Abre_Chat(){
	intTop  = (screen.availHeight - 390) / 2;
	intLeft = (screen.availWidth  - 430) / 2;	
	//strParam = "scrollbars=no,height=390,width=420,location=no,menubar=no,resizable=no,titlebar=no,toolbar=no,left=" + intLeft + ",top=" + intTop;		
	//window.open('../chat/default.asp?chapa=kalunga', 'janelaCliente', strParam);
	
	strParam = "scrollbars=no,height=390,width=430,location=no,menubar=no,resizable=no,titlebar=no,toolbar=no,left=" + intLeft + ",top=" + intTop;		
	window.open('http://chat.kasolution.com.br/default.asp?chapa=kalunga', 'janelaCliente', strParam);
}


function chk_num(caracter)
  {
	if (caracter == null) {caracter = ''}
	goodChars = "0123456789"
	goodChars += caracter
	
	caracDigit = String.fromCharCode(window.event.keyCode)
	
	if (goodChars.indexOf(caracDigit) == -1)	
		{window.event.returnValue = false}
  }
  
 function Enviar(){
   
   if (frmContato.IsContrato.value == "false" ||  frmContato.IsContrato.value == "")
   {
      if (frmContato.txtNomeContato.value == "")
         {alert ('Favor Preencher o Nome');return}
   }
   else
   {
      if (frmContato.txtNomeContato.value == "")
         {alert ('Favor Preencher o Campo Empresa');return}
   } 
   
   if (frmContato.txtEmail.value == "")
      {alert ('Favor Preencher o Email');return}   
   if (checkEmail(frmContato.txtEmail) == false)
	  {return}
   if (frmContato.sel_Assunto.value == "")
      {alert ('Favor Preencher o Departamento e o Assunto');return}   
   if ( (frmContato.txtMensagem.value == "") && (frmContato.IsContrato.value == "false" ||  frmContato.IsContrato.value == ""))
      {alert ('Favor Preencher a Mensagem'); return}

   if (frmContato.IsContrato.value == "false" ||  frmContato.IsContrato.value == "")
   {
        frmContato.hdTextAssunto.value = frmContato.sel_Assunto.item(frmContato.sel_Assunto.selectedIndex).text
   }
   
   frmContato.blnEnviar.value = "S"
   frmContato.submit()

}

function mudaLabelMensagem()
{
    if (frmContato.IsContrato.value == "false" ||  frmContato.IsContrato.value == "")
    {
        var lblm = document.getElementById("lblMensagem");
        if (lblm != null)
        {
            if (frmContato.sel_Assunto.item(frmContato.sel_Assunto.selectedIndex).value == "29")
            {
                lblm.innerText = "Motivo do Cancelamento:"
            }
            else
            {
                lblm.innerText = "Mensagem:"
            }
        }
    }
}

function garantiaEstendida()
{
    window.open("popupEGarantia.htm", "carantiaEstendida", "width=450,height=500,status=no,scrollbars=yes,top=80,left=80");
}


function garantiaEstendidaFormaPagto(sProduto, sProdutoTerceiro, sPlano, sExibePrecoTradeIn)
{	
    var url  = "sProduto=" + sProduto + "&" 
        url  = url + "sPT=" + sProdutoTerceiro + "&" 
        url  = url + "sPTPlano=" + sPlano + "&" 
        url  = url + "blnTradeIn=" + sExibePrecoTradeIn
        

    url = "popegplanos.asp?" + url
    window.open(url, "carantiaEstendida", "width=380,height=280,status=no,scrollbars=yes,top=80,left=80");
}


function garantiaCertificados(CodigoPedido)
{
	//----------------------------------------
	// Se for necessario alterar esta funcao, deve-se alterar 
	// também as cópias que estao em:
	//		/include/i_javascript.js
	//		/services/include/render_orders.asp
	//		/popupEGarantia.htm
	//----------------------------------------
	var url  = "Pedido="+ CodigoPedido

	url = "../../popEgTermoGarantia.asp?"+ url
	window.open(url, "CertificadoGarantia", "width=800,height=600,status=no,scrollbars=yes,top=0,left=0");
}



// Autor: Eric
// retorna true se o codigo da string for de um numero.
function isNumericCode(i)
{
 if (i >= 96 && i <= 105)
    return true;
    
 if (i >= 48 && i <= 57)
    return true;
    
    
    return false;
}

// parametros
// keyCode = Código do caractere 
// altSelected (Opcional) = Boolean que representa a tecla alt pressionada
// ctrlSelected (Opcional) = Boolean que representa a tecla ctrl pressionada
// shiftSelected (Opcional) = Boolean que representa a tecla shift pressionada
// CCP_Constante (Opcional Default 0) = define se é permitido atalho de copiar e colar.
// = 0 - Não permite copiar e colar (default)
// = 1 - Permite apenas copiar
// = 2 - Permite apenas colar
// = 3 - Permite copiar e colar
function IsEspecialKeys(keyCode, altSelected, ctrlSelected, shiftSelected, PermitirSpacos, CC_Constante)
{

 var retorno = false;
 
 if (altSelected    != true) altSelected    = false;
 if (ctrlSelected   != true) ctrlSelected   = false;
 if (shiftSelected  != true) shiftSelected  = false;
 if (PermitirSpacos != true) PermitirSpacos = false;
 if (isNaN(CC_Constante) == true) CC_Constante  = 0;
 
 //shift
 switch(keyCode)
 {
    case 18: retorno  = true; break; // alt
    case 17: retorno  = true; break; // ctrl
    case 16: retorno  = true; break; // shift
    case 20: retorno  = true; break; // capslock
    case 9: retorno   = true; break; // tab
    case 8: retorno   = true; break; // backspace
    case 46: retorno  = true; break; // delete
    case 45: retorno  = true; break; // insert
    case 35: retorno  = true; break; // end
    case 36: retorno  = true; break; // home
    case 13: retorno  = true; break; // enter
    case 145: retorno = true; break; //scroll lock
    case 19: retorno  = true; break; //pause
    case 37: retorno  = true; break; // esquerda
    case 38: retorno  = true; break; // para cima
    case 39: retorno  = true; break; // direita
    case 40: retorno  = true; break; // para baixo
    case 144: retorno = true; break; // num lock
 }
 
 
 // special 
 if ( ((ctrlSelected  == true && keyCode == 67) && (CC_Constante == 1 || CC_Constante  == 3)) || // copiar
      ((ctrlSelected  == true && keyCode == 86) && (CC_Constante == 2 || CC_Constante == 3)) || // colar
      (PermitirSpacos == true && keyCode == 32) || // Permitir Espacos em branco
      (ctrlSelected   == true && keyCode == 37) || // ctrl + esquerda
      (ctrlSelected   == true && keyCode == 39))   // ctrl + direita
    {
        retorno = true;
    }
 return retorno;
 
}

/*****************************************************
*********  Codificação para SubMenu  *****************
*****************************************************/

var MenuAnteriorItemID = null;
var MenuAnteriorTDID   = null;
var setTimeOutHandler  = null;

function CancelPopUpHidden()
{
    if (setTimeOutHandler != null)
    {
        window.clearTimeout(setTimeOutHandler);
        setTimeOutHandler = null;
    }
}

/*Primeira função a ser chamada quando clicado na página*/
function CategoryMenuSubItemPopUp(oSource, oPopupObject, vWidth, vHeight)
{  
    CreateContextPopUp(1, oSource, oPopupObject, null, null, vWidth, vHeight);
    CancelPopUpHidden();
    
    MenuAnteriorItemID  = oPopupObject;
    MenuAnteriorTDID    = oSource;
}

function CategoryMenuSubItemHiddenPopUp(evt)
{
/*
    var oPopUp  = null; 
    var oTarget = GetEventTarget(evt);
    
    if (MenuAnteriorItemID == null) 
        return;
        
    if ( (oTarget.id == MenuAnteriorItemID) ||
         (oTarget.id == MenuAnteriorTDID))
         return;
  
  */       
    
    oPopUp = document.getElementById(MenuAnteriorItemID);

    if (oPopUp == null)
        return;
    
    oPopUp.style.display = "none";
    MenuAnteriorItemID = null
    MenuAnteriorTDID   = null
}

function CreateContextPopUp(tp, oSource, oPupUpObject, vX, vY, vWidth, vHeight)
{
    var sc      = CrossBrowser_Screen();
    var LeftFix = 0;
    var vWidth  = 0;
    var vX1     = vX;
    var vY1     = vY; 
    var PodeDes = false;
    
    oSource      = document.getElementById(oSource);
    oPupUpObject = document.getElementById(oPupUpObject);
    
    if (tp == 1)
    {
        if (vY == null) 
            vY = 0;
        if (vX == null)
            vX = 0;
                        
        vY += (oSource.offsetTop + oSource.offsetHeight)
        vX += (oSource.offsetLeft) // + oSource.offsetWidth)
    }
   
    if (!(oPupUpObject == null))
    {
        if (oPupUpObject.style.display == "none")
        {
            oPupUpObject.style.display = "block";
            vWidth                     = oPupUpObject.offsetWidth;
            vHeight                    = oPupUpObject.offsetHeight;
            
            oPupUpObject.onmouseover = function(evt){PodeDes = true;}
            
            // OnClick dos itens do submenu
            document.body.onclick = 
                function(evt)
                {
                    if (MenuAnteriorTDID != null) 
                    {
                        var obj = GetEventTarget(evt);
                        if (! (obj.id == MenuAnteriorTDID))
                        {
                            CancelPopUpHidden();
                            void CategoryMenuSubItemHiddenPopUp();
                        }
                    }
                }
            
            document.onmousemove = 
                function(evt)
                {
                    var cursorX, cursorY;
                    
                    if (document.all) {
                        evt = event;
                        cursorX = evt.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
                        cursorY = evt.clientY + document.documentElement.scrollTop + document.body.scrollTop;
                    }
                    else {
                        cursorX = evt.clientX + window.scrollX;
                        cursorY = evt.clientY + window.scrollY;
                    }

                    
                    if (! (oPupUpObject.style.display == "none") && 
                          (PodeDes == true))
                    {
                            
                        if ( (cursorX < vX)           ||
                             (cursorX > vX + vWidth)  ||
                             (cursorY < vY)           ||
                             (cursorY > vY + vHeight))
                        {
                            if (setTimeOutHandler == null)
                            {
                                setTimeOutHandler = window.setTimeout('void CategoryMenuSubItemHiddenPopUp()', 1000);
                            }
                            //void CategoryMenuSubItemHiddenPopUp()
                        }                
                        else
                        {
                            if (setTimeOutHandler != null)
                            {
                                CancelPopUpHidden();
                            }
                            
                        }
                    }
                }
        }
        else
        {
            oPupUpObject.style.display = "none";
            return;
        }
    }
    
    if (!(document.all))
    {
            LeftFix = 0;
    }
    
    /*** Faz o menu ficar alinhado a direita ****/
    vX = (sc.width - parseInt(vWidth) - 21)
    
    /*
    // Faz o menu ficar alinhado a direita (codigo Eric)
    
    if( (parseInt(vX)+parseInt(vWidth)) > sc.width)
    {
        vX = (sc.width - parseInt(vWidth) - 22)
    }
    else    
    {
        vX = (sc.width - parseInt(vWidth) - 22)
    } 
    */  
    
    if (! (oPupUpObject == null))
    {
        if(vY = 135)
        {
            vY = 139;
        }
        
        oPupUpObject.style.position  = "absolute";
        oPupUpObject.style.top       = vY - 3;
        oPupUpObject.style.left      = vX;
    }
} 


/** crossbrowser functions **/

function GetEventTarget(evt)
{
    if (evt == null)
    {
        evt = event;
    }

    if (evt.srcElement)
    {
        return evt.srcElement;
    }
    else
    {
        return evt.target;
    }
        
    return null;
}

function CrossBrowser_Screen()
{
    var o = new Object();
    
    o.screenWidth  = screen.width;
    o.screenHeight = screen.height;
    
    o.availWidth  = screen.availWidth
    o.availHeight = screen.availHeight
    

    
    if (document.all)
    {
        o.width  = document.body.offsetWidth
        o.height = document.body.offsetHeight
        o.left = window.screenLeft
        o.top  = window.screenTop
    }
    else
    {
        o.width  = window.innerWidth
        o.height = window.innerheight
        o.left = window.screenX
        o.top  = window.screenY
    }
    return o;
}


// Autor: Eric
// Retorna um objeto com as propriedades do evento keyup key, down e keypress
// evitando tratametnos para firefox e ie sempre
// que utilizado este evento
function CrossBrowserEvent_KeyEvents(e, PermitirSpacos, CC_Constante)
{
    var evt   = null;
    var valor = null;
    var t     = new Object();
    
    if (window.event)
        evt = event;
    else
        evt = e;    
       
    if (evt == null)
        return null;

    if (evt.keyCode)
        valor = evt.keyCode;
    else
        valor = evt.which;
    
    if (evt.srcElement)
        t.source    = evt.srcElement;
    else
        t.source    = evt.target;
    
    t.event        = evt;
    t.getType      = 'Precisa ser sobrescrito na chamada filha';
    t.getValue     = valor;
    t.getKeyCode   = valor;
    t.getString    = String.fromCharCode(valor); 
    t.ToString     = function(){return String.fromCharCode(valor)} 
    
    t.IsALTDown    = evt.altKey;
    t.IsCTRLDown   = evt.ctrlKey;
    t.IsSHIFTDown  = evt.shiftKey;
   
    t.IsNumeric    = isNumericCode(valor);
    t.EspecialKeys = IsEspecialKeys(valor, evt.altKey, evt.ctrlKey, evt.shiftKey, PermitirSpacos, CC_Constante);
    return t;
}

/** EVENT FUNCTIONS **/    
// Autor: Eric
// Retorna um objeto com as propriedades do evento
// evitando tratametnos para firefox e ie sempre
// que utilizado este evento.
function CrossBrowserEvent_KeyDown(e, PermitirEspacos, CC_Constante)
{                       
    var CrossEvent = CrossBrowserEvent_KeyEvents(e, PermitirEspacos, CC_Constante);
    CrossEvent.getType = 'keydown';
    return CrossEvent;
}

// Autor: Eric
// Retorna um objeto com as propriedades do evento
// evitando tratametnos para firefox e ie sempre
// que utilizado este evento.
function CrossBrowserEvent_Keyup(e, PermitirEspacos, CC_Constante)
{
    var CrossEvent = CrossBrowserEvent_KeyEvents(e, PermitirEspacos, CC_Constante);
    CrossEvent.getType = 'keyup';
    return CrossEvent;
}

// Autor: Eric
// Retorna um objeto com as propriedades do evento
// evitando tratametnos para firefox e ie sempre
// que utilizado este evento.
function CrossBrowserEvent_KeyPress(e, PermitirEspacos, CC_Constante)
{
    var CrossEvent = CrossBrowserEvent_KeyEvents(e, PermitirEspacos, CC_Constante);
    CrossEvent.getType = 'keypress';
    return CrossEvent;
}

//#DBC-2009-09-03-CMS-000082-SiteEstatística#{
function abrirPopUpResumoVendas(sSubGrupo)
{	
    var url  = "sSubGrupo=" + sSubGrupo        
    url = "/include/resumoanual.asp?" + url
    window.open(url, "resumoAnual", "width=1010,height=120,status=no,scrollbars=yes,top=100,left=0");
}
//#DBC-2009-09-03-CMS-000082-SiteEstatística#}

//Usado para exibir os nomes dos campos
//document.onclick = 
//function(e)
//{
//  alert(e.target.name);
//}
-->
