
	var lastaction		= "";
	var selected		= "";
	var selection		= "";
		
	var divisionid		= "";
	var teamid			= "";
	var playerid		= "";
	var player_area		= "";
	var entrant_count	= 0;
	var entrants_html	= new Array();
	var entrants_email	= new Array();
	var entrants_contact= new Array();		
	var entrants_index	= new Array();
	var entrants_name	= new Array();

	///////////////////////////////////////////////////////
    function switchUserTeam()
	///////////////////////////////////////////////////////
	//
	//
	//		    
    {
        document.forms['general_variables']['TEAM'].value               = document.getElementById("PREF_TEAM").value;
        document.forms['general_variables']['USERNAME'].value           = document.getElementById("PREF_USERNAME").value;
        document.forms['general_variables']['PASSWORD'].value           = document.getElementById("PREF_PASSWORD").value;
        document.forms['general_variables']['USERDISPLAYNAME'].value    = document.getElementById("PREF_USERDISPLAYNAME").value;
        document.forms['general_variables']['EMAILADDRESS'].value       = document.getElementById("PREF_EMAILADDRESS").value;
        document.forms['general_variables']['EMAILNEWS'].value          = document.getElementById("PREF_EMAILNEWS").value;
        document.forms['general_variables']['EMAILRESULTS'].value       = document.getElementById("PREF_EMAILRESULTS").value;
        document.forms['general_variables']['EMAILDRAWS'].value         = document.getElementById("PREF_EMAILDRAWS").value;                                                                
        document.forms['general_variables']['STARTPAGE'].value          = document.getElementById("PREF_STARTPAGE").value;                                                                        
        redirect('USER_PREFERENCES');
    }

	///////////////////////////////////////////////////////	
	function displayNews()
	///////////////////////////////////////////////////////
	//
	//
	//		
	{
	    redirect("LATESTNEWS&NEWSID=" + document.getElementById("NEWSID").value);
	}

	///////////////////////////////////////////////////////	
	function validateUserMembership()
	///////////////////////////////////////////////////////
	//
	//
	//		
	{
	    if (document.getElementById("PREF_USERNAME").value.length < 6)
	    {
	        alert("User Name must be at least 6 characters");
	    }
	    else if (document.getElementById("PREF_PASSWORD").value.length == 0)
	    {
	        alert("You must enter a password");	    
	    }
	    else if (document.getElementById("PREF_PASSWORD").value != document.getElementById("PREF_PASSWORDCONFIRM").value)
	    {
	        alert("The passwords entered do not match");	    	    
	    }	    
	    else if (document.getElementById("PREF_USERDISPLAYNAME").value.length == 0)
	    {
	    	alert("You must enter a full name");	   
	    }   
	    else if (document.getElementById("PREF_EMAILADDRESS").value.length == 0)
	    {
	    	alert("You must enter an email address");	
	    }   
	    else if (document.getElementById("PREF_EMAILADDRESSCONFIRM").value != document.getElementById("PREF_EMAILADDRESS").value)
	    {
	        alert("The email addresses do not match");		    
	    }   	    
	    else
	    {
	        document.forms["general_variables"]["USERNAME"].value           = document.getElementById("PREF_USERNAME").value;
	        document.forms["general_variables"]["PASSWORD"].value           = document.getElementById("PREF_PASSWORD").value;
	        document.forms["general_variables"]["USERDISPLAYNAME"].value    = document.getElementById("PREF_USERDISPLAYNAME").value;
	        document.forms["general_variables"]["EMAILADDRESS"].value       = document.getElementById("PREF_EMAILADDRESS").value;
	        document.forms["general_variables"]["TEAM"].value               = document.getElementById("PREF_TEAM").value;
	        document.forms["general_variables"]["PLAYER"].value             = document.getElementById("PREF_PLAYER").value;
	        document.forms["general_variables"]["EMAILNEWS"].value          = document.getElementById("PREF_EMAILNEWS").value;
	        document.forms["general_variables"]["EMAILRESULTS"].value       = document.getElementById("PREF_EMAILRESULTS").value;
	        document.forms["general_variables"]["EMAILDRAWS"].value         = document.getElementById("PREF_EMAILDRAWS").value;	        
	        document.forms["general_variables"]["STARTPAGE"].value          = document.getElementById("PREF_STARTPAGE").value;	   	        
	        document.forms["general_variables"]["ACTION"].value             = "UPDATE";
	        redirect("USER_PREFERENCES");
	    }
	}	
	
	///////////////////////////////////////////////////////	
	function login()
	///////////////////////////////////////////////////////
	//
	//
	//		
	{
	    document.forms["general_variables"]["MANUALLOGIN"].value    = "YES";
		document.forms["general_variables"]["USERNAME"].value	    = document.forms["credentials"]["USERNAME"].value;
		document.forms["general_variables"]["PASSWORD"].value	    = document.forms["credentials"]["PASSWORD"].value;
		redirect("FUNC_USER_LOGIN");
	}	
	
	///////////////////////////////////////////////////////	
	function logout()
	///////////////////////////////////////////////////////
	//
	//
	//		
	{
		redirect("FUNC_USER_LOGOUT");
	}	
	
	///////////////////////////////////////////////////////	
	function populate_map_url(id)
	///////////////////////////////////////////////////////
	//
	//
	//			
	{
		var postcode = "";
		
		postcode	= document.forms[0]["POSTCODE" + id].value;
			
		if (postcode.length > 0)
		{
			document.forms[0]["MAPURL" + id].value = "http://maps.google.co.uk/maps?q=" + postcode + "&hl=en";
		}
		else
		{
			document.forms[0]["MAPURL" + id].value = "";
		}
	
	}

	///////////////////////////////////////////////////////	
	function performsearch(page)
	///////////////////////////////////////////////////////
	//
	//
	//		
	{
		document.forms["general_variables"]["CRITERIA"].value	= document.getElementById("CRITERIA").value; 		
		document.forms["general_variables"].action="?script=" + page;
		document.forms["general_variables"].submit();	
	}
	
	///////////////////////////////////////////////////////	
	function changeseason(page)
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
		var x=document.getElementById("NEWSEASONID");
		document.forms["general_variables"]["SEASONID"].value	= document.getElementById("NEWSEASONID").value;
		document.forms["general_variables"]["SEASONNAME"].value	= x.options[x.selectedIndex].text; 		
		document.forms["general_variables"].action="?script=SEASON_CHANGE";
		document.forms["general_variables"].submit();
	}	

	///////////////////////////////////////////////////////	
	function refreshtableview()
	///////////////////////////////////////////////////////
	//
	//	
	{
		document.forms["general_variables"]["PAGENAME"].value	= "TABLES";
		document.forms["general_variables"].action="?script=TABLES&ACTION=" + 
		                                            document.forms["leaguecontrols"]["LEAGUEDISPLAY"].value;
	    document.forms["general_variables"].target="";	
		document.forms["general_variables"].submit();	
	}
		
	///////////////////////////////////////////////////////	
	function redirect(page)
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
		document.forms["general_variables"]["PAGENAME"].value	=   page;
		document.forms["general_variables"].action              =   "?script=" + page;
	    document.forms["general_variables"].target              =   "";		
		document.forms["general_variables"].submit();
	}	

    ///////////////////////////////////////////////////////	
	function changefixtureperiod()
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
	    var period = document.getElementById("FIXTURE_PERIOD");
		document.forms["general_variables"]["PAGENAME"].value	= "FIXTURES";
		document.forms["general_variables"].action="?script=FIXTURES&PERIOD=" + period.value;
		document.forms["general_variables"].submit();
	}	
		
	///////////////////////////////////////////////////////		
	function windowpopup(url)
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
		document.forms["general_variables"].action=url;
		document.forms["general_variables"].target="_blank";
		document.forms["general_variables"].submit();
	}	
	
	
	///////////////////////////////////////////////////////	
	function redirectpopup(page)
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
		document.forms["general_variables"]["PAGENAME"].value	= page;
		document.forms["general_variables"].action="?script=" + page;
		document.forms["general_variables"].target="_blank";
		document.forms["general_variables"].submit();
	}	
	
	///////////////////////////////////////////////////////	
	function display_map_url()
	///////////////////////////////////////////////////////
	//
	//
	//		
	{
		id = selection.replace("venue","");
		
		if (id.length > 0)
		{
			var url = document.forms[0]["MAPURL" + id].value;
			window.open(url,"WinPrint","width=717,height=600,menubar=no,toolbar=no,scrollbars=yes");	
		}
		else
		{
			alert("Please select venue on which to view directions");
		}
	}
	
	///////////////////////////////////////////////////////		
	function highlight(id,colourOn,colourOff)
	///////////////////////////////////////////////////////
	//
	//
	//		
    {
        try
        {
            var cls = document.getElementById(id).className;
            document.getElementById(id).className = cls.replace(colourOff,colourOn);
        }
        catch (e)
        {        }
    }
    
	///////////////////////////////////////////////////////		
	function border(id,border)
	///////////////////////////////////////////////////////
	//
	//
	//		
    {
        try
        {
            var cls = document.getElementById(id).className;
            
            if (cls.indexOf(border) > 0)
            {
                document.getElementById(id).className = cls.replace(border,"");
            }
            else
            {
                document.getElementById(id).className = cls + " " + border;
            }
        }
        catch (e)
        {       }
    }    

	///////////////////////////////////////////////////////					
	function buildResultData()
	///////////////////////////////////////////////////////
	//
	//
	//		
	{
		var xml_out = new Array();
		var xml_string ='';
		var b = '';
		
		for (i=0; i < document.forms[0].elements.length;i++)
		{
			b = document.forms[0].elements[i].id;

			if (b.indexOf("fixture") >= 0)
			{
				var id = b.substring(7);
				try
				{
					var f = id;
					var h = document.getElementById("home" + id).value;
					var a = document.getElementById("away" + id).value;						
				}
				catch (e) {}	
				xml_out.push("<FIXTUREID>" + f + "</FIXTUREID><HOME>" + h + "</HOME><AWAY>" + a + "</AWAY>");	
			}
		}
		xml_string = xml_out.join(' ');
		//document.forms[0]["DATALIST"].value	= '<RESULTS>' + xml_string + '</RESULTS>';
		document.forms[0].submit();
	}
													

	///////////////////////////////////////////////////////						
	function validateField(field_name, field_type)
	///////////////////////////////////////////////////////
	//
	//
	//						
	{	
		if (field_type == 'Number')
		{
			IsNumericField('',field_name);
		}
		else if (field_type == 'Decimal')
		{
			IsDecimalField('',field_name);		
		}
		else if (field_type == 'Date')
		{
			IsDateField('',field_name);	
		}
	}
	
	///////////////////////////////////////////////////////						
	function CheckValue(s,i)
	///////////////////////////////////////////////////////
	//
	//
	//						
	{
		var t = document.forms[0][s + i].value;

		IsNumericField(i,s);
		
		if (t.length == 0)	
		{
			document.forms[0][s + i].value = '0';
		}
	}

	///////////////////////////////////////////////////////						
	function replaceChars(a,b,isTrue,isFalse)
	///////////////////////////////////////////////////////
	//
	//
	//
	{
		if (a == b)
		{
			return isTrue;
		}
		else
		{
			return isFalse;
		}
	}

	///////////////////////////////////////////////////////						
	function IsNumericField(i,t)
	///////////////////////////////////////////////////////
	//
	//		i = input field
	//		t =  name of text field
	//
	//		Stops the user front entering non-valid characters into field
	//		Valid characters are 0 to 9
	{	
		var validChars;
		var IsNumber;
				
		validChars = '0123456789';

		var s = document.forms[0][t + i].value;		

		for (n = 0; n < s.length; n++) 
		{ 
			var v = document.forms[0][t + i].value;	
			var c = s.charAt(n); 
			if (validChars.indexOf(c) == -1) 
			{	
				document.forms[0][t + i].value = v.replace(c,'');
			}
		}
	}
			
	///////////////////////////////////////////////////////						
	function IsDecimalField(i,t)
	///////////////////////////////////////////////////////
	//
	//		i = input field
	//		t =  name of text field
	//
	//		Stops the user front entering non-valid characters into field
	//		Valid characters are 0 to 9, "." and "-"
						
	{	

		var validChars;
		var IsNumber;
				
		validChars = '0123456789.';

		var s = document.forms[0][t + i].value;		

		for (n = 0; n < s.length; n++) 
		{ 
			var v = document.forms[0][t + i].value;	
			var c = s.charAt(n); 
			if (validChars.indexOf(c) == -1) 
			{	
				document.forms[0][t + i].value = v.replace(c,'');
			}
		}
	}

	///////////////////////////////////////////////////////						
	function IsDateField(i,t)
	///////////////////////////////////////////////////////
	//
	//		i = input field
	//		t =  name of text field
	//
	//		Stops the user front entering non-valid characters into field
	//		Valid characters are 0 to 9, "/" 
						
	{	

		var validChars;
		var IsNumber;
				
		validChars = '0123456789/';

		var s = document.forms[0][t + i].value;		

		for (n = 0; n < s.length; n++) 
		{ 
			var v = document.forms[0][t + i].value;	
			var c = s.charAt(n); 
			if (validChars.indexOf(c) == -1) 
			{	
				document.forms[0][t + i].value = v.replace(c,'');
			}
		}
	}

	///////////////////////////////////////////////////////
	function CheckValue(fieldname,id)
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
		var val = document.getElementById(fieldname + id);

