    var pulseInterval;

    function ajaxEmail() {

	$('email_status_message').innerHTML = "";
	$('email_form_submit').style.display = "none";
	$('email_form_submit_mask').style.display = "inline";

	$("email_form_name_label").removeClassName("failure_message");
	$("email_form_from_label").removeClassName("failure_message");
	$("email_form_to_label").removeClassName("failure_message");
	$("email_form_note_label").removeClassName("failure_message");

	$('email_form_md5').value = hex_md5($('email_form_to').value);

	var valid = true;

	if ($("email_form_name").value == "") {

		$("email_form_name_label").addClassName("failure_message");
		valid = false;
	}

	if (!mvalidate("email",$("email_form_from").value,1,"")) {

		$("email_form_from_label").addClassName("failure_message");
		valid = false;
	}

	if (!mvalidate("email",$("email_form_to").value,1,"")) {

		$("email_form_to_label").addClassName("failure_message");
		valid = false;
	}

	if (valid) {

		pulseInterval = setInterval("pulseImage('email_form_submit_mask')", 40);

		new Ajax.Request('EmailProcess.aspx', 
			{
			method: 'post',
			parameters: $('email_popup_form').serialize(true),
			onSuccess: function(transport) {

				//alert(transport.responseText.escapeHTML() + " and " + transport.status);

				if (transport.responseText == "ok") {

					$('email_status_message').addClassName("success_message");
					$('email_status_message').innerHTML = "Email sent.";
					$('email_form_submit_mask').style.display = "none";
					$('email_form_submit').style.display = "inline";
					clearInterval(pulseInterval);
				}

				else {

					$('email_status_message').addClassName("failure_message");
					$('email_status_message').innerHTML = transport.responseText;
					$('email_form_submit_mask').style.display = "none";
					$('email_form_submit').style.display = "inline";
					clearInterval(pulseInterval);
				}
			},
			onFailure: function() {

				$('email_status_message').addClassName("failure_message");
				$('email_status_message').innerHTML = "Error connecting to server. Please try again in a moment.";
				$('email_form_submit_mask').style.display = "none";
				$('email_form_submit').style.display = "inline";
				clearInterval(pulseInterval);
			}
		}
		);
	}

	else {

		$('email_form_submit_mask').style.display = "none";
		$('email_form_submit').style.display = "inline";
	}

	return false;
    }

    var pulseDirection = -1;
    var pulseOpacity = 1.0;

    function pulseImage(id) {

	elem = $(id);
	newOpacity = pulseOpacity + (pulseDirection * 0.08);

	if (newOpacity < 0.08) {

		newOpacity = 0;
		pulseDirection = 1;
	}
	else if (newOpacity > 0.92) {

		newOpacity = 1;
		pulseDirection = -1;
	}

	elem.setOpacity(newOpacity);
	pulseOpacity = newOpacity;
    }

    var currentPopupID = null;

    function toggleScrim(popup_id) {

	scrim = $("scrim");

	if (scrim.style.display != "block") {

		var arrayPageSize = getPageSize();
		$('scrim').style.width = arrayPageSize[0] + 'px';
		$('scrim').style.height = arrayPageSize[1] + 'px';
		$('scrim').style.display = "block";

		if (popup_id != null) {

			$(popup_id).style.display = "block";
			currentPopupID = popup_id;
		}
	}

	else {

		scrim.style.display = "none";

		if (currentPopupID != null) {

			$(currentPopupID).style.display = "none";

			if (currentPopupID == "email_popup_outer" && $("email_status_message").innerHTML != "") {

				$("email_status_message").removeClass("success_message");
				$("email_status_message").removeClass("failure_message");
				$("email_status_message").innerHTML = "";
				$("email_form_name").value = "";
				$("email_form_from").value = "";
				$("email_form_to").value = "";
				$("email_form_note").innerHTML = "";
			}
		}
	}

	return false;
    }

    function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}