function setDetails(linkText,linkClass) {
	var rowList,thisRow,previousRow,toggleLink,detailGroup,i,t;
	var tableList = document.getElementsByTagName('TABLE');
	for(t=0;t<tableList.length;t++) {
		thisTable = tableList.item(t);
		if(thisTable.className.search(/\boptions\b/)!=-1) {
			rowList = thisTable.getElementsByTagName('TR');
			for(i=0;i<rowList.length;i++) {
				thisRow = rowList.item(i);
				if(i+1<rowList.length) {
					nextRow = rowList.item(i+1);
					if(nextRow.className.search(/\bdetails\b/)!=-1) {
						toggleLink = document.createElement('A');
						toggleLink.href = "#";
						toggleLink.id = "cell"+t+i;
						toggleLink.onclick = showDetail;
						toggleLink.innerHTML = linkText;
						//toggleLink.innerHTML = toggleLink.id;
						
						detailGroup = new Array(toggleLink,nextRow);
						//nextRow.detailGroup = detailGroup;
						toggleLink.detailGroup = detailGroup;
						
						nextRow.className += ' closed';
						toggleLink.className = 'closed' + ((linkClass) ? " " + linkClass : "");
						//nextRow.onclick = showDetail;
						
						newCell = document.createElement('TD');
						newCell.appendChild(toggleLink);
						thisRow.appendChild(newCell);
						
						newCell = document.createElement('TD');
						nextRow.appendChild(newCell);
						
						i++; // skip details row
					} else {
						newCell = document.createElement('TD');
						thisRow.appendChild(newCell);
					}
				} else {
					newCell = document.createElement('TD');
					thisRow.appendChild(newCell);
				}
			}
		}
	}
}
function showDetail() {
	for(i in this.detailGroup) {
		detailNode = this.detailGroup[i];
		if(detailNode.className.search(/\bclosed\b/)==-1) {
			detailNode.className += " closed";
		} else {
			detailNode.className = detailNode.className.replace(/\bclosed\b/g,'');
		}
	}
	return false;
}

function convertSubmit() {
    inputList = document.getElementsByTagName("INPUT");
    for (i = 0; i < inputList.length; i++) {
        thisInput = inputList.item(i);
        if (convertTo = thisInput.className.match(/(\w+)Submit/)) {
            newInput = document.createElement("INPUT");
            newInput.type = convertTo[1].toUpperCase();
            newInput.name = thisInput.name;
            newInput.value = thisInput.value;
            newInput.onclick = function () {this.form.submit();};
            thisInput.parentNode.replaceChild(newInput, thisInput);
        }
    }
}
function checkTOS(frm) {
	if(!frm.tosAgreement.checked) {
		alert('Please read and agree to the Terms of Service before proceeding.');
		return false;
	} else return true;
}
function requireTOS() {
	ctrlTOS = document.getElementById("tosAgreement");
	if(ctrlTOS && !ctrlTOS.checked) {
		alert('Please read and agree to the Terms of Service before proceeding.');
		return false;
	} else return true;
}
function populateShippingAddress(frm,state) {
	frm['shippingAddr1'].value = (state) ? frm['addr1'].value : '';
	frm['shippingAddr2'].value = (state) ? frm['addr2'].value : '';
	frm['shippingCity'].value = (state) ? frm['city'].value : '';
	frm['shippingState'].value = (state) ? frm['state'].value : '';
	frm['shippingZip'].value = (state) ? frm['zip'].value : '';
}
function standby() {
	divCart = document.getElementById('cart');
	if(divCart) divCart.className += ' processing';
}
function setVisibility(element) {
	if(toggleItem = document.getElementById(element)) {
		if (toggleItem.style.display == "none") {toggleItem.style.display = ""; }
		else {toggleItem.style.display = "none"; }
	}
	return false;
}
function chatWindow() {
	window.open(this.href,'_blank','resizable= no,width=535,height=475');
	return false;
}
function initChatWindow() {
	$("#chatbox a").click(chatWindow);
}

function fixCart(){	
	$('.controls').find('img[alt="Empty Cart"]').hide();
	$('.controls').find('input[alt="Proceed To Checkout"]').css('margin-left','25px');
	$('h4').parent('th[colspan="3"]').parent('tr').children('th').css({verticalAlign: 'middle',backgroundColor: '#A5D867'});
	$('.controls a').each( function (index) { if(index==0){this.style.verticalAlign = "top";}});
	$('.controls a').each( function (index) { if(index==0){this.innerHTML = "<span style='color: 00853F;padding-top:50px;'>Continue Shopping</span>";}});
}
$(initChatWindow);
if (window.location.href.indexOf('cartLanding') > 0){
	$(document).ready(fixCart);
} else if (window.location.href.indexOf('removeFeature') > 0){
	$(document).ready(fixCart);
}

