/* Evento window.onstopscroll */
window.intervalstopscroll = null;
window.onstopscroll2 = function(){
	SA.alinha();	
}
window.onscroll = function() {
	clearTimeout(window.intervalstopscroll);
	window.intervalstopscroll = setTimeout('window.onstopscroll2();window.onstopscroll();', 50);
};
window.onstopscroll = new Function();
// Fundo preto do site 
var bgSite = {
	'show': function() {
		setAlpha('bgSite', 70);
		$('bgSite').style.height = getDocSize().y+13+'px';
		$('bgSite').style.display = 'block';
		var obj = document.getElementsByTagName('SELECT');
		for (var i = 0; i < obj.length; i++) {
			obj[i].style.display = "none";
		}
	},
	'hide': function() {
		$('bgSite').style.display = 'none';
		var obj = document.getElementsByTagName('SELECT');
		for (var i = 0; i < obj.length; i++) obj[i].style.display = "block";
	},
	'alinha': function(){
		var newY;
		if(getDocVisibleSize().y > getDocSize().y){
			newY = getDocVisibleSize().y;
		}else{
			newY = getDocSize().y+44
		}
		$('bgSite').style.width = getDocSize().x+'px';
		$('bgSite').style.height = newY+'px';
	}
};

var SA = {
	'opened': false,
	'show': function(txt) {
		this.opened = true;
		bgSite.show();
		
		$('alertError').innerHTML = txt;
		$('alertSite').style.display = 'block';
		
		this.onClick = function(bt){ this.hide(); }
		
		this.alinha();
	},
	'open': function(txt){ this.show(txt); },
	'alinha' : function(){
		if(!this.opened) return;
		var SC = getScroll();
		var VS = getDocVisibleSize();
		var SZ = getSize('alertSite');
		newX = (VS.x-SZ.x)/2;
		newY = (VS.y-(SZ.y))/2;
		$('alertSite').style.top = (newY+SC.y)+"px";
		$('alertSite').style.left = (newX+SC.x)+"px";
		bgSite.alinha();
	},
	'hide': function(){
		this.opened = false;
		
		$('alertError').innerHTML = '';
		
		$('alertSite').style.top = "-1000px";
		$('alertSite').style.lef = "-1000px";
		$('alertSite').style.display = "none";
		bgSite.hide();
	},
	'onClick': function(bt){ this.hide(); }
}

addNewEvents = function(){
	try{
		$('emailNews').onclick = function(){ if(this.value == "cadastre seu email") this.value = ""; }
		$('emailNews').onblur = function(){ if(this.value == "") this.value = "cadastre seu email"; }
	}catch(e){}
}

addNews = function(){
	var xml = new xmlConnection();
	var erro = false;

	if($('emailNews').value.isWhite() || $('emailNews').value == "" || !validateEmail($('emailNews').value)){
		SA.open("Digite um email v&aacute;lido!");
		erro = true;	
	}
	
	if(erro == true) return;
		
	with (xml) {
		if (create()) {
			add('email', $('emailNews').value);
			setURL('/site/addnews/');
			setMethod('POST');
			onComplete = function(){
				$('emailNews').value = 'cadastre seu email';
				
				if(this.getText() == '1'){
					SA.show('E-mail cadastrado com sucesso!');
				}else{
					SA.show('E-mail j&aacute; cadastrado em nosso sistema!');
				}
				enviando = false;
				
			}
			onError = function(){
				$('emailNews').value = 'cadastre seu email';				
				SA.show('Erro ao enviar o contato!<br>Por favor, tente mais tarde.');
				enviando = false;				
			}
		}
		enviando = true;
		execute();
	}
}
