function switchTabs(button,container) {

		document.getElementById('listings_tab_events').className = 'unselected';
		document.getElementById('listings_tab_restaurants').className = 'unselected';
		document.getElementById('listings_tab_movies').className = 'unselected';

		document.getElementById('thescene_events').style.display = 'none';
		document.getElementById('thescene_restaurants').style.display = 'none';
		document.getElementById('thescene_movies').style.display = 'none';

		document.getElementById(button).className = 'selected';
		document.getElementById(container).style.display = 'inline';
		document.getElementById(button).blur();
		document.getElementById(container).blur();
}

function ratingOverlay(which,what) {
		if(what=='show'){
			document.getElementById(which).style.display = 'block';
		}
		else
		{
			document.getElementById(which).style.display = 'none';
		}

}

var thisID;

function rateMe(whichID, whichType, whichRating)
{
//	alert("ID: " + whichID + "\nType: " + whichType + "\nRating: " + whichRating);

	SetCookie(whichID, whichRating, 9999);
	thisID = whichID;
	var url = "/v03_includes/listings_rate.php?id=" + whichID + "&type=" + whichType + "&rating=" + whichRating;
	rate_makeRequest(url);
}

var rate_http_request = false;

function rate_makeRequest(url)
{
	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		rate_http_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{ // IE
		rate_http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	rate_http_request.onreadystatechange = rate_alertContents;
	rate_http_request.open('GET', url, true);
	rate_http_request.send(null);
}

function rate_alertContents()
{

	if (rate_http_request.readyState == 4)
	{
		if (rate_http_request.status == 200)
		{
			alreadyRated();
		}
		else
		{
			alert('There is a problem with the rating system.  Please try again later, thanks.');
		}
	}
}

function alreadyRated()
{
	ratingOverlay('listing_rating_overlay', 'hide');
	var cookieRating = ReadCookie(thisID);
/*
	alert(thisID);
	alert(ReadCookie(thisID));
*/
	document.getElementById('ratingBox').innerHTML = "<img border=0 src=\"/v03_images/redarrow-greybg.jpg\" class=\"redarrow\"> Your Rating: " + cookieRating + "/10";

}

function SetCookie(cookieName,cookieValue,nDays)
{
//	alert("setting cookie " + cookieName);
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
	+ ";expires="+expire.toGMTString();
}

function ReadCookie(cookieName)
{
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return "";
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=548,height=275');");
}

function toggleRemainingDates(howMany) {

	if(document.getElementById('remainingdates').style.display == 'block')
	{	
		document.getElementById('remainingdates').style.display = 'none';
		document.getElementById('toggleLink').innerHTML = '+ Show All ' + howMany + ' Dates';
	}
	else
	{
		document.getElementById('remainingdates').style.display = 'block';
		document.getElementById('toggleLink').innerHTML = '- Hide...';
	}
}

function checkSwitch(whichTab)
{

	switch (whichTab)
	{
		case "events" :
			switchTabs('listings_tab_events','thescene_events');
			break;
		case "restaurants" :
			switchTabs('listings_tab_restaurants','thescene_restaurants');
			break;
		case "movies" :
			switchTabs('listings_tab_movies','thescene_movies');
			break;
		default :
			break;
	}

}