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

var OEM = 0;

var operationsMessageCheckID = 0;

var loadUserLogAdmin_filter = "";
var loadUserLogAdmin_sort = "";

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;
	}

function resetTree(var_guid)
	{
	var paramHash = new Array();
//	profileRequest = 1;
	paramHash["parent_guid"] = var_guid;
	paramHash["type"] = "var";
	paramHash["view_id"] = "1";
	paramHash["function"] = "openChild";
	makeRequest("/cgi-bin/profile.cgi",paramHash);
	}

///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;

		if (currentTab == "view")
			{
			var mw2 =  width - 290 - 215;
			}
		else
			{
			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";

			if (currentTab == "view")
				{
				var mw =  width - 252;
				}
			else
				{
				var mw =  width - 237;
				}

			document.getElementById('tools').style.left = mw + "px";

			if (currentTab == "view")
				{
				document.getElementById('tools').style.width = "215px";
				}
			else
				{
				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();

	if (fullScreenMapCheck == 0)
		{

		if (width < 1080)
			{
			if (document.getElementById('support_info_DIV'))
				{
				document.getElementById('support_info_DIV').style.display = "none";
				}
			if (document.getElementById('support_info_NEWDIV'))
				{
				document.getElementById('support_info_NEWDIV').style.display = "inline";
				document.getElementById('support_info_NEWDIV').style.color = "#000000";
				}

//			info = document.getElementById('support_info_DIV');
//			infoleft = document.getElementById('support_info_DIV').offsetLeft;
//			//infotop = document.getElementById('support_info_DIV').offsetTop;
//
//			info.style.left = infoleft;
//			info.style.position = "relative";

			if (document.getElementById('weather_DIV'))
				{
				document.getElementById('weather_DIV').style.display = "none";
				}
			if (document.getElementById('weather_info_DIV'))
				{
				document.getElementById('weather_info_DIV').style.display = "none";
				}
			}
		else
			{
			if (document.getElementById('support_info_DIV'))
				{
				document.getElementById('support_info_DIV').style.display = "inline";
				}
			if (document.getElementById('support_info_NEWDIV'))
				{
				document.getElementById('support_info_NEWDIV').style.display = "none";
				document.getElementById('support_info_NEWDIV').style.color = "#D6D9E6";
				}

//			info = document.getElementById('support_info_NEWDIV');
//			dWidth = info.style.width;
//			pWidth = document.documentElement. clientWidth;
//
//			info.style.left = pWidth - 720// - dWidth.replace("px","");
//			info.style.position = "absolute";

			if (document.getElementById('weather_DIV'))
				{
				document.getElementById('weather_DIV').style.display = "inline";
				}
			if (document.getElementById('weather_info_DIV'))
				{
				document.getElementById('weather_info_DIV').style.display = "inline";
				}
			}

		if (width < 780)
			{
			if (document.getElementById('support_info_NEWDIV'))
				{
				document.getElementById('support_info_NEWDIV').style.display = "none";
				}
			}

		if (document.getElementById('clearLayer_DIV'))
			{
			clearLayer_FUNC();
			}
		}
	}

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";
		}
	}

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

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);

		if (document.getElementById('support_info_DIV'))
			{
			document.getElementById('support_info_DIV').style.display = "none";
			}
		if (document.getElementById('weather_info_DIV'))
			{
			document.getElementById('weather_info_DIV').style.display = "none";
			}
		if (document.getElementById('weather_DIV'))
			{
			document.getElementById('weather_DIV').style.display = "none";
			}
		if (document.getElementById('clearLayer_DIV'))
			{
			//clearLayer_FUNC();
			document.getElementById('clearLayer_DIV').style.display = "none";
			}
		}
	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();

		if (document.getElementById('support_info_DIV'))
			{
			document.getElementById('support_info_DIV').style.display = "inline";
			}
		if (document.getElementById('weather_info_DIV'))
			{
			document.getElementById('weather_info_DIV').style.display = "inline";
			}
		if (document.getElementById('weather_DIV'))
			{
			document.getElementById('weather_DIV').style.display = "inline";
			}
		if (document.getElementById('clearLayer_DIV'))
			{
			clearLayer_FUNC();
			//document.getElementById('clearLayer_DIV').style.display = "inline";
			}
		}
	}

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)
	{
	currentTab = 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';
		}
	if (document.getElementById('floathisimg') != null)
		{
		document.body.removeChild(document.getElementById('floathisimg'));
		}
	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_multi_variety_ARRAY.length=0;
			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';
			if (fetilitySystem == 'aj')
				{
				paramHash["class"] = "fertilityMgnt";
				paramHash["function"] = "startFertilityProfile";
				}
			else
				{
				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);
			}
		}

	currentTab = tab;

	//Clean out the old data
	if (tab != "event")
		{
		document.getElementById('topTreeEntry').innerHTML = "";
		}

	///////Set search box stuff//////
	setSize();
	}

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

	loadingAnimation_Count = loadingAnimation_Count + 1;

	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 + "=" + encodeURIComponent(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'; loadingAnimation_Count = loadingAnimation_Count - 1; }
			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'; loadingAnimation_Count = loadingAnimation_Count - 1; }
			//alert('There was a problem with the request.');
			}
		}

	if (loadingAnimation_Count == 0)
		{
		document.getElementById("loading_animation").style.display='none';
		}
	else
		{
		if (document.getElementById("loading_animation"))
			{
			document.getElementById("loading_animation").style.display='inline';
			}
		}
	}

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();

openAlertBox_Resize_Box_WidthHold = 0;
openAlertBox_Resize_Box_HeightHold = 0;
openAlertBox_Resize_ViewCloseBox = 0

function openAlertBox(boxType,title,innerhtml,boxWidth,boxHeight,viewCloseBox, onCloseScript, gggg)
	{
	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";
		closeAlertBox2();
		}
	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; padding: 0px; margin: 0px;' id='OAB_dataMenu_table'>";
	html += "<tr width='100%'>";
	middle = boxWidth - 28;
	html += "	<td style='width:14px;height:14px;background-image: url(/images/" + corner + "_left.gif)' nowrap>&nbsp;</td>";
	html += "	<td style='background-color: " + color +";height:25px;color:white;font-size: 10pt;width:" + middle + "px;' align='center' id='OAB_dataMenu_middle' nowrap><span id='dialogBoxTitle'>" + title + "</span></td>";
	html += "	<td valign='bottom' style='width:14px;height:14px;background-image: url(/images/" + corner + "_right.gif)' nowrap><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='OAB_mid' style='height:" + internalHeight + "px;width:" + boxWidth + "px;' valign='top'>";
	html += innerhtml;
	html += "</td></tr>";
	html += "<tr width='100%'>";
	html += "<td style='width:14px;height:7px;font-size: 1pt;' nowrap><img src='/images/left_b.gif'></td>";
	html += "<td style='background-color: #eeeeee;height:7px;font-size: 1pt;width:" + middle + "px;' nowrap></td>";
	html += "<td style='width:14px;height:7px;font-size: 1pt;' nowrap><img src='/images/right_b.gif'></td>";
	html += "</tr>";
	html += "</table>";
	if (viewCloseBox)
		{
		openAlertBox_Resize_ViewCloseBox = 1
		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();" + unescape(onCloseScript) + ";\" style='position:absolute;left:" + closeBox + "px;top:" + closeBoxTop + "px;font-size: 8pt;color:white;cursor: pointer; float: right;' id='OAB_dataMenu_close'>Close/Cancel</span>";
		}
	dataMenu.innerHTML = html;
	document.body.appendChild(dataMenu);

	openAlertBox_Resize_Box_WidthHold = boxWidth;
	openAlertBox_Resize_Box_HeightHold = boxHeight;
	}

