// JavaScript Document
function validateLogin( ) {
	var error = 0;
	
	// clear all errors
	var elems = $$( '#foLogin input' );
	for( i = 0; i < elems.length; i++ ){
		if( $( 'error_' + $( elems[i] ).name ) ) {
			$( 'error_' + $( elems[i] ).name ).set( 'html', '' );
			$( elems[i] ).setStyle( 'background', '' );
		}
	}

	//if( !( checkEmail( 'loginEmail' ) ) ) {
	if ( $( 'loginEmail' ).value == '' ) {
		$( 'error_loginEmail' ).set( 'html', 'Please enter a valid email address.' );
		$( 'loginEmail' ).setStyle( 'background', '#ffff99' );
		$( 'loginEmail' ).focus( );
		error = 1;
	}
	
	if ( $( 'loginPassword' ).value == '' ) {
		$( 'error_loginPassword' ).set( 'html', 'Please enter your password.' );
		$( 'loginPassword' ).setStyle( 'background', '#ffff99' );
		$( 'loginPassword' ).focus( );
		error = 1;
	}

	if ( !error ) {
		$( 'foLogin' ).submit();
	}
}

function validatePayment( ) {
	var error = 0;
	
	// clear all errors
	var elems = $$( '#foPayment input', '#foPayment select' );
	for( i = 0; i < elems.length; i++ ){
		if( $( 'error_' + $( elems[i] ).name ) ) {
			$( 'error_' + $( elems[i] ).name ).set( 'html', '' );
		}
		$( elems[i] ).setStyle( 'background', '' );
	}
	
	if( !( checkCreditCard( 'ccNum' ) ) ) {
		$( 'error_ccNum' ).set( 'html', 'Please enter a valid credit card number.' );
		$( 'ccNum' ).setStyle( 'background', '#ffff99' );
		$( 'ccNum' ).focus( );
		error = 1;
	}
	
	if( $( 'ccMo' ).value == '' || $( 'ccYr' ).value == '' ) {
		$( 'error_ccMo' ).set( 'html', 'Please choose a valid card expiration date.' );
		$( 'ccMo' ).setStyle( 'background', '#ffff99' );
		$( 'ccYr' ).setStyle( 'background', '#ffff99' );
		$( 'ccMo' ).focus( );
		error = 1;
	}
	
	if( $( 'cvv2' ).value == '' ) {
		$( 'error_cvv2' ).set( 'html', 'Please enter a valid card secuity (cvv2) number.' );
		$( 'cvv2' ).setStyle( 'background', '#ffff99' );
		$( 'cvv2' ).focus( );
		error = 1;
	}
	
	if( $( 'BillingName' ).value == '' ) {
		$( 'error_BillingName' ).set( 'html', 'Please enter the name on the card.' );
		$( 'BillingName' ).setStyle( 'background', '#ffff99' );
		$( 'BillingName' ).focus( );
		error = 1;
	}
	
	if( $( 'BillingAddress' ).value == '' ) {
		$( 'error_BillingAddress' ).set( 'html', 'Please enter the billing address.' );
		$( 'BillingAddress' ).setStyle( 'background', '#ffff99' );
		$( 'BillingAddress' ).focus( );
		error = 1;
	}
	
	if ( $( 'BillingCountry' ) ) {
		if ( $( 'BillingCountry' ).value == 'US' ){
			if( $( 'BillingCity' ).value == '' || $( 'BillingState' ).value == '' || $( 'BillingZip' ).value == '' ) {
				$( 'error_BillingCity' ).set( 'html', 'Please complete your billing information.' );
				if( $( 'BillingCity' ).value == '' ) {
					$( 'BillingCity' ).setStyle( 'background', '#ffff99' );
					$( 'BillingCity' ).focus( );
				}
				if( $( 'BillingState' ).value == '' ) {
					$( 'BillingState' ).setStyle( 'background', '#ffff99' );
					$( 'BillingState' ).focus( );
				}
				if( $( 'BillingZip' ).value == '' ) {
					$( 'BillingZip' ).setStyle( 'background', '#ffff99' );
					$( 'BillingZip' ).focus( );
				}
				
				error = 1;
			}
		} else {
			if( $( 'BillingOtherCity' ).value == '' || $( 'BillingOtherZip' ).value == '' ) {
				$( 'error_BillingOtherCity' ).set( 'html', 'Please complete your billing information.' );
				if( $( 'BillingOtherCity' ).value == '' ) {
					$( 'BillingOtherCity' ).setStyle( 'background', '#ffff99' );
					$( 'BillingOtherCity' ).focus( );
				}
				if( $( 'BillingOtherZip' ).value == '' ) {
					$( 'BillingOtherZip' ).setStyle( 'background', '#ffff99' );
					$( 'BillingOtherZip' ).focus( );
				}
				
				error = 1;
			}
		}
	}
	
	if( $( 'LeagueName' ) && $( 'LeagueName' ).value == '' ) {
		$( 'error_LeagueName' ).set( 'html', 'Please enter the name of your league..' );
		if( $( 'LeagueName' ).value == '' ) {
			$( 'LeagueName' ).setStyle( 'background', '#ffff99' );
			$( 'LeagueName' ).focus( );
		}
		
		error = 1;
	}
	
	if ( !error ) {
		$( 'foPayment' ).submit();
	}
}
	
