//////////////////Basic Functions//////////////////////////////////////
var highlightedDiv = "";
var debug = 0;
var mapshotsAccess = 0;
var mainReadOnly = 0;
var user_level = 3;

var OEM = 0;

var operationsMessageCheckID = 0;

openTest = 0
function addProfile(html,id)
	{
	if (openTest == 0)
		{
		openTest = 1
		if (id)
			{
			document.getElementById(id).innerHTML = html;
			}
		else
			{
			document.getElementById('profile_tree').innerHTML = html;
			}
		}
	openTest = 0
	}


function openTestx()
	{
	openTest = 0
	return false;
	}

///Set page div sizes
function setSize()
	{
	var width = document.documentElement.clientWidth;
	var height = document.documentElement.clientHeight;
	if (OEM == 0)
		{
		document.getElementById('backgroundimage').style.height = height;
		document.getElementById('backgroundimage').style.width = width;
		document.getElementById('top').style.width = width;

		var new_main_height = height - 100;
		document.getElementById('maindiv').style.height = new_main_height + "px";
		document.getElementById('maintable').style.height = new_main_height + "px";
		var maintablewidth = width - 60;
		document.getElementById('maintable').style.width = maintablewidth + "px";
		var midh = new_main_height - 32;
		document.getElementById('mid').style.height = midh + "px";

		if (currentTab == "view" || currentTab == "fertility" || currentTab == "blend" || currentTab == "event")
			{
			if (document.getElementById("autofill"))
				{
				var profile_tree_h = new_main_height - 60;
				document.getElementById('profile_tree').style.height = profile_tree_h + "px";
				document.getElementById("autofill").style.display = "inline";
				}
			else
				{
				var profile_tree_h = new_main_height - 35;
				document.getElementById('profile_tree').style.height = profile_tree_h + "px";
				}
			document.getElementById('profile_tree').style.top= "100px";
			}
		else
			{
			if (document.getElementById("autofill"))
				{
				var profile_tree_h = new_main_height - 35;
				document.getElementById('profile_tree').style.height = profile_tree_h + "px";
				document.getElementById("autofill").style.display = "none";
				}
			else
				{
				var profile_tree_h = new_main_height - 35;
				document.getElementById('profile_tree').style.height = profile_tree_h + "px";
				}
			document.getElementById('profile_tree').style.top= "100px";
			}

		if (currentTab == "event")
			{
			document.getElementById('profile_tree').style.top= "120px";
			document.getElementById('profile_tree').style.bottom = '200px';
			h = document.getElementById('profile_tree').style.height;

			document.getElementById('profile_tree').style.height = (parseInt(h) - 20) + "px";

			document.getElementById('tools').style.overflowX = 'hidden';
			}
		//var profile_tree_h = new_main_height - 60;
		//document.getElementById('profile_tree').style.height = profile_tree_h + "px";

		var linkswidth = width - 380;
		document.getElementById('links').style.display = "inline";
		document.getElementById('links').style.left = linkswidth + "px";

		var mh =  new_main_height - 40;
		var mw =  width - 290 - 200;
		var mw2 =  width - 290 - 200;

		document.getElementById('map').style.height = mh + "px";
		document.getElementById('map').style.width = mw2 + "px";

		if (document.getElementById('blendDiv'))
			{
			document.getElementById('blendDiv').style.height = mh + "px";
			document.getElementById('blendDiv').style.width = mw2 + "px";
			}

		//alert(document.getElementById('map').offsetHeight);
		document.getElementById('myMap').style.height = document.getElementById('map').offsetHeight + "px";
		document.getElementById('myMap').style.width = document.getElementById('map').offsetWidth + "px";

		if (VE6map) { VE6map.Resize(document.getElementById('map').offsetWidth, document.getElementById('map').offsetHeight); }


		if (currentTab != "asset" && currentTab != "agrian" )
			{
			var mh =  new_main_height - 40;
			document.getElementById('tools').style.height = mh + "px";
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "200px"
			}
		else
			{
			var mh =  new_main_height - 40;
			document.getElementById('tools').style.height = mh + "px";
			document.getElementById('tools').style.left = "250px";
			var newWidth = width-290;
			document.getElementById('tools').style.width = newWidth + "px"
			}
		if (currentTab == "workorder")
			{
			var width = document.documentElement.clientWidth - 40 - 40;
			document.getElementById('profile_tree').style.width= width + "px";
			if (document.getElementById('listdiv'))
				{
				var listheight = parseInt(document.getElementById('profile_tree').style.height)-55;
				document.getElementById('listdiv').style.height= listheight + 'px';
				}
			}
		else
			{
			document.getElementById('profile_tree').style.width= "215px";
			}

		if (fullScreenMapCheck == 1)
			{
			document.getElementById('map').style.zIndex = 20;
			document.getElementById('map').style.top = "0px";
			document.getElementById('map').style.left = "0px";
			document.getElementById('map').style.height = height + "px";
			document.getElementById('map').style.width = width + "px";
			if (VE6map) { VE6map.Resize(width, height); }
			if (document.getElementById('activeTrack').style.display != "none" || document.getElementById('activeTrack').style.display != "")
				{
				var left = width - 152;
				document.getElementById('activeTrack').style.top = "5px";
				document.getElementById('activeTrack').style.left = left + "px";
				}
			}
		else if (currentTab == "event")
			{
			mw = document.getElementById('map').style.width;
			document.getElementById('map').style.width = (parseInt(mw) - 70) + "px";

			tw = document.getElementById('tools').style.width;
			document.getElementById('tools').style.width = (parseInt(tw) + 70) + "px";

			tl = document.getElementById('tools').style.left;
			document.getElementById('tools').style.left = (parseInt(tl) - 70) + "px";
			}
		else if (currentTab == "operations")
			{
			mw = document.getElementById('map').style.width;
			document.getElementById('map').style.width = (parseInt(mw) - 100) + "px";

			tw = document.getElementById('tools').style.width;
			document.getElementById('tools').style.width = (parseInt(tw) + 100) + "px";

			tl = document.getElementById('tools').style.left;
			document.getElementById('tools').style.left = (parseInt(tl) - 100) + "px";
			}
		else
			{
			if (VE6map)
				{
				if (document.getElementById('activeTrack').style.display != "none" || document.getElementById('activeTrack').style.display != "")
					{
					var top = VE6map.GetTop() + 2;
					var left = VE6map.GetLeft() + VE6map.GetWidth() - 152;
					document.getElementById('activeTrack').style.top = top + "px";
					document.getElementById('activeTrack').style.left = left + "px";
					}
				}
			}
		}
	else
		{
		document.getElementById('backgroundimage').style.height = height;
		document.getElementById('backgroundimage').style.width = width;
		document.getElementById('top').style.width = width;

		var new_main_height = height;
		document.getElementById('maindiv').style.height = new_main_height + "px";
		document.getElementById('maintable').style.height = new_main_height + "px";
		var maintablewidth = width;
		document.getElementById('maintable').style.width = maintablewidth + "px";
		var midh = new_main_height - 32;
		document.getElementById('mid').style.height = midh + "px";
		var profile_tree_h = new_main_height-10;
		document.getElementById('profile_tree').style.height = profile_tree_h + "px";

		var linkswidth = width - 380;
		document.getElementById('links').style.display = "none";
		document.getElementById('links').style.left = linkswidth + "px";

		var mh =  new_main_height - 5;
		var mw =  width - 290 - 200;
		var mw2 =  width - 290 - 200;

		document.getElementById('map').style.height = mh + "px";
		document.getElementById('map').style.width = mw2 + "px";

		if (document.getElementById('blendDiv'))
			{
			document.getElementById('blendDiv').style.height = mh + "px";
			document.getElementById('blendDiv').style.width = mw2 + "px";
			}

		//alert(document.getElementById('map').offsetHeight);
		document.getElementById('myMap').style.height = document.getElementById('map').offsetHeight + "px";
		document.getElementById('myMap').style.width = document.getElementById('map').offsetWidth + "px";

		if (VE6map) { VE6map.Resize(document.getElementById('map').offsetWidth, document.getElementById('map').offsetHeight); }


		if (currentTab != "asset" && currentTab != "agrian" )
			{
			var mh =  new_main_height;
			document.getElementById('tools').style.height = mh + "px";
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "225px"
			}
		else
			{
			var mh =  new_main_height;
			document.getElementById('tools').style.height = mh + "px";
			document.getElementById('tools').style.left = "250px";
			var newWidth = width-270;
			document.getElementById('tools').style.width = newWidth + "px"
			}
		if (currentTab == "workorder")
			{
			var width = document.documentElement.clientWidth - 40 - 40;
			document.getElementById('profile_tree').style.width= width + "px";
			if (document.getElementById('listdiv'))
				{
				var listheight = parseInt(document.getElementById('profile_tree').style.height)-55;
				document.getElementById('listdiv').style.height= listheight + 'px';
				}
			}
		else
			{
			document.getElementById('profile_tree').style.width= "245px";
			}

		if (fullScreenMapCheck == 1)
			{
			document.getElementById('map').style.zIndex = 20;
			document.getElementById('map').style.top = "0px";
			document.getElementById('map').style.left = "0px";
			document.getElementById('map').style.height = height + "px";
			document.getElementById('map').style.width = width + "px";
			if (VE6map) { VE6map.Resize(width, height); }
			if (document.getElementById('activeTrack').style.display != "none" || document.getElementById('activeTrack').style.display != "")
				{
				var left = width - 152;
				document.getElementById('activeTrack').style.top = "5px";
				document.getElementById('activeTrack').style.left = left + "px";
				}
			}
		else
			{
			if (VE6map)
				{
				if (document.getElementById('activeTrack').style.display != "none" || document.getElementById('activeTrack').style.display != "")
					{
					var top = VE6map.GetTop() + 2;
					var left = VE6map.GetLeft() + VE6map.GetWidth() - 152;
					document.getElementById('activeTrack').style.top = top + "px";
					document.getElementById('activeTrack').style.left = left + "px";
					}
				}
			}
		}

	// Operations Message Check
	if (currentTab == "operations")
		{
		//setInterval ( operationsMessageCheck(), 1000 );
		operationsMessageCheckID = setInterval ( "operationsMessageCheck()", 60000 );
		}
	else
		{
		clearInterval(operationsMessageCheckID);
		}

	setZoneBoxPosition();
	}

function setZoneBoxPosition(width,height)
	{
	var zoneDisplay = document.getElementById("zoneDisplay");
	if (zoneDisplay && VE6map)
		{
		var top = VE6map.GetTop() + 2;
		var left = 0;
		if (width) {
			left = width - parseInt(zoneDisplay.style.width);
		} else {
			left = VE6map.GetLeft() + VE6map.GetWidth() - parseInt(zoneDisplay.style.width);
		}
		zoneDisplay.style.top = top + "px";
		zoneDisplay.style.left = left + "px";
		}
	}