//		if (val.value < 0 || val.value > 7)
//		{
//			alert("Invalid result value (0-7).");
//			val.value = '';
//		}
	}
	
	///////////////////////////////////////////////////////
	function CheckResult(fieldname,id,frames,bestof,mandatory)
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
		var val = document.getElementById("home" + id);		
		var val2 = document.getElementById("away" + id);

//		if (val.value.length == 0)
//		{
//			val.value = 0;
//		}
		
//		if (val2.value.length == 0)
//		{
//			val2.value = 0;
//		}
				
		// Check if the number of frames played in the result is equal to the
		// number of frames required to be played e.g. best of 5 may need all 5 frames
		// to be played (if a league match) or just 3 frames (if a KO match)
		if ((parseInt(bestof) > (parseInt(val.value) + parseInt(val2.value))) && mandatory == "Y")
		{
			alert("Invalid scores. The match is best of " + bestof + " frames");
		}
		else if ((parseInt(bestof) < (parseInt(val.value) + parseInt(val2.value))))
		{
			alert("Invalid scores. The match is best of " + bestof + " frames");
		}		
		// Check to see if one of the scores equals the frames requred for a win
		else if ((parseInt(val.value) != parseInt(frames)) && (parseInt(val2.value) != parseInt(frames)))
		{
			alert("Invalid score. The match is the first to " + frames + " frames");
		}
	}
		
	///////////////////////////////////////////////////////
	function showhide_fixture(fieldname)
	///////////////////////////////////////////////////////
	//
	//
	//	
	{
		var f = document.getElementById(fieldname);		
		var display = f.style.display ? '' : 'none';
		f.style.display = display;

	}	
		
	///////////////////////////////////////////////////////						
	function round_decimals(n, places) 
	///////////////////////////////////////////////////////
	//
	//
	//						
	{
		var a;
		var b;
		var c;														

		
		a = n * Math.pow(10, places);
		b = Math.round(a);
		c = b / Math.pow(10, places);
		return pad_with_zeros(c,places);
	}

	///////////////////////////////////////////////////////
	function pad_with_zeros(rounded_value, decimal_places) 
	///////////////////////////////////////////////////////
	//
	//
	//						
	{
		var value_string = rounded_value.toString();
		var decimal_location = value_string.indexOf(".");

		if (decimal_location == -1) 
		{
			decimal_part_length = 0;
			value_string += decimal_places > 0 ? "." : "";
		}
		else 
		{

			// If yes, then only the extra decimal places will be padded with 0s
			decimal_part_length = value_string.length - decimal_location - 1;
		}
		
		// Calculate the number of decimal places that need to be padded with 0s
		var pad_total = decimal_places - decimal_part_length;
		
		if (pad_total > 0) 
		{
			
			// Pad the string with 0s
			for (var counter = 1; counter <= pad_total; counter++) 
			{
				value_string += "0";
			}
		}
		return value_string;
	}

	function itemSelector(s)
	{
		if (selection != "")
		{	
			var d = document.getElementById(selection);
			d.className = "app_icon_record_selector_off";
		}
		
		var c = document.getElementById(s);

		try
		{		
			if (c.className == "app_icon_record_selector_off" && s != selection)
			{
				c.className = "app_icon_record_selector_on";
				selection = s;
			}
			else
			{
				c.className = "app_icon_record_selector_off";
				selection = "";
			}
		}
		catch (e) {}
	}	
	
	function viewExtraDetail(id)
	{
	
		var selector  = document.getElementById(id + '_record_selector');
		var isVisible = document.getElementById(id + '_visible');
		if (isVisible.value == "true")
		{
			setVisibility([id + '_hidden'],false);	
			isVisible.value = "false";
			selector.className = "app_icon_record_selector_open";
		}
		else
		{
			setVisibility([id + '_hidden'],true);	
			isVisible.value = "true";
			selector.className = "app_icon_record_selector_close";
		}

	}	
	
	function setVisibility(aFieldList, bVisibility)	
	{
		var sVisibility = bVisibility ? "" : "none";
		for(var i = 0 ; i < aFieldList.length ; i++)
		{
			oElement = document.getElementById(aFieldList[i]);
			if( oElement )
			{
				oElement.style.display = sVisibility;
			}
		}
	}



	function show_status_bar() 
	{ 
		var sb= document.getElementById('status_bar'); 
		var nv= document.getElementById('gen_navigation');
		var pc= document.getElementById('gen_pagecontent');
				
		sb.style.visibility	= "visible"; 
		sb.style.display	="inline"; 

		nv.style.visibility	= "hidden"; 
		nv.style.display	="none"; 

		pc.style.visibility	= "hidden"; 
		pc.style.display	="none"; 

		
		sb.src = '../Images/icon-status-bar.gif';
	} 
	

	function trimAll(sString)
	{
		while (sString.substring(0,1) == '' && sString.length >= 1)
		{
			sString = sString.substring(1, sString.length);
		}
		
		while (sString.substring(sString.length-1, sString.length) == ' '  && sString.length >= 1)
		{
			sString = sString.substring(0,sString.length-1);
		}
		
		return sString;
	}

	function selectEntrantContact(id)
	{
		var n;
		
		selectItem(id);
		
		for (var i = 0;i < entrants_index.length;i++)
		{
			n = entrants_index[i];
			
			if (n == id)
			{
				document.forms[0]["ENTRANTCONTACT"].value	= entrants_contact[i];
				document.forms[0]["ENTRANTEMAIL"].value		= entrants_email[i];
			}
		}					
	}

	function selectItem(id)
	{
		// If already something selected unselect it!
		if (selection != "")
		{
			document.getElementById(selection).className = "admin-selector";	
		}
		selected = id;
	
		try
		{
			var e = document.getElementById(id);
			var i = e.className;

			if (i == "admin-selector")
			{
				e.className = "admin-selector-on";
			}
			else
			{
				e.className = "admin-selector";		
			}
			
			selection = id;
		}
		catch (e) {}
	}

	function frame_target(bestof)
	{
		var frames;
		
		frames = Math.round(bestof/2);
		
		return frames;
	}
	
	
	
	function roll_over(id,class1,class2)
	{
		i = document.getElementById(id);
		
		if (i.className == class2)
		{
			i.className = class1;
		}
		else
		{
			i.className = class2;
		}
	}
	
