function AttachOnload(MyFunction) {
	if (window.attachEvent) { window.attachEvent("onload",MyFunction); }
	else if (window.addEventListener) { window.addEventListener("load",MyFunction,false); }
}
function CrossBrowserSupport() {
	var ua = navigator.userAgent.toLowerCase();
	var sf = ua.indexOf("safari") > -1;
	if (sf) {
		// find all text-less buttons and add text to them...
		var inputs = document.getElementsByTagName("INPUT");
		for (var i = 0; i < inputs.length; i++) {
			if (inputs[i].type == "submit") {
				if (inputs[i].value == "" || inputs[i].value == " ") {
					inputs[i].value = inputs[i].id;
				}
			}
		}
	}
}

// Check for targetblank
function makeLinksPopup() {
	convertLinks("a");		// Links
	convertLinks("area");	// Image Maps
}
function convertLinks(tagType) {
	var targets = document.getElementsByTagName(tagType); 
	if (targets) {
		for (var i = 0; i < targets.length; i++) {
			if (targets[i].rel) {
				if (targets[i].rel == "targetblank") {
					targets[i].target = "_blank";
				}
			}
		}
	}
}

function splitBrowsers(id) {
	if (typeof(document.styleSheets[id].cssRules) == "object") {
		return document.styleSheets[id].cssRules;
	}
	else {
		return document.styleSheets[id].rules;
	}
}

function getStyleBySelector( selector ) {
   var sheetList = document.styleSheets;
   var ruleList;
   var i, j;

   /* look through stylesheets in reverse order that they appear in the document */
   for (i=sheetList.length-1; i >= 0; i--) {
	   ruleList = splitBrowsers(i);
	   for (j=0; j<ruleList.length; j++) {
		   if (ruleList[j].selectorText == selector) {
				return ruleList[j].style;
		   }   
	   }
   }
   return null;
}

AttachOnload(CrossBrowserSupport);
AttachOnload(makeLinksPopup);
