function MM_findObj(n, d) 
{ 
/************************************************************************
                               MM_findObj
 Author:  	Appears to be code generated by DreamWeaver
 Date:		06/17/09
 
 Purpose:	This function is used to find a specific element in a dom document
			and to return that element to the falling program.
			
 Parameters:	n - this is a string that contains the name of the element in 
					the document that is to be found.
				d - this may be either empty or contain the pointer to a 
					document to be searched.
					
 Returns:	This function returns the reference to the specific element.
 
 Modifications:
 06/18/2009 - Glenn Hassell
	The logic of the script was set up primarily for IE 4.0 with the
	document.all method of accessing the elements instead of the getElementById
	Changed the code to first check to see if getElementById is available and if 
	so to return the element found using that.  Only if this fails will it go 
	through the remainder of the logic.
************************************************************************/
//v4.01
	var p,i,x; 

	// If no reference to a document was passed in, set d to the current document.
	if(!d) 
		d=document; 
		
	//Check to see if there is a ? in the string at a point other than the first position
	// and then if there are subframes within the document
	if((p=n.indexOf("?")) >0 && parent.frames.length) 
	{
		//From this, it would appear that following the ? mark should be
		//the number of the frame that the element resides
		//so now we are setting d equal to the dom reference for that frame
		d=parent.frames[n.substring(p+1)].document; 
		
		// Get the substring that preceeds the ?
		n=n.substring(0,p);
	}
	if(d.getElementById  && (x=d.getElementById(n)))
		return x;
	if(d.getElementsByName && (x=d.getElementsByName(n)))
	{
		return x[0];
	}
	if(!(x=d[n]) && d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	return x;
}

function validateForm() 
{
/************************************************************************
							validateForm
 Author:	Appears to be code generated by DreamWeaver
 Date:		06/17/2009
 
 Purpose:	This function appears to be designed to test different generic 
			types of fields in an input form.  It is designed to accept a variable 
			number of arguemnts.
 
 Parameters:	Various passed in the function.arguments property array.
	 			Each argument sent is composed of three arguments:
					1 - the Id of a DOM element.
					2 - empty, not used
					3 - First char - R required field
					  - first string 'inRange' numeric field with min/max seperated by :
					  - Not equal to 'R' numeric field
					  - contains string 'isEmail' must contain an email address, if not started with
					    a 'R', not required.
					  - Contains string 'isSelect' the field is a select list and a value is required
					    regardless whether preceded by an R.  If followed by a colon, gives 
					    the starting position in the list for a valid selection.  This allows
					    for entries in the list such as 'Select an Item'.
					  - Contains string 'isPhone' the field must contain a valid telephone number
					    consisting of an area code, a prefix and suffix.  It may contain an extension.
					    If preceded by an R, it is a required field.
					  - Contains string 'isText' the field is a text string, just checks that there is
					    content
					  - First char 'R' followed by anything else other than 
					  		'isEmail',
					  		'isSelect',
					  		'isPhone',
					  	a required Numeric field.

 Returns:	Places true or false into a dom variable MM_returnValue this will be 
			true if no errors are found and false if errors are found.
 
 Modifications:
 06/18/2009 - Glenn Hassell
	Added a return statement at the end so that the true/false would be
		returned by the function.  You can now simply say 
		return validateForm(args);
 06/23/2009 - Glenn Hassell
	Replaced the email validation check to call a function that does a 
		more complete check
 08/12/2009 - Glenn Hassell
	Inserted code to handle the validation of select lists and to handle
	the validation of telephone numbers.
************************************************************************/

 //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
	var obj='';
	var domainTypes = new Array("com","net","gov","mil","org","aero","biz","coop","info",
							"museum","name","pro");
	for (i=0; i<(args.length-2); i+=3) 
	{ 
		test=args[i+2];


		//Get the element to which the argument refers and if it exists, process it
		if ((obj=MM_findObj(args[i]))) 
		{
			//The name may be different from the Id, so get that
			nm=obj.name;

			//Determine if a value has been supplied to the element by the user.
			if ((val=obj.value)!="") 
			{
				//Check to see if the input field is supposed to be an email address and
				//if it is at least partially valid.
				if(test.indexOf('isEmail')!=-1) 
				{ 
					if(!checkEmailAddress(val))
						errors+='- '+nm+' must contain a valid e-mail address.\n';
				}
				//Check to see if the input field is a select list.
				else if(test.indexOf('isSelect') != -1)
				{
					if((p=test.indexOf(":")))
					{
						min = test.substring(p+1)*1;
					}
					else min=0;
					if(!checkSelectList(obj,min))
						errors += '-'+nm+' value must be selected.\n';
				}
				// if the field is a phone field, check for a valid phone number
				else if(test.indexOf('isPhone') != -1)
				{
					if(!checkPhone(obj))
						errors += '-'+nm+' must contain a valid phone number.\n';
				}
				//This is for entries that must be numeric, which would appear
				//To be any where the third parameter is not equal to 'R' and does
				//not contain 'isEmail'
				else if (test!='R' && test.indexOf('isText')==-1) 
				{
					//Check to ensure that the value is numeric, if not, report
					//an error.
					num = parseFloat(val);
					if (isNaN(val))
					{
						errors+='- '+nm+' must contain a number.\n';
					}
					//Check to see if a range was given
					else if (test.indexOf('inRange') != -1) 
					{
						//get the position of the colon, this will seperate the
						//min - max values  This requires that both a min and a 
						//max value are given
						p=test.indexOf(':');
						//The min value is to begin immediately after the 'inRange' indicator
						min=test.substring(8,p);
						//The max value begins after the colon
						max=test.substring(p+1);
						
						//check to see if the number supplied is between the min and the max
						//the min and the max are non-inclusive.
						if (num<min || max<num) 
							errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					} 
				} 
			}
			//If no value is given and the first character in the third parameter is equal to 'R'
			//THen the field is required and an error is required.
			
			//This seems strange, it would appear that one cannot have a numeric field that is required
			//and that has a min/max range.  This probably needs to be corrected.
			else if (test.charAt(0) == 'R') 
				errors += '- '+nm+' is required.\n'; 
		}
	} 
	if (errors) 
		alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
	return document.MM_returnValue;
}
function checkEmailAddress(val)
{
/************************************************************************
							checkEmailAddress
 Author:	Glenn Hassell
 Date:		06/22/2009
 
 Purpose:	This function is used to check for somewhat valid email address
			The address must have a recepient name (at least 2 characters)
			before the @ sign.  It must have the @ sign.  It must have a domain
			name (at least 4 characters long) and it must have a domain type
			that is at least 2 characters long.
 
 Parameters:	val - contains the string to check as a valid email
 
 Returns:	true if somewhat valid, false if not valid
 
 Modifications:
************************************************************************/
	return true;
	var address = val.split('@');
	if(address.length == 2)
	{
		var recipient = address[0].replace(" ","");
		if(recipient.length >=2 && address[1].length)
		{
			var domainAddr = address[1].split(".");
			if((p=domainAddr.length) >= 3)
			{
				var domain='';
				for(q=0;q<p;q++)
				{
					domain=domainAddr[q].replace(" ","");
					if(!domain.length || (q==0 && domain.length<2)||(q == p-1 && domain.length<2))
					{
						return false;
					}
				}
			}
			else
				return false;
		}
		else
			return false;
	}
	else 
		return false;
	return true;
}
function checkPhone(obj)
{
	var number = obj.value;
	var extension = 0;
	if(number.length <10)
		return false;
	if(isNaN(number))
	{
		var exp = /\D/gi;
		number = number.replace(exp,'');
		if(number.length<10)
			return false;
	}
	var mainNumber = number.substr(0,10);
	if( mainNumber != number)
		extension = number.substr(10);
	var area = mainNumber.substr(0,3);
	var prefix = mainNumber.substr(3,3);
	var suffix = mainNumber.substr(6);
	if(extension)
		obj.value = area+-+prefix+-+suffix+-+extension;
	return true;
	
}
function checkSelectList(list,offset)
{
	if(!list.selectedIndex || list.selectedIndex < offset)
		return false;
	return true;
}
function targetopener(mylink, closeme, closeonly)
{
/************************************************************************
							name
 Author:	unknown documented by Glenn Hassell
 Date:		6/23/2009
 
 Purpose:	
 
 Parameters:	mylink - this is to be an anchor object with the url to which
					the parent document is to be redirected
				closeme - flag used to close the current window
				closeonly - this appears to be a flag used to determine whethr 
					to open a new window.
 
 Returns:	true or false
 
 Modifications:
************************************************************************/

	//The opener property of a window allows access to the window that opened the 
	//child window.  It will not be set for a parent window.
	
	//if this window does not have focus or if this is a top parent window
	//don't do anything, just return true.
	if (! (window.focus && window.opener))
		return true;
		
	//Put the focus on the parent of the current window
	window.opener.focus();
	
	//reset the url of the parent window to the supplied url
	if (!closeonly)
		window.opener.location.href=mylink.href;
		
	//close the child window
	if (closeme)
		window.close();
	return false;
}
function popup(mylink, windowname,width,height)
{
	if (! window.focus)return true;
		var href;
	if (typeof(mylink) == 'string')
		href=mylink;
	else href=mylink.href;
	if(width == undefined)
		width=500;
	if(height==undefined)
		height=300;
	
	window.open(href, windowname, 'width='+width+',height='+height+',scrollbars=yes,resizable=1');
	return false;
}
function setDistrictRef(ref,ext)
{
	document.getElementById("ref").value=ref;
	if(ext != undefined)
	{
		document.getElementById("ext").value=ext;
	}
	document.DistrictSelectForm.submit()
}
function setDate(val,id)
{
	document.getElementById(id).value=val;
}
function countChar(ele,maxChar,id)
{
	var sz = ele.value.length;
	if(sz > maxChar)
	{
		var tmp = ele.value.substr(0,maxChar);
		ele.value = tmp;
		sz = maxChar;
	}
	var remain = maxChar-sz;
	var display = document.getElementById(id);
	display.value=remain;
}
function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
		var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}