openAlertBox_Resize_toggle = 0
openAlertBox_Resize_toggle_text = ""
function openAlertBox_Resize(buttonID, toggleTextOrg, toggleTextTo, widthPercent, heightPercent)
	{
	if (toggleTextTo == "")
		{
		toggleTextTo = "Toggle"
		}
	
	if (toggleTextOrg == "")
		{
		toggleTextOrg = "Toggle"
		}

	var windowWidth = document.documentElement.clientWidth; //-50;
	var windowHeight = document.documentElement.clientHeight; //-100;

	toWidth = ((parseInt(widthPercent) / 100) * parseInt(windowWidth));
	toHeight = ((parseInt(heightPercent) / 100) * parseInt(windowHeight));

	var top = 0;
	var left = 0;

	if (openAlertBox_Resize_toggle == 0)
		{
		document.getElementById('OAB_dataMenu_table').style.width		= toWidth + "px";
		document.getElementById('OAB_dataMenu_table').style.height		= toHeight + "px";
		document.getElementById('dataMenu').style.width								= toWidth + "px";
		document.getElementById('dataMenu').style.height							= toHeight + "px";

		document.getElementById('OAB_dataMenu_middle').style.width	= (parseInt(toWidth) - 28) + "px";
		document.getElementById('OAB_mid').style.width							= toWidth + "px";
		document.getElementById('OAB_mid').style.height							= (toHeight - 33) + "px";

		if (openAlertBox_Resize_ViewCloseBox == 1)
			{
			document.getElementById('OAB_dataMenu_close').style.top = 9 + "px";
			document.getElementById('OAB_dataMenu_close').style.left = (toWidth - 75) + "px";
			}

		if (buttonID != "")
			{
			document.getElementById(buttonID).innerText = toggleTextTo;
			}
		openAlertBox_Resize_toggle = 1
		}
	else
		{
		toWidth = openAlertBox_Resize_Box_WidthHold;
		toHeight = openAlertBox_Resize_Box_HeightHold;

		document.getElementById('OAB_dataMenu_table').style.width		= toWidth + "px";
		document.getElementById('OAB_dataMenu_table').style.height		= toHeight + "px";
		document.getElementById('dataMenu').style.width								= toWidth + "px";
		document.getElementById('dataMenu').style.height							= toHeight + "px";

		document.getElementById('OAB_dataMenu_middle').style.width	= (parseInt(toWidth) - 28) + "px";
		document.getElementById('OAB_mid').style.width							= toWidth + "px";
		document.getElementById('OAB_mid').style.height							= (toHeight - 33) + "px";

		if (openAlertBox_Resize_ViewCloseBox == 1)
			{
			document.getElementById('OAB_dataMenu_close').style.top = 9 + "px";
			document.getElementById('OAB_dataMenu_close').style.left = (toWidth - 75) + "px";
			}

		if (buttonID != "")
			{
			document.getElementById(buttonID).innerText = toggleTextOrg;
			}
		openAlertBox_Resize_toggle = 0
		}

	top = parseInt(windowHeight)/2 - parseInt(toHeight)/2;
	left = parseInt(windowWidth)/2 - parseInt(toWidth)/2;

	document.getElementById('dataMenu').style.top = top + "px";
	document.getElementById('dataMenu').style.left = left + "px";
	}

//function openAlertBox_Resize_test()
//	{
//	testHTML = "<button onclick=\"openAlertBox_Resize(this.id, 'Enlarge Box', 'Shorten Box', 80, 80);\" id='openAlertBox_Resize_button' style='cursor: pointer;'>Enlarge Box</button>"
//	openAlertBox('std','Edit Sample Values',testHTML,750,300,1);
//	}

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)
		{
		}

	openAlertBox_Resize_Box_WidthHold = 0;
	openAlertBox_Resize_Box_HeightHold = 0;
	openAlertBox_Resize_ViewCloseBox = 0;
	}

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 = "100001"
	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'));
		}
	}


// Open pop-up window
function openPopupBox(html,windowName,URL,width,height,scrollbars,resizable){
	windowName = typeof(windowName) != 'undefined' ? windowName : 'myreport';
	URL = typeof(URL) != 'undefined' ? URL : '';
	width = typeof(width) != 'undefined' ? width : 400;
	height = typeof(height) != 'undefined' ? height : 150;
	scrollbars = typeof(scrollbars) != 'undefined' ? scrollbars : 0;
	resizable = typeof(resizable) != 'undefined' ? resizable : 0;
	var popupWindow = '';
	try{
		attributes = 'width=' + width + ',height=' + height + ',menubar=0,toolbar=0,status=0,scrollbars=' + scrollbars + ',resizable=' + resizable;
		popupWindow=window.open(URL,'_blank', attributes);
		if(!popupWindow){
			alert("This site utilizes pop-up windows.\nPlease disable your browser's pop-up blocker, and try again");
			return;
		}
		if(URL == ''){
			var doc = popupWindow.document.open();
			doc.writeln(html);
			doc.close();
		}

		try{
			popupWindow.focus();
		}
		catch(err){
			alert('Could not open popup window. Please disable pop-ip blocker, refresh browser, and try again');
		}
	}
	catch (err){
		alert('Could not open popup window. Please disable pop-ip blocker, refresh browser, and try again');
	}
}

