var SA2 = {
	'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, _txt, _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 ($('SA2Wait').style.display != 'none' && $('SA2Wait').style.display != ''){
				SA2Wait.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()};

			$('SA2Titulo').innerHTML = _titulo;
			
			
			if(_txt!=''){
				$('SA2Text').innerHTML = _txt;
			}

			$('blockbg').style.height = DS.y + 'px';
			if (!is_ie) {
				$('blockbg').style.width = (DS.x - 17) + 'px';
			} else {
				$('blockbg').style.width = DS.x + 'px';
			}

			if (_type == 1) $('SA2Alert').style.display = "block";
			if (_type == 2) $('SA2Confirm').style.display = "block";

			$('SA2').style.display = "block";
			this.size = {x:$('SA2').offsetWidth, y:$('SA2').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();
			
			$('SA2').style.top = y + "px"; 
			$('SA2').style.left = x + "px";
			$('blockbg').style.display = 'block';
			$('SA2').alphaTo(0,100,'easeoutexpo',0.6,function(){
				SA2.opened = 1;
				SA2.isOpening = 0;
			});
		}
	},
	'close': function() {
		if (this.opened == 1 && this.isClosing == 0) {
			this.isClosing = 1;
			$('blockbg').style.display = 'none';
			$('SA2').alphaTo(100,0,'easeoutexpo',0.6,function(){
				$('SA2').style.display = 'none';

				//resetando as dimenses das imagens laterais
				$('SA2Alert').style.display = "none";
				$('SA2Confirm').style.display = "none";

				SA2.opened = 0;
				SA2.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;
			
			$('SA2').tweenTo(y,x,'easeoutexpo',0.35,null);
		}
	},
	'create': function() {
		if (this.created == 0) {
			new tween('SA2');
			new alpha('SA2');
			setAlpha('SA2', 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 SA2Wait = {
	'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';
		}

		$('SA2Wait').style.display = "block";
		this.size = {x:$('SA2Wait').offsetWidth, y:$('SA2Wait').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();

		$('SA2Wait').style.top = y + "px"; 
		$('SA2Wait').style.left = x + "px";

		$('blockbg').style.display = 'block';
		setAlpha('SA2Wait', 0);
		$('SA2Wait').stopAlpha();
		$('SA2Wait').alphaTo(0,100,'easeoutexpo',0.6,function(){
			$('SA2Wait').stopAlpha();
		});
	},
	'close': function() {
		$('blockbg').style.display = 'none';

		$('SA2Wait').stopAlpha();
		$('SA2Wait').alphaTo(100,0,'easeoutexpo',0.6,function(){
			$('SA2Wait').style.display = 'none';
			$('SA2Wait').stopAlpha();
		});
		if (is_ie6) showSelect();
	},
	'refresh': function() {
		if ($('SA2Wait').style.display != 'none' && $('SA2Wait').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;
			
			$('SA2Wait').tweenTo(y,x,'easeoutexpo',0.35,null);
		}
	},
	'create': function() {
		new tween('SA2Wait');
		new alpha('SA2Wait');
		setAlpha('SA2Wait', 0);
	}
};