/*
 * Javascript routines used for www.healthreform.ie
*/

//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt

//***Cross browser attach event function. For 'evt' pass a string value with the leading "on" omitted
//***e.g. AttachEvent(window,'load',MyFunctionNameWithoutParenthesis,false);
function AttachEvent(obj,evt,fnc,useCapture){
    if (!useCapture) useCapture=false;
    if (obj.addEventListener){
	obj.addEventListener(evt,fnc,useCapture);
	return true;
    } else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
    else{
	MyAttachEvent(obj,evt,fnc);
	obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
    }
} 

function self_referential_links() {
    // remove any links in the document that point to itself.
    var self_referential = new Array();
    var links = document.links;
    for (i = 0; i < links.length; i++) {
	if (links[i].href == document.location.href) {
	    /* 
	       we have a self-referential link.
	       IE5 doesn't support push()
	    */
	    if (links[i].href.search('#top') != -1) {
		continue;
	    }
	    links[i].className="selfref";
	}
    }
}

// alternately coloured rows in the table
function colour_rows() {
    var tables = document.getElementsByTagName("table");
    for (var i = 0; i < tables.length; i++) {
	var table = tables[i];
	var rows = table.rows;
	var count = 1;
	for (var j = 0; j < rows.length; j++) {
	    var row = rows.item(j);
	    if (row.className) {
		continue;
	    }
	    if (count % 2 == 0) {
		row.className = "even";
	    } else {
		row.className = "odd";
	    }
	    count++;
	}
    }
}

try {
    AttachEvent(window,"load",self_referential_links,false);
    AttachEvent(window,"load",colour_rows,false);
} catch (e) {
    // non-DOM browser
}