function makeHttpRequest(url, callback_function, return_xml) 
{ 
   var http_request = false; 

   if (window.XMLHttpRequest) { // Mozilla, Safari,... 
       http_request = new XMLHttpRequest(); 
       if (http_request.overrideMimeType) { 
           http_request.overrideMimeType('text/xml'); 
       } 
   } else if (window.ActiveXObject) { // IE 
       try { 
           http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
       } catch (e) { 
           try { 
               http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
           } catch (e) {} 
       } 
   } 

   if (!http_request) { 
       alert('Unfortunatelly you browser doesn\'t support this feature.'); 
       return false; 
   } 
   http_request.onreadystatechange = function() { 
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
               if (return_xml) { 
                   eval(callback_function + '(http_request.responseXML)'); 
               } else { 
                   eval(callback_function + '(http_request.responseText)'); 
               } 
           } else { 
               alert('There was a problem with the request.(Code: ' + http_request.status + ')'); 
           } 
       } 
   } 
   http_request.open('GET', url, true); 
   http_request.send(null); 
}

function pin(id)
{
	image = '<img src="images/w.gif" alt="waiting" title="waiting" style="padding: 2px 0 0 2px;" />';
	
	el = document.getElementById(id);
	if (el != null) 
	{ 
		el.innerHTML = image;
	}
	
	el2 = document.getElementById('n_'+id);
	if (el2 != null) 
	{ 
		el2.innerHTML = image;
	}
	makeHttpRequest('pin.php?id=' + id, 'pb');
}

function pb(feedback)
{
	pinArr = feedback.split('|');
	var image = '';
	
	if (pinArr[0] == 'pinned')
	{
		image = '<img src=\"images/p.gif\" alt=\"pinned\" title=\"Click to unpin this link\" />';
	}
	else if (pinArr[0] == 'unpinned')
	{
		image = '<img src="images/d.gif" alt="unpinned" title="This link will be removed next time you visit this page. Click here to put this link in the standard mode." />';
	}
	else
	{
		image = '<img src="images/b.gif" alt="normal" title="Click here to pin this link to the front page" />';
	}
	
	el = document.getElementById(pinArr[1]);
	if (el != null)
	{
		el.innerHTML = image;
	}
	
	el2 = document.getElementById('n_'+pinArr[1]);
	if (el2 != null)
	{
		el2.innerHTML = image;
	}
}

function toggle(elid)
{
	el = document.getElementById(elid);
	if (el.style.display != "block")
	{
		
		el.style.display = "block";
	}
	else
	{
		el.style.display = "none";
	}

	return false;
}

var elName = '';

function preview(el, str)
{
	elName = el;
	var strTitle = (elName == 'ptitle') ? 't=y&' : '';
	
	if (str.length > 0)
	{
		image = '<img src="../../images/w.gif" alt="waiting" title="waiting" style="padding: 2px 0 0 2px;" />';
		
		el = document.getElementById(elName);
		if (el != null) 
		{ 
			el.innerHTML = image;
		}
		
		makeHttpRequest('strip.php?'+strTitle+'str='+escape(str), 'show');
	}
}

function show(str)
{
	el = document.getElementById(elName);
	el.innerHTML = str;
}
