function ajaxFunction(div,type,url,twirl)
{
//blank reset
if(url == "reset"){//RESPONSE FOR RESET
document.getElementById(div).innerHTML="";
return false;
}

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  
  xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==1)
      {
		 if(twirl != 0){document.getElementById(div).innerHTML="<img src='Images/Loading/"+twirl+".gif' width='16' height='16' border='0' />";}
      }
		if(xmlHttp.readyState==2)
      {
		 if(twirl != 0){document.getElementById(div).innerHTML="<img src='Images/Loading/"+twirl+".gif' width='16' height='16' border='0' />";}
      }
	if(xmlHttp.readyState==3)
      {
		 if(twirl != 0){document.getElementById(div).innerHTML="<img src='Images/Loading/"+twirl+".gif' width='16' height='16' border='0' />";}
      }
    if(xmlHttp.readyState==4)
      {
		if(xmlHttp.status  == 200){
	 	 	document.getElementById(div).innerHTML=xmlHttp.responseText;
		}else{
			return 0;
		}
	  
	  ///////////////////////////START RESPONSES///////////////////////
	  //login complete
	  if(xmlHttp.responseText == "loading..."){
		  document.getElementById("returnLogin").innerHTML="Login Successfull!";
	  	  window.location="?p=login_home";
	  }
	  
	  //comment sent
	  if(xmlHttp.responseText == "commentsent"){
		  document.getElementById("commentDiv").innerHTML="<div class='msg-success'>Your comment has been sent. You should see it below under 'sent comments'.</div>";
	  	 //run comment grab again
		 ajaxFunction('grabComments', 'GET', 'comments_grab.php?id=session','blue');
	  }
	  
	  //new user added
	  if(xmlHttp.responseText == "newUserComplete"){
		  document.getElementById("newUserForm").innerHTML="";
		  document.getElementById("attemptNewUser").innerHTML="<div class='msg-success'>The user has now been added and can log in if you chose to make their account active.</div>";	  
	  }
	  
	  //account updated
	  if(xmlHttp.responseText == "account_updated"){
		  document.getElementById("account_done").innerHTML="";
		  document.getElementById("account_response").innerHTML="<div class='msg-success'>You have updated your account. Any future forms will require this new information.</div>";	  
	  }
	  
	  //rating sent
	  if(xmlHttp.responseText == "sending rating"){
		  ajaxFunction('rating_add', 'GET', 'flash_rate.php?gid=response');
	  	  ajaxFunction('rating_grab', 'GET', 'flash_rate_grab.php?gid=na');
	  }
	  
	  //user has been updated
	  if(xmlHttp.responseText == "user edited"){
 		  document.getElementById("attemptEditUser").innerHTML="<div class='msg-success'>The user has been saved. The list will update...</div>";
	  	  window.location="?p=manage_users&d=1";
	  }
	  
	  //folder added
	  if(xmlHttp.responseText == "folder added"){
 		  document.getElementById("attemptAddFolder").innerHTML="<div class='msg-success'>The new folder has been added!</div>";
	  	  window.location="?p=manage_folders&a=1";
	  }
	  
	  //folder edited
	  if(xmlHttp.responseText == "folder updated"){
 		  document.getElementById("attemptFolderInfo").innerHTML="<div class='msg-success'>The folder was updated! List updating...</div>";
	  	  window.location="?p=manage_folders&e=1";
	  }
	  
	  //folder deleted
	  if(xmlHttp.responseText == "folder deleted"){
 		  document.getElementById("attemptFolderInfo").innerHTML="<div class='msg-success'>The folder was deleted! List updating...</div>";
	  	  window.location="?p=manage_folders&d=1";
	  }
	  
	  //comment deleted
	  if(xmlHttp.responseText == "comments_delete"){
 		  document.getElementById("comment_view").innerHTML="<div class='msg-success'>The comment was removed. The list below is refreshing...</div>";
	  	  ajaxFunction('comment_grab', 'GET', 'manage_comments_grab.php', 'blue');
	  }
	  //flash add - stage 2 completed
	  if(xmlHttp.responseText == "s2 complete"){
 		  document.getElementById("addForm").innerHTML="";
		  window.location='?p=flash_add_s3';
	  }
	  //flash saved
	  if(xmlHttp.responseText == "flash updated"){
 		  document.getElementById("flash_view").innerHTML="<div class='msg-success'>The flash file was saved!</div>";
		  window.location='?p=manage_flash';
	  }
	  //flash deleted
	  if(xmlHttp.responseText == "file deleted"){
 		  document.getElementById("flash_view").innerHTML="<div class='msg-success'>The flash file was deleted!</div>";
		  window.location='?p=manage_flash';
	  }
	 ///////////////////////////END RESPONSES///////////////////////
	  
      }
    }
  
  xmlHttp.open(type,url,true);
  xmlHttp.send(null);
  }