// The AJAX function...

function AJAX(){
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
}

// Timestamp for preventing IE caching the GET request (common function)

function fetch_unix_timestamp()
{
 return parseInt(new Date().getTime().toString().substring(0, 10))
}

////////////////////////////////
//
// Refreshing the DIV TIMEDIV
//
////////////////////////////////

function refreshdiv_timediv(){

	// Customise those settings

	var seconds = 5;
	var divid = "timediv";
	var url = "boo.php";

	// Create xmlHttp

	var xmlHttp_one = AJAX();

	// No cache

	var timestamp = fetch_unix_timestamp();
	var nocacheurl = url+"?t="+timestamp;

	// The code...

	xmlHttp_one.onreadystatechange=function(){
		if(xmlHttp_one.readyState==4){
			document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
			setTimeout('refreshdiv_timediv()',seconds*1000);
		}
	}
	xmlHttp_one.open("GET",nocacheurl,true);
	xmlHttp_one.send(null);
}

// Start the refreshing process

window.onload = function startrefresh(){
setTimeout('refreshdiv_timediv()',seconds*1000);
}

////////////////////////////////
//
// Refreshing the DIV TIMEINWASHINGTON
//
////////////////////////////////

function refreshdiv_timeinwashington(){

// Customise those settings

var seconds = 8;
var divid = "timeinwashington";
var url = "boo2.php";

// Create xmlHttp

var xmlHttp_two = AJAX();

// No cache

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

// The code...

xmlHttp_two.onreadystatechange=function(){
if(xmlHttp_two.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_two.responseText;
setTimeout('refreshdiv_timeinwashington()',seconds*1000);
}
}
xmlHttp_two.open("GET",nocacheurl,true);
xmlHttp_two.send(null);
}

// Start the refreshing process

window.onload = function startrefresh(){
setTimeout('refreshdiv_timeinwashington()',seconds*1000);
}

////////////////////////////////
//
// Refreshing the DIV OTHERDIV
//
////////////////////////////////

function refreshdiv_otherdiv(){

// Customise those settings

var seconds = 10;
var divid = "otherdiv";
var url = "boo3.php";

// Create xmlHttp

var xmlHttp_three = AJAX();

// No cache

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

// The code...

xmlHttp_three.onreadystatechange=function(){
if(xmlHttp_three.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_three.responseText;
setTimeout('refreshdiv_otherdiv()',seconds*1000);
}
}
xmlHttp_three.open("GET",nocacheurl,true);
xmlHttp_three.send(null);
}

// Start the refreshing process

var seconds;
window.onload = function startrefresh(){
setTimeout('refreshdiv_otherdiv()',seconds*1000);
}

////////////////////////////////
//
// Attempting product refresh
//
////////////////////////////////

function RefreshProductDisplayOLD(category){

	// Customise those settings

	var seconds = 10;
	var divid = "productDisplay";
	var url = "/inc/displayProducts.php?action=displayProducts&catID=category";

	// Create xmlHttp

	var xmlHttp_products = AJAX();

	// No cache

	var timestamp = fetch_unix_timestamp();
	var nocacheurl = url;

	// The code...

	xmlHttp_products.onreadystatechange=function(){
		if(xmlHttp_products.readyState==4){
			document.getElementById(divid).innerHTML=xmlHttp_products.responseText;
			//setTimeout('RefreshProductDisplay(category)',seconds*1000);
		}
	}
	xmlHttp_products.open("GET",nocacheurl,true);
	xmlHttp_products.send(null);
}

/*
// Start the refreshing process

var seconds;
window.onload = function startrefresh(){
setTimeout('refreshdiv_otherdiv()',seconds*1000);
}
*/

function RefreshProductDisplay(category, catName)
{
	var action='displayProducts';
	var catID=category;
	var passData = 'action='+escape(action)+'&catID='+escape(catID)+'&catName='+escape(catName);
	var AJAX = null;
	
	document.getElementById('productDisplay').innerHTML = '';
	document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/displayProducts.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('productDisplay').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function DisplayProductDescription(productID)
{
	var action='displayDescription';
	var passData = 'action='+escape(action)+'&catID='+escape(productID);
	var AJAX = null;
	
	document.getElementById('productDisplay').innerHTML = '';
	document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/displayProducts.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('productDisplay').innerHTML = AJAX.responseText; 
	      }                               
	   }                                  
	   AJAX.send(passData);
	}

}

