﻿var Feedback = {

	Filter : function (w, d, b) {
	
		var r = w ? w : 0;
		
		if (d && (!r || (r > d)))
			r = d;
		
		return b && (!r || (r > b)) ? b : r;

	},
	
	Measures : function(o) {

		var l = (o.style.left)?parseInt(o.style.left.replace('px', '')):0;
		var t = (o.style.top)?parseInt(o.style.top.replace('px', '')):0;
		var w = (o.style.width)?parseInt(o.style.width.replace('px', '')):0;
		var h = (o.style.height)?parseInt(o.style.height.replace('px', '')):0;

		return { left : l, top : t, width : w, height : h };
	},

	Reset : function () {
	
		var o   = document.getElementById('divFeedback');
		var fix = document.getElementById('divFeedbackFix');
		var txt = document.getElementById('txtFeedback');
        var ico = document.getElementById('icoFeedback');
		
		o.style.left    = Feedback.Filter(window.innerWidth ? window.innerWidth : 0,
						document.documentElement ? document.documentElement.clientWidth : 0,
						document.body ? document.body.clientWidth : 0) / 2 + "px";
					
        //fix.style.left  = o.style.left;
					
		o.style.top     = (Feedback.Filter(window.innerWidth ? window.innerWidth : 0,
						document.documentElement ? document.documentElement.clientWidth : 0,
						document.body ? document.body.clientWidth : 0) / 2) + Feedback.Filter(window.pageYOffset ? window.pageYOffset : 0,
																			document.documentElement ? document.documentElement.scrollTop : 0,
																			document.body ? document.body.scrollTop : 0) - 300 + "px";
        //fix.style.top   = o.style.top;
	
		txt.innerHTML 		    = '';
		ico.style.visibility    = 'hidden';
		ico.src                 = 'Img/pixel.gif';
		o.style.visibility 	    = 'hidden';
		o.style.width 		    = 0;
		
		//fix.style.visibility 	= 'hidden';
		//fix.style.width 		= 0;
	},
	
	Show : function (text, width, height, type) {
	
		Feedback.Reset();
		
		Feedback.Expand(text, width, height, type);

	},

	Expand : function (text, width, height, type) {

		var o   = document.getElementById('divFeedback');
		var fix = document.getElementById('divFeedbackFix');
		var txt = document.getElementById('txtFeedback');
        var ico = document.getElementById('icoFeedback');

		if (Feedback.Measures(o).width != width)
		{
			o.style.visibility 	    = 'visible';
			o.style.height          = height;
			o.style.width 		    = Feedback.Measures(o).width + 10 + "px";
			o.style.left  		    = Feedback.Measures(o).left  - 5 + "px";
			
			//fix.style.visibility 	= 'visible';
			//fix.style.height        = height;
			//fix.style.width 		= Feedback.Measures(o).width + 10 + "px";
			//fix.style.left  		= Feedback.Measures(o).left  - 5 + "px";
			
			setTimeout("Feedback.Expand('" + text + "', " + width + ", " + height + ", " + type + ");", 10);
		}
		else
		{
			switch (type)
			{
			    case 1:
			        ico.src = 'Img/icoInfo.gif';
			    break;
			    
			    case 2:
			        ico.src = 'Img/icoAlerta.gif';
			    break;
			    
			    case 3:
			        ico.src = 'Img/icoErro.gif';
			    break;
			    
			    case 4:
			        ico.src = 'Img/icoSucesso.gif';
			    break;
			}
			
			ico.style.visibility = 'visible';
			txt.innerHTML        = text + '<br><br>[Fechar]';
		}
	},
	
	Hide : function ()
	{
		Feedback.Reset();
	}
}