var xmlhttp

//----------------------------------------------------------
// The following two functions are for search
var callback_fileview = function()
{
	if (xmlhttp.readyState==4)
	  {
	  document.getElementById("fileview").innerHTML=xmlhttp.responseText;
	  }
}

// delete a file
function deletefile(php, id_files)
{
	var r = confirm("Are you sure that you want to delete this file: "+id_files);
	if (r == true)
	{
		var poststr = "id_files="+id_files;;
		var url=php+"?cmd=file_delete";
		makePOSTRequest(url, poststr, callback_fileview);
	}
}


//----------------------------------------------------------
// The following two functions are for search
var callback_search = function()
{
	if (xmlhttp.readyState==4)
	  {
	  document.getElementById("results").innerHTML=xmlhttp.responseText;
	  }
}

function clearText()
{
	search.keyword.value = "";
}

function submitSimpleSearch2(searchkey,start)
{
	searchkey_ = escape(encodeURI(searchkey));
	if (searchkey != null) 
	{
		url="search.php";
		url=url+"?keyword="+searchkey_;
		url=url+"&start="+start;
		makeGETrequest(url, callback_search);
	}
}


function submitSimpleSearch()
{
	searchkey = escape(encodeURI(simple_search.keyword.value ));
	if (searchkey != null) 
	{
		url="search.php";
		url=url+"?keyword="+searchkey;
		makeGETrequest(url, callback_search);
	}
	else
	{
		alert('Please enter keywords or a phrase');
	}
}

//-------------------------------------------------------------
// common functions are for AJAX
// To make POST request
function makePOSTRequest(url, parameters, callback) {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }

	xmlhttp.onreadystatechange=callback;
	xmlhttp.open('POST', url, true);
	xmlhttp.overrideMimeType('text/html');
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", parameters.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(parameters);
}

// To make GET request
function makeGETrequest(url, callback)
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	xmlhttp.onreadystatechange=callback;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

// create xmlHTTPobject
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}

