





var isContestCoupon = false;
var sizeHash = new Object();
var sizeHash = new Object();
var shippingCost = 0;
sizeHash['s'] = 'S';
sizeHash['m'] = 'M';
sizeHash['l'] = 'L';
sizeHash['xl'] = 'XL';
var shippingHash = new Array();
shippingHash[0] = 3;
shippingHash[1] = 3;
shippingHash[2] = 8;
shippingHash[3] = 8;
shippingHash[4] = 1000000;

var fadeInterval = 0;
var shippingus = new Object();
var shippingcanada = new Object();
var shippingeurope = new Object();
var shippingother = new Object();
var sidebarImages = new Array();
sidebarImages[0] = new Image();
sidebarImages[1] = new Image();
sidebarImages[2] = new Image();
sidebarImages[3] = new Image();
sidebarImages[4] = new Image();
sidebarImages[5] = new Image();
sidebarImages[6] = new Image();
sidebarImages[7] = new Image();
sidebarImages[8] = new Image();
sidebarImages[9] = new Image();
sidebarImages[10] = new Image();
sidebarImages[0].src = "http://www.insanelygreattees.com/stockimages/president/president_icon_large.png";
sidebarImages[1].src = "http://www.insanelygreattees.com/stockimages/640k/640k_icon_large.png";
sidebarImages[2].src = "http://www.insanelygreattees.com/stockimages/camera/camera_icon_large.png";
sidebarImages[3].src = "http://www.insanelygreattees.com/stockimages/binarytree/binarytree_icon_large.png";
sidebarImages[4].src = "http://www.insanelygreattees.com/stockimages/imamac/imamac_icon_large.png";
sidebarImages[5].src = "http://www.insanelygreattees.com/stockimages/pixeltools/pixeltools_icon_large.png";
sidebarImages[6].src = "http://www.insanelygreattees.com/stockimages/thebomb/thebomb_icon_large.png";
sidebarImages[7].src = "http://www.insanelygreattees.com/stockimages/jollyroger/jollyroger_icon_large.png";
sidebarImages[8].src = "http://www.insanelygreattees.com/stockimages/futurism/futurism_icon_large.png";
sidebarImages[9].src = "http://www.insanelygreattees.com/stockimages/heart/heart_icon_large.png";
sidebarImages[10].src = "http://www.insanelygreattees.com/stockimages/magiceraser/magiceraser_icon_large.png";

shippingus["firstclass0"] = 4;
shippingus["firstclass1"] = 4;
shippingus["firstclass2"] = 0;
shippingus["firstclass3"] = 0;
shippingus["firstclass4"] = 0;
shippingus["firstclass5"] = 0;
shippingus["firstclass6"] = 0;
shippingus["firstclass7"] = 0;
shippingus["firstclass8"] = 0;
shippingus["firstclass9"] = 0;
shippingus["firstclass10"] = 0;
shippingus["firstclass11"] = 0;
shippingus["firstclass12"] = 0;
shippingus["firstclass13"] = 0;
shippingus["firstclass14"] = 0;
shippingus["firstclass15"] = 0;
shippingus["firstclass16"] = 0;
shippingus["firstclass17"] = 0;
shippingus["firstclass18"] = 0;
shippingus["firstclass19"] = 0;
shippingus["firstclass20"] = 0;
shippingus["USPS0"] = 5;
shippingus["USPS1"] = 5;
shippingus["USPS2"] = 5;
shippingus["USPS3"] = 6;
shippingus["USPS4"] = 10;
shippingus["USPS5"] = 12;
shippingus["USPS6"] = 12;
shippingus["USPS7"] = 13;
shippingus["USPS8"] = 13;
shippingus["USPS9"] = 13;
shippingus["USPS10"] = 14;
shippingus["USPS11"] = 14;
shippingus["USPS12"] = 14;
shippingus["USPS13"] = 16;
shippingus["USPS14"] = 16;
shippingus["USPS15"] = 16;
shippingus["USPS16"] = 18;
shippingus["USPS17"] = 18;
shippingus["USPS18"] = 18;
shippingus["USPS19"] = 20;
shippingus["USPS20"] = 20;
shippingus["UPS0"] = 6;
shippingus["UPS1"] = 6;
shippingus["UPS2"] = 7;
shippingus["UPS3"] = 7;
shippingus["UPS4"] = 7;
shippingus["UPS5"] = 9;
shippingus["UPS6"] = 9;
shippingus["UPS7"] = 10;
shippingus["UPS8"] = 10;
shippingus["UPS9"] = 10;
shippingus["UPS10"] = 12;
shippingus["UPS11"] = 12;
shippingus["UPS12"] = 12;
shippingus["UPS13"] = 12;
shippingus["UPS14"] = 12;
shippingus["UPS15"] = 14;
shippingus["UPS16"] = 14;
shippingus["UPS17"] = 14;
shippingus["UPS18"] = 15;
shippingus["UPS19"] = 15;
shippingus["UPS20"] = 15;
shippingcanada["fedex0"] = 17;
shippingcanada["fedex1"] = 17;
shippingcanada["fedex2"] = 19;
shippingcanada["fedex3"] = 19;
shippingcanada["fedex4"] = 22;
shippingcanada["fedex5"] = 24;
shippingcanada["fedex6"] = 24;
shippingcanada["fedex7"] = 25;
shippingcanada["fedex8"] = 25;
shippingcanada["fedex9"] = 25;
shippingcanada["fedex10"] = 30;
shippingcanada["fedex11"] = 30;
shippingcanada["fedex12"] = 35;
shippingcanada["fedex13"] = 35;
shippingcanada["fedex14"] = 35;
shippingcanada["fedex15"] = 35;

