function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
}

/**
 * Dynamically transforms the search field at the bottom of the page into a
 * Safari Search control in Safari
 */
var safariSearch = {
	init: function() {
		if(navigator.userAgent.toLowerCase().indexOf('webkit') != -1) {
			safariSearch.build();
		}
	},
	build: function() {
		var baseObj = document.getElementById('base_search');
		if(typeof(baseObj) != 'undefined' && baseObj != null)
		{
			this.label = baseObj.getElementsByTagName('label')[0];
			this.field = baseObj.getElementsByTagName('input');
			// loop through all inputs in the LI - capture just the textfield
			for (var i=0; i<this.field.length; i++) {
				if (this.field[i].type == 'text') {
					this.field = this.field[i];
					break;
				}
			}
			
			if(typeof(this.field) != 'undefined')
			{
				this.field.setAttribute('type','search');
				this.field.setAttribute('placeholder',this.label.firstChild.nodeValue);
				this.field.setAttribute('results','20');
				this.field.setAttribute('class',this.field.className.replace("fake_safari",""));
			}
		}
	}
}

var ieSearch = {	
	init: function() {
		ieSearch.build();
	},
	build: function() {
		var baseObj = document.getElementById('base_search');
		
		if(typeof(baseObj)  != 'undefined' && baseObj != null)
		{
			this.fields = baseObj.getElementsByTagName('input');
			// loop through all inputs in the LI - capture just the textfield
			for (var i=0; i<this.fields.length; i++) {
				switch(this.fields[i].type)
				{
					case 'text':
						this.field = this.fields[i];
						break;
					case 'image':
						this.button = this.fields[i];
						break;
				}
			}
			
			if(typeof(this.field) != 'undefined')
			{
				addEvent(this.field,'keypress',this.checkEnter,false);
			}
		}
	},
	checkEnter: function(e) {
		if(e.keyCode == 13)
		{
			e.cancelBubble = true;
			e.returnValue = false;	
			
			ieSearch.submitForm();
		}
	},
	submitForm: function() {
		this.button.click();
		//this.form = document.getElementById("Form1");
		//this.form.submit();
	}
}

addEvent(window,'load',safariSearch.init,false);
addEvent(window,'load',ieSearch.init,false);

// onclick popup function
POPUP_W = 600;
POPUP_H = 620;
POPUP_SCROLL = true;
POPUP_RESIZE = true;
POPUP_EXTRAS = 'location=0,status=0,menubar=0,directories=no,toolbar=no';
if (!(document.cookie)) {
    document.cookie = 'allowCookies=true';
    var docCookie = document.cookie;
}
// USAGE: popuplink(['non-js url',] this[, w[, h[, scroll[, resize[, extras]]]]])
function popuplink() {
	var undef, i=0, args=popuplink.arguments;
	var url = (typeof(args[i])=='string') ? args[i++] : args[i].getAttribute('href');
	var target = args[i++].getAttribute('target') || '_blank';
	var w = args[i++];
	var h = args[i++];
	var s = (args[i]===undef) ? POPUP_SCROLL : args[i++];
	var r = (args[i]===undef) ? POPUP_RESIZE : args[i++];
	var features = 'width=' + (w || POPUP_W)
				 + ',height=' + (h || POPUP_H)
				 + ',scrollbars=' + (s ? 'yes,' : 'no,')
				 + ',resizable=' + (r ? 'yes,' : 'no,')
				 + (args[i] || POPUP_EXTRAS);
	var win = window.open(url, target, features);
	win.focus();
	return false;
}