function validateRegistration( ) {
	/*
	var error = 0;
	var errorFocus = '';
	
	// clear all errors
	var elems = $$( '#registration input,#registration select' );
	for( i = 0; i < elems.length; i++ ){
		if( $( 'error_' + $( elems[i] ).name ) ) {
			$( 'error_' + $( elems[i] ).name ).set( 'html', '' );
			$( elems[i] ).setStyle( 'background', '' );
		}
	}

	if( !( $( 'isAgreeTerms' ).checked ) ) {
		$( 'error_isAgreeTerms' ).set( 'html', 'Please check the box indicating that you agree to the terms and privacy policy of this website.' );
		$( 'isAgreeTerms' ).setStyle( 'background', '#ffff99' );
		//$( 'isAgreeTerms' ).focus( );
		errorFocus = 'SignUp_Info';
		error = 1;
	}
	
	if( $( 'isFootball' ).checked && $( 'isFootballComments' ).value == '') {
		$( 'error_isFootballComments' ).set( 'html', 'You\'ve indicated that your are involved in football. Please explain.' );
		$( 'isFootballComments' ).setStyle( 'background', '#ffff99' );
		//$( 'isFootballComments' ).focus( );
		errorFocus = 'Football_Info';
		error = 1;
	}
	
	//if( $( 'Password' ).value.length < 7 ) {
	if( $( 'Password' ).value == '' ){
		$( 'error_Password' ).set( 'html', 'Your password must be at least 7 characters.' );
		$( 'Password' ).setStyle( 'background', '#ffff99' );
		//$( 'Password' ).focus( );
		errorFocus = 'Member_Info';
		error = 1;
	} else if ( $( 'Password' ).value != $( 'ConfirmPassword' ).value ) {
		$( 'error_Password' ).set( 'html', 'Your passwords do not match. Please re-enter.' );
		$( 'ConfirmPassword' ).setStyle( 'background', '#ffff99' );
		$( 'Password' ).setStyle( 'background', '#ffff99' );
		//$( 'Password' ).focus( );
		errorFocus = 'Password';
		error = 1;
	}
	
	if( $( 'Username' ).value == '' ){
		$( 'error_Username' ).set( 'html', 'Please enter your desired username.' );
		$( 'Username' ).setStyle( 'background', '#ffff99' );
		//$( 'Username' ).focus( );
		errorFocus = 'Username';
		error = 1;
	} else {
		// using AJAX, check for an existing username
	}

	if( !( checkRadio( 'Gender' ) ) ) {
		$( 'error_Gender' ).set( 'html', 'Please choose your gender.' );
		$( 'Gender_Male' ).setStyle( 'background-color', '#ffff99' );
		//$( 'Gender_Male' ).focus( );
		errorFocus = 'Gender';
		error = 1;
	}

	//if( !( checkEmail( 'Email' ) ) ) {
	if ( $( 'Email' ).value == '' ) {
		$( 'error_Email' ).set( 'html', 'Please enter a valid email address.' );
		$( 'Email' ).setStyle( 'background', '#ffff99' );
		//$( 'Email' ).focus( );
		errorFocus = 'Email';
		error = 1;
	} else if ( $( 'Email' ).value != $( 'ConfirmEmail' ).value ) {
		$( 'error_Email' ).set( 'html', 'Your email addresses do not match. Please re-enter.' );
		$( 'ConfirmEmail' ).setStyle( 'background', '#ffff99' );
		$( 'Email' ).setStyle( 'background', '#ffff99' );
		//$( 'Email' ).focus( );
		errorFocus = 'Email';
		error = 1;
	}
	
	//if( !( checkZip( 'Zip' ) ) ) {
	if( $( 'Zip' ).value == '' ) {
		$( 'error_Zip' ).set( 'html', 'Please enter a valid zip code.' );
		$( 'Zip' ).setStyle( 'background', '#ffff99' );
		//$( 'Zip' ).focus( );
		errorFocus = 'Zip';
		error = 1;
	}
	
	if( !( checkDate( 'DOB' ) ) ) {
		$( 'error_DOB' ).set( 'html', 'Please enter your birthdate in format "MM/DD/YYYY".' );
		$( 'DOB' ).setStyle( 'background', '#ffff99' );
		//$( 'DOB' ).focus( );
		errorFocus = 'DOB';
		error = 1;
	}
	
	if( $( 'LastName' ).value == '' ){
		$( 'error_LastName' ).set( 'html', 'Please enter your last name.' );
		$( 'LastName' ).setStyle( 'background', '#ffff99' );
		//$( 'LastName' ).focus( );
		errorFocus = 'LastName';
		error = 1;
	}

	if( $( 'FirstName' ).value == '' ){
		$( 'error_FirstName' ).set( 'html', 'Please enter your first name.' );
		$( 'FirstName' ).setStyle( 'background', '#ffff99' );
		//$( 'FirstName' ).focus( );
		errorFocus = 'FirstName';
		error = 1;
		
	}
	
	if ( !error ) {
		$( 'registration' ).submit();
	} else {
		$( errorFocus ).focus();
	}
	*/
	$( 'registration' ).submit();
}

