function checkUncheckAll(theElement)
{
	var thisForm = document.getElementById(theElement), z = 0;
	for(z=0; z < thisForm.length; z++)
	{		
		if(thisForm[z].type == 'checkbox')
		{
			if(thisForm[z].checked == true)
			{
				thisForm[z].checked = false;
			}
			else
			{
				thisForm[z].checked = true;
			}
		}
	}
}

function confirmLink(theQuestion,theLink)
{
	if (confirm('Are you sure you want to ' + theQuestion))
	{
		theLink.href += (theLink.href.charAt(theLink.href.length) != '/') ? '/' : '';
		theLink.href += 'true';
		return true;
	}
	else {
		return false;
	}
}

function confirmForm(theQuestion,theForm)
{
	if (confirm('Are you sure you want to ' + theQuestion))
	{
		theForm = gid(theForm);
		theForm.action += theForm.action.charAt(theForm.action.length)!='/'?'/':'';
		theForm.action += 'true';
		theForm.submit();
		return true;
	}
	else {
		return false;
	}
}

function showHide(elementId, linkTag)
{
	if (element = document.getElementById(elementId))
	{
		if (element.style.display == '')
		{
			element.style.display = 'none';
			linkTag.innerHTML = '+';
		}
		else
		{
			element.style.display = '';
			linkTag.innerHTML = '-';
		}
		
		return true;
	}
	else
	{
		return false;
	}
}

function updateOperatorPaymentAmount(operator_user_id, amount, cBox)
{
	if (element = document.getElementById('operator_' + operator_user_id + '_payment'))
	{
		if (cBox.checked)
		{
			if (element.value == '')
			{
				element.value = 0;
			}
		}
		else
		{
			amount *= -1;
		}

		element.value = Math.round( (parseFloat(element.value) + amount) * 100 ) / 100;
		
		return element.value;
	}
	
	return false;
}

/* event options */

function addEventOption(divId)
{
	var optionLi = document.createElement('li');
	var div = $(divId);
	var arrLi = div.getElementsByTagName ('li');
	var liCount = arrLi.length;
	
	var optionID = 'event_option_' + liCount;
	optionLi.id = optionID;	
							
	optionLi.innerHTML = '<dl>'+
							'<dt>Membership Type:</dt>'+
							'<dd><select name="data[EventOption][' + liCount + '][membership_id]" id="dataeventoptionmembershipid"><option value="10" selected="selected">Community</option><option value="20">Explorer</option></select></dd>'+
							'<dt>Automatic:</dt>'+
							'<dd><input value="1" name="data[EventOption][' + liCount + '][is_automatic]" id="dataeventoptionisautomatic" type="radio"><label>Yes</label>&nbsp;<input value="0" name="data[EventOption][' + liCount + '][is_automatic]" id="dataeventoptionisautomatic" type="radio" checked="checked"><label>No</label></dd>'+
							'<dt>Name:</dt>'+
							'<dd><input name="data[EventOption][' + liCount + '][name]" id="dataeventoptionname" value="" type="text"></dd>'+
							'<dt>Description:</dt>'+
							'<dd><textarea name="data[EventOption][' + liCount + '][description]" id="dataeventoptiondesciption"></textarea></dd>'+
							'<dt>Option Type:</dt>'+
							'<dd><input value="+" name="data[EventOption][' + liCount + '][modifier_symbol]" id="dataeventoptionmodifiersymbol" type="radio"><label>Cost</label>&nbsp;<input value="-" name="data[EventOption][' + liCount + '][modifier_symbol]" id="dataeventoptionmodifiersymbol" type="radio"><label>Discount</label></dd>'+
							'<dt>Amount Type:</dt>'+
							'<dd><input value="$" name="data[EventOption][' + liCount + '][amount_symbol]" id="dataeventoptionamountsymbol" type="radio"><label>Fixed Cost</label>&nbsp;<input value="%" name="data[EventOption][' + liCount + '][amount_symbol]" id="dataeventoptionamountsymbol" type="radio"><label>Percentage</label></dd>'+
							'<dt>Amount:</dt>'+
							'<dd><input name="data[EventOption][' + liCount + '][amount]" id="dataeventoptionamount" value="" type="text"></dd>'+
							'<dd><a href="javascript:;" onclick="javascript: removeEventOption(\'' + liCount + '\',\'' + optionID + '\');">Remove Option</a></dd>'+
						'</dl>';
						
	div.appendChild(optionLi);
}

function removeEventOption(liCount, optionLiId)
{
  if(confirm('Are you sure you want to delete this option?'))
  {  
	  var optToDelete = $(optionLiId);
	  
	  optToDelete.innerHTML += '<input name="data[EventOption][' + liCount + '][delete]" id="dataeventoptiondelete" value="yes" type="hidden">';
	  optToDelete.style.display = 'none';
	  
  }
  return true;
  /*
  var parentDiv = $(divId);
  var arrLi = parentDiv.getElementsByTagName ('li');
  
  
  parentDiv.removeChild(optToDelete);
  
  for(var i = 0; arrLi.length; i++)
  {
	  arrLi[i].id = 'event_option_' + i;
  }
  */
}
/* end event options */

function populateRegistrant()
{
	new Ajax.Updater('divRegistrantForm', '/members/loadRegistrantInfo');
}
				