var errors;
var bullet = '   * ';
var selectedRow = null;


function getObj(i)
	{
	return document.getElementById(i);
	}


function buyTickets()
	{
	portalWin = window.open('https://salesportal.jockeyclubracecourses.com/jcr_ws/jcr.aspx?venue=NEW','buytickets', 'left='+((screen.width/2)-380)+',top=20,directories=no,width=740,height=580,location=no,menubar=no,resizable=no,scrollbars=yes,status=yes,titlebar=no,toolbar=no');
	portalWin.focus();
	}


function required(field,label)
	{
	var obj = getObj(field);
	if (obj)
		{
		switch(obj.type)
			{
			case 'text'      :if (obj.value         == '') {errors += bullet + 'You must enter '  + label +'.\n'; break;}
			case 'password'  :if (obj.value         == '') {errors += bullet + 'You must enter '  + label +'.\n'; break;}
			case 'select-one':if (obj.selectedIndex ==  0) {errors += bullet + 'You must select ' + label +'.\n'; break;}
			}
		}
	}


function validate_form()
	{
	errors = '';

	required('forename','your first name');
	required('surname','your last name');
	required('email','your e-mail address');

	if ((getObj('email').value != '') && (getObj('email').value.match(/^[\.\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~0-9A-Za-z]+\@[A-Za-z0-9\-\_\.]+\.[A-Za-z]{2,4}$/) == null))
		{errors += bullet + 'You must enter a valid email address.\n';}

	required('recipient_id','the department');
	required('details','your enquiry');

	if (errors != '')
		{
		alert('**** Please complete the following required fields ****\n\n' + errors);
		return false;
		}
	else
		{return true;}
	}


function openFlash(id)
	{
	myWindow = window.open(null,'flash'+id,'resizable=yes,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,copyhistory=0,width=550,height=300,top=0,left=0');
	myWindow.document.write('<html>\n');
	myWindow.document.write('	<head>\n');
	myWindow.document.write('		<title>NewMarket: Video</title>\n');
	myWindow.document.write('	</head>\n');
	myWindow.document.write('	<body>\n');
	myWindow.document.write(document.getElementById('flash_' + id + '_div').innerHTML);
	myWindow.document.write('	</body>\n');
	myWindow.document.write('</html>\n');
	myWindow.document.close();
	}


function toggleTab(li)
	{
	var ul = li.parentNode;
	var lis = ul.getElementsByTagName('LI');
	for (var i=0; i<lis.length; i++)
		{
		var panel = document.getElementById('panel_' + lis[i].id);

		if (lis[i] === li)
			{
			lis[i].className = 'active';
			panel.className = 'show';
			}
		else
			{
			lis[i].className = '';
			panel.className = 'hide';
			}
		}
	}


function toggleRow(td)
	{
	if (selectedRow != null)
		{selectedRow.className = '';}

	if (selectedRow !== td.parentNode)	
		{
		selectedRow = td.parentNode;
		selectedRow.className = 'active';
		}
	}