
/* 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=\"image/processing.gif\"  align=\"absmiddle\" vspace=2 hspace=2>";
var alpha = "<img src=\"button_plus_alpha.gif\" width=\"32\" height=\"32\" 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 = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // 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 uID = "";
var varID = "test";
function callAddToCart(userID, image, title, ID, album) {
// Get the city and state from the web form
//var loc = document.getElementById("loc").value;
// Only go on if there are values for both fields
if ((userID == null) || (userID == "")) return;
varID = ID; 
uID = userID; 
//document.getElementById('cart'+varID).innerHTML=processing;
// Build the URL to connect to
formatID = document.getElementById('format'+varID).value;
var url = "ajax_update_order.php?userID=" + escape(userID)+"&image="+ escape(image)+"&title="+ escape(title)+"&album="+ escape(album)+"&formatID="+ escape(formatID)+"&action=add";
document.getElementById('cart'+varID).innerHTML=processing;
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateAddToCart;
// Send the request
xmlHttp.send(null);
}

function updateAddToCart() {	
if (xmlHttp.readyState == 4) {
//document.getElementById("order").innerHTML=xmlHttp.responseText;
document.getElementById('cart'+varID).innerHTML=xmlHttp.responseText;
Callgettotal(uID);
}
}


function callDeleteFromCart(userID, formatID, title, ID) {
if ((userID == null) || (userID == "")) return;
varID = ID; 
uID = userID; 
var url = "ajax_update_order.php?userID="+escape(userID)+"&formatID="+escape(formatID)+"&title="+escape(title)+"&action=delete";
document.getElementById('cart'+varID).innerHTML=processing;
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateDeleteFromCart;
// Send the request
xmlHttp.send(null);
}

function updateDeleteFromCart() {	
if (xmlHttp.readyState == 4) {
//document.getElementById("order").innerHTML=xmlHttp.responseText;
document.getElementById('cart'+varID).innerHTML=xmlHttp.responseText;
Callgettotal(uID);
}
}







/*var uID = "";
var varID = "test";
function callDeleteFromCart(userID, image, title, ID, album) {
// Get the city and state from the web form
//var loc = document.getElementById("loc").value;
// Only go on if there are values for both fields
if ((userID == null) || (userID == "")) return;
varID = ID; 
uID = userID; 
//document.getElementById('cart'+varID).innerHTML=processing;
// Build the URL to connect to
formatID = document.getElementById('format'+varID).value;
var url = "ajax_add_to_order.php?userID=" + escape(userID)+"&image="+ escape(image)+"&title="+ escape(title)+"&album="+ escape(album)+"&formatID="+ escape(formatID);
document.getElementById('cart'+varID).innerHTML=processing;
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateDeleteFromCart;
// Send the request
xmlHttp.send(null);
}

function updateDeleteFromCart() {	
if (xmlHttp.readyState == 4) {
//document.getElementById("order").innerHTML=xmlHttp.responseText;
document.getElementById('cart'+varID).innerHTML=xmlHttp.responseText;
Callgettotal(uID);
}
}*/




function Callgettotal() {
	//alert('shabba');
var url2 = "ajax_get_total.php?userID=" + escape(uID);
xmlHttp2.open("GET", url2, true);
xmlHttp2.onreadystatechange = CallUpdateTotal;
xmlHttp2.send(null);
}

function CallUpdateTotal() {
if (xmlHttp2.readyState == 4) {
document.getElementById("total1").innerHTML=xmlHttp2.responseText;
document.getElementById("total2").innerHTML=xmlHttp2.responseText;
}
}











var thetitle = "";
var varID = "test";
var button = "";
function callDelete(userID, image, title, album, id) {
thetitle = title;
//button = "<img src=\"button_plus.gif\" width=\"26\" height=\"26\" align=\"absmiddle\" onclick=\"callAdd("+userID+",'"+image+"', '"+image+"','"+title+"', '"+id+"')\">";
// Get the city and state from the web form
//var loc = document.getElementById("loc").value;
// Only go on if there are values for both fields
if ((userID == null) || (userID == "")) return;
// Build the URL to connect to
var url = "ajax_delete_from_order.php?userID=" + escape(userID)+"&image="+ escape(image)+"&title="+ escape(title)+"&album="+ escape(album);
//document.getElementById("control_"+varID).innerHTML=processing;
//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 = updateDelete;
// Send the request
xmlHttp.send(null);
}

function updateDelete() {
	
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("order").innerHTML="wahoo";
//alert(document.getElementById("div_"+ok).innerHTML);
document.getElementById(thetitle).innerHTML=button;
//document.getElementById("test").innerHTML=xmlHttp.responseText.getElementById("testcontent");
previous = 10;
}
}
function callAlert() {
alert("wahoo");
}