shippingcanada["USPS0"] = 8;
shippingcanada["USPS1"] = 8;
shippingcanada["USPS2"] = 10;
shippingcanada["USPS3"] = 14;
shippingcanada["USPS4"] = 14;
shippingcanada["USPS5"] = 22;
shippingcanada["USPS6"] = 22;
shippingcanada["USPS7"] = 25;
shippingcanada["USPS8"] = 25;
shippingcanada["USPS9"] = 25;
shippingcanada["USPS10"] = 27;
shippingcanada["USPS11"] = 27;
shippingcanada["USPS12"] = 29;
shippingcanada["USPS13"] = 29;
shippingcanada["USPS14"] = 30;
shippingcanada["USPS14"] = 30;

shippingeurope["fedex0"] = 19;
shippingeurope["fedex1"] = 19;
shippingeurope["fedex2"] = 22;
shippingeurope["fedex3"] = 24;
shippingeurope["fedex4"] = 24;
shippingeurope["fedex5"] = 24;
shippingeurope["fedex6"] = 24;
shippingeurope["fedex7"] = 26;
shippingeurope["fedex8"] = 26;
shippingeurope["fedex9"] = 26;
shippingeurope["fedex10"] = 26;
shippingeurope["fedex11"] = 26;
shippingeurope["fedex12"] = 29;
shippingeurope["fedex13"] = 29;
shippingeurope["fedex14"] = 35;
shippingeurope["fedex15"] = 35;
shippingeurope["fedex16"] = 35;

shippingeurope["USPS0"] = 12;
shippingeurope["USPS1"] = 12;
shippingeurope["USPS2"] = 15;
shippingeurope["USPS3"] = 17;
shippingeurope["USPS4"] = 22;
shippingeurope["USPS5"] = 27;
shippingeurope["USPS6"] = 31;
shippingeurope["USPS7"] = 45;
shippingeurope["USPS8"] = 45;

shippingother["fedex0"] = 23;
shippingother["fedex1"] = 23;
shippingother["fedex2"] = 25;
shippingother["fedex3"] = 27;
shippingother["fedex4"] = 27;
shippingother["fedex5"] = 30;
shippingother["fedex6"] = 30;
shippingother["fedex7"] = 35;
shippingother["fedex8"] = 35;

shippingother["USPS0"] = 14;
shippingother["USPS1"] = 14;
shippingother["USPS2"] = 14;
shippingother["USPS3"] = 15;
shippingother["USPS4"] = 18;
shippingother["USPS5"] = 30;
shippingother["USPS6"] = 30;
shippingother["USPS7"] = 45;
shippingother["USPS8"] = 45;


window.onload = function() {
  setFooter();
}
window.onresize = function() {
  setFooter();
}


function checkShippingSubmitPayPal(){


if (document.getElementById("shippingGroupSelect").selectedIndex > 0) {
	document.paypal.submit();	
} else {
	alert("Hey Buster! You've gotta choose some shipping options!");
}

}

