
function subscribeWidget(url, containerId, labelText, submitButtonText, initialPrompt, finalPrompt, disableAfterSubmit) {

	var showInitialPrompt = true;
	var submitOnce = true;
	
	if ((typeof initialPrompt == "undefined") || (initialPrompt == null)) {
		
		initialPrompt = "";
				
	} // endif

	if ((typeof finalPrompt == "undefined") || (finalPrompt == null)) {
		
		finalPrompt = "";
		
	} // endif

	if ((typeof labelText == "undefined") || (labelText == null)) {
		
		labelText = "Email address:";
				
	} // endif
	
	if ((typeof submitButtonText == "undefined") || (submitButtonText == null)) {
		
		submitButtonText = "Go";
				
	} // endif

	if ((typeof disableAfterSubmit != "undefined") && (disableAfterSubmit != null)) {
		
		submitOnce = disableAfterSubmit;
				
	} // endif
	
	
	html = "<form id='" + containerId + "_form' method='POST'>";
	html += "<label id='" + containerId + "_label'>" + labelText + "</label>";
	html += "<input type='text' name='email' id='" + containerId + "_email' />";
	html += "<input type='button' id='" + containerId + "_button' value='" + submitButtonText + "' />";
	html += "</form>";
	
	document.getElementById(containerId).innerHTML = html;

	document.getElementById(containerId + '_button').onclick = submitForm;
	document.getElementById(containerId + '_email').onkeypress = gotEnter;
	
	var emailField = document.getElementById(containerId + "_email");
	emailField.setAttribute("class", "prompt");
	emailField.value = initialPrompt;
	
	emailField.onfocus = function () {
		
		if ((this.value == initialPrompt) || (this.value == finalPrompt)) {
		
			// clear out the field for input
			this.value = "";
			this.setAttribute("class", "");
			
		} // endif
		
	} // email onfocus function
	
	emailField.onblur = function () {
		
		if (this.value.length == 0) {
			
			// return to the prompt
			if (showInitialPrompt) {
				
				this.value = initialPrompt;
				
			} else {
				
				this.value = finalPrompt;
				
			} // endif
			
			this.setAttribute("class", "prompt");
			
		} // endif
		
	} // email onblur function
	
	function submitForm() {
		
		var xml;
		var pattern = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
		if (!pattern.test(document.getElementById(containerId + "_email").value)) {
	
			alert("Please enter a valid email address");
			var formField = document.getElementById(containerId + "_email");
			formField.focus();
			return false;
			
		} // endif
			
		if (window.XMLHttpRequest) {
			
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xml = new XMLHttpRequest();
		
		} else {
			
			// code for IE6, IE5
			xml = new ActiveXObject("Microsoft.XMLHTTP");
			
		} // endif
		
		finalUrl = url + "?email=" + document.getElementById(containerId + "_email").value; 
				
		xml.open("GET",encodeURI(finalUrl));
		xml.send();
		
		showInitialPrompt = false;
		var emailField = document.getElementById(containerId + '_email');
		
		emailField.value = finalPrompt;
		emailField.setAttribute("class", "prompt");
		
		if (submitOnce) {

			emailField.disabled = true;
			document.getElementById(containerId + '_button').disabled = true;
	
		} // endif
		
		return false;
		
	} // button onclick function

	function gotEnter() {
		
		if (window.event && (window.event.keyCode == 13)) {
			
			//submitForm();
			return false;
			
		} // endif
		
		return true;
		
	} // gotEnter()
	
} // subscribeWidget()



