function getOpacity(obj){
	if(obj.style.opacity){
		return obj.style.opacity;
	}
	else if(obj.style.MozOpacity){
		return obj.style.MozOpacity
	}
	else if(obj.style.MozOpacity){
		return obj.style.MozOpacity
	}
	else if(obj.style.KhtmlOpacity){
		return obj.style.KhtmlOpacity
	}
	else if(obj.style.filter){
		//alert('Filter Incompleto');
		//return obj.style.filter;
	}
	return 1;
}
function setOpacity(obj,opacity){
	obj.style.opacity = (opacity);
    obj.style.MozOpacity = (opacity );
    obj.style.KhtmlOpacity = (opacity );
    obj.style.filter = "alpha(opacity=" + opacity*100 + ")"; 
}
function myParseInt(v){
	if(v == "") return 0;
	return parseInt(v);
}
function getScrollPosition() {
  var scrOfX = 0, scrOfY = 0;
  
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  }
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } 
  return [ scrOfX, scrOfY ];
}

function getRealClientBound(obj){
	var r = obj.getBoundingClientRect();
	
	//alert({left:r.left,top:r.top,bottom:r.bottom,right:r.right});
	if(navigator.appName == "Microsoft Internet Explorer"){
		var s = getScrollPosition();
		
		var r2 = {
			left:r.left - (myParseInt(obj.style.borderLeftWidth) + myParseInt(obj.style.borderRightWidth) - s[0] + 2),
			top:r.top-(myParseInt(obj.style.borderTopWidth)),
			right:r.right -((myParseInt(obj.style.borderRightWidth) + myParseInt(obj.style.borderRightWidth))*2),
			bottom:r.bottom - (myParseInt(obj.style.borderBottomWidth))
		};
	
		//alert(s);
		
		return r2;
	}
	else{
		
		return {left:r.left,right:r.right -(parseInt(obj.style.borderRightWidth) + parseInt(obj.style.borderRightWidth)),top:r.top,bottom:r.bottom};
	}
}
function registerMessageWindow(prop){
	prop = getCommonProperty(prop,{
      id:"",
	  xy:"",
	  moveTo:"up",
	  showOnOver:true
   	});		
	
	var obj = document.getElementById(prop.id);
	if(obj){
		obj.target = document.getElementById(prop.targetid);
		obj.showOnOver = prop.showOnOver;
	 	var r = getRealClientBound(obj);
		var tr = getRealClientBound(obj.target);
		obj.msgHeightFinal = parseInt(obj.style.height);
		obj.style.position = "absolute";
		
		obj.style.top = tr.top -(r.bottom-r.top) + "px";
		obj.style.left = tr.left + "px";
		obj.style.width = tr.right - tr.left + "px";
		obj.style.overflow = "hidden";
		obj.msgMoveTo = "up";
		obj.style.position = "absolute";
		obj.realOpacity = getOpacity(obj);
		setOpacity(obj,0);
		obj.msgStatus = "hide";
		
		obj.onmouseover = function(){
			if(obj.showOnOver && obj.msgStatus == "hide"){
				obj.show();
			}
		}
		obj.setTarget = function(id){
			obj.target = document.getElementById(id);
			var r = getRealClientBound(obj);
			var tr = getRealClientBound(obj.target);
			obj.style.top = tr.top -(r.bottom-r.top) + "px";
			obj.style.left = tr.left + "px";
			obj.style.width = tr.right - tr.left + "px";
			obj.style.position = "absolute";
			return true;
		}
		obj.onmouseout = function(){
			if(obj.showOnOver && obj.msgStatus == "visible"){
				obj.hide();
			}
		}
		obj.setEnabled = function(b){
			if(b){
				if(obj.showOnOver){
					setOpacity(obj,obj.realOpacity);	
				}
				else{
					setOpacity(obj,obj.realOpacity);	
					obj.style.display = "block";
				}
			}
			else{
				if(obj.showOnOver){
					setOpacity(obj,0);
				}
				else{
					setOpacity(obj,0);
					obj.style.display = "none";
				}
			}
		}
		obj.setInativeTime = function(time){
			var s = obj.msgStatus;
			obj.msgStatus = "visibleprocess";
			setTimeout(function(){
				obj.msgStatus = s;
			},time);
		}
		obj.show = function(){
			obj.msgStatus = "visibleprocess";
			var hf = parseInt(obj.style.height);
			obj.style.top = parseInt(obj.style.top) + hf + "px"; 
			obj.style.height = "0px";
			obj.setEnabled(true);
			stopResize(obj);
			resize(obj,"none",hf,function(){
				obj.msgStatus = "visible";
				obj.onShow();
			},"reverseheight");
		}
		
		obj.hide = function(){
			obj.msgStatus = "hideprocess";
			var hf = parseInt(obj.style.height);
			stopResize(obj);
			resize(obj,"none",0,function(){
				obj.setEnabled(false);
				obj.style.top = parseInt(obj.style.top) - hf + "px";
				obj.style.height = hf - parseInt(obj.style.borderTopWidth)-parseInt(obj.style.borderBottomWidth)+"px";
				obj.msgStatus = "hide";
				obj.onHide();
			},"reverseheight");
		}

		obj.onShow = function(){

		}
		obj.onHide = function(){

		}
		
		obj.hide();
		
		
	}
	return obj;
}

