
function emailThisPage()
{
	var popupWidth = 510;
	var popupHeight = 510;
	var arrPageSize = GetPageSize();
	
	fadeScreenToBlack(arrPageSize[0], arrPageSize[1]);     
	
	var popup = document.getElementById('divPopupEmail');        	    
	popup.style.position = 'absolute';
	popup.style.top = '0px';
	popup.style.left = '0px';
	
	var left = Math.floor(arrPageSize[0] / 2) - Math.floor(popupWidth / 2) + arrPageSize[4];
	left = (left < 0) ? 0 : left;
	var top = Math.floor(arrPageSize[3] / 2) - Math.floor(popupHeight / 2) + arrPageSize[5];
	top = (top < 0) ? 0 : top;
	
	popup.style.display = 'block';
	popup.style.marginLeft = left + 'px';
	popup.style.marginTop = top + 'px';
	
	document.getElementById('divEmailPopup_Sent').style.display = 'none';
	document.getElementById('divEmailPopup_Content').style.display = '';
	document.getElementById('divEmailPopup_Loading').style.display = 'none'; 
}    

function hideEmailPopup()
{
	fadeScreenToNormal();
	
	document.getElementById('divEmailPopup_Sent').style.display = 'none';
	document.getElementById('divEmailPopup_Content').style.display = '';
	document.getElementById('divEmailPopup_Loading').style.display = 'none';        
		
	var popup = document.getElementById('divPopupEmail');
	popup.style.display = 'none';
} 

function fadeScreenToBlack(pagewidth, pageheight)
{
	var fade = document.getElementById('fade');
	var num = parseInt(fade.className.replace('black_overlay_',''));
	fade.style.display = 'block';
	
	if (num == 1) {
		fade.style.width = pagewidth + 'px';
		fade.style.height = pageheight + 'px';        
		
		var homeFlash = document.getElementById('flashContent');
		if (homeFlash != null)
				homeFlash.style.display = 'none';	        
	}
	
	if (num < 6)
	{
			num++;
			fade.className = 'black_overlay_'+num;
			setTimeout('fadeScreenToBlack();', 25);
	}
}   

function fadeScreenToNormal()
{
	var fade = document.getElementById('fade');
	var num = parseInt(fade.className.replace('black_overlay_',''));
	num--;    
			
	if (num > 0) {
			fade.className = 'black_overlay_'+num;
			setTimeout('fadeScreenToNormal();', 25);
	} else {
			fade.style.display = 'none';
		var homeFlash = document.getElementById('flashContent');
		if (homeFlash != null)
				homeFlash.style.display = 'block';         
	}
}     

function sendEmailPopup()
{
	var fromName = document.getElementById('txtEmailPopup_SenderName').value;
	var fromEmail = document.getElementById('txtEmailPopup_SenderEmail').value;
	var toName = document.getElementById('txtEmailPopup_RecipientName').value;
	var toEmail = document.getElementById('txtEmailPopup_RecipientEmail').value;
	var message = document.getElementById('txtEmailPopup_Message').value;
	var privacy = document.getElementById('chkEmailPopup_Privacy').checked;
	
	var validResponse = '';
	validResponse += (fromName == 0) ? 'Please enter your name.\n' : '';
	validResponse += (ValidEmail(fromEmail)) ? 'Please enter your valid email address.\n' : '';
	validResponse += (toName == 0) ? 'Please enter your friend\'s name.\n' : '';
	validResponse += (ValidEmail(toEmail)) ? 'Please enter your friend\'s valid email address.\n' : '';		
	validResponse += (!privacy) ? 'You must agree to the terms of privacy to continue.\n' : '';		

	if (validResponse != '') {
		alert('Some fields need to be corrected:\n\n' + validResponse);
		return false;
	}	 else { 
		var xhr; 
		try {
			xhr = new XMLHttpRequest(); 
		} catch(e) {
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}

		document.getElementById('divEmailPopup_Sent').style.display = 'none';
		document.getElementById('divEmailPopup_Content').style.display = 'none';
		document.getElementById('divEmailPopup_Loading').style.display = 'block';
		
		var url = 'emailPage.php?do=emailPage';
		var emailForm = '&fromName='+fromName;
		emailForm += '&fromEmail='+fromEmail;
		emailForm += '&toName='+toName;
		emailForm += '&toEmail='+toEmail;
		emailForm += '&message='+escape(message);
		emailForm += '&mailUrl='+ escape(location.href);
		emailForm += '&dt='+Date();
		
		xhr.open('POST', url,  true);
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhr.onreadystatechange  = function() {
			if(xhr.readyState  == 4 && xhr.status  == 200) {
				var response = xhr.responseText;
				if (response == '1') {
					document.emailPageForm.reset();
					document.getElementById('divEmailPopup_Sent').style.display = 'block';
					document.getElementById('divEmailPopup_Content').style.display = 'none';
					document.getElementById('divEmailPopup_Loading').style.display = 'none';	
				} else {
					alert('Your email could not be sent at the moment. Please try again later.');
					document.getElementById('divEmailPopup_Sent').style.display = 'none';
					document.getElementById('divEmailPopup_Content').style.display = 'block';
					document.getElementById('divEmailPopup_Loading').style.display = 'none';		
				}
			}
		}; 		
		xhr.send(emailForm);	
	}
} 

function GetPageSize() { var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight) { xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; }; var windowWidth, windowHeight; if (self.innerHeight) { windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; }; var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body; var leftScroll = document.all ? iebody.scrollLeft : pageXOffset; var topScroll = document.all ? iebody.scrollTop : pageYOffset; if(yScroll < windowHeight) { pageHeight = yScroll; } else { pageHeight = yScroll; } if(xScroll < windowWidth) { pageWidth = xScroll; } else { pageWidth = xScroll; }; var arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight, leftScroll, topScroll); return arrayPageSize; }
function ValidEmail(str) { var supported = 0; if (window.RegExp) { var tStr = "a"; var tReg = new RegExp(tStr); if (tReg.test(tStr)) supported = 1; } if (!supported) { return (str.indexOf(".") <= 2) || (str.indexOf("@") < 0); } var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)"); var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"); return (r1.test(str) || !r2.test(str)); }

