var Post = new Object();
Post.Send = function(form)
{
	var itemname = Post.getElementValue(form.elements['1']);
	if(confirm('This will add 1 '+itemname+' to your shopping cart?') == true){
		var query = Post.buildQuery(form);
		Ajax.Request(form.method, form.action, query, Post.OnResponse);
	}
	window.location.reload();
}

Post.Remove = function(form)
{
	var itemname = Post.getElementValue(form.elements['1']);
	if(confirm('This will remove 1 '+itemname+' from your shopping cart?') == true){
		var query = Post.buildQuery(form);
		Ajax.Request(form.method, form.action, query, Post.OnResponse);
	}
	window.location.reload();
}

Post.OnResponse = function(xml)
{	
	if(xml.childNodes[0]){
		var msg = xml.childNodes[0].firstChild.nodeValue;
		var tot = document.getElementById('shopcarttotal');
		var quant = document.getElementById('shopcartquantity');
		quant.innerHTML = xml.childNodes[1].firstChild.nodeValue;
		tot.innerHTML = '$' + num.toFixed(2);
		quant.style.color = 'red';
		tot.style.color = 'red';
	}else{
		alert('SOMETHING WENT WRONG ! ');
	}
}

Post.buildQuery = function(form)
{
	var query = "";
	for(var i=0; i<form.elements.length; i++)
	{
		var key = form.elements[i].name;
		var value = Post.getElementValue(form.elements[i]);
		if(key && value)
		{
			query += key +"="+ value +"&";
		}
	}
	return query + "js=true";
}

Post.getElementValue = function(formElement)
{
	if(formElement.length != null) var type = formElement[0].type;
	if((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;

	switch(type)
	{
		case 'undefined': return;

		case 'radio':
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].checked == true)
			return formElement[x].value;

		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			return myArray;

		case 'checkbox': return formElement.checked;
	
		default: return formElement.value;
	}
}


