// JavaScript Document
function Ajax()
{
	var xmlhttp=false;
 	try 
	{
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try 
		{
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function urlencode(s) {
  s = encodeURIComponent(s);
  return s.replace(/~/g,'%7E').replace(/%20/g,'+');
}

function monitorPreview(path)
{
//  firstData = document.getElementById('post_content');
  IntervalId = setInterval("sendPostToPreview()", 2000)
}


function sendPostToPreview()
{ 
  data = document.getElementById('post_content');
	if (gdata != data.value)
	{
    var target = document.getElementById('live_comment_preview_main_content');
  	var url = gpath+"/process_preview.php";
  	var ajax = Ajax();
  	ajax.open("POST", url , true);
  	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	ajax.onreadystatechange=function() {
  		if (ajax.readyState==4) {
  			target.innerHTML = ajax.responseText
  		}
  	}
  	ajax.send("data="+urlencode(data.value));  }
  gdata = data.value;
  setTimeout("sendPostToPreview()",3000);
}

