$(document).ready(function(){
	$("#newsletter_email").bind("blur",function(e){
			if($("#newsletter_email").val()=="" ){
				$("#newsletter_email").val(email_initial);
			}
			//$("#newsletter_email").val()==email_initial?$("#field_text").nextAll("label").remove():"";
		});
	$("#newsletter_email").bind("focus",function(e){
			$("#newsletter_email").val($("#newsletter_email").val()==email_initial ?"":$("#newsletter_email").val());	
		
		});	
	$("#form_newsletter").validationEngine({
				success :  function() {
					$.ajax({						   
						   type: "POST",						   
						   url: base_url + 'home/register_contact',						   
						   data: $("#form_newsletter").serialize(),						   
						   beforeSend: function() {
							   $("#newsletter_form_div").hide();
							   $("#loading_image").show();
							},
						   success: function(msg){
							   $("#newsletter_form_div").show();
							   $("#loading_image").hide();
							   var return_msg="";
							   var font_color="#FFCC33";
							   if(msg=="201"){
								   return_msg="You have successfully been added to our mailing list.";
								   font_color="#99CCCC";
							   }
							   else if(msg=="409"){	
								   return_msg="This email address is already subscribed.";
							   }
							   else{
								   return_msg="There was an error in your request, try again";
							   }
							  /* if(msg=="200"){
								   return_msg="Your request was successful";
							   }
							   if(msg=="204"){
								   return_msg="Your request was successful";
							   }
							   if(msg=="400"){
								   return_msg="There was an error in your request, please try again";
							   }
							   if(msg=="401"){
								   return_msg="Authentication problems";
							   }
							   if(msg=="404"){
								   return_msg="URI incorrect";
							   }
							   */
							   
							  /* if(msg=="415"){
								   return_msg="The Media Type (Content Type) of the data you are sending does not match the expected Content Type for the specific action you are performing on the specific Resource you are acting on. Often this is due to an error in the content-type you define for your HTTP invocation (GET, PUT, POST). You will also get this error message if you are invoking a method (PUT, POST, DELETE) which is not supported for the Resource (URI) you are referencing.
To understand which methods are supported for each resource, and which content-type is expected, see the documentation for that Resource.";
							   }
							   if(msg=="500"){
								   return_msg="There are many possible causes for this error. The problem may be with the API itself, but most commonly there is a problem with the structure or content of XML your application provided. Carefully review your XML and the URL you are using.";
							   }*/
							   
							   $("#error_newsletter").css("color",font_color);
							   $("#error_newsletter").html(return_msg);
							   $("#error_newsletter").show();
							   setTimeout(function(){
												   $("#error_newsletter").hide();
												   if(msg==201){
													   $("#newsletter_email").val("");
												   }
												   
												   },4500);
								   $("#newsletter_form_div").show();

							}
					   		}); 
				},
				failure : function() {
					}
				});
	});