function send2friend(id)
{
	window.open("sendfriend.php?id=" + id,null,"height=110,width=160,status=0,titlebar=no,toolbar=no,menubar=no,location=no");
}
///////////////////////////////////////////////////////////////////////
// Author: Leon Cripps (leon@leon-cripps.com)
// Title: Ajax friend sender version 1.0
// Desc: mailing list script used in conjunction with php and mysql
///////////////////////////////////////////////////////////////////////
var AjaxServerPageName;

AjaxServerPageName = "../includes/ajaxsendfriend.php";

//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}


//Gets called when country combo box selection changes
function sendtofriend(id) 
{

	var txtemailaddress = document.getElementById('txtmailbox');
	
	var txtfriendsname = document.getElementById('txtyourname');
	
	 index = txtemailaddress.value.indexOf("@",txtemailaddress.value);
	 
	 document.getElementById('sendbtn').value = "wait";
	 
	 if(txtfriendsname.value == "")
	 {
	 
	  alert("You did not enter your name");
	  
	  document.getElementById('sendbtn').value = "send info";
	  
	 }else{
	 
		if(index == -1){
		  
			alert("You did not enter a valid email address");
			
			document.getElementById('sendbtn').value = "send info";
			
		}else{
			
			var randomnumber=Math.floor(Math.random()*101)
			// URL to get states for a given country
			var requestUrl = AjaxServerPageName + "?email=" + encodeURIComponent(txtemailaddress.value) + "&friend=" + encodeURIComponent(txtfriendsname.value) + "&id=" + encodeURIComponent(id) + "&unique=" + encodeURIComponent(randomnumber);

			CreateXmlHttp();
			
			// If browser supports XMLHTTPRequest object
			if(XmlHttp)
			{
				//Setting the event handler for the response
				XmlHttp.onreadystatechange = GetMailValue;
				
				//Initializes the request object with GET (METHOD of posting), 
				//Request URL and sets the request as asynchronous.
				XmlHttp.open("GET", requestUrl, true);
				
				//Sends the request to server
				XmlHttp.send(null);		
			}
			
			
		}
	
	}
		
	
}
//Called when response comes back from server
function GetMailValue()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			alert(XmlHttp.responsetext);
			
			document.getElementById('sendbtn').value = "send info";
			
			document.getElementById('txtmailbox').value = "";
			window.close();
			
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
		
	}
}
