
function GetXmlHttpObject()
  { 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
			{
        objXMLHttp=new XMLHttpRequest()
      }
			else if (window.ActiveXObject)
			{
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
      return objXMLHttp
  }     


function load_content(div, url, poststr, upload)
{
		if(!div || !url)
			{
				return;
			}
		id(div).innerHTML = '<span class="loading">Loading..</span>';
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		
		
		
		if (xmlHttp.readyState == 4) {
		  
		  result = xmlHttp.responseText;
		  // with this I get all the response that a PHP page build
		  document.getElementById(div).innerHTML = result;
		  evalScripts( result );
		}
				
		xmlHttp.onreadystatechange = function ()
			{
				if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete"){
					
					var result = xmlHttp.responseText;
					id(div).innerHTML = result;
					evalScript( result);
					setForm();
					hide_calendar();
					date_chooser_init();
					date_chooser_call();
				}	
			}
		if(poststr)
			{
				xmlHttp.open('POST', url, true);
				xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlHttp.setRequestHeader("Content-length", poststr.length);
				xmlHttp.setRequestHeader("Connection", "close");
				xmlHttp.send(poststr);	
			}
		else
			{
				xmlHttp.open("GET", url, true);
				xmlHttp.send(null);
			}
			
}

// function used to run javascript after a AJAX call
function evalScript(scripts)
{	try
	{	if(scripts != '')	
		{	var script = "";
			scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
									 if (scripts !== null) script += arguments[1] + '\n';
										return '';});
			if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
		}
		return false;
	}
	catch(e)
	{	alert(e)
	}
}
