//addEvent(window, "load", ezlinks_init);
//window.onload = ezlinks_nt_init;

var SORT_COLUMN_INDEX;
var link_no = 1;
var link_increment_no = 1;
var alpha_increment = 60;

function ezlinks_nt_init() {
    // Find all tables with class ezlinks and apply ezlinks
    if (!document.getElementsByTagName) return;
    div = document.getElementsByTagName("div");
	//alert(div.length);
    for (ti=0;ti<div.length;ti++) {
        thisDiv = div[ti];
        //if (((' '+thisTbl.className+' ').indexOf("ezlinks") != -1) && (thisTbl.id)) {
        if (((' '+thisDiv.className+' ').indexOf(ezlinks_area) != -1)) {
			link_increment_no = 1;
			ez_makeEZLinks_nt(thisDiv);
        }
    }
}	


function ez_makeEZLinks_nt(div) {
    if (div) {
		
        	var links = div.getElementsByTagName("a"); //get links from current row
			var linklength = links.length;	// We have a link so create an EZ link
			if (linklength < 1){ // if there are no links in this row we have to decrement the counter
				link_no--;
			}
    	for (var i=0;i<linklength;i++) {
			
			var j = (i+link_increment_no)-1 //this fixes the strange behaviour when it counts the added links in the array
      		ez_givemelinks(links[j]); //put the current link into a variable
    	}
	}

    if (!links) return;
    
}

function ez_givemelinks(mylink){
       var myhref = ez_getLinkHref(mylink); //get the href from the current link
		var cell = mylink.parentNode; //get the cell that the current link is in so we can later append the new link to it
		var newlink = document.createElement("a"); //create new EZ link elemnt
		var theStyle = 'ezlink';
		newlink.setAttribute("href", myhref); //set the href of the new EZ link element
		newlink.className = 'ezlink'; //apply ezlink style
		newlink.style.color = 'white';
		var newlinkspace = document.createTextNode(' ');
		var alphachr = unescape('%' +alpha_increment); //create ascii character for extra links on same line
		
		if (alpha_increment>60){ // we only want the ascii character if there is more than one link on this line
			var newlinktext = document.createTextNode(link_no + alphachr);	
		}
		else
		{
			var newlinktext = document.createTextNode(link_no);
		}
		link_no++;
		link_increment_no++;
		newlink.appendChild(newlinktext);
		cell.insertBefore(newlinkspace,mylink); //insert the new space element before the old link
		cell.insertBefore(newlink,newlinkspace); //insert the new element before the old link
}



function ez_getLinkHref(thislink){
	var linkhref = '';
	linkhref = thislink.getAttribute("href"); // pull the href from the current link
	return linkhref;
}