// JavaScript Document
/*var f = document.forms[0];
MaskInput(f.fone, "(99)9999-9999");
MaskInput(f.data, "99/99/9999");
MaskInput(f.etc, "Cc99-*C");
MaskInput(f.except, "E^abc");
MaskInput(f.only, "O^abc");
MaskInput(f.letra, "C^");
MaskInput(f.letra2, "C^ ");
MaskInput(f.numero, "9^abc");*/

MaskInput = function(f, m){
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
};

addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};

function max(txarea,total)
{
    tam = txarea.value.length;
    str="";
    str=str+tam;
    
    Digitado.innerHTML = str;
    Restante.innerHTML = total - str;

    if (tam > total){
       aux = txarea.value;
       txarea.value = aux.substring(0,total);
       Digitado.innerHTML = total 
       Restante.innerHTML = 0
                    }
} 

//permite digitar somente numeros
function soNumeros(e,args)
    {        
        if (document.all){var evt=event.keyCode;} // caso seja IE
        else{var evt = e.charCode;}    // do contrário deve ser Mozilla
        var chr= String.fromCharCode(evt);    
        if (evt <20 || (evt >47 && evt<58) || (args.indexOf(chr)>-1 ) ){return true;}
        return false;
    } 
	
//funcao altera item carrinho
function altera_item(e, codigo)
{
	if (e.value == '') { e.value = '1';}
	if (e.value == '0') { e.value = '1';}
	if (e.value == '00') { e.value = '1';}
	if (e.value == '000') { e.value = '1';}
	window.location = './?&page=carrinho&alteraitem='+codigo+'&qtde='+e.value;
}

//auto tab
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
        if(arr[index] == ele)
            found = true;
        else
            index++;
        return found;
    }

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;
}
//fim auto tab
