function replaceButs() {
	var allInputs = document.getElementsByTagName('INPUT');
	for(var i = 0;i<allInputs.length;i++) { 
		var myObj = allInputs[i];
		if (myObj.tagName.toLowerCase() == "input") {
			if (myObj.attributes['type'].specified && (!myObj.getAttribute('ignore') == 1)) { 
				if (myObj.type.toLowerCase() == "submit" || myObj.type.toLowerCase() == "button" || myObj.type.toLowerCase() == "reset") {

					currId = "but_"+i;
					myObj.id = currId;

					// determine if this is IE or not:
					var brows = document.getElementById(currId);
					if (brows.currentStyle) {
	
						var replaceme = myObj.outerHTML.replace("\>", "");
						replaceme = replaceme.replace("class=", "");
						var composite = replaceme;
						
						if (myObj.getAttribute('title') != false) {
							var newtitle = myObj.title;
						} else {
							var newtitle = myObj.value;
						}
						
						composite += " onmouseover=\"this.className = 'buthover';\" onmouseout=\"this.className = 'butout';\" title=\""+newtitle+" \" class=\"butout\" >";
						//onmouseover="this.className = 'buthover';" onmouseout="this.className = 'butout';"
						
						myObj.outerHTML = composite;
						
					} else { // if this is a Mozilla type browser:
					 	
						if (myObj.title.value == null) {
							var newtitle = myObj.value;
						} else {
							var newtitle = myObj.title;
						}
						
						 // set the "class" attrib:
						t = document.createAttribute('title');
						t.value = newtitle;
						myObj.setAttributeNode(t);
						
						 // set the "class" attrib:
						var x = document.createAttribute('class');
						x.value = "butout";
						myObj.setAttributeNode(x);
						
						// set the "onmouseover" attrib:
						var z = document.createAttribute('onMouseover');
						z.value = "javascript:document.getElementById('"+currId+"').className = 'buthover';";
						myObj.setAttributeNode(z);
						
						// set the "onmouseout" attrib:
						var y = document.createAttribute('onMouseout');
						y.value = "javascript:document.getElementById('"+currId+"').className = 'butout';";
						myObj.setAttributeNode(y);
						
						//onmouseover="this.className = 'buthover';" onmouseout="this.className = 'butout';"
	
					}

				}
			}
		}
	}
}
// debugging use onClick=showme(ObjId); on button to view HTML:
function showme(a) {
	alert(a.outerHTML);
}

function findTheSwap() {
	// If the Custom StyleSheet [1] has a number in the href filename, this is a real custom StyleSheet and we'll have to search it for a ".butout" selector
	// Else, if it has no number (ends in an underscore) then this is a default StyleSheet template and we already know it contains a ".butout" selector.
	CSScustom = document.styleSheets[1].href;
	strSplitted= CSScustom.split(".");
	strLen = strSplitted.length;
	strPenult = eval(strLen -2);
	strPenultLen = strPenult.length;
	strChk = strSplitted[strPenult].substring((strPenultLen -1),strPenultLen);
	strChkLen = strChk.length;
	fnChk = strChk.substring((strChkLen -1),strChkLen);
	
	if (fnChk != "_" && fnChk != "1") {
		lenCSS = document.styleSheets.length;
		// loop through all CSS skipping the first ASG.CSS (default stylesheet) to check if the Button Swapping's style exists on this template:
		for (i=1;i<lenCSS;i++) {
			try{
				var lenRules = document.styleSheets[i].rules.length;
				for (j=0;j<lenRules;j++) {
					var testCSS = document.styleSheets[i].rules[j].selectorText;
	//window.status = "CSS="+i+" rules="+j+" selectorText="+testCSS+"";
					if (testCSS == ".butout") {
	//alert(testCSS);
						return true;
						break;
					} 
				}
			}catch(e){

			}
		}
		//window.status = " "
		return false;
	} else {
		//window.status = " "
		return true;
	}
	;
}

// Find if there is a ".butout" selector:
if(!document.getElementById('bypassButtonSwap')){
	if (findTheSwap() == true) {

		replaceButs();
	}
}
