 // this function is needed to work around 
 // a bug in IE related to element attributes
 function hasClass(obj) {
    var result = false;
    if (obj.getAttributeNode("class") != null) {
        result = obj.getAttributeNode("class").value;
    }
    return result;
 }   


function stripe(classname)
	{
 		var even = false;
		/* this cool stuff is conditional assignment :o) */
	   	var evenColor = arguments[1] ? arguments[1] : "#fff";
	   	var oddColor = arguments[2] ? arguments[2] : "#f7f";
		if(document.getElementsByTagName)
		{
			var tables = document.getElementsByTagName('table')	;
			if (!tables) { return; }
			for (var t = 0; t< tables.length; t++)
			{
				var table = tables[t];
				
				var a = table.className.split(' ');
		 		for (z = 0; z < a.length; z++)
				{
					if (a[z] == classname)
					{	
					   	var tbodies = table.getElementsByTagName("tbody");
					   	for (var h = 0; h < tbodies.length; h++)
						{
					     	var trs = tbodies[h].getElementsByTagName("tr");
					    	for (var i = 0; i < trs.length; i++) 
							{
					       		if (! hasClass(trs[i]) &&
					           	! trs[i].style.backgroundColor)
								{
					         		var tds = trs[i].getElementsByTagName("td");
					         		for (var j = 0; j < tds.length; j++)
									{
	       				           		var mytd = tds[j];
					           			if ( ! mytd.style.backgroundColor) {
											
					             			mytd.style.backgroundColor = even ? evenColor : oddColor;
					           			}
					         		}
					       		}
					       // flip from odd to even, or vice-versa
					       even =  ! even;
					     }
					}
				}
			}
	  	}
	}
 }



function rollOver(e){
	var src,ftype,newsrc;
	if(!e)	{
		e = event;
	}

	src = this.src;
	ftype = src.substring(src.lastIndexOf('.'), src.length);
	newsrc = src;
	if(/_over/.test(src))
	{
		if(e.type == 'mouseout' && this.hit)	{
				newsrc = src.replace('_over','');
		}
	}else{
		if(e.type == 'mouseover')	{
				newsrc = src.replace(ftype, '_over'+ftype);
		}
	}
	this.hit = true;
	this.src=newsrc;
}

function MT_rollOver(className)
 {
	var menuImages,i,a,z,thisimg,src,ftype,newsrc;
	if(!document.getElementsByTagName){return false;}
	menuImages = document.getElementsByTagName('img');
	if(!menuImages){return false;}
	for (i = 0; i< menuImages.length; i++)
	{
		thisimg = menuImages[i]; 
		if(hasClass(thisimg))
		{
			a = hasClass(thisimg).split(' ');
			for (z = 0; z < a.length; z++)
			{
				if(a[z] == className)
				{
					thisimg.hit = false;
					src = thisimg.src;
					ftype = src.substring(src.lastIndexOf('.'), src.length);
					newsrc = src.replace(ftype, '_over'+ftype);
					// Preload image
					preloads['img'+className+i] = new Image();
					preloads['img'+className+i].src = newsrc;
					// Attach mouse over events to image
					thisimg.onmouseover=rollOver;
					thisimg.onmouseout=rollOver;
				}
			}
		}
	}
}




function MT_jumpMenu(linkClass, popup)
{
	if(document.getElementsByTagName)
	{
		var les = document.getElementsByTagName('select');
		if(!les) { return; }
		for (var t = 0; t < les.length; t++)
		{
			var le = les[t]
			if(!hasClass(le)) { continue; }
			var a = hasClass(le).split(' ');
			for (var z = 0; z < a.length; z++)
			{
				if (a[z] == linkClass){
					le.onchange = function(){
						if(popup != null){
						 	var mywin=open(this.value, 'StearnsLending', popup);
						} else {
							document.location.href = this.value;
						}
					}
				}	
			}
		}
	}
}

function MT_linkPopups(popupClass, popupOptions)
{
	if (document.getElementsByTagName)
	{
		// Declare Variables
		var poplinks, pl, ispop, a, i, z;
		popupprefs[popupClass] = popupOptions
		poplinks = document.getElementsByTagName('a')
		// Check links exist on page
		if (poplinks)
		{
			// Loop through links
			for(i = 0; i< poplinks.length; i++)
			{
				pl = poplinks[i];
				ispop = false;
				// Check that link 'pl' is a valid popup link
	 			a = pl.className.split(' ');
	    		for (z = 0; z < a.length; z++) {
	      		if (a[z] == popupClass)
	       		ispop = true;
	    		}	
				// Attach popup window functionality to link
	    		if(ispop){
					pl.onclick = launchPopup;
	    		} 		
			}
		}
	}
}

function launchPopup(){
	var cn, i, j, prefs;
	prefs = "";
	// cycle through class names and match to popupprefs
	// this enables multiple classes to be applied to an anchor
	cn = this.className.split(' ');
	for(i = 0; i < cn.length; i++)
	{
		for(j = 0; j< popupprefs.length; j++)
		{
			if(cn[i] == popupprefs[j])
			prefs = cn[i];
		}
	}
	
	mywin=open(this.href, 'StearnsLending', popupprefs[this.className]);
	this.blur();
	return false;
}

// Containers for image preloads and popup prefs //
popupprefs = new Object();
preloads = new Object();