function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function toggle2(obj1,obj2) {
	var el_1 = document.getElementById(obj1);
	var el_2 = document.getElementById(obj2);
	if ( el_1.style.display != 'none' ) {
		el_1.style.display = 'none';
		el_2.style.display = '';
		//dateCount variable resets the placeholder to navigate date of Show Start Time menu
		if (obj1 == 'showStart' || obj2 == 'showStart') {dateCount=1};
	}
	else {
		el_1.style.display = '';
		el_2.style.display = 'none';
		//dateCount variable resets the placeholder to navigate date of Show Start Time menu
		if (obj1 == 'showStart' || obj2 == 'showStart') {dateCount=1};
	}
}


function toggle3(obj) {
	var el3 = obj;
	if ( el3 == 'hide' ) {
		setCookie("hideWelcome", "hideWelcome", "100", "", "", "");
		document.getElementById("instructions").innerHTML = '';
		document.getElementById("showWelcome").innerHTML = '<a href=\"javascript:toggle3(\'show\')\">[Show \'welcome\' panel]</a>';
	}
	else if ( el3 == 'show' ) {
		deleteCookie("hideWelcome", "", "")
		javascript:ajaxpage('instruct.php','instructions');
		document.getElementById("showWelcome").innerHTML = '<a href=\"javascript:toggle3(\'hide\')\">[Hide \'welcome\' panel]</a>';
	}
}

function startTimes(numSeconds) {
	var dateID = document.getElementById("dateID").innerHTML;
	ajaxpage('gridInsert.php?dateID=' + dateID + '&time=' + numSeconds, 'nowPlayContainer');
}

function browse(numSeconds) {
	var dateID = document.getElementById("dateID").innerHTML;
	ajaxpage('nowplay.php?dateID=' + dateID + '&time=' + numSeconds, 'nowPlayContainer');
}

function checkLogFav() {
if (document.getElementById("username")) {
	alert("You must be logged in to show favorites!");
	} else {
		toggle2('showFav','showAll');
		showFavs();
		}
}

function showFavs() {
	setCookie("showFavs", "showFavs", "100", "", "", "");
	ajaxpage('nowplay.php', 'nowPlayContainer');
}

function showAll() {
	deleteCookie("showFavs", "", "")
	ajaxpage('nowplay.php', 'nowPlayContainer');
}


/* ************************ */
/*  Functions for the grid
/* ************************ */

function checkLogFav2() {
if (document.getElementById("username")) {
	alert("You must be logged in to show favorites!");
	} else {
		toggle2('showFav','showAll');
		showFavs2();
		}
}

function showFavs2() {
	setCookie("showFavs", "showFavs", "100", "", "", "");
	ajaxpage('gridInsert.php', 'gridContainer');
}

function showAll2() {
	deleteCookie("showFavs", "", "")
	ajaxpage('gridInsert.php', 'gridContainer');
}

function startTimes2(numSeconds) {
	var dateID = document.getElementById("dateID").innerHTML;
	ajaxpage('gridInsert.php?dateBrowse=' + dateID + '&time=' + numSeconds, 'gridContainer');
}

function browse2(numSeconds) {
	var dateBrowse = document.getElementById("dateBrowse").innerHTML;
	ajaxpage('gridInsert.php?dateBrowse=' + dateBrowse + '&time=' + numSeconds, 'gridContainer');
}


//////////////////////////////////////////////////////
// This function controls cookies using javascript  //
//////////////////////////////////////////////////////

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) +
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}