function shippingFinalChange(){
//debug(o("shippingSelect").options[o("shippingSelect").selectedIndex].text);
	if (o("shippingSelect").options[o("shippingSelect").selectedIndex].text.slice(0, 5) == "Fedex") o("phoneInfo").style.display = 'block';
		else o("phoneInfo").style.display = "none";
if (o("shippingSelect").value <= 0 && !isContestCoupon) {
	o("handling_cart_id").value = 0;
	o("shippinglabel").innerHTML = "pre-shipping total:";	
	o("letspayimage").style.opacity=.3;
} else {

	o("handling_cart_id").value = o("shippingSelect").value;
if (callingPage2 == "cart2") o("handling_cart_id").value = ".01";
	o("shippinglabel").innerHTML = "the grand total:";	
	if (parseInt(newTotalPrice) < 0) newTotalPrice = 0;
	o("letspayimage").style.opacity=1;

	finalCustomString = customString + "|" + o("shippingSelect").options[o("shippingSelect").selectedIndex].text + "|" + o("phoneNumber").value;

	o("customInput").value = finalCustomString;
//	debug(o("customInput").value);
}
	o("shippingpricelabel").innerHTML = "$"+(Number(newTotalPrice)+Number(o("shippingSelect").value));

}

function phoneNumberChanged(){
	finalCustomString = customString + "|" + o("shippingSelect").options[o("shippingSelect").selectedIndex].text + "|" + o("phoneNumber").value;
	o("customInput").value = finalCustomString;

}
function setFooter() {
if (callingPage == "news"){
	if (document.getElementById) {
		var windowHeight=getWindowHeight();
		var sidebarHeight = 0;
		if (document.getElementById('blogsidebar')) sidebarHeight = document.getElementById('blogsidebar').offsetHeight;
		
		if (windowHeight>0) {
			var contentHeight= document.getElementById('verticalBarNews').offsetHeight;
			var footerElement=document.getElementById('footer');
			var footerHeight=footerElement.offsetHeight;
				//debug(sidebarHeight);
			var newHeight = 0;
			if ((sidebarHeight+150)<contentHeight) {
				
				newHeight = (contentHeight-50);
			} else {
				newHeight = (sidebarHeight);
			}
			if (windowHeight > contentHeight) newHeight = windowHeight;
			
//			debug(windowHeight);
//			debug(contentHeight);
			newHeight = newHeight + 70;
			footerElement.style.height = newHeight+"px";

/*
			if (sidebarHeight == 0){

				footerElement.style.top = (document.getElementById('verticalBarNews').offsetHeight)+"px";//"0px";//(sidebarHeight+40)+"px";
				footerElement.style.height = "50px";//(windowHeight-sidebarHeight+80)+'px';	
			} else {
				if (document.getElementById('verticalBarNews').offsetHeight == 650) {
					footerElement.style.top = (sidebarHeight+40)+"px";
					footerElement.style.height = (windowHeight-sidebarHeight+80)+'px';
				} else {

					footerElement.style.top = (document.getElementById('verticalBarNews').offsetHeight)+"px";
					footerElement.style.height = (windowHeight-sidebarHeight+50)+'px';
				}
			}
*/
		}
	}

} else {
	if (document.getElementById) {
		var windowHeight=getWindowHeight();
		if (windowHeight>0) {
			var contentHeight= document.getElementById('verticalBar').offsetHeight;
			var footerElement=document.getElementById('footer');
			var footerHeight=footerElement.offsetHeight;
			if ((windowHeight-contentHeight)>=0) {
//				footerElement.style.position='relative';

				footerElement.style.height = (((windowHeight-contentHeight)-11)<0 ? 0 : ((windowHeight-contentHeight)-11))+'px';
			} else {
				footerElement.style.position='static';
				footerElement.style.height = 70;//(windowHeight-contentHeight-11)+'px';
			}
		}
	}
}
}

function sizeSelChanged(){

//	debug(o("sizeSelect").value);
	var cSize = o("sizeSelect").value;
	var cNum = shirtSizes[cSize];
	o("quantitySelect").options.length = 0;
	if (cNum == 0){
		//there are none of this size in stock!
		o("quantitySelect").options[0] = new Option("Sold Out!", 0);
	//	o("buyButtonImage").display = "none";
	} else {
		var i = 1;
		while (i <= cNum){
			o("quantitySelect").options[i-1] = new Option(i, i);
			if (i == 5) i = cNum+1;
			i++;
		}
	//	o("buyButtonImage").display = "block";
		//SOME in stock!
	}
//	o("quantitySelect").options[0] = new Option("A", "value");

}