///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 pref_REFRESH(pref_hold_ID, infoTest)
	{
	var paramHash = new Array();
	paramHash["infoTest"] = infoTest;
	paramHash["pref_hold_ID"] = pref_hold_ID;
	paramHash["function"] = "loadPrefs";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function pref_loadTestPackage(lab_guid)
	{
//	var theform = document.getElementById('prefsform2');
//	theform.preferencesLabAccountNum.value='';

	var ddl = document.getElementById('preferencesLabTestPackagesCheckingDefault_select');
	ddl.length = 0
	if (lab_guid != "")
		{
		var theOption = new Option;
		theOption.text = " - - - ";
		theOption.value = '-99';
		ddl.options[0] = theOption;

		for(i = 1; i <= labTestPackages[lab_guid].length; i++) 
			{
			var theOption = new Option;
			x = i-1
			theOption.text = labTestPackages[lab_guid][x];
			theOption.value = labTestPackages[lab_guid][x];
			ddl.options[i] = theOption;
			}
		}
	}

function savePrefs(pref_hold_ID)
	{
	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["pref_hold_ID"] = pref_hold_ID;
	/*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 savePrefs2(pref_hold_ID)
	{
	var theform = document.getElementById('prefsform2');

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

	for (var i=0; i < theform.preferencesLabTestPackagesCheckingDefault_select.length; i++)
		{
		if (theform.preferencesLabTestPackagesCheckingDefault_select[i].selected == true)
			{
			testPackageValue = theform.preferencesLabTestPackagesCheckingDefault_select[i].value;
			if (testPackageValue == "-99")
				{
				testPackage = "";
				}
			else
				{
				testPackage = theform.preferencesLabTestPackagesCheckingDefault_select[i].text;
				}
			}
		}

	accountNum = theform.preferencesLabAccountNum.value;

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

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

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

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

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

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

	yieldGoal1 = theform.preferencesLabYieldGoal1.value;
	yieldGoal2 = theform.preferencesLabYieldGoal2.value;
	yieldGoal3 = theform.preferencesLabYieldGoal3.value;

	target_ph = theform.preferencesLabTargetPh.value;

//	if (isNaN(yieldGoal1))
//		{
//		alert("Number Needed for Yield Goal!");
//		theform.preferencesLabYieldGoal1.style.backgroundColor = "orange";
//		return false;
//		}
//
//	if (isNaN(yieldGoal2))
//		{
//		alert("Number Needed for Yield Goal!");
//		theform.preferencesLabYieldGoal2.style.backgroundColor = "orange";
//		return false;
//		}
//
//	if (isNaN(yieldGoal3))
//		{
//		alert("Number Needed for Yield Goal!");
//		theform.preferencesLabYieldGoal3.style.backgroundColor = "orange";
//		return false;
//		}
//
//	if (isNaN(target_ph))
//		{
//		alert("Number Needed for Target pH!");
//		theform.preferencesLabTargetPh.style.backgroundColor = "orange";
//		return false;
//		}

	var paramHash = new Array();
	paramHash["pref_hold_ID"] = pref_hold_ID;
	paramHash["default_lab"] = default_lab;
	paramHash["testPackage"] = testPackage;
	paramHash["accountNum"] = accountNum;
	paramHash["crop1"] = crop1;
	paramHash["crop2"] = crop2;
	paramHash["crop3"] = crop3;
	paramHash["yieldGoal1"] = yieldGoal1;
	paramHash["yieldGoal2"] = yieldGoal2;
	paramHash["yieldGoal3"] = yieldGoal3;
	paramHash["target_ph"] = target_ph;
	paramHash["function"] = "savePrefs";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

pref_hold_ID = ""
function pref_mouseover(td)
	{
	gtd = document.getElementById(td);
	bgc = gtd.style.backgroundColor;

	if (td != pref_hold_ID)
		{
		if (bgc != "green")
			{
			document.getElementById(td).style.backgroundColor='#444444';	
			}
		}
	}

function pref_mouseout(td)
	{
	gtd = document.getElementById(td);
	bgc = gtd.style.backgroundColor;

	if (td != pref_hold_ID)
		{
		if (bgc != "green")
			{
			document.getElementById(td).style.backgroundColor='#555555';
			}
		}
	}

function pref_TD_SELECTION(td, div)
	{
	if (pref_hold_ID != "")
		{
		document.getElementById(pref_hold_ID).style.backgroundColor="#555555";
		}

	pref_hold_ID = td;

	document.getElementById(td).style.backgroundColor="#444444";
	document.getElementById(td).style.color="yellow";
	document.getElementById(td).innerHTML="Loading...";
	
	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["pref_hold_ID"] = pref_hold_ID;
	paramHash["function"] = "loadPrefs";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

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

// Need to check for restrictions on options in Tools menu
function loadTools(){
	var paramHash = new Array();
	paramHash["class"] = "tools";
	paramHash["function"] = "determineToolsRestrictions";
	makeRequest("/cgi-bin/main.cgi",paramHash);
}

function loadToolsOptions(newEquationAccess){
	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'>&nbsp;Batch Export</option>" +
		"<option value='profileMover'>&nbsp;Profile Mover</option>" +
		"<option value='asappliedBatchUpload'>&nbsp;As-Applied Batch Upload </option>"+
		"<option value='mobileSyncSetup'>&nbsp;Mobile Sync Setup </option>";

	// Custom Equation Manager
	if ( (newEquationAccess == 'true') && (fetilitySystem == 'aj') ){
		html += "<option value='equaMgnt'>&nbsp;Equation Manager - New</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)
		{
		html += "<option value='locationPref'>&nbsp;Location Pref</option>";
//		html += "<option value='unAssociatedLoggedData'>&nbsp;Unassociated Data</option>";
		html += "<option value='productManagement'>&nbsp;Product Management</option>";
		html += "<option value='unitPreference'>&nbsp;Unit Preference </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 (userlevel == 3 || userlevel == 1)
		{
		html += "<option value='cropadmin'> Fertility Admin</option>"//<option value='user'> User Admin</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>"
		}
	//	}

	//if (var_guid == '5fa96579-5178-425b-89c4-fc0dafb97ffd' || var_guid == '36ce5933-aeb3-4445-8b0c-4109019ebfc6')
	//	{
	if (userlevel == 3 || userlevel == 1)
		{
		if (var_guid != "5498c571-58eb-464f-b9a7-d986c0d7b7ef")
			{
			html += "<option value='seed_management'> Seed Management</options>"
			}
		//html += "<option value='field_trial'> Field Trial</options>"
		}
	//	}

//	if (var_guid == '5498c571-58eb-464f-b9a7-d986c0d7b7ef')
//		{
//		if (userlevel == 3 || userlevel == 1)
//			{
//			html += "<option value='seed_management'> Seed Management</options>"
//			//html += "<option value='field_trial'> Field Trial</options>"
//			}
//		}

	if (userlevel == 3 || userlevel == 1)
		{
		html += "<option value='system_log_email_to_user'> System Log Email</option>"
		}

	//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='user2'> User Admin </option><option value='userlog'>User Log History</option>" //<option value='user'> User Admin Old</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='guid_finder' style='color:#ffffff;background-color:red;'> Guid Finder</options>"
//		html += "<option value='var_maintenance' style='color:#ffffff;background-color:red;'> Var Maintenance</options>"
//		}
	html += "<option value='legacy_data_import' > Legacy Data Import</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 loadInternalAdmin()
	{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		}

	//alert("w: " + 1260 + " h: " + 700);
	adjustW = (myWidth * .6);
	adjustH = (myHeight * .8);

	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,'internalAdminContent','" + adjustW + "','" + adjustH + "')\"><option value='-99' >--------</option>"

	html += "<option value='activity_map' style='color:black;background-color:#E9AB17;'> Activity Map</options>"
	html += "<option value='billing_ledger' style='color:black;background-color:#E9AB17;'> Billing Ledger</options>"
	html += "<option value='equipment_inventory' style='color:black;background-color:#E9AB17;'> Equipment Inventory</options>"
	html += "<option value='guid_finder' style='color:black;background-color:#E9AB17;'> Guid Finder</options>"
	html += "<option value='legacy_data_import' style='color:black;background-color:#E9AB17;'> Legacy Data Import</options>"
	html += "<option value='var_maintenance' style='color:black;background-color:#E9AB17;'> Var Maintenance</options>"
	html += "<option value='owens_test' style='color:black;background-color:#E9AB17;'> Owens Test Shop</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='internalAdminContent' style='height:620px;width:1220px;padding:5px;overflow:auto;'></div>";
	html += "<div id='internalAdminContent' style='height:" + (adjustH-80) + "px;width:" + (adjustW-30) + "px;padding:5px;overflow:auto;'></div>"; // height:620px;width:1220px;
	openAlertBox("std","Internal Administration",html,adjustW,adjustH);
	}

function loadAdminSub(type, div, adjustW, adjustH)
	{
	//debug = 1;
	document.getElementById(div).style.overflow = 'auto';
	var paramHash = new Array();
	if (type == "user") { paramHash["function"] = "loadUserAdmin"; }
	else if (type == "user2") { paramHash["function"] = "loadUserAdmin2"; }
	else if (type == "-99")
		{
		if (document.getElementById('adminContent'))
			{
			document.getElementById('adminContent').innerHTML= "";
			}

		if (document.getElementById('internalAdminContent'))
			{
			document.getElementById('internalAdminContent').innerHTML= "";
			}
		seed_management_hold_ID = "seed_management_variety_TD";
		UnitPreference_hold_ID = "UnitPreference_SAMPLES_TD";
		}

	else if (type == "activity_map") { paramHash["function"] = "loadActivity_map"; paramHash["class"] = "administration";}
	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 == "owens_test") { paramHash["function"] = "loadTestBob2"; paramHash["class"] = "testBob2"; }
	else if (type == "checkBoundary") { paramHash["function"] = "loadCheckBoundary"; }
	else if (type == "cropadmin") { paramHash["function"] = "loadCropAdmin"; paramHash["class"] = "administration";}
	else if (type == "userlog") { paramHash["function"] = "loadUserLogAdmin"; loadUserLogAdmin_filter = "";loadUserLogAdmin_sort = "";}
	else if (type == "undoDelete") { paramHash["function"] = "undoDeleteInterface"; paramHash["class"] = "administrationUndo"; }
	else if (type == "equMgnt") { newEquationEditor = false; paramHash["function"] = "loadEquationInterface"; paramHash["class"] = "administration"; }
	else if (type == "legacy_data_import") { paramHash["function"] = "loadLegacyDataImport"; 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"; paramHash["adjustW"] = adjustW; paramHash["adjustH"] = adjustH; }
	else if (type == "equipment_inventory") { paramHash["function"] = "load_equipment_inventory"; paramHash["class"] = "equipment_inventory"; }
	else if (type == "guid_finder") { paramHash["function"] = "load_guid_finder"; paramHash["class"] = "administration_guid_finder"; }
	else if (type == "seed_management") { paramHash["function"] = "load_seed_management"; paramHash["class"] = "seed_management"; }
	else if (type == "system_log_email_to_user") { paramHash["function"] = "load_system_log_email_to_user"; paramHash["class"] = "system_log_email_to_user"; }
	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 == "locationPref") { paramHash["function"] = "loadLocationPref"; paramHash["class"] = "locationPref"; paramHash["locationPref_hold_ID"] = ""; paramHash["location_guid"] =""}
		else if (type == "productManagement") { paramHash["function"] = "loadProductManagement"; paramHash["class"] = "product_management";}
		else if (type == "asappliedBatchUpload") { paramHash["function"] = "loadAsappliedBatchUpload"; }
		else if (type == "mobileSyncSetup") { paramHash["function"] = "loadMobileSyncSetup"; }
		else if (type == "unitPreference") { paramHash["function"] = "loadUnitPreference"; }
		else if (type == "equaMgnt") { newEquationEditor = true; paramHash["function"] = "loadEquationInterface"; paramHash["class"] = "administration"; }
		else if (type == "unAssociatedLoggedData") { openDataAssociationDialog(); paramHash["function"] = "selectToolDialog"; paramHash["class"] = "unAssociatedLogged"; }
		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 loadUser2(guid, div)
	{
	var paramHash = new Array();
	paramHash["function"] = "loadUser2";
	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 clearProfileAccess2(level, user_guid)
	{
	targetTypeNum = 6;

	if (level == "var")
		{
		targetTypeNum = 1
		}

	if (level == "business_unit")
		{
		targetTypeNum = 2
		}

	if (level == "location")
		{
		targetTypeNum = 3
		}

	if (level == "grower")
		{
		targetTypeNum = 4
		}

	if (level == "farm")
		{
		targetTypeNum = 5
		}

	if (level == "field")
		{
		targetTypeNum = 6
		}

	$(function () {
		$("#profileAccess2_DIV").jstree({
			"plugins" : [ "themes", "json_data", "crrm", "ui", "checkbox"],
			"themes" : {
				"theme" : "classic",
				"dots" : true,
				"icons" : false
			},
			"json_data": {
				//"progressive_render": true,
				"ajax" : {
					"url" : "/cgi-bin/main.cgi",
					"data" : function (n) {
						return {
							"class": "administration",
							"forUserGuid": user_guid,
							"targetType": level,
							"targetTypeNum": targetTypeNum,
							"from": "select",
							"function" : "openChildUserAdmin",
							"id" : n.attr ? n.attr("id").replace("","") : 1
						};
					}
				}
			}
		});
		$("#profileAccess2_DIV").bind("load_node.jstree", function(event, data) {
		 $("#profileAccess2_DIV li").not(".jstree-leaf").each(function() {
			   $("a ins.jstree-checkbox", this).first().hide();
			   $("a", this).first().click(function(event) {
					  $("#profileAccess2_DIV").jstree("toggle_node", "#"+$(this).parent().attr('id'));
					  event.stopPropagation();
					  event.preventDefault();
			   });
			});
		});
	});
	}

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 deleteUser2(user_guid)
	{
	var r=confirm("Delete This User?");
	if (r==true)
		{
		var paramHash = new Array();
		paramHash["userguid"] = user_guid;
		paramHash["function"] = "deleteUser2";
		makeRequest("/cgi-bin/main.cgi",paramHash);
		}
	else
		{
		return false;
		}
	}

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);
	}

function saveUser2()
	{
	var theform = document.getElementById('userform2');

	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; }

	paramHash["profile_view_id"] = 1

	if (theform.clearProfileAccess2_select.value != "") { if (theform.clearProfileAccess2_select.value == '-99'){ alert('Profile Level Needed!'); theform.clearProfileAccess2_select.style.backgroundColor = "#FFFFCA"; return false; } else { paramHash["profile_level"] = theform.clearProfileAccess2_select.value; } }
	else { theform.clearProfileAccess2_select.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; }
	if (theform.agrian_ui.checked == true) { paramHash["agrian_ui"] = true; }
	else { paramHash["agrian_ui"] = false; }

	var profileAccessList = new Array();
	$("#profileAccess2_DIV .jstree-leaf.jstree-checked").each(function() {
		profileAccessList.push(this.id);
		//alert(this.id);
	});

	if (profileAccessList.length > 0)
		{
		paramHash["profileAccess"] = profileAccessList
		}
	else
		{
		//if (theform.clearProfileAccess2_select.value != 'var')
		//	{
		document.getElementById("profileAccess2_DIV").style.backgroundColor = "#FFFFCA";
		alert('Profile Access Needed!');
		return false
		//	}
		}

	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;
			}
		}

	var tbl = document.getElementById('userAdmin_permission_TABLE');
	var input = tbl.getElementsByTagName("input");

	permissionArray = new Array();

	for (var i = 0; i < input.length; i++) 
		{
	//		//labGuid = selectX[i].id;
		permission_name_id = input[i].id;

		row = document.getElementById(permission_name_id);

		if (row.checked == true)
			{
			permissionArray.push(permission_name_id);
			}
		}
	
		if ( document.getElementById('userAdmin_permission_DIV').style.display=='block') 
			{
			if (permissionArray.length > 0)
				{
				paramHash["permissionArray"] = permissionArray;
				}
			}

	paramHash["function"] = "saveUser2";
	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;
var seasonArray = new Array();
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><td><input type='checkbox' class='radio' id='includeQR'></td><td nowrap>Include QR Image</td></tr>";
		html += "<tr><td><input type='checkbox' class='radio' id='zoomToFields'></td><td nowrap>Zoom to Selected " + viewLabel + "(s)</td><td></td><td nowrap></td></tr>";
		
		
		if (view_id == 1 && report == 'zone_map')
			{
			html += "<tr><td colspan='4'>Select Season:</td></tr>";
			html += "<tr><td><select id='reportOptions_SeasonZone' style='width: 150px;'>";
			for (x in seasonArray )
				{
				html += "<option value='" + x + "'>" + seasonArray[x] + "</option>";
				}
			html += "</select></td></tr>";
			}

		if (report == 'map')
			{
			var c=0
			for (var key in overviewGUIDs)
				{
				c=c+1
				}

			if (c > 1)
				{
				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>";
				}
			else
				{
				html += "<tr><td><input type='checkbox' class='radio' id='showAttributes'></td><td nowrap>Show Attributes</td><td></td><td nowrap></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,document.getElementById('soil_element_list_n_units').value,report)
		}
	else if (report == "singlepannel")
		{
		elementalSoilMapReport(document.getElementById('soil_soil_guid').value,document.getElementById('soil_element_list').value,document.getElementById('soil_element_list_n_units').value,report)
		}
	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)
		}
	else if (report == "boundary_download")
		{
		guid = document.getElementById("data_hidden_value_guid").value;
		value = document.getElementById("data_hidden_value_type").value;

		var paramHash = new Array();
		paramHash["guid"] = guid;
		paramHash["value"] = value;
		paramHash["boundary_export"] = 1;
		paramHash["export_format"] = "shape";
		paramHash["class"] = "tools";
		paramHash["operation"] = "tab";
		paramHash["function"] = "batchExport";
		makeRequest("/cgi-bin/main.cgi",paramHash);
		}
	else if (report == "boundary_download2")
		{
		guid = document.getElementById("data_hidden_value_guid2").value;
		value = document.getElementById("data_hidden_value_type2").value;

		var paramHash = new Array();
		paramHash["guid"] = guid;
		paramHash["value"] = value;
		paramHash["boundary_export"] = 1;
		paramHash["export_format"] = "shapeBoundary";
		paramHash["class"] = "tools";
		paramHash["operation"] = "tab";
		paramHash["function"] = "batchExport";
		makeRequest("/cgi-bin/main.cgi",paramHash);
		}
	else if (report == "boundary_download_combined")
		{
		guid = document.getElementById("data_hidden_value_guid").value;
		value = document.getElementById("data_hidden_value_type").value;

		var paramHash = new Array();
		paramHash["guid"] = guid;
		paramHash["value"] = value;
		paramHash["boundary_export"] = 1;
		paramHash["export_format"] = "shapeCombined";
		paramHash["class"] = "tools";
		paramHash["operation"] = "tab";
		paramHash["function"] = "batchExport";
		makeRequest("/cgi-bin/main.cgi",paramHash);
		}
	}

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) {
				//alert(radios[i].value);
				paramHash["fieldLabels"] = radios[i].value;
				break;
			}
		}
	}


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

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

	if (document.getElementById('includeQR'))
		{
		paramHash["includeQR"] = document.getElementById('includeQR').checked;
		}
	else
		{
		paramHash["includeQR"] = false
		}

	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;

	if (theform.reportOptions_SeasonZone)
		{
		paramHash["season_guid"] = theform.reportOptions_SeasonZone.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];
			}
		}
	
	if (lastValue == "")
		{
		alert("Selection Needed!");
		return false;
		}
	else if (lastValue == "var" || lastValue == "business_unit")
		{
		alert("More Selection Needed!");
		return false;
		}
	//debug = 1;

	counter = 0;
	optionArray = new Array();

	var paramHash = new Array();
	paramHash["guid"] = lastGUID;
	paramHash["value"] = lastValue;
	if (document.getElementById("boundary_export").checked == true) { paramHash["boundary_export"] = 1; counter += 1; optionArray.push('boundary'); }
	else { paramHash["boundary_export"] = 0; }
	if (document.getElementById("sampleData_export").checked == true) { paramHash["sampleData_export"] = 1; counter += 1; optionArray.push('sampleData'); }
	else { paramHash["sampleData_export"] = 0; }
//	if (document.getElementById("season_export").checked == true) { paramHash["season_export"] = 1; counter += 1; optionArray.push('season'); }
//	else { paramHash["season_export"] = 0; }
	if (document.getElementById("veris_export").checked == true) { paramHash["veris_export"] = 1; counter += 1; optionArray.push('veris'); }
	else { paramHash["veris_export"] = 0; }
	if (document.getElementById("cropSpec_export").checked == true) { paramHash["cropSpec_export"] = 1; counter += 1; optionArray.push('cropSpec'); }
	else { paramHash["cropSpec_export"] = 0; }
	if (document.getElementById("planting_export").checked == true) { paramHash["planting_export"] = 1; counter += 1; optionArray.push('planting'); }
	else { paramHash["planting_export"] = 0; }
	if (document.getElementById("asApplied_export").checked == true) { paramHash["asApplied_export"] = 1; counter += 1; optionArray.push('asApplied'); }
	else { paramHash["asApplied_export"] = 0; }
	if (document.getElementById("yield_export").checked == true) { paramHash["yield_export"] = 1; counter += 1; optionArray.push('yield'); }
	else { paramHash["yield_export"] = 0; }
	if (document.getElementById("imagery_export").checked == true) { paramHash["imagery_export"] = 1; counter += 1; optionArray.push('imagery'); }
	else { paramHash["imagery_export"] = 0; }

	if (counter == 0)
		{
		alert("Option Needed!");
		document.getElementById("boundary_export").checked = true;
		return false;
		}

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

	if (optionArray.length == 1)
		{
		for ( x in optionArray )
			{
			if (optionArray[x] == "boundary")
				{
				paramHash["email"] = "no";
				}
			}
		}
	else
		{
		if (lastValue == "field")
			{
			paramHash["email"] = "no";
			}
		else
			{
			paramHash["email"] = "yes";
			}
		}
	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 system_log_info(thisAction,jscode, userguid, theError, extraCC)
	{
	var paramHash = new Array();
	paramHash["theTab"] = currentTab;
	paramHash["theBrowser"] = BrowserDetect.browser.toString();
	paramHash["theBrowserVersion"] = BrowserDetect.version.toString();
	paramHash["theOS"] = BrowserDetect.OS.toString();
	paramHash["userguid"] = userguid;
	paramHash["thisAction"] = thisAction;
	paramHash["jscode"] = jscode;
	paramHash["theError"] = theError;
	paramHash["extraCC"] = extraCC;
	paramHash["function"] = "system_log_info";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function thisSiteLogReport(guid, filterBy, sortBy)
	{
	var paramHash = new Array();
	paramHash["class"] = "reports";
	paramHash["guid"] = guid;
	paramHash["filterBy"] = filterBy;
	paramHash["sortBy"] = sortBy;
	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);

	//system_log_info('Error','', theUser, theError, extraCC)

	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
	}

var loadUserLogAdmin_sort_action = "";
var loadUserLogAdmin_sort_date = "";
//var loadUserLogAdmin_sort_value = "";
var loadUserLogAdmin_sort_action_ARRAY = new Array();
var loadUserLogAdmin_sort_date_ARRAY = new Array();
function loadUserLogAdmin_filter_sort(val, type, theDiv, theUser, theOffset)
	{
	if (type == "filter")
		{
		if (val == "-99")
			{
			loadUserLogAdmin_filter = "";
			}
		else
			{
			loadUserLogAdmin_filter = val;
			}
		}

	if (type == "sort")
		{
		if (val == "-99")
			{
			loadUserLogAdmin_sort = "";
			}
		else
			{
			loadUserLogAdmin_sort = val;
			}

//		if (val == "-99")
//			{
//			loadUserLogAdmin_sort = "";
//			}
//		else
//			{
//			loadUserLogAdmin_sort = val;
//			}
//
//		if (val == "action")
//			{
//			//loadUserLogAdmin_filter_sort_ACTION(val, type, theDiv, theUser, theOffset);
//			}
//		else
//			{
//			//loadUserLogAdmin_filter_sort_DATE(val, type, theDiv, theUser, theOffset);
//			}
		}

	//if (type == "filter")
	//	{
		var paramHash = new Array();
		paramHash["function"] = "loadUserLogAdmin";
		paramHash["div"] = theDiv;
		paramHash["theUser"] = theUser;
		paramHash["theOffset"] = theOffset;
		paramHash["filterBy"] = loadUserLogAdmin_filter;
		paramHash["sortBy"] = loadUserLogAdmin_sort;
		//paramHash["sortValue"] = loadUserLogAdmin_sort_value;
		makeRequest("/cgi-bin/main.cgi",paramHash);
	//	}
	}

//function loadUserLogAdmin_filter_sort_ACTION(theSort, type, theDiv, theUser, theOffset)
//	{
//	html = "<div><br/><br/><center><table><tr><td colspan='2' style='text-align:left;'>Action:</td></tr>"
//	html += "<tr><td><select onchange=\"loadUserLogAdmin_sort_valueFUNC(this.value,'" + theSort + "','" + type + "','" + theDiv + "','" + theUser + "','" + theOffset + "');\"><option value='-99'> - - - </option>"
//	loadUserLogAdmin_sort_action_ARRAY.sort();
//	for (x in loadUserLogAdmin_sort_action_ARRAY)
//		{
//		html += "<option value='" + x + "'>" + x + "</option>"
//		}
//	html += "</select></td><td><button onclick='closeSubAlertBox();'>Close</button></td></tr></table></center></div>"
//
//	openSubAlertBox(html,300,100);
//	}
//
//function loadUserLogAdmin_filter_sort_DATE(theSort, type, theDiv, theUser, theOffset)
//	{
//	html = "<div><br/><br/><center><table><tr><td colspan='2' style='text-align:left;'>Date:</td></tr>"
//	html += "<tr><td><select onchange=\"loadUserLogAdmin_sort_valueFUNC(this.value,'" + theSort + "','" + type + "','" + theDiv + "','" + theUser + "','" + theOffset + "');\"><option value='-99'> - - - </option>"
//	loadUserLogAdmin_sort_date_ARRAY.sort();
//	for (x in loadUserLogAdmin_sort_date_ARRAY)
//		{
//		html += "<option value='" + x + "'>" + x + "</option>"
//		}
//	html += "</select></td><td><button onclick='closeSubAlertBox();'>Close</button></td></tr></table></center></div>"
//
//	openSubAlertBox(html,300,100);
//	}
//
//function loadUserLogAdmin_sort_valueFUNC(val, theSort, type, theDiv, theUser, theOffset)
////function loadUserLogAdmin_sort_valueFUNC(val)
//	{
//	loadUserLogAdmin_sort_value = val;
//
//	var paramHash = new Array();
//	paramHash["function"] = "loadUserLogAdmin";
//	paramHash["div"] = theDiv;
//	paramHash["theUser"] = theUser;
//	paramHash["theOffset"] = theOffset;
//	paramHash["filterBy"] = loadUserLogAdmin_filter;
//	paramHash["sortBy"] = loadUserLogAdmin_sort;
//	paramHash["sortValue"] = loadUserLogAdmin_sort_value;
//	makeRequest("/cgi-bin/main.cgi",paramHash);
//	}

function userLogNext(theUser,theOffset,theDiv, filterBy, sortBy)
	{
	//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;
	paramHash["filterBy"] = filterBy;
	paramHash["sortBy"] = sortBy;
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function userLogPrev(theUser,theOffset,theDiv, filterBy, sortBy)
	{
	//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;
	paramHash["filterBy"] = filterBy;
	paramHash["sortBy"] = sortBy;
	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 excelUserAdminInfo(user_guid, var_guid)
	{
	var paramHash = new Array();
	paramHash["class"] = "reports";
	paramHash["function"] = "excelUserAdminInfo";
	paramHash["user_guid"] = user_guid;
	paramHash["var_guid"] = var_guid;
	makeRequest("/cgi-bin/main.cgi",paramHash);

	//var html = "<center><br/><br/><a href='javascript:void(0);' onclick=\"closeSubAlertBox();\"><img src='/images/loading.gif'></a><br/><br/>Processing...";
	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)
	}
	*/

	if (document.createEventObject) {
		// dispatch for IE
		var evt = document.createEventObject();
		return element.fireEvent('on'+event,evt)
	} else 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);
	}
}

