function addAltName()
{
	// Grab the last DL from the alternative names
	if ($('alternativeNames').getElementsBySelector('dl').last()) {
		var lastID = $('alternativeNames').getElementsBySelector('dl').last().id;
		if (lastID != 'undefined') {
			var lastIDArray = new Array();
			lastIDArray = lastID.split("_");
			lastID = +lastIDArray[1] + 1;
		} else {
			lastID = 1;
		}
	} else lastID = 1;

	new Insertion.Bottom('alternativeNames', "<dl id=\"altName_" + lastID + "\">\n\t<dt>#" + lastID + "</dt>\n<dd>\n\t<input name=\"altWeedName_" + lastID + "\" type=\"text\" /><a href=\"#\" onclick=\"$('altName_" + lastID + "').remove(); return false;\"><img src=\"../images/icons/textfield_delete.png\" alt=\"Remove name\" width=\"16\" height=\"16\" /></a> <a href=\"#\" onclick=\"$('altName_" + lastID + "').remove(); return false;\">remove</a></dd>\n</dl>");
	
	$('altNamedWeeds').value = +lastID;
	
	new Effect.Highlight("altName_" + lastID);

	
}

function addMediaItem()
{
	// Grab the last DL from the alternative names
	if ($('additionalMedia').getElementsBySelector('div').last()) {
		var lastID = $('additionalMedia').getElementsBySelector('div').last().id;
		if (lastID != 'undefined') {
			var lastIDArray = new Array();
			lastIDArray = lastID.split("_");
			lastID = +lastIDArray[1] + 1;
		} else {
			lastID = 2;
		}
	} else lastID = 2;

	new Insertion.Bottom('additionalMedia', "<div id=\"mediaItem_" + lastID + "\"><p class=\"clear\">&nbsp;</p>\n<a href=\"#\" onclick=\"$('mediaItem_" + lastID + "').remove(); return false;\"><img src=\"../images/icons/application_form_delete.png\" alt=\"Remove media item\" width=\"16\" height=\"16\" /></a> <a href=\"#\" onclick=\"$('mediaItem_" + lastID + "').remove(); return false;\">Remove media item.</a><br />\n\t<dl>\n\t<dt>File</dt>\n\t<dd>\n\t\t<input name=\"mediaFile_" + lastID + "\" type=\"file\" />\n\t</dd>\n\t<dt>Figure Number</dt>\n\t<dd>\n\t\t<input name=\"mediaFigureNumber_" + lastID + "\" size=\"5\" type=\"text\" value=\"" + lastID + "\" />\n\t</dd>\n\t<dt>Description</dt>\n\t<dd>\n\t\t<textarea name=\"mediaDescription_" + lastID + "\" cols=\"50\" rows=\"4\"></textarea>\n\t</dd>\n</dl></div>");
	
	
	$('additionalMediaItems').value = +lastID;
		return false;
	
}

function addWeedSpecific(val)
{
		if (val > 0) { 
		    new Insertion.Bottom('weedInfoArea',  "<dl id=\"wSI_" + val + "\">\n\t<dt>" + $('wID_' + val).innerHTML + "<br /><a href=\"#\" onclick=\"removeWeedSpecific(" + val + ", '" + $('wID_' + val).innerHTML + "'); return false;\"><img src=\"../images/icons/delete.png\" width=\"16\" height=\"16\" /></a></dt>\n<dd>\n\t<textarea cols=\"50\" rows=\"7\"  name=\"wITA_" + val + "\"></textarea></dd>\n</dl>");
			$('wID_' + val).remove(); 
			if (+$('wIDV').value < val) { $('wIDV').value = val; }
			
		}
	
}

function removeWeedSpecific(val, name)
{
	if (val > 0) {
		new Insertion.Bottom('weedInfoDropdown', '<option value="' + val + '" id="wID_' + val + '">' + name + '</option>');
		$('wSI_' + val).remove();
	}
}

function addBioControl(val)
{
		if (val > 0) { 
			bioName = $('bAID_' + val).innerHTML;
			bioName = bioName.replace(/\'/g,'\\\'');
		    new Insertion.Bottom('bioControlArea',  "<dl id=\"bA_" + val + "\">\n\t<dt>&nbsp;</dt>\n<dd>\n\t" + $('bAID_' + val).innerHTML + " <a href=\"#\" onclick=\"removeBioControl(" + val + ", '" + bioName + "'); return false;\"><img src=\"../images/icons/delete.png\" width=\"16\" height=\"16\" /></a><input type=\"hidden\" name=\"bATA_" + val + "\" value=\"" + val + "\" /></dd>\n</dl>");
			$('bAID_' + val).remove(); 
			if (+$('bAIDV').value < val) { $('bAIDV').value = val; }
			
		}
	
}