function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&document.documentElement.clientHeight) {
windowHeight=document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}



function o(x) {
return document.getElementById(x);
}

function productLoaded(){
	shirtid = location.search.split("=")[1];
	getShirtData(shirtid);
}

function loaded(){
	getCookie();

	if (callingPage == "cart") shippingCost = shippingHash[shippingFromPHP];
}


function debug(msg) {
	if (!debug.box) {
		debug.box = document.createElement("div");
		debug.box.setAttribute("style", "background-color: white; " +
										"color: black; " +
										"font-family: monospace; " +
										"font-size: 10; " + 
										"border: solid black 3px; " +
										"position: absolute;top:0px;" +
										"z-index: 100;" +
										"opacity:.8;" +
										"padding: 2px;");
		document.body.appendChild(debug.box);
	}
	
	var p = document.createElement("p");
	p.appendChild(document.createTextNode(msg));
	debug.box.appendChild(p);
}

function getShirtData(sid){
	//xmlHttp = new XMLHttpRequest();
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlHttp = new XMLHttpRequest();
	}

	var url=relRoot+"getshirtdata.php?sid="+sid;

	xmlHttp.onreadystatechange=getShirtDataHandler;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);	
}

function getShirtDataHandler(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		drawProductPageWithXML(xmlHttp.responseXML);
	}	
}

function showNextImage(whichShirt){

	
	o("productPhoto").style.display = "block";
	Element.setOpacity("productPhoto", 1.0);

	Effect.Fade("productPhoto");
	highlightNumber(nextShirtImage);
	
	window.setTimeout("changeOP('"+whichShirt+"');", 1500);
	
/*	o("navNumberImage1").setOpacity(0.3);
	
	o("navNumberImage2").setOpacity(0.3);
	o("navNumberImage3").setOpacity(0.3);
	o("navNumberImage4").setOpacity(0.3);
	o("navNumberImage5").setOpacity(0.3);

	o("navNumberImage"+currentShirtImage).setOpacity(1);*/
}

function changeOP(whichShirt){
	currentShirtImage = nextShirtImage;
	nextShirtImage++;
	if (nextShirtImage > maxShirtImage) nextShirtImage = 1;
	
	o("productPhoto").src = "/stockimagesnew/"+whichShirt+"/"+whichShirt+"_productimage"+currentShirtImage+".jpg";
	Element.setOpacity("productPhoto", 1.0);
	o("productPhoto").style.display = "block";
	o("productPhoto2").src = "/stockimagesnew/"+whichShirt+"/"+whichShirt+"_productimage"+nextShirtImage+".jpg";
highlightNumber(currentShirtImage);

}

function highlightNumber(which){
	//maxShirtImage
	var opI = 1;

	while (opI <= maxShirtImage) {
		Element.setOpacity("navNumberImage"+opI, .3);
		opI++;
	}

	Element.setOpacity("navNumberImage"+which, 1.0);
}

function loadShirtImage(sName, which){

if (fadeInterval) window.clearInterval(fadeInterval);

if (!nofade) fadeInterval = window.setInterval("showNextImage('"+sName+"');", 5000);

//	if (fadeInterval) clearInterval(fadeInterval);
//	fadeInterval = window.setInterval("showNextImage('"+sName+"');", 4000);
	currentShirtImage = which;
	nextShirtImage = currentShirtImage+1;
	if (nextShirtImage > maxShirtImage) nextShirtImage = 1;
	Element.setOpacity("productPhoto", 1);
	o("productPhoto").style.display = "block";
	o("productPhoto").src="/stockimagesnew/"+sName+"/"+sName+"_productimage"+which+".jpg";

	o("productPhoto2").src="/stockimagesnew/"+sName+"/"+sName+"_productimage"+nextShirtImage+".jpg";
	highlightNumber(which);
/*	o("navNumberImage1").setOpacity(0.3);
	o("navNumberImage2").setOpacity(0.3);
	o("navNumberImage3").setOpacity(0.3);
	o("navNumberImage4").setOpacity(0.3);
	o("navNumberImage5").setOpacity(0.3);

	o("navNumberImage"+which).setOpacity(1);*/

}

