$(function(){
	$("a[menu]", "div.menu").hover(function(){		
		var vItm = $(this).attr('menu');
		$("div.submenu").css('display','none');
		$('div#sub-'+vItm).css('display','block');
	});
	$("a:not([menu])", "div.menu").hover(function(){		
		$("div.submenu").css('display','none');
	});
		
	
	$("div.submenu").mouseout(function(e){	
		if($.contains(this, e.relatedTarget) == false) {
			$(this).css('display', 'none');
		}
	});	
	
	$('a.buscasubmit').click(function(){
		afrmBusca = $('form[name=frmBusca]');
		busStr = $('input[name=busca]', afrmBusca).attr('value');
		if (busStr == ''){
			alert('Especifique um texto para busca');
			return false;			
		} else if (busStr.length < 3){
			alert('O texto para busca deve ter no mínimo 3 caracteres');
			return false;
		} else {
			$('form[name=frmBusca]').trigger('submit');
		}
	})
	
});

/* jsPopup 1.1
--------------------------------------*/
var popWin=false;
var popWin2=false;
function jsPopup(url, Options){

	if(popWin || !!popWin.closed) popWin.close();
	/*defaults*/
	w = 500;
	h = 400;
	j = 'popWin';
	m = 0;
	s = 'no';
	r = 'no';		
	l = 0;
	t = 0;	
	/*override options*/
	for (n in Options) eval(n+' = Options[n]');
	if (w == '100%'){
		l = 0
		w = screen.width;
	} else {
		if (l == 0) l = (screen.width - w) / 2;
	}
	if (h == '100%'){
		t = 0;
		h = screen.height;
	} else {
		if (t == 0) t = (screen.height - h) / 2;				
	}
	
	if (j == 'popWin'){
		if(popWin || !!popWin.closed) popWin.close();
	} else if (j == 'popWin2'){
		if(popWin2 || !!popWin2.closed) popWin2.close();
	}

	/*abre popup*/
	popWin = open(url, j, 'toolbar=no,location=no,directories=no,status=no,menubar='+m+',scrollbars='+s+',resizable='+r+',copyhistory=yes,width='+w+',height='+h+',left='+l+', top='+t+',screenX='+l+',screenY='+t+'');
	popWin.focus();
	return j;
}

/* jsPost - jsc.2.2 - 12/05/2011
jsPost(pagina-destino:string, target:string, campos_valores:json) 
exemplo: jsPost({nome:jose, idade:10}, 'teste.asp', '_blank') */
function jsPost(frmCps, frmAct, frmTrg, frmConfirm){
	$('body').prepend('<form id="autoForm" method="POST"></form>');
	oFrm = $('#autoForm');
	if (!frmTrg) frmTrg = '_self';
	if (!frmAct) frmAct = document.location.href;
	if (!!frmConfirm) {
		question = confirm(frmConfirm);
		if (question == 0) return false;
	};
	oFrm.attr('action', frmAct);		
	oFrm.attr('method', 'POST');
	for (n in frmCps){
		oFrm.append('<input type="hidden" name="'+n+'" value="'+frmCps[n]+'">')
	}

	if (frmTrg == 'ajax'){
		oFrm.append('<a id="btAutoForm" href="#"></a>');
		$('a#btAutoForm').click(function(){
			ajx_submit($(this));	
		})			
		$('a#btAutoForm').trigger('click');
	} else {
		oFrm.attr('target', frmTrg);
		oFrm.trigger('submit');	
	}
}

function eNulo(str, subst){
	if(typeof(str)=="undefined"){ 
		return subst
	} else {
		return str
	}
}

