var xmlhttp = null;

function ajaxPreview(areaId, handler, actionLink){
	var text = document.getElementById(areaId).value;
	if (window.XMLHttpRequest)
	  // code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
	else if (window.ActiveXObject)
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	else
		alert("Your browser does not support XMLHTTP!");
	var url = actionLink;
	var i;
	var part = 256.0;
	var params = "";
	for(i = 0; i < Math.ceil(text.length / part); i++)
	{
		var str = text.substr(i * part, part);
		params += "&input[" + i + "]=" + Url.encode(str);
	}
	xmlhttp.onreadystatechange = handler;
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
}

function ajaxInit() 
{	
	// initiation of AJAX
	if(xmlhttp);
	else
	{
		if(window.XMLHttpRequest)
		{
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
			return true;
		}
		else
		if(window.ActiveXObject)
		{
			// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			return true;
		}
		else
			return false;
	}	
}

function ajaxSendData(dataToBeSend,url) 
{
	// initiation of AJAX	
	if(xmlhttp)
	{
		xmlhttp.onreadystatechange = ajaxHandler;
		xmlhttp.open("GET", url, false);
		if(dataToBeSend.length>1)
		{
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", dataToBeSend.length);
		}
		xmlhttp.setRequestHeader("Connection", "close");
		
		if(dataToBeSend.length<1)
			xmlhttp.send(null);
		else
			xmlhttp.send(dataToBeSend);
		return true;
	}
	else
		return false;
}

function ajaxHandler()
{
	if(xmlhttp)
	{		
		if(xmlhttp.readyState==4 && (xmlhttp.status==200 || xmlhttp.statusText=='OK'))
		{
			alert(xmlhttp.responseText);
			var head2= document.getElementsByTagName('head')[0];
			var script2= document.createElement('script');
			script2.type= 'text/javascript';
			script2.onreadystatechange= function () {
			   if (this.readyState == 'complete') helperTW();
			};
			script2.onload= helperTW;
			script2.innerHTML= xmlhttp.responseText;						
		}
	}
	else
		return false;
}

function helperTW()
{
	var twitting_box = new TWTR.Widget({ version: 2, type: 'profile', rpp: 3, interval: 6000, width: 290, height: 250, theme: {
	 shell: { background: '#f9f9f9', color: '#333333' }, tweets: { background: '#f9f9f9', color: '#666666', links: '#94a3c4' } },
  features: { scrollbar: false, loop: false, live: false, hashtags: false, timestamp: true, avatars: false, behavior: 'all' }}
  );
	twitting_box.render();
	twitting_box.setUser('tunedit');
	twitting_box.start();
}

function decodeRequest(str)
{
	str2=str.replace(/(\%3C)/g,'<');
	str2=str2.replace(/(\%3D)/g,'=');
	str2=str2.replace(/(\%22)/g,'"');
	str2=str2.replace(/(\%3B)/g,';');
	str2=str2.replace(/(\%3A)/g,':');
	str2=str2.replace(/(\%3E)/g,'>');
	str2=str2.replace(/(\%2F)/g,'/');
	str2=str2.replace(/(\%28)/g,'(');
	str2=str2.replace(/(\%29)/g,')');
	str2=str2.replace(/(\+)/g,' ');
	return str2;
}

