var xmlHttp;
var urlToQL;
var urlQL;
function getQuickLink()
{
	//alert(document.getElementById('url').value);
	urlToQL = document.getElementById('url').value;
	//alert(urlToQL);
	if (urlToQL.length==0)
  	{ 
  		while(document.getElementById("quickLink").hasChildNodes())
		{
			document.getElementById("quickLink").removeChild(document.getElementById("quickLink").firstChild);	
			// Fill in here
		}
  		//document.getElementById("quickLink").appendChild(document.) = "No URL Was Entered";
		document.getElementById("quickLink").appendChild(document.createTextNode("No URL Was Entered"))
		document.getElementById("link").style.display = "none";
		return;
  	}
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Browser does not support HTTP Request");
  		return;
  	} 
	
	var url="php/qa.fetch.php";
	url=url+"?url="+ escape(urlToQL); 
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=updateElement;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

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 updateElement() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{ 
		while(document.getElementById("quickLink").hasChildNodes())
		{
			document.getElementById("quickLink").removeChild(document.getElementById("quickLink").firstChild);	
			
			// Fill in here
		}
		urlQL = null;

		document.getElementById("bodyDisplay").style.display = "block";
 		urlQL = xmlHttp.responseText;
		
		document.getElementById("quickLink").appendChild(document.createTextNode(urlQL));
		if(urlQL.substr(0,4) != "http")
		{
			document.getElementById("link").style.display = "none";
		}
		else
		{
			//alert(urlQL);
			document.getElementById("link").style.display = "block";
		}
	} 
}




function showPreviewPopup()
{
	//alert("your mom");
	window.open(urlQL, 'name','location=yes, menubar=yes, scrollbars=yes, titlebar=yes, toolbar=yes, resizable=yes');
	return false;
}