// JavaScript Document

//  Pop up
function popitup(url) {
	newwindow=window.open(url,'name','height=300,width=350,scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}

//Submit the sidebar email

/*function sidebarSubmitEmail() {
	//alert("inside sidebarSubmitEmail");
	var source = "EXT-CLEANSCENE";
	var email = $('#emailAddress').val();
	var optin = true;
//	console.log("submitting to JSON service with: " + "http://beta3.murad.com/webservices/emailoptin/mrdEmailOptInJSON.jsp?email=" + email + "&firstName=" + fname + "&lastName=" + lname + "&zip=" + zip + "&source=" + source  + "&optin=" + optin );
	$.ajax({
		type: "GET",
		url: "http://beta3.murad.com/webservices/emailoptin/mrdEmailOptInJSON.jsp?email=" + email + "&source=" + source + "&optin=" + optin ,
		dataType: "jsonp",
		jsonpCallback: "parseResult"
		//jsonpCallback: ({alert("annonymous callback function")})
	});
}*/

//Submit the footer email

function submitEmail() {
	var source = "EXT-CLEANSCENE";
	var email = $('#emailAddress').val();
	var optin = true;
//	console.log("submitting to JSON service with: " + "http://beta3.murad.com/webservices/emailoptin/mrdEmailOptInJSON.jsp?email=" + email + "&firstName=" + fname + "&lastName=" + lname + "&zip=" + zip + "&source=" + source  + "&optin=" + optin );
	$.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) {
//	console.log("Email Response was: " + data.ResponseMessage);
	if(data.ResponseMessage == "SUCCESS") {		
			$('#footerReplacer').replaceWith("<div id=\"signupResponse\"><img src=\"/wp-content/themes/clean-scene/images/txt_email_signup_sucsess.png\" alt=\"\" border=\"0\" /></div>");
			$('#sidebarReplacer').replaceWith("<div id=\"signupResponseSidebar\"><img src=\"/wp-content/themes/clean-scene/images/txt-sidebar-subscribe-welcome.png\" alt=\"\" border=\"0\" /></div>");
					
		}
		if(data.ResponseMessage == "ERROR") {
			$('#signupResponseSidebar img').replaceWith("<img src=\"/wp-content/themes/clean-scene/images/txt-sidebar-subscribe-error.png\" alt=\"\" border=\"0\" />");
			$('#signupResponse img').replaceWith("<img src=\"/wp-content/themes/clean-scene/images/txt_email_signup_error.png\" alt=\"\" border=\"0\" />");
						
		}
		if(data.ResponseMessage == "DUPLICATE") {
			$('#sidebarReplacer').replaceWith("<div id=\"signupResponseSidebar\"><img src=\"/wp-content/themes/clean-scene/images/txt-sidebar-subscribe-welcome.png\" alt=\"\" border=\"0\" /></div>");
			$('#footerReplacer').replaceWith("<div id=\"signupResponse\"><img src=\"/wp-content/themes/clean-scene/images/txt_email_signup_sucsess.png\" alt=\"\" border=\"0\" />");
			
		}	
}





//Clear and reset the input fields 
function clearText(field){

    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}



function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

function getQuizTotal () {
	var total = 1;
	
	var Answer1 = querySt("q1");
	var Answer2 = querySt("q2");
	var Answer3 = querySt("q3");
	var Answer4 = querySt("q4");
	var Answer5 = querySt("q5");
	
	if (Answer1 == 4) total++; 
	if (Answer2 == 2) total++;
	if (Answer3 == 1) total++;
	if (Answer4 == 4) total++;
	if (Answer5 == 3) total++;
	
	return total;
}