function drawProductPageWithXML(x){
	var items = x.getElementsByTagName('item');
	o("shirtTitle").innerHTML = "<h1>"+items[0].getElementsByTagName('desc')[0].childNodes[0].nodeValue+"</h1>";
	prefix = items[0].getElementsByTagName('prefix')[0].childNodes[0].nodeValue;
	o("productThumb1").src = "stockimages/"+prefix+"/"+prefix+"_productimage2small.jpg";
	o("productThumb2").src = "stockimages/"+prefix+"/"+prefix+"_productimage3small.jpg";
	o("productThumb3").src = "stockimages/"+prefix+"/"+prefix+"_productimage4small.jpg";
	o("productPhoto").src = "stockimages/"+prefix+"/"+prefix+"_productimage1.jpg";
/*
	var i = 0;

	while (i < items.length){
		debug(items[i])
//		addItemToShirtDisplay(items[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue, items[i].getElementsByTagName('size')[0].childNodes[0].nodeValue, items[i].getElementsByTagName('price')[0].childNodes[0].nodeValue, items[i].getElementsByTagName('sizeid')[0].childNodes[0].nodeValue, items[i].getElementsByTagName('shirtid')[0].childNodes[0].nodeValue);
		i++;
	}*/
}

function autoAddShirt(){
//	xmlHttp = new XMLHttpRequest();
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlHttp = new XMLHttpRequest();
	}

	var url=relRoot+"addshirt.php?sid="+o("sizeSelect").value+"&cartid="+localCartID+"&q="+o("quantitySelect").value;
	xmlHttp.onreadystatechange=addShirtHandler;
	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);	

}

function addShirt(sizeID){
//	xmlHttp = new XMLHttpRequest();
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlHttp = new XMLHttpRequest();
	}

	var url=relRoot+"addshirt.php?sid="+sizeID+"&cartid="+localCartID;

	xmlHttp.onreadystatechange=addShirtHandler;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
}


function addShirtHandler(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
//		o("numInCartFooter").innerHTML = '<div><img src="'+relRoot+'images/buybox_top.gif" alt=" " /></div><div class="buyDetails"><p><a href="'+relRoot+'cart.php">You have '+xmlHttp.responseText+' shirts in your cart.</a></p></div><div><img src="'+relRoot+'images/buybox_bottom.gif" alt=" " /></div>';
		window.location.href=relRoot+"cart";

	}
}


function setCookie(cartNum){

	document.cookie = "cart="+cartNum+"; domain=insanelygreattees.com; path=/";
}

