function setDate(field, component, hiddenField) {
	
	var updateval = document.getElementById(field).value;
	var currentdate = document.getElementById(hiddenField).value;
	
	var mydate = new Array();
	mydate = currentdate.split('/');
	
	if(mydate.length != 3) {
		mydate = ['01','01','1900'];
	}
	
	if (component=='d') {
		mydate[0] = updateval;
	} else if (component=='m') {
		mydate[1] = updateval;
	} else if (component=='y') {
		mydate[2] = updateval;
	}
	
	document.getElementById(hiddenField).value = mydate[0] + '/' + mydate[1] + '/' + mydate[2];
	
}

function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

function popUpMsg(text) {

	if(text.length>0) {
		alert(text);
	}
}

function DoNav(theUrl)
  {
  document.location.href = theUrl;
  }

function DoNavLinkNav(theUrl) {

	document.location.href = theUrl;
}
function ChangeColorZeb(tableRow, highLight, rtnCol) {


    if (highLight)
    {
      tableRow.style.backgroundColor = rtnCol;
      tableRow.style.cursor = 'pointer';
    
		//tableRow.className = rtnCol;
			
    }
    else
    {
      tableRow.style.backgroundColor = rtnCol;
      tableRow.style.cursor = 'default';
	  //tableRow.className = rtnCol;
    }
  }

  function DoNav(theUrl)
  {
  document.location.href = theUrl;
  }
  
function addQualRowToTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellLeft.appendChild(textNode);
  
  // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'txtRow' + iteration;
  el.id = 'txtRow' + iteration;
  el.size = 40;
  
  el.onkeypress = keyPressTest;
  cellRight.appendChild(el);
  
  // select cell
  var cellRightSel = row.insertCell(2);
  var sel = document.createElement('select');
  sel.name = 'selRow' + iteration;
  sel.options[0] = new Option('text zero', 'value0');
  sel.options[1] = new Option('text one', 'value1');
  cellRightSel.appendChild(sel);
}

function removeQualRowFromTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}