function loadWeather(userGUID){
	var paramHash = new Array();
	paramHash["class"] = "wxAJAX";
	paramHash["function"] = "loadWeatherData";
	paramHash["userGUID"] = userGUID;
	makeRequest("/cgi-bin/main.cgi",paramHash);
}

// Fetch data via an XMLHTTP object for asset Rollover
req = GetRequestObject();
function GetRequestObject(){
	req = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
	return req;
}

// Populate asset descript on mouserollover
function assetRollover(e){
	if (e.elementID){
		shape = VE6map.GetShapeByID(e.elementID);
		if (shape.GetDescription()){
			var guidRegex = /^XX/;
			var descString = shape.GetDescription();
			if(shape.GetDescription().match(guidRegex)){
				url = 'vehicle.py?id=' + shape.GetID() + '&desc=' + shape.GetDescription();
				shape.SetDescription('<span id="' + shape.GetID() + '_Content"> <img src="/images/loading.gif" alt="" align="absmiddle" /> Loading data....</span>');
				req = GetRequestObject();
				if(req) {
					req.onreadystatechange = function(){
						if(req.readyState == 4){
							if(document.getElementById(shape.GetID() + '_Content')){
								document.getElementById(shape.GetID() + '_Content').innerHTML = req.responseText;
								shape.SetDescription(req.responseText);
							}
						}
					}
					req.open("get", url, true);
					req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					req.send(null);
				} else {
//					alert('Cannot load XMLHTTP object');
				}
			}
			else{
			}
		}
	}
}