// display a popup window at the specified location

// with the specified text

	function ShowPopup(text, x, y, width, height)
	{

		var Popup= window.createPopup();

		var DocBody = Popup.document.body;

		DocBody.style.backgroundColor="lightyellow";

		DocBody.style.border = "solid black 1px";

		// replace new lines with breaks

		while(text.indexOf("\n") > -1)

		{

					text = text.slice(0, text.indexOf("\n")) + "<br\>"  + text.slice(text.indexOf("\n") + 1, -1);

		}

		//setup the font size etc

		DocBody.innerHTML = "<p style=\"COLOR: black; FONT-SIZE : 11px; FONT-WEIGHT : bold\">" + text + "<\p>";

		Popup.show(x,y,width,height, document.body);
	}

	
	function action(actiontype,action,id)
	{
		var nopost = false;
	
		if (action == "VIEW" || action == "SAVE" || action == "TEAMMOVE" || action == "NEW" || action == "CONFIRM" || id.length > 0)
		{
			selected = actiontype.toLowerCase() + id;
		}					
		if (actiontype == "ADMIN_LEAGUE_CONTACTS")
		{
			selected = selection.replace("contact","");				
			
			if (action == "SAVE_CONTACT" || action == "DELETE_CONTACT")
			{
				if (selected.length == 0)
				{
					alert("You must first select a league contact before you perform this action.");
					nopost = true;					
				}
				else
				{
					document.forms[0].action="asp/db_interface.asp"
					document.forms[0]["CONTACTID"].value	= selected; 
					document.forms[0]["CONTACT"].value		= document.forms[0]["contactname" + selected].value;
					document.forms[0]["CONTACTPHONE"].value	= document.forms[0]["phone" + selected].value;	
					document.forms[0]["CONTACTEMAIL"].value	= document.forms[0]["email" + selected].value;						
				}
			}
		}
		else if (actiontype == "LATESTNEWS")
		{
			if (action == "ADD")
			{
				document.forms[0].target = "";
				document.forms[0].action = "asp/db_interface.asp";
			}
			else
			{
				document.forms[0].action = "?script=ADMIN_LATEST_NEWS_PREVIEW";				
			}
		}
		else if (actiontype == "ADMIN_LEAGUE_RULES")
		{
			selected = selection.replace("rule","");	
				
			if (action == "DELETE_RULE" || action == "EDIT_RULE")
			{	
				if (selected.length == 0)
				{
					alert("You must first select a rule before you perform this action.");
					nopost = true;					
				}				
				document.forms[0]["RULEID"].value	= selected; 
			}			
		}		
		else if (actiontype == "ADMIN_LEAGUE_SPONSORS")
		{
			selected = selection.replace("sponsor","");				
			
			if (action == "SAVE_SPONSOR" || action == "DELETE_SPONSOR" || action =="EDIT_SPONSOR_IMAGE")
			{
				if (selected.length == 0)
				{
					alert("You must first select a league sponsor before you perform this action.");
					nopost = true;					
				}
				else
				{
					document.forms[0].action="asp/db_interface.asp"
					document.forms[0]["SPONSOR-ID"].value	= selected; 
					document.forms[0]["SPONSOR"].value		= document.forms[0]["Sponsor" + selected].value;
					document.forms[0]["SPONSOR-DESC"].value	= document.forms[0]["Sponsor-desc" + selected].value;								
					document.forms[0]["SPONSOR-LOGO"].value	= document.forms[0]["Sponsor-logo" + selected].value;											
				}
			}
			else if (action == "ADD_SPONSOR_LOGO")
			{
				if (document.forms[0]["SPONSOR-ID"].value.length == 0)
				{
					alert("You must first select a league sponsor before you perform this action.");
					nopost = true;					
				}			
				else
				{
					document.forms[0].encoding="multipart/form-data";
					document.forms[0].action="asp/file_interface.asp" 
				}
			}
		}
		else if (actiontype == "ADMIN_LEAGUE_DIVISIONS")
		{
			if (action == "SAVE_DIVISION" || action == "DELETE_DIVISION")
			{
				if (selection.length == 0)
				{
					alert("You need to select a division to save/delete.");
					nopost = true;
				}		
				else
				{
					selected = selection.replace("division","");
					document.forms[0]["DIVISIONID"].value	= selected;
					document.forms[0]["DIVISIONNAME"].value	= document.forms[0]["Name" + selected].value;		
				}				
			
			}
			else if (action == "VIEW_TEAMS")
			{
				if (selection.length == 0)
				{
					alert("You need to select a division to view teams for");
					nopost = true;
				}
				else
				{
					selected = selection.replace("division","");
					document.forms[0]["DIVISIONID"].value	= selected;
//					document.forms[0]["DIVISIONNAME"].value	= document.forms[0]["Name" + id].value;		
				}
			}
			else if (action == "VIEW_TEAM_DETAIL" || action == "SAVE_TEAM_DETAILS")
			{
				document.forms[0]["TEAMID"].value	= id;
				
				try
				{
					document.forms[0]["VENUEID"].value = document.forms[0]["VENUE_NAME"].value;
				}
				catch (e) {}
			}
			else if (action != "ADD_DIVISION" && action != "VIEW_TEAMS")
			{
		
				if (id.length == 0)
				{
					document.forms[0]["DIVISIONID"].value	= id;
					document.forms[0]["DIVISIONNAME"].value	= document.forms[0]["Name" + id].value;		
				}
				else if (selection.length == 0)
				{
					document.forms[0]["DIVISIONID"].value	= 0;
					document.forms[0]["DIVISIONNAME"].value	= document.forms[0]["Name0"].value;					
				}
				else
				{
					selected = selection.replace("division","");
					document.forms[0]["DIVISIONID"].value	= selected;
					document.forms[0]["DIVISIONNAME"].value	= document.forms[0]["Name" + selected].value;		
				}	
			}
		}
		else if (actiontype == "ADMIN_LEAGUE_TEAMS")
		{
			if (selection.length == 0 && action != "ADD_TEAM")
			{
				alert("You need to select a team in order to perform this action");
				nopost = true;
			}		
			else if (action == "SAVE_TEAM_DETAILS")
			{
				if (selection.length > 0)
				{
					selected = selection.replace("team","");
					document.forms[0]["TEAMID"].value			= selected;
					document.forms[0]["TEAMNAME"].value			= document.forms[0]["TEAMNAME"		+ selected].value;
					document.forms[0]["CONTACTID"].value		= document.forms[0]["CONTACT_NAME"	+ selected].value;
					document.forms[0]["SHORTTEAMNAME"].value	= document.forms[0]["SHORTTEAMNAME" + selected].value;
					document.forms[0]["VENUEID"].value			= document.forms[0]["VENUE_NAME"	+ selected].value;
					document.forms[0]["DIVISIONID"].value		= document.forms[0]["DIVISION_NAME" + selected].value;
				}
			}
			else if (action == "DELETE_TEAM")
			{
				document.forms[0]["TEAMID"].value			= selected.replace("team","");
			}			
			else if (action == "SAVE_PLAYER")
			{
				if (selection.length > 0)
				{
					selected = selection.replace("player","");
					
					document.forms[0]["PLAYERID"].value			= selected;
					document.forms[0]["PLAYERNAME"].value		= document.forms[0]["PLAYERNAME"		+ selected].value;
					document.forms[0]["PLAYEREMAIL"].value		= document.forms[0]["PLAYEREMAIL"		+ selected].value;
					document.forms[0]["PLAYERCONTACT"].value	= document.forms[0]["PLAYERCONTACT"		+ selected].value;
					document.forms[0]["PLAYERTEAMID"].value		= document.forms[0]["PLAYER_TEAMNAME"	+ selected].value;
				}			
			}
			else if (action == "VIEW_PLAYERS")
			{
				document.forms[0]["TEAMID"].value			= selected.replace("team","");
			
			}
			else if (action == "DELETE_PLAYER")
			{
				document.forms[0]["PLAYERID"].value			= selected.replace("player","");
			}
		}
		else if (actiontype == "ADMIN_LEAGUE_FIXTURES")
		{
			if (action == "GENERATE_FIXTURES")
			{
				alert("Unfortunately this functionality is not currently available.");
				nopost = true;
			
				//var agree=confirm("WARNING: This will remove any fixtures created for your league season and create a whole new set of fixtures. Are you sure you want to continue?");
				//if (!agree)
				//{
				//	nopost = true;
				//}
			}		
			else if (action == "VIEW_TEAM_FIXTURES")
			{
				document.forms[0]["TEAMID"].value = id;
				document.forms[0]["FIXTUREDATE"].value = "";
			}
			else
			{
				document.forms[0]["FIXTUREDATE"].value = id;
			}
		}		
		else if (actiontype == "ADMIN_LEAGUE_PLAYER_RESULTS")
		{
			document.forms[0]["RESULTDATE"].value = id;
		}
		else if (actiontype == "ADMIN_LEAGUE_TEAM_RESULTS")
		{
			document.forms[0]["RESULTDATE"].value = id;
		}		
		else if (actiontype == "ADMIN_LEAGUE_PLAYERS")
		{
			if (selection.length == 0 && action != "ADD_PLAYER")
			{
				alert("You need to select a player in order to perform this action");
				nopost = true;
			}			
			else if (action == "TRANSFER_PLAYER")
			{
				document.forms[0]["PLAYERID"].value = selection.replace("player","");
			}
			else if (action == "DELETE_PLAYER")
			{
				document.forms[0]["PLAYERID"].value = selection.replace("player","");
			}			
			else if (action == "SAVE_PLAYER")
			{
				selected = selection.replace("player","");
				document.forms[0]["PLAYERID"].value			= selected;
				document.forms[0]["PLAYERNAME"].value		= document.forms[0]["PLAYERNAME"		+ selected].value;
				document.forms[0]["PLAYEREMAIL"].value		= document.forms[0]["PLAYEREMAIL"		+ selected].value;
				document.forms[0]["PLAYERCONTACT"].value	= document.forms[0]["PLAYERCONTACT"		+ selected].value;
				document.forms[0]["PLAYERTEAMID"].value		= document.forms[0]["PLAYER_TEAMNAME"	+ selected].value;
			}
		}
		else if (actiontype == "ADMIN_LEAGUE_VENUES")
		{
			if (selection.length == 0 && action != "ADD_VENUE")
			{
				alert("You need to select a venue in order to perform this action");
				nopost = true;
			}			
			else if (action == "DELETE_VENUE")
			{
				document.forms[0]["VENUEID"].value = selection.replace("venue","");
			}			
			else if (action == "SAVE_VENUE")
			{
				selected = selection.replace("venue","");
				document.forms[0]["VENUEID"].value		= selected;
				document.forms[0]["NAME"].value			= document.forms[0]["VENUE_NAME"		+ selected].value;
				document.forms[0]["TELEPHONE"].value	= document.forms[0]["VENUE_TELEPHONE"	+ selected].value;
				document.forms[0]["ADDRESS1"].value		= document.forms[0]["ADDRESS1"			+ selected].value;
				document.forms[0]["TOWN"].value			= document.forms[0]["TOWN"				+ selected].value;
				document.forms[0]["POSTCODE"].value		= document.forms[0]["POSTCODE"			+ selected].value;
				document.forms[0]["NOMATCHES"].value	= document.forms[0]["NOMATCHES"			+ selected].value;								
				document.forms[0]["MAPURL"].value		= document.forms[0]["MAPURL"			+ selected].value;												
			}
		}		

		else if (actiontype == "ADMIN_COMPETITION_LIST")
		{
			if (selection.length == 0 && (action != "ADD_COMPETITION" && action != "CANCEL_COMPETITION"))
			{
				alert("You need to select a competition to perform this action.");
				nopost = true;
			}	
			else
			{
				id		= selection.replace("competition","");

				try
				{
					document.forms[0]["COMPETITIONID"].value		= id;
					document.forms[0]["COMPETITIONPLAYERS"].value	= document.forms[0]["competitionplayers" + id].value;
					document.forms[0]["COMPETITIONNAME"].value		= document.forms[0]["competitionname" + id].value;	
					document.forms[0]["COMPETITIONTYPE"].value		= document.forms[0]["competitiontype" + id].value;
				}
				catch (e) {}					
			}
		}
		else if (actiontype == "ADMIN_COMPETITION_RESULTS")
		{
			if (action == "VIEW_ROUNDS")
			{
				if (selection.length == 0)
				{
					alert("You need to select a competition to perform this action.");
					nopost = true;
				}	
				else
				{
					document.forms[0]["COMPETITIONID"].value		= selection.replace("competition","");
				}
			}
			else
			{
				document.forms[0]["COMPETITIONSTATUSID"].value	= id;
			}						
		}		
		else if (actiontype == "ADMIN_COMPETITION_DRAWS")
		{
			if (action == "VIEW_ROUNDS" || action == "CALC_ROUNDS" || action == "UPDATE_ROUNDS")
			{
				if (selection.length == 0)
				{
					alert("You need to select a competition to perform this action.");
					nopost = true;
				}	
				else if (action == "CALC_ROUNDS")
				{
					if (document.forms[0]["drawstatus" + selection.replace("competition","")].value.length > 0)
					{
						var agree = confirm("The rounds for this competition has already been created. Are you sure you want to re-calcuate the competition rounds?");
						if (!agree)
						{
							nopost = true;
						}
					}
				}
			}		
					
			if (action == "VIEW_DRAW" || action == "VIEW_ENTRANTS")
			{
				try
				{
					document.forms[0]["COMPETITIONSTATUSID"].value	= id;	
				}
				catch (e) {}				
			}
			else if (action != "UPDATE_ROUNDS" && action != "DRAW_SETUP" && action != "MAKE_DRAW" && action != "CONFIRM_DRAW")
			{
				document.forms[0]["COMPETITIONID"].value		= selection.replace("competition","");
				try
				{		
					//document.forms[0]["COMPETITIONENTRANTS"].value	= document.forms[0]["entrants" + id].value;
					document.forms[0]["COMPETITIONENTRANTS"].value	= document.forms[0]["entrants" + document.forms[0]["COMPETITIONID"].value].value;
				}
				catch (e) {}
			}	
		}		
		else if (actiontype == "ADMIN_COMPETITION_ENTRANTS")
		{
			if (action == "VIEW_ENTRANTS" || action == "EDIT_ENTRANT" || action == "DELETE_ENTRANT")
			{
				if (selection.length == 0)
				{
					alert("You need to select a competition to perform this action.");
					nopost = true;
				}	
				else
				{
					if (action == "EDIT_ENTRANT" || action == "DELETE_ENTRANT")
					{
						document.forms[0]["ENTRANTID"].value	= selected.replace("admin_competition_entrants","");
					}
					else
					{
						document.forms[0]["COMPETITIONID"].value	= selected.replace("admin_competition_entrants","");
					}
				}
			}				
			else if (selected.length != 0)
			{
				document.forms[0]["COMPETITIONID"].value	= selected.replace("admin_competition_entrants","");
			}
			 
			if ( action == "ADD_ENTRANT")
			{
				document.forms[0]["ENTRANTID"].value = '';
			}
			
			if (action == "CANCEL_ADD_ENTRANT")
			{
				action = "VIEW_ENTRANTS";
			}
			
			if (action == "SAVE_ENTRANT" || action == "UPDATE_ENTRANT")			
			{
				var n;
				var ids			= "";
				var names		= "";
				var name		= "";
				var space		= 0;
				var displayname = "";

				for (var i = 1;i <= document.forms[0]["NOENTRANTS"].value;i++)
				{
					name		+= document.forms[0]["entrantname" + i].value + ",";
					displayname += document.forms[0]["entrantname" + i].value + " / ";

					if (document.forms[0]["entrantname" + i].value == 0)
					{
						alert("One or more of the entrants are missing. Please fill in all entrant information.");
						nopost = true;
						break;
					}
					
					if (document.forms[0]["entrantid" + i].value.length == 0)
					{
						ids		+= "0,";
					}
					else
					{
						ids		+= document.forms[0]["entrantid" + i].value + ",";
					}
				}

				if (document.forms[0]["COMPETITIONTYPE"].value == "Individual Knockout")
				{
					document.forms[0]["ENTRANTPLAYERID"].value		= ids.substring(0,ids.length-1);	
					document.forms[0]["ENTRANTNAMES"].value			= name.substring(0,name.length-1);
					document.forms[0]["ENTRANTDISPLAYTEAM"].value	= displayname.substring(0,displayname.length-3);
				}
				else
				{
					document.forms[0]["ENTRANTTEAMID"].value		= ids.substring(0,ids.length-1);	
					document.forms[0]["ENTRANTNAMES"].value			= name.substring(0,name.length-1);
					document.forms[0]["ENTRANTDISPLAYTEAM"].value	= displayname.substring(0,displayname.length-3);								
				}

				try
				{		
					if (selected != "")
					{
						//document.forms[0]["ENTRANTID"].value	= id;		
					}
				}
				catch (e) {}	
			}
		}		
		else if (actiontype == "ADMIN_LEAGUE_SETTINGS")
		{
			if (action == "NEW_SEASON")
			{
				var agree=confirm("WARNING: This will archive off all of the current seasons data, including fixtures and results. Are you sure you want to continue?");
				if (!agree)
				{
					nopost = true;
				}
			}
		}
		else if (actiontype == "VENUE")
		{
			try
			{		
				document.forms[0]["VENUEID"].value	= selected.replace("venue","");
	
			}
			catch (e) {}
		
		}
		else if (actiontype == "DIVISION")
		{
			try
			{		
				document.forms[0]["DIVISIONID"].value	= selected.replace("division","");
				document.forms[0]["DIVISIONNAME"].value = document.forms[0]["divname"].value
			}
			catch (e) {}
		}
		else if (actiontype == "COMPETITION")
		{	
			try
			{		
				if (action == "RESULTS")
				{
					document.forms[0]["COMPETITIONSTATUSID"].value	= selected.replace("roundstatus","");
				}	
				else if (selected != "" && action != "VIEWDRAW")
				{
					document.forms[0]["COMPETITIONID"].value		= selected.replace("competition","");
					document.forms[0]["COMPETITIONPLAYERS"].value	= document.forms[0]["competitionplayers0"].value
					document.forms[0]["COMPETITIONNAME"].value		= document.forms[0]["competitionname0"].value
			
				}
				else
				{

					document.forms[0]["COMPETITIONSTATUSID"].value	= id;
	
				}
			}
			catch (e) {}		
		}		
		else if (actiontype == "COMPETITION_DRAW")
		{
			try
			{		
				if (selected != "")
				{
					document.forms[0]["COMPETITIONID"].value		= selected.replace("competition_draw","");
				}
			}
			catch (e) {}
		}				
		else if (actiontype == "TEAM_MOVE")
		{
			document.forms[0]["TEAMID"].value		= selected.replace("team_move","");			
			document.forms[0]["DIVISIONID"].value	= document.forms[0]["DIVISIONLIST"].value;
		}
		else if (actiontype == "PLAYER_MOVE")
		{
			document.forms[0]["TEAMID"].value		= document.forms[0]["TEAMLIST"].value;
			document.forms[0]["PLAYERID"].value		= selected.replace("player_move","");			
		}		
/*
		else if (actiontype == "ADMIN_LEAGUE_TEAMS")
		{
			if (action == "ADD_TEAM")
			{
				document.forms[0]["TEAMID"].value		= "0";
			}

			if (selected.length > 0)
			{
				try
				{
					document.forms[0]["TEAMID"].value		= selected.replace("team","");			
					document.forms[0]["TEAMNAME"].value		= document.forms[0]["teamname0"].value
				}
				catch (e) {}	
			}
		}
*/		
		else if (actiontype == "PLAYER")
		{
			try
			{	
				document.forms[0]["PLAYERID"].value			= selected.replace("player","");
				document.forms[0]["PLAYERNAME"].value		= document.forms[0]["playername0"].value;
				document.forms[0]["PLAYERCONTACT"].value	= document.forms[0]["playercontact0"].value;				
				document.forms[0]["PLAYEREMAIL"].value		= document.forms[0]["playeremail0"].value;	
			}
			catch (e) {}					
		}
		document.forms[0]["ACTIONTYPE"].value	= actiontype;
		document.forms[0]["ACTION"].value		= action;

		if 
		(
			action != "SAVE_ENTRANT" 
		 && action != "UPDATE_ENTRANT" 		
		 && action != "DELETE_ENTRANT" 			 		
		 && action != "SAVE_COMPETITION" 		
		 && action != "SAVE_SETTINGS"	
		 && action != "SAVE_DIVISION"
		 && action != "SAVE_PLAYER"		 
		 && action != "SAVE_VENUE"		 
		 && action != "DELETE_COMPETITION"			 		 
		 && action != "DELETE_DIVISION"		 
		 && action != "DELETE_PLAYER"				 
		 && action != "DELETE_TEAM" 
		 && action != "DELETE_VENUE" 		 
		 && action != "TEAMMOVE" 
		 && action != "MAKE_DRAW" 
		 && action != "CONFIRM_DRAW"  
		 && action != "CALC_ROUNDS"
		 && (actiontype != "LATESTNEWS" || action == "PREVIEW")
		 && action != "UPDATE_ROUNDS"
		 && action != "UPDATE_RESULTS"	
		 && action != "GENERATE_FIXTURES"	
		 && action != "SAVE_TEAM_DETAILS"	
		 && action != "UPDATE_RESULTS"
		 && action != "SAVE_SPONSOR"
		 && action != "DELETE_SPONSOR"		 
		 && action != "ADD_SPONSOR_LOGO"	
		 && action != "SAVE_CONTACT"
		 && action != "DELETE_CONTACT"		
		 && action != "SAVE_RULE"			  		
		 && action != "DELETE_RULE"			  			 
		)
		{	
			if (actiontype == "ADMIN_LEAGUE_CONTACTS")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_CONTACTS";
			}
			else if (actiontype == "ADMIN_LEAGUE_RULES")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_RULES";
			}						
			else if (actiontype == "ADMIN_LEAGUE_DIVISIONS")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_DIVISIONS";
			}
			else if (actiontype == "ADMIN_LEAGUE_TEAMS")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_TEAMS";
			}			
			else if (actiontype == "ADMIN_LEAGUE_FIXTURES")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_FIXTURES";
			}
			else if (actiontype == "ADMIN_LEAGUE_PLAYERS")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_PLAYERS";
			}	
			else if (actiontype == "ADMIN_LEAGUE_VENUES")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_VENUES";
			}						
			else if (actiontype == "ADMIN_COMPETITION_LIST")
			{
				document.forms[0].action = "?script=ADMIN_COMPETITION_LIST";
			}		
			else if (actiontype == "ADMIN_COMPETITION_DRAWS")
			{
				document.forms[0].action = "?script=ADMIN_COMPETITION_DRAWS";
			}	
			else if (actiontype == "ADMIN_COMPETITION_ENTRANTS")
			{
				document.forms[0].action = "?script=ADMIN_COMPETITION_ENTRANTS";			
			}		
			else if (actiontype == "ADMIN_COMPETITION_RESULTS")
			{
				document.forms[0].action = "?script=ADMIN_COMPETITION_RESULTS";			
			}		
			else if (actiontype == "ADMIN_LEAGUE_PLAYER_RESULTS")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_PLAYER_RESULTS";			
			}	
			else if (actiontype == "ADMIN_LEAGUE_TEAM_RESULTS")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_TEAM_RESULTS";			
			}		
			else if (actiontype == "ADMIN_LEAGUE_SPONSORS")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_SPONSORS";			
			}				
			else if (actiontype == "TEAM")
			{
				document.forms[0].action = "?script=ADMIN_LEAGUE_DIVISIONS";
			}			
			else if (actiontype == "COMPETITION" || actiontype == "COMPETITION_ENTRANTS")
			{
				document.forms[0].action = "?script=ADMIN_COMPETITION_MANAGEMENT_OLD";
			}
			else if (action == "PREVIEW")
			{
				document.forms[0].action = "?script=ADMIN_LATEST_NEWS_PREVIEW";
			}
		}
		
		if (!nopost)
		{
			var s = document.forms[0].action;

			if (s.indexOf("?") >= 0)
			{
				document.forms[0].action = s + "&seasonid=" + document.forms[0]["SEASONID"].value + 
											   "&sitetype=" + document.forms[0]["SITETYPE"].value +
											   "&sitename=" + document.forms[0]["SITENAME"].value;				
			}
			else
			{
				document.forms[0].action = s + "?seasonid=" + document.forms[0]["SEASONID"].value +
											   "&sitetype=" + document.forms[0]["SITETYPE"].value +
											   "&sitename=" + document.forms[0]["SITENAME"].value;	
			}
		
			document.forms[0].submit();
		}
	}

	function removeEntrant_old(id)
	{
		var n;
		var text = document.getElementById("entrants");
		text.innerHTML = "";
		
		for (var i = 0;i < entrants_index.length;i++)
		{
			n = entrants_index[i];
			
			if (n == id)
			{
				entrants_html[i]	= "";
				entrants_contact[i] = "";
				entrants_email[i]	= "";
				entrants_name[i]	= "";
				entrants_index[i]	= "";
			}
		}	

		for (var i = 0;i < entrants_index.length;i++)
		{
			text.innerHTML += entrants_html[i];
		}
		
		entrant_count -= 1;
	}

	function addEntrant(id,name,contact,email,noplayers,type,venueid)
	{
		var success = false;
		
		if (type == "Player")
		{
			for (i = 1;i<=noplayers;i++)
			{
				if (document.forms[0]["entrantname" + i].value.length == 0 && !success)
				{
					document.forms[0]["entrantname" + i].value = name;
					document.forms[0]["entrantid" + i].value = id;
					success = true;
				}
			}
		}
		else
		{
			if (document.forms[0]["entrantname1"].value.length == 0)
			{
				document.forms[0]["entrantname1"].value = name;
				document.forms[0]["entrantid1"].value = id;
				success = true;
			}
		}	
		
		if (!success)
		{
			alert("You need to remove a previous team/player before you can add a new one");
		}	
		else
		{			  
			document.forms[0]["ENTRANTCONTACT"].value = contact;
			document.forms[0]["VENUELIST"].value = venueid;
		}
	}	
		
	function removeEntrant(id)
	{
		document.forms[0]["entrantname" + id].value	= "";
		document.forms[0]["entrantid" + id].value	= "";
		document.forms[0]["ENTRANTCONTACT"].value	= "";
		document.forms[0]["VENUELIST"].value		= 1;		
	}

	
	function addEntrant_old(id,name,contact,email,noplayers,type,venueid)
	{
		var text = document.getElementById("entrants");

		if (noplayers == entrant_count)
		{
			alert("You have the required number of entrants to proceed.");
		}
		else 
		{
			if (type == "Player")
			{
				entrants_html.push("<span class='admin-competition-player-to-add-row'>" + 
								"<span class='admin-competition-player-to-add-name'><input name='entrantname" + id + "' type='text' size='20' value='" + name    + "'/></span>" + 
								"<span class='admin-competition-player-to-add-contact'>" + contact + "</span>"+
								"<a href='javascript:removeEntrant(" + id + ");'><div class='admin-competition-x-button-sml'>x</span></a>" + 
							"</span>");
			}
			else
			{
				entrants_html.push("<span class='admin-competition-player-to-add-row'>" + 
								"<span class='admin-competition-player-to-add-name'><input name='entrantname" + id + "' type='text' size='20' value='" + name    + "'/></span>" + 
								"<span class='admin-competition-player-to-add-contact'>" + contact + "</span>"+
								"<a href='javascript:removeEntrant(" + id + ");'><span class='admin-competition-x-button-sml'>x</span></a>" + 
							"</span>");			
			
			}		  
			entrants_index.push(id);	
			entrants_email.push(email);	
			entrants_contact.push(contact);		
			entrants_name.push(name);										  

			entrant_count += 1;

			text.innerHTML  = "";

			for (var i = 0;i < entrants_index.length;i++)
			{
				text.innerHTML += entrants_html[i];
			}
			
			document.forms[0]["ENTRANTCONTACT"].value = contact;
			document.forms[0]["VENUELIST"].value = venueid;
		}
	}	

