    function addError(errorList,errorText) {
		var error = document.createElement("li");
		error.appendChild(document.createTextNode(errorText));
		errorList.appendChild(error);
    }

	function checkEmailMe() {
		
		var errorList = document.getElementById("errorList");
		while(errorList.hasChildNodes()) {
			errorList.removeChild(errorList.firstChild);
		}
		
		var emailRegEx = /^[\w-]+(\.[\w-]+)*@([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*?\.[a-zA-Z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/
		if(!document.getElementById("email").value.match(emailRegEx))
			addError(errorList,"Your email address.  The one you entered is invalid.  Your email address may contain letters, numbers, dashes, underscores, periods, and 1 @ symbol.");
		if(document.getElementById("fName").value=="")
			addError(errorList,"First name");
		if(document.getElementById("lName").value=="")
			addError(errorList,"Last name");
		if(document.getElementById("messageEmail").value=="")
			addError(errorList,"Your message");

			
		if(document.getElementById("c-call").checked) {
			var p1=document.getElementById("p1").value;
			var p2=document.getElementById("p2").value;
			var p3=document.getElementById("p3").value;
			
			if(p1=="" || p2=="" || p3=="")
				addError(errorList,"Phone");
			if(isNaN(p1) || isNaN(p2) || isNaN(p3))
				addError(errorList,"Your phone number.  The one you entered is invalid.  Your phone number can only contain numbers.");
		}
		
		if(document.getElementById("c-mail").checked) {
			if(document.getElementById("address").value=="")
				addError(errorList,"Address");
			if(document.getElementById("city").value=="")
				addError(errorList,"City");
			if(document.getElementById("state").value=="")
				addError(errorList,"State");
			var zipRegEx = /^((\d{5}-\d{4})|(\d{5})|([a-zA-Z]\d[a-zA-Z][\s\-]?\d[a-zA-Z]\d))$/
			if(!document.getElementById("zipCode").value.match(zipRegEx))
				addError(errorList,"Your Zip/Postal Code.  The one you entered is invalid.");
		
		}

		return errorList.hasChildNodes();
	}

	function checkReferAFriend() {
		
		var errorList = document.getElementById("errorListRaf");
		while(errorList.hasChildNodes()) {
			errorList.removeChild(errorList.firstChild);
		}

		var emailRegEx = /^[\w-]+(\.[\w-]+)*@([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*?\.[a-zA-Z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/
		if(!document.getElementById("yEamil").value.match(emailRegEx))
			addError(errorList,"Your email address.  The one you entered is invalid.  Your email address may contain letters, numbers, dashes, underscores, periods, and 1 @ symbol.");
		if(!document.getElementById("fEamil").value.match(emailRegEx))
			addError(errorList,"Your friend's email address.  The one you entered is invalid.  Your email address may contain letters, numbers, dashes, underscores, periods, and 1 @ symbol.");
		if(document.getElementById("ffName").value=="")
			addError(errorList,"Your friend's first name.");
		if(document.getElementById("flName").value=="")
			addError(errorList,"Your friend's last name.");

		return errorList.hasChildNodes();


	}


        function submitEmailMe(modalID) {
			
			if(checkEmailMe()) {
				document.getElementById("errorContainer").style.display="block";
				return;
			} else {
				document.getElementById("errorContainer").style.display="none";
			}
        
                dojo.xhrPost ({
                        // The page that parses the POST request
                        url: "/b2c/AgentMicrositePortlets_Photo/servlet/EmailMe",
                
                        // Name of the Form we want to submit
                        form: "emailMeForm",
                
                        // Loads this function if everything went ok
                        load: function (data) {
                                // Put the data into the appropriate <div>
                                closeSelf(modalID); 
                                showDialog("emailMeConfirm");
                                document.getElementById("emailMeForm").reset();
                        },
                        // Call this function if an error happened
                        error: function (error) {
                                alert("error");
                        }
            });
        }
        
        function submitReferFriend() {


			if(checkReferAFriend()) {
				document.getElementById("errorContainerRaf").style.display="block";
				return;
			} else {
				document.getElementById("errorContainerRaf").style.display="none";
			}



                dojo.xhrPost ({
                        // The page that parses the POST request
                        url: "/b2c/AgentMicrositePortlets_Photo/servlet/ReferAFriend",
                
                        // Name of the Form we want to submit
                        form: "referAFriendEmailForm",
                
                        // Loads this function if everything went ok
                        load: function (data) {
                                // Put the data into the appropriate <div>
                                closeSelf('referFriend'); 
                                showDialog('referFriendThx');
				document.getElementById("referAFriendEmailForm").reset();
                        },
                        // Call this function if an error happened
                        error: function (error) {
                                alert("error");
                        }
            });
        }