function saveMobileSyncSetup() {
	var growerList = new Array();
	$("#divMobileSyncTree li .jstree-leaf.jstree-checked").each(function() {
		growerList.push(this.id.replace("sync-",""));
	});
	/*
	if (growerList.length == 0) {
		alert("Please select at least one grower");
		return;
	}
	*/

	openSubAlertBox("<center><br/><br/><img src='/images/loading.gif'><br/><br/>Saving Profiles...",300,150);

	var paramHash = new Array();
	paramHash["class"] = "tools"
	paramHash["function"] = "saveMobileSyncSetup";
	paramHash["growerList"] = growerList.join(",");
	makeRequest("/cgi-bin/main.cgi",paramHash);
}

function clearLayer_FUNC()
	{
	var theMap = document.getElementById('myMap')

	if (document.getElementById('clearLayer_DIV'))
		{
		theMap.removeChild(document.getElementById('clearLayer_DIV'))
		}

	togoW = theMap.style.width;
	togoW = togoW.replace("px","")

	theW = 80

	togoW = parseInt(togoW) - theW

	var xdiv = document.createElement('div');
	xdiv.setAttribute('id',"clearLayer_DIV");
	xdiv.style.height = "20px";
	xdiv.style.width = theW + "px";
	xdiv.style.left = togoW + "px";
	xdiv.style.zIndex = 100;
	xdiv.style.backgroundColor='#235087';
	xdiv.style.color = 'white';
	xdiv.style.textAlign = 'center';
	//xdiv.style.position = 'relative';
	xdiv.style.position = 'absolute';
	xdiv.style.top = '0px';
	xdiv.innerHTML = 'Clear Layer';
	xdiv.style.textAlign = 'center';
	xdiv.style.cursor = 'pointer';
	xdiv.style.fontSize="8pt";
	//xdiv.style.fontWeight = "700"
	xdiv.style.fontStyle = "Normal";
	xdiv.style.fontFamily='arial';
	xdiv.style.verticalAlign='middle';
	xdiv.style.paddingTop = "5px";
	xdiv.style.filter = 'alpha(opacity = 80)';

	xdiv.onclick = function() { cleanMap(1); if (agrainGeoRSS) { VE6map.DeleteShapeLayer(agrainGeoRSS); }; }
	xdiv.onmouseover = function() { xdiv.style.border = "1px solid white"; }
	xdiv.onmouseout = function() { xdiv.style.border = "0px solid white"; }
	theMap.appendChild(xdiv);
	}

