/**
 * A simple location class.
 */
var Location = Class.create();
Location.prototype = {
	_form: null,
	_input: null,
	_defaultInputValue: 'Enter a ZIP',

	initialize: function() {
		this._form  = $('form-location');
		this._input = $('hdr_location');
	},

	handleEvents: function() {
		Event.observe(this._form, 'submit', 
			this.submit.bindAsEventListener(this)
		);
		Event.observe(this._input, 'focus', 
			this.clearDefaultValue.bindAsEventListener(this)
		);
	},

	validate: function() {
		return true;
	},

	submit: function() {
		this.clearDefaultValue();
		return this.validate();
	},

	clearDefaultValue: function() {
		if (this._input.value == this._defaultInputValue) {
			this._input.value = '';
		}
	}
};

/**
 * Opens a framed URL in a new window.
 */
function goTo(url)
{
	var newWindow = open('/go.php?url=' + url,'goto');
	newWindow.focus();
	return false;
}

// Register location-related event handlers
Event.observe(window, 'load', function() {
	if($('form-location'))
	{
		var location = new Location();
		location.handleEvents();
	}
});

function open_subscribe_window(elem,source)
{
	url = '/subscriber/' + escape($F(elem)) + '/' + escape(source);
	subscribewin = window.open(url,'_email_subscribe','height=385,width=465'); 
	$(elem).value='Email Address';
	$(elem).style.color = '#999';
	subscribewin.focus();
}

function toggleDisplay(id)
{
	var el = document.getElementById(id);
	
	if(!el)
		return;
	
	if(el.style.display == 'none')
		el.style.display = 'block';	
	else
		el.style.display = 'none';
		
}


function addStyleClass(element,className)
{
	if(!element.className.match(className))
	{
		element.className = element.className + " " + className;
	}
}

function removeStyleClass(element,className)
{
	
	if(element.className.match(className))
	{
		element.className = element.className.replace(className,"");
		//element.className = element.className.replace(/^ ?(.+) ?$/,"\1");
	}
}

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 unescape(c.substring(nameEQ.length,c.length)).replace(/[+]/g,' ');
		}
	}
	return '';
}

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