//for collecting info to add horse
var Horse_AutoFields;
var competitor_dataObj;
var horse_dataObj;
var rider_dataObj;
var owner_dataObj;



var COMPETITOR_REGISTRATION = 0;
var HORSE_REGISTRATION = 1;
var RIDER_REGISTRATION = 2;
var OWNER_REGISTRATION = 3;

var competitor_registrations_visible;
var horse_auto_table;
var rider_auto_table;
var home_horse_auto_table;
var home_rider_auto_table;
var competitor_registrations_auto_table;
var horse_registrations_auto_table;
var rider_registrations_auto_table;
var owner_registrations_auto_table;
var horseshow_auto_table;
var home_horseshow_auto_table;
var prizes_horseshow_auto_table;
var diary_auto_table;
var showsection_auto_table;
var class_auto_table;
var basket_auto_table;
var detail_diary_auto_table;
var discount_str;

var booking_list; //which shows has competitor booked for
//var diary_detail_list;

var accomodation_checkin_CALENDAR;
var accomodation_checkout_CALENDAR;

var PROFILE_VISIBLE = 1;
var HORSE_VISIBLE = 2;
var RIDER_VISIBLE = 3;
var SHOW_VISIBLE = 4;
var PRIZES_VISIBLE = 5;
var HOME_VISIBLE = 6;
var DIARY_VISIBLE = 7;

var COLLAPSING_VISIBLE;

var cookie_selected; /*which table element did user click on to bring us here*/

var owner_display="";
var ar_prizes;

function onLoad()
{
	var today = new Date();
	var d = today.getDate();
	var m = today.getMonth()+1;
	var y = today.getFullYear();

	ar_prizes = Array();

	competitor_dataObj = new dataObj("competitor_DB");
	horse_dataObj = new dataObj("horse_DB");
	rider_dataObj = new dataObj("rider_DB");
	owner_dataObj = new dataObj("owner_DB");

	accomodation_checkin_CALENDAR = new sqCalendarDisplay(d,m,y, "accomodation_checkin");
	accomodation_checkin_CALENDAR.sqCreate();
	accomodation_checkin_CALENDAR.sqDraw();
	accomodation_checkout_CALENDAR = new sqCalendarDisplay(d,m,y, "accomodation_checkout");
	accomodation_checkout_CALENDAR.sqCreate();
	accomodation_checkout_CALENDAR.sqDraw();

	competitor_registrations_visible = false;

	horse_auto_table = new auto_table();
	horse_auto_table.init("horse_table");
	home_horse_auto_table = new auto_table();
	home_horse_auto_table.init("home_horse_table");
	home_horse_auto_table.border = false;
	rider_auto_table = new rider_auto_table();
	rider_auto_table.init("rider_table");
	home_rider_auto_table = new auto_table();
	home_rider_auto_table.init("home_rider_table");
	home_rider_auto_table.border = false;
	competitor_registrations_auto_table = new auto_table();
	competitor_registrations_auto_table.init("competitor_registrations_table");
	horse_registrations_auto_table = new auto_table();
	horse_registrations_auto_table.init("horse_registrations_table");
	rider_registrations_auto_table = new auto_table();
	rider_registrations_auto_table.init("rider_registrations_table");
	owner_registrations_auto_table = new auto_table();
	owner_registrations_auto_table.init("owner_registrations_table");

	horseshow_auto_table = new auto_table();
	horseshow_auto_table.init("horseshow_table");
	home_horseshow_auto_table = new horseshow_diary_auto_table();
	home_horseshow_auto_table.init("home_horseshow_table");
	home_horseshow_auto_table.clickable = false;
	home_horseshow_auto_table.public = false;/*don't show "more" for gold shows - competitor is logged on & can purchase*/

	prizes_horseshow_auto_table = new auto_table();
	prizes_horseshow_auto_table.init("prizes_horseshow_table");
	prizes_horseshow_auto_table.clickable = true;


	diary_auto_table = new auto_table();
	diary_auto_table.init("diary_table");
	diary_auto_table.border = false;	
	showsection_auto_table = new auto_table();
	showsection_auto_table.init("showsection_table");	
	class_auto_table = new auto_table();
	class_auto_table.init("showclass_table");
	basket_auto_table = new basket_auto_table(); 
	basket_auto_table.init("basket_table");
	basket_auto_table.clickable = false;
	detail_diary_auto_table = new auto_table();
	detail_diary_auto_table.init("detail_diary_table");
	detail_diary_auto_table.clickable = false;

	ar_society_registrations = Array();
	ar_competitor_registrations = Array();

	booking_list = Array();
	addEvent("mousedown", myMouseDown);
	addEvent("scroll", PositionToolbar);


	Horse_AutoFields = Array();
	Horse_AutoFields.push('db_HorseName');
	Horse_AutoFields.push('db_Colour');
	Horse_AutoFields.push('db_Sire');
	Horse_AutoFields.push('db_Dam');
	Horse_AutoFields.push('db_Breed');
	Horse_AutoFields.push('db_JMBCertificate');
	Horse_AutoFields.push('db_Passport');

	fill_day_dropdown('horse_dob_day');
	fill_month_dropdown('horse_dob_month');
	fill_year_dropdown('horse_dob_year', 2000, 2009);

	horse_auto_table.add_visible_field("db_HorseName");
	home_horse_auto_table.add_visible_field("db_HorseName");
	rider_auto_table.add_visible_field("db_Title");
	rider_auto_table.add_visible_field("db_FirstName");
	rider_auto_table.add_visible_field("db_LastName");
	rider_auto_table.add_visible_field("db_DOB");
	home_rider_auto_table.add_visible_field("db_Title");
	home_rider_auto_table.add_visible_field("db_FirstName");
	home_rider_auto_table.add_visible_field("db_LastName");
	horse_registrations_auto_table.add_visible_field("db_RegistrationID");
	horse_registrations_auto_table.add_visible_field("db_RegistrationNumber");
	horse_registrations_auto_table.add_visible_field("db_StartDate");
	competitor_registrations_auto_table.add_visible_field("db_RegistrationID");
	competitor_registrations_auto_table.add_visible_field("db_RegistrationNumber");
	competitor_registrations_auto_table.add_visible_field("db_StartDate");
	rider_registrations_auto_table.add_visible_field("db_RegistrationID");
	rider_registrations_auto_table.add_visible_field("db_RegistrationNumber");
	rider_registrations_auto_table.add_visible_field("db_StartDate");
	owner_registrations_auto_table.add_visible_field("db_RegistrationID");
	owner_registrations_auto_table.add_visible_field("db_RegistrationNumber");
	owner_registrations_auto_table.add_visible_field("db_StartDate");


	horseshow_auto_table.add_visible_field("db_ShowName");
	home_horseshow_auto_table.add_visible_field("db_ShowName");
	home_horseshow_auto_table.add_visible_field("db_FirstDay");
	diary_auto_table.add_visible_field("db_ShowName");
	diary_auto_table.add_visible_field("db_FirstDay");
	showsection_auto_table.add_visible_field("db_Name");
	class_auto_table.add_visible_field("db_ClassTitle");
	class_auto_table.add_visible_field("db_Number");

	prizes_horseshow_auto_table.add_visible_field("db_ShowName");



	basket_auto_table.add_header("Item");
	basket_auto_table.add_header("Fee");
	basket_auto_table.add_visible_field("db_Item");
	basket_auto_table.add_visible_field("db_Fee");

	detail_diary_auto_table.add_header("Show");
	detail_diary_auto_table.add_header("Item");
	detail_diary_auto_table.add_header("Date");
	detail_diary_auto_table.add_header("To");
	detail_diary_auto_table.add_header("Horse");
	detail_diary_auto_table.add_header("Rider");
	detail_diary_auto_table.add_header("Time");
	detail_diary_auto_table.ar_keys.push("db_ID"); //meaningless, but required for auto_table
	detail_diary_auto_table.ar_keys.push("db_Show");
	detail_diary_auto_table.ar_keys.push("db_Class");
	detail_diary_auto_table.ar_keys.push("db_StartDate");
	detail_diary_auto_table.ar_keys.push("db_EndDate");
	detail_diary_auto_table.ar_keys.push("db_Horse");
	detail_diary_auto_table.ar_keys.push("db_Rider");
	detail_diary_auto_table.ar_keys.push("db_ClassTime");
	detail_diary_auto_table.add_visible_field("db_Show");
	detail_diary_auto_table.add_visible_field("db_Class");
	detail_diary_auto_table.add_visible_field("db_StartDate");
	detail_diary_auto_table.add_visible_field("db_EndDate");
	detail_diary_auto_table.add_visible_field("db_Horse");
	detail_diary_auto_table.add_visible_field("db_Rider");
	detail_diary_auto_table.add_visible_field("db_ClassTime");
	DisplayCollapsing("home");

	cookie_selected = document.cookie;

	if (cookie_selected.indexOf("selected=") != -1)
	{
		start = cookie_selected.indexOf("selected=")+9;
		end = cookie_selected.indexOf(";", start);
		if (end == -1)
			cookie_selected = cookie_selected.substr(start);
		else
			cookie_selected = cookie_selected.substr(start, end-(start));
	}
	else
		cookie_selected = -1;

	init_expanded();


	var hs = new hs_Transport();
	hs.InitCompetitorPage();

}