function setScreenSizeCookie()
{
	var winW = 320, winH = 400;
	if (document.body && document.body.offsetWidth) 
	{
		 winW = document.body.offsetWidth;
		 winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
		document.documentElement &&
		document.documentElement.offsetWidth ) 
		{
			 winW = document.documentElement.offsetWidth;
			 winH = document.documentElement.offsetHeight;
		}
	if (window.innerWidth && window.innerHeight) 
	{
		 winW = window.innerWidth;
		 winH = window.innerHeight;
	}
//	winW = screen.availWidth;
//	winH = screen.availHeight;
	var size;
	
	size = window.orientation+'<>'+winW+'x'+winH;
	eraseCookie('mobileScreenSize');
	createCookie('mobileScreenSize',size,0);
	return false;
}
function reloadMobile()
{
	window.open(document.location.href,'_self');
}
function resizeImage(target,id,direct)
{	
	if(direct != undefined && target)
	{
		window.open(target, "Image", "width=300, height=200, left=100, top=200, " +
		   "location=no, menubar=no, status=no, toolbar=no, " + "scrollbars=yes, resizable=yes")
		  return false;
	}
	var doit = "?Do=popImage&";
	if(target)
		doit += "urlRef="+target;
	else if(id != undefined && id)
	{
		doit += "imageId="+id;
	}
	window.open(doit, "Image", "width=300, height=200, left=100, top=200, " +
		   "location=no, menubar=no, status=no, toolbar=no, " + "scrollbars=yes, resizable=yes")
	return false;
}
function resizeImageWindow()
{
	var element = document.body.getElementsByTagName("img")[0];
	var height =element.height+150;
	var width = element.width+50;
    window.resizeTo(width,height);
	return false;
}
function naisSetRawFmt(val)
{
	var ele = document.getElementById("rnmea");
	if(ele)
	{
		ele.checked=val;
	}
}
function checkLegAction(ele)
{
	if(ele.checked == false)
	{
		var tmp = document.getElementById('ForLEorLegalActionN');
		if( tmp.checked == false)
		{
			ele.checked=true;
			return false;
		}
	}
}
function naisHideGrid()
{
	var ele=document.getElementById("heatMap");
	if(ele)
	{
		var checked = ele.checked;
		if(ele=document.getElementById("gridDisplay"))
		{
			ele.style.display = (checked)?"block":"none";
		}
	}
	naisHideBgImg();
}
function naisHideBgImg()
{
	var ele=document.getElementById("heatMap");
	var heatMap = (ele)?ele.checked:false;
	var kmlAnima = ((ele=document.getElementById("kmlAnima")))?ele.checked:false;
	var stdGraphics = false;
	if(ele = document.getElementsByName("stdGrphFmt"))
	{
		for(i=0;i<ele.length;i++)
			if(ele[i].checked)
			{
				stdGraphics = true;
				if(ele=document.getElementById('clrGrph'))
					ele.checked=true;
				break;
			}
	}
	if(ele=document.getElementById("bgImgDisplay"))
	{
		ele.style.display = (heatMap || kmlAnima || stdGraphics)?"block":"none";
	}
}
function aisClearGrph(item)
{
	if(item == undefined || !item)
		return;
	if(!item.checked)
	{
		if(ele = document.getElementsByName("stdGrphFmt"))
		{
			for(i=0;i<ele.length;i++)
				ele[i].checked = false;
			naisHideBgImg();
		}
	}
}
function definedBoxType(ele)
{
	var id = ele.id;
	var ele2='';
	var ele3='';
	var field='';
	var aoiFields = Array('urlatd','urlatm','urlats','urlongd','urlongm',
		'urlongs','lllatd','lllatm','lllats','lllongd','lllongm','lllongs',
		'urlatN','urlongW','lllatN','lllongW','urlatS','urlongE','lllatS','lllongE');
	var aoiddFields = Array('urlatdd','urlongdd','lllatdd','lllongdd');
	if(id == 'dbll')
	{
		if(!(ele2 = document.getElementById('dbdd')))
			return;
		if(ele.checked)
		{
			ele2.checked=false;
			for(field in aoiFields)
			{
				if((ele3=document.getElementById(aoiFields[field])))
				{
					ele3.disabled=false;
				}
			}
			for(field in aoiddFields)
			{
				if((ele3=document.getElementById(aoiddFields[field])))
				{
					ele3.disabled=true;
				}
			}
		}
		else
		{
			for(field in aoiddFields)
			{
				if((ele3=document.getElementById(aoiddFields[field])))
				{
					ele3.disabled=false;
				}
			}
		}
	}
	else if(id == 'dbdd')
	{
		if(!(ele2 = document.getElementById('dbll')))
			return;
		if(ele.checked)
		{
			ele2.checked=false;
			for(field in aoiddFields)
			{
				if((ele3=document.getElementById(aoiddFields[field])))
				{
					ele3.disabled=false;
				}
			}
			for(field in aoiFields)
			{
				if((ele3=document.getElementById(aoiFields[field])))
				{
					ele3.disabled=true;
				}
			}
		}
		else
		{
			for(field in aoiFields)
			{
				if((ele3=document.getElementById(aoiFields[field])))
				{
					ele3.disabled=false;
				}
			}
		}
	}

}
function resizeWindow(width,height)
{
	try
	{
		top.resizeTo(width,height);
	}
	catch(err){}
}
var checkOrientation = function()
{
    if(window.orientation != undefined && window.orientation != previousOrientation)
	{
        previousOrientation = window.orientation;
        // orientation changed, do your magic here
		setScreenSizeCookie();
		reloadMobile();
	}
}




