function toggleNotes(id)
{
	notes = document.getElementById("notes" + id);
	if(notes != null)
	{
		notes.style.display = "inline";
	}
}

function deleteOpp()
{
	if(confirm('Are you sure you want to delete the selected opportunities?\n\nThis action cannot be undone.'))
	{
		e = document.forms['oppList'].elements;
		e['customAction'].value = 'deleteOpp';
		
		values = new Array();
		for(i = 0; i < e.length; i++)
		{
			if(e[i].type == "checkbox" && e[i].checked)
			{
				values[values.length] = e[i].value;
			}
		}
		
		if(values.length > 0)
		{
			e['idList'].value = values;
			document.forms['oppList'].submit();
		}
		else
		{
			alert('You must select at least one opportunity');
		}
	}
}

function removeRoundUp()
{
	if(confirm('Are you sure you want to remove the selected opportunities from the roundup?\n\nThis action cannot be undone.'))
	{
		e = document.forms['oppList'].elements;
		e['customAction'].value = 'removeRoundUp';
		
		values = new Array();
		for(i = 0; i < e.length; i++)
		{
			if(e[i].type == "checkbox" && e[i].checked)
			{
				values[values.length] = e[i].value;
			}
		}
		
		if(values.length > 0)
		{
			e['idList'].value = values;
			document.forms['oppList'].submit();
		}
		else
		{
			alert('You must select at least one opportunity');
		}
	}
}

function deleteEvent()
{
	if(confirm('Are you sure you want to delete the selected events?\n\nThis action cannot be undone.'))
	{
		e = document.forms['oppList'].elements;
		e['customAction'].value = 'deleteEvent';
		
		values = new Array();
		for(i = 0; i < e.length; i++)
		{
			if(e[i].type == "checkbox" && e[i].checked)
			{
				values[values.length] = e[i].value;
			}
		}
		
		if(values.length > 0)
		{
			e['idList'].value = values;
			document.forms['oppList'].submit();
		}
		else
		{
			alert('You must select at least one event.');
		}
	}
}


function fillOpp()
{
	if(confirm('Are you sure you want to mark the selected opportunities as filled?'))
	{
		e = document.forms['oppList'].elements;
		e['customAction'].value = 'fillOpp';


		values = new Array();
		for(i = 0; i < e.length; i++)
		{
			if(e[i].type == "checkbox" && e[i].checked)
			{
				values[values.length] = e[i].value;
			}
		}
		
		if(values.length > 0)
		{
			e['idList'].value = values;
			document.forms['oppList'].submit();
		}
		else
		{
			alert('You must select at least one opportunity');
		}

	}
}


function unfillOpp()
{
	if(confirm('Are you sure you want to mark the selected opportunities as open?'))
	{
		e = document.forms['oppList'].elements;
		e['customAction'].value = 'unfillOpp';


		values = new Array();
		for(i = 0; i < e.length; i++)
		{
			if(e[i].type == "checkbox" && e[i].checked)
			{
				values[values.length] = e[i].value;
			}
		}
		
		if(values.length > 0)
		{
			e['idList'].value = values;
			document.forms['oppList'].submit();
		}
		else
		{
			alert('You must select at least one opportunity');
		}

	}
}


function changePassword(f)
{
	if( (f.elements['p1'].value != f.elements['p2'].value) || f.elements['p1'].value == "")
	{
		alert('New passwords do not match');
		return false;
	}
	return true;
}

function flipCB(e)
{
	name = e.value;
	for(i = 0; i < e.form.elements.length; i++)
	{
		if(e.form.elements[i].name.indexOf(name) > -1 && e.form.elements[i].type == "checkbox")
		{
			e.form.elements[i].checked = e.checked;
		}
	}
}

function toggleVo()
{
	v = document.getElementById("voMenu");
	if(v.style.display == "none")
	{
		v.style.display = "block";
	}
	else
	{
		v.style.display = "none";
	}
	
}

function toggleNotes(noteId)
{
	note = document.getElementById('notes' + noteId);
	if(note.style.display == "none")
	{
		note.style.display = "inline";
	}
	else
	{
		note.style.display = "none";
	}
	
}

