// JavaScript Document

//Google Analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-23219194-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
//

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_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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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 validateEmployment()
{  
  if (document.frmSend.name.value.length < 1)
  {
    alert("Please enter your name");
	return false;
  } 
  else if (!IsValidEmail(document.frmSend.email.value))
  {
    alert("Please enter a valid email address");
	return false;
  }
  else if(document.frmSend.attach2.value == "" && document.frmSend.resume.value == "")
  {
    alert("Please attach or paste your resume");
	return false;
  }
  else if (document.frmSend.attach2.value.length > 0)
  {
    var dot = document.frmSend.attach2.value.indexOf(".")
    var ext = document.frmSend.attach2.value.substring(dot+1, document.frmSend.attach2.value.length)

    ext = ext.toLowerCase();	
	
	if (!(ext == "doc" || ext == "docx" || ext == "rtf" || ext == "pdf" || ext == "txt"))
    {    
      alert("Please attach a resume of format .doc, .docx, .pdf, .txt or .rtf");
	  return false;
    }
	else
	{
	  document.frmSend.Submit.disabled = true;
	  return true;
	}
  }
  else
  {
    document.frmSend.Submit.disabled = true;
	return true;
  }
}

function IsValidEmail(strEmail)
{
  var IsValid;
  IsValid = true;

  var index;
  index = 0
	  
  if ( strEmail.length > 0 )
  {    	
	if ( strEmail.length < 5 )
    {
      IsValid = false;
    }
    else
    {	  
	  if ( strEmail.indexOf(" ") > 0 )
	  {	    
		IsValid = false;
	  }
      else
	  { 	    
		if ( strEmail.indexOf("@") < 0)
	    {
	      IsValid = false;		  
	    }
	    else
	    {
		  index = strEmail.indexOf("@");
		            
		  while (index != -1)
	      {    
            index = strEmail.indexOf("@", index + 1);			
		  
		    if (index != -1)
		    {
		      IsValid = false;			  			  
		    }
          }
		  if ( strEmail.lastIndexOf(".") < (strEmail.indexOf("@", 1) + 2) )
		  {
		    IsValid = false;
		  }
	    }
	  }
    }
  }
  else
  {
    IsValid = false;
  } 
  return IsValid  
}

function showGallery(id, l)
{
  window.open ('gallery.asp' + '?league=' + l + '&game_id=' + id + '&page=1', '','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600,screenX=0,screenY=0,top=0,left=0'); 
}

function getSchedule(league)
{
    box = document.forms[0].teams;
	destination = box.options[box.selectedIndex].value;		
	
	if (destination == "")
	{
	  location.href = "schedule.asp?league=" + league;
	}
	else
	{
	  location.href = "schedule.asp?league=" + league + "&id=" + destination;
	}
}

function getTeam(l)
{
    box = document.forms[0].teams;
	destination = box.options[box.selectedIndex].value;
	location.href = "rosters.asp?league=" + l + "#" + destination;
	document.form1.teams.selectedIndex = 0;
}

function getStats(l)
{
    box = document.forms[0].teams;
	destination = box.options[box.selectedIndex].value;
	location.href = "stats.asp?league=" + l + "#" + destination;
	document.form1.teams.selectedIndex = 0;
}

function validateForumLogin()
{    
  if (document.forms[0].team.selectedIndex == 0)
  {
    alert("Please select your team");
	return false;
  } 
  else if (!IsValidEmail(document.form1.email.value))
  {
    alert("Please enter a valid email address");
	return false;
  }
  else
  {
    return true;
  }
}

function showCupGallery(l, id)
{
  window.open ('gallery.asp?league=' + l + '&game_id=' + id + '&page=1', '','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=900,height=700,screenX=0,screenY=0,top=0,left=0'); 
}

function getCupSchedule(league)
{
    box = document.forms[0].teams;
	destination = box.options[box.selectedIndex].value;		
	
	if (destination == "")
	{
	  location.href = "schedule.asp?league=" + league;
	}
	else
	{
	  location.href = "schedule.asp?league=" + league + "&id=" + destination;
	}
}

function getCupTeam(l)
{
    box = document.forms[0].teams;
	destination = box.options[box.selectedIndex].value;
	
	if (l == "cup")	
	  location.href = "rosters.asp" + "#" + destination;
	else
	  location.href = "rosters.asp?league=" + l + "#" + destination;
	
	document.form1.teams.selectedIndex = 0;
}

function showGame(id, league)
{
  window.open('playoff_game.asp?league=' + league + '&id=' + id, '','toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable=no,width=350,height=375');
}

function showVid(v)
{
  window.open ('http://www.ulax.org/show_video.asp' + '?vid=' + v, '','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=550,height=425,screenX=0,screenY=0,top=0,left=0'); 
}

function hideForms()
{  
  blog.style.visibility = 'hidden';   
  
  var iframe = document.getElementById("blogFrame");
  iframe.src = "";
}

function showdeadcenterdiv(Xwidth,Yheight,divid) { 
// First, determine how much the visitor has scrolled 

var scrolledX, scrolledY; 
if( self.pageYoffset ) { 
scrolledX = self.pageXoffset; 
scrolledY = self.pageYoffset; 
} else if( document.documentElement && document.documentElement.scrollTop ) { 
scrolledX = document.documentElement.scrollLeft; 
scrolledY = document.documentElement.scrollTop; 
} else if( document.body ) { 
scrolledX = document.body.scrollLeft; 
scrolledY = document.body.scrollTop; 
} 

// Next, determine the coordinates of the center of browser's window 

var centerX, centerY; 
if( self.innerHeight ) { 
centerX = self.innerWidth; 
centerY = self.innerHeight; 
} else if( document.documentElement && document.documentElement.clientHeight ) { 
centerX = document.documentElement.clientWidth; 
centerY = document.documentElement.clientHeight; 
} else if( document.body ) { 
centerX = document.body.clientWidth; 
centerY = document.body.clientHeight; 
} 

  // Xwidth is the width of the div, Yheight is the height of the 
  // div passed as arguments to the function: 
var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
var topoffset = scrolledY + (centerY - Yheight) / 2; 
  // The initial width and height of the div can be set in the 
  // style sheet with display:none; divid is passed as an argument to // the function 
var o=document.getElementById(divid); 
var r=o.style; 
r.position='absolute'; 
r.top = topoffset + 'px'; 
r.left = leftoffset + 'px'; 
r.display = "block"; 

//set width/height of iframe
var iframe = document.getElementById("blogFrame");
iframe.width = '850';
iframe.height = '400';

r.visibility = 'visible';
} 

function selectText()
{
  document.search.search.select();
}

function showCheque()
{
  window.open ('http://www.ulax.org/cheque.asp', '','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=525,height=275,screenX=0,screenY=0,top=0,left=0'); 
}
