// JavaScript Document

/*************************************  
* AJAX submit to capture emails
* 
* Written by: Belsien Thomas
**************************************/
function submitEmail() {
	var source = "MURAD-BLOG";	
	var email = $('#emailAddress').val();
	var optin = true;

	$.ajax({
		type: "GET",
		url: "http://www.murad.com/webservices/emailoptin/mrdEmailOptInJSON.jsp?email=" + email + "&source=" + source + "&optin=" + optin ,
		dataType: "jsonp",
		jsonpCallback: "parseResult"
	});
}

function parseResult(data) {
	
	//alert("Email Response was: " + data.ResponseMessage);
	if(data.ResponseMessage == "SUCCESS") {		
			$('#email-signup').replaceWith("<div id=\"Response\">Thank you for signing up for Murad.com emails. You will receive a confirmation email soon.</div>");		

		}
		if(data.ResponseMessage == "ERROR") {
			$('#signupResponse').replaceWith("<div id=\"Response\">There's a problem with that email address. Please check it and try again.</div>");
			//$('#email-form-c').css("width","555px");			
		}
		if(data.ResponseMessage == "DUPLICATE") {
			$('#signupResponse').replaceWith("<div id=\"Response\">Thank you for signing up. You're already on our email list, so stay tuned!</div>");
			//$('#email-form-c').css("width","650px");
		}	
}


