function update(count)
{
	//alert(document.getElementById(count-1).name + " " + document.getElementById(count-1).value);//works to grab name aka product ID
	var list = '';
	//iterate thru amount textboxes update the session variable with the increment function which calls the add to list
	for(var i = 0; i < count; i++)
	{
		for(var j = 0; j < document.getElementById(i).value; j++)
		{
			list = list + document.getElementById(i).name + ',';
			alert(document.getElementById(i).name);
		}
	}
	list = list.substring(0, list.length -1);
	update_products(list);
	
}
function update_products(list)
{
	//Browser Support Code
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try
		{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} 
		catch (e)
		{
				// Internet Explorer Browsers
				try
				{
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} 
				catch (e) 
				{
					try
					{
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (e)
					{
						// Something went wrong
						alert("Your browser broke!");
						return false;
					}
				}
		}
		
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function()
		{
			// If response is complete
			if(ajaxRequest.readyState == 4)
			{
				var php_response = ajaxRequest.responseText;
				if (php_response == 0)	//if success
				{
					document.location.reload(true);	//refresh browser to update the count of products in wishlist
				}
				else
				{
					//show error
				}
			}


		}
		// open the request then send it to the server
		var queryString = "?list=" + list;
		ajaxRequest.open("GET","update_wishlist.php" + queryString, true);
		ajaxRequest.send(null);
}




function increment(id)
{
	add_to_wishlist(id);
	document.location.reload(true);	//refresh browser to update the count of products in wishlist
}
function add_from_catalog(id)
{
	add_to_wishlist(id);
	var num = document.getElementById('num_items').innerHTML;
	
	num++;
	
	document.getElementById('num_items').innerHTML = num;
}
//*******************************************************************************************

function delete_from_wishlist(id)
{
		//Browser Support Code
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try
		{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} 
		catch (e)
		{
				// Internet Explorer Browsers
				try
				{
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} 
				catch (e) 
				{
					try
					{
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (e)
					{
						// Something went wrong
						alert("Your browser broke!");
						return false;
					}
				}
		}
		
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function()
		{
			// If response is complete
			if(ajaxRequest.readyState == 4)
			{
				var php_response = ajaxRequest.responseText;
				if (php_response == 0)	//if success
				{
					//show success message
					//alert("Success: " + id + " was removed");
					document.location.reload(true);	//refresh browser to update the count of products in wishlist
				}
				else
				{
					//show error
				}
			}


		}
		// open the request then send it to the server
		var queryString = "	?id=" + id;
		ajaxRequest.open("GET","delete_from_wishlist.php" + queryString, true);
		ajaxRequest.send(null);

	
}

//*******************************************************************************************

function add_to_wishlist(id)
{
		//Browser Support Code
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try
		{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} 
		catch (e)
		{
				// Internet Explorer Browsers
				try
				{
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} 
				catch (e) 
				{
					try
					{
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (e)
					{
						// Something went wrong
						alert("Your browser broke!");
						return false;
					}
				}
		}
		
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function()
		{
			// If response is complete
			if(ajaxRequest.readyState == 4)
			{
				var php_response = ajaxRequest.responseText;
				if (php_response == 0)	//if success
				{
					//show success message
				}
				else
				{
					//show error
				}
			}


		}
		// open the request then send it to the server
		var queryString = "	?id=" + id;
		ajaxRequest.open("GET","add_to_wishlist.php" + queryString, true);
		ajaxRequest.send(null);

	
}

//**********************************************************************************************************

function change_category(_category)
{
	category=_category.value;
	set_cookie("category", category);
	var page =  1;
	//refresh page
	window.location = "catalog.php" + "?category=" + category + 
																	"&page=" + page;
}

//****************************************************************
function change_page(page, category)
{
	
	//refresh page
	window.location = "catalog.php" + "?category=" + category + "&page=" + page.value;
	
}//****************************************************************


//*********************************************************************************************************	
	
//creates a cookie with such parameters
function set_cookie ( name, value, expiry_year, expiry_month, expiry_day, path, domain, secure )
{
  //create string to hold cookie info
  var cookie_string = name + "=" + escape ( value );
  
  //if a expiration year was given
  if ( expiry_year )
  {
	var expires = new Date ( expiry_year, expiry_month, expiry_day );
	cookie_string += "; expires=" + expires.toGMTString();
  }
  
  //if a path was given
  if ( path )
		cookie_string += "; path=" + escape ( path );
  
  //if a path was given
  if ( domain )
		cookie_string += "; domain=" + escape ( domain );
  
  //if a path was given
  if ( secure )
		cookie_string += "; secure";
		
		
  //create cookie from string
  document.cookie = cookie_string;
}
//************************************************************************************************************
//************************************************************************************************************

//to retrieve a cookie
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
	return ( unescape ( results[2] ) );
  else
	return null;
}
//************************************************************************************************************
// added by millennium
//************************************************************************************************************
function popUp(page,PWidth,PHeight,id) {
eval("designerwiz"+id+"=window.open('"+page+"','designerwiz1','toolbar=0,scrollbars=1,location=0,status=0,menubars=0,resizable=1,width="+PWidth+",height="+PHeight+"')")
}
