function makerequest(method, URL, params, div) 
{
	var http = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");

	if(method=='GET')  {
		http.open("GET", URL+"?"+params, true);
		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) {
				//alert(http.responseText);
				document.getElementById(div).innerHTML = http.responseText;
			}
		}
		http.send(null);
		if(!http.getResponseHeader("Date"))
		{
			var cached = http;
			http = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
			var ifModifiedSince = cached.getResponseHeader("Last-Modified");
			ifModifiedSince = (ifModifiedSince) ? ifModifiedSince : new Date(0); // January 1, 1970
			http.open("GET", URL+"?"+params, false);
			http.setRequestHeader("If-Modified-Since", ifModifiedSince);
			http.send("");
			if(http.status == 304)
			{
				http = cached;
			}
		}
	}

	if(method=='POST')  {
		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()
		{
			if(http.readyState == 4 && http.status == 200) 
			{
				//alert(http.responseText);
				document.getElementById(div).innerHTML = http.responseText;
			}
		}
		http.send(params);
	}
}

function getpage(URL, poststr) 
{	makerequest('POST', URL, poststr, 'ajaxcontent');
}

function getnew(URL, poststr) 
{	document.getElementById('newajaxcontent').style.display = 'block';
	makerequest('POST', URL, poststr, 'newajaxcontent');
}

function getdiv(URL, poststr, div)
{	document.getElementById(div).style.display = 'block';
	makerequest('POST', URL, poststr, div);
}

function deletepage(URL, poststr) 
{	var delconf = confirm("Are you sure you want to delete this record?");
	if(delconf == true)
		makerequest('POST', URL, poststr, 'ajaxcontent');
}

function deleteitem(URL, poststr, div) 
{	var delconf = confirm("Are you sure you want to delete this record?");
	if(delconf == true)
		makerequest('POST', URL, poststr, div);
}

function closediv(div)
{	document.getElementById(div).innerHTML = '';
	document.getElementById(div).style.display = 'none';
}

function postform(URL, fname) 
{	poststr = buildPOST(fname);
	//alert(fname);
	makerequest('POST', URL, poststr, 'ajaxcontent');
}

function postdivform(URL, fname, div) 
{	poststr = buildPOST(fname);
	makerequest('POST', URL, poststr, div);
}

function buildPOST(theFormName) 
{	theForm = document.forms[theFormName];
	var qs = ''
	for (e=0;e<theForm.elements.length;e++) 
	{	if (theForm.elements[e].name!='')
		{	if(theForm.elements[e].type == 'radio')
			{	if(theForm.elements[e].checked)
				{	var name = theForm.elements[e].name;
					qs+=(qs=='')?'':'&'
					qs+= name+'='+escape(theForm.elements[e].value);
				}
			}
			else if(theForm.elements[e].type == 'checkbox')
			{	var name = theForm.elements[e].name;
				qs+=(qs=='')?'':'&'
				if(theForm.elements[e].checked)
					qs+= name+'='+escape(theForm.elements[e].value);
				else
					qs+= name+'=';
			}			
			else
			{	var name = theForm.elements[e].name;
				var val = theForm.elements[e].value;
				 if(val.substring(0, 3) == '<p>')
					val = val.substring(3, val.length - 4);
				val.replace("\\", "\\\\")
				//alert(val);
				qs+=(qs=='')?'':'&'
				qs+= name+'='+escape(val);
			}
		}
	}
	return qs
}

function postselect(URL, selectval) 
{	poststr = selectval.name + '=' + selectval.value;
	makerequest('POST', URL, poststr, 'ajaxcontent');
}

function postparamselect(URL, selectval, postvals) 
{	poststr = selectval.name + '=' + selectval.value + postvals;
	makerequest('POST', URL, poststr, 'ajaxcontent');
}

function uploadimage(URL, poststr) 
{	poststr = poststr + '&img=' + document.getElementById("uploadFile").value;
	makerequest('POST', URL, poststr, 'imgholder');
}

function startCallback() 
{	return true;
}

function completeimgCallback(response)
{	document.getElementById('imgholder').innerHTML = response;
}

function completedocCallback(response, div)
{	document.getElementById(div).innerHTML = response;
	document.getElementById('newajaxform').innerHTML = '';
	document.getElementById('newajaxform').style.display = 'none';
}

function completecallback(response, div)
{	document.getElementById(div).innerHTML = response;
}

function toggleshow(div, formval, formfield)
{	if(formfield.value == formval)
		document.getElementById(div).style.display = 'block';
	else
		document.getElementById(div).style.display = 'none';
}

function adddateexp(dateval, formele)
{	mydate = new Date(dateval);
	myday = mydate.getDate();
	if(myday < 10)
		myday = '0' + myday;
	mymonth = mydate.getMonth() + 1;
	if(mymonth < 10)
		mymonth = '0' + mymonth;
	myyear = mydate.getFullYear() + 1;
	document.myform[formele].value = mymonth + '/' + myday + '/' + myyear
}