﻿function stopError() {
 	 return true;
 }
 
window.onerror = stopError;

//Seta o texto do botao de Lance 
function VerificaStatusLogado(logado, obj)
{    
    var btn = document.getElementById(obj);
    
    if(btn)
    {
        if(logado == 'N')
        {
            btn.value = 'Entrar';            
        }
        else {
           btn.value = 'Lance';
        }
    }
}
//FIM Seta o texto do botao de Lance 

//DESABILITA BOTAO DIREITO
function mouseDown(e) {
 if (parseInt(navigator.appVersion)>3) {
  var clickType=1;
  if (navigator.appName=="Netscape") clickType=e.which;
  else clickType=event.button;
  if (clickType!=1) {
   
   return false;
  }
 }
 return true;
}
if (parseInt(navigator.appVersion)>3) {
 document.onmousedown = mouseDown;
 if (navigator.appName=="Netscape") 
  document.captureEvents(Event.MOUSEDOWN);
}


function decimal(evt,obj){
    var key_code = evt.keyCode  ? evt.keyCode  :
                   evt.charCode ? evt.charCode :
                   evt.which    ? evt.which    : void 0;

    // Habilita teclas <DEL>, <TAB>, <ENTER>, <ESC> e <BACKSPACE>
    if(key_code == 8  ||  key_code == 9  ||  key_code == 13  ||  key_code == 27) return true;
    
    // Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
    if((key_code >= 35)  &&  (key_code <= 40)) return true;

    // Habilita números de 0 a 9
    if((key_code >= 48)  &&  (key_code <= 57)) return true;

    // Bloqueia mais de um carcter ,
    if((obj.value.indexOf(',') > -1) && (key_code == 44)) return false;
    
    // Habilita carcter ,
    if(key_code == 44) return true;

    return false;
}

function numeric(evt){
    var key_code = evt.keyCode  ? evt.keyCode  :
                   evt.charCode ? evt.charCode :
                   evt.which    ? evt.which    : void 0;

    // Habilita teclas <DEL>, <TAB>, <ENTER>, <ESC> e <BACKSPACE>
    if(key_code == 8  ||  key_code == 9  ||  key_code == 13  ||  key_code == 27) return true;
    
    // Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
    if((key_code >= 35)  &&  (key_code <= 40)) return true;

    // Habilita números de 0 a 9
    if((key_code >= 48)  &&  (key_code <= 57)) return true;

    return false;
}

function nextObj(evt,Obj,max){
    try
    {
        var key_code = evt.keyCode  ? evt.keyCode  :
                       evt.charCode ? evt.charCode :
                       evt.which    ? evt.which    : void 0;

        if(key_code == 13){
            _nextObj(Obj);
        }
        
        if(max > 0){
            if(Obj.value.length == max){
                _nextObj(Obj);
            }
        }
    }
     catch(e) {}
}

function _nextObj(Obj){
 try
    {
    var nextObj = 0;
    var aObj = document.getElementsByTagName('*');
    
	for(var i = 0 ; i < aObj.length ; i++){
	    var getObj = aObj[i];
        if (getObj.type == 'text' || getObj.type == 'textarea' || getObj.type == 'radio' || getObj.type == 'select-one' || getObj.type == 'password' || getObj.type == 'image'){
            if(nextObj == 1){
                if(getObj.type == 'image'){
                    getObj.click();
                    break;
                }else{
                    getObj.focus();
                    break;
                }
            }
            
            if(Obj == getObj){
                nextObj = 1;
            }
        }
	}
	}
     catch(e) {}
}

//Seta imagem
function CarregaImagem(img,ctr) {

     var Obj = document.getElementById(ctr)
           
    if (Obj) {
        if(img != ''){
            Obj.src = img;
        }                 
    }
}

//Seta Imagem Botao
function AlternaImagemBotao(obj){
    obj.style.background = "url('DefaultImg/BotaoLance_Acao.gif')";
}

//IE e firefox
function AcaoBotao(evt, campo){
 var key_code = evt.keyCode  ? evt.keyCode  :
                   evt.charCode ? evt.charCode :
                   evt.which    ? evt.which    : void 0;

    if(key_code == 13){         
          var bt = document.getElementById(campo);
          bt.click();
    }
}

