// JavaScript Document

addLoadEvent(addQuoteButton);

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}






// Get Elements by Class function borrowed from Jonathan Snook - http://www.snook.ca/archives/javascript/your_favourite_1/ 
function getElementsByClassName(needle) {
	var my_array = document.getElementsByTagName("*");
	var retvalue = new Array();
	var h;
	var j;
	for (h=0,j=0;h<my_array.length;h++) {
		var c = " " + my_array[h].className + " ";
		if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[h];
	}
	return retvalue;
}



// Finds <a> elements within the class name "create_quote_button"
// Adds image content with link into the title attribute of the <a> elements within the class name "create_quote_button"
function addQuoteButton() {
	if (!document.getElementsByTagName) {
	return false;
	}
	
	if (!getElementsByClassName("create_quote_button")) {
	return false;
	}
	
	var needButton = getElementsByClassName("create_quote_button");
	
	for (var k=0; k < needButton.length; k++) {
		var myLinks = needButton[k].getElementsByTagName("a");
		
		for (var m=0; m < myLinks.length; m++) {
			
			var ogTitle = myLinks[m].getAttribute("title");
			
			if (ogTitle) {
			
				var makeContent = (ogTitle + "<form method=\'post\' action=\'http://www.calibamboo.com/mm5/merchant.mvc?\'><input type=\'hidden\' name=\'Screen\' value=\'BASK\'><input type=\'hidden\' name=\'Action\' value=\'ADPR\'><input type=\'hidden\' name=\'Store_Code\' value=\'CB\'><input type=\'hidden\' name=\'Product_Code\' value=\'70.FOS.SAM.DISJVA\'><input type=\'hidden\' name=\'Category_Code\' value=\'bambooflooring\'><input type=\'hidden\' class=\'quantity\' name=\'Quantity\' value=1 size=3><a href=\'buybamboonow_flooring.html\'><img src=\'https://www.calibamboo.com/mm5/images/bambooquote.gif\' alt=\'Request Quote\'  ></a><img src=\'mm5/images/spacer.gif\' width=\'225\' height=\'1\'><input type=\'image\' alt=\'Buy Fossilized Strand Wide Plank Hand Scraped Bamboo Flooring Distressed Java Sample\' src=\'mm5/images/buy_sample.jpg\' border=\'0\'><\/form>");
			
			
			myLinks[m].setAttribute("title", makeContent);
			
				
		
			}
			
			else {
				var buttonOnly = "<a href=\'buybamboonow_flooring.html\'><img src=\'https://www.calibamboo.com/mm5/images/bambooquote.gif\' alt=\'Request Quote\'  ><\/a>";
			
			
			myLinks[m].setAttribute("title", buttonOnly);
			
				
			
			}
			// Since IE has issues with onmouseleave, make sure your linked text or image has an alt and a title tag so that the garbage above won't be stuffed in there.
		}
	}
}








