function addToCart(myP)
{
	if (myP > '')
	{
		document.getElementById('atcButton').value = "Adding to Cart...";
		document.getElementById('atcButton').disabled = true;
		var xmlHttp;

		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}

		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				document.getElementById('atcResults').innerHTML = "<span style=\"font-size:100%;font-weight:bold;color:#993333;\">"+xmlHttp.responseText+"</span>&nbsp;&nbsp;<a href=\"?a=cart\">To view your cart and check out, <span style=\"text-decoration:underline;\">click here</span>. <img src=\"cart3.jpg\" style=\"border:0;\" alt=\"\"></a>&nbsp;&nbsp;";
				document.getElementById('atcButton').value = "Add to Cart";
				document.getElementById('atcButton').disabled = false;
			}
		}
		myP2 = myP + '|' + document.getElementById('qToAdd').value;
		xmlHttp.open("GET","addItem.php?rand="+Math.random()+"&p="+myP2,true);
		xmlHttp.send(null);
	}
}

function clearCart()
{
		var xmlHttp;

		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}

		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				window.location = "http://www.wholesalepatiostore.com/index.php?a=cart&emptyCart=si";
			}
		}
	
		xmlHttp.open("GET","emptyCart.php?rand="+Math.random(),true);
		xmlHttp.send(null);
}

function gopp(msg)
{
	var xmlHttp;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				uber = 1;
			}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			uber = 2;
		}
	}
	xmlHttp.open("GET","wentpp.php?rand="+Math.random()+"&msg="+msg,false);
	xmlHttp.send(null);
}
function gtc()
{
	var xmlHttp;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				uber = 1;
			}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			uber = 2;
		}
	}
	xmlHttp.open("GET","gtc.php?rand="+Math.random(),true);
	xmlHttp.send(null);
}

function Set()
{
	this.options = new Array();
	this.upgrades = new Array();
	
	this.getInfo = function()
	{
		return this.options.join(';') + '|' + this.upgrades.join(';');
	}
}

function Product(myId)
{
	this.id = myId;
	this.setChoice = 0;
	this.sets = new Array();
	this.bullets = new Array();
	
	this.addBullet = function(c)
	{
		this.bullets.push(c);
	}
	
	this.addSet = function(s)
	{
		this.sets[s] = new Set();
	}
	
	this.chooseSet = function(s)
	{
		this.setChoice = s;
	}
	
	this.addOptionSet = function(s,i)
	{
		this.sets[s].options[i] = 0;
	}
	
	this.addUpgradeSet = function(s,i)
	{
		this.sets[s].upgrades[i] = 0;
	}
	
	this.changeOptionSet = function(s,o,n)
	{
		this.sets[s].options[o] = n;
	}
	
	this.changeUpgradeSet = function(s,u,n)
	{
		this.sets[s].upgrades[u] = n;
	}
	
	this.getInfo = function(bin)
	{
		myBullets = '';
		cont = true;
		if (this.bullets.length > 0)
		{
			myB = false;
			for (i = 0; i < this.bullets.length; i++)
				if (document.infoForm.npob[i].checked)
				{
					myBullets = document.infoForm.npob[i].value;
					myB = true;
				}

			if (!myB)
			{
				cont = false;    
				alert(bin);
				return false;
			}
		}
		else
			myBullets = '';
	
		if (this.sets.length > 0)
			return this.id + "|" + this.setChoice + "|" + this.sets[this.setChoice].getInfo() + '|' + myBullets;
		else
			return this.id + '|' + myBullets;
	}
}

function enableMe(s,total)
{
	myProduct.chooseSet(s.selectedIndex);
	spot = s.options[s.selectedIndex].value;
	for (i = 0; i< total; i++)
	{
		if (('choice'+i) === spot)
			document.getElementById('choice'+i+"Content").style.display = 'block';
		else
			document.getElementById('choice'+i+"Content").style.display = 'none';
	}
}

function removeItem(p)
{
	var xmlHttp2;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp2=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp2.onreadystatechange=function()
	{
		if(xmlHttp2.readyState==4)
		{
			if (xmlHttp2.responseText === 'Cart Updated.')
			{
				document.getElementById('updateButton').value = "Update";
				document.getElementById('updateButton').disabled = false;
				window.location.href = window.location.href;
			}
			else
				alert('Error removing item:'+xmlHttp2.responseText);
		}
	}
	xmlHttp2.open("GET","removeItem.php?rand="+Math.random()+"&p="+p,true);
	xmlHttp2.send(null);
}

function removeItems(total)
{
	document.getElementById('updateButton').value = "Updating...";
	document.getElementById('updateButton').disabled = true;
	itemA = [];
	for (i = 1; i <= total; i++)
		itemA.push(document.cartForm['remove'+i].value);
	removeItem(itemA.join(','));	
}

function changeChoiceDetails(pc,s,which,me,toAdd)
{
	if (s === 'o')
	{
		pOptions[pc][which] = me+": "+toAdd;
		document.getElementById('pposo'+pc).value = pOptions[pc].join(',');
	}
	else if (s === 'u')
	{
		pUpgrades[pc][which] = me+": "+toAdd;
		document.getElementById('pposu'+pc).value = pUpgrades[pc].join(',');
	}
}

function setChoiceDetails()
{
	for (i in pOptions)
		for (j in pOptions[i])
		{
			if (document.getElementById('item'+i+'op'+j))
			{
				me = document.getElementById('item'+i+'op'+j);
				pOptions[i][j] = document.getElementById('iName'+i+'op'+j).value +': '+me.options[me.selectedIndex].value;
				document.getElementById('pposo'+i).value = pOptions[i].join(',');
			}
		}
		
	for (i in pUpgrades)
		for (j in pUpgrades[i])
		{
			if (document.getElementById('item'+i+'up'+j))
			{
				me = document.getElementById('item'+i+'up'+j);
				pUpgrades[i][j] = document.getElementById('iName'+i+'up'+j).value +': '+me.options[me.selectedIndex].value;
				document.getElementById('pposu'+i).value = pUpgrades[i].join(',');
			}
		}
}

function changeImgSrc(where,which,what)
{
	document.getElementById(where).src = "/finishes/thumbs/"+colors[which][what];
}

colors = [];

function changeMyState(myS)
{
	if (myS)
	{
		var xmlHttpState;

		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttpState=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttpState=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttpState=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}

		xmlHttpState.onreadystatechange=function()
		{
			if(xmlHttpState.readyState==4)
			{

			}
		}
		xmlHttpState.open("GET","changeState.php?myS="+myS,true);
		xmlHttpState.send(null);
	}
	else
		return false;
}

function removeMe(which,t)
{
	document.cartForm['remove' + which].value = 0;
	removeItems(t);
}


function switchPic(n,t)
{
	document.getElementById('pInfoPic').src = "images/"+n;
	document.getElementById('pInfoWord').innerHTML = t;
}

function toggleVisibility(sm,myPlus,lvl)
{
	if (document.getElementById(sm).style.display == 'block')
		document.getElementById(sm).style.display = 'none';
	else
		document.getElementById(sm).style.display = 'block';
				
	if (document.getElementById(myPlus).src == 'http://www.wholesalepatiostore.com/level'+lvl+'minus.jpg')
		document.getElementById(myPlus).src = "level"+lvl+"plus.jpg";
	else
		document.getElementById(myPlus).src = "level"+lvl+"minus.jpg";
	
	return false;
}