function initTabs()
{
    if($('#flashwelcome').length > 0)
    {
	    var so = new SWFObject("/welcome/welcome.swf", "welcome", "343", "260", "8");
        so.write("flashwelcome");
    }
    $('.tabset a.active').each(function(){
        $($(this).attr('href')).show();
    });
    $('.tabset a').click(function(event){
        event.preventDefault();
        $('#tab-holder .gradient > div').hide();
        $($(this).attr('href')).show();
        $('.tabset a').removeClass('active');
        $(this).addClass('active');
        if($(this).attr('href') != '#tab1')
        {
            stopVid();
        }
    });
	
	//$('.CalendarControl .CalendarTitleStyle a').corner();
	SetUpCalendar();
	SeedSignup();
	InterruptLinks();
	Spotlights();
	RegisterCalendarHandler();
}

function EndRequestHandler(sender, args) {
   SetUpCalendar();
}
function RegisterCalendarHandler() {
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}


if (window.addEventListener) window.addEventListener("load", initTabs, false);
else if (window.attachEvent) window.attachEvent("onload", initTabs);

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}
function stopVid(){
	//movieName is the name of the swf file without the extension
     getFlashMovie("welcome").jsStopVid();
}
function playVid(){
     getFlashMovie("welcome").jsPlayVid();
}
function pauseVid(){
     getFlashMovie("welcome").jsPauseVid();
}

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 expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

if(readCookie('spotlight') == null){
    createCookie('spotlight','1');
}
var startSpot = parseInt(readCookie('spotlight'),10);
var showSpot = startSpot;
function Spotlights()
{
    //var spotsy = $('.spotty');
    $('.box #spot'+showSpot).show();
    $('#spotswitch a').click(function(event){
        event.preventDefault();
        var numSpots = $('.spotty').length;
        var PrevNext = $(this).attr('rel');
        if(PrevNext == "Prev")
        {
            if(showSpot > 1)
            {
                showSpot--;
            }
            else
            {
                showSpot = numSpots;
            }
        }
        else if(PrevNext == "Next")
        {
            if(showSpot < numSpots)
            {
                showSpot++;
            }
            else
            {
                showSpot = 1;
            }
        }
        $('.box .spotty').hide();
        $('.box #spot'+showSpot).show();
    });
    if(startSpot>=$('.spotty').length)
    {
        createCookie('spotlight',1);
    }
    else
    {
        createCookie('spotlight',startSpot+1);
    }
}

function SetUpCalendar()
{
	$('.CalendarControl tr').each(function(){
	    var nonempties = 0;
	    $(this).children('td').each(function(){
	        if($(this).html().length > 0)
	        {
	            nonempties++;
	        }
	        else{
	            var nothing = 5;
	        }
	    });
	    $(this).children('th').each(function(){
	        if($(this).html().length > 0)
	        {
	            nonempties++;
	        }
	        else{
	            var nothing = 5;
	        }
	    });
	    if(nonempties < 1)
	    {
	        $(this).hide();
	    }
	});
}


function SeedSignup()
{
    var homePageEmail = $('#HomeEmailInput').val();
    if (homePageEmail != null)
    {
        $('#HomeEmailInput').val(homePageEmail.replace(/%40/g,'@'));
    }
    
    //$('#HomeEmailInput').val($('#HomeEmailInput').val().replace(/%40/g,"@"));
    var formID = jQuery.url.param('ID');
    if(formID == '313')
    {
        var email = jQuery.url.param('email');
        email = email.replace(/%40/,"@");
        $('#ctl00_ctl00_EmailControl_MyText').val(email);        
        $('#ctl00_ctl00_ctl03_MyText').val(jQuery.url.param('lastname').replace(/\+/," "));
        $('#ctl00_ctl00_ctl02_MyText').val(jQuery.url.param('firstname').replace(/\+/," "));
    }
}

function EscapeAtSign(element){
    element.value = element.value.replace(/@/g,'%40');
}

function InterruptLinks(){
    $("a").click(function(event){
        var myLink = $(this).attr('href');
        var currentUrl = jQuery.url.attr('source').toLowerCase();
        var nothing3=5;
        if(currentUrl!=null)
        {
            if(currentUrl.search('/webreturn/') != -1)
            {
                top.location=myLink;
                event.preventDefault();
            }
        }
        var host = jQuery.url.attr('host');
        var newhost = jQuery.url.setUrl(myLink).attr('host');
        if (newhost!=null)
        {
            newhost = newhost.toLowerCase();
            if((newhost != host))// || (newhost.toLowerCase().search('/documentquery/') == 0))
            {
                var dqCheck = newhost.search(/documentquery/);
                var dsCheck = newhost.search(/documentsingle/);
                var dpCheck = newhost.search(/documentprint/);
                var twitterCheck = newhost.search(/twitter/);
                //var ytCheck = newhost.search(/youtube/);
                //var fbCheck = newhost.search(/facebook/);
                var pbCheck = newhost.search(/postback/);
                var nvCheck = newhost.search(/neva/);
                if(dqCheck == -1 && dsCheck == -1 && dpCheck == -1 && twitterCheck == -1 && /*ytCheck == -1 && fbCheck == -1 &&*/ pbCheck == -1 && nvCheck == -1)
                {
                    event.preventDefault();
                    var browseTo = '/webreturn/?url='+myLink;
                    var nothing3=5;
                    window.location = browseTo;
                }
            }
        }
         //alert("As you can see, the link no longer took you to jquery.com");
     });
}