//Mostra Menu categ 
function showMenuC(campo, disp, home, categ, minhaconta, ajuda, leilaoaovivo, proximos, falaconosco, camsite){
    var obj = document.getElementById(campo);
    var imgHome = document.getElementById(home);
    var imgCateg = document.getElementById(categ);
    
    var imgMinhaconta = document.getElementById(minhaconta);
    var imgAjuda = document.getElementById(ajuda);
    var imgLeilaoaovivo = document.getElementById(leilaoaovivo);
    var imgProximos = document.getElementById(proximos);
    var imgFalaconosco = document.getElementById(falaconosco);
    
    var Ocamsite = document.getElementById(camsite);
     
    try
    {    
        if(obj){
            obj.style.display = disp; 
        }
                
        if (disp == 'block'){                      
           //imgHome.src = "DefaultImg/Menu/Home01.gif";
           //imgCateg.src = "DefaultImg/Menu/MENU_Categorias02.gif";       
           if (Ocamsite && imgCateg){
                imgCateg.src = Ocamsite.value + "DefaultImg/Menu/MENU_Categorias02.gif"; 
           }else if (imgCateg){
                imgCateg.src = "DefaultImg/Menu/MENU_Categorias02.gif";        
           }
           if (Ocamsite && imgMinhaconta){           
                imgMinhaconta.src = Ocamsite.value + "DefaultImg/Menu/MENU_MinhaConta02.gif"; 
           }else if (imgMinhaconta){
                imgMinhaconta.src = "DefaultImg/Menu/MENU_MinhaConta02.gif"; 
           }
           
           //imgAjuda.src = "DefaultImg/Menu/Ajuda01.gif"; 
           //imgLeilaoaovivo.src = "DefaultImg/Menu/Arrematados01.gif";
           //imgProximos.src = "DefaultImg/Menu/ProximosLeiloes01.gif";
           //imgFalaconosco.src = "DefaultImg/Menu/FalaConosco01.gif";
        }
        else  {
          //imgHome.src = "DefaultImg/Menu/Home01.gif";
          if (Ocamsite && imgCateg){
                imgCateg.src = Ocamsite.value + "DefaultImg/Menu/MENU_Categorias01.gif"; 
           }else if (imgCateg){
                imgCateg.src = "DefaultImg/Menu/MENU_Categorias01.gif";        
           }
           if (Ocamsite && imgMinhaconta){           
                imgMinhaconta.src = Ocamsite.value + "DefaultImg/Menu/MENU_MinhaConta01.gif"; 
           }else if (imgMinhaconta){
                imgMinhaconta.src = "DefaultImg/Menu/MENU_MinhaConta01.gif"; 
           }
          //imgAjuda.src = "DefaultImg/Menu/Ajuda01.gif"; 
          //imgLeilaoaovivo.src = "DefaultImg/Menu/Arrematados01.gif";
          //imgProximos.src = "DefaultImg/Menu/ProximosLeiloes01.gif";
          //imgFalaconosco.src = "DefaultImg/Menu/FalaConosco01.gif";
        }
   }catch(e) {}
}

///	<summary>
///		Objetivo:	Função utilizada pelo link Saiba mais da marca Verified By Visa.
///		Autor:		Juliano Basali
///		Criação:	15/01/2009
///	</summary>
function OpenSaibaMais(){
	window.open('http://www.visa.com.br/vbv/vbv_saibamais.asp','principal','height=435,width=270,top=0,left=0,resizable=no,status=1');
}