function validateNewPassword( ){
	var error = 0;
	
	if( $( 'foEmail' ).value == '' ) {
		alert('Please enter a valid email address.');
		error = 1;
	}
	
	if ( !error ) {
		$( 'contentForm' ).submit();
	}
	
}

function switchPos( position, source ){
	if( source == 'total access' ){
		theURL = 'front_office_total_access.cfm';
	} else if( source == 'draft guide' ){
		theURL = 'front_office_draft_guide.cfm';
	}
	
	var myRequest = new Request({
		method:		'get',
		url:			theURL + '?ajax=top 10 players&position=' + position,
		evalScripts:	true,
		onSuccess: 	function( ) { if( Mediabox ) Mediabox.scanPage(); },
		onComplete:	function( html ) {
						$( 'ajax_top_10' ).innerHTML = html;
					}
	}).send();
		
}

function nextMRStory( startRow ){
	var myRequest = new Request({
		method:		'get',
		url:			'front_office_draft_guide.cfm?ajax=most recent stories&startRow=' + startRow,
		evalScripts:	true,
		onSuccess:	function( ) {
			sifrRedraw( );
		},
		onComplete:	function( html ) {
						$( 'mrStories' ).innerHTML = html;
					}
	}).send();
		
}

function sifrRedraw() {
		
	var font = { src: '/flash/sifr/din.swf' };  
	var sIFRElement = {
		
		selector: 	'.red_15px',
		css: [
					'.sIFR-root { font-size: 15px; color: #660000; text-transform: uppercase; leading: 0; }',
					'a { color: #660000; text-decoration: none; }',
					'a:hover { color: #660000; text-decoration: underline; }'
		],
		ratios: 		[7, 1.47, 10, 1.43, 15, 1.36, 22, 1.34, 26, 1.32, 29, 1.31, 32, 1.32, 33, 1.3, 37, 1.31, 45, 1.3, 48, 1.29, 51, 1.3, 65, 1.29, 67, 1.28, 68, 1.29, 74, 1.28, 75, 1.29, 1.28],
		wmode: 		'transparent',
		offsetTop:	-4,
		tuneHeight: 	-10
		
	};
	
	window.sIFR.replace( font, sIFRElement );
	
}

function switchCountry( ){
	if ( $( 'BillingCountry' ).value == 'US' ) {	
		$( 'country_us' ).setStyle( 'display', 'block' );
		$( 'country_other' ).setStyle( 'display', 'none' );
	} else {
		$( 'country_us' ).setStyle( 'display', 'none' );
		$( 'country_other' ).setStyle( 'display', 'block' );
	}
}

function validateComment( ) {
	/*
	var error = 0;
	
	// clear all errors
	var elems = $$( '#add_comment input,#add_comment select' );
	for( i = 0; i < elems.length; i++ ){
		if( $( 'error_' + $( elems[i] ).name ) ) {
			$( 'error_' + $( elems[i] ).name ).set( 'html', '' );
			$( elems[i] ).setStyle( 'background', '' );
		}
	}
	
	if( $( 'Username' ).value == '' ){
		$( 'error_Username' ).set( 'html', 'Please enter your name.' );
		$( 'Username' ).setStyle( 'background', '#ffff99' );
		$( 'Username' ).focus( );
		error = 1;
	}
	
	//if( !( checkEmail( 'Email' ) ) ){
	if( $( 'Email' ).value == '' ){
		$( 'error_Email' ).set( 'html', 'Please enter a valid email address.' );
		$( 'Email' ).setStyle( 'background', '#ffff99' );
		$( 'Email' ).focus( );
		error = 1;
	}
	
	if( $( 'Comment' ).value == '' ){
		$( 'error_Comment' ).set( 'html', 'Please enter your comments.' );
		$( 'Comment' ).setStyle( 'background', '#ffff99' );
		$( 'Comment' ).focus( );
		error = 1;
	}
	
	if ( !error ) {
		$( 'add_comment' ).submit();
	}
	*/
	$( 'add_comment_form' ).submit();
}


// DOM Object
////////////////////////////////////////////////////////////////////////
window.addEvent( 'domready', function() {
	if($('isFootball')){
		$( 'isFootball' ).addEvent( 'click', function() {
			$( 'please_explain' ).toggleClass( 'hide' );
		});
	}
	
	if($('Conference')){
		$( 'Conference' ).addEvent( 'change', function() {
			var myRequest = new Request({
				method:		'get',
				url:			'register.cfm?ajax=get college teams&id=' + $('Conference').value,
				evalScripts:	true,
				onComplete:	function(html) {
								$('collegeTeam').innerHTML = html;
							}
			}).send();
		});
	}	
});
