// Setup dialog options
	$(document).ready(function() {
		$("#emaildialog").dialog({
			bgiframe: true, autoOpen: false, modal: true,draggable: false, resizable: false, height:300, width:350
		});
	});

	// Add click handler to anchor
	$('#emaillink').click(function() {
		Recaptcha.create("6LfObAsAAAAAAAjQCD8HIwZWcoLV7EdyZypy-C4Q","recaptcha",{theme: "white",callback: Recaptcha.focus_response_field});
		$('#emaildialog').dialog('open');
	})

	// Call to php validation and email sending.
	function emailvalidate()
	{
		var challengeField = $("input#recaptcha_challenge_field").val();
		var responseField = $("input#recaptcha_response_field").val();
		var name = $("input#name").val();
		var email = $("input#Email").val();
		var product = $(".title").html();
		//var product = "";

		$.post("ajaxemail.php", 
                     {"recaptcha_challenge_field" : challengeField, "recaptcha_response_field" : responseField, "email" : email, "name" : name, "link" : window.location.href, "product" : product},
                     function(response){
                         if(response == "0")
			{
				$('#emaildialog').dialog('close');
                                alert('Your email has been successfully sent.');
			}
                       else if(response == "1")
			{
				$("#error").html("Your email could not be sent at this time. Please try again later.");
                                Recaptcha.reload();
			}
                        else if(response == "2")
			{
				$("#error").html("Your email address is invalid.");
                                Recaptcha.reload();
			}
			else if(response == "3")
			{
				$("#error").html("Your captcha is incorrect. Please try again");
				Recaptcha.reload();
			}
                 });
	}