function ajaxContactList(field,updatediv) {

	//get search string
	var search = document.getElementById(field).value;
	
	search = search.replace("'","_");
		
		document.getElementById('nameSearch').style.display = "block";
		
		var params = "search=" + search;
		
		var myAjax = new Ajax.Updater(
	    			"nameSearch", 
	    			"ajaxContactSearch.htm", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=con&search=" + search });
	    
      

}

function newEntryContact() {
	
	document.getElementById('entrySearch').style.display = "none";
	
	alert("Please leave the name field blank. Then populate the form below adding in the category and the club above")
	
}

function ajaxEntryList(field,updatediv) {
	
	//get search string
	var search = document.getElementById(field).value;
	
	search = search.replace("'","_");
		
		document.getElementById('entrySearch').style.display = "block";
		
		var params = "search=" + search;
		
		var myAjax = new Ajax.Updater(
	    			"entrySearch", 
	    			"ajaxContactSearch.htm", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=ent&search=" + search });
	    
      

}

function ajaxMemberList(field,updatediv) {
	//get search string
	var search = document.getElementById(field).value;
	
	search = search.replace("'","_");
	
	document.getElementById('memberSearch').style.display = "block";
		
	var myAjax = new Ajax.Updater(
	    			"memberSearch", 
	    			"ajaxContactSearch.htm", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=mem&search=" + search });
	    
  
}

function ajaxClubEntryList(field,updatediv) {
	//get search string
	var search = document.getElementById(field).value;
	
	search = search.replace("'","_");
	
	document.getElementById('memberSearch').style.display = "block";
		
	var myAjax = new Ajax.Updater(
	    			"memberSearch", 
	    			"ajaxContactSearch.htm", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=clubentry&search=" + search });
	    
  
}

function saveMainContact() {
	
	var dropdownIndex = document.getElementById('contacts_found').selectedIndex;
	var dropdownValue = document.getElementById('contacts_found')[dropdownIndex].value;
	var dropdownText = document.getElementById('contacts_found')[dropdownIndex].text;
	
	//hide drop down
	document.getElementById('nameSearch').style.display = "none";
	
	// update hidden field with id
	document.getElementById('group.mainContact.id').value = dropdownValue;
	// put text in drop down
	document.getElementById('contactName').value = dropdownText
	
}

function saveGroupMember() {

	var dropdownIndex = document.getElementById('members_found').selectedIndex;
	var dropdownValue = document.getElementById('members_found')[dropdownIndex].value;
	var groupId = document.getElementById('group.id').value;
	
	//hide drop down
	document.getElementById('memberSearch').style.display = "none";
	document.getElementById('memberName').value = "";
	 
	var myAjax = new Ajax.Updater(
	    			"groupMembers", 
	    			"ajaxGroupMembers.htm", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=list&groupId=" + groupId + "&contactId="+dropdownValue });
	    
  
}

function saveEntryContact() {

	var dropdownIndex = document.getElementById('entrant_found').selectedIndex;
	var dropdownValue = document.getElementById('entrant_found')[dropdownIndex].value;
	//var entryId = document.getElementById('group.id').value;
	
	//hide drop down
	document.getElementById('entrySearch').style.display = "none";
	
	// get contact details for id
	lookupContact(dropdownValue);
}
function lookupContact(id) {
		
		var url="ajax_contact_request.htm";
    
    	//send to the database
    
    	var params = "mode=contact&id=" + id;
    
		var myAjax = new Ajax.Request(
        				url, 
        				{method: 'get', parameters: params, 
        				asynchronous: true, onSuccess: processContact,onFailure: notifyFailure});
	}

function saveClubEntryContact() {

	var dropdownIndex = document.getElementById('entrant_found').selectedIndex;
	var dropdownValue = document.getElementById('entrant_found')[dropdownIndex].value;
	//var entryId = document.getElementById('group.id').value;
	
	//hide drop down
	document.getElementById('memberSearch').style.display = "none";
	
	document.getElementById('contact.id').value = dropdownValue;
	
	document.form.submit();
}

/*
function lookupContact(id) {
		
		var url="ajaxContactSearch.htm";
    
    	//send to the database
    
    	var params = "mode=entrant&id=" + id;
    
		var myAjax = new Ajax.Request(
        				url, 
        				{method: 'get', parameters: params, 
        				asynchronous: true, onSuccess: processContact,onFailure: notifyFailure});
	}
*/
function processContact(originalRequest) {
	
		eval(originalRequest.responseText);	
		document.getElementById('entrySearch').style.display = "none";
	}
	
function notifyFailure(originalRequest)
{
  alert("Failed AJAX Request.")
    
}

function select_Value_Set(selectName, Value)
{
	eval('selectObject = document.' + selectName + ';');
	for(index = 0; index < selectObject.length; index++)
	{
		if(selectObject[index].value == Value)
			selectObject.selectedIndex = index;
	}
} 

function readyToSendEmail() {
	
	confirm("Please confirm you wish to send this email");
	document.getElementById("sendMail").value= "Yes";
	
}

function addSmsParam() {

	var param = document.getElementById("paramList");
	var text = document.getElementById("mymessage").value;
	var myParam = param.options[param.selectedIndex].value;
	text = text + "$"+ myParam;
	
	document.getElementById("mymessage").value = text;
	
}

function addEmailParam() {
	
	var param = document.getElementById("paramList");
	var oEditor = FCKeditorAPI.GetInstance('email.message') ;
	var myParam = param.options[param.selectedIndex].value;
	
	oEditor.InsertHtml("$" + myParam);
	
}
function addLetterParam() {

	var param = document.getElementById("paramList");
	var text = document.getElementById("email.message").value;
	var myParam = param.options[param.selectedIndex].value;
	text = text + "$"+ myParam;
	
	document.getElementById("email.message").value = text;
	
}

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}


function addProductToCart(itemId) {

	document.getElementById("product.id").value=itemId;
	document.form.submit();
}

function addProductItemToCart(itemId) {
	
	var param = document.getElementById("productId_" + itemId);
	var myParam = param.options[param.selectedIndex].value;
	
	if(myParam==0) {
		alert("No Item Selected");
		return
	}
	
	document.getElementById("productItem.id").value=myParam;
	document.form.submit();
}


function ajaxClubList(field,updatediv) {
	
	//get search string
	var search = document.getElementById(field).value;
	
	search = search.replace("'","_");
		
		document.getElementById('clubSearch').style.display = "block";
		
		var params = "search=" + search;
		
		var myAjax = new Ajax.Updater(
	    			"clubSearch", 
	    			"ajaxSearch.htm?mode=club", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=club&search=" + search });
	    
      

}
function processContact(originalRequest) {
	
	eval(originalRequest.responseText);	
	document.getElementById('clubSearch').style.display = "none";
}
function closeClubSearch() {

	document.getElementById('clubSearch').style.display = "none";
}

function saveEntrantClub() {

	var dropdownIndex = document.getElementById('clubs_found').selectedIndex;
	var dropdownValue = document.getElementById('clubs_found')[dropdownIndex].value;
	var dropdownText = document.getElementById('clubs_found')[dropdownIndex].text;
	
	//hide drop down
	document.getElementById('clubSearch').style.display = "none";
	
	if(document.getElementById('clubLookup.id') == null) {
		
		document.getElementById('clubName').value = dropdownText;
		document.getElementById('entry.club.id').value = dropdownValue;
		
	} else {
		// update hidden field with id
		document.getElementById('clubLookup.id').value = dropdownValue;
		// put text in drop down
		document.getElementById('clubLookup.name').value = dropdownText
	}
}

function viewThumbnailPicker() {

		var dropdownIndex = document.getElementById('thumbnailAlbum').selectedIndex;
		var id = document.getElementById('thumbnailAlbum')[dropdownIndex].value;
		document.getElementById('thumbnailPicker').style.display = "block";
		
		var myAjax = new Ajax.Updater(
	    			"thumbnailPicker", 
	    			"/clubs/ajaxWebSearch.htm", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "galleryId=" + id });
		
}

function selectImage(imgSrc) {
	
	var imagesrc = "<img src='../../" + imgSrc + "'>";
	document.getElementById('thumbnailView').innerHTML = imagesrc;
	document.getElementById('blog.thumbnail').value= imgSrc;
	
	closeThumbnailPicker();
}

function closeThumbnailPicker() {
	
	document.getElementById('thumbnailPicker').innerHTML = '';
	document.getElementById('thumbnailPicker').style.display = "none";
}

function addProductToOrder(box, count,price) {

	var name = 'productItemList[' + count +']';
	var elm = document.getElementById(name); 
	elm.style.display = box.checked? "":"none"; 
		
		
		if(elm.style.display == "none") {
			updateTotal("minus",price);
		} else {
			updateTotal("plus",price);
		}
		
}

function addProditemItemToOrder(dropDown, price) {

	var dropdownIndex = dropDown.selectedIndex;
	var dropdownValue = dropDown[dropdownIndex].value;
	
	
	if(dropdownValue == 0) {
		updateTotal("minus",price);
	} else {
		updateTotal("plus",price);
	}
	
}
function updateTotal(up,price) {
		
		var total = parseFloat(document.getElementById('order.orderTotal').value);
		
		if(up=="plus") {
			if(total > 0) {
				total = total + price;
			} else {
				total = price;
			}
		} else {
			total = total - price;
		}
		document.getElementById('order.orderTotal').value = total;
		
		document.getElementById('totalPrice').innerHTML  = '<strong>£' + total + '</strong>';
	}
function closeClubSearchAdmin() {

	document.getElementById('clubSearchAdmin').style.display = "none";
}
function selectEvent(box, num, price, epId) {
		
		var name = 'epList[' + num +']';
		var elm = document.getElementById(name); 
		elm.style.display = box.checked? "":"none"; 
		
		document.getElementById('entryPackage.id').value = epId;
	
		
		if(elm.style.display == "none") {
			updateTotal("minus",price);
		} else {
			updateTotal("plus",price);
		}
		
	} 
function ajaxClubAdminList(field,updatediv) {
	
	//get search string
	var search = document.getElementById(field).value;
	
	search = search.replace("'","_");
		
		document.getElementById('clubSearchAdmin').style.display = "block";
		
		var params = "search=" + search;
		
		var myAjax = new Ajax.Updater(
	    			"clubSearchAdmin", 
	    			"ajaxSearch.htm?mode=club&tem=admin&", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=club&tem=admin&search=" + search });
	    
      

}
function closeEntrantSearch() {

	document.getElementById('entrySearch').style.display = "none";
}
function ajaxEntrantSearch() {
	
	//get search string
	var lastname = document.getElementById('entry.entrant.lastname').value;
	var firstname = document.getElementById('entry.entrant.firstname').value;
	//var dob = document.getElementById('entry.entrant.dob').value;
	
	lastname = lastname.replace("'","_");
	firstname = firstname.replace("'","_");
		
	document.getElementById('entrySearch').style.display = "block";
		
		var myAjax = new Ajax.Updater(
	    			"entrySearch", 
	    			"ajaxSearch.htm", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=entfull&lastname=" + lastname + "&firstname=" + firstname });

}

function getAdminEntrant(entId) {

	
	//lookup entrant
	var url="ajaxSearch.htm";
    
    	//send to the database
    
    	var params = "mode=entrant&entId=" + entId;
    
		var myAjax = new Ajax.Request(
        				url, 
        				{method: 'get', parameters: params, 
        				asynchronous: true, onSuccess: processEntrant,onFailure: notifyFailure});
}

function getEntrant() {

	var dropdownIndex = document.getElementById('entrants_found').selectedIndex;
	var dropdownValue = document.getElementById('entrants_found')[dropdownIndex].value;
	var dropdownText = document.getElementById('entrants_found')[dropdownIndex].text;
	
	//lookup entrant
	var url="ajaxSearch.htm";
    
    	//send to the database
    
    	var params = "mode=entrant&entId=" + dropdownValue;
    
		var myAjax = new Ajax.Request(
        				url, 
        				{method: 'get', parameters: params, 
        				asynchronous: true, onSuccess: processEntrant,onFailure: notifyFailure});
}