function initialisation_complete()
{
	var start_soc_reg = 10; //start year for society registrations 10 year ago?

	var today = new SB_Date();
	today.fromSQL(server_today_str);

	fill_day_dropdown('competitor_soc_reg_day');
	fill_month_dropdown('competitor_soc_reg_month');
	fill_year_dropdown('competitor_soc_reg_year', today.year-start_soc_reg, today.year);
	fill_day_dropdown('horse_soc_reg_day');
	fill_month_dropdown('horse_soc_reg_month');
	fill_year_dropdown('horse_soc_reg_year', today.year-start_soc_reg, today.year);
	fill_day_dropdown('rider_soc_reg_day');
	fill_month_dropdown('rider_soc_reg_month');
	fill_year_dropdown('rider_soc_reg_year',today.year-start_soc_reg, today.year);
	fill_day_dropdown('owner_soc_reg_day');
	fill_month_dropdown('owner_soc_reg_month');
	fill_year_dropdown('owner_soc_reg_year',today.year-start_soc_reg, today.year);

/*this must be here - only now do we know what year it is*/
	fill_day_dropdown('competitor_dob_day');
	fill_month_dropdown('competitor_dob_month');
	fill_year_dropdown('competitor_dob_year', today.year-25, today.year);
	fill_day_dropdown('rider_dob_day');
	fill_month_dropdown('rider_dob_month');
	fill_year_dropdown('rider_dob_year', today.year-25, today.year);

	horse_auto_table.display_all_records();
	rider_auto_table.display_all_records();
	competitor_registrations_auto_table.display_all_records();
	horse_registrations_auto_table.display_all_records();
	rider_registrations_auto_table.display_all_records();
	owner_registrations_auto_table.display_all_records();
	horseshow_auto_table.display_all_records();
	showsection_auto_table.display_all_records();
	class_auto_table.display_all_records();
	basket_auto_table.display_all_records();

	var drop = gbi('competitor_DB_db_Title');
	for(var i=0; i < TitleDropdown.length; i++)
		drop.options[drop.options.length] = new Option(TitleDropdown[i], i);
	drop = gbi('owner_DB_db_Title');
	for(var i=0; i < TitleDropdown.length; i++)
		drop.options[drop.options.length] = new Option(TitleDropdown[i], i);
	drop = gbi('rider_DB_db_Title');
	for(var i=0; i < TitleDropdown.length; i++)
		drop.options[drop.options.length] = new Option(TitleDropdown[i], i);
	set_select('competitor_DB_db_Title', competitor_dataObj.fields['db_Title']);
	set_select('owner_DB_db_Title', owner_dataObj.fields['db_Title']);
	set_select('rider_DB_db_Title', rider_dataObj.fields['db_Title']);

	competitor_dataObj.display();
	gbi('competitor_DB_db_EmailRetype').value = competitor_dataObj.fields['db_Email'];
	DisplayCollapsing("home");


	fill_profile_droplists();

	if (cookie_selected != -1)
	{
		DisplayCollapsing("show");
		horseshow_auto_table.mousedown("horseshow_table_" + cookie_selected);
		handle_horseshow_mousedown();
	}
	document.cookie = "selected=-1; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/";

	if (competitor_dataObj.fields['db_IsEmulated'] == 0 )	
	{
		gbi('emulated_logoff').style.display = "none";
		if ((competitor_dataObj.fields['db_AccessLevel'] & 0x20)==0)
		{
			gbi("admin_only").style.display = "none";
			if ((competitor_dataObj.fields['db_AccessLevel'] & 0x02)==0)
				gbi("showsec_only").style.display = "none";
		}
	}
	else
	{
		gi('competitor_DB_db_Email').disabled = true;
		gi("competitor_DB_db_EmailRetype").style.visibility = "hidden";
		gbi("admin_only").style.display = "none";
		gbi("showsec_only").style.display = "none";
		gbi("ChangePasswordBtn").style.display = "none";
	}
	
	set_div_text("forthcoming_shows", "Forthcoming Shows on MyShowEntries.co.uk");		
}

function return_to_showsec()
{
	var hs = new hs_Transport();
	hs.ExitEmulation();
}


function fill_competitor_dataObj(obj)
{
}


/*add item to a dropdown list*/
function add_option_from_server(obj)
{
	var droplist = null;
	switch(obj.action)
	{
		case 'horse_sex':
			droplist = "horse_DB_db_Sex";
			break;
		case 'horse_height':
			droplist = "horse_DB_db_Height";
			break;
		case 'horse_height_cert':
			droplist = "horse_DB_db_CertificateType";
			break;
		case 'horse_registrations':
			droplist = "society_registrations";
			break;
	}
	if (droplist == null)
		return;
	
	var count = 0;		
	if (droplist != "society_registrations")
	{
		count = gbi(droplist).length;
		gbi(droplist).options[count] = new Option(obj.db_Value, obj.db_ID);
	}
	else
	{
		droplist = "competitor_society_registrations";
		count = gbi(droplist).length;
		gbi(droplist).options[count] = new Option(obj.db_Value, obj.db_ID);
		droplist = "horse_society_registrations";
		count = gbi(droplist).length;
		gbi(droplist).options[count] = new Option(obj.db_Value, obj.db_ID);
		droplist = "rider_society_registrations";
		count = gbi(droplist).length;
		gbi(droplist).options[count] = new Option(obj.db_Value, obj.db_ID);
		droplist = "owner_society_registrations";
		count = gbi(droplist).length;
		gbi(droplist).options[count] = new Option(obj.db_Value, obj.db_ID);

	}
}

function myMouseDown(e)
{
	var targ = getEventTarget(e, mousedown_event);
	var id = targ.id;
	if (id.indexOf("CALENDAR_") == 0 )
	{
		var dot = id.indexOf(".")-9; //9 = length of CALENDAR_
		var day = id.substr(dot+10);
		var cal = id.substr(9, dot);
		if ((eval(cal+"_CALENDAR")).Click(day, 0, 0) == true)
		{
			set_div_text(cal + "_CALENDAR_text", (eval(cal+"_CALENDAR")).sqGetHumanDateString());
			gbi(cal+"_wrapper").style.display = "none";
		}
	}
	else if (id.indexOf("BUTTON_CALENDAR_") == 0 )
	{
		var cal = "";
		if (id.indexOf("BUTTON_CALENDAR_PLUS_") == 0 )
		{
			cal = id.substr(21);
			(eval(cal+"_CALENDAR")).sqScroll(1);
		}
		else
		{
			cal = id.substr(22);
			(eval(cal+"_CALENDAR")).sqScroll(-1);
		}
	}

	if (targ.className == "auto_table_td" || targ.className == "horseshow_auto_table_td")
	{
		if (targ.id.indexOf("competitor_registrations_table") != -1)
			competitor_registrations_auto_table.mousedown(id);
		if (targ.id.indexOf("horse_registrations_table") != -1)
			horse_registrations_auto_table.mousedown(id);
		if (targ.id.indexOf("rider_registrations_table") != -1)
			rider_registrations_auto_table.mousedown(id);
		if (targ.id.indexOf("owner_registrations_table") != -1)
			owner_registrations_auto_table.mousedown(id);

		if (targ.id.indexOf("home_horseshow_table") != -1)
		{
			if (id.indexOf('enter') != -1)
			{
				DisplayCollapsing('show');
				home_horseshow_auto_table.mousedown(id);
				var sel = home_horseshow_auto_table.selected_index;
				/*emulate a mouse click on the horseshow_auto_table so when we switch to that page the correct item is selected*/
				horseshow_auto_table.mousedown("horseshow_table_" + sel);
				do_horseshow_display();
				get_showsection_for_show();
			}
			else if (id.indexOf('more') != -1)
			{
				DisplayCollapsing('show');
				home_horseshow_auto_table.mousedown(id);
				var sel = home_horseshow_auto_table.selected_index;
				/*emulate a mouse click on the horseshow_auto_table so when we switch to that page the correct item is selected*/
				horseshow_auto_table.mousedown("horseshow_table_" + sel);
				do_horseshow_display();
				get_showsection_for_show();
			}
		}
		else if (targ.id.indexOf("prizes_horseshow_table") != -1)
		{
			prizes_horseshow_auto_table.mousedown(id);
			handle_prizes_horseshow_mousedown();
		}
		else if (targ.id.indexOf("horseshow_table") != -1)
		{
			horseshow_auto_table.mousedown(id);
			handle_horseshow_mousedown();
		}
		if (targ.id.indexOf("showsection_table") != -1)
		{
			showsection_auto_table.mousedown(id);
			show_section_details();
			gbi('showclass_table_panel').style.display = "none";
			gbi('showclass_detail_panel').style.display = "none";
			set_closing_online_warning();
			get_classes_for_section();
		}
		if (targ.id.indexOf("class_table") != -1)
		{
			class_auto_table.mousedown(id);
			show_class_details();
		}
		
		if (targ.id.indexOf("home_horse_table") != -1)
		{
			home_horse_auto_table.mousedown(id);
			var sel = home_horse_auto_table.selected_index;
			/*emulate a mouse click on the horse_auto_table so when we switch to that page the correct item is selected*/
			horse_auto_table.mousedown("horse_table_" + sel);
			DisplayCollapsing("horse");
			get_data_for_horse();
		}
		else if (targ.id.indexOf("horse_table") != -1)
		{
			horse_auto_table.mousedown(id);
			get_data_for_horse();
		}
		if (targ.id.indexOf("rider_table") != -1)
		{
			rider_auto_table.mousedown(id);
			get_registrations_for_ID('rider');
			gbi('AddRiderSocReg').disabled = false;
		}
	}
}    

