/**
 * @author Kevin
 */

function validate_private_lessons()
{
	error = '';
	
	// we should always have a start time, but you never know.
	if(document.getElementById('start_time').value == '')
	{
		error += 'Start Time\n';
	}
	// Name is required
	if(document.getElementById('lbname').value == '')
	{
		error += 'Name\n';
	}
	// Email is required
	if(! is_valid_email(document.getElementById('lbemail').value))
	{
		error += 'Valid Email\n';
	}
	
	// loop through our payment methods to see if an option is checked
	pmindex = false;
	for(i=0; i<document.forms['book_lesson_form'].pmindex.length; i++)
	{
		if(document.forms['book_lesson_form'].pmindex[i].checked == true)
		{
			pmindex = true;
		}
	}
	// if we don't have a payment method selected, give an error
	if(!pmindex)
	{
		error += 'Payment Method\n';
	}
	
	if(error != '')
	{
		error = 'The following fields are required in order to book a lesson:\n\n'+error;
		alert(error);
		return false;
	}
	
	document.forms['book_lesson_form'].submit();
	
	return false;
}


function is_valid_email(email_address)
{
	if (email_address != '') 
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (reg.test(email_address) == false) 
		{
			return false;
		}
		return true;
	}
	return false;
}


function book_lesson(cindex, cname, start_time, lesson_date, next_booked)
{
	// if the next timeslot is booked, disable options to take a 40 minute lesson.
	if(next_booked == 1)
	{
		document.getElementById('two_lessons').disabled 	= true;
		document.getElementById('one_lesson').checked 		= true;
		document.getElementById('duration').innerHTML 		= 20;
	}
	// if the next slot is available, enable the thirty minute option
	else
	{
		document.getElementById('two_lessons').disabled = false;
	}
	
	document.getElementById('start_time').value 				= start_time;		// Our lbstart value
	document.getElementById('cindex').value 					= cindex;			// The Coach index
	document.getElementById('lbdate').value 					= lesson_date;		// The date of the lesson
	document.getElementById('cname').innerHTML 					= cname;			// Name display
	document.getElementById('lesson_date').innerHTML 			= lesson_date;		// Date display
	document.getElementById('lesson-wrapper').style.display 	= 'block';			// Show this block
	document.getElementById('lesson-container').style.display 	= 'block';			// Show this block
}
