function a_or_an(text) {
	if (!text) return;
	return text.match(/^[aeiouAEIOU]/) != null ? 'an' : 'a';
}

function get_select_value(sel) {
	return sel.options[sel.selectedIndex].value;
}

function set_select_value(sel, value) {
	for (var i=0; i < sel.options.length; i++) {
		if (sel.options[i].value == value) {
			sel.selectedIndex = i;
			sel.onchange;
		}
	}
}

// Given the id of a page element, and an object containg style keys and values,
// sets those styles on the given object
function styler(id, styles) {
	try {
	var elem = document.getElementById(id);
	if (!id) {return;}
	for (var stylename in styles) {
		var stylevalue = styles[stylename];
		elem.style[stylename] = stylevalue;
	}
	} catch(e) { }
}

function dopopup(url, args) {
	
	var defaults = {
		height: 600,
		width: 475,
		top: 10,
		left: 10,
		resizable: 'yes',
		scrollbars: 'yes',
		status: 'no',
		toolbar: 'no',
		menubar: 'no',
		name: 'pop'
	};
	args = mergeobjs(defaults, args);
	
	var specs =
		'height='+args.height+
		',width='+args.width+
		',top='+args.top+
		',left='+args.left+
		',resizable='+args.resizeable+
		',scrollbars='+args.scrollbars+
		',status='+args.status+
		',toolbar='+args.toolbar+
		',menubar='+args.menubar+
		',location='+url;
	//alert(f);
	window.open(url, args.name, specs);

}

// Copies paramters the first object into the second object
function mergeobjs(one, two) {
	for (var key in one) {
		if (two[key]) { continue; }
		two[key] = one[key];
	}
	return two;
}


function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = 
    	name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function deleteCookie(name, path, domain) {
	document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

// Attach link tags to all links
/*
Event.observe(window, 'load', function() {
    elCSS('a').each(function(elem) {
        if (!elem.href) return;
        var href = elem.pathname;
        if (!href.match(/tmpl|html|htm|asp$/)) {
            var id = elem.innerHTML.unescapeHTML();
            Event.observe(elem, 'click', function(evt) {
                cmCreateManualPageviewTag(
                    id, PageTracking.category, href, window.location.pathname);
            });
        }
    });
});
*/