/*so we can handle clicks on the public page when we first arrive here, as well as actual clicks on the horseshow table*/
function handle_horseshow_mousedown()
{
	showsection_auto_table.deselect();
	class_auto_table.deselect();
	do_horseshow_display();
	get_showsection_for_show();
}

function handle_prizes_horseshow_mousedown()
{
	var id = prizes_horseshow_auto_table.selectedID;
	var hs = new hs_Transport();
	hs.GetPrizesForShow(id);
}



function do_horseshow_display()
{
	gbi('showsection_detail_panel').style.display = "none";
	gbi('showclass_table_panel').style.display = "none";
	gbi('showclass_detail_panel').style.display = "none";
	gbi('showsection_table_panel').style.display = "none";	
	gbi('basket_table_panel').style.display = "none";
    gbi('online_entry_show').style.display = "none";
	gbi('none_online_entry_show').style.display = "none";
	gbi('SHOW_DETAILS_PLUSMINUS').style.display = "block";

	gbi('show_entries').style.display = "none"; /*show_entries is the steps to entering a show*/

	if (horseshow_auto_table.not_selected() == true)
		return;
				
	if ((horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipLevel > 1)&&(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Published == 2))
		gbi('showsection_table_panel').style.display = "block";
				
	if (horseshow_auto_table.selected_index >= 0 )
	{
		gbi('horseshow_details_panel').style.display = "block";
		gbi('show_details_plus_minus_panel').style.display = "block";
	}
	else
		gbi('show_details_plus_minus_panel').style.display = "none";

	if (showsection_auto_table.selected_index >= 0 )
	{
		gbi('showsection_detail_panel').style.display = "block";
		gbi('showclass_table_panel').style.display = "block";
	}
	if (class_auto_table.selected_index >= 0 )
		gbi('showclass_detail_panel').style.display = "block";

	var sbd = new SB_Date();
	var sel = horseshow_auto_table.selected_index;

	var sbd_start = new SB_Date();
	var sbd_end = new SB_Date();
	sbd_start.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_FirstDay.substr(8));
	sbd_end.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_LastDay.substr(8));

	var additional = horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Extra.replace(/\|n/g, "<br/> ")
	var test = additional.replace(/ /g, "");
	if (test.length == 0 )
		additional = "";


	var addr  = detail_title(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowName );
	addr += detail_title(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowGround );
	addr+= detail_data(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Address1);
	addr+= detail_data(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Address2);
	addr+= detail_data(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Address3);
	addr+= detail_data(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Town);
	addr+= detail_data(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_County);
	addr+= detail_data(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_PostCode);
	addr+= detail_title_data("Phone: ", horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Phone);
	addr += detail_title_data("Email: ", "<a href='mailto:" + horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Email + "'>" + horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Email + "</a>");
	addr += detail_title_data("Web: ", "<a href='" + horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_URL + "'>" + horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_URL + "</a>");

	addr += detail_title_data("From:- ", sbd_start.get_date_string() + " - " + sbd_end.get_date_string() );	

/* NO MORE DISPLAY FOR BRONZE SHOWS*/
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipLevel == 1)
	{
		gbi('horseshow_details_panel').innerHTML = addr;
		gbi('horseshow_details_panel').style.display = "block";
		gbi('show_entries').style.display = "none";
		gbi('showsection_table_panel').style.display = "none";
		set_div_text("none_online_entry_show_text", "Online purchasing is not available for this show");
		gbi("online_entry_show").style.display = "none";
		gbi("none_online_entry_show").style.display = "block";
		return;
	}

