// See http://blog.stevenlevithan.com/archives/faster-trim-javascript
function trim (str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function swapDiv(closeMe, openMe) {
	closeDiv(closeMe);
	openDiv(openMe);
}

function openDiv(divName) {
	document.getElementById(divName).style.display = 'block';
	return false;
}

function closeDiv(divName) {
	document.getElementById(divName).style.display = 'none';
	return false;
}

var roundlist = false;
var count = 1;
var selectthing = '<div>' +
	'<select name="drink_%COUNT%">' +
		'<option value="0">--Select Drink--</option>' +
				'<option value="1">Guinness</option>' +
				'<option value="20">Smithwicks </option>' +
				'<option value="3">Budweiser</option>' +
				'<option value="4">Carlsberg</option>' +
				'<option value="5">Heineken</option>' +
				'<option value="6">Bulmers</option>' +
				'<option value="14">Gin</option>' +
				'<option value="13">Vodka</option>' +
				'<option value="12">Whiskey</option>' +
				'<option value="17">Mixer</option>' +
				'<option value="19">1/4 bottle of Wine</option>' +
			
	'</select>' +
	' <input type="text" name="number_of_drinks_%COUNT%" value="0" size="4" />' +
		'</div>';
		
function add_drink() {
	if (!roundlist) {
		roundlist = document.getElementById('roundlist');
	}
	
	if (count > 10) {
		alert('There is a limit of 10 drinks in a round');
		return;
	}
	count++;

	var divTag = document.createElement("div"); 
    divTag.id = "option_" + count;  

	divTag.innerHTML = selectthing.replace(/%COUNT%/g, count);	

	roundlist.appendChild(divTag);
}

function rateBar(barid, ratevalue)
{	
	$.ajax({
		   type: "POST",
		   url: "/ajax/rateBar",
		   datatype:"html",
		   data: "bar_id=" + barid + "&rating=" + ratevalue,
		   success: function(msg){
		     $("#rating").html(msg);
		   }
		 });
}

function rateBarToilet(barid, ratevalue)
{	
	$.ajax({
		   type: "POST",
		   url: "/ajax/rateBarToilet",
		   datatype:"html",
		   data:{bar_id: barid, rating: ratevalue},
		   success: function(msg){
		     $("#toilet_rating").html(msg);
		   }
		 });
}



function distanceSearch(lat, lng, distance) {
	window.location.href = "/search/index/lat/" + lat + "/lng/" + lng + "/distance/" + distance;	
}

function sendcrawl() {
	var params = $('crawlemail').serialize(true);

	var myAjax = new Ajax.Updater('emailformdiv', '/ajax/emailcrawl', {
		method: 'post',
		parameters: params
	});

}

function imageformswap() {
	$('#showimageform').toggle();
	$('#closeimageform').toggle();
	$('#imagesubmit').toggle();
}