function listShippingPrices(numShirts){

//	if (document.getElementById("shippingGroupSelect").length == 5) document.getElementById("shippingGroupSelect").options[0] = null;

	while(document.getElementById("shippingSelect").options.length > 0) document.getElementById("shippingSelect").options[0] = null;

/*	if (document.getElementById("shippingGroupSelect").value == 1){
		document.getElementById("shippingSelect").options[0] = new Option("UPS - "+numShirts, "15");
		document.getElementById("shippingSelect").options[1] = new Option("USPS - "+numShirts, "15");
	}
*/	
	var shippingMod = 0;
	if (isContestCoupon) shippingMod = 4;
	switch(document.getElementById("shippingGroupSelect").value){
		case "1":
				//US
//				if (document.getElementById("shippingInfo")) document.getElementById("shippingInfo").innerHTML = "UPS is the fastest option, and has full tracking on all packages. Customers in Puerto Rico must choose USPS (not UPS).";//US Postal Service shipping is the cheapest, but it can be slow and has no tracking! UPS costs a bit more, but you'll get your package really fast and be able to track it!
				if (document.getElementById("shippingInfo")) document.getElementById("shippingInfo").innerHTML = "UPS is the fastest option, and has full tracking on all packages. Customers in Puerto Rico must choose USPS (not UPS). <span style='color:white;'>We can't guarantee Christmas delivery, but choose UPS if you want to try!</span>";//US Postal Service shipping is the cheapest, but it can be slow and has no tracking! UPS costs a bit more, but you'll get your package really fast and be able to track it!
				setFooter();
				if (shippingus["UPS"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("UPS Ground: $"+(shippingus["UPS"+parseInt(numShirts)]-shippingMod), shippingus["UPS"+parseInt(numShirts)]-parseInt(shippingMod));
				if (shippingus["firstclass"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("First Class: $"+(shippingus["firstclass"+parseInt(numShirts)]-parseInt(shippingMod)), shippingus["firstclass"+parseInt(numShirts)]-parseInt(shippingMod));
				if (shippingus["USPS"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("USPS Priority: $"+(shippingus["USPS"+parseInt(numShirts)]-shippingMod), shippingus["USPS"+parseInt(numShirts)]-parseInt(shippingMod));
				
	//			document.getElementById("shippingSelect").options[0] = new Option("AIRMAIL - "+numShirts, "15");
	//			document.getElementById("shippingSelect").options[1] = new Option("UPS - "+numShirts, "15");
	//			document.getElementById("shippingSelect").options[2] = new Option("USPS - "+numShirts, "15");
			break;
		case "2":
		//Canada
			if (document.getElementById("shippingInfo")) document.getElementById("shippingInfo").innerHTML = "US Postal Service shipping is the cheapest, but it's slow (sometimes a few weeks!) and has no tracking! FedEx costs a bit more, but you'll get your package really fast (even internationally) and be able to track it! <span style='color:white;'>We can't guarantee Christmas delivery, but choose Fedex if you want to try!</span>";
			setFooter();
			if (shippingcanada["fedex"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("Fedex Priority : $"+(shippingcanada["fedex"+parseInt(numShirts)]-shippingMod), shippingcanada["fedex"+parseInt(numShirts)]-shippingMod);
			if (shippingcanada["USPS"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("USPS : $"+(shippingcanada["USPS"+parseInt(numShirts)]-shippingMod), shippingcanada["USPS"+parseInt(numShirts)]-shippingMod);
			break;
		case "3":
		//europe
			if (document.getElementById("shippingInfo")) document.getElementById("shippingInfo").innerHTML = "US Postal Service shipping is the cheapest, but it's slow (sometimes a few weeks!) and has no tracking! FedEx costs a bit more, but you'll get your package really fast (even internationally) and be able to track it! <span style='color:white;'>We can't guarantee Christmas delivery, but choose Fedex if you want to try!</span>";
			setFooter();		
			if (shippingeurope["fedex"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("Fedex Priority : $"+(shippingeurope["fedex"+parseInt(numShirts)]-shippingMod), shippingeurope["fedex"+parseInt(numShirts)]-shippingMod);
			if (shippingeurope["USPS"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("USPS : $"+(shippingeurope["USPS"+parseInt(numShirts)]-shippingMod), shippingeurope["USPS"+parseInt(numShirts)]-shippingMod);
			break;
		case "4":
		//other
		if (document.getElementById("shippingInfo")) document.getElementById("shippingInfo").innerHTML = "US Postal Service shipping is the cheapest, but it's slow (sometimes a few weeks!) and has no tracking! FedEx costs a bit more, but you'll get your package really fast (even internationally) and be able to track it! <span style='color:white;'>We can't guarantee Christmas delivery, but choose Fedex if you want to try!</span>";
		setFooter();
		if (shippingother["fedex"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("Fedex Priority : $"+(shippingother["fedex"+parseInt(numShirts)]-shippingMod), shippingother["fedex"+parseInt(numShirts)]-shippingMod);
		if (shippingother["USPS"+parseInt(numShirts)] > 0) document.getElementById("shippingSelect").options[o("shippingSelect").length] = new Option("USPS : $"+(shippingother["USPS"+parseInt(numShirts)]-shippingMod), shippingother["USPS"+parseInt(numShirts)]-shippingMod);
			break;						
		default:
			document.getElementById("shippingSelect").options[0] = new Option("-", 0);
	}
	shippingFinalChange();
}

function setShippingCookie(){
	shippingCost = o("shippingSelect").value;

//	debug(o("shippingSelect").selectedIndex);
//	document.cookie = "shipping="+o("shippingSelect").selectedIndex;
//	window.location.reload();
//	window.location.href=relRoot+"cart";
	/*
	var submitForm = document.createElement("form");
	submitForm.method = "POST";
	submitForm.action= relRoot+"cart";
	debug("A");
	var newElement = document.createElement("<input type='hidden' name='shippingSelectedIndex' value='"+o("shippingSelect").value+"'>");
	debug("B");


	submitForm.appendChild(newElement);
	document.body.appendChild(submitForm);
	debug("C");
	document.submitForm.submit();
	*/
	
}

function readCookie(cname){
//	document.cookie.domain = "insanelygreattees.com";
	var ca = document.cookie.split(';');
	var cookiename = cname+"=";
	for(var i=0; i < ca.length; i++) {

    	var c = ca[i];
	    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
	    if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length, c.length);
    }
	return null;
}

function getCookie(){
	var cookietemp = readCookie('cart');

	if (cookietemp != null) {

		localCartID = cookietemp;
//		getCartFromLocalCartID();
	} else {
		//no cookie, so ask php for one.
		setCookieWithPHP();
	}


}

function clearCookie(){
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );

  document.cookie = "cart=; domain=insanelygreattees.com; ; path=/; expires=" + cookie_date.toGMTString();
}

function setCookieWithPHP(){
//	xmlHttp3 = new XMLHttpRequest();
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlHttp3 = new XMLHttpRequest();
	}

	var url=relRoot+"getnewcart.php";

	xmlHttp3.onreadystatechange=setCookieWithPHPHandler;

	xmlHttp3.open("GET",url,true);

	xmlHttp3.send(null);	
}

function setCookieWithPHPHandler(){
	if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete"){
		setCookieWithSessionID(xmlHttp3.responseText);
	}
}

function setCookieWithSessionID(text){
	setCookie(text);

	localCartID = text;
//	getCartFromLocalCartID();
}

function removeCouponFromCart(couponid){
//	xmlHttp = new XMLHttpRequest();
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlHttp = new XMLHttpRequest();
	}

	var url=relRoot+"removecoupon.php?couponid="+couponid+"&cartid="+localCartID;

	xmlHttp.onreadystatechange=removeCouponHandler;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
}

function removeCouponHandler(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
//			getCartContents(localCartID);
//			window.location.reload();
			window.location.href=relRoot+"cart";

	}
}

//----------- from cart.js
function removeShirtFromCart(sizeid){
//	xmlHttp = new XMLHttpRequest();
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlHttp = new XMLHttpRequest();
	}

	var url=relRoot+"removeshirt.php?sid="+sizeid+"&cartid="+localCartID;

	xmlHttp.onreadystatechange=removeShirtHandler;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
}

function removeShirtHandler(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
//			getCartContents(localCartID);
//			window.location.reload();
			window.location.href=relRoot+"cart";
//		debug(xmlHttp.responseText);
	}
}

function getCartContents(cartID){
//	xmlHttp = new XMLHttpRequest();
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlHttp = new XMLHttpRequest();
	}

	var url=relRoot+"getcontents.php?cid="+cartID+"&shipping="+shippingCost;

	xmlHttp.onreadystatechange=getcontentshandler;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
	

}

function getcontentshandler(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

		drawCartFromXML(xmlHttp.responseXML);
	}

}

function drawCartFromXML(xml){

//	while(o("cart").hasChildNodes()){
//		o("cart").removeChild(o("cart").childNodes[0]);

//	}

	var cartHTML = "<ul>\n";
//	var formHTML = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">\n<input type="hidden" name="cmd" value="_cart">\n<input type="hidden" name="upload" value="1">\n<input type="hidden" name="business" value="joshua@insanelygreattees.com">';
	var wholeForm = xml.getElementsByTagName('items');
	var items = xml.getElementsByTagName('item');
	var i = 0;
	
	var formText = wholeForm[0].getAttribute("formtext");

	formText = formText.replace(/\[/g, "<");
	formText = formText.replace(/\]/g, ">");
	formText = formText.replace(/\;/g, "\"");
//debug(formText);
	o("payButton").innerHTML = formText;

	totalPrice = 0;
	while (i < items.length){

	//	carthtml = carthtml + items[i].getElementsByTagName('num')[0].childNodes[0].nodeValue + " " + items[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue + "(" + items[i].getElementsByTagName('size')[0].childNodes[0].nodeValue + ") <br>";
	//	addItemToCartDisplay(items[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue, items[i].getElementsByTagName('size')[0].childNodes[0].nodeValue, items[i].getElementsByTagName('num')[0].childNodes[0].nodeValue, items[i].getElementsByTagName('sizeid')[0].childNodes[0].nodeValue);

	//	formHTML = formHTML + '<input type="hidden" name="item_name_'+(i+1)+'" value="'+items[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue+'('+items[i].getElementsByTagName('size')[0].childNodes[0].nodeValue+')">\n<input type="hidden" name="amount_'+(i+1)+'" value="'+items[i].getElementsByTagName('price')[0].childNodes[0].nodeValue+'">\n<input type="hidden" name="quantity_'+(i+1)+'" value="'+items[i].getElementsByTagName('num')[0].childNodes[0].nodeValue+'">\n';
		var j = parseInt(items[i].getElementsByTagName('num')[0].childNodes[0].nodeValue);

		while (j > 0) {
			cartHTML = cartHTML + '<li>\n';
			cartHTML = cartHTML + '<img src="'+relRoot+'stockimages/'+items[i].getElementsByTagName('prefix')[0].childNodes[0].nodeValue+'/'+items[i].getElementsByTagName('prefix')[0].childNodes[0].nodeValue+'_carticon.png" class="cartIcon" />\n';
			cartHTML = cartHTML + '<div class="options">\n<h2>$'+items[i].getElementsByTagName('price')[0].childNodes[0].nodeValue+'</h2>\n<h3><a href="javascript:removeShirtFromCart(\''+items[i].getElementsByTagName('sizeid')[0].childNodes[0].nodeValue+'\');">Remove</a></h3>\n</div>\n<div class="desc">\n<h2>'+items[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue+'<span>('+sizeHash[items[i].getElementsByTagName('size')[0].childNodes[0].nodeValue]+')</span></h2>\n<p>'+items[i].getElementsByTagName('carttext')[0].childNodes[0].nodeValue+'</p>\n</div>\n';
			cartHTML = cartHTML + '<br style="clear:both;" />\n</li>\n';
			j--;
		}
		totalPrice = totalPrice + parseInt(items[i].getElementsByTagName('price')[0].childNodes[0].nodeValue)*parseInt(items[i].getElementsByTagName('num')[0].childNodes[0].nodeValue);

		i++;
	}

	o("totalDetails").innerHTML = "<p>the grand total: </p> <h2>$"+(totalPrice+shippingCost)+"</h2></p>";
	cartHTML = cartHTML + '</ul>\n';
	o("cartProductList").innerHTML = cartHTML;
//	formHTML = formHTML + '<input type="submit" value="PayPal">\n</form>';

}


function sizedPopup(x,y,myURL) {
  winstyle = "width="+x+",height="+y+",location=no,menubars=no,toolbars=no,scrollbars";
  window.open(myURL, "popup", winstyle);
}

function changedShippingTypeRadio(){
	if (document.newCartForm.shippingRadio[0].checked){

		checkoutslider = new Effect.Move ('checkout_outline',{ x: 0, y: 4, mode: 'absolute'});
	  
	} else {

		checkoutslider = new Effect.Move ('checkout_outline',{ x: 0, y: 60, mode: 'absolute'});
	
	}
}

function shippingRadioChanged(){

	if (document.newCartForm.shippingRadio[0].checked){

		document.newCartForm.shippingRadio[1].checked = true;
		checkoutslider = new Effect.Move ('checkout_outline',{ x: 0, y: 60, mode: 'absolute'});

	  
	} else {
		
		document.newCartForm.shippingRadio[0].checked = true;
		checkoutslider = new Effect.Move ('checkout_outline',{ x: 0, y: 4, mode: 'absolute'});

	}
}

function goToStep(whichStep){
	switch(whichStep){
		case 1:
			document.newCartForm.action = "step1.php";
			document.newCartForm.submit();
			return 0;
		case 2:
			document.newCartForm.action = "step2.php";
			document.newCartForm.submit();
			return 0;
		case 3:
			document.newCartForm.action = "step3.php";
			document.newCartForm.submit();
			return 0;
		case 4:	
			document.newCartForm.action = "step4.php";
			document.newCartForm.submit();
			return 0;
		default:
}		
		
}

function billingaddresschecked(){
	if (document.newCartForm.shiptosame.checked == true) {
		document.newCartForm.address1b.disabled = false;
		document.newCartForm.address2b.disabled = false;
		document.newCartForm.nameb.disabled = false;				
		document.newCartForm.cityb.disabled = false;
		document.newCartForm.stateb.disabled = false;
		document.newCartForm.zipb.disabled = false;
		document.newCartForm.countryb.disabled = false;
	} else {
		document.newCartForm.address1b.disabled = true;
		document.newCartForm.address2b.disabled = true;
		document.newCartForm.nameb.disabled = true;				
		document.newCartForm.cityb.disabled = true;
		document.newCartForm.stateb.disabled = true;
		document.newCartForm.zipb.disabled = true;
		document.newCartForm.countryb.disabled = true;

	}
}

function setoutlineheight(){
	if (document.newCartForm.shippingRadio[0].checked) o("checkout_outline").style.top = "4px";
		else {
			o("checkout_outline").style.top = "60px";
			document.newCartForm.shippingRadio[1].checked = true;
		}
}
