// JavaScript Document
	
	/*
	// this function is the Ajax 
	var xmlhttp
	var place_set
	
	function loadHTTPrequest(url, location)
	{
		place_set = location ; // this allows passing the value of location outside of the function
		
		xmlhttp=null
		// code for Mozilla, etc.
		
		if (window.XMLHttpRequest)
		{
		  xmlhttp=new XMLHttpRequest()
		}
	
		// code for IE
		else if (window.ActiveXObject)
		{
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	
		if (xmlhttp!=null)
		{
		  xmlhttp.onreadystatechange=state_Change
		  xmlhttp.open("GET",url,true)
		  xmlhttp.send(null)
		}
	
		else
		{
		  alert("Your browser does not support XMLHTTP.")
		}
	}
	
	function state_Change()
	{
		// if xmlhttp shows "loaded"
		if (xmlhttp.readyState==4)
		  {
			  // if "OK"
			  if (xmlhttp.status==200)
			  {
				  
		// calls email address matching function
		pick_up_emails(xmlhttp.responseText)
		
		//document.getElementById(place_set).innerHTML=xmlhttp.responseText
				 
	}
			  
			  else
			  {
			  	alert("Problem retrieving data:" + xmlhttp.statusText)
			  }
		  }
	}
	
	// email address matching function
	function pick_up_emails(the_response)
	{
		// checks for an email pattern
		var pattern = /[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+/g ;
		// this is the string that is passed from the httprequest
		var string = the_response ;
			
		// this creates an array of all instances of an email
		var matches = string.match(pattern);
				
				// if the string contains any instances of the matched pattern
				// this checks to see if matches exist and processes a new string
				if (matches) 
				{
					// this loops trhough the array, each time it replaces the match with the text in the string
					for (i = 0; i < matches.length; i++) 
					{	
					string = string.replace(matches[i], "<a href=\"mailto:"+matches[i]+"\">"+matches[i]+"</a>");
					}
				}
			
			// this prints the text to the page
			document.getElementById('bm_body').innerHTML = string ;
	}	
	*/

// this function is the Ajax 
	var xmlhttp
	var place_set
	
	function loadHTTPrequest(url, location)
	{
		place_set = location ; // this allows passing the value of location outside of the function
		
		xmlhttp=null
		// code for Mozilla, etc.
		
		if (window.XMLHttpRequest)
		{
		  xmlhttp=new XMLHttpRequest()
		}
	
		// code for IE
		else if (window.ActiveXObject)
		{
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	
		if (xmlhttp!=null)
		{
		  xmlhttp.onreadystatechange=state_Change
		  xmlhttp.open("GET",url,true)
		  xmlhttp.send(null)
		}
	
		else
		{
		  alert("Your browser does not support XMLHTTP.")
		}
	}
	
	function state_Change()
	{
		// if xmlhttp shows "loaded"
		if (xmlhttp.readyState==4)
		  {
			  // if "OK"
			  if (xmlhttp.status==200)
			  {
		
		// this pass the string to the function that checks for and parses email addresses
		pick_up_emails(xmlhttp.responseText)
		

				 
	}
			  
			  else
			  {
			  	alert("Problem retrieving data:" + xmlhttp.statusText)
			  }
		  }
	
	}
	
	
	//----------------------------------------------------------------------
	
		// this function not written by me, removes duplicates in the array
		// that I build from the emails in a document
		function RemoveDuplicates(arr)
		{
			//get sorted array as input and returns the same array without duplicates.
			var result=new Array();
			var lastValue="";
			
			for (var i=0; i<arr.length; i++)
			{
				var curValue=arr[i];
				if (curValue != lastValue)
				{
					 result[result.length] = curValue;
				}
			
				lastValue=curValue;
			}
		
		
		return result;
		}
		
		
		
	function pick_up_emails(gotten)
	{

			// checks for an email pattern
			var pattern = /[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+/g 
	
			var string = gotten //document.getElementById('bm_body').innerHTML ;
		
		
			// this creates an array of all instances of an email
			var matches = string.match(pattern);
		

		
			if (matches)
			{
				
			// sorts the array so that all duplicate entries are lined up so that they can be removed
			matches.sort()
		
			// creates an array without any duplicates
			var new_mails = RemoveDuplicates(matches)		
			
				// this loops trhough the array, each time it replaces the match with the text in the string
				for (i = 0; i < new_mails.length; i++) 
				{
				var test = new RegExp(new_mails[i], "g");
				
				//document.write( matches[i] );
					
				string = string.replace(test, "<a href='mailto:" + new_mails[i] + "'>" + new_mails[i] + "</a>");
				}
			}
		
			// edit 22 april 08
			//  
			// Checks to see if the page is in in edit mode, ie <body class="edit">
			// If yes, it uses the menu to paste the text content to the editor
			// 
			// Seems to be working well so far
			//
			var edit_body = document.getElementsByTagName('body');
			
			if (edit_body[0].getAttribute('classname') == 'edit')
			{
			
				var oEditor = FCKeditorAPI.GetInstance('fckeditor') ;
   				oEditor.SetHTML(string);
 
			}
			// end of 22 april edit
			
			// 22 april, I added the else but the method remains the same and is action
			// only if the body class does not equal 'edit'
			
			else
			{
				// this prints the text to the page
				document.getElementById('bm_body').innerHTML = string ;//matches.length;
			}

	}	