function list(category)
{
	clear_body();
	var http = false;
	var page = "_GetList.php?c=" + category;

	
	
	if(navigator.appName == "Microsoft Internet Explorer") {
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  http = new XMLHttpRequest();
	}
	
	http.open("GET", page);
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		HandleResponse(http.responseText,"List");
	  }
	}
	http.send(null);
}

function browse()
{
	

	clear_body();
	var http = false;
	//var page = "_GetList.php?c=" + category;
	var page = "_GetCategories.php";
	
	
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
	{
	  http = new XMLHttpRequest();
	}
	
	http.open("GET", page);
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		HandleResponse(http.responseText,"Browse");
	  }
	}
	http.send(null);
}

function add(i)
{
	
	var http = false;
	
	mdate = new Date();
	var stamp = mdate.getMonth()   + "" + mdate.getDay()    + "" + mdate.getHours() + "" 
	          + mdate.getMinutes() + "" + mdate.getSeconds()
	
	var page = "cart.php?t=" + stamp + "1&item=" + i;
	
	
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
	{
	  http = new XMLHttpRequest();
	}
	
	http.open("GET", page);
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		HandleResponse(http.responseText,"Add");
	  }
	}
	http.send(null);
}

function update_cart(post,final)
{
	

	var http = false;
	
	mdate = new Date();
	var stamp = mdate.getMonth()   + "" + mdate.getDay()    + "" + mdate.getHours() + "" 
	          + mdate.getMinutes() + "" + mdate.getSeconds()
	
	var page = "cart_mod.php?t=" + stamp;
	
	
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
	{
	  http = new XMLHttpRequest();
	}
	
	http.open("POST", page, true);
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		document.getElementById('cart').innerHTML = http.responseText;
		if ( final )
		{
			
			document.shopping_cart.submit();	
		}
	  }
	}      
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", post.length);
    http.setRequestHeader("Connection", "close");
    http.send(post);
}


function cart_request()
{
	var http = false;
	
	mdate = new Date();
	var stamp = mdate.getMonth()   + "" + mdate.getDay()    + "" + mdate.getHours() + "" 
	          + mdate.getMinutes() + "" + mdate.getSeconds()

	
	var page = "cart_display.php?t=" + stamp ;
	
	if(navigator.appName == "Microsoft Internet Explorer") {
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  http = new XMLHttpRequest();
	}
	
	http.open("GET", page);
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		document.getElementById('cart').innerHTML = http.responseText;
	  }
	}
	http.send(null);
}




function request_shipping(weight,country,postal)
{
	
	var http = false;
	string = "?ajax=on&weight=" + weight + "&country=" + country + "&postal=" + postal;
	var page = "_getServices.php" + string;

	
	
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
	{
	  http = new XMLHttpRequest();
	}
	
	http.open("GET", page);
	http.onreadystatechange=function() 
	{
	  if(http.readyState == 4) 
	  {
		document.getElementById('bodyarea').innerHTML = http.responseText;
	  }
	}
	http.send(null);
}

function HandleResponse(msg,action)
{
	
	switch ( action )
	{	/******************************************************************
	    LIST:   LIST ALL THE ITEMS FOR A CATEGORY
	    ******************************************************************/
		case "List":    
		
		//alert(msg);
		strings = msg.split("\|");
		len = strings.length;
		title = strings[0];
		desc  = strings[1];
		
		
		out = "<p>"  + desc  + "</p>";



		out += "<table width='100%' border=0><tr><td colspan='3'><hr noshade></td></tr>";

		for ( var x = 2; x < len; x+=7 )
		{
			if ( strings[x] == "" )
				break;	
			
			id     = strings[x];
			name   = strings[x+1];
			desc   = strings[x+2];
			image  = "../" + strings[x+3];
			pr_cad = strings[x+4];
			pr_usd = strings[x+5];
			pr_link = (strings[x+6] != "") ? strings[x+6] : "#";
			
			out += "\n";
			// Image
			out += "<!-- IMAGE //-->";
			out += "<tr><td rowspan='3' width='153'>";
			out += "<img src='" + image + "' >";
			//out += image;
			out += "</td>";

			out += "\n";
			// Title

			out += "<td valign='top' colspan='2'><p><strong>";
			out += "<a href='" + pr_link + "'>";
			out += name;
			out += "</a></p></strong></td></tr>";
			
			
			out += "\n";
			// Details
			out += "<tr>";
			out += "<td align='left' valign='top'> <p>";
			out += desc;
			out += "<br> CA $" + pr_cad;
			out += "</p></td>";
			out += "</tr>";
			
			out += "\n";
			out += "<td align='center'>";

			// buttons
			out += '<table border="0" align="center" cellpadding="0" cellspacing="0">';
            out += '  <tr>';
            out += '    <th width="134" align="center" scope="col"><a href="' + pr_link + '" ';
			out += ' onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image' + x + '\',\'\',\'Images/details_down.jpg\',1)">';
			out += '<img src="Images/details_up.jpg" alt="Read more about this recording" ';
			out += 'name="Image21" width="100" height="18" border="0" id="Image' + x + '" /></a></th>';
            out += '   <th width="134" align="center" scope="col">';
			out += '<span onClick="add(\'' + id + '\')" onmouseout="MM_swapImgRestore()" ';
			out += 'onmouseover="MM_swapImage(\'Image' + (x+1) + '\',\'\',\'Images/purchase_down.jpg\',1)">';
			out += '<img src="Images/purchase_up.jpg" alt="Buy this recording" name="Image' + (x+1) + '" width="100" height="18" ';
			out += 'border="0" id="Image22" /></a></th>';
            out += ' </tr>';
            out += '</table>';

			out += "</span>";
			out += "</td>";
			
			out += "\n";
			out += "</tr>";
			
			out += "\n";
			out += "<tr><td colspan='3'><hr noshade></td></tr>";

		}
		out += "</table>";
		
		title_area = document.getElementById('titlearea');
		title_area.innerHTML = title;
		body_area = document.getElementById('bodyarea');
		body_area.innerHTML = out;
		break;
		
		/******************************************************************
	    BROWSE:   LIST ALL THE CATEGORIES
	    ******************************************************************/
		case "Browse":
		strings = msg.split("\|");
		len = strings.length;

		out = "<br><table>"
		for ( var x = 0; x < len-1; x+=2 )
		{
			id   = strings[x];
			name = strings[x+1];
			
			out += "<tr><td>" + 
				   "<H2>" +
			       "<span onClick='list(" + id + ")' class='pseudolink'>" + name + "</span>" +
			       "</H2>" +
				   "</td><tr>";
		}
		out += "</table>";
		
			body_area = document.getElementById('titlearea');
			body_area.innerHTML = "";
			body_area = document.getElementById('bodyarea');
			body_area.innerHTML = out;
		break;	
		/******************************************************************
	    ADD:   ADDED AN ITEM
	    ******************************************************************/
		case "Add":
		if (msg.substr(0,2) != "OK")
		{
			alert(msg);
			return;
		}
		msg = msg.substr(2)
		out = msg;
		document.getElementById('cart').innerHTML = out;
		return;
		
		/******************************************************************
	    DUMP:   DUMP OUTPUT TO BODY
	    ******************************************************************/
		case "Dump":
		document.getElementById('bodyarea').innerHTML = msg;
		return;
	}
	


	
}

function clear_body()
{
	body_area = document.getElementById('bodyarea');
	body_area.innerHTML = "";	
	
}