function getUrl()
{
	s = (document.location+"").split('?');
	if(s.length > 0)
	{
		s = s[1];
		s = s.split('&');
		s = s[0];
	}
	else
	{
		s = "/";
	}
	return s;
}

function loadForm()
{
	if(document.forms['opp'])
	{
		e = document.forms['opp'].elements;
	
			
		avail = '';
		if(e['availH'])
			avail = e['availH'].value;
		if(e['areaH'])
			area =  e['areaH'].value;
		if(e['interestH'])
			interest = e['interestH'].value;
	
		for(i = 0; i < e.length; i++)
		{
			if(e[i].name.indexOf("avail") > -1 && avail.indexOf(','+e[i].value) > -1)
				e[i].checked = true;
			if(e[i].name.indexOf("area") > -1 && area.indexOf(','+e[i].value) > -1)
				e[i].checked = true;
			if(e[i].name.indexOf("interest") > -1 && (','+interest+',').indexOf(','+e[i].value+',') > -1)
				e[i].checked = true;
		}
		
		
		if(e['aProfile'] != null)
		{
			//e['aProfile'].value = e['aProfile'].value.replace(/<br>/gi, '\n');
			e['aProfile'].value = unescape(unescape(e['aProfile'].value));
		}
		
		if(e['description'] != null)
		{
			//e['description'].value = e['description'].value.replace(/<br>/gi, '\n');
			e['description'].value = unescape(unescape(e['description'].value));
		}

		if(e['description_FR'] != null)
		{
			//e['description'].value = e['description'].value.replace(/<br>/gi, '\n');
			e['description_FR'].value = unescape(unescape(e['description_FR'].value));
		}


	}
	
	s = document.location;
	links = document.getElementsByTagName('a');
	
	// Highlight the correct tab on the top navigation
	for(i = 0; i < links.length; i++)
	{
		if(links[i].className == "mainlevel")
		{
			// If IE
			if(document.all)
			{
				if(links[i].innerText != "Home" && links[i].innerText != "Page d'accueil" && (document.location+"").indexOf(links[i].href) > -1)
				{
					links[i].className = "mlha";
				}
			}
			// If not IE
			else
			{
				if(links[i].text != "Home" && links[i].text != "Page d'accueil" && (document.location+"").indexOf(links[i].href) > -1)
				{
					links[i].className = "mlha";
				}
			}
		}
		
		if(links[i].href.indexOf("glenmcinnis.com") > -1)
		{
			links[i].href = links[i].href.replace("glenmcinnis.com", "volunteerottawa.ca");
		}
	}
}

function createOppValues()
{
	e = document.forms['opp'].elements;
	avail = new Array();
	area = new Array();
	interest = new Array();
	for(i = 0; i < e.length; i++)
	{
		if(e[i].name.indexOf("avail") > -1 && e[i].checked && e[i].name.indexOf("_all") < 0)
		{
			avail[avail.length] = e[i].value;
		}
		if(e[i].name.indexOf("area") > -1 && e[i].checked && e[i].name.indexOf("_all") < 0)
		{
			area[area.length] = e[i].value;
		}
		if(e[i].name.indexOf("interest") > -1 && e[i].checked && e[i].name.indexOf("_all") < 0)
		{
			interest[interest.length] = e[i].value;
		}
	}
	e['availH'].value = avail;
	e['areaH'].value = area;
	e['interestH'].value = interest;
}

function validateCal()
{
	e = document.forms['opp'].elements;
	
	if(e['title'].value.length == 0)
	{
		alert('Please enter the title of the event.');
		e['title'].focus();
		return false;
	}

	if(e['link'].value.length == 0)
	{
		alert('Please enter the link to your event website.');
		e['link'].focus();
		return false;
	}

	if(e['schedule'].value.length == 0)
	{
		alert('Please enter the schedule information for the event.');
		e['schedule'].focus();
		return false;
	}

	
}