var fullScreenMapCheck = 0;
/*
function fullScreenMap
This function makes the map full screen
Input:
	event: event object
	tab: the tab to change to
*/
function fullScreenMap()
	{
	//alert(document.getElementById('subLayerMenu').value);
	if (document.getElementById('subLayerMenu') != null)
		{
		document.body.removeChild(document.getElementById('subLayerMenu'));
		//document.getElementById('subLayerMenu').style.display = 'none';
		}

	var menu = document.getElementById("layer_menu");
	if (menu.style.display != "none")
		{
		menu.style.display = "none";
		}

	var menu = document.getElementById("find_menu");
	if (menu.style.display != "none")
		{
		menu.style.display = "none";
		}

	if (fullScreenMapCheck == 0)
		{
		//alert(document.getElementById('subLayerMenu'));
		fullScreenMapCheck = 1;
		var width = document.documentElement.clientWidth;
		var height = document.documentElement.clientHeight;
		document.getElementById('map').style.zIndex = 20;
		document.getElementById('map').style.top = "0px";
		document.getElementById('map').style.left = "0px";
		document.getElementById('map').style.height = height + "px";
		document.getElementById('map').style.width = width + "px";
		if (VE6map) { VE6map.Resize(width, height); }
		if (document.getElementById('activeTrack').style.display != "none" || document.getElementById('activeTrack').style.display != "")
			{
			var top = VE6map.GetTop() + 2;
			var left = width - 152;
			document.getElementById('activeTrack').style.top = "5px";
			document.getElementById('activeTrack').style.left = left + "px";
			}

		setZoneBoxPosition(width,height);
		}
	else
		{
		//alert('2');
		var width = document.documentElement.clientWidth;
		var height = document.documentElement.clientHeight;


		var new_main_height = height - 100;

		var linkswidth = width - 380;
		document.getElementById('links').style.display = "inline";
		document.getElementById('links').style.left = linkswidth + "px";

		var mh =  new_main_height - 40;
		var mw =  width - 290 - 200;
		var mw2 =  width - 290 - 200;



		fullScreenMapCheck = 0;
		if (OEM == 0)
			{
			document.getElementById('map').style.top = "105px";
			document.getElementById('map').style.left = "250px";
			}
		else
			{
			document.getElementById('map').style.top = "10px";
			document.getElementById('map').style.left = "250px";
			}
		document.getElementById('map').style.height = mh + "px";
		document.getElementById('map').style.width = mw2 + "px";
		setSize();
		}
	}

var currentTab = "view";

/*
function changeTab
This function changes the function tab of the site and call the proper scripts
Input:
	event: event object
	tab: the tab to change to
*/
function changeTab(event,tab)
	{
	if (document.getElementById('additionalList').style.display == 'inline')
		{
		document.getElementById('additionalList').style.display = 'none';
		document.getElementById('openHeaderList_image').src = '/images/down_arrow.gif';
		}


	if (document.getElementById('subLayerMenu') != null)
		{
		document.body.removeChild(document.getElementById('subLayerMenu'));
		//document.getElementById('subLayerMenu').style.display = 'none';
		}

	var width = document.documentElement.clientWidth;
	var height = document.documentElement.clientHeight;
	if (!event) { event = window.event; }
	if (document.getElementById("viewTab")) { document.getElementById("viewTab").className = "taboff"; }
	if (document.getElementById("assetTab")) { document.getElementById("assetTab").className = "taboff"; }
	if (document.getElementById("workorderTab")) { document.getElementById("workorderTab").className = "taboff"; }
	if (document.getElementById("fertilityTab")) { document.getElementById("fertilityTab").className = "taboff"; }
	if (document.getElementById("eventTab")) { document.getElementById("eventTab").className = "taboff"; }
	if (document.getElementById("blendTab")) { document.getElementById("blendTab").className = "taboff"; }
	if (document.getElementById("agrianTab")) { document.getElementById("agrianTab").className = "taboff"; }
	if (document.getElementById("operationsTab")) { document.getElementById("operationsTab").className = "taboff"; }
	if (document.getElementById("dispatchTab")) { document.getElementById("dispatchTab").className = "taboff"; }

	if (document.getElementById('trackingButton')) { removeHistory(); }
	document.getElementById('layer_menu').style.display="none";
	document.getElementById('find_menu').style.display="none";
	document.getElementById(tab + "Tab").className = "tabon"

	if (document.getElementById('blendDiv')) { document.body.removeChild(document.getElementById('blendDiv')); }
	if (document.getElementById('ssurgoZoneDisplay')) { document.body.removeChild(document.getElementById("ssurgoZoneDisplay")); }

	if (VE6map) { VE6map.DeleteAllShapes(); }
	cleanMap();
	var paramHash = new Array();

	clearInterval(IntervalId);
	clearInterval(IntervalIdWO);

	document.getElementById("profile_tree").innerHTML = "";
	document.getElementById("tool_area").innerHTML = "";

	if (OEM == 0)
		{
		if (tab == 'view')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "200px"

			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startProfile";
			makeRequest("/cgi-bin/profile.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			reloadAssets();
			reloadWorkorder();
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'asset')
			{
			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='block';

			document.getElementById('tools').style.left = "250px";
			var newWidth = width-290;
			document.getElementById('tools').style.width = newWidth + "px"

			paramHash["class"] = "asset";
			paramHash["function"] = "startAssetProfile";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			//reloadAssets();
			//reloadWorkorder();
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'workorder')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "200px"

			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='none';
			var width = document.documentElement.clientWidth - 40 - 40;
			document.getElementById('profile_tree').style.width= width + "px";
			if (document.getElementById('showAllWorkorders'))
				{
				if (document.getElementById('showAllWorkorders').checked == true) {	paramHash["showAll"] = "true"; }
				else { paramHash["showAll"] = "false"; }
				}

			var listheight = parseInt(document.getElementById('profile_tree').style.height)-55;
			paramHash["listdivHeight"] = listheight + 'px';

			paramHash["class"] = "workorder";
			paramHash["function"] = "startWorkorderList";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			}
		else if (tab == "event")
			{
			field_event_hold_ID = "field_event_TAB1_TD"

			var fieldEventgDisplayDate = new Date() /// 2010-03-05
			fieldEventDisplayYear = fieldEventgDisplayDate.getFullYear();

			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';

			//paramHash["function"] = "startProfile";
			paramHash["class"] = "field_event";
			paramHash["function"] = "startFieldEventProfile";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			toggleAsset("off");
			///////////////////////////////////////////////////////////
			commodity_guid_hold='';
			manufacture_guid_hold = '';

			field_event_checked_field_ARRAY.length=0;
			field_event_checked_field_guid="";
			field_event_field_guid = "";
			}
		else if (tab == 'fertility')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "200px"

			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startProfile";
			paramHash["class"] = "fertility";
			paramHash["function"] = "startFertilityProfile";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			toggleAsset("off");
			///////////////////////////////////////////////////////////
			elementArray.length = 0;
			fertility_target_element_TEST.length = 0;
			fertility_target_element_TEST_USED.length = 0;
			}
		else if (tab == 'blend')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "200px"

			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startBlendProfile";
			paramHash["class"] = "blend";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			toggleAsset("off")
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'agrian')
			{
			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='block';

			document.getElementById('tools').style.left = "250px";
			var newWidth = width-290;
			document.getElementById('tools').style.width = newWidth + "px"

			paramHash["function"] = "startAgrianProfile";
			paramHash["class"] = "agrian";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			toggleAsset("off")
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'operations')
			{
			toggleWorkorder(true);
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "200px";
			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startOperations";
			paramHash["class"] = "operations";
			makeRequest("/cgi-bin/main.cgi",paramHash);

			if (document.getElementById('workordertoggle'))
				{
				document.getElementById('workordertoggle').checked = true;
				}

			///Add assets back in////////////////////////////////////////
			reloadAssets();
			reloadWorkorder();
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'dispatch')
			{
			var mw =  width - 337;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "300px";
			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startDispatch";
			paramHash["class"] = "dispatch";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			}
		}
	else
		{
		if (tab == 'view')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "225px"

			document.getElementById('profile_tree').style.width= "245px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startProfile";
			makeRequest("/cgi-bin/profile.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			reloadAssets();
			reloadWorkorder();
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'asset')
			{


			document.getElementById('profile_tree').style.width= "245px";
			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='block';

			document.getElementById('tools').style.left = "250px";
			var newWidth = width-290;
			document.getElementById('tools').style.width = newWidth + "px"

			paramHash["class"] = "asset";
			paramHash["function"] = "startAssetProfile";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			//reloadAssets();
			//reloadWorkorder();
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'workorder')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "225px"

			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='none';
			var width = document.documentElement.clientWidth - 40 - 40;
			document.getElementById('profile_tree').style.width= width + "px";
			if (document.getElementById('showAllWorkorders'))
				{
				if (document.getElementById('showAllWorkorders').checked == true) {	paramHash["showAll"] = "true"; }
				else { paramHash["showAll"] = "false"; }
				}

			var listheight = parseInt(document.getElementById('profile_tree').style.height)-55;
			paramHash["listdivHeight"] = listheight + 'px';

			paramHash["class"] = "workorder";
			paramHash["function"] = "startWorkorderList";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			}
		else if (tab == 'fertility')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "225px"

			document.getElementById('profile_tree').style.width= "245px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startProfile";
			paramHash["class"] = "fertility";
			paramHash["function"] = "startFertilityProfile";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			toggleAsset("off")
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'blend')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "225px"

			document.getElementById('profile_tree').style.width= "245px";
			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startBlendProfile";
			paramHash["class"] = "blend";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			toggleAsset("off")
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'agrian')
			{
			document.getElementById('profile_tree').style.width= "245px";
			document.getElementById('map').style.display='none';
			document.getElementById('tools').style.display='block';

			document.getElementById('tools').style.left = "250px";
			var newWidth = width-290;
			document.getElementById('tools').style.width = newWidth + "px"

			paramHash["function"] = "startAgrianProfile";
			paramHash["class"] = "agrian";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			///Add assets back in////////////////////////////////////////
			toggleAsset("off")
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'operations')
			{
			toggleWorkorder(true);
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "225px";
			document.getElementById('profile_tree').style.width= "245px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startOperations";
			paramHash["class"] = "operations";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			document.getElementById('workordertoggle').checked = true;
			///Add assets back in////////////////////////////////////////
			reloadAssets();
			reloadWorkorder();
			///////////////////////////////////////////////////////////
			}
		else if (tab == 'dispatch')
			{
			var mw =  width - 237;
			document.getElementById('tools').style.left = mw + "px";
			document.getElementById('tools').style.width = "200px";
			document.getElementById('profile_tree').style.width= "215px";
			document.getElementById('map').style.display='block';
			document.getElementById('tools').style.display='block';
			paramHash["function"] = "startDispatch";
			paramHash["class"] = "dispatch";
			makeRequest("/cgi-bin/main.cgi",paramHash);
			}
		}
	//Clean out the old data
	if (tab != "event")
		{
		document.getElementById('topTreeEntry').innerHTML = "";
		}

	currentTab = tab
	///////Set search box stuff//////
	setSize();
	}

var killSystem = false;
function makeRequest(url,paramHash) {
	if (killSystem == true){ return; }

	var httpRequest;

	///put up loadding message
	if (document.getElementById("loading_animation"))
		{
		document.getElementById("loading_animation").style.display='inline';
		document.body.style.cursor = 'wait';
		}

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
			// See note below about this line
		}
	}
	else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
					   try {
							httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
						   }
						 catch (e) {}
					  }
								   }

	if (!httpRequest) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	///encode params/////////////////////
	var parameters = "";
	for (keyVar in paramHash )
		{
		parameters += keyVar + "=" + encodeURI(paramHash[keyVar]) + "&";
		}
	var strLen = parameters.length;
	parameters = parameters.slice(0,strLen-1);
	/////////////////////////////////////

	httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
	httpRequest.open('POST', url, true);
    httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httpRequest.setRequestHeader("Content-length", parameters.length);
    httpRequest.setRequestHeader("Connection", "close");
    httpRequest.send(parameters);
	//alert(parameters);

}

function alertContents(httpRequest) {

	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			if (document.getElementById("loading_animation")) { document.body.style.cursor = 'default'; document.getElementById("loading_animation").style.display='none'; }
			if (debug == 1) { writeConsole(httpRequest.responseText); }
			try
				{
				eval(httpRequest.responseText);
				}
			catch (error)
				{
				if (debug!=1)
					{
					openTestx();
					loadErrorLog("<pre>" + error.name + ": " + error.message + "\n-------------------------------\n" + httpRequest.responseText + "</pre>");
					}
				//alert('An error has been detected. Please inform you administrator');
				//closeAlertBox();
				}
		} else {
			if (document.getElementById("loading_animation")) {document.body.style.cursor = 'default';  document.getElementById("loading_animation").style.display='none'; }
			//alert('There was a problem with the request.');
		}
	}

}