function loadUserLogAdmin_DETAIL(log_event_guid, event_classification, user_guid)
	{
	var paramHash = new Array();
	paramHash["log_event_guid"] = log_event_guid;
	paramHash["event_classification"] = event_classification;
	paramHash["user_guid"] = user_guid;
	paramHash["function"] = "loadUserLogAdmin_DETAIL";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}


function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function submitPersonSearch()
	{
	obj = document.getElementById('testinput2');

	var curTop = 0;
    if(obj.offsetParent)
        while(1)
        {
		curTop += obj.offsetTop;
		if(!obj.offsetParent)
			break;
		obj = obj.offsetParent;
        }
    else if(obj.x)
        curTop += obj.x;

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		}

	curTop = myHeight - curTop;

	var options = {
			script:"/cgi-bin/namefill.py?json=true&limit=16&",
			varname:"input",
			json:true,
			shownoresults:false,
			maxresults:5,
			positionOverride:"bottom",
			//positionOverride: "top",
			positionOverrideAmount: parseInt(curTop), //55,
			//maxheight: 50,
			callback: function (obj) { document.getElementById('testid2').value = obj.id; submitPersonSearch2()}
		};
	var as_json = new bsn.AutoSuggest('testinput2', options);
	}

function submitPersonSearch2()
	{
	guid = document.getElementById('testid2').value
	div = "user2TD"

	loadUser2(guid, div);

	checkShortcut(event);

	var scrollFunc = function() {
		var div = document.getElementById("li_" + guid);
		var tree = document.getElementById('userTree2_DIV');
		if (div && tree) {
			var divPos = find_element_position(div);
			var scrollTo = divPos[1] - 300;
			tree.scrollTop = scrollTo;
			tree.pageYOffset = scrollTo;
		}
	};
	setTimeout(scrollFunc,250);
	}

