//station function of badger crap for contact page
function station_display()
{
   // select box with locations
   var s = document.getElementById('frmLocation').location;
   // station index
   var i = s.selectedIndex;
   //set station attribs
   document.getElementById('s_name').innerHTML           = stations[i]['name'];
   document.getElementById('s_address1').innerHTML       = stations[i]['address1'];
   document.getElementById('s_city').innerHTML           = stations[i]['city'];
   document.getElementById('s_state').innerHTML          = stations[i]['state'];
   document.getElementById('s_zip').innerHTML            = stations[i]['zip'];
   document.getElementById('s_tollfreephone').innerHTML  = stations[i]['tollfreephone'];
   document.getElementById('s_localphone').innerHTML     = stations[i]['localphone'];
   document.getElementById('s_fax').innerHTML            = stations[i]['fax'];
   document.getElementById('s_email').innerHTML          = stations[i]['email'];
   // address 2 
   // if not blank
   if (stations[i]['address2'] != '')
   {
   //postpend a line break
   document.getElementById('s_address2').innerHTML = stations[i]['address2'] + '<br />';
   }else{
   document.getElementById('s_address2').innerHTML = '';
   }
   //mailto href
   document.getElementById('s_mailto').href =   'mailto:' + stations[i]['email'] + '?subject=Request From Contact Page';
}

// clear vallue of passed control
function clearVal(o)
{
	if (o.value) 
	{
		if (o.value.indexOf('-') == 1)
		o.value = '';
	}
}

// show hidden div under service pages header
function showText(o)
{
	var len = o.childNodes.length;	
	for (x = 0; x < len; x++)
	{
		if (o.childNodes[x].tagName == 'DIV')
		{
			if (o.childNodes[x].style.display != 'block')
				o.childNodes[x].style.display = 'block';
			else
				o.childNodes[x].style.display = 'none';
		}
	}	
} // showText()
// show / hide all
function toggleList()
{
	var u 	= document.getElementById('u_items');
	var len = u.childNodes.length;
	var l;			
	var a = document.getElementById('a_items');

	for(x = 0; x < len; x++)
	{
		l = u.childNodes[x];
		
		//dwrite('u.childNodes[' + x + '].tagName = ' + l.tagName);
		if (l.tagName == 'LI')
		{
			d = getChildElement(l, 'DIV');

			if (a && a.innerHTML == 'show all items')
				d.style.display = 'block';
			else
				d.style.display = 'none';
		}
	}

	
	if (a)
	{
		if (a.innerHTML == 'show all items')
			a.innerHTML = 'hide all items';
		else
			a.innerHTML = 'show all items';
	}

} // toggleList()
// iterate children - return first elem w/ passed tag name
// returns: html element
function getChildElement(o, tag)
{
	if (!o) 
	{
		alert('null ref passed to getChildElement()');
		return;
	}
	
	var len = o.childNodes.length;
	var x, e;
		
	for(x = 0; x < len; x++)
	{
		//dwrite('l.kid[' + x + '].tagName= ' + o.childNodes[x].tagName);
		if (o.childNodes[x].tagName == tag)
		{
			e = o.childNodes[x];
			break;
		}
	}

	return e;
} // getChildElement()

// trim leading & trailing spaces
function trim(str)
{
	if (! str) return "";

	var ret = str.replace(/^\s*/g, "");

	ret 	= ret.replace(/\s*$/g, "");	

	return ret;
}

function openStationmap()
{
	win = window.open('/maps/station.aspx', 'stationmap', 'height=600,width=600,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1');
	win.focus();
}
// does string match name@domain.ext?
function validateEmail(sEmail)
{
	var ret = false;
	
	var re = /^.+?@.+?\..+$/; 
	
	if (sEmail.match(re))
	{
		ret = true;
	}
	
	return ret;
}

function validateSubscriptionForm(sEmail)
{
	var ret = validateEmail(sEmail);
	
	if (!ret)
	{
		alert("Please enter a valid email address.");
	}
	
	return ret;
}
