function fTOpen(page) {
  w = 580;
  h = 750;
  x = (screen.availWidth/2) - (w/2);
  y = (screen.availHeight/2) - (h/2);

  OpenWin = window.open(page, "pop", "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height="+h+",width="+w+",left="+x+",top="+y);
  if (document.images) {OpenWin.focus();}
}
function fWOpen(page) {
  w = 725;
  h = 580;
  x = (screen.availWidth/2) - (w/2);
  y = (screen.availHeight/2) - (h/2);

  OpenWin = window.open(page, "pop", "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height="+h+",width="+w+",left="+x+",top="+y);
  if (document.images) {OpenWin.focus();}
}
function fTeamOpen(page) {
  w = 750;
  h = 600;
  x = (screen.availWidth/2) - (w/2);
  y = (screen.availHeight/2) - (h/2);

  OpenWin = window.open(page, "pop", "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height="+h+",width="+w+",left="+x+",top="+y);
  if (document.images) {OpenWin.focus();}
}
function fPrintWinOpen(page) {
  OpenWin = window.open(page, "pop", "status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes,height=720,width=870,screenX=0,screenY=0");
  if (document.images) {OpenWin.focus();}
}

function fOpenWin(page,p_wintype,p_width,p_height) {
  if ((p_wintype=="")||(p_wintype==undefined)) {
       s_wintype="new";
  }else{
       s_wintype=p_wintype;
  }
  if ((p_width=="")||(p_width==undefined)) {
       s_width=600;
  }else{
       s_width=p_width;
  }
  if ((p_height=="")||(p_height==undefined)) {
       s_height=700;
  }else{
       s_height=p_height;
  }

  x = (screen.availWidth/2) - (s_width/2);
  y = (screen.availHeight/2) - (s_height/2);

  OpenWin = window.open(page, s_wintype, "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width="+s_width+",height="+s_height+",left="+x+",top="+y);
  if (document.images) {OpenWin.focus();}
}
function showScores(el) {
  whichEl = eval(el + "_Scores");

  whichEl.style.visibility="visible";
  whichEl.style.position="absolute";
}
function hideScores(el) {
  whichEl = eval(el + "_Scores");

  whichEl.style.visibility="hidden";
  whichEl.style.position="absolute";
}

function showSection(el,p_section) {
  whichEl = eval(el + "_" + p_section);

  whichEl.style.visibility="visible";
  whichEl.style.position="absolute";
}
function hideSection(el,p_section) {
  whichEl = eval(el + "_" + p_section);

  whichEl.style.visibility="hidden";
  whichEl.style.position="absolute";
}
function convertQuestion(p_question) {
  if(p_question==1) {
     document.write("Where do/did you go to school?");
  }else if(p_question==2) {
     document.write("What is the name of your favorite pet?");
  }else if(p_question==3) {
     document.write("Who is your favorite paintball player?");
  }else if(p_question==4) {
     document.write("What do you want to be when you grow up?");
  }
}

function fCheckLength(p_field,p_value,p_length) {
  if (p_value.length > p_length) {
      lcl_value=p_value.substring(0,p_length);
      p_field.value=lcl_value;
      return false;
  }
}