/*
	function buildEntrants()
	{
		var playerids		= "";
		var playernames		= "";
		var playercontacts	= "";
		var playeremails	= "";						
		
		
alert("DDD");
		
		playerids		= document.forms[0]["playerids"].value;
		alert(playerids);
		
		playernames		= document.forms[0]["playernames"].value;
		alert(playernames);
		playercontacts	= document.forms[0]["playercontacts"].value;
		alert(playercontacts);
		playeremails	= document.forms[0]["playeremails"].value;						
	
		pid		= playerids.Split(",");
		pname	= playernames.Split(",");
		pcontact= playercontacts.Split(",");
		pemail	= playeremails.Split(",");

alert(pid.length);
				
		for (var n = 0;n < pid.length;n++)
		{
			entrants_index.push(pid[n];);	
			entrants_email.push(email[n]);	
			entrants_contact.push(pcontact[n]);		
			entrants_name.push(pname[n]);	
			entrant_count += 1;			
		}

	}

			*/
			
	function change(changetype,action,actiontype,page)
	{
		try
		{
			document.forms[0]["CONTACTID"].value	= document.forms[0]["CONTACT_NAME"].value
		}
		catch (e) {}

		try
		{		
			document.forms[0]["VENUEID"].value		= document.forms[0]["VENUE_NAME"].value
		}
		catch (e) {}
		
		try
		{		
			document.forms[0]["TEAMID"].value		= document.forms[0]["TEAMLIST"].value
		}
		catch (e) {}
		
		try
		{		
			document.forms[0]["COMPETITIONSTATUSID"].value		= document.forms[0]["STATUSLIST"].value
		}
		catch (e) {}
						
		document.forms[0]["ACTIONTYPE"].value	= actiontype;		
		document.forms[0]["ACTION"].value		= action;		
		document.forms[0].action = "?script=" + page + "&seasonid=" + document.forms[0]["SEASONID"].value +
												   "&sitetype="	+ document.forms[0]["SITETYPE"].value +
												   "&sitename=" + document.forms[0]["SITENAME"].value;
		document.forms[0].submit();
	}
	
	function aaa()
	{

		if (type == 'DELETE' 
			|| type == 'SAVENAME' 
			|| type == 'NEWDIVISION'				 
			)
		{
			if (type != 'SAVENAME')
			{
				id = document.DIVISIONS.DIVISIONID.value;
			}
			else
			{			
				id = nameid;
			}
			
			if (id == '')
			{
				id = '0';
			}
			document.DIVISIONS.DIVISIONID.value		= id;
			document.DIVISIONS.DIVISIONNAME.value	= document.DIVISIONS["divisionname" + id].value;				
			document.DIVISIONS.action = '?script=ADMIN_DIVISION_ACTION';
			document.DIVISIONS.submit();
		}
						
		else if (type == 'ADD')
		{
			document.DIVISIONS.action = '?script=ADMIN_LEAGUE_DIVISIONS&DIVISIONID=' + id;
			document.DIVISIONS.submit();						
		}
		else
		{
			document.DIVISIONS.action = "?script=ADMIN_DIVISION_MANAGEMENT&DIVISIONID=" +id;	
			document.DIVISIONS.submit();
		}
		
	
	}

	function selectTeam(id)
	{
		var e = document.getElementById('ind' + id);
		var i = e.src;
		var o;

		if (i.indexOf("-on.gif") < 0)
		{
			e.src = '/newbold/images/record-selector-on.gif';				
			o = document.getElementById("TEAMID");	
			e = document.getElementById("ind" + o.value);			
			o.value = id;				
			e.src = '/newbold/images/record-selector.gif';					
		}
		else
		{
			e.src = '/newbold/images/record-selector.gif';	
			document.TEAMS.TEAMID.value = "";			
		}
	}


	function teamAction(actiontype,id)
	{
		var divid = document.LEAGUE.DIVISIONID.value;

		if (actiontype == "VIEW")
		{
			document.LEAGUE.action = "?script=ADMIN_LEAGUE_HOME&DIVISIONID=" + divid+ "&TEAMID=" + id ;
			document.LEAGUE.submit();				
		}
		else if (type == 'DELETE' 
			|| type == 'SAVENAME' 
			|| type == 'NEWTEAM'	
			|| type == 'MOVESAVE'			 
			)
		{
			if (type == 'MOVESAVE')
			{
				id = document.TEAMS["MOVEID"].value;
				document.TEAMS.DIVISIONIDFROM.value	= divisionid;		
				document.TEAMS.DIVISIONIDTO.value	= document.TEAMS.DIVISIONLIST.value;	
			}				
			else if (type != 'SAVENAME')
			{
				id = document.TEAMS.TEAMID.value;
			}
			else
			{			
				id = nameid;
			}
			
			if (id == '')
			{
				id = '0';
			}
			document.TEAMS.TEAMID.value		= id;
			document.TEAMS.TEAMNAME.value	= document.TEAMS["teamname" + id].value;				
			document.TEAMS.action = '?script=ADMIN_TEAM_ACTION';
			document.TEAMS.submit();
		}
		else if (type == 'MOVE' && document.TEAMS.TEAMID.value != '')
		{			

			document.TEAMS.action = '?script=ADMIN_LEAGUE_HOME&DIVISIONID=' +  divisionid;
			document.TEAMS.submit();
		}								
		else if (type == 'ADD')
		{
			document.TEAMS.action = '?script=ADMIN_LEAGUE_HOME&DIVISIONID=' + divisionid;
			document.TEAMS.submit();						
		}
		else if (type == 'VIEW')
		{
			document.TEAMS.action = '?script=ADMIN_LEAGUE_HOME&TEAMID=' + id;
			document.TEAMS.submit();						
		}
	}
	
	function selectPlayer(id)
	{
		var e = document.getElementById('ind' + id);
		var i = e.src;
		var o;

		if (i.indexOf("-on.gif") < 0)
		{
			e.src = '/newbold/images/record-selector-on.gif';				
			o = document.getElementById("PLAYERID");	
			e = document.getElementById("ind" + o.value);			
			o.value = id;				
			e.src = '/newbold/images/record-selector.gif';					
		}
		else
		{
			e.src = '/newbold/images/record-selector.gif';	
			document.PLAYERS.PLAYERID.value = "";			
		}
	}
	
	function playerAction(type,nameid)
	{		
		var id;
		
		document.PLAYERS.PLAYERACTION.value = type;
							
		if (type == 'DELETE' 
			|| type == 'SAVENAME' 
			|| type == 'TRANSFERSAVE'
			|| type == 'NEWPLAYER'				 
			)
		{
			if (type == 'TRANSFERSAVE')
			{
				id = document.PLAYERS["TRANSFERID"].value;
				document.PLAYERS["TEAMIDFROM"].value	= teamid;		
				document.PLAYERS["TEAMIDTO"].value		= document.PLAYERS["TRANSFERLIST"].value;							
			}
			else if (type != 'SAVENAME')
			{
				id = document.PLAYERS["PLAYERID"].value;
			}
			else
			{			
				id = nameid;
			}
			
			if (id == '')
			{
				id = '0';
			}

			document.PLAYERS["PLAYERID"].value		= id;
			document.PLAYERS["PLAYERNAME"].value	= document.PLAYERS["playername" + id].value;				
			document.PLAYERS.action = '?script=ADMIN_LEAGUE_HOME';
			document.PLAYERS.submit();
		}
		else
		{
			if (type == 'TRANSFER' && document.PLAYERS.PLAYERID.value != '')
			{				
				document.PLAYERS.action = '?script=ADMIN_LEAGUE_HOME&TEAMID=' + teamid;
				document.PLAYERS.submit();
			}
			else if (type == 'ADD')
			{
				document.PLAYERS.action = '?script=ADMIN_LEAGUE_HOME&TEAMID=' + teamid;
				document.PLAYERS.submit();						
			}
			else
			{
				alert('You have not selected a player from the list.');
			}
		}
	}	
	
	function showDivision()
	{
		var a = document.getElementById('newdivision0');
		a.className = "admin-division-list";
	
	}


 



