function get_xmlhttp()
{
	xmlhttp=null
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		try { xmlhttp = new XMLHttpRequest (); } catch (e) 
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	}
	// code for IE
	else if (window.ActiveXObject)
	  {
		 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  }
	return xmlhttp;
}
function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


// use this on the onclick of a post. pass in the formname and page that you would like to do the processing. show_loading is true if you want to show a loading icon
function basecamp_ajax_post(formname,process_page)
{
	show_loading_image();
      var fields = new Array();
    if(formname){
      var ajax = formname;
    }
    for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
		 eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
    }

	
    var sendf = 'page='+process_page+'&'+fields.join('&');
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
				
			hide_loading_image();
			var str = xmlhttp.responseText;	
			window.location.href=window.location.href; // refreshes the page, by reloading the current link
		}
	}
	
}

function ajax_multiple_forms(formname,formname2,process_page)
{
	show_loading_image();
      var fields = new Array();
    if(formname){
      var ajax = formname;
    }
    for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
		 eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
    }
	 if(formname2){
      var ajax = formname2;
	   for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
		 eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
	 }
    }
   
	
    var sendf = 'page='+process_page+'&'+fields.join('&');
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			hide_loading_image();
			var str = xmlhttp.responseText;	
			window.location.href=window.location.href; // refreshes the page, by reloading the current link
		}
	}
	xmlhttp.send(null);
}


// use this on the onclick of a post. pass in the formname and page that you would like to do the processing. show_loading is true if you want to show a loading icon
function ajax_post(formname,process_page)
{
	show_loading_image();
      var fields = new Array();
    if(formname){
      var ajax = formname;
    }
    for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
		 eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
    }
    var sendf = 'page='+process_page+'&'+fields.join('&');
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			var str = xmlhttp.responseText;	
			hide_loading_image();
		}
	}
	xmlhttp.send(null);
}

// use this on the onclick of a post. pass in the formname and page that you would like to do the processing. show_loading is true if you want to show a loading icon
function send_basecamp_message(formname,process_page)
{
	show_loading_image();
	var work=document.getElementById('report_gen_table').innerHTML;
	var extra=document.getElementById('report_gen_extra_table').innerHTML;
	
      var fields = new Array();
    if(formname){
      var ajax = formname;
    }
    for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
		 eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
    }
    var sendf = 'page='+process_page+'&'+fields.join('&')+'&work='+work+'&extra='+extra;
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			hide_loading_image();
			window.location.href=window.location.href; 
		}
	}
	xmlhttp.send(null);
}

function list_timeoff()
{
    var sendf = 'page=list_timeoff';
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);

	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			var str = xmlhttp.responseText; 
			document.getElementById('list_timeoff').innerHTML=str;
		}
	}
	xmlhttp.send(null);
}
function add_timeoff(formname,process_page)
{
      var fields = new Array();
    if(formname){
      var ajax = formname;
    }
    for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
		 eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
    }
    var sendf = 'page='+process_page+'&'+fields.join('&');
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			var str = xmlhttp.responseText; 
				document.getElementById('add_timeoff_status').innerHTML=str
			list_timeoff();
		}
	}
	xmlhttp.send(null);
}


function timeoff_change_status(id)
{
     
    var sendf = 'page=timeoff_process&status_id='+id;
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			var str = xmlhttp.responseText; 
			document.getElementById('add_timeoff_status').innerHTML=str;
			list_timeoff();
		}
	}
	xmlhttp.send(null);
}
function timeoff_delete(id)
{
     
    var sendf = 'page=timeoff_process&remove_id='+id;
	sendf=trimAll(sendf);
	var xmlhttp=get_xmlhttp();
	xmlhttp.open("POST", onetime_root()+'server_handler.php',true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(sendf);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			var str = xmlhttp.responseText; 
			document.getElementById('add_timeoff_status').innerHTML=str;
			list_timeoff();
		}
	}
	xmlhttp.send(null);
}



