

if( document.all && !document.getElementById ) {
    document.getElementById = function( id ) {
         return document.all[ id ];
    }
}


function showtime(){

	var day = document.getElementById('Day').value;
	var TimeMF = document.getElementById('TimeMF');
	var TimeSat = document.getElementById('TimeSat');


	switch( day.substr( day.length-3,3 ) ){
	case "Sat":
		TimeSat.style.display = "";
		TimeSat.disabled = false;
		TimeMF.style.display = "none";
		TimeMF.disabled = true;
		break;
	default:
		TimeMF.style.display = "";
		TimeMF.disabled = false;
		TimeSat.style.display = "none";
		TimeSat.disabled = true;
	}
}


function hideinput( input ){
	input.style.display = "none";
	input.disabled = true;
}

function showinput( input ){
	input.style.display = "";
	input.disabled = false;
	input.focus();
}

var subhow;

function showsubhow(){

	how = document.getElementById('How');
	var how_value = how.value;

	if( subhow ) hideinput( subhow );

	subhow = document.getElementById( "How" + how_value );

	if( subhow ) showinput( subhow );
}

function onload(){
	showsubhow();
}

window.onload = onload;

function validate(){

	var firstname = document.getElementById('FirstName').value;
	var mainphone = document.getElementById('MainPhone').value;

	var homecity = document.getElementById('HomeCity').value;
	var homestate = document.getElementById('HomeState').value;

	var loc = document.getElementById('Location').value;


	var day = document.getElementById('Day').value;
	var timeMF = document.getElementById('TimeMF').value;
	var timeSat = document.getElementById('TimeSat').value;

	var good = true;

	good = good && ( firstname.length > 0 );
	good = good && ( mainphone.length > 0 );
	good = good && ( homecity.length > 0 );
	good = good && ( homestate.length > 0 );
	good = good && ( loc.length > 0 );
	good = good && ( day.length > 0 );

	switch( day.substr( day.length-3,3 ) ){
	case "Sat":
		if( timeSat.length == 0 ) good = false;
		break;
	default:
		if( timeMF.length == 0 ) good = false;
	}

	if( ! good ){
		alert( "A required field is missing." );
	}

	return good;
}


function location_onchange(){

	var Location = document.getElementById('Location');

	if( Location.value == 'outofarea' ) redirect_to_home_program();
	
}

function redirect_to_home_program(){

	var form_field_name_ = new Array(
		'FirstName',
		'LastName',
		'MainPhone',
		'AltPhone',
		'Email',
		'HomeCity',
		'Email',
		'HomeState'
	);

	var count = form_field_name_.length;
	var qs_part_ = [];
	
	for( i=0; i<count; i++ ){
		var name = form_field_name_[i];
		var field = document.getElementById( name );
		var value = field.value;
		
		//if( value ) qs_part_.push( name + '=' + value );
		qs_part_.push( name + '=' + value );
	}

	var qs = '';
	if( qs_part_.length > 0 ) qs = qs_part_.join('&'); 

	window.location = 'home_program.php?' + qs; 

}


