/*This javascript is to support the printable order form on Brent Black's site.  To allow users to order multiple hats from the same form, buttons are provided which allows the user to add (and remove) clones of the hat section of the form.  The information of what constitutes the hat section of the form is contained in the form itself -- it's the content of the DIV with ID="hatInformationOriginal".  Do not change that DIV name (or the DIV with ID "hatHolder") as those values are hardcoded into this script.  Otherwise, the HTML can be changed and the script should still work.Christopher Werby (c) 2007.  Pipsqueak Productions, LLChttp://www.pipsqueak.com/April 9, 2007*/function addHatButton(){//This a reference to the pristine HAT HTML element (the first one).var hatInformationOriginal = document.getElementById("hatInformationOriginal");//hatHTML contains the pristine HTML inside the reference to pristine originalvar hatHTML = hatInformationOriginal.innerHTML;//Create a new DIV with the attribute class="newHat"newDiv = document.createElement("div");newDiv.setAttribute("class", "newHat");//set the inner HTML of the new DIV to the pristine HTMLnewDiv.innerHTML= hatHTML;//Get an array of all the divs that contain the class attribute "newHat"var NewHatsArray = getArrayOfNewHatAdds();//Sets an extra class on every 3rd add for printingif ((NewHatsArray.length + 2)%3 == 0) {	newDiv.setAttribute("class", "newHat pageBreak");	}	//Make the Remove Button Visibleif(NewHatsArray.length == 0) {	var styleSheet = createNewStyleSheet();	addHeadStyleRule(styleSheet, "body#printableOrderForm div.removeHat", "visibility: inherit;");	} //This is a reference to the outer DIV surrounding the new hat addsvar hatHolder = document.getElementById("hatHolder");//The NewDiv is inserted the last child in the hatHolder DIVnewChild = hatHolder.appendChild(newDiv);return true;}  function removeHatButton(){//Get an array of all the divs that contain the class attribute "newHat"var NewHatsArray = getArrayOfNewHatAdds();//LastHat contains a reference to the last item in the array of div.newHatvar LastHat = NewHatsArray[NewHatsArray.length - 1];//parent contains a reference to the parent of the LastHat (should be div#hatHolder)var parent = LastHat.parentNode;//Make the Remove Button invisibleif(NewHatsArray.length == 1) {	var styleSheet = createNewStyleSheet();	addHeadStyleRule(styleSheet, "body#printableOrderForm div.removeHat", "visibility: hidden;");	}//This removes the LastHat code from the parent div#hatHolder//removedChild is a reference which isn't used.var removedChild = parent.removeChild(LastHat);return true;}function getArrayOfNewHatAdds() {//Create a new arrayvar NewHatsArray = new Array();//Get a list of all the DIVs in the documentvar allDivList = document.getElementsByTagName("div");//Iterate through all the DIVs and place all the div.newHat references into a new arrayfor (var i=0; i<allDivList.length; i++) {	if ((allDivList[i].getAttribute("class") == "newHat") || (allDivList[i].getAttribute("class") == "newHat pageBreak"))  {		NewHatsArray[NewHatsArray.length] = allDivList[i];		}	}//Return the array of all the div.newHat referencesreturn NewHatsArray;}