// JavaScript Document

function news_register()
{
	document.getElementById('frmNewsAjaxIcon').style.display = 'inline';
	document.getElementById('frmNewsSubmit').style.display = 'none';
	
	var frm = document.frmNews;
	
	var input_email = frm.email;
	
	var ajx = new ajax();

	try
	{
		ajx.seturl('/news');
		ajx.post();
		ajx.setparam('email',input_email.value);

		ajx.mystatereader = function()
		{
//			frm.submit_contato.className = 'ajax';

			if (this.readyState == 4)
			{
				if (this.status == 200)
				{
					if ( this.responseText == '') //sucesso
					{
						jQuery.noConflict();
						jQuery(document).ready(function($){
							$("#newsMsgSucesso").modal({onOpen: function (dialog) 
								{
									dialog.overlay.fadeIn('500', function () {
										dialog.container.show();
										dialog.data.show();
										setTimeout(function(){document.location.href = document.location}, 2500);
									});
								},
								opacity:85,
								overlayCss: {backgroundColor:"#fff"}
							});
						});
					}
					else // falha
					{
						alert(this.responseText);
						input_email.focus();
						document.getElementById('frmNewsAjaxIcon').style.display = 'none';
						document.getElementById('frmNewsSubmit').style.display = 'inline';

						return false;
					}
				}
			}
		}
		ajx.gorequest();
	}
	catch (err)
	{
		document.getElementById('frmNewsAjaxIcon').style.display = 'none';
		document.getElementById('frmNewsSubmit').style.display = 'inline';
		return alert(err.message);
	}
}