var imageSelect = ''
function callSelect(id, image) {
// Get the city and state from the web form
//var loc = document.getElementById("loc").value;
// Only go on if there are values for both fields
if ((id == null) || (id == "")) return;
varID = id; 
imageSelect = image;
//document.getElementById('cart'+varID).innerHTML=processing;
// Build the URL to connect to
var url = "ajax_select.php?id=" + escape(varID);
//document.getElementById('cart'+varID).innerHTML=processing;
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateSelect;
// Send the request
xmlHttp.send(null);
}

function updateSelect() {	
if (xmlHttp.readyState == 4) {
document.getElementById(imageSelect).setAttribute("class", "thumb_selected");
}
}

function callDeselect(id, image) {
// Get the city and state from the web form
//var loc = document.getElementById("loc").value;
// Only go on if there are values for both fields
if ((id == null) || (id == "")) return;
varID = id; 
imageSelect = image;
//document.getElementById('cart'+varID).innerHTML=processing;
// Build the URL to connect to
var url = "ajax_deselect.php?id=" + escape(varID);
//document.getElementById('cart'+varID).innerHTML=processing;
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateDeselect;
// Send the request
xmlHttp.send(null);
}

function updateDeselect() {	
if (xmlHttp.readyState == 4) {
document.getElementById(imageSelect).setAttribute("class", "thumb");
}
}





var group = '';
var albumID = '';
var imageSelect = ''
function callChoose(id, image, group, album) {
	
// Get the city and state from the web form
//var loc = document.getElementById("loc").value;
// Only go on if there are values for both fields
if ((id == null) || (id == "")) return;
varID = id; 
group = group;
imageSelect = image;
albumID = album;
//alert(varID+"   "+group+"   "+imageSelect+"   "+albumID);
//document.getElementById('cart'+varID).innerHTML=processing;
// Build the URL to connect to
var url = "ajax_group.php?id=" + escape(varID)+"&group=" + escape(group);
//document.getElementById('cart'+varID).innerHTML=processing;
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
xmlHttp.setRequestHeader('Cache-Control', 'no-cache');
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateChoose;
// Send the request
xmlHttp.send(null);
}

function updateChoose() {	

if (xmlHttp.readyState == 4) {
	if(document.getElementById(imageSelect).className=="butt"){;
document.getElementById(imageSelect).setAttribute("className", "butt_selected");
document.getElementById(imageSelect).setAttribute("class", "butt_selected");
	}else{;
	document.getElementById(imageSelect).setAttribute("className", "butt");
	document.getElementById(imageSelect).setAttribute("class", "butt");
	};
//document.getElementById("t").innerHTML=xmlHttp.responseText;
xmlHttp.abort();
countSelected(albumID);
}
}






var action = '';
var uID = '';

function callChoosePrint(theaction, image, userID, id, albumid) {
// Get the city and state from the web form
//var loc = document.getElementById("loc").value;
// Only go on if there are values for both fields
if ((userID == null) || (userID == "")) return;
varID = id; 
action = theaction;
uID = userID;


//document.getElementById('cart'+varID).innerHTML=processing;
// Build the URL to connect to
var url = "ajax_ChoosePrint.php?userID=" + escape(userID)+"&image=" + escape(image)+"&action=" + escape(action)+"&albumid=" + escape(albumid);
//document.getElementById('cart'+varID).innerHTML=processing;
xmlHttp.open("GET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updateChoosePrint;
// Send the request
xmlHttp.send(null);
}

function updateChoosePrint() {	

if (xmlHttp.readyState == 4) {
	if(action=='add'){;
	//alert('add');
document.getElementById('div_'+varID).style.color='#00B9F0';
	}else if(action=='remove'){;
	//alert(action);
	document.getElementById('div_'+varID).style.color='#505050';
	};
countChosen();
}
}

function countChosen(){
var url = "ajax_countchosen.php?userID=" + escape(uID);
xmlHttp2.open("GET", url, true);
xmlHttp2.onreadystatechange = updateCountChosen;
xmlHttp2.send(null);
}

function updateCountChosen() {	
if (xmlHttp2.readyState == 4) {
document.getElementById("no_selected").innerHTML=xmlHttp2.responseText;
}
}









function countSelected(albumID){
	
	if ((albumID == null) || (albumID == "")) return;
var url = "ajax_selected_count.php?albumID=" + escape(albumID);
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
xmlHttp.setRequestHeader('Cache-Control', 'no-cache');
xmlHttp.onreadystatechange = updateCountSelected;
xmlHttp.send(null);
}

function updateCountSelected() {	
if (xmlHttp.readyState == 4) {
document.getElementById("no_selected").innerHTML=xmlHttp.responseText;
}
}