function writeConsole(content) {
 //alert(content);
 var consoleRef=window.open('','myconsole',
  'width=350,height=250'
   +',menubar=0'
   +',toolbar=1'
   +',status=0'
   +',scrollbars=1'
   +',resizable=1')
 consoleRef.document.writeln(
  '<html><head><title>Console</title></head>'
   +'<body bgcolor=white onLoad="self.focus()"><pre>'
   +content
   +'</pre></body></html>'
 )
 consoleRef.document.close()
}


/// function to find the position on the page of any object///
function find_element_position(obj)
	{
		if (obj.offsetParent) {
			for (var X = 0, Y = 0; obj.offsetParent; obj = obj.offsetParent) {
				X += obj.offsetLeft;
				Y += obj.offsetTop;
			}
			return [X, Y];
		} else {
			return [obj.x, obj.y];
		}
    }


/// function to find reletve coords when an opject is clicked///
function get_event_coords(evt) {
	var x = "";
	var y = "";
	if (document.all) {
		x = evt.offsetX;
		y = evt.offsetY;
	} else {
		var Element = evt.target;

		do
			{
			Element = Element.parentNode;
			}
		while (Element.tagName.match(/svg/))

		var ep = find_element_position(Element);

		var Element = evt.target;
		var CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop = 0;
		while (Element.offsetParent) {
			CalculatedTotalOffsetLeft += Element.offsetLeft;
			CalculatedTotalOffsetTop += Element.offsetTop;
			Element = Element.offsetParent;
		}

		x = evt.pageX - CalculatedTotalOffsetLeft - ep[0];
		y = evt.pageY - CalculatedTotalOffsetTop - ep[1];
	}

	return [x,y];
}
////////////////////////////////////
 function getPosition(e) {
      e = e || window.event;
      var cursor = {x:0, y:0};
      if (e.pageX || e.pageY) {
          cursor.x = e.pageX;
          cursor.y = e.pageY;
      }
      else {
          cursor.x = e.clientX +
              (document.documentElement.scrollLeft ||
              document.body.scrollLeft) -
              document.documentElement.clientLeft;
          cursor.y = e.clientY +
              (document.documentElement.scrollTop ||
              document.body.scrollTop) -
              document.documentElement.clientTop;
      }
      return cursor;
 }


  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }



 //////////////////////////////////////////////////////////////
//Source: http://www.quirksmode.org/js/detect.html			//
//Browser name: BrowserDetect.browser						//
//Browser version: BrowserDetect.version					//
//OS name: BrowserDetect.OS									//
//////////////////////////////////////////////////////////////

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function openAlertBox(boxType,title,innerhtml,boxWidth,boxHeight,viewCloseBox)
	{

	if (document.getElementById("dataMenu"))
		{
		//alert('test');
		closeAlertBox();
		}

	var color = "";
	var corner = "";
	if (boxType == "std")
		{
		color = "#4B79B1";
		corner = "blue";
		}
	else if(boxType == "error")
		{
		color = "#ff0000";
		corner = "red";
		}
	else if (boxType == "prompt")
		{
		color = "#999999";
		corner = "grey";
		}

	if (document.getElementById('ContextMenu'))
		{
		document.body.removeChild(document.getElementById('ContextMenu'));
		}

	///Add upload box///
	var width = document.documentElement.clientWidth;
	var height = document.documentElement.clientHeight;
	var backGroundDiv = document.createElement('div');

	backGroundDiv.setAttribute('id',"backGround");
	backGroundDiv.className="backGroundDiv";
	backGroundDiv.style.width=width + "px";
	backGroundDiv.style.height=height + "px";
	document.body.appendChild(backGroundDiv);



	var dataMenu = document.createElement('div');
	dataMenu.setAttribute('id',"dataMenu");
	dataMenu.className="dataMenu";

	var top = 0;
	var left = 0;
	if (boxWidth)
		{
		dataMenu.style.width = boxWidth + "px";
		left = parseInt(width)/2 - parseInt(boxWidth)/2;
		}
	else
		{
		dataMenu.style.width = "400px";
		left = parseInt(width)/2 - 200;
		}
	if (boxHeight)
		{
		dataMenu.style.height = boxHeight + "px";
		top = parseInt(height)/2 - parseInt(boxHeight)/2;
		}
	else
		{
		dataMenu.style.height = "300px";
		top = parseInt(height)/2 - 300;
		}

	//var top = parseInt(height)/2 - 150;
	//var left = parseInt(width)/2 - 200;
	dataMenu.style.top = top + "px";
	dataMenu.style.left = left + "px";
	var closeBox = boxWidth - 75;
	var closeBoxTop = 9;

	var internalHeight = parseInt(dataMenu.style.height) - 33;

	var html = "";
	html += "<table CELLSPACING='0' CELLPADDING='0' style='width:" + boxWidth + "px;height:" + boxHeight + "px;'>";
	html += "<tr>";
	middle = boxWidth - 28;
	html += "	<td style='width:14px;height:14px;background-image: url(/images/" + corner + "_left.gif)'>&nbsp;</td>";
	html += "	<td style='background-color: " + color +";height:25px;color:white;font-size: 10pt;width:" + middle + "px;' align='center'>" + title + "</td>";
	html += "	<td valign='bottom' style='width:14px;height:14px;background-image: url(/images/" + corner + "_right.gif)'><img style='cursor: pointer;filter:alpha(opacity=0);-moz-opacity:.0;opacity:.0;' src=\"/images/icons/close_icon.gif\" onclick=\"closeAlertBox()\"></td>";
	html += "</tr>";
	html += "<tr><td colspan='3' bgcolor='#eeeeee' id='mid' style='height:" + internalHeight + "px;width:" + boxWidth + "px;' valign='top'>";
	html += innerhtml;
	html += "</td></tr>";
	html += "<tr>";
	html += "<td style='width:14px;height:7px;font-size: 1pt;'><img src='/images/left_b.gif'></td>";
	html += "<td style='background-color: #eeeeee;height:7px;font-size: 1pt;width:" + middle + "px;'></td>";
	html += "<td style='width:14px;height:7px;font-size: 1pt;'><img src='/images/right_b.gif'></td>";
	html += "</tr>";
	html += "</table>";
	if (viewCloseBox)
		{
		html += "<span onclick=\"if (!event) { event = window.event; };if (document.getElementById('ContextMenu') != null){document.body.removeChild(document.getElementById('ContextMenu'));document.body.removeChild(document.getElementById('ContextMenu2'));};closeAlertBox();\" style='position:absolute;left:" + closeBox + "px;top:" + closeBoxTop + "px;font-size: 8pt;color:white;cursor: pointer;'>Close/Cancel</span>";
		}
	dataMenu.innerHTML = html;
	document.body.appendChild(dataMenu);
	}

function closeAlertBox()
	{
	try
		{
		if (document.getElementById('dataMenu'))
			{
			document.body.removeChild(document.getElementById('dataMenu'));
			}

		if (document.getElementById('backGround'))
			{
			document.body.removeChild(document.getElementById('backGround'));
			}
		}
	catch (e)
		{
		}
	}

function openSubAlertBox(innerhtml,boxWidth,boxHeight)
	{
	var width = document.documentElement.clientWidth;
	var height = document.documentElement.clientHeight;

	var backGroundDiv = document.createElement('div');

	backGroundDiv.setAttribute('id',"backGround2");
	backGroundDiv.className="backGroundDiv";
	backGroundDiv.style.width=width + "px";
	backGroundDiv.style.height=height + "px";
	document.body.appendChild(backGroundDiv);

	var alertDiv = document.createElement('div');
	alertDiv.setAttribute('id',"subDataMenu");
	alertDiv.style.width= boxWidth + "px";
	alertDiv.style.height= boxHeight + "px";
	alertDiv.style.position = "absolute";
	var top = height/2 - 100;
	var left = width/2 - boxWidth/2;
	alertDiv.style.top=top + "px";
	alertDiv.style.left=left + "px";
	//alertDiv.style.zIndex = "200"  //changed from 200 to 100 to allow for the calendarPopup to be in front
	alertDiv.style.zIndex = "100"
	alertDiv.style.backgroundColor = "#ffffff";
	alertDiv.style.border = "1px solid red";
	alertDiv.style.padding = "3px";
	alertDiv.style.fontSize  = "8pt";
	alertDiv.innerHTML = innerhtml;
	document.body.appendChild(alertDiv);
	}

function closeSubAlertBox()
	{
	if (document.getElementById('backGround2'))
		{
		document.body.removeChild(document.getElementById('backGround2'));
		}

	if (document.getElementById('subDataMenu'))
		{
		document.body.removeChild(document.getElementById('subDataMenu'));
		}
	}

///AJAX file Upload
function startCallback()
	{
	// make something useful before submit (onStart)
	return true;
	}

function completeCallback(response)
	{
	// make something useful after (onComplete)
	eval(response);
	}

function editBox(mode,type,ex_number,in_number,newbdy)
	{
	///Get location and size on page///////////////////
	var top = VE6map.GetTop();
	var left = VE6map.GetLeft();
	var width = VE6map.GetWidth();
	var height = VE6map.GetHeight();
	///Add upload box///
	var win_width = document.documentElement.clientWidth;
	var win_height = document.documentElement.clientHeight;

	if (document.getElementById('backGround_top'))
		{
		return false;
		}

	var backGroundDiv_top = document.createElement('div');
	backGroundDiv_top.setAttribute('id',"backGround_top");
	backGroundDiv_top.className="backGroundDiv";
	backGroundDiv_top.style.height = top + "px";
	backGroundDiv_top.style.width = win_width + "px";
	backGroundDiv_top.style.zIndex = 100;
	document.body.appendChild(backGroundDiv_top);

	var backGroundDiv_bottom = document.createElement('div');
	backGroundDiv_bottom.setAttribute('id',"backGroundDiv_bottom");
	backGroundDiv_bottom.className="backGroundDiv";
	var topb = top + height;
	var heightb = win_height - top - height;
	if (heightb < 0)
		{
		heightb = 0;
		}
	backGroundDiv_bottom.style.top = topb + "px";
	backGroundDiv_bottom.style.height = heightb + "px";
	backGroundDiv_bottom.style.width = win_width + "px";
	backGroundDiv_bottom.style.zIndex = 100;
	document.body.appendChild(backGroundDiv_bottom);

	var backGroundDiv_left = document.createElement('div');
	backGroundDiv_left.setAttribute('id',"backGroundDiv_left");
	backGroundDiv_left.className="backGroundDiv";
	backGroundDiv_left.style.width = left + "px";
	backGroundDiv_left.style.top = top + "px";
	backGroundDiv_left.style.height = height + "px";
	backGroundDiv_left.style.zIndex = 100;
	document.body.appendChild(backGroundDiv_left);


	var backGroundDiv_right = document.createElement('div');
	backGroundDiv_right.setAttribute('id',"backGroundDiv_right");
	backGroundDiv_right.className="backGroundDiv";
	var leftb = width + left;
	backGroundDiv_right.style.left = leftb + "px";
	var widthb = win_width - width - left;
	backGroundDiv_right.style.width = widthb + "px";
	backGroundDiv_right.style.top = top + "px";
	backGroundDiv_right.style.height = height + "px";
	backGroundDiv_right.style.zIndex = 100;
	document.body.appendChild(backGroundDiv_right);

	var tooldiv = document.createElement('div');
	tooldiv.setAttribute('id',"tooldiv");
	tooldiv.style.position = "absolute";
	//tooldiv.style.backgroundColor = "white";
	tooldiv.style.borderTop = "1px solid black";
	tooldiv.style.borderBottom = "1px solid black";
	tooldiv.style.borderLeft = "1px solid black";
	var links_top = top;
	tooldiv.style.top = links_top + "px";
	tooldiv.style.left = left + "px";
	//tooldiv.style.width = width;
	tooldiv.style.height = "16px";
	tooldiv.style.zIndex = 200;
	tooldiv.style.verticalAlign = "middle";

	if (mode == "sample")
		{
		tooldiv.innerHTML = "<a class='tool_item' onclick=\"mapDis.unLoadStage('save','sample');saveDirectedSamples();\">Save</a><a class='tool_item' onclick=\"mapDis.unLoadStage('cancel')\">Cancel</a>";
		}
	else if (mode == "mgmtZones")
		{
		tooldiv.innerHTML = "<a class='tool_item' onclick=\"mapDis.unLoadStage('save','mgmtZones');displayDrawnZones();\">Done</a><a class='tool_item' onclick=\"mapDis.unLoadStage('cancel')\">Cancel</a>";
		}
	else if (mode == "fieldTrial")
		{
		tooldiv.innerHTML = "<a class='tool_item' onclick=\"mapDis.unLoadStage('save','fieldTrial');saveTrialBoundary();\">Save</a><a class='tool_item' onclick=\"mapDis.unLoadStage('cancel')\">Cancel</a>";
		}
	else
		{
		tooldiv.innerHTML = "<a class='tool_item' onclick=\"mapDis.unLoadStage('save','polygon');saveBoundary();\">Save</a><a class='tool_item' onclick=\"mapDis.unLoadStage('cancel');cancelTheEdit('" + type + "','" + ex_number + "','" + in_number + "','" + newbdy + "');\">Cancel</a>";
		}
	document.body.appendChild(tooldiv);

	}

