    function CheckMandatoryFields() {        var errorMsg ="";        var fieldList = checkSubscriptionFields();  	    if (fieldList != "") {	        errorMsg = "The following information is needed to process your request:" + "\n" + fieldList;	   	    alert(errorMsg);    		    return false;	    } else {	        return true;        }	}	     function checkSubscriptionFields(){        // function to check if the required fields are empty or null.        var fieldList = "";        var fName = eval("document.getElementById('forename').value");        var sName = eval("document.getElementById('surname').value");        var sEmail = eval("document.getElementById('emailaddress').value");        var sConfirmEmail = eval("document.getElementById('emailaddressconfirmation').value");        var sPostcode = eval("document.getElementById('postcode').value");        if (fName==""){          fieldList +=" -- Forename\n";        }        if (sName==""){          fieldList +=" -- Surname\n";        }        if (sEmail==""){          fieldList +=" -- E-mail Address\n";        }        if (sConfirmEmail==""){          fieldList +=" -- Confirm E-mail Address\n";        }        if (sPostcode==""){          fieldList +=" -- ZIP/Postal Code\n";        }            return fieldList;    }    function clearForm(oForm) {        // function to clear the subscription fields.	      	    var elements = oForm.elements; 	    oForm.reset();	    for(i=0; i<elements.length; i++) {		    field_type = elements[i].type.toLowerCase();		    var name = elements[i].name;				    // Do not clear the email data.		    if(name == 'xwdf_emailAddress' || name == 'wdf_emailAddress') {		        continue;		    }		    switch(field_type) {			    case "text":  			    case "textarea":		        case "hidden":					    elements[i].value = ""; 				    break;			    default: 				    break;		    }	    }	}		// object to hold the original content of subscriptionPopupBody    var originalContent;          function killPopup(o) {        // o - Object to kill        Popout.toggle('email_program_popout');        // replace the body with the original.               document.getElementById('subscriptionPopupBody').innerHTML = originalContent;    }	var EmailProgram = {};	EmailProgram.finalize = function() {	    // function to process the subscription details.	    var allFieldsPopulated = CheckMandatoryFields();		if (allFieldsPopulated == true) {            var url = "/" + "itd/amtrak/EmailSubscriptionConfirmation?";  	        var params = '_subscriptionfirstname=' + $F('forename') + '&_subscriptionlastname=' + $F('surname')+ '&_subscriptionemail=' + $F('emailaddress') + '&_subscriptionconfirmemail=' + $F('emailaddressconfirmation')+ '&_subscriptionpostcode=' + $F('postcode');   	    	var myAjax = new Ajax.Updater("subscriptionPopupBody", url, {method: 'get', parameters: params});		}	}
		   	EmailProgram.initialize = function() {        // function to process the initial subscription email.        originalContent = document.getElementById('subscriptionPopupBody').innerHTML;        if ($F('emailaddress') < 1) {            errorMsg = "Please enter an email address to subscribe.";            alert(errorMsg);        } else {            var url = "/" + "itd/amtrak/EmailSubscription?";   	        var params = '_subscriptionemail=' + $F('emailaddress'); 		    var myAjax = new Ajax.Updater("subscriptionPopupBody", url, {method: 'get', parameters: params});		    Popout.toggle('email_program_popout');        }    }
	