function loadAdminSub_REFRESH()
	{
	var paramHash = new Array();
	paramHash["div"] = "adminContent";
	paramHash["fromSave"] = "true";
	paramHash["function"] = "loadUserAdmin2";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

/////////// TOOLS ( Unit Preference )
var UnitPreference_hold_ID = "UnitPreference_SAMPLES_TD";
var UnitPreference_hold_LOCATION = "";
function UnitPreference_mouseover(td)
	{

	if (td != UnitPreference_hold_ID)
		{
		document.getElementById(td).style.backgroundColor='#444444';
		}
	}

function UnitPreference_mouseout(td)
	{
	if (td != UnitPreference_hold_ID)
		{
		document.getElementById(td).style.backgroundColor='#555555';
		}
	}

function UnitPreference_TD_SELECTION(td, div, theLocation)
	{
	if (theLocation != "")
		{
		UnitPreference_hold_LOCATION = theLocation;
		}
	else
		{
		UnitPreference_hold_LOCATION = document.getElementById('UnitPreference_Location').value;
		}

	document.getElementById(UnitPreference_hold_ID).style.backgroundColor="#555555";
	UnitPreference_hold_ID = td;

	document.getElementById(td).style.backgroundColor="#444444";
	document.getElementById(td).style.color="yellow";
	document.getElementById(td).innerHTML="Loading...";

	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["UnitPreference_hold_ID"] = UnitPreference_hold_ID;
	paramHash["theLocation"] = UnitPreference_hold_LOCATION;
	paramHash["function"] = "loadUnitPreference";
	paramHash["class"] = "tools";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function UnitPreference_SELECTION(guid, div)
	{
	UnitPreference_hold_LOCATION = guid

	document.getElementById(UnitPreference_hold_ID).style.color="yellow";
	document.getElementById(UnitPreference_hold_ID).innerHTML="Loading...";

	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["UnitPreference_hold_ID"] = UnitPreference_hold_ID;
	paramHash["theLocation"] = guid;
	paramHash["fromSelect"] = "";
	paramHash["function"] = "loadUnitPreference";
	paramHash["class"] = "tools";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function UnitPreference_SAMPLES_SELECT(imp_met, div, fromSelect, theLocation)
	{
	//UnitPreference_hold_LOCATION = document.getElementById('UnitPreference_Location').value

	document.getElementById(UnitPreference_hold_ID).style.color="yellow";
	document.getElementById(UnitPreference_hold_ID).innerHTML="Loading...";

	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["UnitPreference_hold_ID"] = UnitPreference_hold_ID;
	if (theLocation != "")
		{
		paramHash["theLocation"] = theLocation;
		}
	else
		{
		paramHash["theLocation"] = UnitPreference_hold_LOCATION;
		}
	paramHash["imp_met"] = imp_met;
	paramHash["fromSelect"] = fromSelect;
	paramHash["function"] = "loadUnitPreference";
	paramHash["class"] = "tools";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function UnitPreference_APPLICATION_SELECT(imp_met, div, fromSelect, theLocation){
	document.getElementById(UnitPreference_hold_ID).style.color="yellow";
	document.getElementById(UnitPreference_hold_ID).innerHTML="Loading...";

	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["UnitPreference_hold_ID"] = UnitPreference_hold_ID;
	if (theLocation != "")
		{
		paramHash["theLocation"] = theLocation;
		}
	else
		{
		paramHash["theLocation"] = UnitPreference_hold_LOCATION;
		}
	paramHash["imp_met"] = imp_met;
	paramHash["fromSelect"] = fromSelect;
	paramHash["function"] = "loadUnitPreference";
	paramHash["class"] = "tools";
	makeRequest("/cgi-bin/main.cgi",paramHash);
}
function UnitPreference_APPLICATION_SELECT_SUBMIT(imp_met, fromSelect, div, theLocation){
	var prefList = new Object();

	tbl = document.getElementById('UnitPreference_APPLICATION_DATA_TYPE_table');

	var selectX = tbl.getElementsByTagName("select");

	for (var i = 0; i < selectX.length; i++) {
		prefGuid = selectX[i].id;
		val = selectX[i].value
		prefList[prefGuid] = val
	}

	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["UnitPreference_hold_ID"] = UnitPreference_hold_ID;
	if (theLocation != "")
		{
		paramHash["theLocation"] = theLocation;
		}
	else
		{
		paramHash["theLocation"] = document.getElementById('UnitPreference_Location').value   //UnitPreference_hold_LOCATION;
		}
	paramHash["fromSelect"] = fromSelect;
	paramHash["imp_met"] = imp_met;
	paramHash["prefList"] = JSON.stringify(prefList);
	paramHash["function"] = "UnitPreference_APPLICATION_SELECT_SUBMIT";
	paramHash["class"] = "tools";
	makeRequest("/cgi-bin/main.cgi",paramHash);
}



function UnitPreference_SAMPLES_SELECT_SUBMIT(imp_met, fromSelect, div, theLocation)
	{

	//var prefList = new Object();
	var prefList = new Object();

	tbl = document.getElementById('UnitPreference_SAMPLE_DATA_TYPE_table');

	var selectX = tbl.getElementsByTagName("select");

	for (var i = 0; i < selectX.length; i++) {
		prefGuid = selectX[i].id;
		val = selectX[i].value

		prefList[prefGuid] = val
		}

	//aler(prefGuid);

	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["UnitPreference_hold_ID"] = UnitPreference_hold_ID;

	if (theLocation != "")
		{
		paramHash["theLocation"] = theLocation;
		}
	else
		{
		paramHash["theLocation"] = document.getElementById('UnitPreference_Location').value   //UnitPreference_hold_LOCATION;
		}
	paramHash["fromSelect"] = fromSelect;
	paramHash["imp_met"] = imp_met;
	paramHash["prefList"] = JSON.stringify(prefList);
	paramHash["function"] = "UnitPreference_SAMPLES_SELECT_SUBMIT";
	paramHash["class"] = "tools";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}

function UnitPreference_YIELD_SELECT_SUBMIT(imp_met, fromSelect, div, theLocation)
	{

	//var prefList = new Object();
	var prefList = new Object();

	tbl = document.getElementById('UnitPreference_YIELD_DATA_TYPE_table');

	var selectX = tbl.getElementsByTagName("select");

	for (var i = 0; i < selectX.length; i++) {
		prefGuid = selectX[i].id;
		val = selectX[i].value

		prefList[prefGuid] = val
		}

	//aler(prefGuid);

	var paramHash = new Array();
	paramHash["div"] = div;
	paramHash["UnitPreference_hold_ID"] = UnitPreference_hold_ID;
	if (theLocation != "")
		{
		paramHash["theLocation"] = theLocation;
		}
	else
		{
		paramHash["theLocation"] = document.getElementById('UnitPreference_Location').value   //UnitPreference_hold_LOCATION;
		}
	paramHash["fromSelect"] = fromSelect;
	paramHash["imp_met"] = imp_met;
	paramHash["prefList"] = JSON.stringify(prefList);
	paramHash["function"] = "UnitPreference_YIELD_SELECT_SUBMIT";
	paramHash["class"] = "tools";
	makeRequest("/cgi-bin/main.cgi",paramHash);
	}
//////////

function getAdjusted_H_W()
	{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		}

	//alert("w: " + 1260 + " h: " + 700);
	adjustW = (myWidth * .6);
	adjustH = (myHeight * .8);

	return [adjustW, adjustH]
	}

function additionalList_Check()
	{
	if (document.getElementById('additionalList').style.display == 'inline')
		{
		document.getElementById('additionalList').style.display = 'none';
		document.getElementById('openHeaderList_image').src = '/images/down_arrow.gif';
		}
	}

// Create additional dialog box(es) (mask out background)
function openAlertBox2(boxType,title,innerhtml,boxWidth,boxHeight,viewCloseBox,viewBoxID){
	var undef;
	var viewBoxDefined = true;
	if(viewBoxID === undef){
		viewBoxID = "dialogBox2";
		viewBoxDefined = false;
	}
	viewBoxBGID = viewBoxID + 'BG'

	if (document.getElementById(viewBoxID)){
		closeAlertBox2(viewBoxID);
	}

	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";
	}
	else if (boxType == "white"){
		color = "#4B79B1";
		corner = "blue";
	}

	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');

	// add background div
	backGroundDiv.setAttribute('id',viewBoxBGID);
	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',viewBoxID);
	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>";
	if (viewBoxDefined){
		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=\"closeAlertBox2('" + viewBoxID + "')\"></td>";
	}
	else{
		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=\"closeAlertBox2()\"></td>";
	}
	html += "</tr>";

	if (boxType == "white"){
		html += "<tr><td colspan='3' bgcolor='#ffffff' id='mid' style='height:" + internalHeight + "px;width:" + boxWidth + "px;' valign='top'>";
	}
	else{
		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>";

	if (boxType == "white"){
		html += "<td style='background-color: #ffffff;height:7px;font-size: 1pt;width:" + middle + "px;'></td>";
	}
	else{
		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){
		if (viewBoxDefined){
			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'));};closeAlertBox2('" + viewBoxID + "');\" style='position:absolute;left:" + closeBox + "px;top:" + closeBoxTop + "px;font-size: 8pt;color:white;cursor: pointer;'>Close/Cancel</span>";
		}
		else{
			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'));};closeAlertBox2();\" 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);
}

// Close additional dialog box(es)
function closeAlertBox2(viewBoxID){
	try{
		var undef;
		if(viewBoxID === undef){
			viewBoxID = "dialogBox2";
		}
		viewBoxBGID = viewBoxID + 'BG'
		if (document.getElementById(viewBoxID)){
			document.body.removeChild(document.getElementById(viewBoxID));
		}
		if (document.getElementById(viewBoxBGID)){
			document.body.removeChild(document.getElementById(viewBoxBGID));
		}
	}
	catch (e){
		// alert('error:' + e + ';');
	}
}

function useradmin2_readonly_check(tab_id)
	{
	readonly = document.getElementById("tab_r_" + tab_id);
	theTab = document.getElementById("tab_" + tab_id);

	if (readonly.checked == true)
		{
		theTab.checked = true;
		}
	}

function useradmin2_thetab_check(tab_id)
	{
	readonly = document.getElementById("tab_r_" + tab_id);
	theTab = document.getElementById("tab_" + tab_id);

	if (theTab.checked == false)
		{
		readonly.checked = false;
		}
	}