function unloadEditBox(tools)
	{
	document.body.removeChild(document.getElementById('backGround_top'));
	document.body.removeChild(document.getElementById('backGroundDiv_bottom'));
	document.body.removeChild(document.getElementById('backGroundDiv_left'));
	document.body.removeChild(document.getElementById('backGroundDiv_right'));
	document.body.removeChild(document.getElementById('tooldiv'));
	}

function loadPrefs()
	{
	//debug = 1;
	var paramHash = new Array();
	paramHash["function"] = "loadPrefs";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function savePrefs()
	{
	var theform = document.getElementById('prefsform');
	var units = "";
	/*var preferencesCrop = "";
	var preferencesCrop_num = "";
	var preferencesElement = "";
	var preferencesElement_product = "";*/

	for (var i=0; i < theform.units.length; i++)
		{
		//alert(theform.units[i].value);
		if (theform.units[i].checked)
			{
			var units = theform.units[i].value;
			}
		}

	for (var i=0; i < theform.preferencesDefaultTab_select.length; i++)
		{
		if (theform.preferencesDefaultTab_select[i].selected == true)
			{
			default_tab = theform.preferencesDefaultTab_select[i].value;
			}
		}

	//default_tab = theform.preferencesDefaultTab_select[0].selected;
	//alert(default_tab);

	/*for (var i=0; i < theform.preferencesCrop_select.length; i++)
		{

		if (theform.preferencesCrop_select[i].selected)
			{
			//alert(theform.preferencesCrop_select[i].value);
			var preferencesCrop = theform.preferencesCrop_select[i].value;
			if (preferencesCrop == "-99")
				{
				preferencesCrop = "";
				}
			}
		}


	if (theform.preferencesCrop_text.value != "")
		{
		//alert(preferencesCrop_num);
		preferencesCrop_num = theform.preferencesCrop_text.value;
		}
	//alert(preferencesCrop_n);

	for (var i=0; i < theform.preferencesElement_select.length; i++)
		{

		if (theform.preferencesElement_select[i].selected)
			{
			//alert(theform.preferencesElement_select[i].value);
			var preferencesElement = theform.preferencesElement_select[i].value;
			}

		if (preferencesElement == "-99")
				{
				preferencesElement = "";
				}
		}

	try{
		for (var i=0; i < theform.preferencesProduct_select.length; i++)
			{

			if (theform.preferencesProduct_select[i].selected)
				{
				//alert(theform.preferencesProduct_select[i].value);
				var preferencesElement_product = theform.preferencesProduct_select[i].value;
				}

			if (preferencesElement_product == "-99")
				{
				preferencesElement_product = "";
				}
			}
		}
	catch(e)
		{
		}*/

	var paramHash = new Array();
	//debug = 1;
	//alert(units);
	paramHash["units"] = units;
	paramHash["default_tab"] = default_tab;
	/*paramHash["preferencesCrop"] = preferencesCrop;
	paramHash["preferencesCrop_num"] = preferencesCrop_num;
	paramHash["preferencesElement"] = preferencesElement;
	paramHash["preferencesElement_product"] = preferencesElement_product;*/
	paramHash["function"] = "savePrefs";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function loadSetup()
	{
	//debug = 1;
	var paramHash = new Array();
	paramHash["function"] = "loadSetup";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function loadTools()
	{
	var html = "<div style='padding:3px;border-bottom:1px solid #999999;'>" +
		"<table style='width:100%'>" +
		"<tr><td nowrap>Select Tool: <select value='-99' onchange=\"loadToolSub(this.value,'toolContent')\">" +
		"<option value='-99'>--------</option>" +
		"<option value='batchExport'> Batch Export</option>" +
		"<option value='profileMover'> Profile Mover</option>" +
		"<option value='asappliedBatchUpload'> As-Applied Batch Upload </option>";
//	if (user_level <= 5 && mapshotsAccess == 1)
//		{
//		html += "<option value='fertilizer'> Fertilizer Management</option>";
//		//html += "<option value='productManagement'> Product Management</option>";
//		}
	//if (user_level <= 5)
	if (user_level <= 5)
		{
		html += "<option value='productManagement'> Product Management</option>";
		}
	html += "</select></td><td align='right'>" +
		"<button type='button' onclick='closeAlertBox()'>Close</button>" +
		"</td></tr></table></div>";
	html += "<div id='toolContent' style='height:450px;width:760px;padding:5px;overflow:auto;'></div>";
	openAlertBox("std","Tools",html,770,500);
	}

function loadDownloads()
	{
	var paramHash = new Array();
	paramHash["function"] = "loadDownloads";
	makeRequest("/cgi-bin/data.cgi",paramHash);
	}

function saveSetup()
	{
	//debug = 1;
	var theform = document.getElementById('setupform');
	var paramHash = new Array();
	paramHash["real_name"] = theform.real_name.value;
	paramHash["company"] = theform.company.value;
	paramHash["job_title"] = theform.job_title.value;
	paramHash["phone"] = theform.phone.value;
	paramHash["cell"] = theform.cell.value;
	paramHash["fax"] = theform.fax.value;
	paramHash["address1"] = theform.address1.value;
	paramHash["address2"] = theform.address2.value;
	paramHash["city"] = theform.city.value;
	paramHash["state"] = theform.state.value;
	paramHash["zip"] = theform.zip.value;
	paramHash["function"] = "saveSetup";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

//////Admin functions/////////
function loadAdmin(userlevel,var_guid)
	{
	var html = "<div style='padding:3px;border-bottom:1px solid #999999;'><table style='width:100%'><tr><td nowrap>Select Tool: <select onchange=\"loadAdminSub(this.value,'adminContent')\"><option value='-99' >--------</option>"

	if (mapshotsAccess == 1)
		{
		//html += "<option value='equMgnt'>Equation Manager</option>"
		html += "<option value='agrianEnrolment'> Agrian Enrolment</option>"
		}
	html += "<option value='batchAssetReports'> Batch Asset Reports</option>"
	if (userlevel == 3 || userlevel == 1 || userlevel == 2)
		{
		html += "<option value='billing'> Billing</option>"
		}
	if (userlevel == 3 || userlevel == 1 || userlevel == 2)
		{
		html += "<option value='checkBoundary'> Check Boundary</option>"//<option value='user'> User Admin</option>"
		}
	if (mapshotsAccess == 1)
		{
		html += "<option value='equMgnt'>Equation Manager</option>"
		//html += "<option value='agrianEnrolment'> Agrian Enrolment</option>"
		}

	if (var_guid == '5fa96579-5178-425b-89c4-fc0dafb97ffd')
		{
		if (userlevel == 3 || userlevel == 1)
			{
			html += "<option value='seed_management'> Seed Management</options>"
			html += "<option value='field_trial'> Field Trial</options>"
			}
		}
	//html += "<option value='undoDelete'>Un-Delete</option><option value='batchAssetReports'> Batch Asset Reports</option><option value='userlog'>User Log History</option>"
	//alert(userlevel);
	if (userlevel == 3 || userlevel == 1 || userlevel == 2)
		{
		html += "<option value='undoDelete'>Un-Delete</option>";
		}
	html += "<option value='user'> User Admin</option><option value='userlog'>User Log History</option>"
	if (userlevel == 1)
		{
		html += "<option value='field_trial' style='color:#ffffff;background-color:green;'> Field Trial</options>"
		html += "<option value='billing_ledger' style='color:#ffffff;background-color:red;'> Billing Ledger</options>"
		html += "<option value='equipment_inventory' style='color:#ffffff;background-color:red;'> Equipment Inventory</options>"
		html += "<option value='var_maintenance' style='color:#ffffff;background-color:red;'> Var Maintenance</options>"
		}

	//html += "<option value='seed_management' style='color:#ffffff;background-color:green;'> Seed Management</options>"

	html += "</select></td><td align='right'><button type='button' onclick='closeAlertBox()'>Close</button></td></tr></table></div>"; //<option value='AandL_Login'> A&L Portal</option><option value='batchAssetReports'> Batch Asset Reports</option><option value='equMgnt'>Equation Manager</option><option value='userlog'>User Log History</option>
	html += "<div id='adminContent' style='height:450px;width:750px;padding:5px;overflow:auto;'></div>";
	openAlertBox("std","Administration",html,760,500);
	}



function loadAdminSub(type,div)
	{
	//debug = 1;
	var paramHash = new Array();
	if (type == "user") { paramHash["function"] = "loadUserAdmin"; }
	else if (type == "-99") { document.getElementById('adminContent').innerHTML= ""; seed_management_hold_ID = "seed_management_variety_TD";  }
	else if (type == "batchAssetReports") { paramHash["function"] = "loadBatchAssetReports"; }
	else if (type == "batchExport") { paramHash["function"] = "loadBatchExport"; }
	else if (type == "billing") { paramHash["function"] = "loadBilling"; paramHash["class"] = "billing"; }
	else if (type == "checkBoundary") { paramHash["function"] = "loadCheckBoundary"; }
	else if (type == "userlog") { paramHash["function"] = "loadUserLogAdmin"; }
	else if (type == "undoDelete") { paramHash["function"] = "undoDeleteInterface"; paramHash["class"] = "administrationUndo"; }
	else if (type == "equMgnt") { paramHash["function"] = "loadEquationInterface"; paramHash["class"] = "administration"; }
	else if (type == "AandL_Login") { paramHash["function"] = "loadAandL"; paramHash["class"] = "administration"; }
	else if (type == "agrianEnrolment") { paramHash["function"] = "loadAgrianEnrolment"; paramHash["class"] = "administration"; }
	else if (type == "billing_ledger") { paramHash["function"] = "load_billing_ledger"; paramHash["class"] = "billing_ledger"; }
	else if (type == "equipment_inventory") { paramHash["function"] = "load_equipment_inventory"; paramHash["class"] = "equipment_inventory"; }
	else if (type == "seed_management") { paramHash["function"] = "load_seed_management"; paramHash["class"] = "seed_management"; }
	else if (type == "field_trial") { paramHash["function"] = "load_field_trial"; paramHash["class"] = "field_trial";field_trial_hold_ID = "field_trial_chemical_program_TD";field_trial_ADD_CHEMICAL_PROGRAM_SWITCH = 0;field_trial_chemical_program_edit_state = "";field_trial_chemical_program_edit_state_index = "";	 }
	else if (type == "var_maintenance") { paramHash["function"] = "load_var_maintenance"; paramHash["class"] = "var_maintenance"; }

	if (type != "-99")
		{
		paramHash["div"] = div;
		makeRequest("/cgi-bin/main.cgi",paramHash);
		}
	}

function loadToolSub(type,div)
	{
	if (type != "")
		{
		var paramHash = new Array();
		paramHash["class"] = "tools"
		if (type == "profileMover") { paramHash["function"] = "loadProfileMover"; }
		else if (type == "-99") { document.getElementById('toolContent').innerHTML= ""; }
		else if (type == "batchExport") { paramHash["function"] = "loadBatchExport"; }
		else if (type == "fertilizer") { paramHash["function"] = "loadFertilizerAdmin"; paramHash["class"] = "tools";}
		else if (type == "productManagement") { paramHash["function"] = "loadProductManagement"; paramHash["class"] = "product_management";}
		else if (type == "asappliedBatchUpload") { paramHash["function"] = "loadAsappliedBatchUpload"; }
		if (type != "-99")
			{
			paramHash["div"] = div;
			makeRequest("/cgi-bin/main.cgi",paramHash);
			}
		}
	else
		{
		document.getElementById('toolContent').innerHTML = "";
		}
	}

function loadProfileMoveSelect(level)
	{
	var paramHash = new Array();
	paramHash["class"] = "tools"
	paramHash["function"] = "loadProfileMoveSelect";
	paramHash["div"] = "profileDiv";
	paramHash["level"] = level;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function moveProfiles(from,to)
	{
	fromSelect = document.getElementById("admin_" + from);
	toSelect = document.getElementById("admin2_" + from);
	var guidsToMove = ""
	var namesToSkip = ""
	for (var i=0; i < fromSelect.options.length; i++)
		{
		if (fromSelect.options[i].selected == true)
			{
			checkName = 0;
			for (var j=0; j < toSelect.options.length; j++)
				{
				if (toSelect.options[j].text == fromSelect.options[i].text) { checkName = 1; }
				}
			if (checkName == 0)
				{
				guidsToMove += "'" + fromSelect.options[i].value + "',"
				}
			else
				{
				namesToSkip += fromSelect.options[i].text + ","
				}
			}
		}
	if (namesToSkip != "")
		{
		namesToSkip = namesToSkip.slice(0,namesToSkip.length-1);
		alert("The following fiels have been skipped: " + namesToSkip);
		}

	if (guidsToMove != "")
		{
		guidsToMove = guidsToMove.slice(0,guidsToMove.length-1);
		}
	else
		{
		alert("No profile selected to move");
		return false;
		}

	var paramHash = new Array();
	paramHash["class"] = "tools"
	paramHash["function"] = "moveProfiles";
	paramHash["profilesToMove"] = guidsToMove;
	paramHash["newProfile"] = document.getElementById("admin2_" + to).value;
	paramHash["from"] = from;
	paramHash["to"] = to;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openSubAlertBox(html,300,150);
	}

var tabList = new Array();
function loadUser(guid,div)
	{
	//debug = 1;
	var paramHash = new Array();
	paramHash["function"] = "loadUser";
	paramHash["user_guid"] = guid;
	paramHash["div"] = div;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}
function addUserProfile(event,maxLevel)
	{
	if (!event) { event = window.event; }
	var position = getPosition(event);
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id',"profileselect");
	var left = position.x - 150;
	var top = position.y - 50;
	newdiv.style.left = left + "px";
	newdiv.style.top = top + "px";
	newdiv.style.width = "250px";
	newdiv.style.height = "150px";
	newdiv.style.position= "absolute";
	newdiv.style.zIndex = 300;
	newdiv.style.backgroundColor = "white";
	newdiv.style.border = "1px solid #ff0000";
	newdiv.style.padding = "3px";
	//newdiv.innerHTML = maxLevel;
	document.body.appendChild(newdiv);

	//debug = 1;
	var paramHash = new Array();
	paramHash["function"] = "startProfileSelect";
	paramHash["maxLevel"] = maxLevel;
	paramHash["div"] = "profileselect";
	paramHash["userguid"] = document.getElementById('userform').userguid.value;
	paramHash["profile_view_id"] = document.getElementById('userform').profile_view_id.value;
	paramHash["profile_level"] = document.getElementById('userform').profile_level.value;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function loadProfileChild(guid,profile_view,nextlevel,maxlevel,id)
	{
	if (nextlevel > maxlevel) { return false; }
	//debug = 1;
	var paramHash = new Array();
	paramHash["function"] = "loadProfileChild";
	paramHash["guid"] = guid;
	paramHash["profile_view"] = profile_view;
	paramHash["nextlevel"] = nextlevel;
	paramHash["maxlevel"] = maxlevel;

	if (id)
		{
		paramHash["id"] = id;
		}
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function insertProfileAccess(guid,name)
	{
	if (guid == "-99") { alert('Please select a profile'); return false; }
	var tbl = document.getElementById("profileAccess");
	var i=0;
	while (i < tbl.rows.length)
		{
		if (guid == tbl.rows[i].id) { document.body.removeChild(document.getElementById('profileselect')); return false; }
		++i;
		}
	var lastRow = tbl.rows.length;
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);
	row.id = guid;
	row.style.backgroundColor = "#cccccc";

	var cellDelete = row.insertCell(0);
	cellDelete.innerHTML = "<img style='cursor: pointer;' src='/images/icons/delete_icon.gif' onclick=\"deleteRow(this,'profileAccess');\">";

	var cellLeft = row.insertCell(1);
	cellLeft.innerHTML = name;

	document.body.removeChild(document.getElementById('profileselect'));
	}

function deleteRow(button,tableID)
	{
	var row = button.parentNode.parentNode;
	var tbody = document.getElementById(tableID).getElementsByTagName('tbody')[0];
	tbody.removeChild(row);
	}

function selectProfileViewLevels(profile_view_id)
	{
	//debug = 1;
	var paramHash = new Array();
	paramHash["profile_view_id"] = profile_view_id;
	paramHash["function"] = "selectProfileViewLevels";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	clearProfileAccess();
	}
function clearProfileAccess()
	{
	var tbl = document.getElementById("profileAccess");
	var tbody = tbl.getElementsByTagName('tbody')[0];
	var i = 0;
	while (i < tbl.rows.length)
		{
		tbody.removeChild(tbl.rows[i]);
		}
	}

function deleteUser()
	{
	var theform = document.getElementById('userform');

	var paramHash = new Array();
	paramHash["userguid"] = theform.userguid.value;
	paramHash["function"] = "deleteUser";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function saveUser()
	{
	var theform = document.getElementById('userform');

	//debug = 1;
	var paramHash = new Array();

	paramHash["userguid"] = theform.userguid.value;

	var error_check = 0;
	if (theform.name.value != "")
		{
		var str=theform.name.value
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str)) { }
		else
			{
			alert("Please input a valid email address!")
			theform.name.style.backgroundColor = "#FFFFCA";
			return false;
			}
		paramHash["name"] = theform.name.value;
		}
	else { theform.name.style.backgroundColor = "#FFFFCA"; ++error_check; }

	if (theform.password.value != "") { paramHash["password"] = theform.password.value; }
	else { theform.password.style.backgroundColor = "#FFFFCA"; ++error_check; }

	if (theform.real_name.value != "") { paramHash["real_name"] = theform.real_name.value; }
	else { theform.real_name.style.backgroundColor = "#FFFFCA"; ++error_check; }

	if (theform.level.value != "") { paramHash["level"] = theform.level.value; }
	else { theform.level.style.backgroundColor = "#FFFFCA"; ++error_check; }

	if (theform.profile_view_id.value != "") { paramHash["profile_view_id"] = theform.profile_view_id.value; }
	else { theform.profile_view_id.style.backgroundColor = "#FFFFCA"; ++error_check; }

	if (theform.profile_level.value != "") { paramHash["profile_level"] = theform.profile_level.value; }
	else { theform.profile_level.style.backgroundColor = "#FFFFCA"; ++error_check; }

	if (error_check > 0)
		{
		alert("Please Fill in Required Fields");
		return false;
		}
	if (theform.active.checked == true) { paramHash["active"] = 1; }
	else { paramHash["active"] = 0; }
	if (theform.custom_equ.checked == true) { paramHash["custom_equ"] = true; }
	else { paramHash["custom_equ"] = false; }

	var profile_list = "";
	var tbl = document.getElementById("profileAccess");
	var i=0;
	while (i < tbl.rows.length)
		{
		profile_list += tbl.rows[i].id + ",";
		++i;
		}
	profile_list = profile_list.substring(0,profile_list.length-1)
	paramHash["profileAccess"] = profile_list;

	paramHash["company"] = theform.company.value;
	paramHash["job_title"] = theform.job_title.value;
	paramHash["address1"] = theform.address1.value;
	paramHash["address2"] = theform.address2.value;
	paramHash["city"] = theform.city.value;
	paramHash["state"] = theform.state.value;
	paramHash["zip"] = theform.zip.value;
	paramHash["phone"] = theform.phone.value;
	paramHash["fax"] = theform.fax.value;
	paramHash["cell"] = theform.cell.value;

	//Look for tabs//
	for(i=0; i< theform.elements.length; i++)
		{
		if (theform.elements[i].name.indexOf('tab') !=-1)
			{
			paramHash[theform.elements[i].name] = theform.elements[i].checked;
			}
		}
	paramHash["function"] = "saveUser";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

var alertTimerId = 0;

function timerClickHandler (event,guid,type,view_id)
{
if (!event) { event = window.event; }
if (BrowserDetect.browser == "Explorer") {  window.event.cancelBubble = true;}
else { event.stopPropagation(); }
  if ( alertTimerId == 0 )
  {
    // Start the timer
    alertTimerId = setTimeout ("loadProfileBoundries('" + guid + "','" + type + "','" + view_id + "')", 1500 );
  }
  else
  {
    clearTimeout ( alertTimerId );
	alertTimerId = 0;
  }
}




var report_view_id;
function openReportOptions(report,div,view_id)
	{
	report_view_id = view_id;
	viewLabel = 'Field';
	if (report == 'zone_map'){ viewLabel = 'Zone'; }
	if (report == "map" || report == "zone_map")
		{
		html = "<form id='reportform' style='display:inline'><table style='font-size: 8pt'>";
		html += "<tr><td colspan='4'>" + viewLabel + " Labels:</td></tr>";
		html += "<tr><td><input type='hidden' value='" + report + "' name='reportsSelectChoice' /><input type='radio' id='fieldLabels' name='fieldLabels' style='width:auto' value='none'></td><td>None</td></tr>";
		html += "<tr><td><input type='radio' id='fieldLabels' name='fieldLabels' style='width:auto' value='fieldNames' checked></td><td>" + viewLabel + " Names</td></tr>";
		html += "<tr><td><input type='radio' id='fieldLabels' name='fieldLabels' style='width:auto' value='fieldNamesArea'></td><td>" + viewLabel + " Names with Area</td></tr>";
		html += "<tr><td colspan='4'>Options:</td></tr>";
		html += "<tr><td><input type='checkbox' class='radio' id='zoomToFields'></td><td nowrap>Zoom to Selected " + viewLabel + "(s)</td></tr>";
		if (report == 'map')
		{
			html += "<tr><td><input type='checkbox' class='radio' id='hideUnselected'></td><td nowrap>Hide Unselected Field(s)</td><td><input type='checkbox' class='radio' id='showAttributes'></td><td nowrap>Show Attributes</td></tr>";
			html += "<tr><td colspan='3' style='padding-top:5px'>Color Labels</td></tr></table><table>";
			html += "<tr><td><div style='border:1px solid black;background-color: rgb(173,35,35);width:10px;height:10px;'></td><td><input style='font-size: 7pt' type=text name='redNotes'></td><td><div style='border:1px solid black;background-color: rgb(255,238,51);width:10px;height:10px;'></td><td><input style='font-size: 7pt' type=text name='yellowNotes'></td><td><div style='border:1px solid black;background-color: rgb(42,75,215);width:10px;height:10px;'></div></td><td><input style='font-size: 7pt' type=text name='blueNotes'></td></tr>";
			html += "<tr><td><div style='border:1px solid black;background-color: rgb(29,105,20);width:10px;height:10px;'></div></td><td><input style='font-size: 7pt' type=text name='greenNotes'></td><td><div style='border:1px solid black;background-color: rgb(129,74,25);width:10px;height:10px;'></td><td><input style='font-size: 7pt' type=text name='brownNotes'></td><td><div style='border:1px solid black;background-color: rgb(129,38,192);width:10px;height:10px;'></div></td><td><input style='font-size: 7pt' type=text name='purpleNotes'></td></tr>";
			html += "<tr><td><div style='border:1px solid black;background-color: rgb(216,196,133);width:10px;height:10px;'></div></td><td><input style='font-size: 7pt' type=text name='tanNotes'></td><td><div style='border:1px solid black;background-color: rgb(129,197,122);width:10px;height:10px;'></td><td><input style='font-size: 7pt' type=text name='lightgreenNotes'></td><td><div style='border:1px solid black;background-color: rgb(157,175,255);width:10px;height:10px;'></div></td><td><input style='font-size: 7pt' type=text name='lightblueNotes'></td></tr>";
			html += "<tr><td><div style='border:1px solid black;background-color: rgb(255,146,51);width:10px;height:10px;'></div></td><td><input style='font-size: 7pt' type=text name='orangeNotes'></td><td><div style='border:1px solid black;background-color: rgb(87,87,87);width:10px;height:10px;'></div></td><td><input style='font-size: 7pt' type=text name='greyNotes'></td><td>&nbsp;</td><td>&nbsp;</td></tr>";
		}
		html += "</table><table><tr><td colspan='2'>Notes<br/><textarea name='notes' style='height:40px;width:350px;font-size: 8pt;'></textarea></td></tr>";
		html += "<tr><td colspan='2'><input type='checkbox' onclick=\"if (this.checked == true) { document.getElementById('saveNameBox').style.display='inline';} else { document.getElementById('saveNameBox').style.display='none'; }\" style='width:15px' id='savePrint'/>Print & Save&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style='display:none;' id='saveNameBox'>Name: <input type='text' id='saveName'/></div></td></tr>";
		html += "<tr><td colspan='2'><button type='button' onclick='submitMap();'>Submit</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type='button' onclick='closeAlertBox()'>Cancel</button></td></tr>";
		html += "</table>";
		html += "</form>";

		openAlertBox("std","Map Report",html,575,400);
		}
	else if (report == "summary_pdf")
		{
		submitSummary("pdf");
		}
	else if (report == "summary_xls")
		{
		submitSummary("xls");
		}
	else if (report == "boundaryMap")
		{
		html = "<form id='reportform' style='display:inline'><table>";
		html += "<tr><td>Notes<br/><textarea name='notes' style='height:50px;width:300px;font-size: 8pt;'></textarea></td></tr>";
		html += "<tr><td><button type='button' onclick='submitBoundaryMap();'>Submit</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type='button' onclick='closeAlertBox()'>Cancel</button></td></tr>";
		html += "</table></form>";
		openAlertBox("std","Map Report",html,400,400);
		}
	else if (report == "4pannel")
		{
		elementalSoilMapReport(document.getElementById('soil_soil_guid').value,document.getElementById('soil_element_list').value)
		}
	else if (report == "sampleIdMap")
		{
		submitSampleIdMap();
		}
	else if (report == "sampleIdMapWithData")
		{
		submitSampleIdMapWithData();
		}
	else if (report == "veris_report")
		{
		verisMapReport(document.getElementById('veris_veris_guid').value,document.getElementById('veris_element_list').value)
		}
	}

function openAerialImageReport(type,guid,imageId)
	{
	if (type == "aerial_current_map")
		{
		var div = document.getElementById("div_aerial_imagery_options");
		var inputs = div.getElementsByTagName("input");
		var selected_product = "";
		for (var i = 0; i < inputs.length; i++)
			{
			if (inputs[i].name == "aerial_image_type" && inputs[i].checked)
				{
				selected_product = inputs[i].value;
				break;
				}
			}

		if (selected_product == "")
			{
			alert("Please select a map product");
			return;
			}
		else
			{
			// get bounding box
			var width = VE6map.GetWidth();
			var height = VE6map.GetHeight();
			pixel = new VEPixel(0, height);
			var LL = VE6map.PixelToLatLong(pixel);
			pixel = new VEPixel(width, 0);
			var UR = VE6map.PixelToLatLong(pixel);

			var paramHash = new Array();
			paramHash["minx"] = LL.Longitude;
			paramHash["miny"] = LL.Latitude;
			paramHash["maxx"] = UR.Longitude;
			paramHash["maxy"] = UR.Latitude;
			paramHash["centerPoint"] = VE6map.GetCenter().Longitude + "," + VE6map.GetCenter().Latitude;

			paramHash["class"] = "reports";
			paramHash["function"] = "aerialMap";
			paramHash["guid"] = guid;
			paramHash["imageId"] = imageId;
			paramHash["productType"] = selected_product;

			openAlertBox("std","Processing Report","<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...",300,150);
			makeRequest("/cgi-bin/main.cgi",paramHash);
			}
		}
	else if (type == "aerial_print_imagery")
		{

		}
	}

function openAsappliedImageReport(type,guid,appliedDate,productName)
	{
	if (type == "asapplied_current_map")
		{
		var div = document.getElementById("div_asapplied_options");
		var inputs = div.getElementsByTagName("input");
		var selected_product = "";
		for (var i = 0; i < inputs.length; i++)
			{
			if (inputs[i].name == "asapplied_product" && inputs[i].checked)
				{
				selected_product = inputs[i].value;
				break;
				}
			}

		if (selected_product == "")
			{
			alert("Please select a map product");
			return;
			}
		else
			{
			// get bounding box
			var width = VE6map.GetWidth();
			var height = VE6map.GetHeight();
			pixel = new VEPixel(0, height);
			var LL = VE6map.PixelToLatLong(pixel);
			pixel = new VEPixel(width, 0);
			var UR = VE6map.PixelToLatLong(pixel);

			var paramHash = new Array();
			paramHash["minx"] = LL.Longitude;
			paramHash["miny"] = LL.Latitude;
			paramHash["maxx"] = UR.Longitude;
			paramHash["maxy"] = UR.Latitude;
			paramHash["centerPoint"] = VE6map.GetCenter().Longitude + "," + VE6map.GetCenter().Latitude;

			paramHash["class"] = "reports";
			paramHash["function"] = "asappliedMap";
			paramHash["guid"] = guid;
			paramHash["appliedDate"] = appliedDate;
			paramHash["productName"] = selected_product;

			openAlertBox("std","Processing Report","<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...",300,150);
			makeRequest("/cgi-bin/main.cgi",paramHash);
			}
		}
	}

function submitMap()
	{
	//alert(type);
	var theform = document.getElementById('reportform');
	//debug = 1;
	var paramHash = new Array();
	var guidColor = ""
	for (var key in overviewGUIDs)
		{
		var shape = VE6map.GetShapeByID(key);
		var color = shape.GetFillColor();
		guidColor += overviewGUIDs[key] + ":" +  color.R + "," + color.G + "," + color.B + "~";
		}

	// get current layer type
	paramHash["veLayerName"] = "";
	var mapStyle = VE6map.GetMapStyle();
	if (mapStyle == VEMapStyle.Hybrid) {
		paramHash["veLayerName"] = "hybrid";
	} else if (mapStyle == VEMapStyle.Road) {
		paramHash["veLayerName"] = "roads";
	} else if (mapStyle == VEMapStyle.Aerial) {
		paramHash["veLayerName"] = "aerial";
	}

	// get field label option
	paramHash["fieldLabels"] = "";
	var radios = document.forms["reportform"].fieldLabels;
	if (radios) {
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].checked) {
				paramHash["fieldLabels"] = radios[i].value;
				break;
			}
		}
	}


	// report selection choice
	paramHash["reportsSelectChoice"] = theform.reportsSelectChoice.value;

	if (paramHash["reportsSelectChoice"] == 'map')
	{
		paramHash["showAttributes"] = document.getElementById('showAttributes').checked;
		paramHash["hideWhiteLayer"] = document.getElementById('hideUnselected').checked;
	}
	else{
		paramHash["showAttributes"] = true;
		paramHash["hideWhiteLayer"] = false;
	}
	paramHash["zoomToFields"] = document.getElementById('zoomToFields').checked;
	paramHash["SSURGO"] = document.getElementById('ssurgo').checked;

	//guids and colors
	paramHash["guidColor"] = guidColor;
	paramHash["view_id"] = report_view_id;

	//Color notes
	if (paramHash["reportsSelectChoice"] == 'map')
	{
	paramHash["redNotes"] = theform.redNotes.value;
	paramHash["yellowNotes"] = theform.yellowNotes.value;
	paramHash["blueNotes"] = theform.blueNotes.value;
	paramHash["greenNotes"] = theform.greenNotes.value;
	paramHash["brownNotes"] = theform.brownNotes.value;
	paramHash["purpleNotes"] = theform.purpleNotes.value;
	paramHash["tanNotes"] = theform.tanNotes.value;
	paramHash["lightgreenNotes"] = theform.lightgreenNotes.value;
	paramHash["lightblueNotes"] = theform.lightblueNotes.value;
	paramHash["orangeNotes"] = theform.orangeNotes.value;
	paramHash["greyNotes"] = theform.greyNotes.value;
	}
	paramHash["notes"] = theform.notes.value;
	paramHash["centerPoint"] = VE6map.GetCenter().Longitude + "," + VE6map.GetCenter().Latitude;

	///get bounding box
	var width = VE6map.GetWidth();
	var height = VE6map.GetHeight();
	pixel = new VEPixel(0, height);
	var LL = VE6map.PixelToLatLong(pixel);
	pixel = new VEPixel(width, 0);
	var UR = VE6map.PixelToLatLong(pixel);

	paramHash["minx"] = LL.Longitude;
	paramHash["miny"] = LL.Latitude;
	paramHash["maxx"] = UR.Longitude;
	paramHash["maxy"] = UR.Latitude;

	if (document.getElementById('saveName')) {
		paramHash["saveName"] = document.getElementById('saveName').value;
	}

	paramHash["overViewProfileGUID"] = document.getElementById("overViewProfileGUID").value;

	paramHash["class"] = "reports";
	paramHash["function"] = "quickMap";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	closeAlertBox();
	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openAlertBox("std","Processing Report",html,300,150);
	}

function submitSummary(format)
	{
	//debug = 1;
	var paramHash = new Array();
	guids = "";
	for (var key in overviewGUIDs)
		{
		guids += overviewGUIDs[key] + ",";
		}
	paramHash["guids"] = guids;
	paramHash["view_id"] = report_view_id;
	paramHash["format"] = format;

	///get bounding box
	var width = VE6map.GetWidth();
	var height = VE6map.GetHeight();
	pixel = new VEPixel(0, height);
	var LL = VE6map.PixelToLatLong(pixel);
	pixel = new VEPixel(width, 0);
	var UR = VE6map.PixelToLatLong(pixel);

	paramHash["minx"] = LL.Longitude;
	paramHash["miny"] = LL.Latitude;
	paramHash["maxx"] = UR.Longitude;
	paramHash["maxy"] = UR.Latitude;

	paramHash["class"] = "reports";
	paramHash["function"] = "quickSummary";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openAlertBox("std","Processing Report",html,300,150);
	}

function submitBoundaryMap()
	{
	var theform = document.getElementById('reportform');
	var paramHash = new Array();
	//debug = 1;
	///get bounding box
	var width = VE6map.GetWidth();
	var height = VE6map.GetHeight();
	pixel = new VEPixel(0, height);
	var LL = VE6map.PixelToLatLong(pixel);
	pixel = new VEPixel(width, 0);
	var UR = VE6map.PixelToLatLong(pixel);

	paramHash["minx"] = LL.Longitude;
	paramHash["miny"] = LL.Latitude;
	paramHash["maxx"] = UR.Longitude;
	paramHash["maxy"] = UR.Latitude;

	paramHash["notes"] = theform.notes.value;
	paramHash["guid"] = active_boundary_guid;
	paramHash["view_id"] = report_view_id;
	paramHash["class"] = "reports";
	paramHash["function"] = "quickBoundaryMap";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	closeAlertBox();
	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openAlertBox("std","Processing Report",html,300,150);
	}

function submitSampleIdMap()
	{
	var paramHash = new Array();
	//debug = 1;
	///get bounding box
	var width = VE6map.GetWidth();
	var height = VE6map.GetHeight();
	pixel = new VEPixel(0, height);
	var LL = VE6map.PixelToLatLong(pixel);
	pixel = new VEPixel(width, 0);
	var UR = VE6map.PixelToLatLong(pixel);

	// get current layer type
	paramHash["veLayerName"] = "";
	var mapStyle = VE6map.GetMapStyle();
	if (mapStyle == VEMapStyle.Hybrid) {
		paramHash["veLayerName"] = "hybrid";
	} else if (mapStyle == VEMapStyle.Road) {
		paramHash["veLayerName"] = "roads";
	} else if (mapStyle == VEMapStyle.Aerial) {
		paramHash["veLayerName"] = "aerial";
	}
	paramHash["SSURGO"] = document.getElementById('ssurgo').checked;

	paramHash["minx"] = LL.Longitude;
	paramHash["miny"] = LL.Latitude;
	paramHash["maxx"] = UR.Longitude;
	paramHash["maxy"] = UR.Latitude;
	paramHash["soil_date"] = document.getElementById('soil_date').value;
	paramHash["soil_lab"] = document.getElementById('soil_lab').value;
	paramHash["profile_guid"] = document.getElementById('soil_profile_guid').value;
	paramHash["soil_soil_guid"] = document.getElementById('soil_soil_guid').value;
	paramHash["soil_shape_file"] = document.getElementById('soil_shape_file').value;
	paramHash["class"] = "reports";
	paramHash["function"] = "sampleIdMap";
	makeRequest("/cgi-bin/main.cgi",paramHash);

	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openAlertBox("std","Processing Report",html,300,150);
	}

function submitSampleIdMapWithData()
	{
	var paramHash = new Array();
	//debug = 1;
	///get bounding box
	var width = VE6map.GetWidth();
	var height = VE6map.GetHeight();
	pixel = new VEPixel(0, height);
	var LL = VE6map.PixelToLatLong(pixel);
	pixel = new VEPixel(width, 0);
	var UR = VE6map.PixelToLatLong(pixel);

	// get current layer type
	paramHash["veLayerName"] = "";
	var mapStyle = VE6map.GetMapStyle();
	if (mapStyle == VEMapStyle.Hybrid) {
		paramHash["veLayerName"] = "hybrid";
	} else if (mapStyle == VEMapStyle.Road) {
		paramHash["veLayerName"] = "roads";
	} else if (mapStyle == VEMapStyle.Aerial) {
		paramHash["veLayerName"] = "aerial";
	}
	paramHash["SSURGO"] = document.getElementById('ssurgo').checked;

	paramHash["minx"] = LL.Longitude;
	paramHash["miny"] = LL.Latitude;
	paramHash["maxx"] = UR.Longitude;
	paramHash["maxy"] = UR.Latitude;
	paramHash["soil_date"] = document.getElementById('soil_date').value;
	paramHash["soil_lab"] = document.getElementById('soil_lab').value;
	paramHash["profile_guid"] = document.getElementById('soil_profile_guid').value;
	paramHash["soil_soil_guid"] = document.getElementById('soil_soil_guid').value;
	paramHash["soil_shape_file"] = document.getElementById('soil_shape_file').value;
	paramHash["class"] = "reports";
	paramHash["function"] = "sampleIdMapWithData";
	makeRequest("/cgi-bin/main.cgi",paramHash);

	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openAlertBox("std","Processing Report",html,300,150);
	}


var admin_profile_list = new Array();
function submitBatchExport()
	{
	var lastGUID = "";
	var lastValue = "";
	for (var i=0; i < admin_profile_list.length; ++i)
		{
		if (document.getElementById("admin_" + admin_profile_list[i]).value != "-99")
			{
			lastGUID = document.getElementById("admin_" + admin_profile_list[i]).value;
			lastValue = admin_profile_list[i];
			}
		}
	//debug = 1;
	var paramHash = new Array();
	paramHash["guid"] = lastGUID;
	paramHash["value"] = lastValue;
	if (document.getElementById("boundary_export").checked == true) { paramHash["boundary_export"] = 1; }
	else { paramHash["boundary_export"] = 0; }
	paramHash["export_format"] = document.getElementById("export_format").value;
	paramHash["class"] = "tools";
	paramHash["function"] = "batchExport";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	document.getElementById("messgage_box").innerHTML = "Processing Export...";
	}

function checkBoundaries()
	{
	var lastGUID = "";
	var lastValue = "";
	for (var i=0; i < admin_profile_list.length; ++i)
		{
		if (document.getElementById("admin_" + admin_profile_list[i]).value != "-99")
			{
			lastGUID = document.getElementById("admin_" + admin_profile_list[i]).value;
			lastValue = admin_profile_list[i];
			}
		}
	//debug = 1;
	if (lastValue == "var" || lastValue == "business_unit")
		{
		alert("Please Select a Location");
		return false;
		}
	var paramHash = new Array();
	paramHash["guid"] = lastGUID;
	paramHash["level"] = lastValue;
	paramHash["div"] = "field_list";

	if (document.getElementById("invalid").checked == true) { paramHash["invalid"] = 1; }
	else { paramHash["invalid"] = 0; }

	paramHash["function"] = "checkBoundaries";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	document.getElementById("messgage_box").innerHTML = "Processing Request...";
	}

function printCheckBoundaries()
	{
	var lastGUID = "";
	var lastValue = "";
	for (var i=0; i < admin_profile_list.length; ++i)
		{
		if (document.getElementById("admin_" + admin_profile_list[i]).value != "-99")
			{
			lastGUID = document.getElementById("admin_" + admin_profile_list[i]).value;
			lastValue = admin_profile_list[i];
			}
		}
	//debug = 1;

	var paramHash = new Array();
	paramHash["guid"] = lastGUID;
	paramHash["level"] = lastValue;
	paramHash["div"] = "field_list";

	if (document.getElementById("invalid").checked == true) { paramHash["invalid"] = 1; }
	else { paramHash["invalid"] = 0; }

	paramHash["class"] = "reports";
	paramHash["function"] = "boundaryCheckSummary";
	makeRequest("/cgi-bin/main.cgi",paramHash);

	document.getElementById("messgage_box").innerHTML = "Processing Request...";
	}



function thisSiteLog(thisAction,jscode)
	{
		var paramHash = new Array();
		//paramHash["thisUser"] = thisUser;
		paramHash["thisAction"] = thisAction;
		paramHash["jscode"] = jscode;
		paramHash["function"] = "thisSiteLog";
		makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function thisSiteLogReport(guid)
	{
	var paramHash = new Array();
	paramHash["class"] = "reports";
	paramHash["guid"] = guid;
	paramHash["function"] = "thisSiteLogReport";

	makeRequest("/cgi-bin/main.cgi",paramHash);
	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openSubAlertBox(html,300,150);
	}

function logout()
	{
		window.location = "/index.html"
	}

function printUserLog(userGUID, theDIV)
	{
	var paramHash = new Array();
	paramHash["guid"] = userGUID;
	paramHash["div"] = theDIV;

	paramHash["class"] = "reports";
	paramHash["function"] = "userLogReport";
	makeRequest("/cgi-bin/main.cgi",paramHash);


	document.getElementById("messgage_box").innerHTML = "Processing Request...";
	}

function loadErrorLog(theError,extraCC)
	{
	theError = escape(theError)
	//alert(theError);
	var paramHash = new Array();
	paramHash["function"] = "loadErrorLog";
	paramHash["theError"] = theError;
	if (extraCC) { paramHash["extraCC"] = extraCC; }
	paramHash["div"] = "theErrorDIV";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function saveErrorInfo(theDiv, theUser, theError, extraCC)
	{
	theUserInfo = document.getElementById("errorText").value;
	//xxx = document.getElementById("errorText").value
	//alert(theDiv);
	//alert(theUser);
	//alert(theError);
	//alert(theUserInfo);
	//alert(currentTab);
	//alert(BrowserDetect.OS.toString());

	if (theUserInfo == ""){
		theUserInfo = 'No Response';
	}else{
		theUserInfoLength = theUserInfo.length;
		theUserInfo = theUserInfo;
		for (i=0; i<theUserInfoLength; i++){
			theUserInfo = theUserInfo.replace("\'", "\"");
		}
	}


	var paramHash = new Array();
	paramHash["function"] = "saveErrorInfo";
	paramHash["theDiv"] = theDiv;
	paramHash["theUser"] = theUser;
	paramHash["theError"] = theError;
	paramHash["theUserInfo"] = theUserInfo;
	paramHash["theTab"] = currentTab;
	paramHash["theBrowser"] = BrowserDetect.browser.toString();
	paramHash["theBrowserVersion"] = BrowserDetect.version.toString();
	paramHash["theOS"] = BrowserDetect.OS.toString();
	paramHash["extraCC"] = extraCC;
	makeRequest("/cgi-bin/main.cgi",paramHash);

	closeAlertBox();
	}


function thePrevious(x)
	{
	x = parseInt(x);
	x = x - 10

	if (x <= 0)
	{
		x = 0
	}

	window.location="http://aj-dev:28080/cgi-bin/errorView.py?theOffset=" + x
	}

function theNext(x)
	{
	x = parseInt(x);
	x = x + 10;
	window.location="http://aj-dev:28080/cgi-bin/errorView.py?theOffset=" + x
	}

function userLogNext(theUser,theOffset,theDiv)
	{
	//alert("next " + theUser);
	theOffset = parseInt(theOffset);
	theOffset = theOffset + 100;

	//alert(theDiv);
	var paramHash = new Array();
	paramHash["function"] = "loadUserLogAdmin";
	paramHash["div"] = theDiv;
	paramHash["theUser"] = theUser;
	paramHash["theOffset"] = theOffset;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function userLogPrev(theUser,theOffset,theDiv)
	{
	//alert("prev " + theUser);
	theOffset = parseInt(theOffset);
	theOffset = theOffset - 100;

	//alert(theDiv);
	var paramHash = new Array();
	paramHash["function"] = "loadUserLogAdmin";
	paramHash["div"] = theDiv;
	paramHash["theUser"] = theUser;
	paramHash["theOffset"] = theOffset;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function printUserAdminInfo(user_guid, var_guid)
	{
	var paramHash = new Array();
	paramHash["class"] = "reports";
	paramHash["function"] = "printUserAdminInfo";
	paramHash["user_guid"] = user_guid;
	paramHash["var_guid"] = var_guid;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	//closeAlertBox();
	var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
	openSubAlertBox(html,300,150);
	}

function submitAsapBatchUpload()
	{
	if (document.formAsapUpload.asapFile.value == "")
		{
		alert("Please select a file to upload");
		return;
		}

	// verify extension
	var ext = document.formAsapUpload.asapFile.value;
	ext = ext.substr(ext.lastIndexOf(".") + 1).toLowerCase();
	if (ext != "rbin" && ext != "zip" && ext != "log")
		{
		alert("Only .RBIN, .LOG, and .ZIP files are accepted.");
		return;
		}
	document.formAsapUpload.submit();
	}

function asapProductFormClick()
	{
	var formObj = document.formAsapUpload.asapProductForm;
	var form = "";
	for (var i = 0; i < formObj.length; i++)
		{
		if (formObj[i].checked) { form = formObj[i].value; }
		}

	var unitObj = document.formAsapUpload.asapProductUnit;
	unitObj.selectedIndex = -1;
	unitObj.length = 0;
	if (form == "dry")
		{
		unitObj.options[unitObj.options.length] = new Option("lbs/ac","lbs/ac");
		unitObj.options[unitObj.options.length] = new Option("tons/ac","tons/ac");
		}
	else if (form == "liquid")
		{
		unitObj.options[unitObj.options.length] = new Option("gals/ac","gals/ac");
		}
	}

///Slider Stuff////////////////////////////////////////
//---------------------------------+
//  CARPE  S l i d e r        1.3  |
//  2005 - 12 - 10                 |
//  By Tom Hermansson Snickars     |
//  Copyright CARPE Design         |
//  http://carpe.ambiprospect.com/ |
//---------------------------------+

// carpeGetElementByID: Cross-browser version of "document.getElementById()"
function carpeGetElementById(element)
{
	if (document.getElementById) element = document.getElementById(element);
	else if (document.all) element = document.all[element];
	else element = null;
	return element;
}
// carpeLeft: Cross-browser version of "element.style.left"
function carpeLeft(elmnt, pos)
{
	if (!(elmnt = carpeGetElementById(elmnt))) return 0;
	if (elmnt.style && (typeof(elmnt.style.left) == 'string')) {
		if (typeof(pos) == 'number') elmnt.style.left = pos + 'px';
		else {
			pos = parseInt(elmnt.style.left);
			if (isNaN(pos)) pos = 0;
		}
	}
	else if (elmnt.style && elmnt.style.pixelLeft) {
		if (typeof(pos) == 'number') elmnt.style.pixelLeft = pos;
		else pos = elmnt.style.pixelLeft;
	}
	return pos;
}
// carpeTop: Cross-browser version of "element.style.top"
function carpeTop(elmnt, pos)
{
	if (!(elmnt = carpeGetElementById(elmnt))) return 0;
	if (elmnt.style && (typeof(elmnt.style.top) == 'string')) {
		if (typeof(pos) == 'number') elmnt.style.top = pos + 'px';
		else {
			pos = parseInt(elmnt.style.top);
			if (isNaN(pos)) pos = 0;
		}
	}
	else if (elmnt.style && elmnt.style.pixelTop) {
		if (typeof(pos) == 'number') elmnt.style.pixelTop = pos;
		else pos = elmnt.style.pixelTop;
	}
	return pos;
}
// moveSlider: Handles slider and display while dragging
function moveSlider(evnt)
{
	var evnt = (!evnt) ? window.event : evnt; // The mousemove event
	if (mouseover) { // Only if slider is dragged
		x = pxLeft + evnt.screenX - xCoord // Horizontal mouse position relative to allowed slider positions
		y = pxTop + evnt.screenY - yCoord // Horizontal mouse position relative to allowed slider positions
		if (x > xMax) x = xMax // Limit horizontal movement
		if (x < 0) x = 0 // Limit horizontal movement
		if (y > yMax) y = yMax // Limit vertical movement
		if (y < 0) y = 0 // Limit vertical movement
		carpeLeft(sliderObj.id, x)  // move slider to new horizontal position
		carpeTop(sliderObj.id, y) // move slider to new vertical position
		sliderVal = x + y // pixel value of slider regardless of orientation
		sliderPos = (sliderObj.pxLen / sliderObj.valCount) * Math.round(sliderObj.valCount * sliderVal / sliderObj.pxLen)
		v = Math.round((sliderPos * sliderObj.scale + sliderObj.fromVal) * // calculate display value
			Math.pow(10, displayObj.dec)) / Math.pow(10, displayObj.dec)
		displayObj.value = v // put the new value in the slider display element
		return false
	}
	return
}
// moveSlider: Handles the start of a slider move.
function slide(evnt, orientation, length, from, to, count, decimals, display)
{
	if (!evnt) evnt = window.event;
	sliderObj = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated slider element.
	sliderObj.pxLen = length // The allowed slider movement in pixels.
	sliderObj.valCount = count ? count - 1 : length // Allowed number of values in the interval.
	displayObj = carpeGetElementById(display) // Get the associated display element.
	displayObj.dec = decimals // Number of decimals to be displayed.
	sliderObj.scale = (to - from) / length // Slider-display scale [value-change per pixel of movement].
	if (orientation == 'horizontal') { // Set limits for horizontal sliders.
		sliderObj.fromVal = from
		xMax = length
		yMax = 0
	}
	if (orientation == 'vertical') { // Set limits and scale for vertical sliders.
		sliderObj.fromVal = to
		xMax = 0
		yMax = length
		sliderObj.scale = -sliderObj.scale // Invert scale for vertical sliders. "Higher is more."
	}
	pxLeft = carpeLeft(sliderObj.id) // Sliders horizontal position at start of slide.
	pxTop  = carpeTop(sliderObj.id) // Sliders vertical position at start of slide.
	xCoord = evnt.screenX // Horizontal mouse position at start of slide.
	yCoord = evnt.screenY // Vertical mouse position at start of slide.
	mouseover = true
	document.onmousemove = moveSlider // Start the action if the mouse is dragged.
	document.onmouseup = sliderMouseUp // Stop sliding.
}
// sliderMouseup: Handles the mouseup event after moving a slider.
// Snaps the slider position to allowed/displayed value.
function sliderMouseUp()
{
	mouseover = false // Stop the sliding.
	v = (displayObj.value) ? displayObj.value : 0 // Find last display value.
	var trans = v/100;
	SetTileLayerOpacity(zonetileid,trans);
	pos = (v - sliderObj.fromVal)/(sliderObj.scale) // Calculate slider position (regardless of orientation).
	if (yMax == 0) carpeLeft(sliderObj.id, pos) // Snap horizontal slider to corresponding display position.
	if (xMax == 0) carpeTop(sliderObj.id, pos) // Snap vertical slider to corresponding display position.
	if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co).
		document.removeEventListener('mousemove', moveSlider)
		document.removeEventListener('mouseup', sliderMouseUp)
	}
	else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co).
		document.detachEvent('onmousemove', moveSlider)
		document.detachEvent('onmouseup', sliderMouseUp)
	}
}

function need_eula(user_guid,level,new_guid,eula_id,x_eula_id,agreement)
	{
	//alert(user_guid + " " + level + " " + new_guid + " " + eula_id + " " + agreement);
	html = "<center><div style='margin:10px;width:480px;'>"
	html += "<table style='width:480px;'>"
	html += "<tr><td colspan='2'><textarea id='eula_agreement' rows='15' cols='55' READONLY>" + agreement + "</textarea></td></tr>"
	html += "<tr><td align='left'><a href='#' style='color:#800080;' onclick=\"var consoleRef=window.open('/docs/eula/website_terms_of_use_A1441714.doc','EULA', 'width=400,height=150,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0');consoleRef.document.close();\">Download</a></td><td style='text-align:right;'><a href='#' onclick=\"agree_to_eula('" + user_guid + "','" + level + "','" + new_guid + "','" + eula_id + "','" + x_eula_id + "','false','false','false');\">Agree</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' onclick='closeAlertBox();'>Disagree</a></td></tr>"
	html += "</table>"
	html += "</div></center>"

	openAlertBox("prompt","End User Lisence Agreement",html,500,300);
	}

function agree_to_eula(user_guid,level,new_guid,eula_id,x_eula_id,noajax,uName,pWord)
	{
	//alert(user_guid + " " + level + " " + new_guid + " " + eula_id);
	var paramHash = new Array();
	paramHash["user_guid"] = user_guid;
	paramHash["level"] = level;
	paramHash["new_guid"] = new_guid;
	paramHash["eula_id"] = eula_id;
	paramHash["x_eula_id"] = x_eula_id;
	paramHash["noajax"] = noajax;

	if (uName != "false")
		{
		paramHash["uName"] = uName;
		paramHash["pWord"] = pWord;
		}
	//paramHash["class"] = "reports";
	paramHash["function"] = "agree_to_eula";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	//closeAlertBox();

	if (uName == "false")
		{
		var html = "<center><br/><br/><img src='/images/loading.gif'><br/><br/>Processing...";
		openSubAlertBox(html,300,130);
		}
	}

// Preferences - Default Tab
function preferencesDefaultTab_select_change()
	{
	var theSelect = document.getElementById("preferencesDefaultTab_select").value;

	var paramHash = new Array();
	paramHash["default_tab"] = theSelect;
	//paramHash["class"] = "fertility";
	paramHash["function"] = "preferencesDefaultTab_select";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}
// END Preferences - Default Tab

//// Main Workorders
function openWorkorderChild(event,parent_guid,workorder_level)
	{
	if (!event) { event = window.event; }
	if (BrowserDetect.browser == "Explorer") {  window.event.cancelBubble = true;}
	else { event.stopPropagation(); }

	//alert(parent_guid);

	if (!document.getElementById(parent_guid + "_workorder_li").getElementsByTagName('ul')[0])
		{
		document.getElementById(parent_guid + "_workorder_li").className = "open_workorder";

		parentOject = document.getElementById(parent_guid + "_workorder_li");
		var newUL = document.createElement('span');
		newUL.id='loading';
		newUL.innerHTML = "&nbsp;&nbsp;Loading....";
		parentOject.appendChild(newUL);

		//alert(workorder_level);
		//alert(parent_guid + " " + parent_type + " " + parent_view_id);
		var paramHash = new Array();
		paramHash["parent_guid"] = parent_guid;
		paramHash["workorder_level"] = workorder_level;
		//paramHash["parent_type"] = parent_type;
		//paramHash["parent_view_id"] = parent_view_id;
		paramHash["class"] = "workorder";
		paramHash["function"] = "openWorkorderChild";
		makeRequest("/cgi-bin/main.cgi",paramHash);
		}
	else
		{
		if (document.getElementById(parent_guid + "_workorder_li").className == "open_workorder" )
			{
			document.getElementById(parent_guid + "_workorder_li").removeChild(document.getElementById(parent_guid + "_workorder_li").getElementsByTagName('ul')[0]);
			document.getElementById(parent_guid + "_workorder_li").className = "close_workorder";
			}
		/*else
			{
			document.getElementById(parent_guid + "_" + letter_id).getElementsByTagName('ul')[0].style.display='block';
			if (type == "saved_rx") { document.getElementById(parent_guid + "_" + letter_id).className = "rx_file_open"; }
			else { document.getElementById(parent_guid + "_" + letter_id).className = "open";  }
			}*/
		}
	}

function addWorkorderChild(parent_guid,HTML)
	{
	//alert(parent_guid);
	//child_pg = 'test1';
	//alert(child_pg);
	//document.getElementById(parent_guid + "_workorder_li").className = "x_workorder";

	parentOject = document.getElementById(parent_guid + "_workorder_li");
	if (document.getElementById('loading'))
		{ parentOject.removeChild(document.getElementById('loading')); }
	var newUL = document.createElement('ul');
	//newUL.id = parent_guid + "_ul";
	//paramHash["true_parent_guid"] = parent_guid;
	newUL.innerHTML = HTML;
	parentOject.appendChild(newUL);
	return false;
	}

//// END Main Workorders


// use to trigger an event programmatically.
// replaces use of object.click(), IE only, and object.onclick(), all others
function fireEvent (element,event) {
	if (document.createEvent) {
		// dispatch for firefox + others
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent(event, true, true ); // event type,bubbling,cancelable
		return !element.dispatchEvent(evt);
	} else {
		// dispatch for IE
		var evt = document.createEventObject();
		return element.fireEvent('on'+event,evt)
	}
}