///////////////////////////////////////////////////////////////////////////////
// Table Sorter: used to re-order rows by clicking on a column
///////////////////////////////////////////////////////////////////////////////
var table=function(){
	function sorter(n){
		this.n=n; this.t; this.b; this.r; this.d; this.p; this.w; this.a=[]; this.l=0
	}
	sorter.prototype.init=function(t,f){
		this.t=document.getElementById(t);
		this.b=this.t.getElementsByTagName('tbody')[0];
		this.r=this.b.rows; var l=this.r.length;
		for(var i=0;i<l;i++){
			if(i==0){
				var c=this.r[i].cells; this.w=c.length;
				for(var x=0;x<this.w;x++){
					if(c[x].className!='nosort'){
						c[x].className='head';
						c[x].onclick=new Function(this.n+'.work(this.cellIndex)')
					}
				}
			}else{
				this.a[i-1]={}; this.l++;
			}
		}
		if(f!=null){
			var a=new Function(this.n+'.work('+f+')'); a()
		}
	}
	sorter.prototype.work=function(y){
		this.b=this.t.getElementsByTagName('tbody')[0]; this.r=this.b.rows;
		var x=this.r[0].cells[y],i;
		for(i=0;i<this.l;i++){
			this.a[i].o=i+1; var v=this.r[i+1].cells[y].firstChild;
			this.a[i].value=(v!=null)?v.nodeValue:''
		}
		for(i=0;i<this.w;i++){
			var c=this.r[0].cells[i];
			if(c.className!='nosort'){c.className='head'}
		}
		if(this.p==y){
			this.a.reverse(); x.className=(this.d)?'asc':'desc';
			this.d=(this.d)?false:true
		}else{
			this.p=y; this.a.sort(compare); x.className='asc'; this.d=false
		}
		var n=document.createElement('tbody');
		n.appendChild(this.r[0]);
		for(i=0;i<this.l;i++){
			var r=this.r[this.a[i].o-1].cloneNode(true);
			n.appendChild(r); r.className=(i%2==0)?'even':'odd'
		}
		this.t.replaceChild(n,this.b)
	}
	function compare(f,c){
		f=f.value,c=c.value;
		var i=parseFloat(f.replace(/(\$|\,)/g,'')),n=parseFloat(c.replace(/(\$|\,)/g,''));
		if(!isNaN(i)&&!isNaN(n)){f=i,c=n}
		return (f>c?1:(f<c?-1:0))
	}
	return{sorter:sorter}
}();

///////////////////////////////////////////////////////////////////////////////
// Directions Page: Google Map
///////////////////////////////////////////////////////////////////////////////
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function initialize() {
      if (GBrowserIsCompatible()) {      
        map  = new GMap2(document.getElementById("map_canvas"), { size: new GSize(760,400) } );

        map.removeMapType(G_HYBRID_MAP);
        map.setCenter(new GLatLng(0,0), 11);
        map.addControl(new GLargeMapControl());
 
        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);

        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

//        setDirections("San Francisco", "Mountain View", "en_US");
        document.getElementById("view_directions").style.display="none";
      }
    }
    
    //function setDirections(fromAddress, toAddress, locale) {
    function setDirections() {
      document.getElementById("view_directions").style.display="block";
      lcl_fromAddress = document.getElementById('fromAddress').value;
      lcl_toAddress   = document.getElementById('toAddress').value;
      lcl_locale      = document.getElementById('locale').value;

      if(lcl_fromAddress == "") {
         alert("Please enter a 'From Address'");
         return false;
      }

      gdir.load("from: " + lcl_fromAddress + " to: " + lcl_toAddress,{ "locale": lcl_locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
//	   else alert("An unknown error occurred.");
	   else alert("Please enter an address.");
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}

///////////////////////////////////////////////////////////////////////////////
// No longer used.  Was used to expand/collapse the side menubar
///////////////////////////////////////////////////////////////////////////////
var lcl_field_length;
var lcl_original_value;

  NS4 = (document.layers) ? 1 : 0;
  IE4 = (document.all) ? 1 : 0;
  ver4 = (NS4 || IE4) ? 1 : 0;
  if (ver4) {
      with (document) {
          write("<STYLE TYPE='text/css'>");
          if (NS4) {
              write(".parent   {position:absolute; visibility:visible}");
              write(".child_sb {position:absolute; visibility:visible}");
              write(".child_ds {position:absolute; visibility:visible}");
              write(".regular  {position:absolute; visibility:visible}");
          }else{
              write(".child_sb {display:none}");
              write(".child_ds {display:none}");
              write("td.menu{background:#EFEFEF}");
              write("table.menu");
              write("{");
              write("font-size:100%;");
              write("position:absolute;");
              write("visibility:hidden;");
              write("}");
              write("td.help{background:#FFEFBD}");
              write("p.lineHeight{line-height:2cm}");
              write("table.help");
              write("{");
              write("font-size:100%;");
              write("position:absolute;");
              write("width:140;");
              write("left:862;");
              write("top:65;");
              write("visibility:hidden;");
              write("}");
        }
    write("</STYLE>");
    }
}
// These variables and functions are what is used to access Cookies
var expDays = 1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var ShowCount = 0;
var SwapColour;
sbExpanded = false;
dsExpanded = false;

// expands/collapses and repositions side menubar sections

function getIndex(el) {
    ind = 0;
    for (i=0; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.id == el) {
ind = i;
break;
        }
    }
    return ind;
}
function arrange() {
    nextY = document.layers[firstInd].pageY + document.layers[firstInd].document.height;
    for (i=firstInd+1; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.visibility != "hide") {
            whichEl.pageY = nextY;
            nextY += whichEl.document.height;
        }
    }
}
function initIt(){
    if (!ver4) return;
    if (NS4) {
        for (i=0; i<document.layers.length; i++) {
             whichEl = document.layers[i];
             if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
        }
        arrange();
    }else{
        divColl = document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
             whichEl = divColl(i);
             if (whichEl.className == "child_sb") {
                 whichEl.style.display = "none";
             }else if(whichEl.className == "child_ds") {
                 whichEl.style.display = "none";
             }
        }
    }
}

