// global vars
var width = screen.availWidth - 10
var height = screen.availHeight - 120
var activeSection = 'record';
var summaries = new Array;

function mOver(src,clrOver){ 
	if (!src.contains(event.fromElement)){ 
		src.style.cursor = 'auto'; src.bgColor = clrOver; 
	} 
} 
function mOverBG(src,clrOver){ 
	if (!src.contains(event.fromElement)){ 
		src.style.cursor = 'auto'; src.background = clrOver; 
	} 
} 
function mOut(src,clrIn){ 
	if (!src.contains(event.toElement)){ 
		src.style.cursor = 'default'; 
		src.bgColor = clrIn; 
	} 
} 
function mOutBG(src,clrIn){ 
	if (!src.contains(event.toElement)){ 
		src.style.cursor = 'default'; 
		src.background = clrIn; 
	} 
} 
function testmovie_doFSCommand(command, args) { 
	if (command == "open_win") { 
		window.open(args,'_blank','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizeable=0,height=500,width=400,top=0,left=0');
	}
}

function mClk(src, theURL){ 
	if(event.srcElement.tagName=='TD'){ 
		window.open(theURL, '_self', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=0,left=0'); 
	} 
} 

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function NewWin (selObj, theURL) {
	if(theURL != ''){
	  window.open(theURL, '_blank', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=0,left=0');
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validate_login(theForm) { // Initialize function

  if (theForm.username.value == ""){ // Check to see if field is empty
    alert("Please enter a username");
    theForm.username.focus();
    return (false);
  }
  if (theForm.username.value.length > 12){ // Check field length
    alert("Please enter at most 15 characters in the \"Username\" field");
    theForm.username.focus();
    return (false);
  }
  if (theForm.password.value == ""){ // Check to see if field is empty
    alert("Please enter a password");
    theForm.password.focus();
    return (false);
  }
  if (theForm.password.value.length > 8){ // Check field length
    alert("Please enter at most 15 characters in the \"Password\" field");
    theForm.password.focus();
    return (false);
  }
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function cAction(action){
	return confirm(action);
}

//
// functions by eric thunberg aka lp.kane
//

function openwin(url,width,height,mode) 
{
	var full, mode, scroll, pos, posy, aheight, awidth;

	if( mode == 'fullscreen' )
	{
		width = screen.width;
		height = screen.height;
		width = 100;
		height = 100;
		posx = 0;
		posy = 0;
		scroll = 0;
		full = 1;
	}
	else
	{
		full = 0;
		aheight = screen.height - 100;
		awidth = screen.width - 12;

		if( ( height > aheight ) && ( width > awidth ) )
		{
			height = aheight;
			width = awidth;
			posy = 0;
			posx = 0;
			scroll = 1;
		}
		else if( height > aheight )
		{
			height = aheight;
			width += 16;
			posx = ( awidth / 2 ) - ( width / 2 );
			posy = 0;
			scroll = 1;
		}
		else if( width > awidth )
		{
			width = awidth;
			height += 20;
			posy = ( aheight / 2 ) - ( height / 2 );
			posx = 0;
			scroll = 1;
		}
		else
		{
			scroll = 0;
			posx = ( awidth / 2 ) - ( width / 2 );
			posy = ( aheight / 2 ) - ( height / 2 );
		}
	}

	window.open(url,'1','fullscreen='+full+',width='+width+',height='+height+',resizable=1,scrollbars='+scroll+',directories=0,status=0,menu=0,copyhistory=0,left='+posx+',top='+posy); 
};

function tabSwap(section)
{
	var i, sList = new Array();

	sList[0] = 'record';
	sList[1] = 'schedule';
	sList[2] = 'recent';

	for (i = 0; i < sList.length; i++)
	{
		if(sList[i] == section)
		{
			activeSection = section;
			document.getElementById('tab-' + sList[i]).src = 'images/ui_button_' + sList[i] + '_on.gif';
			document.getElementById('body-' + sList[i]).style.display = 'block';
		}
		else
		{
			document.getElementById('tab-' + sList[i]).src = 'images/ui_button_' + sList[i] + '_off.gif';
			document.getElementById('body-' + sList[i]).style.display = 'none';
		}
	}
}

function tabHoverOn(section)
{
	if(section != activeSection)
	{
		document.getElementById('tab-' + section).src = 'images/ui_button_' + section + '_over.gif';
	}
}

function tabHoverOff(section)
{
	if(section != activeSection)
	{
		document.getElementById('tab-' + section).src = 'images/ui_button_' + section + '_off.gif';
	}
}

function contentToggle(section, obj, setcookie)
{
	var obj, expdate = new Date();
	expdate.setTime(expdate.getTime() + 15768000);

	if(obj.id == 'on')
	{
		document.getElementById(section).style.display = 'none';
		obj.id = 'off';

		if(setcookie)
		{
			document.cookie = section + "=" + 0 + "; expires=" + expdate.toGMTString();
		}
	}
	else
	{
		document.getElementById(section).style.display = 'block';
		obj.id = 'on';

		if(setcookie)
		{
			document.cookie = section + "=" + 1 + "; expires=" + expdate.toGMTString();
		}
	}
}

function contentSwitch(hide, hide2, display)
{
	var display, expdate = new Date();
	expdate.setTime(expdate.getTime() + 15768000);
	
	document.getElementById('tab-' + hide).src = 'images/ui_button_' + hide.toLowerCase(hide) + '_off.gif';
	document.getElementById("body-" + hide).style.display = 'none';
	document.getElementById('tab-' + hide2).src = 'images/ui_button_' + hide2.toLowerCase(hide2) + '_off.gif';
	document.getElementById("body-" + hide2).style.display = 'none';
	document.getElementById('tab-' + display).src = 'images/ui_button_' + display.toLowerCase(display) + '_on.gif';
	document.getElementById("body-" + display).style.display = 'block';

	document.cookie = "nav-members-div=" + display + "; expires=" + expdate.toGMTString();
}

function headerCookie()
{
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + 15768000);

	document.cookie = "flashheader=" + 1 + ";";
}

function openwin(url,width,height) 
{
	var posx, posy;

	posx = ( screen.width / 2 ) - ( width / 2 );
	posy = ( ( screen.height - 100 ) / 2 ) - ( height / 2 );

	window.open(url,'popup','width='+width+',height='+height+',resizable=0,scrollbars=1,directories=0,status=0,menubar=0,left='+posx+',top='+posy+''); 
}

function cleardropdowns(exclude)
{
	var count = 0;

	for(i = 0; i < document.form1.elements.length; i++)
	{
		if(document.form1.elements[i].type == "select-one")
		{
			if(count != exclude)
			{
				document.form1.elements[i].options[0].selected=true;
			}
			count++;
		}
	}
}

function loyaltyPoints(iPoints,bPoints,lMinutes)
{
	if(!document.getElementById('points-button').disabled)
	{
		document.getElementById('points-button').disabled = true;
	}
	else
	{
		if((iPoints + bPoints) >= lMinutes)
		{
			document.getElementById('points-button').disabled = false;
		}
	}
}

function rowHover(row)
{
	row.className = row.className + " " + row.className + "hover";
}

function rowRestore(row)
{
	array = new Array();
	array = row.className.split(" ");
	row.className = array[0];
}

function highlightSortedCols(cclass)
{
	array = new Array();

	array = getElementsByClassName(cclass);

	for(i = 0; i < array.length; i++)
	{
		array[i].id = "sorted";
	}
}

function tabSync(tabSet, tab)
{
	elList = document.getElementsByTagName('A');
	for (i = 0; i < elList.length; i++)
	{
		if(elList[i].id == tabSet)
		{
			if(elList[i].title == tab.title)
			{
				elList[i].className = "tab activeTab";
				document.getElementById(elList[i].title).style.display = 'block';
			}
			else
			{
				elList[i].className = "tab";
				document.getElementById(elList[i].title).style.display = 'none';
			}
		}
	}

	return false;
}

function getElementsByClassName(class_name)
{
  var all_obj,ret_obj=new Array(),j=0;
  if(document.all)all_obj=document.all;
  else if(document.getElementsByTagName && !document.all)all_obj=document.getElementsByTagName("*");
  for(i=0;i<all_obj.length;i++)
  {
    if(all_obj[i].className==class_name)
    {
      ret_obj[j]=all_obj[i];
      j++;
    }
  }
  return ret_obj;
}

var adRotatorCurrIndex;
function changeImage()
{
	if(document.getElementById('proshop-specials-img'))
	{
		imageDir = '../ads/';
		totalImages = adImagesSrc.length;
		randIndex = Math.floor(Math.random() * totalImages);
		
		while(randIndex == adRotatorCurrIndex)
		{
			randIndex = Math.floor(Math.random() * totalImages);
		}
		adRotatorCurrIndex = randIndex;
		document.getElementById('proshop-specials-img').src = imageDir + adImagesSrc[randIndex];
		document.getElementById('proshop-specials-a').href = adImagesHref[randIndex];
		setTimeout("changeImage();", 10000);
	}
}

function googleSearch(form)
{
	if(document.forms[0].elements[12].selectedIndex == 0 || document.forms[0].elements[12].selectedIndex == 1)
	{
		document.forms[0].action = "http://www.google.com/custom";
		document.forms[0].target = "_top";
		document.forms[0].elements[1].value = form.elements[11].value;

		if(document.forms[0].elements[12].selectedIndex == 1)
		{
			document.forms[0].elements[0].value = "esportsea.com";
		}
	}
	else
	{
		document.forms[0].action = "index.php";
		document.forms[0].target = "";
		document.forms[0].elements[2].value = '';
		document.forms[0].elements[3].value = '';
		document.forms[0].elements[4].value = '';
		document.forms[0].elements[5].value = '';
		document.forms[0].elements[6].value = '';
		document.forms[0].elements[7].value = '';
		document.forms[0].elements[8].value = '';
	}

	return false;
}

function postLink (ele) {
	var commentQuote = ele.parentNode.parentNode;
	var elements = commentQuote.getElementsByTagName('*');
	for (var i = 0; i < elements.length; i++) {
		if (elements[i].className == 'comment-quote-ellipses') {
			elements[i].style.display = (ele.innerHTML == 'Read More') ? 'none' : 'inline';
		} else if (elements[i].className == 'comment-quote-hidden') {
			elements[i].style.display = (ele.innerHTML == 'Read More') ? 'inline' : 'none';
		}
	}
	ele.innerHTML = (ele.innerHTML == 'Read More') ? 'Hide Text' : 'Read More';
}

function getPos(el) {
	if (document.getBoxObjectFor) {
		var bo = document.getBoxObjectFor(el);
		el.x = bo.x;
		el.w = bo.width;
		el.y = bo.y;
		el.h = bo.height;
	} else if (el.getBoundingClientRect) {
		var rect = el.getBoundingClientRect();
		el.x = rect.left;
		el.w = rect.right - rect.left;
		el.y = rect.top + document.documentElement.scrollTop;
		el.h = rect.bottom - rect.top;
	}

	return el;
}

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 toArray(obj) {
	if (!isArray(obj)) {
		var tmp = obj;
		obj = new Array;
		obj[0] = tmp;
	}
	return obj;
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isFunction(a) {
    return typeof a == 'function';
}

function showSummary(el) {
	var id = el.getAttribute('dataField');
	summaries[id] = el;
	setTimeout("doShowSummary('" + id + "');", 500);
}

function doShowSummary(id) {
	if (summaries[id]) {
		var el = summaries[id];
		var pos = getPos(el);
		var summary = el.getElementsByTagName('div')[0];
		summary.style.top = (pos.y + 16) + 'px';
		summary.style.display = 'block';
	}
}

function hideSummary(el) {
	var id = el.getAttribute('dataField');
	summaries[id] = false;
	el.getElementsByTagName('div')[0].style.display = 'none';
}

function showFilter(el) {
	var pos = getPos(el);
	var filter = document.getElementById('filter');

	var filterCookie = readCookie('filter');
	if (filterCookie) {
		var contentTypes = new Array;
		contentTypes = filterCookie.split(',');
	}
	var list = filter.getElementsByTagName('input');
	for (i = 0; i < list.length; i++) {
		if (filterCookie) {
			for (j = 0; j < contentTypes.length; j++) {
				if (contentTypes[j] == list[i].value) {
					list[i].checked = true;
				}
			}
		} else {
			list[i].checked = true;
		}
	}
	filter.style.top = (pos.y + 14) + 'px';
	filter.style.left = (pos.x - 5) + 'px';
	filter.style.display = 'block';
}

function hideFilter(el, evt) {
	if (!el.contains) {
		HTMLElement.prototype.contains = function(node) {
			if (node == null)
				return false;
			if (node == this)
				return true;
			else
				return this.contains(node.parentNode);
		}
	}
	if (!evt || !el.contains(evt.relatedTarget || evt.toElement)) {
		el.style.display = 'none';
		var list = el.getElementsByTagName('input');
		var contentTypes = new Array;
		for (i = 0; i < list.length; i++) {
			if (list[i].checked) {
				contentTypes.push(list[i].value);
			}
		}
		var expdate = new Date();
		expdate.setTime(expdate.getTime() + 15768000);
		document.cookie = "filter=" + contentTypes.toString() + "; expires=" + expdate.toGMTString();
		getDiscussion(false);
	}
}

function redrawFixedHeight(element) {
	element.style.height = '1px';
	element.style.height = 'auto';
}

function showEditGraph(el) {
	var pos = new Object;
	if (document.getBoxObjectFor) {
		var bo = document.getBoxObjectFor(el);
		pos.x = bo.x;
		pos.y = bo.y;
	} else if (el.getBoundingClientRect) {
		var rect = el.getBoundingClientRect();
		pos.x = rect.left;
		pos.y = rect.top + document.documentElement.scrollTop;
	}

	el.style.filter = 'alpha(opacity=50)';
	el.style.MozOpacity = '.50';
	el2 = document.getElementById('editGraph');
	el2.style.top = pos.y + 22 + 'px';
	el2.style.left = pos.x + 10 + 'px';
	el2.style.display = 'block';
}

function doEditGraph(el) {
	el2 = document.getElementById('editGraph');
	el3 = document.getElementById('displayGraph');
	el3.src = '/global/dynamic_image.php?type=stats&alias=' + el.elements['alias'].value + '&graph=' + el.elements['graph'].value + '&compare=' + el.elements['compare'].value;
	el2.style.display = 'none';
	el3.style.filter = '';
	el3.style.MozOpacity = '';
}

 function doClear(theText) 
{
     if (theText.value == theText.defaultValue)
 {
         theText.value = ""
     }
 }
