function wmdOpenPopup(theUrl, width, height)
{
	var w = 512, h = 512;
	
	if (width != undefined) w = width;
	if (height != undefined) h = height;
			
	var left = (screen.availWidth - w)/2;
	var top = (screen.availHeight - h)/2;
	
	if (w == screen.availWidth) w = w - 12;
	if (h == screen.availHeight) h = h - 24;
	
	var arg = "scrollbars,resizable" + ",width=" + w + ",height=" + h + ",top=" + top + ",left= " + left;
	var win = window.open(theUrl, 'wmdPopup', arg );
	if (!win.opener) { win.opener = self; }
	if (window.focus) {win.focus()}
	
	return false;
}	

function wmdOpenPrintFriedly(theUrl, width, height)
{
	var w = 470, h = 470;
	
	if (width != undefined) w = width;
	if (height != undefined) h = height;
			
	var left = (screen.availWidth - w)/2;
	var top = (screen.availHeight - h)/2;
	
	if (w == screen.availWidth) w = w - 12;
	if (h == screen.availHeight) h = h - 24;
		
	var arg = "toolbar,status,menubar,location,scrollbars,resizable" + ",width=" + w + ",height=" + h + ",top=" + top + ",left= " + left;
	var win = window.open(theUrl, 'PrinterFriendly', arg);
	if (win) { win.focus(); }
	
	return false;
}	
	
function wmdDoBookmark()
{ 
	if (window.external)
	{ 
		window.external.AddFavorite(location.href,document.title); 
	} 
	else
	{ 
		alert('Press CTRL + D to bookmark this page'); 
	} 
	return false; 
}	

function trim(value)
{
  if(value == null) return "";
	return value.replace(/^\s*|\s*$/g, "");
}

function isNumOnly(sNum) 
{
	var sNum = new String(sNum)
	var re = new RegExp(/\D/);

	if (sNum.length > 0) 
	{
		if (sNum.search(re)>=0) 
		{
			return false;
		}
	}
	
	return true;
}

function validateDir(addr, city, state, zip) {
  if(addr == null) addr = "";
  if(city == null) city = "";
  if(state == null) state = "";
  if(zip == null) zip = "";
  
		  if (addr.length < 1) 
			{
				alert("Please enter an address or intersection");
				return false;
			}	
			
			if (zip.length > 0) 
			{
				if (!isNumOnly(zip) || zip.length != 5) 
				{
					alert("Please enter a 5-digit numeric ZIP code");
	   			return false;
				}
			}
			else if (city.length > 1) 
			{
				if (state == "")
				{
					alert("Please select a state");
					return false;
				}	
			}
			else if (state != "") 
			{
				alert("Please enter a city or ZIP code");
				return false;
			}	
			else 
			{
				alert("Please enter a city and state or a ZIP code")
				return false;
			}
			
			return true;
}