/* ADD A "COMING SOON" MESSAGE FOR SILVER/GOLD SHOWS WHICH ARE NOT YET FULLY PUBLISHED AND RETURN*/
	var coming_soon = (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Published < 2);
	/*if user is showsec, viewing own show, then allow to view details*/
	var showsec_view_unpublished = false;
	if (coming_soon)
		showsec_view_unpublished = (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowsecID == competitor_dataObj.fields['db_ID']);

	if (coming_soon && (!showsec_view_unpublished))
	{
		addr += "<h6>Online details for this show are not yet available</h6>";
		if (additional.length > 0 )
			addr += detail_title_data("Additional info ", additional);
		gbi('horseshow_details_panel').innerHTML = addr;
		gbi('horseshow_details_panel').style.display = "block";
		gbi('show_entries').style.display = "none";
		gbi('showsection_table_panel').style.display = "none";
		if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipLevel == 3)
			set_div_text("none_online_entry_show_text", "Awaiting online purchasing details for this show");
		else
			set_div_text("none_online_entry_show_text", "Online purchasing is not available for this show");
		gbi("online_entry_show").style.display = "none";
		gbi("none_online_entry_show").style.display = "block";
		return;
	}

	var buy_online = false;
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipLevel == 3)
		buy_online = true;
	
	if (buy_online)
	{
		gbi('show_entries').style.display = "block"; /*show_entries is the steps to entering a show*/
		set_div_text('purchasing_show', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowName);
		set_closing_online_warning();	
		gbi("none_online_entry_show").style.display = "none";
		gbi("online_entry_show").style.display = "block";
	
		sbd.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ClosingDate_Online.substr(8));
		addr += detail_title_data("Closing Date for Online Entries:", sbd.get_date_string());
	}
	else
		addr += detail_title_data("Closing Date for Online Entries:", "NOT CURRENTLY AVAILABLE");

	sbd.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ClosingDate_Postal.substr(8));
	addr += detail_title_data("Closing Date for Postal Entries:", sbd.get_date_string());
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_EntriesOnDay == "1")
		addr += detail_title_data("Entries accepted on Day:", "Yes. Fee £" +  horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_EntriesOnDayFee);
	else
		addr += detail_title_data("Entries accepted on Day:", "No");
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowJumping == "0")
		addr += detail_title_data("Show Jumping:", "No");
	else
	{
		addr += detail_title_data("Show Jumping:", "Yes");
		if (buy_online)
		{
			sbd.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ClosingDate_ShowJumping_Online.substr(8));
			addr += detail_title_data("Closing Date for Show Jumping Online Entries: " ,  sbd.get_date_string() );
		}
		else
			addr += detail_title_data("Closing Date for Show Jumping Online Entries: " ,  "NOT CURRENTLY AVAILABLE" );

		sbd.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ClosingDate_ShowJumping_Postal.substr(8));
		addr += detail_title_data("Closing Date for Show Jumping Postal Entries: " , sbd.get_date_string() );
		if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowJumping_EntriesOnDay == "0")
			addr += detail_title_data("Show Jumping Entries accepted on day: ", "No");
		else
			addr += detail_title_data("Show Jumping Entries accepted on day: ", "Yes. Fee £" + horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowJumping_EntriesOnDayFee );
	}

	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Charity == '1')
		addr += detail_title_data("Charity Number", horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_CharityNumber);
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_VAT == '1')
		addr += detail_title_data("VAT Number", horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_VATNumber);
	if (additional.length > 0 )
		addr += detail_title_data("Additional info", additional);

	gbi('horseshow_details_panel').innerHTML = addr;
	gbi('horseshow_details_panel').style.display = "block";

	if (buy_online == false)
	{
		set_div_text("none_online_entry_show_text", "Online purchasing is not available for this show");
		gbi("online_entry_show").style.display = "none";
		gbi("none_online_entry_show").style.display = "block";

		if (showsec_view_unpublished)	
			set_div_text("none_online_entry_show_text", "*** PREVIEWING AN UNPUBLISHED SHOW ***");
//		get_showsection_for_show();
		return;
	}

	if (showsec_view_unpublished)	
	{
		set_div_text("none_online_entry_show_text", "*** PREVIEWING AN UNPUBLISHED SHOW ***");
		gbi("none_online_entry_show").style.display = "block";
		//gbi('payment_button').disabled = true;
	}
	else
	//	gbi('payment_button').disabled = false;


	gbi("online_entry_show").style.display = "block";
	gbi('show_entries').style.display = "block";
	set_closing_online_warning();
	gbi('basket_table_panel').style.display = "block";
	gbi("showsection_table_panel").style.display = "block";

	var show_membership = false;

	gbi('membership1').style.display = "none";
	gbi('membership2').style.display = "none";
	gbi('membership3').style.display = "none";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Membership.indexOf('1') != -1)
	{
		if((horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipDiscount1 != 0)&&(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPrice1 != 0))
		{	
			gbi('membership1').style.display = "block";
			show_membership = true;
		}
	}

	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Membership.indexOf('2') != -1)
	{
		if((horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipDiscount2 != 0)&&(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPrice2 != 0))
		{			
			gbi('membership2').style.display = "block";
			show_membership = true;
		}
	}
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Membership.indexOf('3') != -1)
	{
		if((horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipDiscount3 != 0)&&(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPrice3 != 0))
		{			
			gbi('membership3').style.display = "block";
			show_membership = true;
		}
	}

	if (show_membership == false)
		gbi('membership_wrapper').style.display = "none";
	else
		gbi('membership_wrapper').style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Stabling == 0 )
		gbi('stabling_wrapper').style.display = "none";
	else
		gbi('stabling_wrapper').style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Catalogue == 0 )
		gbi('catalogue_wrapper').style.display = "none";
	else
		gbi('catalogue_wrapper').style.display = "block";
		

	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_Pony == 0)
		gbi("span_stable_daily_pony").style.display = "none";
	else
		gbi("span_stable_daily_pony").style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_Stallion == 0)
		gbi("span_stable_daily_stallion").style.display = "none";
	else
		gbi("span_stable_daily_stallion").style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_MareFoal == 0)
		gbi("span_stable_daily_marefoal").style.display = "none";
	else
		gbi("span_stable_daily_marefoal").style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_Horse == 0)
		gbi("span_stable_daily_horse").style.display = "none";
	else
		gbi("span_stable_daily_horse").style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_HeavyHorse == 0)
		gbi("span_stable_daily_heavyhorse").style.display = "none";
	else
		gbi("span_stable_daily_heavyhorse").style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_HeavyHorse == 0)
		gbi("span_stable_daily_heavyhorse").style.display = "none";
	else
		gbi("span_stable_daily_heavyhorse").style.display = "block";

	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_Pony == 0)
		gbi("span_stable_show_pony").style.display = "none";
	else
		gbi("span_stable_show_pony").style.display = "block";
		
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_Stallion == 0)
		gbi("span_stable_show_stallion").style.display = "none";
	else
		gbi("span_stable_show_stallion").style.display = "block";
		
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_MareFoal == 0)
		gbi("span_stable_show_marefoal").style.display = "none";
	else
		gbi("span_stable_show_marefoal").style.display = "block";
		
		
		
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_Horse == 0)
		gbi("span_stable_show_horse").style.display = "none";
	else
		gbi("span_stable_show_horse").style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_HeavyHorse == 0)
		gbi("span_stable_show_heavyhorse").style.display = "none";
	else
		gbi("span_stable_show_heavyhorse").style.display = "block";
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_HeavyHorse == 0)
		gbi("span_stable_show_heavyhorse").style.display = "none";
	else
		gbi("span_stable_show_heavyhorse").style.display = "block";
		

	
	discount_str = "";
	var ar_discounts = Array();
	if ( horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPerks & 1)
		ar_discounts.push(" class entries");
	if ( horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPerks & 2)
		ar_discounts.push(" stabling");
	if ( horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPerks & 4)
		ar_discounts.push(" catalogue");
	if ( horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPerks & 8)
		ar_discounts.push(" first aid");

	var i=0;
	if (ar_discounts.length == 0 )
		discount_str = "";
	if (ar_discounts.length == 1)
		discount_str += ar_discounts[0];
	else
	{
		for (i=0; i < ar_discounts.length; i++)
		{
			discount_str += ar_discounts[i];
			if (i == ar_discounts.length-2)
				discount_str += " and ";
			else if (i < ar_discounts.length-1)
				discount_str += ", ";
		}
	}
	set_div_text("membership_discount_description", "Membership is available for this Show and gives a discount on " + discount_str);


	set_div_text('membership1_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPrice1);
	set_div_text('membership2_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPrice2);
	set_div_text('membership3_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipPrice3);
	set_div_text('membership1_discount', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipDiscount1 + "%");
	set_div_text('membership2_discount', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipDiscount2 + "%");
	set_div_text('membership3_discount', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipDiscount3 + "%");
	set_div_text('catalogue_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_CataloguePrice);

	set_div_text('pony_daily_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_Pony);
	set_div_text('stallion_daily_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_Stallion);
	set_div_text('marefoal_daily_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_MareFoal);
	set_div_text('horse_daily_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_Horse);
	set_div_text('heavyhorse_daily_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationDay_HeavyHorse);

	set_div_text('pony_show_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_Pony);
	set_div_text('stallion_show_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_Stallion);
	set_div_text('marefoal_show_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_MareFoal);
	set_div_text('horse_show_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_Horse);
	set_div_text('heavyhorse_show_accomodation_fee_display', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_AccomodationShow_HeavyHorse);

	set_div_text('membership_description1', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipOption1);
	set_div_text('membership_description2', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipOption2);
	set_div_text('membership_description3', horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipOption3);

	accomodation_checkin_CALENDAR.sqSetSelectableLimits(sbd_start.day, sbd_start.month, sbd_start.year, sbd_end.day, sbd_end.month, sbd_end.year);
	accomodation_checkout_CALENDAR.sqSetSelectableLimits(sbd_start.day, sbd_start.month, sbd_start.year, sbd_end.day, sbd_end.month, sbd_end.year);

//	get_showsection_for_show();

}

/*show registrations for 1 horse selected in horse auto table*/
function do_horse_registrations_display()
{
	var horse_id = horse_auto_table.selectedID;
	horse_registrations_auto_table.ar_filtered.length = 0;
	var i = 0;
	for (i=0; i < horse_registrations_auto_table.ar_unfiltered.length; i++)
	{
		if (horse_registrations_auto_table.ar_unfiltered[i].db_HorseID == horse_id)
			horse_registrations_auto_table.ar_filtered.push(horse_registrations_auto_table.ar_unfiltered[i]);
	}
	horse_registrations_auto_table.display_html_table();
}

function show_horse_details()
{
	str = detail_title_data("Name:" , horse_dataObj.fields['db_HorseName']);
	var sbd = new SB_Date();
	sbd.fromSQL(horse_dataObj.fields['db_DOB'].substr(8));
	str += detail_title_data("Sex: " , gbi('horse_DB_db_Sex').options[horse_dataObj.fields['db_SexID']-1].text);
	str += detail_title_data("DOB:" ,  sbd.get_date_string());
	str += detail_title_data("Colour: " , horse_dataObj.fields['db_Colour']);
	str += detail_title_data("Sire: " , horse_dataObj.fields['db_Sire']);
	str += detail_title_data("Dam: " ,horse_dataObj.fields['db_Dam']);
	str += detail_title_data("Breed: " , horse_dataObj.fields['db_Breed']);
	str += detail_title_data("Height: " , horse_dataObj.fields['db_HeightID']);
	str += detail_title_data("JMB Certificate: " , horse_dataObj.fields['db_JMBCertificate']);
	str += detail_title_data("Certificate Type: " , gbi('horse_DB_db_CertificateType').options[horse_dataObj.fields['db_CertificateTypeID']-1].text);
	str += detail_title_data("Passport: " , horse_dataObj.fields['db_Passport']);
	str += detail_title_data("Owner: " , owner_display);

	gbi('horse_detail_panel').innerHTML = str;
	gbi('horse_detail_panel').style.display = "block";
}

function edit_competitor_to_DB()
{
	var em1 = gbi('competitor_DB_db_Email').value;
	var em2 = gbi('competitor_DB_db_EmailRetype').value;
	if (em1 != em2)
	{
		alert('The email fields you have entered do not match');
		return;
	}
	competitor_dataObj.enableAllFields();
	competitor_dataObj.fillFieldsFromHTML();

	var strip_em = em1;
	var strip_firstname = competitor_dataObj.fields['db_FirstName'];
	var strip_lastname = competitor_dataObj.fields['db_LastName'];
	strip_em = strip_em.replace(/ /g, "");
	strip_firstname = strip_firstname.replace(/ /g, "");
	strip_lastname = strip_lastname.replace(/ /g, "");

	if (strip_firstname.length == 0 )
	{	
		alert("You must enter your first name!");
		return;
	}
	else if (strip_lastname.length == 0 )
	{	
		alert("You must enter your last name!");
		return;
	}
	else if (strip_em.length == 0 )
	{	
		alert("You must enter your email address!");
		return;
	}



	competitor_dataObj.fields['db_Title'] = gi('competitor_DB_db_Title').value;
	competitor_dataObj.fields['db_Over25'] = '0';
	if (gbi('Competitor_Over25').checked)
		competitor_dataObj.fields['db_Over25'] = '1';
	if (competitor_dataObj.fields['db_Over25'] == '0')
	{
		var d = gbi('competitor_dob_day').value;
		var m = gbi('competitor_dob_month').value;
		var y = gbi('competitor_dob_year').value;
		var dat = new SB_Date();
		dat.fromDMY(d, m, y);
		competitor_dataObj.fields['db_DOB'] = dat.get_sql_date();
	}
	competitor_dataObj.TX('edit_competitor');
}


//id, table, reg_id, reg_number, start) - can add registration to any of competitor, horse, owner, rider
function add_registration_to_DB(id)
{
	var reg_num;
	var dat = new SB_Date();
	var dl;
	var table;
	var assoc_id = -1; /*can be horse, owner, rider. or -1 for competitor, cos thats determined by barrier id*/

	switch(id)
	{
		 case 'competitor':			
			reg_num = gbi('competitor_society_number').value;
			dat.SetDateFromDropLists('competitor_soc_reg_day', 'competitor_soc_reg_month', 'competitor_soc_reg_year');
			var dl = gbi('competitor_society_registrations').value;
			table = COMPETITOR_REGISTRATION;
			assoc_id = -1;
			break;
		 case 'horse':			
			reg_num = gbi('horse_society_number').value;
			dat.SetDateFromDropLists('horse_soc_reg_day', 'horse_soc_reg_month', 'horse_soc_reg_year');
			var dl = gbi('horse_society_registrations').value;
			table = HORSE_REGISTRATION;
			assoc_id = gbi('select_horse_reg').value;
			break;
		 case 'rider':	
			if (rider_auto_table.selectedID	== -1)
			{
				alert("You must select a rider from the table opposite");
				return;
			}
			if (rider_auto_table.ar_filtered[rider_auto_table.selected_index]['db_IsCompetitor'] == '1')
			{
				alert("Please update registrations for yourself on your profile page");
				return;
			}

			reg_num = gbi('rider_society_number').value;
			dat.SetDateFromDropLists('rider_soc_reg_day', 'rider_soc_reg_month', 'rider_soc_reg_year');
			var dl = gbi('rider_society_registrations').value;
			table = RIDER_REGISTRATION;
			assoc_id = rider_auto_table.selectedID;
			break;
		 case 'owner':			
			if (gbi('reg_owner_droplist').options.length > 0 )
			{
				reg_num = gbi('owner_society_number').value;
				dat.SetDateFromDropLists('owner_soc_reg_day', 'owner_soc_reg_month', 'owner_soc_reg_year');
				var dl = gbi('owner_society_registrations').value;
				table = OWNER_REGISTRATION;
				assoc_id = gbi('reg_owner_droplist').value;
			}
			break;

	}
	if (id != 'competitor')
	{
		if (assoc_id <= 0)
		{
			if (id == "horse")
				alert("Please select a horse!");
			else if (id == "rider")
				alert("Please select a rider!");
			else
				alert("Please select an owner!");
			return;
		}
	}
	
	var suppress_message = 0;
	if (competitor_dataObj.fields['db_PromptMoreRegistrations'] == '1')
	{
		competitor_dataObj.fields['db_PromptMoreRegistrations'] = '0';
	    if (confirm("Your registration has been entered and is shown in the list below. \n To add more registrations, just fill in the form and submit it again for each registration.\n This applies to registrations for yourself, horses, riders and owners. \n (Press Cancel if you want to hide this message in future)") )
	        suppress_message = 0;
	    else
	        suppress_message = 1;
}

	var hs = new hs_Transport();
	hs.AddRegistrationToDB(assoc_id, table, dl, reg_num, dat.get_sql_date(), suppress_message);	
}

function delete_registration_from_DB(id)
{
	var table;
	var to_del;
	var to_del_ID ;
	var assoc_id; /*can be horse, owner, rider. or -1 for competitor, cos thats determined by barrier id*/


	switch(id)
	{
		case 'competitor':
			table = COMPETITOR_REGISTRATION;
			to_del = competitor_registrations_auto_table.selected_index;
			if (to_del < 0 || to_del > competitor_registrations_auto_table.ar_filtered.length)
			{
				alert("Select a registration to delete");
				return;
			}

			to_del_ID = competitor_registrations_auto_table.ar_filtered[to_del]['db_ID'];
			assoc_id = -1;
			break;
		case 'horse':
			table = HORSE_REGISTRATION;
			to_del = horse_registrations_auto_table.selected_index;
			if (to_del < 0 || to_del >horse_registrations_auto_table.ar_filtered.length)
			{
				alert("Select a horse registration to delete");
				return;
			}
			to_del_ID = horse_registrations_auto_table.ar_filtered[to_del]['db_ID'];
			assoc_id = gbi('select_horse_reg').value;
			break;
		case 'rider':
			table = RIDER_REGISTRATION;
			to_del = rider_registrations_auto_table.selected_index;
			if (to_del < 0 || to_del >rider_registrations_auto_table.ar_filtered.length)
			{
				alert("Select a rider registration to delete");
				return;
			}
			to_del_ID = rider_registrations_auto_table.ar_filtered[to_del]['db_ID'];
			assoc_id = rider_auto_table.selectedID;
			break;
		case 'owner':
			table = OWNER_REGISTRATION;
			to_del = owner_registrations_auto_table.selected_index;
			if (to_del < 0 || to_del >owner_registrations_auto_table.ar_filtered.length)
			{
				alert("Select a registration to delete");
				return;
			}
			to_del_ID = owner_registrations_auto_table.ar_filtered[to_del]['db_ID'];
			assoc_id = gbi('reg_owner_droplist').value;
			break;
	}

	var hs = new hs_Transport();		
	hs.DeleteRegistrationFromDB(table, to_del_ID, assoc_id);
}

/*this requires get horse registrations, owner, and owner registrations*/
function get_data_for_horse()
{
	var	to_get = horse_auto_table.selected_index;
	var to_get_ID = horse_auto_table.ar_filtered[to_get]['db_ID'];
	var hs = new hs_Transport();		
	hs.GetHorseRelatedFromDB( to_get_ID);	
}

function get_registrations_for_horse()
{	
	var id = gbi('select_horse_reg').value;
	if (id == -1)
	{
		alert("You have not entered any horses");
		return;
	}
	var hs = new hs_Transport();		
	hs.GetHorseRegistrationsFromDB(id);
}

function get_registrations_for_owner()
{
	var id = gbi('reg_owner_droplist').value;
	if (gbi('reg_owner_droplist').options.length == 0 )
	{
		alert("Your owner list is empty");
		return;
	}

	var hs = new hs_Transport();		
	hs.GetOwnerRegistrationsFromDB(id);
}


function get_registrations_for_ID(id)
{
	var table;
	var to_get;
	var to_get_ID ;

	switch(id)
	{
		case 'competitor':
			table = COMPETITOR_REGISTRATION;
			to_get_ID = -1;
			break;
		case 'horse':
			table = HORSE_REGISTRATION;
			to_get = horse_auto_table.selected_index;
			to_get_ID = horse_auto_table.ar_filtered[to_get]['db_ID'];
			break;
		case 'rider':
			table = RIDER_REGISTRATION;
			to_get = rider_auto_table.selected_index;
			to_get_ID = rider_auto_table.ar_filtered[to_get]['db_ID'];
			break;
	}

	var hs = new hs_Transport();		
	hs.GetRegistrationFromDB(table, to_get_ID);
}


/*************************************************************************************************************************************************************/
/*HORSE*/
/*************************************************************************************************************************************************************/
function add_horse_to_db()
{
	horse_dataObj.enableAllFields();
	horse_dataObj.fillFieldsFromHTML();
	var test = horse_dataObj.fields['db_HorseName'].replace(/ /g, "");
	if (test.length == 0 )
	{
		alert('Please enter a name for this horse');
		return;
	}

	var dob = new SB_Date();
	dob.SetDateFromDropLists('horse_dob_day', 'horse_dob_month', 'horse_dob_year');
	horse_dataObj.fields['db_DOB'] = dob.get_sql_date();
	horse_dataObj.fields['db_SexID'] = gbi('horse_DB_db_Sex').value;
	horse_dataObj.fields['db_HeightID'] = gbi('horse_DB_db_Height').value;
	horse_dataObj.fields['db_CertificateTypeID'] = gbi('horse_DB_db_CertificateType').value;
	horse_dataObj.fields['db_Active'] = '1';
	//owner field gets set to whatever is currently displaying for the last selected horse.
	//this is wrong so unset it
	horse_dataObj.fields['db_OwnerID'] = '-1';
//	horse_dataObj.debugFields();
	//return;


	horse_dataObj.TX('add_horse_to_db');
}


function delete_horse_from_db()
{
/*hide horse registrations, owner & owner registrations cos they are currently displaying data for this horse*/
	gbi('horse_detail_panel').style.display = "none";
	gbi('owner_registrations_table_panel').style.display = "none";
	gbi('horse_registrations_table_panel').style.display = "none";
	var sel = horse_auto_table.selected_index;
	if (sel == -1)
	{
		alert("You must select a horse to delete");
		return;
	}
	var id = horse_auto_table.ar_filtered[sel].db_ID;
	var hs = new hs_Transport();
	hs.DeleteHorseFromDB(id);
}

function delete_owner_from_db()
{
	var sel = gbi('delete_owner_droplist').value;
	var hs = new hs_Transport();
	var displayed_horse_id = horse_auto_table.selectedID;
	var displayed_owner_reg_id = gbi('reg_owner_droplist').value;
	/*if the owner selected in the reg droplist is the same as the one we are about to delete, send -1 as the id so we return an empty list*/
	if (displayed_owner_reg_id == sel)
		displayed_owner_reg_id = -1;
	hs.DeleteOwnerFromDB(sel, displayed_horse_id, displayed_owner_reg_id);
}

function delete_rider_from_db()
{
/*hide rider reg cos table refers to current selection*/
	gbi('rider_registrations_table_panel').style.display = "none";
	var sel = rider_auto_table.selected_index;
	if (sel == -1)
	{
		alert("Select a rider from the list");
		return;
	}

	if (rider_auto_table.ar_filtered[rider_auto_table.selected_index]['db_IsCompetitor'] == '1')
	{
		alert("You cannot delete yourself from this list!");
		return;
	}
	var id = rider_auto_table.ar_filtered[sel].db_ID;
	var hs = new hs_Transport();
	hs.DeleteRiderFromDB(id);
}

function add_horse_to_droplist(obj)
{
	var list = gbi('enter_horse_droplist');
	list.options[list.options.length] = new Option(obj.db_HorseName, obj.db_ID);
	list = gbi('horse_owner_droplist');
	list.options[list.options.length] = new Option(obj.db_HorseName, obj.db_ID);
	list = gbi('select_horse_reg');
	list.options[list.options.length] = new Option(obj.db_HorseName, obj.db_ID);
}

function add_rider_to_droplist(obj)
{
	var list = gbi('enter_rider_droplist');
	list.options[list.options.length] = new Option(get_title_string(obj) + obj.db_FirstName + " " + obj.db_LastName, obj.db_ID);
}

function add_owner_to_droplist(obj)
{
	var list = gbi('owner_droplist');
	list.options[list.options.length] = new Option(get_title_string(obj) + obj.db_FirstName + " " + obj.db_LastName, obj.db_ID);
	if (obj.db_IsCompetitor == 0)
	{	
		list = gbi('delete_owner_droplist');
		list.options[list.options.length] = new Option(get_title_string(obj) + obj.db_FirstName + " " + obj.db_LastName, obj.db_ID);
		list = gbi('reg_owner_droplist');
		list.options[list.options.length] = new Option(get_title_string(obj) + obj.db_FirstName + " " + obj.db_LastName, obj.db_ID);
	}
}



/*now done with radio?*/
function add_stable_to_droplist(obj)
{
return;
	var list = gbi('stable_droplist');
	list.options[list.options.length] = new Option(obj.display, obj.value);
}

function add_vehicle_to_droplist(obj)
{
	var list = gbi('vehicle_droplist');
	list.options[list.options.length] = new Option(obj.display, obj.value);
}

function get_showsection_for_show()
{
	showsection_auto_table.clear();
	gbi('showsection_detail_panel').style.display = "none";
	gbi('showclass_detail_panel').style.display = "none";
	gbi('showclass_table_panel').style.display = "none";

	if (horseshow_auto_table.not_selected())
		return;
		/*only get details if membership > bronze, and show is fully published*/
	if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_MembershipLevel > 1)
	{
		if (horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_Published == 2)
		{
			var hs = new hs_Transport();
			hs.GetSectionsAndBasketForShow(horseshow_auto_table.selectedID);	
		}
	}
}

function get_classes_for_section()
{
	class_auto_table.clear();
	var hs = new hs_Transport();
	hs.GetClassesForSection(showsection_auto_table.selectedID);	
}


function show_section_details()
{
	var sbd = new SB_Date();
	sbd.fromSQL(showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Date.substr(8));

	var data = detail_data(sbd.get_date_string() + "   " + showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_StartTime );
	
	data += detail_title_data("Fee: " ,showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Fee );
	
	data += detail_data( showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Description);
	data += detail_title_data("Ring: ",showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Ring  );
	
	data += detail_title_data("Ring Judge: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_RingJudge );
	data += detail_title_data("Ring Judge County: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_RingJudgeCounty );
	
	data += detail_title_data("Prize 1: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Prize1 );
	data += detail_title_data("Prize 2: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Prize2 );
	data += detail_title_data("Prize 3: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Prize3  );
	data +=detail_title_data("Prize 4: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Prize4 );
	data += detail_title_data("Prize 5: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Prize5 );
	data +=detail_title_data("Prize 6: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Prize6 );
	
	data += detail_title_data("Prize Champion: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_PrizeChampion );
	data += detail_title_data("Prize Reserve Champion: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_PrizeReserveChampion );
	data += detail_title_data("Entrants required to award prizes: " , showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_PrizeRequiredEntrants );



	gbi('showsection_detail_panel').innerHTML = data.replace(/\|n/g, "<br/> ");
	gbi('showsection_detail_panel').style.display = "block";

	set_div_text("purchasing_section", showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_Name);
	set_div_text("purchasing_class", "");
}

function show_class_details()
{
	var data  =  detail_data(class_auto_table.ar_filtered[class_auto_table.selected_index].db_Number + "   " + class_auto_table.ar_filtered[class_auto_table.selected_index].db_Time);
	data +=  detail_data(class_auto_table.ar_filtered[class_auto_table.selected_index].db_Info);
	data +=detail_title_data("Sponsor: " , class_auto_table.ar_filtered[class_auto_table.selected_index].db_Sponsor );
	data += detail_title_data("Qualifiers: ", class_auto_table.ar_filtered[class_auto_table.selected_index].db_Qualifiers);
	gbi('showclass_detail_panel').innerHTML = data.replace(/\|n/g, "<br/> ");
	gbi('showclass_detail_panel').style.display = "block";
	set_div_text("purchasing_class", class_auto_table.ar_filtered[class_auto_table.selected_index].db_ClassTitle);
}


function add_rider_to_DB()
{
	rider_dataObj.enableAllFields();
	rider_dataObj.fillFieldsFromHTML();
	rider_dataObj.fields['db_Over25'] = '0';
	if (gbi('Rider_Over25').checked)
		rider_dataObj.fields['db_Over25'] = '1';

	var dob = new SB_Date();
	dob.SetDateFromDropLists('rider_dob_day', 'rider_dob_month', 'rider_dob_year');
	rider_dataObj.fields['db_Title'] = gbi('rider_DB_db_Title').value;
	rider_dataObj.fields['db_DOB'] = dob.get_sql_date();
	rider_dataObj.fields['db_Active'] = '1';

	rider_dataObj.TX("add_rider_to_db");
}

function add_owner_to_DB()
{
	owner_dataObj.enableAllFields();
	owner_dataObj.fillFieldsFromHTML();

	var fn = owner_dataObj.fields['db_FirstName'];
	var sn = owner_dataObj.fields['db_LastName'];
	fn = fn.replace(/ /g, "");
	sn = sn.replace(/ /g, "");

	if (fn.length == 0 || sn.length == 0 )
	{
		alert("The owner must have a first and last name");
		return;
	}

	owner_dataObj.fields['db_ID'] = horse_auto_table.selectedID;
	owner_dataObj.fields['db_Title'] = gbi('owner_DB_db_Title').value;
	owner_dataObj.fields['db_IsCompetitor'] = '0';
	owner_dataObj.fields['db_Active'] = '1';
	var oar = owner_dataObj.array_for_DB();
	var hs = new hs_Transport();
	hs.AddOwnerToDB(oar);	
}

function select_owner_to_DB()
{
	var horse_id = gbi('horse_owner_droplist').value;
	if(horse_id == -1)
	{
		alert("You have not entered any horses");
		return;
	}
	var owner_id = gbi('owner_droplist').value;
	var displayed_horse_id = horse_auto_table.selectedID;
	var hs = new hs_Transport();
	hs.SetOwnerForHorse(owner_id, horse_id, displayed_horse_id);
}

function competitor_over25()
{
	var ch = gbi('Competitor_Over25').checked;
	gbi('competitor_dob_day').disabled = (ch==true);
	gbi('competitor_dob_month').disabled = (ch==true);
	gbi('competitor_dob_year').disabled = (ch==true);
}

function rider_over25()
{
	var ch = gbi('Rider_Over25').checked;
	gbi('rider_dob_day').disabled = (ch==true);
	gbi('rider_dob_month').disabled = (ch==true);
	gbi('rider_dob_year').disabled = (ch==true);
}


function accomodation_checkin_CALENDAR()
{
}

function accomodation_checkout_CALENDAR()
{
}

function button_press(id)
{
	if (id == "accomodation_checkin_CALENDAR")
	{
		if (accomodation_checkin_CALENDAR.visible)
			gbi('accomodation_checkin_wrapper').style.display = "none";
		else
			gbi('accomodation_checkin_wrapper').style.display = "block";
		accomodation_checkin_CALENDAR.visible = !accomodation_checkin_CALENDAR.visible;
	}
	if (id == "accomodation_checkout_CALENDAR")
	{
		if (accomodation_checkout_CALENDAR.visible)
			gbi('accomodation_checkout_wrapper').style.display = "none";
		else
			gbi('accomodation_checkout_wrapper').style.display = "block";
		accomodation_checkout_CALENDAR.visible = !accomodation_checkout_CALENDAR.visible;
	}
}


function DisplayCollapsing(id)
{

	if (id=="showsec")
	{
		window.location = "../showsec/showsec_index.html";
		return;
	}
	if (id=="admin")
	{
		window.location = "../admin/admin_index.html";
		return;
	}

	gbi('DIV_HOME_COLLAPSING').style.display = "none";
	gbi('DIV_MY_PROFILE_COLLAPSING').style.display = "none";
	gbi('DIV_HORSE_COLLAPSING').style.display = "none";
	gbi('DIV_RIDER_COLLAPSING').style.display = "none";
	gbi('DIV_SHOW_COLLAPSING').style.display = "none";
	gbi('DIV_DIARY_COLLAPSING').style.display = "none";
	gbi('DIV_PRIZES_COLLAPSING').style.display = "none";
	gbi('DIV_PASSWORD_COLLAPSING').style.display = "none";

	gbi('competitor_registrations_table_panel').style.display = "none";
	gbi('horse_registrations_table_panel').style.display = "none";
	gbi('owner_registrations_table_panel').style.display = "none";
	gbi('rider_registrations_table_panel').style.display = "none";
	gbi('basket_table_panel').style.display = "none";
	gbi('showsection_table_panel').style.display = "none";
	gbi('showclass_table_panel').style.display = "none";
	gbi('horse_table_panel').style.display = "none";
	gbi('horse_detail_panel').style.display = "none";
	gbi('rider_table_panel').style.display = "none";
	gbi('showsection_detail_panel').style.display = "none";
	gbi('showclass_detail_panel').style.display = "none";
	gbi('online_entry_show').style.display = "none";
	gbi('none_online_entry_show').style.display = "none";
	gbi('horseshow_details_panel').style.display = "none";	
	gbi('show_entries').style.display = "none";

	gbi('home_btn').style.backgroundColor = "#000000";
	gbi('profile_btn').style.backgroundColor = "#000000";
	gbi('horse_btn').style.backgroundColor = "#000000";
	gbi('rider_btn').style.backgroundColor = "#000000";
	gbi('show_btn').style.backgroundColor = "#000000";
	gbi('diary_btn').style.backgroundColor = "#000000";
	gbi('prizes_btn').style.backgroundColor = "#000000";


	switch (id)
	{
		case 'password':
			gbi("DIV_PASSWORD_COLLAPSING").style.display = "block";
			break;
		case 'diary':
			gbi("DIV_DIARY_COLLAPSING").style.display = "block";
			gbi('diary_btn').style.backgroundColor = "#1A3201";
			COLLAPSING_VISIBLE = DIARY_VISIBLE;
			break;
		case 'home':
			gbi('DIV_HOME_COLLAPSING').style.display = "block";
			gbi('home_btn').style.backgroundColor = "#1A3201";
			COLLAPSING_VISIBLE = HOME_VISIBLE;
		break;
		case 'profile':
			gbi('DIV_MY_PROFILE_COLLAPSING').style.display = "block";
			
			if (competitor_registrations_auto_table.ar_filtered.length > 0 )
				gbi('competitor_registrations_table_panel').style.display = "block";
			else
				gbi('competitor_registrations_table_panel').style.display = "none";
			gbi('profile_btn').style.backgroundColor = "#1A3201";				
			COLLAPSING_VISIBLE = PROFILE_VISIBLE;
		break;
		case 'horse':
			if (rider_auto_table.ar_filtered.length == 0 )
			{
				alert("Please complete your profile before entering this section");
				return;
			}
			gbi('DIV_HORSE_COLLAPSING').style.display = "block";
			COLLAPSING_VISIBLE = HORSE_VISIBLE;
			if (horse_auto_table.ar_filtered.length > 0 )				
				gbi('horse_table_panel').style.display = "block";
			else
				gbi('horse_table_panel').style.display = "none";
			if (horse_registrations_auto_table.ar_filtered.length > 0 )				
				gbi('horse_registrations_table_panel').style.display = "block";
			else
				gbi('horse_registrations_table_panel').style.display = "none";
			if (horse_auto_table.selected_index >= 0 )
				gbi('horse_detail_panel').style.display = "block";
			gbi('horse_btn').style.backgroundColor = "#1A3201";
		break;
		case 'rider':
			if (rider_auto_table.ar_filtered.length == 0 )
			{
				alert("Please complete your profile before entering this section");
				return;
			}
			gbi('DIV_RIDER_COLLAPSING').style.display = "block";
			if (rider_auto_table.ar_filtered.length > 0 )				
			{
				gbi('rider_table_panel').style.display = "block";
			//	rider_auto_table.scroll_to_end();
			}
			else
				gbi('rider_table_panel').style.display = "none";
			if (rider_registrations_auto_table.ar_filtered.length > 0 )				
				gbi('rider_registrations_table_panel').style.display = "block";
			else
				gbi('rider_registrations_table_panel').style.display = "none";
			gbi('rider_btn').style.backgroundColor = "#1A3201";
			COLLAPSING_VISIBLE = RIDER_VISIBLE;
		break;
		case 'show':
			if (COLLAPSING_VISIBLE == SHOW_VISIBLE)
				return;

			gbi('DIV_SHOW_COLLAPSING').style.display = "block";	
			gbi('show_btn').style.backgroundColor = "#1A3201";
			do_horseshow_display();
			COLLAPSING_VISIBLE = SHOW_VISIBLE;
			break;
		case 'prizes':
			gbi('DIV_PRIZES_COLLAPSING').style.display = "block";
			gbi('prizes_btn').style.backgroundColor = "#1A3201";
			COLLAPSING_VISIBLE = PRIZES_VISIBLE;
		break;
	}
}

function SetToolbarDisplay(id)
{
}


function PositionToolbar()
{
	//gbi("toolbar").style.top = getScrollY() +  "px";
}


function add_class_to_basket()
{
	var class_id = class_auto_table.selectedID;
	var horse_id = gbi('enter_horse_droplist').value;
	var rider_id = gbi('enter_rider_droplist').value;

	if (competitor_dataObj.fields['db_IsEmulated'] != 0 )	
	{
		var show_id = horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ShowsecID;
		if (show_id != competitor_dataObj.fields['db_IsEmulated'])
		{
			alert("You can only enter an offline competitor for a show where you are the Show Organiser!");
			return;
		}
	}
	if (class_id == -1)
	{
		alert("You must select a class to enter");
		return;
	}
	if (horse_id == -1)
	{
		alert("You must enter at least one horse!");
		return;
	}
	if (rider_id == -1)
	{
		alert("You must enter at least one rider!");
		return;
	}

	var hs = new hs_Transport();
	hs.AddClassToBasket(class_id, horse_id, rider_id);	
}

function add_accomodation_to_basket()
{
	var show_id = horseshow_auto_table.selectedID;
	if (show_id == -1)
	{
		alert("You must select a show (at the top of the page)");
		return;
	}
	var accom_type = 0;
	if (gi('stable_daily_radio_pony').checked)
		accom_type = 1;
	if (gi('stable_daily_radio_stallion').checked)
		accom_type = 2;
	if (gi('stable_daily_radio_marefoal').checked)
		accom_type = 3;
	if (gi('stable_daily_radio_horse').checked)
		accom_type = 4;
	if (gi('stable_daily_radio_heavyhorse').checked)
		accom_type = 5;
	if (gi('stable_show_radio_pony').checked)
		accom_type = 6;
	if (gi('stable_show_radio_stallion').checked)
		accom_type = 7;
	if (gi('stable_show_radio_marefoal').checked)
		accom_type = 8;
	if (gi('stable_show_radio_horse').checked)
		accom_type = 9;
	if (gi('stable_show_radio_heavyhorse').checked)
		accom_type = 10;
		
	if (accom_type == 0)
	{
		alert("You must select a type of accomodation");
		return;
	}

	var accom_start = accomodation_checkin_CALENDAR.sqGetSQLDateString();
	var accom_end = accomodation_checkout_CALENDAR.sqGetSQLDateString();


	if (accom_type < 5) //not duration of show
	{
		start = new SB_Date();
		start.fromDMY(accomodation_checkin_CALENDAR.selectedDay, accomodation_checkin_CALENDAR.selectedMonth, accomodation_checkin_CALENDAR.selectedYear);
		end = new SB_Date();
		end.fromDMY(accomodation_checkout_CALENDAR.selectedDay, accomodation_checkout_CALENDAR.selectedMonth, accomodation_checkout_CALENDAR.selectedYear);
		if (start.to_int() >= end.to_int() )
		{
			alert("Departure date must be later than arrival date!");
			return;
		}
	}

	var vehicle = gbi('vehicle_droplist').value;

	var hs = new hs_Transport();
	hs.AddAccomodationToBasket(show_id, accom_type, accom_start, accom_end, vehicle);	
}


function show_basket_discount_notice(obj)
{
	str = obj.description + " membership entitles you to " + obj.discount + "% discount on " + discount_str + ". Items marked with a * are discounted";
	set_div_text("basket_discount_panel", str);
}





function nav_to_showsec()
{
	window.location = "../showsec/showsec_index.html";
}



function logoff()
{
	var hs = new hs_Transport();
	hs.Logoff();
}

function do_pre_purchase()
{
	var show_id = horseshow_auto_table.selectedID;
	var hs = new hs_Transport();
	if (competitor_dataObj.fields['db_IsEmulated'] == 0 )		
		hs.PrePurchase(show_id);		
	else
		hs.Purchase(show_id);	
}

function do_paypal_purchase(obj)
{
	gbi('amount').value = obj.total;
	gbi('custom').value = obj.show_id + "-" + obj.competitor_id;
	gbi('item_name').value = "Purchases for " + obj.show_name;
	document.paypal_form.submit();
}

function add_membership()
{
	var member = -1;
	if (gi('PurchaseMembership1').checked)
		member = 1;
	if (gi('PurchaseMembership2').checked)
		member = 2;
	if (gi('PurchaseMembership3').checked)
		member = 3;
	if (member == -1)
	{
		alert("You must select a membership level");
		return;
	}

	var show_id = horseshow_auto_table.selectedID;
	if (show_id == -1)
	{
		alert("You must select a show (at the top of the page)");
		return;
	}
	var hs = new hs_Transport();
	hs.AddMembershipToBasket(show_id, member);	
}

function add_catalogue()
{
	var show_id = horseshow_auto_table.selectedID;
	if (show_id == -1)
	{
		alert("You must select a show (at the top of the page)");
		return;
	}
	var hs = new hs_Transport();
	hs.AddCatalogueToBasket(show_id);	
}

function remove_from_basket(index)
{
	var show_id = horseshow_auto_table.selectedID;
	var hs = new hs_Transport();
	hs.RemoveFromBasket(basket_auto_table.ar_filtered[index].db_ID, basket_auto_table.ar_filtered[index].db_Table, show_id);
}

function show_home_profile_details()
{
	var sbd = new SB_Date();
	var str = "";
	if (competitor_dataObj.fields['db_LastName']  == undefined)
		str = "not entered";
	else
	{	
		str = detail_title_data("Name: ", competitor_dataObj.fields['db_FirstName'] + "  " + competitor_dataObj.fields['db_LastName']);
		if (competitor_dataObj.fields['db_Over25'] == 0)
		{
			sbd.fromSQL(competitor_dataObj.fields['db_DOB'].substr(8));
			str += detail_title_data("DOB: ", sbd.get_date_string());
		}
		else
			str += detail_title_data("DOB: ", "N/A");
		str += detail_data(competitor_dataObj.fields['db_House']);
		str += detail_data(competitor_dataObj.fields['db_Address1']);
		str += detail_data(competitor_dataObj.fields['db_Address2']);
		str += detail_data(competitor_dataObj.fields['db_Address3']);
		str += detail_data(competitor_dataObj.fields['db_Town']);
		str += detail_data(competitor_dataObj.fields['db_County']);
		str += detail_data(competitor_dataObj.fields['db_PostCode']);
		str += detail_title_data("Phone: ", competitor_dataObj.fields['db_Phone']);
		str += detail_title_data("mobile: ", competitor_dataObj.fields['db_Mobile']);
		str += detail_title_data("Email: ", competitor_dataObj.fields['db_Email']);
	}
	gbi('home_profile_details').innerHTML = str;
}


function fill_profile_droplists()
{
	if (competitor_dataObj.fields['db_Over25'] != 1)
		fill_dob_dropdown('competitor_dob', competitor_dataObj.fields['db_DOB']);
}

function show_diary_table()
{
	var i=0; 
	for (i=0; i < diary_auto_table.ar_unfiltered.length; i++)
	{
		if (in_array(booking_list, diary_auto_table.ar_unfiltered[i]['db_ID']))
			diary_auto_table.ar_filtered.push(diary_auto_table.ar_unfiltered[i]);
	}
	diary_auto_table.display_html_table();
}


function show_server_status()
{
}

function hide_server_status()
{
}


function forgot_password()
{
	var mail = gbi('db_PassName').value;
	var hs = new hs_Transport();
	hs.RequestNewPwd(mail);
}

function change_password()
{
	var skip = false;
	var pwd1 = gbi('pwd1').value;
	var pwd2 = gbi('pwd2').value;

	if (pwd1 != pwd2)
	{
		skip = true;
		alert("The passwords you have entered do not match");
	}

	if (pwd1.length == 0 )
	{
		skip = true;
		alert("You must enter a password");
	}

	if (pwd1.length < 6 || pwd1.length > 8)
	{
		alert("Please enter a password of length 6 - 8 characters");
		skip = true;
	}

	if (skip)
	{
		gbi('pwd1').value = "";
		gbi('pwd2').value = "";
		return;
	}
	var hs = new hs_Transport();
	hs.SetNewPwd(pwd1);
}

function cancel_password()
{
	gbi('pwd1').value = "";
	gbi('pwd2').value = "";
	DisplayCollapsing('profile');
}

function init_expanded()
{
	gbi('PROFILE_PLUSMINUS').style.display = "block";
	gbi('PROFILE_REG_PLUSMINUS').style.display = "none";

	gbi('HORSE_PLUSMINUS').style.display = "block";
	gbi('HORSE_REG_PLUSMINUS').style.display = "none";
	gbi('OWNER_PLUSMINUS').style.display = "none";
	gbi('MANAGE_OWNER_PLUSMINUS').style.display = "none";
	gbi('OWNER_REG_PLUSMINUS').style.display = "none";

	gbi('SHOW_DETAILS_PLUSMINUS').style.display = "none";
	gbi('ENTER_CLASS_PLUSMINUS').style.display = "block";
	gbi('BUY_MEMBERSHIP_PLUSMINUS').style.display = "none";
	gbi('BUY_STABLING_PLUSMINUS').style.display = "none";
	gbi('BUY_CATALOGUE_PLUSMINUS').style.display = "none";
	gbi('show_details_plus_minus_panel').style.display = "none";

}

function panel_expand(click_elem)
{
	var elem = click_elem + "_PLUSMINUS";

	if (gbi(elem).style.display == "none")
		gbi(elem).style.display = "block";
	else
		gbi(elem).style.display = "none";
}


function handle_end_owner_list()
{
	if (gbi('reg_owner_droplist').options.length == 0 )
	{
		gbi('reg_owner_droplist').options[0] = new Option("none entered", -1);
		gbi('reg_owner_droplist').disabled = true;
		gbi('delete_owner_droplist').options[0] = new Option("none entered", -1);
		gbi('delete_owner_droplist').disabled = true;
		gbi('owner_registrations_table_panel').style.display = "none";
	}
	else
	{
		gbi('reg_owner_droplist').disabled = false;
		gbi('delete_owner_droplist').disabled = false;
		gbi('owner_registrations_table_panel').style.display = "block";
	}
}

function set_closing_online_warning()
{
	
	var sbdc = new SB_Date();
	if (showsection_auto_table.selected_index < 0 || showsection_auto_table.selected_index >= showsection_auto_table.ar_filtered.length)	
	{
		gbi('closing_date_online_warning').style.display = "none";
		return;
	}

	if(horseshow_auto_table.selected_index<0 || horseshow_auto_table.selected_index >= horseshow_auto_table.ar_filtered.length)
	{
		gbi('closing_date_online_warning').style.display = "none";
		return;
	}
	if (showsection_auto_table.ar_filtered[showsection_auto_table.selected_index].db_ClosingDate_ShowJumping == '1')
		sbdc.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ClosingDate_ShowJumping_Online.substr(8));
	else
		sbdc.fromSQL(horseshow_auto_table.ar_filtered[horseshow_auto_table.selected_index].db_ClosingDate_Online.substr(8));

	var online_closing = sbdc.get_date_string();
	set_div_text('closing_date_online_warning_text', online_closing);
	gbi('closing_date_online_warning').style.display = "block";
}


function start_prizes()
{
	ar_prizes.length = 0;
}

function prizes_add_section(obj)
{
	var sect = new prize_section_dataObj(obj);
	ar_prizes.push(sect);
}

function prizes_add_class(obj)
{
	var len = ar_prizes.length-1;
	var sect = ar_prizes[len];
	sect.add_class(obj);
}

function prizes_display()
{
	var str = "";
	var i=0; 
	for (i=0; i < ar_prizes.length; i++)
		str += ar_prizes[i].display(i);

	gbi('prizes_detail_panel').innerHTML = str.replace(/\|n/g, "<br/>");
	gbi('prizes_detail_panel').style.display = "block";
}





