// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function(){
	//pop newsletter


	verificaFormatoEmail = function(data){
		var regex = /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/;
		if(regex.test(data))
		{ 
			return true;
		}else{
			return false;
		}
	}


	$("#news_assinar").click(function(){

		if(verificaFormatoEmail($("#email_news").val())){
		 $.ajax({
		   type: "POST",
		   url: $("#myForm").attr("action"),
		   data: $("#myForm").serialize(),
				success: function(data){					
					$("#dialog_newsletter").html(data);
					$("#email_news").val('');
					$("#dialog_newsletter").dialog({ 
					    modal: true, 
							resizable: false,
							width: 530,
							height: 250,
							title: "<img src='/images/logo.png' align='top' alt=''/>&nbsp;Cortex - Industrial Computing Platforms / Newsletter",
					    overlay: { 
					        opacity: 0.5, 
					        background: "black" 
					    } 
					});
				},
			
				error: function(){
					//alert('erro');
				}
		 });
		}
			return false;
	})
	
	//
	var verificaNumber = function(obj, event)
	{
		var str = obj.value;
	  var Tecla = event.which;
	  if(Tecla == null)
	      Tecla = event.keyCode;		
		
	}

	// incio de fale
	
	$(".submitTagFale").click(function(e){

		
		var msg = "";
		if($("#faleForm #nome").val() == ''){
			msg += "Campo Nome não deve ficar em branco.\n<br/>";
		}
		
		if(!verificaFormatoEmail($("#faleForm #email").val())){
			msg += "Campo E-mail incorreto. \n<br />";			
		}
		 if($("#faleForm #area").val() == '' && $("#faleForm #area").val() == ''){
				msg += "Campos de telefone não devem ficar em branco. \n<br />";
		 }else{
			var re = /[0-9]/;
			var area = $("#faleForm #area").val();
			var codigo = $("#faleForm #area").val();
				if(!re.test(area) && !re.test(codigo))
					msg += "Campos de telefone só aceitam números. \n<br />";
		}
		 if($("#faleForm #assunto").val() == ''){
			msg += "Campo Assunto não deve ficar em branco. \n<br />";
		}
		 if($("#faleForm #mensagem").val() == ''){
				msg += "Campo Mensagem não deve ficar em branco. \n<br />";
		 }
		
		 if (msg != ''){
			 $("#error").html('').css('font-size', '.8em').css('padding',' 0 0 25px 10px').css('text-align','left');
			 $("#error").html(msg).animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 360).animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 360).animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 360).animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 360);
			 return false;
		 }

		$.ajax({
			type: "POST",
			url: $("#faleForm").attr("action"),
			data: $("#faleForm").serializeArray(),
			success: function(data){
				$("#faleForm input[@type=text], textarea").val('');
				$("#error").html("E-mail enviado com sucesso").css('font-size', '1em').css('text-align', 'center');
				
			},
			error: function(){
				$("#error").html("ERRO: E-mail não pôde ser enviado, tente novamente mais tarde.").css('font-size', '.8em').css('text-align', 'center');
			}			
		})
		
	
	
		return false;
	})
	
	// fim de fale
	

		// inicio de newsletter

		$(".submitTag").click(function(){
			if(verificaFormatoEmail($("#email_news_mais").val())){
			$.ajax({
				type: "POST",
				url: $("#newsForm").attr("action"),
				data: $("#newsForm").serialize(),
				success: function(data){
					$("#dialog_newsletter").html(data);
					$("#email_news_mais").val('');
					$("#nome_news_mais").val('');
					$("#dialog_newsletter").dialog({ 
					    modal: true, 
							resizable: false,
							width: 530,
							height: 250,
							title: "<img src='/images/logo.png' align='top' alt=''/>&nbsp;Cortex - Industrial Computing Platforms / Newsletter",
					    overlay: { 
					        opacity: 0.5, 
					        background: "black" 
					    } 
					});
				},
				error: function(){
					//alert('erro');
				}			
			})
			$("#newsForm #error").fadeOut('slow');
		}else{
			if($("#newsForm #email").val() == ''){
				$("#newsForm #error").html('Campo email não pode ficar em branco.').animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 120).animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 120).animate({"left": "+=20px"}, 180).animate({"left": "-=20px"}, 180);
			}else{
				$("#newsForm #error").html("O formato do email esta incorreto.").animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 120).animate({"left": "+=20px"}, 120).animate({"left": "-=20px"}, 120).animate({"left": "+=20px"}, 180).animate({"left": "-=20px"}, 180);
			}
		}

			return false;
		})

		// fim de newsletter

		// FAQ ACCORDION

		$("#faqMenu").accordion({
		   event: "mouseover",
			   autoHeight: false
		});
		$("a[@rel='voltar_faq']").click(function(){
			$(".faqDiv").hide();
			location.href = $(this).attr("href");
			return false;
		})
			var forma = 0;
			var cubo = 0
		$(".faqTitle").click(function(i, valor) {
				$(".faqDiv").eq($(".faqTitle").index(this)).toggle();

		});


		// FIM FAQ ACCORDIOM

		reinitializeScroll = function(data){
			$(data).jScrollPane({showArrows:true});
		}

		//outra comparacao
		/*
		$('a[@rel="comparar"]').click(function(){
			$('.cmp').load($(this).attr('href'), function(){
				$(this).show('slow');
			})
			return false;
		})
		*/


	//AQUI COMECA O DRAGGABLE


				$('li.drawer UL:not(:first)').hide(); // hide all ULs inside LI.drawer except the first one

				$('h2.drawer-handle').click(function () {
				  // hide all the drawer contents
				  $('li.drawer ul:visible').slideUp().prev().removeClass('open');

				  // show the associated drawer content to 'this' (this is the current H2 element)
				  // since the drawer content is the next element after the clicked H2, we find
				  // it and show it using this:
				  $(this).addClass('open').next().slideDown();
				});



	


});
