function game_onreset()
{
	/*
	var oCardXMLData = document.getElementById("cardXMLText"); //This contains xml for the original list of cards
	var oCardList = document.getElementById("cardsSelect");
	var cardXML = oCardXMLData.value ;
	//populate the cards option list
	alert("game_onreset");
	//if there are cards to process
	if ( cardXML.length > 0 )
	{
		//get each card and process it
		alert("loadAction2");
		var tmp, i1, i2;
		i1 = 0;
		i2 = 0
		do
		{
			i1 = cardXML.indexOf("<card>", i1);
			if(i1>-1)
			{
				i2 = cardXML.indexOf("</card>", i1);
				tmp = cardXML.substr(i1+6, i2);
				alert(tmp);
				tmp="clean";
			}
		}while(i1>-1)
		 
	}*/
	
	//to reset the form reload the page
	document.location.reload(true);
}

function game_onsubmit()
{	
	//check there is a username and password entered
	var uName = document.getElementById("userName").value;
	var uEmail = document.getElementById("userEMail").value;
	var uPass = document.getElementById("userPassword").value;
	
	if( uName.length <= 1 || uEmail.length <= 1 || uPass.length <= 1 ) 
	{
		alert("User Name, Email or Password has not been entered");
	}
	else
	{
		//populate cards hidden field
		populateHiddenCardField();
		document.getElementById("gameUpdateForm").submit();
	}
}

function cardClick()
{
	//if a row is selected enable the buttons
	//alert("cardClick");
}

function cardAction(myAction)
{
	//alert(myAction);
	if( myAction == "add")	
	{
		window.open("game_cardPopup.asp?cAction=add", "EditCard", "height=150,width=500");
	}
	else if (myAction == "edit")
	{
		var selectBox = document.getElementById("cardsSelect");
		if (selectBox.selectedIndex >= 0)
		{		
			var selectedOption = selectBox.options[selectBox.selectedIndex].value;
			var cName = XMLElement(selectedOption, "name");
			var cColor = XMLElement(selectedOption, "color");
			var cOffence = XMLElement(selectedOption, "offence");
			var cDescription = XMLElement(selectedOption, "description");
			window.open("game_cardPopup.asp?cAction=edit&cName=" + cName + "&cColor=" + cColor + "&cOffence=" + cOffence + "&cDescription=" + cDescription, "EditCard", "height=150,width=500");
		}
		else alert("No card has been selected to edit");
	}
	else if (myAction == "delete")
	{
		var selectBox = document.getElementById("cardsSelect");
		if (selectBox.selectedIndex >= 0)
		{
	  	//replace selected card with null
	  	var curIndex = selectBox.selectedIndex;
	  	selectBox.options[curIndex] = null;		
	  	populateHiddenCardField();
  	}
  	else alert("No card has been selected to delete");
	}
}

function XMLElement(XMLText, XMLElement)
{
	var returnString = ""
	var i1 = XMLText.indexOf("<" + XMLElement + ">") + XMLElement.length + 2;
	var i2 = XMLText.indexOf("</" + XMLElement + ">");
	returnString = XMLText.substr(i1 , i2 - i1)
	return returnString;
}
// http://localhost/dnhc/game_update.asp?file=200511120000mens1.xml

function cardPopupCancel()
{
	window.close();
}

function cardPopupAdd()
{
	var cAction = document.getElementById("cAction").value ;
	var cName = document.getElementById("cName").value ;
	//var cColor = document.getElementById("cColor").value ;
	//var cOffence = document.getElementById("cOffence").value ;
	var cColor = document.getElementById("cColor") ;
	var cOffence = document.getElementById("cOffence") ;
	cColor = cColor.options[cColor.selectedIndex];
	cOffence = cOffence.options[cOffence.selectedIndex];
	cColor = cColor.text;
	cOffence = cOffence.text;
	var cDescription = document.getElementById("cDescription").value ;
	opener.cardPopupAddEx(cAction, cName, cColor, cOffence, cDescription);
	window.close();
}

function cardPopupAddEx(cAction, cName, cColor, cOffence, cDescription)
{
	var selectList = document.getElementById("cardsSelect");
	var nextIndex = selectList.length ;
	var XMLFragment = '<card xmlns="www.DidsburyNorthernHC.co.uk"><name>' + cName + '</name><color>' + cColor + '</color><offence>' + cOffence + '</offence><description>' + cDescription + '</description></card>'
	if( cAction=="add" )
	{
		//Add option to the select group
		selectList.options[nextIndex] = new Option(cColor + ": " + cName, XMLFragment);
	}
  else if( cAction=="edit")
  {
  	//replace selected card with this new one
  	var curIndex = selectList.selectedIndex;
  	selectList.options[curIndex] = new Option(cColor + ": " + cName, XMLFragment);
  }
  
  //now populate the hidden field with the all the card details
  populateHiddenCardField();
}

function populateHiddenCardField()
{
	var selectList = document.getElementById("cardsSelect");
	var cards = document.getElementById("cards");
  cards.value = "" ;
  var i = 0;
  var tmp = "";
  for(i=0;i<selectList.length;i++)
  {
  	tmp = tmp + selectList.options[i].value;
  }
  //now get rid of the namespaces from all the cards
  var regX = new RegExp(" xmlns=\"www.DidsburyNorthernHC.co.uk\"", "g")
  tmp = tmp.replace(regX, "");
  cards.value = tmp;
}