var host = 'http://www.thestyleriot.com';
//var host = 'http://localhost:8080/thestyleriot';

function addToBag(productID, color, size)
{
	setHost();
	new Ajax.Request(host + '/ajax/addToBag.jsp', { method: 'post',   parameters: {productID: productID, color: color, size: size}   }); 
	document.getElementById('header-checkout').style.display = 'block';
	document.getElementById('addToBagButtonWrapper').style.display = 'none';
	document.getElementById('addedToBagButtonWrapper').style.display = 'block';
	document.getElementById('addedNextSteps').style.display = 'block';

	incrementCounter(1);	
}

function removeFromBag(itemIndex)
{
	setHost();
	new Ajax.Request(host + '/ajax/removeFromBag.jsp', { method: 'post',   parameters: {indexOf: itemIndex}   });
	document.getElementById('bagItem' + itemIndex).style.display = 'none';

	incrementCounter(-1);	
}

function incrementCounter(count)
{
	var e = document.getElementById('checkoutItemCount');
	itemCount = parseInt(e.innerHTML);
	itemCount = itemCount + count;
	e.innerHTML = itemCount;
}

function setHost()
{
	var url = window.location.href;
	var http = url.split('//')[0];
	var nohttp = url.split('//')[1];
	if(nohttp.split('/')[0] == "localhost:8080")
	{
		host = http + "//" + nohttp.split('/')[0] + "/thestyleriot";
	}
	else
	{
		host = http + "//" + nohttp.split('/')[0];
	}
}

function toggleDiv(divID)
{
	var e = document.getElementById(divID);
	if(e.style.display == 'block')
		e.style.display = 'none';
	else
		e.style.display = 'block';
}


function applyDiscount(discountCode)
{
	setHost();
	new Ajax.Updater('itemUpdater', host + '/ajax/applyDiscount.jsp', { evalScripts: true, parameters: {discountCode: discountCode} });
}

