$(document).ready(function()
{
	
	
	$("#offer1").click(function()
	{	
		$("#overlaypanel").load("/themes/1/files/beatprice/overlay.html",function()
		{
				$("#formbeatprice").keyup(function(e)
				{
					if(e.keyCode == 13)
					{
						return false;
					}
				});
				
				$("#formbeatprice").keydown(function(e)
				{
					if(e.keyCode == 13)
					{
						return false;
					}
				});

				
				
				
			
				$(".popmedown").click(function()
				{
					$("#overlaypanel").popMeDown();
				});
				
				$("#beatpricesubmit").click(function()
				{
					/* Validate */
					var error = false;
					if ($("#fullname").val()=="") error=true;
					if ($("#email").val()==""||$("#email").val().indexOf("@")<0) error=true;
					if ($("#productname").val()=="") error=true;
					if ($("#url").val()=="") error=true;
					
					
					if (error)
					{
						$("#beaterror").html("Please complete all of the fields above.");	
					}
					else
					{
						$("#beaterror").html("");
					}
					if (!error)
					{
						$.post("http://www.cplights.com/page/beatprice-postback", $("#formbeatprice").serialize(),function(data) 
						{
	  						if (data.indexOf("#EMAILOK#")>=0)
	  						{
	  							$("#overlaypanel").load("/themes/1/files/beatprice/overlay2.html",function()
	  							{	
									$(".popmedown").click(function()
									{
										$("#overlaypanel").popMeDown();
									});							
	  							});
	  						}
	  						else
	  						{
	  							alert(data);	
	  						}
						});
					}
					return(false);
					
				});
				$("#overlaypanel").popMeUp();
		});
	});
});

