// JavaScript Document

var phpGrabberLocalPath = "annotations/grab.php";

var annotationsFolderURL = "http://cook.rfe.org/annotations/";

function CreateAnnotations()
{
	var xRequest=null;
	
	if (window.XMLHttpRequest)
	{
		xRequest=new XMLHttpRequest();
	} 
	else if (window.ActiveXObject)
	{
		xRequest=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (xRequest)
	{
		xRequest.onreadystatechange=function() 
		{
			if (xRequest.readyState==4)
			{				
				var annotationsFileURL = annotationsFolderURL + xRequest.responseText;				

				//alert(annotationsFileURL);

				if (document.getElementsByName("cref")[0] != null)
				{
					document.getElementsByName("cref")[0].value = decodeURIComponent(annotationsFileURL);
				}
			}
		};
		
		xRequest.open("POST", phpGrabberLocalPath, true);
		xRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xRequest.send("url=" + encodeURIComponent(document.location.href));
	}
	else
	{
		alert("An unexpected error occured while trying to create annotations file.\n\nGoogle search is not available");
	}	
}

