// The name of the cookie that will store 
// if the user has been added to the mailing 
// list or not.
var ckMailingListPrompt = "foleybf_mail_list_cookie";

function mailingListInit() {
	
	// If the user does not have cookies
	// enabled don't bother them with a 
	// message about our mailing list.
	if(hasCookiesEnabled()) {
		// Check and see if the user has a cookie set
		// that specifies that they have either already 
		// been added to the mailing list or that they have 
		// chosen not to be added to the mailing list.
		var isNewUser = readCookie(ckMailingListPrompt);
		
		isNewUser = (isNewUser == null) ? true : false;
		
		if(isNewUser) {
			// Display either the message about the ipod 
			// give away or the normal message after the 
			// contest.
			displayMessage();
		}
	}
}

function setMailingListCookie(toggle) {
	
	if(toggle)
		writeCookie( ckMailingListPrompt, "notNewUser", 365);
	else
		deleteCookie(ckMailingListPrompt);
}

function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	
	if(browser == "Microsoft Internet Explorer")
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		ro = new XMLHttpRequest();
	}
	
	return ro;
}

function sndAddMailingAddressReq() {
	
	if(submitNSetCookie()) {
		var emailAddr = document.getElementById("email").value;
	
		emailAddr = escape(emailAddr);
	
			
		http.open('POST', '/cgi-bin/MailingListAddRequestAJAX.pl', true);
		http.setRequestHeader("Content-type", 
                         "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", emailAddr.length);
		http.setRequestHeader("Connection", "close");		

   		http.onreadystatechange = function() {

			if(http.readyState == 4 && http.status == 200)
			{
				var responseText = null;
				responseText = http.responseText;
				if(responseText == "success")
				{
					/*
					var msgElement = document.getElementById("messageDiv");
					msgElement.innerHTML = "Thank you.";
					
					var form1 = document.getElementById("form1");
					form1.style.visibility="hidden"; 
					*/
					
										var center = document.createElement("CENTER");
					var h2Text = document.createElement("H2");
					
					var br0 = document.createElement("BR");
					var br1 = document.createElement("BR");
					var br2 = document.createElement("BR");
					var br3 = document.createElement("BR");
					var br4 = document.createElement("BR");
					
					var br5 = document.createElement("BR");
					
					var closeButton = document.createElement("BUTTON");
					var msgElement = document.getElementById("messageDiv");
					
					h2Text.innerHTML = "Thank You!";
					closeButton.innerHTML = "Close";
					
					closeButton.id = "closeButton";
					closeButton.onclick=function() { tb_remove(); };
					
					center.appendChild(br0);
					center.appendChild(br1);
					center.appendChild(br2);
					center.appendChild(br3);
					center.appendChild(br4);
					center.appendChild(h2Text);
					center.appendChild(br5);
					center.appendChild(closeButton);
					
					msgElement.innerHTML = "";
					msgElement.appendChild(center);
					
					
					
					closeButton.style.className="popover";
					
					
					var form1 = document.getElementById("form1");
					form1.style.visibility="hidden";
					

				} else {
					alert("responseText: " + responseText);
				}
			}
		};		

		http.send("email="+emailAddr);
		return false;
	}
}

var http = createRequestObject();