///	<summary>
///		Objetivo:	Função utilizada para bloqueio da tecla controlc+v
///		Autor:		Matheus
///		Criação:	30/04/2009
///	</summary>
function BloqueioControlC(e, Obj, Act)
{
        //list all CTRL + key combinations you want to disable
        var forbiddenKeys = new Array("c","v");
        var key;
        var isCtrl;

        if(window.event)
        {
                key = window.event.keyCode;     //IE
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        else
        {
                key = e.which;     //firefox
                if(e.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }

        //if ctrl is pressed check if other key is in forbidenKeys array        
        if(isCtrl)
        {        
                for(i=0; i<forbiddenKeys.length; i++)
                {
                        //case-insensitive comparation
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                        {
                                alert('Teclas combinadas CTRL + ' +String.fromCharCode(key) + ' está desabilitado. Por favor, digite novamente.');
                               if ( Act == 1 )  Obj.value = '';                                 
                                return false;
                        }
                }
        }
        return true;
}   

function pulsada(evt) 
{

    var key_code = evt.keyCode  ? evt.keyCode  :
                   evt.charCode ? evt.charCode :
                   evt.which    ? evt.which    : void 0; 

    var codigoTecla;
    codigoTecla = (String.fromCharCode(key_code));
            
    //INIBE CARACTERES - #$%&(    
    if (codigoTecla == '#' || codigoTecla == '$' || codigoTecla == '%' || codigoTecla == '&' || codigoTecla == '(' || codigoTecla == '#' || codigoTecla == "'" || codigoTecla == "@") return false;
        
    // Habilita teclas <DEL>, <TAB>, <ENTER>, <ESC> e <BACKSPACE>
    if(key_code == 8  ||  key_code == 9  ||  key_code == 13  ||  key_code == 27 ||  key_code == 46) return true;
    
    // Habilita teclas _ - @
    if(key_code == 45 ||  key_code == 64 ||  key_code == 95) return true;

  // Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
    if((key_code >= 35)  &&  (key_code <= 40)) return true;
    
    // Habilita números de 0 a 9
    if((key_code >= 48)  &&  (key_code <= 57)) return true;
    
    // Habilita letra de A - Z maiusculas
    if((key_code >= 65)  &&  (key_code <= 90)) return true;
        
    // Habilita letra de A - Z minusculas
    if((key_code >= 97)  &&  (key_code <= 122)) return true;
    
    return false;
}


//FUNÇÕES PARA STRING BUILDER
function StringBuilder(value){
    this.strings = new Array("");
    this.append(value);
}

StringBuilder.prototype.append = function (value){
    if (value){
        this.strings.push(value);
    }
}

StringBuilder.prototype.clear = function (){
    this.strings.length = 1;
}

StringBuilder.prototype.toString = function (){
    return this.strings.join("");
}
//FIM FUNÇÕES PARA STRING BUILDER    

//NOVAS FUNÇÕES ARRAY   
var aCheckMethods = new Array("concat", "push", "pop", "every", "some", "forEach", "filter", "map", "indexOf", "lastIndexOf", "slice", "splice", "shift", "unshift");

Array.prototype.append = function(){
    for (var i=0; i < arguments.length; i++) {
        this[this.length] = arguments[i];
    }
};

Array.prototype.clone = function () /*:Array*/ {
    return this.concat();
};

Array.prototype.contains = function (vItem /*:variant*/) /*:boolean*/ {
    return this.indexOf(vItem)>-1;
};

Array.prototype._every = function (fnTest /*:Function*/, oThis /*:Object*/)/*:boolean*/ {
    if (this.length > 0) {
        var bResult = true;

        oThis = oThis || window;
        oThis.__everyFunc__ = fnTest;
        
        for (var i=0, l=this.length; i < l && bResult; i++) {
            bResult = bResult && oThis.__everyFunc__(this[i], i, this);
        }
        
        oThis.__everyFunc__ = null;
        
        return bResult;
    } else {
        return true;   //fix(1.02): changed from false
    }
};

Array.prototype._filter= function (fnTest /*:Function*/, oThis /*:Object*/)/*:Array*/ {
    
    var aResult /*:Array*/ = new Array();
    oThis = oThis || window;
    oThis.__filterFunc__ = fnTest;
    
    for (var i=0, l=this.length; i < l; i++) {
        if (oThis.__filterFunc__(this[i], i, this)) {
           aResult.push(this[i]);
        }
    }
    
    oThis.__filterFunc__ = null;
    
    return aResult;
};

Array.prototype._forEach = function (fnExec /*:Function*/, oThis /*:Object*/) {
    
    oThis = oThis || window;
    oThis.__forEachFunc__ = fnExec;
    
    for (var i=0, l=this.length; i < l; i++) {
        oThis.__forEachFunc__(this[i], i, this);
    }
    
    oThis.__forEachFunc__ = null;

};

Array.prototype._indexOf = function (vItem /*:Variant*/, iStart /*:int*/)/*:int*/ {
    if (iStart == null) {
        iStart = 0;
    }
    
    for (var i=iStart, l=this.length; i < l; i++) {
        if (this[i] == vItem) {
            return i;
        }
    }
    return -1;
};

Array.prototype.insertAt = function (vItem /*:variant*/, iIndex /*:int*/) /*:variant*/ {
    this.splice(iIndex, 0, vItem);
};

Array.prototype.insertBefore = function (vItem /*:variant*/, vBeforeItem /*:variant*/) /*:variant*/ {
    this.insertAt(vItem, this.indexOf(vBeforeItem));
};

Array.prototype._lastIndexOf = function (vItem /*:Variant*/, iStart /*:int*/)/*:int*/ {
    if (iStart == null || iStart >= this.length) {
        iStart = this.length-1;
    }
    
    for (var i=iStart; i >= 0; i--) {
        if (this[i] == vItem) {
            return i;
        }
    }
    return -1;
};

Array.prototype._map = function (fnExec /*:Function*/, oThis /*:Object*/)/*:Array*/ {
    
    var aResult /*:Array*/ = new Array();
    oThis = oThis || window;
    oThis.__mapFunc__ = fnExec;
    
    for (var i=0, l=this.length; i < l; i++) {
        aResult.push(oThis.__mapFunc__(this[i], i, this));
    }
    
    oThis.__mapFunc__ = null;
    
    return aResult;
};

Array.prototype._pop = function ()/*:variant*/ {

    var oItem /*:Variant*/ = null;
    
    if (this.length > 0) {
        oItem = this[this.length-1];
        this.length--;
    }
    
    return oItem;
};

Array.prototype._push = Array.prototype.append;
Array.prototype.remove = function (vItem /*:variant*/) /*:variant*/ {
    this.removeAt(this.indexOf(vItem));    
    return vItem;
};

Array.prototype.removeAt = function (iIndex /*:int*/) /*:variant*/ {
    var vItem = this[iIndex];
    if (vItem) {
        this.splice(iIndex, 1);
    }
    return vItem;
};

Array.prototype._slice = function (iStart /*:int*/, iStop /*:int*/)/*:Array*/ {
 
    var aResult /*:Array*/ = new Array();
    iStop = iStop || this.length;
    
    for (var i=iStart; i < iStop; i++) {
        aResult.push(this[i]);
    }
    
    return aResult;
};

Array.prototype._shift = function ()/*:variant*/ {
 
    var vItem = this[0];
    if (vItem) {
        this.splice(0,1);
    }
    return vItem;
};

Array.prototype._some= function (fnTest /*:Function*/, oThis /*:Object*/)/*:boolean*/ {
    
    oThis = oThis || window;
    oThis.__someFunc__ = fnTest;
    
    for (var i=0, l=this.length; i < l; i++) {
        if (oThis.__someFunc__(this[i], i, this)) {
           return true;
        }
    }
    
    oThis.__someFunc__ = null;
    
    return false;
};

Array.prototype._splice = function (iIndex /*:int*/, iLength /*:int*/)/*:Array*/ {
 
    var aResult /*:Array*/ = new Array();
    var aRemoved /*: Array */ = new Array();
    
    for (var i=0; i < iIndex; i++){
        aResult.push(this[i]);
    }
    
    for (var i=iIndex; i < iIndex+iLength; i++) {
       aRemoved.push(this[i]);
    }
    
    if (arguments.length > 2) {
        for (var i=2; i < arguments.length; i++) {
            aResult.push(arguments[i]);
        }
    }

    for (var i=iIndex+iLength; i < this.length; i++) {
        aResult.push(this[i]);
    }
    
    for (var i=0; i < aResult.length; i++) {
        this[i] = aResult[i];
    }
    this.length = aResult.length;
    
    return aRemoved;
};

Array.prototype.sum = function (fnConvert /*:Function*/, oThis /*:Object*/)/*:variant*/ {

    if (this.length > 0) {
        var vResult = null;

        oThis = oThis || window;
        oThis.__sumFunc__ = fnConvert || function (vVal) { return vVal; };
        
        vResult = oThis.__sumFunc__(this[0], 0, this);
        
        for (var i=1, l=this.length; i < l; i++) {
            vResult += oThis.__sumFunc__(this[i], i, this);
        }
        
        oThis.__sumFunc__ = null;
        
        return vResult;
    } else {
        return null;
    }
};

Array.prototype._unshift = function () {
    var sExec = "this.splice(";
    
    var aArgs = new Array();
    for (var i=0,l=arguments.length; i < l; i++) {
        aArgs.push("arguments["+i+"]");
    } 
    
    eval("this.splice(0,0," + aArgs.join(",") + ")");
};

for (var i=0; i < aCheckMethods.length; i++) {
    if(!Array.prototype[aCheckMethods[i]]) {
        Array.prototype[aCheckMethods[i]] = Array.prototype["_"+aCheckMethods[i]];
    }
}