function SwitchLargeImage(imageID)
{
	var action='getLargeImageLocation';
	var passData = 'action='+escape(action)+'&productID='+escape(imageID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('popupMainProductImage').src = AJAX.responseText; 
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function SwitchThumbImage(imageID)
{
	var action='getThumbImageLocation';
	var passData = 'action='+escape(action)+'&productID='+escape(null)+'&imageID='+escape(imageID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	         document.getElementById('mainProductImage').src = AJAX.responseText; 
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function FullSizeProductImagePopup(productID)
{
	var action='getFullSizeProductImagePopup';
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	var popupWidth;
	var popupHeight;
	
	if(windowHeight < windowWidth * 2/3)
	{
		popupHeight = Math.round(windowHeight * 0.99);
		popupWidth = Math.round(popupHeight * 3/2);
		
	}
	else
	{
		popupWidth = Math.round(.95 * windowWidth);
		popupHeight = Math.round(2/3 * popupWidth);
	}
	document.getElementById('fullSizeProductImagePopup').style.width = popupWidth + 'px';
	document.getElementById('fullSizeProductImagePopup').style.height = popupHeight + 'px';
	document.getElementById('fullSizeProductImagePopup').style.left = (windowWidth - popupWidth) / 2 + 'px';
	//document.getElementById('closeFullSizeProductImagePopupButton').style.left = document.getElementById('fullSizeProductImagePopup').offsetLeft - 15 + 'px';
	
	var passData = 'action='+escape(action)+'&productID='+escape(productID)+'&popupWidth='+escape(popupWidth)+'&popupHeight='+escape(popupHeight);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
			document.getElementById('fullSizeProductImagePopup').innerHTML = AJAX.responseText;
	        
	        document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledDark");
	        document.getElementById('fullSizeProductImagePopup').setAttribute("class", "fullSizeProductImagePopupEnabled");
	        //document.getElementById('closeFullSizeProductImagePopupButton').setAttribute("class", "closeFullSizeProductImagePopupButtonEnabled");
	        
	        // set top element based on browser height
	        SetPopupTopValue(document.getElementById('fullSizeProductImagePopup'), document.getElementById('closeFullSizeProductImagePopupButton'));
	        
	        // set left
	        //document.getElementById('closeFullSizeProductImagePopupButton').style.left = document.getElementById('popupMainProductImage').style.left + 'px';
			//alert('windowWidth: ' + windowWidth + ' left: ' + document.getElementById('closeFullSizeProductImagePopupButton').style.left);
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function GetWindowWidth()
{
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
}
 
function GetWindowHeight()
{
        var y = 0;
        if (self.innerHeight)
        {
                y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        return y;
}

function CloseFullSizeProductImagePopup()
{
	document.getElementById('fullSizeProductImagePopup').innerHTML = "";
	document.getElementById('fullSizeProductImagePopup').style.width = 0 + 'px';
	document.getElementById('fullSizeProductImagePopup').style.height = 0 + 'px';
	document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupDisabledDark");
	document.getElementById('fullSizeProductImagePopup').setAttribute("class", "fullSizeProductImagePopupDisabled");
	document.getElementById('closeFullSizeProductImagePopupButton').setAttribute("class", "closeFullSizeProductImagePopupButtonDisabled");
}

function SetPlaced(orderID)
{
	var action='setPlacedDateTime';
	var passData = 'action='+escape(action)+'&orderID='+escape(orderID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('placed' + '_' + orderID).innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function SetStarted(orderID)
{
	var action='setStartedDateTime';
	var passData = 'action='+escape(action)+'&orderID='+escape(orderID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	      	EnablePickedButtons(orderID);
	        document.getElementById('started' + '_' + orderID).innerHTML = AJAX.responseText;
	        UpdateOrderStatusOnScreen(orderID, 'STARTED');
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function EnablePickedButtons(orderID)
{
	var n_numTabs = $("#orderDetailsTableContainer_"+orderID+" > div").size();
	
	// start at one because we want to skip the header row div
	for(var i=1; i<n_numTabs; i++)
	{
		document.getElementById('pickedButton_'+ orderID + '_' + i).disabled = false;
	}
}

function SetReady(orderID, type)
{
	var action='setReadyDateTime';
	var passData = 'action='+escape(action)+'&orderID='+escape(orderID)+'&type='+escape(type);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('ready' + '_' + orderID).innerHTML = AJAX.responseText;
	         document.getElementById('deliveredButton' + '_' + orderID).disabled = false;
	         UpdateOrderStatusOnScreen(orderID, (type == 'Pickup' ? 'READY' : 'IN ROUTE'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function SetDelivered(orderID, type)
{
	var action='setDeliveredDateTime';
	var passData = 'action='+escape(action)+'&orderID='+escape(orderID)+'&type='+escape(type);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('delivered' + '_' + orderID).innerHTML = AJAX.responseText;
	         UpdateOrderStatusOnScreen(orderID, (type == 'Pickup' ? 'PICKEDUP' : 'DELIVERED'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function UpdateOrderStatusOnScreen(orderID, status)
{
	document.getElementById('status_'+orderID).innerHTML = ''+status;
}

function GetOrderDetails(orderID, started)
{
	if(document.getElementById('orderDetails' + '_' + orderID).innerHTML == '')
	{	
		var action='getOrderDetails';
		var passData = 'action='+escape(action)+'&orderID='+escape(orderID)+'&started='+escape(started);
		var AJAX = null;
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");
		   $("#notificationsLoaderMain").empty();	                                         
		   return false
		} else {
		   AJAX.open("POST", "inc/orderFunctions.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
		         document.getElementById('orderDetails' + '_' + orderID).innerHTML = AJAX.responseText;
		         document.getElementById('orderDetails' + '_' + orderID).scrollTop = document.getElementById('orderDetails' + '_' + orderID).offsetTop;
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}
	}
	else
	{
		document.getElementById('orderDetails' + '_' + orderID).innerHTML = '';
	}
}

function SetPicked(productID, orderID)
{
	var action='setPicked';
	var passData = 'action='+escape(action)+'&orderID='+escape(productID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	      	 EnableReadyButton(orderID);
	         document.getElementById('picked' + '_' + productID).innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function EnableReadyButton(orderID)
{
	var action='checkIfAllItemsPicked';
	var passData = 'action='+escape(action)+'&orderID='+escape(orderID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	      	if(AJAX.responseText.match("true"))
	      	{
	      		document.getElementById('readyButton_' + orderID).disabled = false;
	      	}
	         
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function Checkout()
{
	if(document.getElementById("basketTotalWrapNumber").innerHTML == '0.00')
	{
		alert('Please add something to your basket to checkout.');
	}
	else
	{
		document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
		
		var action = 'getReviewOrderScreen'
		var passData = 'action='+escape(action);
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");                                         
		   return false
		} else {
		   AJAX.open("POST", "inc/checkout.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
		         document.getElementById('productDisplay').innerHTML = AJAX.responseText;
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}
	}
}


function GoCheckout(basketTotal)
{
	document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';

	var action='goCheckout';
	var passData = 'action='+escape(action)+'&basketTotal='+escape(basketTotal);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/checkout.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
			document.getElementById('productDisplay').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}

}

function GoCheckoutDelivery(basketSubTotal, taxRate)
{
	if(document.getElementById("basketTotalWrapNumber").innerHTML < 10)
	{
		alert('Delivery requires at least a $10 order.');
	}
	else
	{
		document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
		
		var action='goCheckoutDelivery';
		var passData = 'action='+escape(action)+'&basketTotal='+escape(basketSubTotal)+'&taxRate='+escape(taxRate);
		var AJAX = null;
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");
		   $("#notificationsLoaderMain").empty();	                                         
		   return false
		} else {
		   AJAX.open("POST", "inc/checkout.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
				document.getElementById('productDisplay').innerHTML = AJAX.responseText;
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}

	}
}

function UpdateDeliveryAddressForm()
{
	if(document.getElementById('useProfileAddresForDeliverySelect').options[document.getElementById('useProfileAddresForDeliverySelect').selectedIndex].value == 'Yes')
	{
		var firstName = document.getElementById('userFirstName').value;
		var lastName = document.getElementById('userLastName').value;
		var phone = document.getElementById('userPhone').value;
		var address1 = document.getElementById('userAddress1').value;
		var address2 = document.getElementById('userAddress2').value;
		var city = document.getElementById('userCity').value;
		var state = document.getElementById('userState').value;
		var zip = document.getElementById('userZip').value;
		
		if(state != 'AR')
		{
			alert('Cannot use address in profile. Not registered in Arkansas.')
		}
		else
		{
			var zipAndCitySet = false;
			
			// Set zip code then city
			var childNodeArray = document.getElementById('deliveryZip').childNodes;
			for(var i=0; i<childNodeArray.length; i++)
			{
				if(childNodeArray[i].value == zip)
				{
					childNodeArray[i].selected = true;
					SetDeliveryCity();
					zipAndCitySet = true;
					break;
				}
			}
			
			// Set city then zip if not already set
			if(!zipAndCitySet)
			{
				var childNodeArray = document.getElementById('deliveryCity').childNodes;
				for(var i=0; i<childNodeArray.length; i++)
				{
					if(childNodeArray[i].value == city)
					{
						childNodeArray[i].selected = true;
						SetDeliveryZip();
						zipAndCitySet = true;
						break;
					}
				}
			}
			
			// Set address
			if(!zipAndCitySet)
			{
				// Don't set address because neither zip nor city matched
				alert('Cannot use address in profile, neither city nor zip are currently supported for deliveries.')
			}
			else
			{
				document.getElementById('deliveryFirstName').value = firstName;
				document.getElementById('deliveryLastName').value = lastName;
				document.getElementById('phone1').value = phone[0] + phone[1] + phone[2];
				document.getElementById('phone2').value = phone[3] + phone[4] + phone[5];
				document.getElementById('phone3').value = phone[6] + phone[7] + phone[8] + phone[9];
				document.getElementById('deliveryAddress1').value = address1;
				document.getElementById('deliveryAddress2').value = address2;
			}
		}
	}
	else
	{
		document.getElementById('deliveryFirstName').value = '';
		document.getElementById('deliveryLastName').value = '';
		document.getElementById('phone1').value = '';
		document.getElementById('phone2').value = '';
		document.getElementById('phone3').value = '';
		document.getElementById('deliveryAddress1').value = '';
		document.getElementById('deliveryAddress2').value = '';
	}
}

function SetDeliveryCity()
{
	var action = 'getCityForDeliveryZip';
	var zip = document.getElementById('deliveryZip').options[document.getElementById('deliveryZip').selectedIndex].value;
	var passData = 'action='+escape(action)+'&zip='+escape(zip);

	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/checkout.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	        var childNodeArray = document.getElementById('deliveryCity').childNodes;
			for(var i=0; i<childNodeArray.length; i++)
			{
				if(childNodeArray[i].value == AJAX.responseText)
				{
					childNodeArray[i].selected = true;
					UpdateDeliveryTotal(zip);
					break;
				}
			}
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
	
}

function SetDeliveryZip()
{
	var action = 'getZipForDeliveryCity';
	var city = document.getElementById('deliveryCity').options[document.getElementById('deliveryCity').selectedIndex].value;
	var passData = 'action='+escape(action)+'&city='+escape(city);

	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/checkout.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	        var childNodeArray = document.getElementById('deliveryZip').childNodes;
			for(var i=0; i<childNodeArray.length; i++)
			{
				if(childNodeArray[i].value == AJAX.responseText)
				{
					childNodeArray[i].selected = true;
					UpdateDeliveryTotal(AJAX.responseText);
					break;
				}
			}
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function UpdateDeliveryTotal(zip)
{
	var childNodeArray = document.getElementById('deliveryZip').childNodes;
	for(var i=0; i<childNodeArray.length; i++)
	{
		if(childNodeArray[i].value == zip)
		{
			document.getElementById('deliveryChargeNumber').innerHTML = childNodeArray[i].getAttribute("name");

			// times 100 and divide by 100 to round to 2 decimals
			var tax = Math.round(((parseFloat(childNodeArray[i].getAttribute("name")) + parseFloat(document.getElementById('deliverySubtotalNumber').innerHTML)) * parseFloat(document.getElementById('taxRate').value)) * 100) / 100;
			document.getElementById('deliveryTaxNumber').innerHTML = tax.toFixed(2);
			
			var total = Math.round((parseFloat(document.getElementById('deliveryTaxNumber').innerHTML) + parseFloat(document.getElementById('deliveryChargeNumber').innerHTML) + parseFloat(document.getElementById('deliverySubtotalNumber').innerHTML)) * 100) / 100;
			document.getElementById('deliveryTotalNumber').innerHTML = total.toFixed(2);
			break;
		}
	}
}

function CopyDeliveryAddressToBillingAddress()
{
	document.getElementById('creditCardEntryPageCardAddressLine1').value = document.getElementById('deliveryAddress1').value;
	document.getElementById('creditCardEntryPageCardAddressLine2').value = document.getElementById('deliveryAddress2').value;
	document.getElementById('creditCardEntryPageCardCity').value = document.getElementById('deliveryCity').value;
	document.getElementById('creditCardEntryPageCardState').value = document.getElementById('deliveryState').value;
	document.getElementById('creditCardEntryPageCardZip').value = document.getElementById('deliveryZip').value;
}

function TestIfCardNumberIsNumber(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  key = String.fromCharCode( key );
  var regex = /[0-9]/;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    theEvent.preventDefault();
  }
}

function UpdateCreditCardEntryPageDueTime()
{
	var action = 'getDueTimeInnerHTML';
	var selectedDate = document.getElementById('creditCardEntryPageCardDueDate').value;
	var passData = 'action='+escape(action)+'&selectedDate='+escape(selectedDate);
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/checkout.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	      	 //document.getElementById('creditCardEntryPageCardDueTime').innerHTML = '';
	         document.getElementById('creditCardEntryPageCardDueTime').outerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function ProcessOrder()
{
	var action = 'processOrder';
	var cardNum = document.getElementById('creditCardEntryPageCardNumber').value;
	var cardName = document.getElementById('creditCardEntryPageCardName').value;
	var cardAmount = document.getElementById('creditCardEntryPageCardAmount').value;
	var cardExpMonth = document.getElementById('creditCardEntryPageCardExpMonth').value;
	var cardExpYear = document.getElementById('creditCardEntryPageCardExpYear').value;
	var cardAddress1 = document.getElementById('creditCardEntryPageCardAddressLine1').value;
	var cardAddress2 = document.getElementById('creditCardEntryPageCardAddressLine2').value;
	var cardCity = document.getElementById('creditCardEntryPageCardCity').value;
	var cardState = document.getElementById('creditCardEntryPageCardState').value;
	var cardZip = document.getElementById('creditCardEntryPageCardZip').value;
	var cardCCV = document.getElementById('creditCardEntryPageCardCCV').value;
	var dueDate = document.getElementById('creditCardEntryPageCardDueDate').value;
	var dueTime = document.getElementById('creditCardEntryPageCardDueTime').value;
	var type = 'Pickup';
	
	if(cardNum == '' ||
		cardName == '' ||
		cardAmount == '' ||
		cardExpMonth == '' ||
		cardExpYear == '' ||
		cardAddress1 == '' ||
		cardCity == '' ||
		cardState == '' ||
		cardZip == '' ||
		cardCCV == '')
	{
		document.getElementById('fillAllInformationInInfoBox').style.display = "block";
		window.scroll(0,0);
	}
	else
	{
		document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
		var passData = 'action='+escape(action)+'&cardNum='+escape(cardNum)+'&cardAmount='+escape(cardAmount)+'&cardName='+escape(cardName)+'&cardExpMonth='+escape(cardExpMonth)+'&cardExpYear='+escape(cardExpYear)+'&cardAddress1='+escape(cardAddress1)+'&cardAddress2='+escape(cardAddress2)+'&cardCity='+escape(cardCity)+'&cardState='+escape(cardState)+'&cardZip='+escape(cardZip)+'&cardCCV='+escape(cardCCV)+'&dueDate='+escape(dueDate)+'&dueTime='+escape(dueTime)+'&type='+escape(type);
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");                                         
		   return false
		} else {
		   AJAX.open("POST", "inc/checkout.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
		         document.getElementById('productDisplay').innerHTML = AJAX.responseText;
		         
		         var childNodeArray = document.getElementById('productDisplay').childNodes;
		         if(childNodeArray[0].id != 'rejectedCardInfoBox')
		         {
		         	document.getElementById('basketItemsWrap').innerHTML = '<ul><li></li></ul>';
		         	document.getElementById("basketTotalWrap").innerHTML = '				Subtotal:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$<span id="basketTotalWrapNumber">0.00</span>';
		         }		        		         
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}
	}
}

function ProcessOrderDelivery()
{
	var action = 'processOrder';
	var cardNum = document.getElementById('creditCardEntryPageCardNumber').value;
	var cardName = document.getElementById('creditCardEntryPageCardName').value;
	var cardAmount = parseFloat(document.getElementById('deliveryTotalNumber').innerHTML);
	var cardExpMonth = document.getElementById('creditCardEntryPageCardExpMonth').value;
	var cardExpYear = document.getElementById('creditCardEntryPageCardExpYear').value;
	var cardAddress1 = document.getElementById('creditCardEntryPageCardAddressLine1').value;
	var cardAddress2 = document.getElementById('creditCardEntryPageCardAddressLine2').value;
	var cardCity = document.getElementById('creditCardEntryPageCardCity').value;
	var cardState = document.getElementById('creditCardEntryPageCardState').value;
	var cardZip = document.getElementById('creditCardEntryPageCardZip').value;
	var cardCCV = document.getElementById('creditCardEntryPageCardCCV').value;
	var dueDate = document.getElementById('creditCardEntryPageCardDueDate').value;
	var dueTime = document.getElementById('creditCardEntryPageCardDueTime').value;
	var type = 'Delivery';
	var firstName = document.getElementById('deliveryFirstName').value;
	var lastName = document.getElementById('deliveryLastName').value;
	var phone = document.getElementById('phone1').value+document.getElementById('phone2').value+document.getElementById('phone3').value;
	var address1 = document.getElementById('deliveryAddress1').value;
	var address2 = document.getElementById('deliveryAddress2').value;
	var city = document.getElementById('deliveryCity').value;
	var state = document.getElementById('deliveryState').value;
	var zip = document.getElementById('deliveryZip').value;
	
	if(cardNum == '' ||
		cardName == '' ||
		cardAmount == '' ||
		cardExpMonth == '' ||
		cardExpYear == '' ||
		cardAddress1 == '' ||
		cardCity == '' ||
		cardState == '' ||
		cardZip == '' ||
		cardCCV == '' ||
		phone.length < 10)
	{
		document.getElementById('fillAllInformationInInfoBox').style.display = "block";
		window.scroll(0,0);
	}
	else
	{
		document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
		var passData = 'action='+escape(action)+'&cardNum='+escape(cardNum)+'&cardAmount='+escape(cardAmount)+'&cardName='+escape(cardName)+'&cardExpMonth='+escape(cardExpMonth)+'&cardExpYear='+escape(cardExpYear)+'&cardAddress1='+escape(cardAddress1)+'&cardAddress2='+escape(cardAddress2)+'&cardCity='+escape(cardCity)+'&cardState='+escape(cardState)+'&cardZip='+escape(cardZip)+'&cardCCV='+escape(cardCCV)+'&dueDate='+escape(dueDate)+'&dueTime='+escape(dueTime)+'&type='+escape(type)+'&firstName='+escape(firstName)+'&lastName='+escape(lastName)+'&phone='+escape(phone)+'&address1='+escape(address1)+'&address2='+escape(address2)+'&city='+escape(city)+'&state='+escape(state)+'&zip='+escape(zip);
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");                                         
		   return false
		} else {
		   AJAX.open("POST", "inc/checkout.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
		         document.getElementById('productDisplay').innerHTML = AJAX.responseText;
		         
		         var childNodeArray = document.getElementById('productDisplay').childNodes;
		         if(childNodeArray[0].id != 'rejectedCardInfoBox')
		         {
		         	document.getElementById('basketItemsWrap').innerHTML = '<ul><li></li></ul>';
		         	document.getElementById("basketTotalWrap").innerHTML = '				Subtotal:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$<span id="basketTotalWrapNumber">0.00</span>';
		         }		        		         
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}
	}
}

function SortUp(term)
{
	var action='sortUp';
	var passData = 'action='+escape(action)+'&orderID='+escape(term);
	var AJAX = null;
	
	document.getElementById('tableContainer').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('tableContainer').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function SortDown(term)
{
	var action='sortDown';
	var passData = 'action='+escape(action)+'&orderID='+escape(term);
	var AJAX = null;
	
	document.getElementById('tableContainer').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('tableContainer').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function DueTodayOrderFiltering()
{
	var action='getDueTodayOrders';
	var passData = 'action='+escape(action)+'&orderID='+escape(null);
	var AJAX = null;
	
	document.getElementById('tableContainer').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('tableContainer').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function DueTomorrowOrderFiltering()
{
	var action='getDueTomorrowOrders';
	var passData = 'action='+escape(action)+'&orderID='+escape(null);
	var AJAX = null;
	
	document.getElementById('tableContainer').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('tableContainer').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function OverdueOrderFiltering()
{
	var action='getOverdueOrders';
	var passData = 'action='+escape(action)+'&orderID='+escape(null);
	var AJAX = null;
	
	document.getElementById('tableContainer').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('tableContainer').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function AllOrderFiltering()
{
	var action='getAllOrders';
	var passData = 'action='+escape(action)+'&orderID='+escape(null);
	var AJAX = null;
	
	document.getElementById('tableContainer').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('tableContainer').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoadUsersListContentWrap()
{
	var action='getUsersListPaginated';
	var passData = 'action='+escape(action)+'&orderID='+escape(null);
	var AJAX = null;
	
	document.getElementById('tableContainer').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('tableContainer').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoadUsersListPage(startIndex, endIndex)
{
	var action='getUsersListPage';
	var passData = 'action='+escape(action)+'&startIndex='+escape(startIndex)+'&endIndex='+escape(endIndex);
	var AJAX = null;
	
	document.getElementById('userListPage').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/orderFunctions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('userListPage').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoginForm()
{
	var action='populateLoginForm';
	var term = 0;
	var passData = 'action='+escape(action)+'&orderID='+escape(term);
	var AJAX = null;
	
	document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('productDisplay').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function VerifyLogin()
{		
	var action='validateLogin';
	var email = document.getElementById('loginEmail').value;
	var password = document.getElementById('loginPassword').value;
	var passData = 'action='+escape(action)+'&email='+escape(email)+'&password='+escape(password);
	var AJAX = null;
	//alert('email: ' + email + ' password: ' + password);	
	document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/login.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         if(AJAX.responseText == '')
	         {
	         	document.getElementById('productDisplay').innerHTML = AJAX.responseText;
	         }
	         else
	         {
	         	DisplayLoggedInUser();
	         	LoadProductHomePage();
	         }
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function CheckEnterPressedToVerifyLogin(e)
{
	var unicode=e.keyCode? e.keyCode : e.charCode;
	
	if(unicode == 13)
	{
		VerifyLogin();
	}
}

function DisplayLoggedInUser()
{
	var action='getLoggedInUser';
	var passData = 'action='+escape(action)+'&orderID='+escape(null);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
	         document.getElementById('loggedInUser').innerHTML = AJAX.responseText;
	         
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LogoutUser()
{
	var action='logoutUser';
	var passData = 'action='+escape(action)+'&email='+escape(null)+'&password='+escape(null);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/login.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      window.location = 'https://www.ricksbakery.com/store/';
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function ReloadPage(numMillisecDelay)
{
	setTimeout("window.location.reload()",numMillisecDelay);
}

function RedirectToHTTPS()
{
	if(window.parent.document.location.protocol == 'http:')
	{
		window.location = window.location + 'SSLredirect.htm';
	}
}

function CreateContainsMethodForMozilla()
{
	if (window.Node && Node.prototype && !Node.prototype.contains)
	{
		Node.prototype.contains = function (arg) {
			return !!(this.compareDocumentPosition(arg) & 16)
		}
	}
}

function LoadIndexHTML()
{
	RedirectToHTTPS();
	//CreateContainsMethodForMozilla();
	
	var action='loadIndexHTML';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	document.getElementById('mainWrap').innerHTML = '<div id="applicationLoadingScreen"><p>Loading</p><img src="images/ajax-loader-main.gif"><br/><br/>Optimized for modern browsers like<br/>Firefox, Safari, and Chrome.</div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('mainWrap').innerHTML = AJAX.responseText;
		      $('div.demo-show> div').hide();  
			  $('div.demo-show> .showHideHeader').click(function() {
			    $(this).next('div').slideToggle('fast')
			    .siblings('div:visible').slideUp('fast');
			  });
	         
	         
	         //$("#slider").easySlider();
	         $("#slider").easySlider({
				loop: true,                           // Looping
				orientation: 'fade',                  // Fading
				autoplayDuration: 3000,               // Autoplay with 1 second intervals
				autogeneratePagination: true,         // Automatically generate pagination links
				restartDuration: 2500,                // In case of user interaction, restart the autoplay after 2.5 seconds
				//nextId: 'next',
				//prevId: 'prev',
				pauseable: true,                       // Pause by hovering over the image!  Then restart after 2.5 seconds (see above)
				prevText: '',          // text for autogenerated prev link
      			nextText: ''
			});
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoadViewOrdersContentWrap()
{
	var action='getDueTodayOrders';
	var passData = 'action='+escape(null)+'&productID='+escape(null);
	var AJAX = null;
	
	document.getElementById('contentWrap').innerHTML = '<div id="applicationLoadingScreen"><p>Loading</p><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/viewOrders.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('contentWrap').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoadStoreContentWrap()
{
	var action='loadStoreContent';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	document.getElementById('contentWrap').innerHTML = '<div id="applicationLoadingScreen"><p>Loading</p><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('contentWrap').innerHTML = AJAX.responseText;
		      $('div.demo-show> div').hide();  
			  $('div.demo-show> .showHideHeader').click(function() {
			    $(this).next('div').slideToggle('fast')
			    .siblings('div:visible').slideUp('fast');
			  });
			  
			  $("#slider").easySlider({
				loop: true,                           // Looping
				orientation: 'fade',                  // Fading
				autoplayDuration: 3000,               // Autoplay with 1 second intervals
				autogeneratePagination: true,         // Automatically generate pagination links
				restartDuration: 2500,                // In case of user interaction, restart the autoplay after 2.5 seconds
				//nextId: 'next',
				//prevId: 'prev',
				pauseable: true,                       // Pause by hovering over the image!  Then restart after 2.5 seconds (see above)
				prevText: '',          // text for autogenerated prev link
      			nextText: ''
			});
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoadAdminContentWrap()
{
	var action='loadAdminPage';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	document.getElementById('contentWrap').innerHTML = '<div id="applicationLoadingScreen"><p>Loading</p><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('contentWrap').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function UploadImageAdminPage()
{
	var action='uploadImageAdminPage';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	document.getElementById('adminPageContent').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('adminPageContent').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function GetImageUploadInputs()
{
	var action='getImageUploadInputs';
	var numberOfInputs = document.getElementById('numberOfImages').value;
	var passData = 'action='+escape(action)+'&numberOfInputs='+escape(numberOfInputs);
	var AJAX = null;
	
	//document.getElementById('adminPageContent').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('imageUploadInputs').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function CheckIfPrimaryImageSet(checkboxID)
{
	var numOfInputs = document.getElementById('numberOfImages').value;
	var checkboxNum = parseInt(checkboxID.charAt(checkboxID.length - 1));
	
	for(var i=1; i<=numOfInputs; i++)
	{
		if(document.getElementById('checkbox_' + i).checked && i != checkboxNum)
		{
			alert('Only one primary image may be selected!');
			document.getElementById(checkboxID).checked = false;
		}
	}
}

function CheckIfFileExists(elementID)
{
	var action='checkIfFileExists';
	var filePath = document.getElementById(elementID).value;
	var passData = 'action='+escape(action)+'&filePath='+escape(filePath);
	var AJAX = null;
	
	//document.getElementById('adminPageContent').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      alert(AJAX.responseText);
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function UpdateProductSelectOptions()
{
	var action = 'outputProductSelectBox';
	var catID = document.getElementById('categorySelect').value;
	var passData = 'action='+escape(action)+'&catID='+escape(catID);
	var AJAX = null;
	
	//$("#loadingImage").html('<img src="images/ajax-loader.gif">');
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   //$("#loadingImage").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/displayProducts.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	         document.getElementById('productSelect').innerHTML = AJAX.responseText
	      }                               
	   }                                  
	   AJAX.send(passData);
	   //$("#loadingImage").empty();	
	}
}

function UploadImages()
{
	var images = document.getElementById('numberOfImages').value;
	alert(document.getElementById('uploadedImage_1').value);
	/*
for(var i=0; i<images; i++)
	{
		var action='uploadImages';
		var numberOfInputs = document.getElementById('numberOfImages').value;
		var passData = 'action='+escape(action)+'&numberOfInputs='+escape(numberOfInputs);
		var AJAX = null;
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");                                        
		   return false
		} else {
		   AJAX.open("POST", "inc/admin.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
			      document.getElementById('adminPageContent').innerHTML = document.getElementById('adminPageContent').innerHTML + AJAX.responseText;
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}	
	}
*/

	var action='uploadImages';
	var passData = 'action='+escape(action);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('adminPageContent').innerHTML = document.getElementById('adminPageContent').innerHTML + AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function ManageFeaturedProducts()
{
	var action='manageFeaturedProducts';
	var passData = 'action='+escape(action);
	var AJAX = null;
	
	document.getElementById('adminPageContent').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	      document.getElementById('adminPageContent').innerHTML = '';
		      document.getElementById('adminPageContent').innerHTML = document.getElementById('adminPageContent').innerHTML + AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function ManageProducts()
{
	var action='manageProducts';
	var catID = document.getElementById('categorySelect').value;
	var passData = 'action='+escape(action)+'&catID='+escape(catID);
	var AJAX = null;
	
	var table = document.getElementById('tableContainer');
    if(table)
    {
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('tableContainer'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('addFeaturedProductButton'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('removeFeaturedProductButton'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('backgroundForPopup'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('changeFeaturedProductImagePopup'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('closeFeaturedProductImagePopupButton'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('productImageManagerPopup'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('closeProductImageManagerPopupButton'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('textEditorPopup'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('addProductPopup'));
  	  document.getElementById('adminPageContent').removeChild(document.getElementById('closeAddFeaturedProductImagePopupButton'));
    }
	document.getElementById('adminPageContent').innerHTML = document.getElementById('adminPageContent').innerHTML +
		'<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	      	  document.getElementById('adminPageContent').removeChild(document.getElementById('mainLoaderImage'));
		      document.getElementById('adminPageContent').innerHTML = document.getElementById('adminPageContent').innerHTML + AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoadManageProductsPage()
{
	var action='getProductManagementPage';
	var passData = 'action='+escape(action);
	var AJAX = null;
	
	document.getElementById('adminPageContent').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	      document.getElementById('adminPageContent').innerHTML = '';
		      document.getElementById('adminPageContent').innerHTML = document.getElementById('adminPageContent').innerHTML + AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function GetChangeFeaturedProductImagePopup(productID)
{
	var action='getChangeFeaturedProductImagePopup';
	var passData = 'action='+escape(action)+'&productID='+escape(productID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('changeFeaturedProductImagePopup').innerHTML = AJAX.responseText;
		      
		      //close other popup
		      //document.getElementById('addFeaturedProductImagePopup').innerHTML = '';
			  //document.getElementById('addFeaturedProductImagePopup').setAttribute("class", "addFeaturedProductImagePopupDisabled");
		  	  //document.getElementById('closeAddFeaturedProductImagePopupButton').setAttribute("class", "closeAddFeaturedProductImagePopupButtonDisabled");
		      
		      //open new popup
		      document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledLight");
		      document.getElementById('changeFeaturedProductImagePopup').setAttribute("class", "changeFeaturedProductImagePopupEnabled");
		      document.getElementById('closeFeaturedProductImagePopupButton').setAttribute("class", "closeFeaturedProductImagePopupButtonEnabled");
		      
		      // set top element based on browser height
		      SetPopupTopValue(document.getElementById('changeFeaturedProductImagePopup'), document.getElementById('closeFeaturedProductImagePopupButton'));
		      
		      //var dim = GetTopLeft(document.getElementById('changeImageButton_'+productID));
		      
		      
		      //alert('changeImageButton_'+productID+' top: '+dim.Top);
		      //document.getElementById('changeFeaturedProductImagePopup').style.top = dim.Top + 15 + 'px';
		      //document.getElementById('closeFeaturedProductImagePopupButton').style.top = dim.Top - 6 + 'px';
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function UploadFeaturedImageJS(productID)
{
	var action='uploadFeaturedImage';
	var passData = 'action='+escape(action)+'&productID='+escape(productID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('changeFeaturedProductImagePopup').innerHTML = document.getElementById('changeFeaturedProductImagePopup').innerHTML + AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function UpdateFeaturedImageForProduct(productID)
{
	var action='updateFeaturedImageForProduct';
	var passData = 'action='+escape(action)+'&productID='+escape(productID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('featuredProductThumbCell_'+productID).innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function UpdateDisplayWithNewFeaturedProduct(productID)
{
	var action='updateDisplayWithNewFeaturedProduct';
	var passData = 'action='+escape(action)+'&productID='+escape(productID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('tableContainer').innerHTML = document.getElementById('tableContainer').innerHTML + AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function CloseFeaturedProductImagePopup()
{
	// run javascript to change displayed featured product thumbnail w/o page refresh
	UpdateFeaturedImageForProduct(document.getElementById('productIDTextBox').value);
	
	document.getElementById('changeFeaturedProductImagePopup').innerHTML = '';
	document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupDisabledLight");
	document.getElementById('changeFeaturedProductImagePopup').setAttribute("class", "changeFeaturedProductImagePopupDisabled");
	document.getElementById('closeFeaturedProductImagePopupButton').setAttribute("class", "closeFeaturedProductImagePopupButtonDisabled");
}

function AddFeaturedProductPopup()
{
	var action='getAddFeaturedProductPopup';
	var passData = 'action='+escape(action);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('addFeaturedProductImagePopup').innerHTML = AJAX.responseText;
		      
		      //close other popup
		      //document.getElementById('changeFeaturedProductImagePopup').innerHTML = '';
			  //document.getElementById('changeFeaturedProductImagePopup').setAttribute("class", "changeFeaturedProductImagePopupDisabled");
			  //document.getElementById('closeFeaturedProductImagePopupButton').setAttribute("class", "closeFeaturedProductImagePopupButtonDisabled");
		      
		      //open new popup
		      document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledLight");
		      document.getElementById('addFeaturedProductImagePopup').setAttribute("class", "addFeaturedProductImagePopupEnabled");
		      document.getElementById('closeAddFeaturedProductImagePopupButton').setAttribute("class", "closeAddFeaturedProductImagePopupButtonEnabled");
		      
		      // set top element based on browser height
		      SetPopupTopValue(document.getElementById('addFeaturedProductImagePopup'), document.getElementById('closeAddFeaturedProductImagePopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function CloseAddFeaturedProductPopup()
{
	// run javascript to add featured product table row w/o page refresh
	if(document.getElementById('productSelect').value)
	{
		UpdateDisplayWithNewFeaturedProduct(document.getElementById('productSelect').value);
	}
	
	document.getElementById('addFeaturedProductImagePopup').innerHTML = '';
	document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupDisabledLight");
	document.getElementById('addFeaturedProductImagePopup').setAttribute("class", "addFeaturedProductImagePopupDisabled");
	document.getElementById('closeAddFeaturedProductImagePopupButton').setAttribute("class", "closeAddFeaturedProductImagePopupButtonDisabled");
}

function AddProductPopup(catID)
{
	var action='getAddProductPopup';
	var passData = 'action='+escape(action)+'&catID='+escape(catID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('addProductPopup').innerHTML = AJAX.responseText;
		      
		      //open new popup
		      document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledLight");
		      document.getElementById('addProductPopup').setAttribute("class", "addProductPopupEnabled");
		      document.getElementById('closeAddFeaturedProductImagePopupButton').setAttribute("class", "closeAddFeaturedProductImagePopupButtonEnabled");
		      
		      // set top element based on browser height
		      SetPopupTopValue(document.getElementById('addProductPopup'), document.getElementById('closeAddFeaturedProductImagePopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function CloseAddProductPopup()
{
	document.getElementById('addProductPopup').innerHTML = '';
	document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupDisabledLight");
	document.getElementById('addProductPopup').setAttribute("class", "addProductImagePopupDisabled");
	document.getElementById('closeAddFeaturedProductImagePopupButton').setAttribute("class", "closeAddFeaturedProductImagePopupButtonDisabled");
}

function CreateNewProduct(catID)
{
	var productName = document.getElementById('newProductName').value;
	var productPrice = document.getElementById('newProductPrice').value;
	
	if(productName != null && productName != "")
	{
		if(productPrice != null && productPrice != "")
		{
			var action='addProduct';
			var passData = 'action='+escape(action)+'&catID='+escape(catID)+'&productName='+escape(productName)+'&productPrice='+escape(productPrice);
			var AJAX = null;
			
			CloseAddProductPopup();
			
			if (window.XMLHttpRequest) {
			   AJAX=new XMLHttpRequest();
			} else {
			   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
			}
			if (AJAX==null) {
			   alert("Your browser doesn't support AJAX.");                                        
			   return false
			} else {
			   AJAX.open("POST", "inc/admin.php", true);
			   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			   AJAX.onreadystatechange = function() {                      
			      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
					ManageProducts();
			      }                               
			   }                                  
			   AJAX.send(passData);	
			}
		}
		else
		{
			alert('Please enter a Product Price.')
		}
	}
	else
	{
		alert('Please enter a Product Name.');
	}
}


function DisplayRemoveFeaturedProductIcons()
{
	var nodes = document.getElementById('tableContainer').childNodes;
	
	for(var i=0; i<nodes.length; i++)
	{
		if(nodes[i].className == 'row')
		{
			var rowNodes = nodes[i].childNodes;
			for(var j=0; j<rowNodes.length; j++)
			{
				if(rowNodes[j].className == 'minusCellDisabled')
				{
					// switch minus icon on
					rowNodes[j].setAttribute("class", "minusCellEnabled");
					break;
				}
				else if(rowNodes[j].className == 'minusCellEnabled')
				{
					// switch minus icon off
					rowNodes[j].setAttribute("class", "minusCellDisabled");
					break;
				}
			}
		}
	}
}

function RemoveFeaturedProduct(productID)
{
	var action='removeFeaturedProduct';
	var passData = 'action='+escape(action)+'&productID='+escape(productID);
	var AJAX = null;

	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		  	document.getElementById('tableContainer').removeChild(document.getElementById('row_'+productID));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function FindPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return {X:curleft, Y:curtop};
}

function TextEditorPopup(productID, divClassName)
{
	var pos = FindPos(document.getElementById(divClassName+'_'+productID));
	var mainPos = FindPos(document.getElementById('mainWrap'));
	
	document.getElementById('textEditorPopup').style.top = pos.Y - mainPos.Y + 'px';
	document.getElementById('textEditorPopup').style.left = pos.X - mainPos.X + 'px';

	var divWidth = parseInt(document.getElementById(divClassName+'_'+productID).offsetWidth);
	var divHeight = parseInt(document.getElementById(divClassName+'_'+productID).offsetHeight);
	document.getElementById('textEditorPopupTextbox').style.width = divWidth + "px";
	document.getElementById('textEditorPopupTextbox').style.height = divHeight + "px";

	document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledLight");
	document.getElementById('textEditorPopup').setAttribute("class", "textEditorPopupEnabled");
	document.getElementById('textEditorPopupTextbox').setAttribute("currentFieldBeingEdited", divClassName+'_'+productID);
	//alert('editing: '+document.getElementById('textEditorPopupTextbox').getAttribute('currentFieldBeingEdited'));

	//document.getElementById('textEditorPopupTextbox').style.visibility = 'visible';
	document.getElementById('textEditorPopupTextbox').focus();
	document.getElementById('textEditorPopupTextbox').value = document.getElementById(divClassName+'_'+productID).innerHTML;
}

function EnterTextInPopup(passedID, e)
{
	var unicode=e.keyCode? e.keyCode : e.charCode;

	//if(unicode == 27 || unicode == 13) now, only enter will submit changes
	if(unicode == 13)
	{
		e.returnValue = false;
        if (e.preventDefault) {
            e.preventDefault();
        }
		
		document.getElementById(passedID).setAttribute('class', passedID + 'Disabled');
		document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupDisabled");
		
		// update value in database
		var action='updateProduct';
		var currentFieldBeingEdited = document.getElementById('textEditorPopupTextbox').getAttribute('currentFieldBeingEdited').split('_');
		var field = currentFieldBeingEdited[0].substring(0, currentFieldBeingEdited[0].length - 4);	// -4 to remove 'Cell' at end
		var productID = currentFieldBeingEdited[1];
		var value = document.getElementById('textEditorPopupTextbox').value;
		
		//alert('field: '+field+' productID: '+productID);
		var passData = 'action='+escape(action)+'&productID='+escape(productID)+'&field='+escape(field)+'&value='+escape(value);
		var AJAX = null;
	
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");                                        
		   return false
		} else {
		   AJAX.open("POST", "inc/admin.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
			  	//document.getElementById('tableContainer').removeChild(document.getElementById('row_'+productID));
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}

		document.getElementById(document.getElementById('textEditorPopupTextbox').getAttribute('currentFieldBeingEdited').toString()).innerHTML = document.getElementById('textEditorPopupTextbox').value;
		document.getElementById('textEditorPopupTextbox').value = '';
	}
	
	// Do the form submit
	//this.form.submit();
}

function ExitPopup(passedID, e)
{
	var unicode=e.keyCode? e.keyCode : e.charCode;
	if(unicode == 27)
	{
		ExitPopupWithClick();
	}
}

function ExitPopupWithClick()
{
	document.getElementById('textEditorPopup').setAttribute('class', 'textEditorPopupDisabled')
	document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupDisabled");
}

function UpdateProductFromSelect(field, productID)
{
	if(field == 'enabled')
	{
		var value = document.getElementById('enabledSelect_'+productID).value;
	}
	else if(field == 'catID')
	{
		var value = document.getElementById('productCategorySelect_'+productID).value;
	}
	
	// update value in database
	var action='updateProduct';

	var passData = 'action='+escape(action)+'&productID='+escape(productID)+'&field='+escape(field)+'&value='+escape(value);
	var AJAX = null;

	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		  	document.getElementById('adminToolbar').innerHTML += AJAX.responseText;
		  	if(field == 'enabled')
			{
				if(value == 'Y')
				{
					document.getElementById('enabledCell_'+productID).setAttribute("class", "enabledCellEnabled");
				}
				else
				{
					document.getElementById('enabledCell_'+productID).setAttribute("class", "enabledCellDisabled");
				}
			}
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function PopupProductImageManager(productID)
{
	var action='getProductImageManagerPopup';
	var passData = 'action='+escape(action)+'&productID='+escape(productID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('productImageManagerPopup').innerHTML = AJAX.responseText;
		      
		      //open new popup
		      document.getElementById('productImageManagerPopup').setAttribute("class", "productImageManagerPopupEnabled");
		      document.getElementById('closeProductImageManagerPopupButton').setAttribute("class", "closeProductImageManagerPopupButtonEnabled");
		      document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledLight");
		      
		      // set top element based on browser height
		      SetPopupTopValue(document.getElementById('productImageManagerPopup'), document.getElementById('closeProductImageManagerPopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}

}

function SetPopupTopValue(popup, button)
{
	
	if(GetWindowSize().Height < popup.offsetHeight)
	{
		popup.style.top = GetWindowSize().Height / 8 + 'px';
		button.style.top = (GetWindowSize().Height / 8) - 14 + 'px';
	}
	else
	{
		popup.style.top = (GetWindowSize().Height - popup.offsetHeight) / 2 + 'px';
		button.style.top = ((GetWindowSize().Height - popup.offsetHeight) / 2) - 14 + 'px';
	}
	
	
}

function GetWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return {Width:myWidth, Height: myHeight};
}

function DisplayAddProductImageTool(productID)
{
	// turn off primary and enable|disable buttons
	if(document.getElementById('addProductImageButton').style.backgroundColor == '')
	{	
		if(document.getElementById('enableDisableProductImageButton').style.backgroundColor != '')
		{
			DisplayDisableProductImageIcons();
		}
		if(document.getElementById('selectPrimaryProductImageButton').style.backgroundColor != '')
		{
			SelectPrimaryProductImage();
		}
		
		//toggle button color
		document.getElementById('addProductImageButton').style.backgroundColor = '#BABABA';

		var action='displayAddProductImageTool';
		var passData = 'action='+escape(action)+'&productID='+escape(productID);
		var AJAX = null;
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");                                        
		   return false
		} else {
		   AJAX.open("POST", "inc/admin.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      	  
		      	  var popupHeight = document.getElementById('productImageManagerPopup').offsetHeight;
	   	      	  var nodes = document.getElementById('productImageManagerPopup').childNodes;
			      for(var i=0; i<nodes.length; i++)
				  {
						if(nodes[i].className == 'productImageManagerPopupRow')
						{
							document.getElementById('productImageManagerPopup').removeChild(nodes[i]);
						}
				  }
				  popupHeight = popupHeight + 'px';
				  document.getElementById('productImageManagerPopup').style.height = popupHeight;
				  var innerHTML = document.getElementById('productImageManagerPopup').innerHTML;
				  var innerHTML = AJAX.responseText + innerHTML;
				  document.getElementById('productImageManagerPopup').innerHTML = document.getElementById('productImageManagerPopup').innerHTML + AJAX.responseText;
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}
		
	}
	else
	{
		//toggle button color
		document.getElementById('addProductImageButton').style.backgroundColor = '';
	
		var action='productImageManagerPopupImages';
		var passData = 'action='+escape(action)+'&productID='+escape(productID);
		var AJAX = null;
		
		if (window.XMLHttpRequest) {
		   AJAX=new XMLHttpRequest();
		} else {
		   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (AJAX==null) {
		   alert("Your browser doesn't support AJAX.");                                        
		   return false
		} else {
		   AJAX.open("POST", "inc/admin.php", true);
		   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   AJAX.onreadystatechange = function() {                      
		      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      	  //document.getElementById('productImageManagerPopup').offsetHeight = '';
		      	  
		      	  var nodes = document.getElementById('productImageManagerPopup').childNodes;
			      for(var i=0; i<nodes.length; i++)
				  {
						if(nodes[i].id == 'uploadImageForm')
						{
							document.getElementById('productImageManagerPopup').removeChild(nodes[i]);
						}
				  }
		      	  
				  document.getElementById('productImageManagerPopup').innerHTML = AJAX.responseText + document.getElementById('productImageManagerPopup').innerHTML;
		      }                               
		   }                                  
		   AJAX.send(passData);	
		}
	}
}

function DisplayDisableProductImageIcons()
{
	// turn off primary button
	if(document.getElementById('selectPrimaryProductImageButton').style.backgroundColor != '')
	{
		SelectPrimaryProductImage();
	}
	
	// toggle button color
	if(document.getElementById('enableDisableProductImageButton').style.backgroundColor == '')
	{
		document.getElementById('enableDisableProductImageButton').style.backgroundColor = '#BABABA';
	}
	else
	{
		document.getElementById('enableDisableProductImageButton').style.backgroundColor = '';
	}
	
	// turn off add image button
	if(document.getElementById('addProductImageButton').style.backgroundColor != '')
	{
		document.getElementById('addProductImageButton').style.backgroundColor = '';
		var productID = document.getElementById('uploadImageForm').name.substr(16,document.getElementById('uploadImageForm').name.length);
		RepopulatePopupProductImageManager(productID);
		return;
	}
	
	var nodes = document.getElementById('productImageManagerPopup').childNodes;
	
	for(var i=0; i<nodes.length; i++)
	{
		if(nodes[i].className == 'productImageManagerPopupRow')
		{
			var rowNodes = nodes[i].childNodes;
			for(var j=0; j<rowNodes.length; j++)
			{
				if(rowNodes[j].className == 'productImage' || 
				   rowNodes[j].className == 'primaryProductImage' || 
				   rowNodes[j].className == 'disabledProductImage')
				{
					var spanNodes = rowNodes[j].childNodes;
					for(var k=0; k<spanNodes.length; k++)
					{
						if(spanNodes[k].className == 'disableProductImageCellDisabled')
						{
							// switch minus icon on
							spanNodes[k].setAttribute("class", "disableProductImageCellEnabled");
							break;
						}
						else if(spanNodes[k].className == 'disableProductImageCellEnabled')
						{
							// switch minus icon off
							spanNodes[k].setAttribute("class", "disableProductImageCellDisabled");
							break;
						}
					}
				}
			}
		}
	}
}

function RepopulatePopupProductImageManager(productID)
{
	var action='productImageManagerPopupImages';
	var passData = 'action='+escape(action)+'&productID='+escape(productID);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	      		var nodes = document.getElementById('productImageManagerPopup').childNodes;
			    for(var i=0; i<nodes.length; i++)
			    {
					if(nodes[i].id == 'uploadImageForm')
					{
						document.getElementById('productImageManagerPopup').removeChild(nodes[i]);
					}
				}
	      
		        document.getElementById('productImageManagerPopup').innerHTML = AJAX.responseText + document.getElementById('productImageManagerPopup').innerHTML;
		      
		        //open new popup
		        document.getElementById('productImageManagerPopup').setAttribute("class", "productImageManagerPopupEnabled");
		        document.getElementById('closeProductImageManagerPopupButton').setAttribute("class", "closeProductImageManagerPopupButtonEnabled");
		        document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledLight");
		      
		        // set top element based on browser height
		        SetPopupTopValue(document.getElementById('productImageManagerPopup'), document.getElementById('closeProductImageManagerPopupButton'));
		      
		        var nodes = document.getElementById('productImageManagerPopup').childNodes;
	
				if(document.getElementById('selectPrimaryProductImageButton').style.backgroundColor != '')
				{
					// toggle productImage cell functions
					var nodes = document.getElementById('productImageManagerPopup').childNodes;
					var primaryProductImageID = 0;
					
					// find primaryProductImageID
					for(var i=0; i<nodes.length; i++)
					{
						if(nodes[i].className == 'productImageManagerPopupRow')
						{
							var rowNodes = nodes[i].childNodes;
							
							for(var j=0; j<rowNodes.length; j++)
							{
								if(rowNodes[j].className == 'primaryProductImage')
								{
									primaryProductImageID = rowNodes[j].id.substr(13,rowNodes[j].id.length);
									//alert('primaryImageID: '+primaryProductImageID);
									break;
								}
							}
						}
						if(primaryProductImageID != 0)
						{
							break;
						}
					}
					
					// enable primary product selection
					for(var i=0; i<nodes.length; i++)
					{
						if(nodes[i].className == 'productImageManagerPopupRow')
						{
							var rowNodes = nodes[i].childNodes;
							
							for(var j=0; j<rowNodes.length; j++)
							{
								if(rowNodes[j].className == 'productImage')
								{
									rowNodes[j].setAttribute('onmouseover', 'EnableHoverForPrimaryProductImage(this,'+primaryProductImageID+')');
									rowNodes[j].setAttribute('onmouseout', 'DisableHoverForProductImage(this)');
									//alert('id: '+rowNodes[j].id.substr(13,rowNodes[j].id.length));
								}
								else if(rowNodes[j].className == 'disabledProductImage')
								{
									rowNodes[j].setAttribute('onmouseover', 'EnableHoverForPrimaryProductImage(this,'+primaryProductImageID+')');
									rowNodes[j].setAttribute('onmouseout', 'DisableHoverForDisabledProductImage(this)');
									//alert('nodeName: '+rowNodes[j].nodeName);
								}
							}
						}
					}
				}
				else if(document.getElementById('enableDisableProductImageButton').style.backgroundColor != '')
				{
					for(var i=0; i<nodes.length; i++)
					{
						if(nodes[i].className == 'productImageManagerPopupRow')
						{
							var rowNodes = nodes[i].childNodes;
							for(var j=0; j<rowNodes.length; j++)
							{
								if(rowNodes[j].className == 'productImage' || 
								   rowNodes[j].className == 'primaryProductImage' || 
								   rowNodes[j].className == 'disabledProductImage')
								{
									var spanNodes = rowNodes[j].childNodes;
									for(var k=0; k<spanNodes.length; k++)
									{
										if(spanNodes[k].className == 'disableProductImageCellDisabled')
										{
											// switch minus icon on
											spanNodes[k].setAttribute("class", "disableProductImageCellEnabled");
											break;
										}
										else if(spanNodes[k].className == 'disableProductImageCellEnabled')
										{
											// switch minus icon off
											spanNodes[k].setAttribute("class", "disableProductImageCellDisabled");
											break;
										}
									}
								}
							}
						}
					}
				}
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function DisableProductImage(imageID)
{
	var action='enableDisableProductImage';
	var passData = 'action='+escape(action)+'&imageID='+escape(imageID)+'&value='+escape('N');
	var AJAX = null;

	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		  	document.getElementById('productImageIMG_'+imageID).setAttribute('class', 'productImageIMGDisabled');
		  	//document.getElementById('disableProductImageCell_'+imageID).setAttribute('class', disableProductImageCellDisabled);
		  	document.getElementById('disableEnableIcon_'+imageID).setAttribute('src', 'images/CheckMark.png');
		  	document.getElementById('enableDisableProductIconLink_'+imageID).setAttribute('onclick', 'javascript:EnableProductImage('+imageID+');');
		  	document.getElementById('productImageManagerPopup').innerHTML += AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function EnableProductImage(imageID)
{
	var action='enableDisableProductImage';
	var passData = 'action='+escape(action)+'&imageID='+escape(imageID)+'&value='+escape('Y');
	var AJAX = null;

	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		  	document.getElementById('productImageIMG_'+imageID).setAttribute('class', 'productImageIMGEnabled');
		  	//document.getElementById('disableProductImageCell_'+imageID).setAttribute('class', disableProductImageCellEnabled);
		  	document.getElementById('disableEnableIcon_'+imageID).setAttribute('src', 'images/cancel_icon.png');
		  	document.getElementById('enableDisableProductIconLink_'+imageID).setAttribute('onclick', 'javascript:DisableProductImage('+imageID+');');
		  	document.getElementById('productImageManagerPopup').innerHTML += AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function CloseProductImageManagerPopup()
{
	document.getElementById('closeProductImageManagerPopupButton').setAttribute('class', 'closeProductImageManagerPopupButtonDisabled');
	document.getElementById('backgroundForPopup').setAttribute('class', 'backgroundForPopupDisabled');
	document.getElementById('productImageManagerPopup').setAttribute('class', 'productImageManagerPopupDisabled');
}

function SelectPrimaryProductImage()
{
	// turn off enable|disable button
	if(document.getElementById('enableDisableProductImageButton').style.backgroundColor != '')
	{
		DisplayDisableProductImageIcons();
	}
	
	// toggle primary image button functionality
	if(document.getElementById('selectPrimaryProductImageButton').style.backgroundColor == '')
	{
		document.getElementById('selectPrimaryProductImageButton').style.backgroundColor = '#BABABA';
	
		
		// turn off add image button
		if(document.getElementById('addProductImageButton').style.backgroundColor != '')
		{
			document.getElementById('addProductImageButton').style.backgroundColor = '';
			var productID = document.getElementById('uploadImageForm').name.substr(16,document.getElementById('uploadImageForm').name.length);
			RepopulatePopupProductImageManager(productID);
			return;
		}
	
		// toggle productImage cell functions
		var nodes = document.getElementById('productImageManagerPopup').childNodes;
		var primaryProductImageID = 0;
		
		// find primaryProductImageID
		for(var i=0; i<nodes.length; i++)
		{
			if(nodes[i].className == 'productImageManagerPopupRow')
			{
				var rowNodes = nodes[i].childNodes;
				
				for(var j=0; j<rowNodes.length; j++)
				{
					if(rowNodes[j].className == 'primaryProductImage')
					{
						primaryProductImageID = rowNodes[j].id.substr(13,rowNodes[j].id.length);
						//alert('primaryImageID: '+primaryProductImageID);
						break;
					}
				}
			}
			if(primaryProductImageID != 0)
			{
				break;
			}
		}
		
		// enable primary product selection
		for(var i=0; i<nodes.length; i++)
		{
			if(nodes[i].className == 'productImageManagerPopupRow')
			{
				var rowNodes = nodes[i].childNodes;
				
				for(var j=0; j<rowNodes.length; j++)
				{
					if(rowNodes[j].className == 'productImage')
					{
						rowNodes[j].setAttribute('onmouseover', 'EnableHoverForPrimaryProductImage(this,'+primaryProductImageID+')');
						rowNodes[j].setAttribute('onmouseout', 'DisableHoverForProductImage(this)');
						//alert('id: '+rowNodes[j].id.substr(13,rowNodes[j].id.length));
					}
					else if(rowNodes[j].className == 'disabledProductImage')
					{
						rowNodes[j].setAttribute('onmouseover', 'EnableHoverForPrimaryProductImage(this,'+primaryProductImageID+')');
						rowNodes[j].setAttribute('onmouseout', 'DisableHoverForDisabledProductImage(this)');
						//alert('nodeName: '+rowNodes[j].nodeName);
					}
				}
			}
		}
	}
	else
	{
		document.getElementById('selectPrimaryProductImageButton').style.backgroundColor = '';
	
		// toggle productImage cell functions
		var nodes = document.getElementById('productImageManagerPopup').childNodes;
		
		for(var i=0; i<nodes.length; i++)
		{
			if(nodes[i].className == 'productImageManagerPopupRow')
			{
				var rowNodes = nodes[i].childNodes;
				for(var j=0; j<rowNodes.length; j++)
				{
					if(rowNodes[j].className == 'productImage')
					{
						rowNodes[j].setAttribute('onmouseover', '');
						rowNodes[j].setAttribute('onmouseout', '');
						rowNodes[j].setAttribute('onclick', '');
					}
					else if(rowNodes[j].className == 'disabledProductImage')
					{
						rowNodes[j].setAttribute('onmouseover', '');
						rowNodes[j].setAttribute('onmouseout', '');
						rowNodes[j].setAttribute('onclick', '');
					}
				}
			}
		}
	}

}

function SetPrimaryImage(imageID, primaryProductImageID)
{
	//alert('imageID: '+imageID+'primaryID: '+primaryProductImageID);
	var action='setPrimaryImage';
	var passData = 'action='+escape(action)+'&imageID='+escape(imageID);
	var AJAX = null;

	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/admin.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
	      	document.getElementById('productImage_'+imageID).setAttribute('onmouseover', '');
		  	document.getElementById('productImage_'+imageID).setAttribute('onclick', '');
		  	document.getElementById('productImage_'+imageID).setAttribute('onmouseout', '');
		  	document.getElementById('productImage_'+imageID).setAttribute('class', 'primaryProductImage');
		  	document.getElementById('productImage_'+imageID).style.opacity = 1.0;
		  	
		  	// make sure no other element looks like primaryImage
		  	var nodes = document.getElementById('productImageManagerPopup').childNodes;
			for(var i=0; i<nodes.length; i++)
			{
				if(nodes[i].className == 'productImageManagerPopupRow')
				{
					var rowNodes = nodes[i].childNodes;
					for(var j=0; j<rowNodes.length; j++)
					{
						if(rowNodes[j].className == 'primaryProductImage' && rowNodes[j].id != 'productImage_'+imageID)
						{
							rowNodes[j].setAttribute('class', 'productImage');
		  					rowNodes[j].setAttribute('onmouseover', 'EnableHoverForPrimaryProductImage(this,'+imageID+')');
							rowNodes[j].setAttribute('onmouseout', 'DisableHoverForProductImage(this)');
						}
					}
				}
			}
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function EnableHoverForPrimaryProductImage(element, primaryProductImageID)
{
	element.setAttribute('class', 'primaryProductImage');
	element.style.opacity= 0.7;
	element.setAttribute('onclick', 'javascript:SetPrimaryImage('+element.id.substr(13,element.id.length)+', '+primaryProductImageID+');');
}

function DisableHoverForProductImage(element)
{
	element.setAttribute('class', 'productImage');
	element.style.opacity= 1.0;
}

function MoveCellSelectionCursor(passedID, e)
{
	alert(document.getElementById('cellSelectionCursor'));
	if(!document.getElementById('cellSelectionCursor'))
	{
		alert('here too');
		document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productNameCell_1');
	}
	var unicode=e.keyCode? e.keyCode : e.charCode;
	
	var selectedCell = document.getElementById('cellSelectionCursor').getAttribute('selectedCell');
	var currentFieldSelected = selectedCell.split('_');
	var field = currentFieldSelected[0].substring(0, currentFieldSelected[0].length - 4);	// -4 to remove 'Cell' at end
	var productID = currentFieldSelected[1];
	
	if(unicode == 37)	//left
	{
		switch(field)
		{
			case 'productID':
				// do nothing
			 	break;
			case 'productName':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productID'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productID'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
				break;
			case 'productCategory':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productName'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productName'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'productPrice':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productCategory'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productCategory'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'enabled':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productPrice'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productPrice'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'imageCollage':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'enabled'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('enabled'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'productDescription':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'imageCollage'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('imageCollage'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
		}	
	}
	else if(unicode == 38)	//up
	{
		if(productID > 2)	//change when doing dynamic table population
		{
			productID--;
			document.getElementById('cellSelectionCursor').setAttribute('selectedCell', field+'Cell_'+productID);
		}
	}
	else if(unicode == 39)	//right
	{
		switch(field)
		{
			case 'productID':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productName'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productName'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'productName':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productCategory'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productCategory'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
				break;
			case 'productCategory':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productPrice'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productPrice'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'productPrice':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'enabled'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('enabled'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'enabled':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'imageCollage'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('imageCollage'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'imageCollage':
				document.getElementById('cellSelectionCursor').setAttribute('selectedCell', 'productDescription'+'Cell_'+productID);
				var dim = GetTopLeft(document.getElementById('productDescription'+'Cell_'+productID));
				document.getElementById('cellSelectionCursor').style.top = dim.Top - 11 + 'px';
				document.getElementById('cellSelectionCursor').style.left = dim.Left - 230 + 'px';
			 	break;
			case 'productDescription':
				// do nothing
			 	break;
			case 'default':
				alert('non-valid cell selected');
				break;
		}
	}
	else if(unicode == 40)	//down
	{
		if(productID < 20)	//change when doing dynamic table population
		{
			productID++;
			document.getElementById('cellSelectionCursor').setAttribute('selectedCell', field+'Cell_'+productID);
		}
	}
}

function GetTopLeft(elm)

{

	var x, y = 0;
	
	//set x to elmÕs offsetLeft
	x = elm.offsetLeft;
	
	
	//set y to elmÕs offsetTop
	y = elm.offsetTop;
	
	
	//set elm to its offsetParent
	elm = elm.offsetParent;
	
	
	//use while loop to check if elm is null
	// if not then add current elmÕs offsetLeft to x
	//offsetTop to y and set elm to its offsetParent
	
	while(elm != null)
	{
	
		x = parseInt(x) + parseInt(elm.offsetLeft);
		y = parseInt(y) + parseInt(elm.offsetTop);
		elm = elm.offsetParent;
	}
	
	//here is interesting thing
	//it return Object with two properties
	//Top and Left
	
	return {Top:y, Left: x};

}

function redirect()
{
document.getElementById('uploadImageForm').target = 'my_iframe'; //'my_iframe' is the name of the iframe
document.getElementById('uploadImageForm').submit();
}

function redirectFeaturedProduct()
{
	document.getElementById('uploadImageForm').target = 'my_iframe_featured_product'; //'my_iframe' is the name of the iframe
	document.getElementById('uploadImageForm').submit();
}

function redirectProductImageUpload()
{
	document.getElementById('uploadImageForm').target = 'my_iframe'; //'my_iframe' is the name of the iframe
	document.getElementById('uploadImageForm').submit();
}

function Sleep(delay)
{
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

function LoadProductHomePage()
{
	var action='loadHomePage';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('productDisplay').innerHTML = AJAX.responseText;
		      
		      $("#slider").easySlider({
				loop: true,                           // Looping
				orientation: 'fade',                  // Fading
				autoplayDuration: 3000,               // Autoplay with 1 second intervals
				autogeneratePagination: true,         // Automatically generate pagination links
				restartDuration: 2500,                // In case of user interaction, restart the autoplay after 2.5 seconds
				//nextId: 'next',
				//prevId: 'prev',
				pauseable: true,                       // Pause by hovering over the image!  Then restart after 2.5 seconds (see above)
				prevText: '',          // text for autogenerated prev link
      			nextText: ''
			});
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function ShowRegistrationForm()
{
	var action='loadRegistrationForm';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('hiddenRegistrationForm').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function RegisterUser()
{
	var action='validateRegistrationForm';
	var firstName = document.getElementById('firstName').value;
	var lastName = document.getElementById('lastName').value;
	var phone1 = document.getElementById('phone1').value;
	var phone2 = document.getElementById('phone2').value;
	var phone3 = document.getElementById('phone3').value;
	var address1 = document.getElementById('address1').value;
	var address2 = document.getElementById('address2').value;
	var city = document.getElementById('city').value;
	var state = document.getElementById('state').value;
	var zip = document.getElementById('zip').value;
	var email = document.getElementById('email').value;
	var password1 = document.getElementById('registrationPassword1').value;
	var password2 = document.getElementById('registrationPassword2').value;
	var passData = 'action='+escape(action)+'&firstName='+escape(firstName)+'&lastName='+escape(lastName)+'&phone1='
					+escape(phone1)+'&phone2='+escape(phone2)+'&phone3='+escape(phone3)+'&address1='+escape(address1)
					+'&address2='+escape(address2)+'&city='+escape(city)+'&state='+escape(state)+'&zip='+escape(zip)
					+'&email='+escape(email)+'&password1='+escape(password1)+'&password2='+escape(password2);
	var AJAX = null;
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/register.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('hiddenRegistrationForm').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function LoadMyOrders()
{
	var action='loadMyOrders';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	document.getElementById('productDisplay').innerHTML = '<div id="mainLoaderImage"><img src="images/ajax-loader-main.gif"></div>';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");                                        
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") {
		      document.getElementById('productDisplay').innerHTML = AJAX.responseText;
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function ScrollUp(){
      var offy;
      if(self.pageYOffset) {
            offy = self.pageYOffset;
      } else if(document.documentElement && document.documentElement.scrollTop){
            offy = document.documentElement.scrollTop;
      } else {
            offy = document.body.scrollTop;
      }

      if(offy <= 0) return;

      window.scrollBy(0, -50);
      setTimeout("ScrollUp()", 0);
}

function ShowPrivacyPolicy()
{
	var action='getPrivacyPolicy';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	var popupWidth;
	var popupHeight;
	
	if(windowHeight < windowWidth * 2/3)
	{
		popupHeight = Math.round(windowHeight * 0.99);
		popupWidth = Math.round(popupHeight * 3/2);
		
	}
	else
	{
		popupWidth = Math.round(.95 * windowWidth);
		popupHeight = Math.round(2/3 * popupWidth);
	}
	document.getElementById('fullSizeProductImagePopup').style.width = popupWidth + 'px';
	document.getElementById('fullSizeProductImagePopup').style.height = popupHeight + 'px';
	document.getElementById('fullSizeProductImagePopup').style.left = (windowWidth - popupWidth) / 2 + 'px';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
			document.getElementById('fullSizeProductImagePopup').innerHTML = AJAX.responseText;
	        
	        document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledDark");
	        document.getElementById('fullSizeProductImagePopup').setAttribute("class", "fullSizeProductImagePopupEnabled");
	        
	        // set top element based on browser height
	        SetPopupTopValue(document.getElementById('fullSizeProductImagePopup'), document.getElementById('closeFullSizeProductImagePopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}

}

function ShowTermsOfUse()
{
	var action='getTermsOfUse';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	var popupWidth;
	var popupHeight;
	
	if(windowHeight < windowWidth * 2/3)
	{
		popupHeight = Math.round(windowHeight * 0.99);
		popupWidth = Math.round(popupHeight * 3/2);
		
	}
	else
	{
		popupWidth = Math.round(.95 * windowWidth);
		popupHeight = Math.round(2/3 * popupWidth);
	}
	document.getElementById('fullSizeProductImagePopup').style.width = popupWidth + 'px';
	document.getElementById('fullSizeProductImagePopup').style.height = popupHeight + 'px';
	document.getElementById('fullSizeProductImagePopup').style.left = (windowWidth - popupWidth) / 2 + 'px';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
			document.getElementById('fullSizeProductImagePopup').innerHTML = AJAX.responseText;
	        
	        document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledDark");
	        document.getElementById('fullSizeProductImagePopup').setAttribute("class", "fullSizeProductImagePopupEnabled");
	        
	        // set top element based on browser height
	        SetPopupTopValue(document.getElementById('fullSizeProductImagePopup'), document.getElementById('closeFullSizeProductImagePopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}

}

function ShowReturnPolicy()
{
	var action='getReturnPolicy';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	var popupWidth;
	var popupHeight;
	
	if(windowHeight < windowWidth * 2/3)
	{
		popupHeight = Math.round(windowHeight * 0.99);
		popupWidth = Math.round(popupHeight * 3/2);
		
	}
	else
	{
		popupWidth = Math.round(.95 * windowWidth);
		popupHeight = Math.round(2/3 * popupWidth);
	}
	document.getElementById('fullSizeProductImagePopup').style.width = popupWidth + 'px';
	document.getElementById('fullSizeProductImagePopup').style.height = popupHeight + 'px';
	document.getElementById('fullSizeProductImagePopup').style.left = (windowWidth - popupWidth) / 2 + 'px';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
			document.getElementById('fullSizeProductImagePopup').innerHTML = AJAX.responseText;
	        
	        document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledDark");
	        document.getElementById('fullSizeProductImagePopup').setAttribute("class", "fullSizeProductImagePopupEnabled");
	        
	        // set top element based on browser height
	        SetPopupTopValue(document.getElementById('fullSizeProductImagePopup'), document.getElementById('closeFullSizeProductImagePopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}

}

function ShowContactUs()
{
	var action='getContactUs';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	var popupWidth;
	var popupHeight;
	
	if(windowHeight < windowWidth * 2/3)
	{
		popupHeight = Math.round(windowHeight * 0.99);
		popupWidth = Math.round(popupHeight * 3/2);
		
	}
	else
	{
		popupWidth = Math.round(.95 * windowWidth);
		popupHeight = Math.round(2/3 * popupWidth);
	}
	document.getElementById('fullSizeProductImagePopup').style.width = popupWidth + 'px';
	document.getElementById('fullSizeProductImagePopup').style.height = popupHeight + 'px';
	document.getElementById('fullSizeProductImagePopup').style.left = (windowWidth - popupWidth) / 2 + 'px';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
			document.getElementById('fullSizeProductImagePopup').innerHTML = AJAX.responseText;
	        
	        document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledDark");
	        document.getElementById('fullSizeProductImagePopup').setAttribute("class", "fullSizeProductImagePopupEnabled");
	        
	        // set top element based on browser height
	        SetPopupTopValue(document.getElementById('fullSizeProductImagePopup'), document.getElementById('closeFullSizeProductImagePopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}

}

function ShowWelcomeMessage()
{
	var action='getWelcomeMessage';
	var passData = 'action='+escape(action)+'&productID='+escape(null);
	var AJAX = null;
	
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	var popupWidth;
	var popupHeight;
	
	if(windowHeight < windowWidth * 2/3)
	{
		popupHeight = Math.round(windowHeight * 0.99);
		popupWidth = Math.round(popupHeight * 3/2);
		
	}
	else
	{
		popupWidth = Math.round(.95 * windowWidth);
		popupHeight = Math.round(2/3 * popupWidth);
	}
	document.getElementById('fullSizeProductImagePopup').style.width = popupWidth + 'px';
	document.getElementById('fullSizeProductImagePopup').style.height = popupHeight + 'px';
	document.getElementById('fullSizeProductImagePopup').style.left = (windowWidth - popupWidth) / 2 + 'px';
	
	if (window.XMLHttpRequest) {
	   AJAX=new XMLHttpRequest();
	} else {
	   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX==null) {
	   alert("Your browser doesn't support AJAX.");
	   $("#notificationsLoaderMain").empty();	                                         
	   return false
	} else {
	   AJAX.open("POST", "inc/functions.php", true);
	   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   AJAX.onreadystatechange = function() {                      
	      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
			document.getElementById('fullSizeProductImagePopup').innerHTML = AJAX.responseText;
	        
	        document.getElementById('backgroundForPopup').setAttribute("class", "backgroundForPopupEnabledDark");
	        document.getElementById('fullSizeProductImagePopup').setAttribute("class", "fullSizeProductImagePopupEnabled");
	        
	        // set top element based on browser height
	        SetPopupTopValue(document.getElementById('fullSizeProductImagePopup'), document.getElementById('closeFullSizeProductImagePopupButton'));
	      }                               
	   }                                  
	   AJAX.send(passData);	
	}
}

function PrintOrders()
{
	var elements = document.getElementsByClassName('printOrderDetailsCheckbox');
	var outputText = '<H1>ONLINE ORDERING</H1><br/>';
	
	for(var i=0; i<elements.length; i++)
	{
		if(elements[i].checked == 1)
		{
			outputText += '<H2>' + elements[i].value + '</H2>';
			
			var splitString = elements[i].id.split("_");
			outputText += document.getElementById('typeCell_' + splitString[1]).getAttribute("name");
			outputText += '<br/><br/><br/>';
		}
	}
	
	if(outputText != '')
	{
		var display_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
		display_setting+="scrollbars=yes,width=750, height=600, left=100, top=25";
		
		var document_print=window.open("","",display_setting);
		document_print.document.open();
		document_print.document.write('<html><head><title>Print using javascript </title></head>');
		document_print.document.write('<body style="font-family:verdana; font-size:12px;" onLoad="self.print();self.close();" >');
		document_print.document.write(outputText);
		document_print.document.write('</body></html>');
		document_print.print();
		document_print.document.close();
		return false;
	}
	else
	{
		alert('Nothing Selected to Print');
	}
}

function ShowDeliveryInfoPopOver(popoverID)
{
	document.getElementById('deliveryInfoPopOver').innerHTML = '<p>' + document.getElementById(popoverID).value + '</p>';
	document.getElementById('deliveryInfoPopOver').style.top = GetOffsetTop(popoverID) - 75 + 'px';
	document.getElementById('deliveryInfoPopOverArrow').style.top = GetOffsetTop(popoverID) - 15 + 'px';
	document.getElementById('deliveryInfoPopOver').setAttribute("class", "deliveryInfoPopOverVisible");
	document.getElementById('deliveryInfoPopOverArrow').style.visibility = "visible";
}

function HideDeliveryInfoPopOver(popoverID)
{
	document.getElementById('deliveryInfoPopOver').innerHTML = '';
	document.getElementById('deliveryInfoPopOverArrow').style.visibility = "hidden";
	document.getElementById('deliveryInfoPopOver').setAttribute("class", "deliveryInfoPopOverHidden");
}

function GetOffsetTop(elementID)
{
	var iReturnValue = 0;
	elementid=document.getElementById(elementID);
	while( elementid != null ){
	iReturnValue += elementid.offsetTop;
	elementid = elementid.offsetParent;
	}
	return iReturnValue;
}

