
var exp_email = /(^[A-Za-z0-9_.-]+@([A-Za-z0-9_]+\.)+[A-Za-z]{2,4}$)/;


/*
--------------------------------------------------------------------
 Funções para selecionar multiplos cheboxes e excluir em lote
 
 - frm  :			Recebe o nome do form;
 - _del :			O nome dos check deve ser del_0,del_1,del_2...
--------------------------------------------------------------------
*/


function excluir(frm) {
  chk = false;
  with(frm) {
    for(i=0; i<elements.length;i++) {
      thiselm = elements[i];
      if (thiselm.name.substr(0,4) == 'del_') {
        if(thiselm.checked) chk = true; 
      }
    }
  }
  if(!chk==true)  {
    alert("Nenhum ítem selecionado.");
    confirma = false;
  } else {
    confirma = false;
    confirma = confirm("Os itens selecionados serão excluídos. Continuar?");
  }
  if (confirma) frm.submit();
}

function CheckAll(frm) {
  with (frm) {
    for (i=0;i<elements.length;i++) {
      thiselm = elements[i];
      if(thiselm.name.substr(0,4) == 'del_') thiselm.checked = !thiselm.checked
    }
  }
}


/*
--------------------------------------------------------------------
 Funções para exibir label ou tooltips 
 
 - e    :			event (objeto javascript);
 - text :			Texto a ser exibido no label
--------------------------------------------------------------------
*/


function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        cursor.x = e.clientX + 
            (document.documentElement.scrollLeft || 
            document.body.scrollLeft) - 
            document.documentElement.clientLeft;
        cursor.y = e.clientY + 
            (document.documentElement.scrollTop || 
            document.body.scrollTop) - 
            document.documentElement.clientTop;
    }
    return cursor;
} 

function show_label(text,e) {
	idlb = document.getElementById('id_label');
	idlb.innerHTML = text;
	idlb.style.visibility = "visible";
	idlb.style.position = "absolute";
	acaba = eval(idlb.offsetWidth + getPosition(e).x + 10);
	if (acaba>screen.width) {
		idlb.style.left = eval(getPosition(e).x - 10 - idlb.offsetWidth) + "px";
	} else { 
		idlb.style.left = eval(getPosition(e).x + 10) + "px";
	}
	idlb.style.top = getPosition(e).y + "px";
	//document.getElementById('hlppp').innerHTML = idlb.style.left+' x '+idlb.style.top+'<br>'+acaba+' '+screen.width;
}

function hide_label() {
	idlb = document.getElementById('id_label');
	idlb.style.visibility = "hidden";
}


/*
--------------------------------------------------------------------
Funções que permite digitar apenas números em campo input
 
 - e    :			event (objeto javascript);
--------------------------------------------------------------------
*/



function tecla(e){
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	if (key==46) { return key = 46; } //ponto
	if (key==45) { return key = 45; } //menos
	if (key==8) { return key = 8; } //backspace
	if (key <48 | key > 57){ return key = false; }
}


/*
--------------------------------------------------------------------
Verifica se uma data está no formato dia/mes/ano
 
 - d	:			data;
 - name :			nome do campo que contem a data;
--------------------------------------------------------------------
*/


function isdate(d,name){
er_data = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/; // ER pra data
msg  = ""; // mensagem de erro
erro = false;
	if(d == ""){	  
	  erro = true;
	  msg = msg + "O campo "+name+" está vazio.\n";
	}else if(!er_data.test(d)){	  
	  erro = true;
	  msg = msg + "A "+name+" informada não é válida.\n";	
	}

	if(!erro){	  
	  return true;
	}else{	 
	  alert(msg);	 
	  return false;	
	}
}


/*
--------------------------------------------------------------------
Funcão para que os PNGs com fundo transparente funcionem no IE
 
 - onload:		a função carrega automaticamente no window.onload;
--------------------------------------------------------------------
*/


//
//	addEvent()
//	Allows attachment of events to elements
//
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

addEvent(window,'unload',EventCache.flush);

//
//	correctPNG()
//	Allows transparent PNG images to be display correctly in IE
//
function correctPNG() {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}


//
// Correct the PNG images
//
if( navigator.userAgent.indexOf('MSIE') >= 0 )
	addEvent(window,'load',correctPNG);




// -----------------------------------------------------------