function addListing() {
	document.getElementById('addListing').style.display = "block";
	return true;
}
function addListingCancel() {
	var doCancel = confirm("Are you sure?");
	if (doCancel) {
		document.getElementById('addListing').style.display = "none";
		return true;
	}
	return false;
}
function itemMouseOver(item, nElements) {
	for (i=1; i<=nElements; i++) {
		//document.getElementById("t"+i+item).style.backgroundColor = "greenyellow";
		//document.getElementById("t"+i+item).style.backgroundColor = "aliceblue";
		//document.getElementById("t"+i+item).style.backgroundColor = "silver";
		//document.getElementById("t"+i+item).style.backgroundColor = "gainsboro";
		document.getElementById("t"+i+item).style.backgroundColor = "#eee";
	}
	return true;
}
function itemMouseOut(item, nElements) {
	for (i=1; i<=nElements; i++) {
		document.getElementById("t"+i+item).style.backgroundColor = "";
	}
	return true;
}
function onClickCollapseExpand(item) {
	if (document.getElementById(item).style.display != "none") {
		createCookie("uiPref"+item,'Y',365*5);
		document.getElementById(item).style.display = "none";
		document.getElementById("o1"+item).innerHTML = '<img src="/img/plus.png"/>';
	}
	else {
		createCookie("uiPref"+item,'N',365*5);
		document.getElementById(item).style.display = "block";
		document.getElementById("o1"+item).innerHTML = '<img src="/img/minus.png"/>';
	}
	return true;
}

function buyListing(item) {
	var answer = confirm("Are you sure you want to buy this?\n\nAnswering yes will provide the seller with your email so they can arrange the sale.");
	if (answer) {
		document.getElementById('OfferFormArea').innerHTML = "<form action='/offer/"+item+"' method='POST' id='buyListingForm'><input type='hidden' name='typeOffer' value='buy'></form>";
		document.getElementById('buyListingForm').submit();
	}
	else return false;
}
function offerListing(item) {
  document.getElementById("formListing-"+item).innerHTML = "<hr/><form action='/offer/"+item+"' method='POST' id='formOffer-"+item+"' onSubmit='offerListingSubmit("+item+")'><input type='hidden' name='typeOffer' value='offer'>Offer price: <input type='text' name='priceOffer'><br/><input type='submit' value='Make offer'></form>";
}
function offerListingSubmit(item) {
	var answer = confirm("Are you sure you want to buy this?\n\nAnswering yes will provide the seller with your email so they can arrange the sale.");
	if (answer) {
		document.getElementById('formOffer-'+item).submit();
	}
	else return false;
}
function sellNow(item) {
	weSuck("sell " + item);
}
function weSuck(debugText) {
	alert("Sorry, we haven't finished building this feature. Come back again soon!\n\ndebugText:\n" + debugText);
}

//
// Cookie functions
//

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
