var SA = {
	'created': 0,
	'opened': 0,
	'size': null,
	'docSize': null,
	'scroll': null,
	'isClosing': 0,
	'isOpening': 0,
	'onYes': null,
	'onNo': null,
	'onOk': null, 
	'ESCClose': 0,
	'open': function(_titulo, _callback, _type, _esc) {
		//type: 1->ok(alert)(X) / 2->yes/no(confirm)
		//format: 1->Warning(X) / 2->Ok
		if (this.opened == 0 && this.isOpening == 0) {
			if ($_('SAWait').style.display != 'none' && $_('SAWait').style.display != ''){
				SAWait.close();
			}

			mensure.load();//exec sempre na abertura do alert

			this.isOpening = 1;

			this.callback = _callback;
			this.ESCClose = _esc;

			this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
			this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};
			var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};
			
			$_('SATitulo').innerHTML = _titulo;

			$_('blockbg').style.height = DS.y + 'px';
			if (!is_ie) {
				$_('blockbg').style.width = (DS.x - 17) + 'px';
			} else {
				$_('blockbg').style.width = DS.x + 'px';
			}

			$_('SA').style.display = "block";
			this.size = {x:$_('SA').offsetWidth, y:$_('SA').offsetHeight};

			var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
			var y = (this.docSize.y-this.size.y)/2+this.scroll.y;
			
			if (is_ie6) hideSelect();
			
			$_('SA').style.top = y + "px"; 
			$_('SA').style.left = x + "px";
			$_('blockbg').style.display = 'block';
			$_('SA').alphaTo(0,100,'easeoutexpo',0.6,function(){
				SA.opened = 1;
				SA.isOpening = 0;
			});
		}
	},
	'close': function() {
		if (this.opened == 1 && this.isClosing == 0) {
			this.isClosing = 1;
			$_('blockbg').style.display = 'none';
			$_('SA').alphaTo(100,0,'easeoutexpo',0.6,function(){
				$_('SA').style.display = 'none';

				SA.opened = 0;
				SA.isClosing = 0;
			});
			if (is_ie6) showSelect();
		}
	},
	'refresh': function() {
		if (this.opened == 1 || this.isOpening == 1) {
			this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
			this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};

			var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};
			
			$_('blockbg').style.height = DS.y + 'px';
			if (!is_ie) {
				$_('blockbg').style.width = (DS.x - 17) + 'px';
			} else {
				$_('blockbg').style.width = DS.x + 'px';
			}

			var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
			var y = (this.docSize.y-this.size.y)/2+this.scroll.y;
			
			$_('SA').tweenTo(y,x,'easeoutexpo',0.35,null);
		}
	},
	'create': function() {
		if (this.created == 0) {
			new tween('SA');
			new alpha('SA');
			setAlpha('SA', 0);
			
			this.created = 1;
		}
	},
	'clickOk': function() {
		if (this.callback == null) this.close();
		else {
			this.callback.onOk();
			this.close();
		}
	},
	'clickYes': function() {
		this.callback.onYes();
	},
	'clickNo': function() {
		this.callback.onNo();
	}
};

var SAWait = {
	'size': null,
	'docSize': null,
	'scroll': null,
	'open': function() {
		mensure.load();//exec sempre na abertura do alert

		this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
		this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};
		var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};

		$_('blockbg').style.height = DS.y + 'px';
		if (!is_ie) {
			$_('blockbg').style.width = (DS.x - 17) + 'px';
		} else {
			$_('blockbg').style.width = DS.x + 'px';
		}

		$_('SAWait').style.display = "block";
		this.size = {x:$_('SAWait').offsetWidth, y:$_('SAWait').offsetHeight};

		var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
		var y = (this.docSize.y-this.size.y)/2+this.scroll.y;
		
		if (is_ie6) hideSelect();

		$_('SAWait').style.top = y + "px"; 
		$_('SAWait').style.left = x + "px";

		$_('blockbg').style.display = 'block';
		setAlpha('SAWait', 0);
		$_('SAWait').stopAlpha();
		$_('SAWait').alphaTo(0,100,'easeoutexpo',0.6,function(){
			$_('SAWait').stopAlpha();
		});
	},
	'close': function() {
		$_('blockbg').style.display = 'none';

		$_('SAWait').stopAlpha();
		$_('SAWait').alphaTo(100,0,'easeoutexpo',0.6,function(){
			$_('SAWait').style.display = 'none';
			$_('SAWait').stopAlpha();
		});
		if (is_ie6) showSelect();
	},
	'refresh': function() {
		if ($_('SAWait').style.display != 'none' && $_('SAWait').style.display != ''){
			this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
			this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};

			var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};
			
			$_('blockbg').style.height = DS.y + 'px';
			if (!is_ie) {
				$_('blockbg').style.width = (DS.x - 17) + 'px';
			} else {
				$_('blockbg').style.width = DS.x + 'px';
			}

			var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
			var y = (this.docSize.y-this.size.y)/2+this.scroll.y;
			
			$_('SAWait').tweenTo(y,x,'easeoutexpo',0.35,null);
		}
	},
	'create': function() {
		new tween('SAWait');
		new alpha('SAWait');
		setAlpha('SAWait', 0);
	}
};