// Expand/Collapse Individual Side Menubar

function expandIt(el,imType) {
    if (!ver4) return;
    if (IE4) {
        whichEl = eval(el + "_Child");
        if(imType!="OTHER") {
           whichIm = event.srcElement;
        }
        if (whichEl.style.display == "none") {
            whichEl.style.display = "block";
            if (imType == "DS") {
                whichIm.src = "../menubar/ds_collapse.jpg";
            }
//            if (el == "News") {
//                whichIm.src = "../menubar/news.gif";
//                SetCookie(el,'N');
//            }else if (el == "Events") {
//                whichIm.src = "../menubar/events.gif";
//                SetCookie(el,'N');
//            }else if (el == "Diehard") {
//                whichIm.src = "../menubar/diehard.gif";
//                SetCookie(el,'N');
//            }else if (el == "TeamInfo") {
//                whichIm.src = "../menubar/TeamInfo.gif";
//                SetCookie(el,'N');
//            }else if (el == "Other") {
//                whichIm.src = "../menubar/other.gif";
//                SetCookie(el,'N');
//            }
        }else{
            whichEl.style.display = "none";
            if (imType == "DS") {
                whichIm.src = "../menubar/ds_expand.jpg";
            }
//            if (el == "News") {
//                whichIm.src = "../menubar/news.gif";
//                SetCookie(el,'N');
//            }else if (el == "Events") {
//                whichIm.src = "../menubar/events.gif";
//                SetCookie(el,'N');
//            }else if (el == "Diehard") {
//                whichIm.src = "../menubar/diehard.gif";
//                SetCookie(el,'N');
//            }else if (el == "TeamInfo") {
//                whichIm.src = "../menubar/TeamInfo.gif";
//                SetCookie(el,'N');
//            }else if (el == "Other") {
//                whichIm.src = "../menubar/other.gif";
//                SetCookie(el,'N');
//            }
        }
    }else{
        whichEl = eval("document." + el + "_Child");
        whichIm = eval("document." + el + "Parent.document.images['imSB']");
        if (whichEl.visibility == "hide") {
            whichEl.visibility = "show";
            if (el == "News") {
                whichIm.src = "../menubar/news.gif";
            }else if (el == "Events") {
                whichIm.src = "../menubar/events.gif";
            }else if (el == "Diehard") {
                whichIm.src = "../menubar/diehard.gif";
            }else if (el == "TeamInfo") {
                whichIm.src = "../menubar/TeamInfo.gif";
            }else if (el == "Other") {
                whichIm.src = "../menubar/other.gif";
            }
        }else{
            whichEl.visibility = "hide";
            if (el == "News") {
                whichIm.src = "../menubar/news.gif";
            }else if (el == "Events") {
                whichIm.src = "../menubar/events.gif";
            }else if (el == "Diehard") {
                whichIm.src = "../menubar/diehard.gif";
            }else if (el == "TeamInfo") {
                whichIm.src = "../menubar/TeamInfo.gif";
            }else if (el == "Other") {
                whichIm.src = "../menubar/other.gif";
            }
        }
        arrange();
    }
}
function expandIt_onLoad(el,imType) {
  whichEl = eval(el + "_Child");
//  if (whichEl.style.display == "none") {
//      whichEl.style.display = "block";
//  }else{
//      whichEl.style.display = "none";
//  }

  divColl = document.all.tags("DIV");
  imColl = document.images.item("im" + imType);
  for (i=0; i<divColl.length; i++) {
       if (imType == "DS") {
           if (divColl(i).className == "child_ds") {
               if (divColl(i).id == whichEl.id) {
                  divColl(i).style.display = (dsExpanded) ? "none" : "block";
//                  a=(i-1)/2;
//                  for (j=0; j<imColl.length; j++) {
//                       if (j==a) {
//                           imColl(j).src = "../menubar/ds_collapse.jpg";
//                       }
//                  }
               }
           }
       }
  }


}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
      endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}
