
/* Create a new XMLHttpRequest object to talk to the Web server */
//var xmlHttp = false;
//if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
 // xmlHttp = new XMLHttpRequest();
//}

var processing = "<img src=\"/images/misc/indicator_snake.gif\" width=\"16\" height=\"16\" align=\"absmiddle\">";

// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}



// stores the reference to the XMLHttpRequest object
var xmlHttp2 = createXmlHttpRequestObject2(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject2() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp2;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp2 = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp2 = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp2 = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp2)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp2;
}





var id = 1;
function callServerShowHide(ID) {

if ((ID == null) || (ID == "")) return;
id = ID; 
// Build the URL to connect to
var url = "ajax_homepage_edit.php?id=" + escape(id);
document.getElementById("filter_"+id).innerHTML=processing;
// Open a connection to the server
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateDBShowHide;
// Send the request
xmlHttp.send(null);

};

function updateDBShowHide() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("filter_"+id).innerHTML=xmlHttp.responseText;
}
}








var id = 1;
function callServerLightboxAdd(resourceID, userID) {

if ((resourceID == null) || (resourceID == "")) return;
id = resourceID; 
uID = userID;
//Build the URL to connect to
var url = "ajax_lightbox.php?resourceID=" + escape(resourceID)+"&userID=" + escape(userID)+"&action=add";
document.getElementById("lightbox_add_"+id).innerHTML=processing;
// Open a connection to the server
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateLightboxAdd;
// Send the request
xmlHttp.send(null);
};

function updateLightboxAdd() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("lightbox_add_"+id).innerHTML=response;
callServerLightboxTotal();
}
}


function callServerLightboxTotal() {
var url = "ajax_lightbox_count.php?userID=" + escape(uID)+"&action=total";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updateLightboxTotal;
xmlHttp.send(null);
//document.getElementById("lbox_count"
}

function updateLightboxTotal() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("lbox_count").innerHTML=response;
}
}


var id = 1;
function callServerDelRes(resourceID) {
if ((resourceID == null) || (resourceID == "")) return;
id = resourceID; 
//Build the URL to connect to
var url = "ajax_delete_resource.php?resourceID=" + escape(resourceID);
// Open a connection to the server
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateDelRes;
// Send the request
xmlHttp.send(null);
};

function updateDelRes() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("container").innerHTML=xmlHttp.responseText;
}
}



var start = 0;
var thetotal;
var current=0;
var filename='';
var nocreated;
var waiting = "<img src=\"images/html/clock.png\" width=\"16\" height=\"16\" align=\"absmiddle\"> Waiting";
var processing = "<img src=\"images/html/indicator_snake.gif\" width=\"16\" height=\"16\" align=\"absmiddle\"> Processing";
var complete = "<img src=\"images/html/accept.png\" width=\"16\" height=\"16\" align=\"absmiddle\"> Thumbnail Created";

function callServerThumb(total, created) {
thetotal = total;
nocreated = created;
filename = document.getElementById("field_"+current).value;
document.getElementById("waiting_"+current).innerHTML=processing;
document.getElementById("progress").innerHTML="<p>"+processing+" Thumbnails</p>";
 // Only go on if there are values for both fields
if ((thetotal== null) || (thetotal == "")) return;
 // Build the URL to connect to
var url = "ajax_create_thumbs.php?filename="+filename;
// Open a connection to the server
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updatePage;
// Send the request
xmlHttp.send(null);
}




function updatePage() {
  if (xmlHttp.readyState == 4) {
	document.getElementById("waiting_"+current).innerHTML=xmlHttp.responseText;
	document.getElementById("waiting_"+current).innerHTML=complete;
	
	current++;
	nocreated++;
	document.getElementById("sofar").innerHTML=nocreated;
	 callServerThumb(thetotal, nocreated);
  }
}




var processing2 = "<p><b><img src=\"images/html/ajax-loader.gif\" align=\"absmiddle\"> Processing</b></p>";

var folder = '';
var count = '';
var total = '';
var userID = 0;
function callServerFTP(f, i, tot, id) {
folder = f;
count = i;
total = tot;
userID = id;
 // Only go on if there are values for both fields
if ((folder== null) || (folder == "")) return;
 // Build the URL to connect to
var url = "ajax_upload.php?folder="+folder+"&count="+count+"&total="+total+"&userID="+userID;
document.getElementById("progressicon_"+folder).innerHTML=processing2;
document.getElementById("test").innerHTML="";
//alert(url);
// Open a connection to the server
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateFTP;
// Send the request
xmlHttp.send(null);
}




function updateFTP() {
  if (xmlHttp.readyState == 4) {
	document.getElementById("folder_"+folder).innerHTML=xmlHttp.responseText;
	count++;
	if(count<=total){
	 callServerFTP(folder, count, total, userID);
	}else{
		document.getElementById("progressicon_"+folder).innerHTML="<p><img src=\"images/gif/tick16.gif\" align=\"absmiddle\"> <b>Process complete</b></p>";
	}
  }
}






var folder = '';
var nextfolder = '';
var count = '';
var nexttotal = '';
var total = '';
var userID = 0;
function callServerFTPALL(i, t, nt, f, nf, id) {
folder = f;
nextfolder = nf;
count = i;
total = t;
nexttotal = nt;
userID = id;
 // Only go on if there are values for both fields
if ((i== null) || (i == "")) return;
 // Build the URL to connect to
var url = "ajax_upload_all.php?folder="+folder+"&nextfolder="+nextfolder+"&count="+count+"&total="+total+"&nexttotal="+nexttotal+"&userID="+userID;
//alert("progressicon_"+folder);
document.getElementById("progressicon_"+folder).innerHTML=processing2;
document.getElementById("test").innerHTML="Processing folders...";
// Open a connection to the server
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateFTPALL;
// Send the request
xmlHttp.send(null);
}




function updateFTPALL() {
  if (xmlHttp.readyState == 4) {
	document.getElementById("folder_"+folder).innerHTML=xmlHttp.responseText;
	count++;
	if(count<=total){
	 callServerFTPALL(count, total, nexttotal, folder, nextfolder, userID);
	}else{
		document.getElementById("progressicon_"+folder).innerHTML="<p><img src=\"images/gif/tick16.gif\" align=\"absmiddle\"> <b>Process complete</b></p>";
	}
  }
}