var xmlHttp;
var loadstatustext="loading...";

var xmlHttp
var loadstatustext='<div style="margin:0px 0px 0px 0px; float:left; width:100%;text-align:center"><img src="/images/loading.gif" alt="" align="absmiddle" /></div>'

function ajaxSelect(page_id,filename,displayid,param1,param2)
{ 

	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 

	var url=filename;
	url=url+"?page_id="+page_id;
	url=url+"&sid="+Math.random();	
	if (param1) url=url+"&param1="+param1;	
	if (param2) url=url+"&param2="+param2;

	document.getElementById(displayid).innerHTML=loadstatustext;

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	
	function stateChanged() {
		if (xmlHttp.readyState==4) {		
			document.getElementById(displayid).innerHTML=xmlHttp.responseText;		
		}
	}
}

function easyAjax(url,displayid){

	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 

	url=url+"&sid="+Math.random();
	document.getElementById(displayid).innerHTML=loadstatustext
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	
	
	function stateChanged() {
		if (xmlHttp.readyState==4) { 
		document.getElementById(displayid).innerHTML=xmlHttp.responseText;
		}
	}
}

function easyAjaxPost(url,displayid)
{ 
	var http = new XMLHttpRequest();
	var text='';
 	var n="wysiwyg" +document.getElementById('editor').value;
	var text=document.getElementById(n).contentWindow.document.body.innerHTML;
	
	//var enter = new RegExp("chr(10)");
	//text = text.replace( enter , "<br />" );  //replaces all enters to <br />
	
	var space = new RegExp("&nbsp;");
	var br = new RegExp("<BR >");
	
	text = text.replace( br , '<br /> ' );  //replaces all <BR> to <br />
	text=text.replace(/\"/g,'\'');	//replaces all double quotes to single
	text=text.replace('\'','a');	//replaces all double quotes to single
	text = text.replace( space , ' ' );  //replaces all enters to 
	
	//alert(text);
	http.open("POST", url, true);
	
	var params = "text="+text;
	
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			
			document.getElementById(displayid).innerHTML=http.responseText;
			generate_wysiwyg(document.getElementById('editor').value);
		}
	}

	http.send(params);
}



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;
}