function removeBioControl(val, name)
{
	if (val > 0) {
		new Insertion.Bottom('bioControlDropdown', '<option value="' + val + '" id="bAID_' + val + '">' + name + '</option>');
		$('bA_' + val).remove();
	}
}

function checkAll(checked)
{
	
		elements = Form.getInputs($('searchWeed'), 'checkbox');
		elements.each( function(checkbox){
			if (checkbox.id == 'searchBy') {
				if (checked == true) { 
					
					checkbox.checked = true; 
				} else { 
					checkbox.checked = false; 
				}
			}
	
		});
	
}

function checkAllBox(checked)
{
	if (checked == false) {
		$('searchByAll').checked = false;

	}
}

function changeAction(form, searchString)
{
	form.action = 'editWeed.php?a=1&q=' + escape(searchString);
	return true;
	
}

function filterWeeds(name, checked) 
{
	switch(name)
	{
		case 'grass':
			if (checked == true) {
				$$('.type2').each(function(s) { s.removeClassName('grass'); });
				$('grassIcon').removeClassName('fade'); 
			} else {
				$$('.type2').each(function(s) { s.addClassName('grass'); });
				$('grassIcon').addClassName('fade'); 
			}
			break;
		case 'broadleaf':
			if (checked == true) {
				$$('.type1').each(function(s) { s.removeClassName('broadleaf'); });
				$('broadleafIcon').removeClassName('fade'); 
			} else {
				$$('.type1').each(function(s) { s.addClassName('broadleaf'); });
				$('broadleafIcon').addClassName('fade'); 
			}
			break;
		case 'perennial':
			if (checked == true) {
				$$('.type3').each(function(s) { s.removeClassName('perennial'); });
				$('perennialIcon').removeClassName('fade'); 
			} else {
				$$('.type3').each(function(s) { s.addClassName('perennial'); });
				$('perennialIcon').addClassName('fade'); 
			}
			break;
		case 'noxious':
			if (checked == true) {
				$$('.type4').each(function(s) { s.removeClassName('noxious'); });
				$('noxiousIcon').removeClassName('fade'); 
			} else {
				$$('.type4').each(function(s) { s.addClassName('noxious'); });
				$('noxiousIcon').addClassName('fade'); 
			}
			break;
		default:
			alert('huh?');
			break;
	}
	
}


/* NEED FOR SIDE BAR WEED PAGE */

initCalled=false;

if (! initCalled) {init()}

function init ()
{
	zindexStart = 1000;  
	initCalled=true;
}

	     

function setzindex(element, effect)
{
	if (effect.direction == Spry.forwards) {
		element.style.zIndex=zindexStart;
		//seems that IE needs a seperate solution
		if(/MSIE/.test(navigator.userAgent) && /Windows NT/.test(navigator.userAgent)) {
			Spry.Effect.setStyleProp(element.parentNode, 'zIndex', zindexStart);
			//element.parentNode.style.zIndex = zindexStart;
		}
	}
	zindexStart++;
}


function resetzindex(element, effect)
{
	if (effect.direction == Spry.backwards) {
		element.style.zIndex=1;
		
		if (/MSIE/.test(navigator.userAgent) && /Windows NT/.test(navigator.userAgent)) {
			Spry.Effect.setStyleProp(	element.parentNode, 'zIndex', 1);
		}
	}
}

var thumb = false;
function toggleThumb(targetElement, mediaID)
{

	Spry.Effect.GrowShrink(targetElement, {duration: 400, from: '100%', to: '800%', growCenter: false, toggle: true, setup:setzindex, finish:resetzindex});
	
	if ($('m' + mediaID)) {
		$('m' + mediaID).toggle();
	}
	if (thumb==false) { thumb = true; } 
	else { thumb= false; }
	
}

function checkThumb(targetElement, mediaID)
{
	if (thumb==true) { 
		Spry.Effect.GrowShrink(targetElement, {duration: 400, from: '100%', to: '800%', growCenter: false, toggle: true, setup:setzindex, finish:resetzindex});
		thumb=false;
		if ($('m' + mediaID)) {	
			$('m' + mediaID).toggle();
		}
		
	}
}

function toggleDescription(mediaID, command)
{
	
	if ($('m' + mediaID)) {
	
		if (command=='show') { 
			$('m' + mediaID).show();
		} else if (command=='hide') {
			$('m' + mediaID).hide();
		}
	}
}