$(document).ready(function(){
	$(".parent").each(function(){
		$("#menu li").hover(function(){
		$(this).addClass("selecionado");
		$(this).find("ul").fadeIn("fast");
		},
		function (){
		$(this).removeClass("selecionado");
		$(this).find("ul").fadeOut("fast");
		});
	});
});

$(document).ready(function(){
	$("#telefone").mask("(99) 9999-9999");
	$("#cpf").mask("999.999.999-99");
	$("#cep").mask("99999-999");
	$("#data").mask("99/99/9999");
	$("#admissao").mask("99/99/99");
	$("#senha").mask("999999");
	$("#resenha").mask("999999");
	$("#ano").mask("99");
	$("#mes").mask("99");
	$("#data_ini").mask("99/99/9999");
	$("#data_fim").mask("99/99/9999");
	$("#cnpj").mask("99.999.999./9999-99");
});


function ajaxInit() {
    var req;
    try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(ex) {
            try {
                req = new XMLHttpRequest();
            } catch(exc) {
                alert("Esse browser não suporta Ajax");
                req = null;
            }
        }
    }
    return req;
}

function ChecaPasta(){
    valor = ajaxInit();
    valor.open("GET",'pages/pasta.asp?pasta='+document.f.pasta.value, true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==4) && (valor.status==200)){
			document.getElementById("resultado").innerHTML = valor.responseText;
			document.getElementById('checar').style.display = 'none';
			document.getElementById('resultado').style.display = 'block';
			}
    }
    valor.send(null);
}

function MostrarFotos(id,pasta){
    valor = ajaxInit();
    valor.open("GET",'pages/fotos.asp?id='+id+'&pasta='+pasta, true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==4) && (valor.status==200)){
			document.getElementById("fotos").innerHTML = valor.responseText;
			document.getElementById("fotos").style.display = 'block';
			document.getElementById('ver_fotos').style.display = 'none';
			document.getElementById('fechar_fotos').style.display = 'block';
			}
    }
    valor.send(null);
}
function Fotos(){
			document.getElementById('ver_fotos').style.display = 'block';
			document.getElementById('fechar_fotos').style.display = 'none';	
			document.getElementById("fotos").style.display = 'none';
	}

function Checar(){
	document.getElementById('checar').style.display = 'block';
	document.getElementById('resultado').style.display = 'none';
	}
	
function ChamaUsuarios(empresa,tipo,galeria){
	//alert("empresa: "+empresa+"   tipo: "+tipo+"   galeria: "+galeria);
    valor = ajaxInit();
    valor.open("GET",'pages/lista_usuarios.asp?empresa='+empresa+'&tipo='+tipo+'&galeria='+galeria, true);
    valor.onreadystatechange=function() {
        if ((valor.readyState==4) && (valor.status==200)){
			document.getElementById("usuarios").innerHTML = valor.responseText;
			}
    }
    valor.send(null);
}

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; 
    } 
}; 

function formatCurrency(o, n, dig, dec) { 
   o.c = !isNaN(n) ? Math.abs(n) : 2; 
   o.dec = typeof dec != "string" ? "," : dec, o.dig = typeof dig != "string" ? "." : dig; 
   addEvent(o, "keypress", function(e) { 
      if (e.key > 47 && e.key < 58) { 
         var o, s, l = (s = ((o = this).value.replace(/^0+/g, "") + String.fromCharCode(e.key)).replace(/\D/g, "")).length, n; 
         if(o.maxLength + 1 && l >= o.maxLength) return false; 
         l <= (n = o.c) && (s = new Array(n - l + 2).join("0") + s); 
         for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += o.dig); 
         n && n < l && (s[l - ++n] += o.dec); 
         o.value = s.join(""); 
      } 
      e.key > 30 && e.preventDefault(); 
   }); 
} 

function fmtMoney(n, c, d, t){ 
   var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".", 
      /(\d+)(?:(\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0; 
   return (x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(\d{3})(?=\d)/g, 
      "$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : ""); 
}; 