function validateAgencyProfile()
{
	e = document.forms['opp'].elements;
	
	if(e['aName'].value.length == 0)
	{
		alert('Please enter the agency name');
		e['aName'].focus();
		return false;
	}

	if(e['aAddress'].value.length == 0)
	{
		alert('Please enter the address');
		e['aAddress'].focus();
		return false;
	}

	if(e['aCity'].value.length == 0)
	{
		alert('Please enter a city');
		e['aCity'].focus();
		return false;
	}

	if(e['aPostalCode'].value.length == 0)
	{
		alert('Please enter the postal code');
		e['aPostalCode'].focus();
		return false;
	}

	if(e['aPhoneNumber'].value.length == 0)
	{
		alert('Please enter a phone number');
		e['aPhoneNumber'].focus();
		return false;
	}

	/*if(e['aFaxNumber'].value.length == 0)
	{
		alert('Please enter a fax number');
		e['aFaxNumber'].focus();
		return false;
	}*/

/*
	if(e['aWebsite'].value.length == 0)
	{
		alert('Please enter a website address');
		e['aWebsite'].focus();
		return false;
	}

*/


	if(e['aEmail'].value.length == 0)
	{
		alert('Please enter an email address');
		e['aEmail'].focus();
		return false;
	}

	
	//e['aProfile'].value = e['aProfile'].value.replace(/\n/gi, '<br>');
	if(e['aProfile'].value.length == 0)
	{
		alert('Please enter the agency profile');
		e['aProfile'].focus();
		return false;
	}
	//e['aProfile'].value = escape(e['aProfile'].value);
	//e['aProfileHidden'].value = escape(e['aProfile'].value);
	e['aProfileHidden'].value = e['aProfile'].value;

	return true;
}

function createOppValues2()
{
	e = document.forms['opp'].elements;
	avail = new Array();
	area = new Array();
	interest = new Array();
	for(i = 0; i < e.length; i++)
	{
		if(e[i].name.indexOf("avail") > -1 && e[i].type == "checkbox" && e[i].checked)
		{
			avail[avail.length] = e[i].value;
		}
		if(e[i].name.indexOf("area") > -1 && e[i].type == "checkbox" && e[i].checked)
		{
			area[area.length] = e[i].value;
		}
		if(e[i].name.indexOf("interest") > -1  && e[i].type == "checkbox" && e[i].checked)
		{
			interest[interest.length] = e[i].value;
		}
	}

	if(e['title'].value.length == 0 && e['title_FR'].value.length == 0)
	{
		alert('Please enter a title');
		e['title'].focus();
		return false;
	}
	if(e['contactName'].value.length == 0)
	{
		alert('Please enter a contact name');
		e['contactName'].focus();
		return false;
	}
	if(e['contactPhone'].value.length == 0)
	{
		alert('Please enter a contact phone number');
		e['contactPhone'].focus();
		return false;
	}
	if(e['contactEmail'].value.length == 0)
	{
		alert('Please enter a contact email');
		e['contactEmail'].focus();
		return false;
	}
	if(e['description'].value.length == 0 && e['description_FR'].value.length == 0)
	{
		alert('Please enter a description');
		e['description'].focus();
		return false;
	}
	if(avail.length < 1)
	{
		alert('Please specify an availability');
		return false;
	}
	if(area.length < 1)
	{
		alert('Please specify at least one location');
		return false;
	}
	if(interest.length < 1)
	{
		alert('Please specify at least one interest');
		return false;
	}
	
	if(e['mapLocation'].value.length > 0)
	{
		ml = e['mapLocation'].value;
		parts = ml.split(" ");
		if(parts.length < 4)
		{
			alert('A valid map address has not been entered.  Your address does not appear to contain all the information needed.\nFor example:\n1 Main St., Ottawa, ON');
			e['mapLocation'].focus();
			return false;
		}
		if(isNaN(parts[0]))
		{
			alert('Map addresses need to start with a street number.  The address you have entered starts with:\n\t'+parts[0]+'\nDo not include suite numbers like 150A in the map address.');
			e['mapLocation'].focus();
			return false;
		}
	}

	e['availH'].value = avail;
	e['areaH'].value = area;
	e['interestH'].value = interest;

	//e['description'].value = escape(e['description'].value);
	//e['description_FR'].value = escape(e['description_FR'].value);

	e['descriptionHidden'].value = escape(e['description'].value);
	e['descriptionFRHidden'].value = escape(e['description_FR'].value);
	

	return true;
}