function createFloater( name ) {

    /*
       floater should be contained in a <div id="the_bounding_box_parent"><div id="the_column_slash_wrapper"> ((here)) </div></div>
       floater should have a width defined in CSS, but no positioning stuff, and an initial class of pinned_top
    */

    $('#' + name ).parent().parent().css( { "min-height": $('#' + name).outerHeight(true) } );

    var offset = $('#' + name).offset();
    var bar_height = $('#' + name).height();
    var margin_value = $('#' + name).outerHeight(true) - bar_height ;
    var par_height = $('#' + name).parent().parent().height() ;
    var cutoff = par_height + $('#' + name).parent().parent().offset().top;
    
    //if ( par_height > bar_height + (2 * margin_value) + 100 )
    $(window).scroll(function () {
	var scrollTop = $(window).scrollTop();
	
	if (offset.top - margin_value < scrollTop) {
	    if (scrollTop > cutoff - ( 2 * margin_value) - bar_height) {
		$('#' + name).addClass('pinned-bottom');
		$('#' + name).css( {"top": cutoff - bar_height - ( 2 * margin_value) - $('#' + name).parent().parent().offset().top } );
		$('#' + name).removeClass('floating'); 
		$('#' + name).removeClass('pinned-top');
	    } else {
		$('#' + name).addClass('floating');
		$('#' + name).removeClass('pinned-top');
		$('#' + name).css( { "top" : "" } );
		$('#' + name).removeClass('pinned-bottom');
	    }
	} else {
            $('#' + name).css( { "top" : "" } );
            $('#' + name).addClass('pinned-top');
            $('#' + name).removeClass('floating');
            $('#' + name).removeClass('pinned-bottom');
	}
    });
}

var join = 2;
function cycleJoin() {
    $("#join_btn").attr("src" , "images/join0.png" );
    setTimeout("$('#join_btn').attr( 'src', 'images/join" + join + ".png' );", 300);
    
    ++join;
    if ( join >= 3 ) join = 1;
    setTimeout( "cycleJoin()", 5000);
}

function showDisclaim( $callback ) {
    $('#disclaim_ok').click( function() {
	$('#' + $callback).submit();
      });
    if ( $('#sports_smenu_wrap').length ) $('#sports_smenu_wrap').fadeOut(300);
    $('#disclaim').fadeIn(300);
}

function promptJoin() {
    //showDisclaim( "fullRegister" );
    $('#fullRegister').submit();
}

function promptLogin( ) {
//    showDisclaim( "login" );
//    $('#account').focus();
    $('#disclaim_ok').click( function() {
	$('#login').submit();
    });
    if ( $('#sports_smenu_wrap').length ) $('#sports_smenu_wrap').fadeOut(300);
    $('#disclaim').fadeIn(300);
    $('#account').focus();
}

function cancelLogin() {
    $('#disclaim').fadeOut(300);
    if ( $('#sports_smenu_wrap').length ) $('#sports_smenu_wrap').fadeIn(300);
}

function checkKey( e ) {
    var charCode = 0;
    
    if ( window.event ) charCode = window.event.keyCode; 
    else charCode = e.which;
    
    return charCode;
}

function checkEnter( e ) {
    return ( checkKey(e) == 13);
}

function checkEscape(e) {
    return ( checkKey(e) == 27);
}

function handleLoginKeys( e ) {
    if ( checkEscape(e) ) {
	cancelLogin();
	return false;
    }
    return checkEnter( e );
}

function validateLogin() {
    $('#login').submit();
}

function validateJoin() {
    var tfn = document.getElementById("txtName").value;
    var tln = document.getElementById("txtLastName").value;
    var tph = document.getElementById("txtPhone").value;
    var tem = document.getElementById("txtEmail").value;
    var tps = document.getElementById("txtPassword").value;
    var tp2 = document.getElementById("txtPWConf").value;
    
    var errors = "";
    if ( tfn == "" ) errors += "-First Name Required\n";
    if ( tln == "" ) errors += "-Last Name Required\n";
    if ( tph == "" ) errors += "-Phone Required\n";
    //if ( tem == "" ) errors += "-Email Required\n";
    if ( tps == "" ) errors += "-Password Required\n";
    
    if ( tps.length < 4 ) errors += "-Password must be 4 characters\n";
    if ( tem != "" && tem.search( /^[^@]+@[^@.]+\.[^@]*\w\w$/ ) == -1 ) errors += "-Valid Email Required\n";
    var phn = tph.replace(/[\(\)\.\-\ ]/g, ''); 
    if ( isNaN(parseInt(phn)) || phn.length != 10 ) errors += "-Valid Phone (with area code) Required\n";
    if ( tps != tp2 ) {
	document.getElementById("txtPassword").value = "";
	document.getElementById("txtPWConfirm").value = "";
	errors += "-Your Passwords Do Not Match\n";
    }
    
    if ( errors == "" ) promptJoin();
    else alert( "Please correct these errors:\n\n" + errors );
}