function findStyleRule(styleName) 
{
alert(document.styleSheets.length);

  for (i = 0; i < document.styleSheets.length; i++) 
  { 
alert(document.styleSheets(i).rules.length);
  
    for (j = 0; j < document.styleSheets(i).rules(0).length; j++) 
    {
alert(document.styleSheets(i).rules(j).selectorText);
    
      if (document.styleSheets(i).rules(j).selectorText  == styleName) 
      {
       return document.styleSheets(i).rules(j);
      }
    }     
  }
}


// global popup handle
var Popup = window.createPopup();

// display a popup window at the specified location
// with the specified text
function ShowPopup(stylesheet,       // style sheet to use
				   boxstyle,		 // box style to use
                   title,            // title text
                   titlestyle,       // title style name
                   text,             // body text
                   textstyle,        // body style
                   closetext,        // closure text
                   closestyle,       // closure style name
                   x,                
                   y,
                   width,
                   height,
				   elementid)
{
    // if the variable is instantiated, then
    // do not create it.
    //
    var DocBody = Popup.document.body;

    //
    //DocBody.style.backgroundColor="lightyellow";
    //DocBody.style.border = "solid black 1px";
    //DocBody.style.margin=5;
    //

    var DocBody = Popup.document.body;
    //
    if(Popup.document.createStyleSheet)
    {
            Popup.document.createStyleSheet(stylesheet);
    }
    else
    {
            var newSS;
            newSS= Popup.document.createElement('link'); 
            newSS.rel='stylesheet';  
            newSS.href= stylesheet;
            Popup.document.getElementsByTagName('head')[0].appendChild(newSS); 
    }

	a = findStyleRule(boxstyle);

    // replace new lines with breaks
    //text. replace(/\n/,'<br\>'); // doesn't work
    while(text.indexOf("\n") != -1)
    {
	    var tmp = text
        text = text.slice(0, text.indexOf("\n")) + "<br\>"  + text.slice(tmp.indexOf("\n") + 1, tmp.length);
    }

    //setup the font size etc
    Popup.document.title = "This is the Document Title";

    //    
    DocBody.innerHTML = "<div class='" + boxstyle + "'>" +
                            "<span class='"  + titlestyle + "'>" + title + "</span>" +
							"<span >" +
								"<a class='" + closestyle + "' href='javascript:{function ClosePopup(){window.blur();};ClosePopup();}\'>" + closetext + "</a>" +
							"</span>" +
                            "<span class='" + textstyle + "'>" + text + "</span>" +
                         "</div>";
      //
      try
      {
		ielement = document.getElementById(elementid);
      }
      catch (e){}
      Popup.show(x,y,width,height, ielement);
}

function getGraph(id, height, width, data, colours, type, text, scale, barwidth, texttype)
{
    document.getElementById(id).innerHTML = "<img src='http://chart.apis.google.com/chart?cht=" + type + "&chs=" + width + "x" + height + "&chp=" + scale + "&chd=t:" + data + "&chbh=" + barwidth + "&" + texttype + "=" + text + "&chco=" + colours.replace("#","") + "' alt=''/>";

    //http://chart.apis.google.com/chart?cht=lc&chd=t:9,15,16,14,6,12,13,16,15&chs=160x120&chco=697DC5&chds=1,16&chtt=Chart%20Title&chxt=y&chxl=0:|16th|12th|8th|4th|1st&chxs=0,697DC5,9&chg=20,20&chts=697DC5,11&chm=c,697DC5,0,1.0,9.0|c,697DC5,0,2.0,9.0|c,697DC5,0,3.0,9.0|c,697DC5,0,4.0,9.0|c,697DC5,0,5.0,9.0|c,697DC5,0,6.0,9.0|c,697DC5,0,7.0,9.0
    
}
