/*
 *
 *	bespoke functions;
 *	used to build ie quicklinks
 *	
 *	
 *	
 *	
 *
 */
 

function BuildLink()
{
	this.body 			= Body;
	this.build 			= Build;
	this.getfunction 	= GetFunction;
	this.load			= Load;
	this.maxLength		= 2048;// ie max length
	this.test 			= Test;
	
	function Body()
	{
		var b = document.getElementsByTagName("BODY")[0];
		var c = document.getElementById("textareaTest").value;
		b.innerHTML+= c;
		alert("The following HTML was added to the body\n\n"+c)
	}
	function Build()
	{
		var f = this.getfunction() ;
		var href = "";
		var a = document.getElementById("anchorTarget");
		a.href = href = "javascript:void(new function(){"+ f +"})";
		var t = prompt("Please add a name for your function","");
		if (t)  {
			if (t.match(/"/)){
				t = t.replace(/"/g,'');		
			}
			a.innerHTML=a.title=t;
			a.className = "active";
		}
	}
	function GetFunction()
	{
		var f = document.getElementById("textareaSrc").value;
		f = f.replace(/\n/g,"");
		f = f.replace(/\r/g,"");
		f = f.replace(/\t/g," ");
		f = f.replace(/  /g," ");
		if (f.length > this.maxLength)
			alert("Warring, your script is too long and may not work, try removing spaces and shorten variable names")
		return f;
	}
	function Load(el)
	{
		el = (document.getElementById(el)) ? document.getElementById(el) : el.parentNode.getElementsByTagName('textarea')[0] ;
		document.getElementById("textareaSrc").value = el.value;
	}
	function Test()
	{
		var f = this.getfunction();
		
		location.href="javascript:void(new function(){"+ f +"})";
	}
}

var buildLink = new BuildLink;

// usage:
// _onLoad.add('yourfunctionname()');
