function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}



function showEmailToFriend()
{
        document.getElementById("emailtofriend").style.display='';
        document.getElementById("emailtofriend").innerHTML='<div id="emailtofriendcontent" style="padding:5px;font-size:small;"><b>Email this Page to your Friend!</b><br>Enter your email address: <input type="text" name="fromaddress" id="fromaddress" /><br>Enter your Friends email address: <input type="text" name="toaddress" id="toaddress" /><br><input type="button" value="Send Email" onclick="mailThisUrl();"></div><div style="text-align:right;padding:5px;"><input type="button" value="close" onclick="hideEmailToFriend();"></div>';
}

function hideEmailToFriend()
{
        document.getElementById("emailtofriend").style.display='none';
        document.getElementById("emailtofriend").innerHTML='';
}



function mailThisUrl() {
    // sends the email...
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 

	var toaddress = document.getElementById("toaddress");
	var fromaddress = document.getElementById("fromaddress");

	fromaddress.style.border='1px solid #7F9DB9';
	toaddress.style.border='1px solid #7F9DB9';

	var goodTo = toaddress.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	var goodFrom = fromaddress.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
        
        if (goodFrom == null)
        {
        	alert("Please enter a valid e-mail address.");
    		fromaddress.focus();
    		fromaddress.select();
    		fromaddress.style.border='2px solid red';

        } 
	else if (goodTo == null)
	{
        	alert("Please enter a valid e-mail address.");
    		toaddress.focus();
    		toaddress.select();
    		toaddress.style.border='2px solid red';
        }
	else
	{
		u = window.location;
		var url="emailtofriend-script.asp";
		url=url+"?toaddress="+toaddress.value;
		url=url+"&fromaddress="+fromaddress.value;
		url=url+"&url="+u;
		url=url+"&sid="+new Date().getTime();
		xmlHttp.onreadystatechange=mailThisUrlstateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function mailThisUrlstateChanged() 
{ 
	if (xmlHttp.readyState < 4)
	{ 
		document.getElementById("emailtofriendcontent").innerHTML='<img src="images/loading.gif" /> <b>Sending Email...Please Wait!</b>';
	}
	else
        {
		document.getElementById("emailtofriendcontent").innerHTML='<b>Email has been succesfully send to your friend! Thank You for your interest!</b>';
	}
}


