var IE = (document.all) ? 1 : 0;
var DOM = 0; 
if (parseInt(navigator.appVersion) >=5) {DOM=1};



var running = false;

function trimmit(){
	var str2 = document.billingsubmit.giftnote.value;
	var retstr = str2.substr(0,150);
	document.billingsubmit.giftnote.value = retstr;
}

function startcharcount(){
    running = true;
    runcharcount();
}
function runcharcount()
{
	var maxKeys = 150;
	var str = document.billingsubmit.giftnote.value;
	var len = document.billingsubmit.giftnote.value.length;
	var showstr = len + " of " + maxKeys + " characters.";
	if (len > maxKeys) {
		showstr += '<h3 class="brown"><i class="hilite">Woah there! Too many characters!</i></h3>';
		setTimeout('trimmit();',1000);		
	}
	if (DOM) {
		var viewer = document.getElementById("charcount");
		viewer.innerHTML=showstr;
	}
		else if(IE) {
		document.all["charcount"].innerHTML=showstr;
	}
	if(running) {
		setTimeout('runcharcount();',100);
	}
}
function stopcharcount(){
    running = false;
}


function billingsubmit(x) {
	document.billingsubmit.whichaddress.value = x;
    document.billingsubmit.submit();
}

function closecartadded() {
	document.getElementById("cartadded").className = "closecartadded";
}

function imageflip(x) {
	document.getElementById("p_stack").style.backgroundPosition = "0px -"+x+"px";
}
function fabricflip(x) {
	document.getElementById("f_stack").style.backgroundPosition = "0px -"+x+"px";
}

function stateswitch(x) {
	if ( x == "Canada" ) {
		document.getElementById("province").style.display = "block";
		document.getElementById("state").style.display = "none";
		document.getElementById("australianstate").style.display = "none";
		document.getElementById("stateinput").style.display = "none";
	}
	else if ( x == "United States" ) {
		document.getElementById("state").style.display = "block";
		document.getElementById("province").style.display = "none";
		document.getElementById("australianstate").style.display = "none";
		document.getElementById("stateinput").style.display = "none";
	}
	else if ( x == "Australia" ) {
		document.getElementById("australianstate").style.display = "block";
		document.getElementById("province").style.display = "none";
		document.getElementById("state").style.display = "none";
		document.getElementById("stateinput").style.display = "none";
	}
	else {
		document.getElementById("stateinput").style.display = "block";
		document.getElementById("australianstate").style.display = "none";
		document.getElementById("province").style.display = "none";
		document.getElementById("state").style.display = "none";
		document.forms["billingsubmit"].stateinput.value = '';
	}
}
function sstateswitch(x) {
	if ( x == "Canada" ) {
		document.getElementById("province").style.display = "block";
		document.getElementById("state").style.display = "none";
		document.getElementById("australianstate").style.display = "none";
		document.getElementById("stateinput").style.display = "none";
	}
	else if ( x == "United States" ) {
		document.getElementById("state").style.display = "block";
		document.getElementById("province").style.display = "none";
		document.getElementById("australianstate").style.display = "none";
		document.getElementById("stateinput").style.display = "none";
	}
	else if ( x == "Australia" ) {
		document.getElementById("australianstate").style.display = "block";
		document.getElementById("province").style.display = "none";
		document.getElementById("state").style.display = "none";
		document.getElementById("stateinput").style.display = "none";
	}
	else {
		document.getElementById("stateinput").style.display = "block";
		document.getElementById("australianstate").style.display = "none";
		document.getElementById("province").style.display = "none";
		document.getElementById("state").style.display = "none";
		document.forms["shippingsubmit"].sstateinput.value = '';
	}
}

function roundNumber(num) {
	var result = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
	return result;
}
function updatePrice(x) 
{
	var prices = new Array();
	prices[1] = 29;
	prices[2] = 68;
	prices[3] = 160;
	var thisprice = prices[x]+'.00';
	if (DOM) {
		var pricespan = document.getElementById("pricespan");
		pricespan.innerHTML =  thisprice;
	}
		else if(IE) {
			document.all["pricespan"].innerHTML = thisprice;
	}
}