function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}
function DeleteItem(Count) {
  var name = ('MenuItem'+Count);
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie(name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function expandAll(imType) {
  divColl = document.all.tags("DIV");
  imColl = document.images.item("im" + imType);
  for (i=0; i<divColl.length; i++) {
       if (imType == "DS") {
           if (divColl(i).className == "child_ds") {
               divColl(i).style.display = (dsExpanded) ? "none" : "block";
               a=(i-1)/2;
               for (j=0; j<imColl.length; j++) {
                    if (j==a) {
                        imColl(j).src = "../menubar/ds_collapse.jpg";
                    }
               }

           }
       }
  }
}

function collapseAll(imType) {
  divColl = document.all.tags("DIV");
  imColl = document.images.item("im" + imType);
  for (i=0; i<divColl.length; i++) {
       if (imType == "DS") {
           if (divColl(i).className == "child_ds") {
               divColl(i).style.display = (dsExpanded) ? "block" : "none";
               a=(i-1)/2;
               for (j=0; j<imColl.length; j++) {
                    if (j==a) {
                        imColl(j).src = "../menubar/ds_expand.jpg";
                    }
               }

           }
       }
  }
}

// This function is used to track which Side Menubar and/or Page Sections have been
// expanded and/or collapsed as the user works within the web site.

function ShowMenuItemsList(imType) {
  var NumMenuItemsTotal = 5;
  var NumMenuItems = 0;
  var i;
  var b;
  var NewsItem;
  var EventsItem;
  var MenuItemExpand;
  divColl = document.all.tags("DIV");
  imColl = document.images.item("im" + imType);
  for (i=0; i<divColl.length; i++) {
       if (imType == "SB") {
           if (divColl(i).className == "child_sb") {
               divColl(i).style.display = (sbExpanded) ? "none" : "block";
               a=(i-1)/2;
               for (j=0; j<imColl.length; j++) {
                    if (j==a) {
                        imColl(j).src = "images/mb_expanded.jpg";
                    }
               }
           }else{
               divColl(i).style.display = (sbExpanded) ? "block" : "none";
               for (j=0; j<imColl.length; j++) {
                    if (j==(i-1)/2) {
                        imColl(j).src = "images/mb_collapsed.jpg";
                    }
               }
           }
       }
  }
}
onload = initIt;
