
/***	General Functions	***/
function addToList(listString, index) {
	if (listString == "")
	{
		listString += index;
	} else {
		listString += "," + index;
	}

	return listString;
}

function removeFromList(listString, index) {

	var listArray = listString.split(",");
	var newListString = '';
	for (i = 0 ; i < listArray.length ; i++ )
	{
		if (listArray[i] != index)
		{
			if (i == (listArray.length-1))	newListString += listArray[i];
			else							newListString += listArray[i] + ",";
		}
	}

	if (newListString.charAt(newListString.length-1) == ",")
	{
		newListString = newListString.substring(0, newListString.length-1);
	}

	return newListString;
}

function deleteRow(tableId, cell) 
{
	var tbl = document.getElementById(tableId);
	var pnode = getRowObj(cell);
	tbl.deleteRow(pnode.rowIndex);
}

function getRowObj(cell)
{
	var pnode = cell.parentNode;
	while (pnode.tagName != 'TR')
	{
		pnode = pnode.parentNode;
	}
	return pnode;
}

function clearTextBox(textBox)
{
	if (textBox.className != "changed")
	{	
		textBox.value = '';
		textBox.className = 'changed';
		textBox.style.color = 'black';
	}
}

function getTodayDatetime()
{
	var currentTime = new Date();
	var month	= currentTime.getMonth() + 1;
	var day		= currentTime.getDate();
	var year	= currentTime.getFullYear();
	var hrs		= currentTime.getHours();
	var mins	= currentTime.getMinutes();
	var secs	= currentTime.getSeconds();
	
	return (year+'-'+month+'-'+day+' '+hrs+':'+mins+':'+secs);
}

function confirmDelete(text, link)
{
  var agree = confirm(text);
  if (agree) location=link;
  else return false;
}

/* Cookie Functions */
function setFHLCookie() {
	var x = document.getElementById('select-league-drop').value;	
	if (x == "Select your league...")
		eraseCookie('fhlDivisionCookie');
	else {
		createCookie('fhlDivisionCookie',x,7);		
	}
	document.location.reload();
}

function readIt(name) {
	alert('The value of the cookie is ' + Cookies[name]);
}

function eraseIt(name) {
	Cookies.erase(name);
	alert('Cookie erased');
}

function init() {
	for (var i=1;i<3;i++) {
		var x = Cookies['ppkcookie' + i];
		if (x) alert('Cookie ppkcookie' + i + '\nthat you set on a previous visit, is still active.\nIts value is ' + x);
	}
}

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 eraseCookie(name) {
	createCookie(name,"",-1);
}


