


YAHOO.Ideia_SA.QGN.Init = function() {

	

	var DOM = YAHOO.util.Dom;

	

	//var webdoor_obj = get('homeWebdoor_obj');

	//var destaques_obj = get('homeDestaques_obj');

	

	var mRegExp = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	

	YAHOO.Ideia_SA.QGN.handles = {

		

		search: function(e) {



			var anim  = new YAHOO.util.Anim('homeDestaques_obj', { opacity: { to: 0 }})

			

			search_result = YAHOO.util.Dom.get('search_result');

			search_result.innerHTML = 'Pesquisando...';

			

			search_Obj = YAHOO.util.Dom.get('search_Obj');

			

			anim.onComplete.subscribe(function() { 

						YAHOO.util.Dom.get('homeDestaques_obj').style.display='none';

				        search_Obj.style.display=''; 

				    }); 



			anim.animate(); 

			

			txtSearch = YAHOO.util.Dom.get('txtSearch');

			

			YAHOO.util.Connect.asyncRequest('GET', 'http://www.qgn.com.br/?q='.concat(txtSearch.value),

				{

					success: function(h) {

					search_result.innerHTML = h.responseText;

					}

				});

			

		},

		openAjx: function(obj_id) {

				YAHOO.Ideia_SA.QGN.handles.hideHomeContent();

				YAHOO.util.Connect.asyncRequest('GET', 'http://www.qgn.com.br/item/'.concat(obj_id),

					{

						success: function(h) {

						alert(h.responseText);

						}

					});

			},

		hideHomeContent: function() {

			var anim = [

				new YAHOO.util.Anim('homeWebdoor_obj', { opacity: { to: 0 }}),

				new YAHOO.util.Anim('homeDestaques_obj', { opacity: { to: 0 }})

			];

			

			anim.onComplete.subscribe(function() { 

				        changeColor.animate(); 

				    }); 



			//DOM.setStyle('homeContent_obj','display','block');

			//DOM.setStyle('homeDestaques_obj','display','none');

			

			for(var i = 0; i < anim.length; i++) anim[i].animate(); 

		},

		showHomeContent: function() {

			var anim = [

				new YAHOO.util.Anim('homeWebdoor_obj', { opacity: { to: 1 }}),

				new YAHOO.util.Anim('homeDestaques_obj', { opacity: { to: 1 }})

			];

			DOM.setStyle('homeContent_obj','display','none');

			//DOM.setStyle('homeWebdoor_obj','display','none');

			//DOM.setStyle('homeDestaques_obj','display','none');

			

			for(var i = 0; i < anim.length; i++) anim[i].animate(); 

		},

		newsletter_register: function() {

			var email = DOM.get('txtNewsletter');

			if(mRegExp.test(email.value)) {

			location.href="http://www.qgn.com.br/cadastraEmail.php?email="+email.value

			}  else {

			alert('Preencha seu e-mail corretamente');

			email.focus();

			}

		},

		sendEmail: function() {

			

			var f = YAHOO.util.Dom.get('frmContatoExp'),

				nome = f.nome,

				contato = f.contato,

				assunto = f.assunto,

				msg = f.msg;

			

			if(nome.value.length < 2) {

				alert("Preencha seu nome corretamente!");

				nome.focus();

				return false;

			}

			if(!(mRegExp.test(contato.value))) {

				alert('Preencha seu e-mail corretamente!');

				contato.focus();

				return false;

			}

			if(assunto.selectedIndex < 1) {

				alert("Selecione o assunto!");

				assunto.focus();

				return false;

			}

			if(msg.value.length < 1) {

				alert("Preencha a mensagem!");

				msg.focus();

				return false;

			}

			

			(new YAHOO.util.Anim(f, { opacity: { to: .4 }})).animate();

			

			DOM.setStyle(this,'display','none');

			DOM.setStyle('spnEnviar','display','block');

			

			var postData = '';

			postData = postData.concat('from='.concat(encodeURIComponent(nome.value)));

			postData = postData.concat('&from_email='.concat(encodeURIComponent(contato.value)));

			postData = postData.concat('&subject='.concat(Math.floor(assunto.options[assunto.selectedIndex].value)));

			postData = postData.concat('&msg='.concat(encodeURIComponent(msg.value)));

			

			var restartForm = function() {

				(new YAHOO.util.Anim(f, { opacity: { to: 1 }})).animate();

				DOM.setStyle('btnEnviar','display','block');

				DOM.setStyle('spnEnviar','display','none');

				f.reset();

			};

			

			YAHOO.util.Connect.asyncRequest('POST', 'http://www.qgn.com.br/sendMail', { success:

				function(h) {

					if(h.responseText=='ok') {

						alert("E-mail enviado com sucesso!");

					}

					restartForm();

				},

				failure: 

				function() {

					restartForm();	

				}

			}, postData);

			

			

			//(new YAHOO.util.Anim('spnEnviar',{ opacity: { from: 0, to: 1}})).animate();

			

		

			return true;



		}

		

	};



	YAHOO.util.Event.on('btnSearch', 'click', YAHOO.Ideia_SA.QGN.handles.search);

	YAHOO.util.Event.on('btnEnviar', 'click', YAHOO.Ideia_SA.QGN.handles.sendEmail);

	YAHOO.util.Event.on('btnNewsletterSubmit', 'click', YAHOO.Ideia_SA.QGN.handles.newsletter_register)

	

}



YAHOO.util.Event.onDOMReady(YAHOO.Ideia_SA.QGN.Init);


