emptyFormData = "56:0!!59:0!!62:0!!67:0!!70:0!!71:false!!72:0!!73:false!!74:0!!75:false!!76:0!!77:0!!78:0!!79:0!!80:0!!81:0!!82:0!!83:0!!84:0!!85:0!!86:0!!87:0!!88:0!!89:0!!90:0!!91:0!!"
standardProductionDays = 7
standardRushFeePercent = 0.20

codeVersion = new Array()
	codeVersion[0] = "1.0.062207"
	codeVersion[1] = "1.0.072207"
	codeVersion[2] = "1.0.072907"
	codeVersion[3] = "1.1.100107"
	codeVersion[4] = "1.1.030508"
	codeVersion[5] = "2.0.032008"
	
	
function downLevelScriptHandler(){
	switch (getCookie("swVersion")){
		case codeVersion[0]:
		case codeVersion[1]:
		case codeVersion[2]:
		case codeVersion[3]:
		case codeVersion[4]:
		case codeVersion[5]:
			alert('This website was updated with new software since the last time that you visited the site.\n\nAny previously saved orders on this computer are being updated to work with the new software.') 
			setCookie("swVersion",codeVersion[codeVersion.length-1])
			return
			break
			
		default:
			alert('This website was updated with new software since the last time that you visited the site.\n\nAny previously saved orders are going to be deleted from this computer so that the new software can recreate the data structures.\n\nWe are sorry for any inconvience that this may cause.') 
			clearCookie("orderform")
			clearCookie("signcopy")
			clearCookie("specialinstructions")
			clearCookie("shipping")
			clearCookie("itemnumber")
			clearFormData(document.sign_order_form)
			setCookie("swVersion",codeVersion[codeVersion.length-1])
			return
			break
	}
}

function getSalesman(){
	var salesmanCode = ""
	var referCode = ""
	salesCode = gup("S")	//check to see if a sales code was passed.  if so save it in a cookie
	referCode = gup("R")	//check to see if a refer code was passed.  if so save it in a cookie
	if (salesCode != "") setCookie("S",salesCode)
	if (referCode != "") setCookie("R",referCode)
}

function referSite(docObj){
	var linkFrom = docObj.referrer
	
	var origLink = getCookie("orig")
	var referLink = getCookie("refer")
	
	var ninetyDays = 90 * 24 * 60 * 60 * 1000
	var expDate = new Date()
	expDate.setTime(expDate.getTime() + ninetyDays)
	
//	alert("from="+linkFrom+" - orig="+origLink+" - refer="+referLink)

	if (origLink == null) setCookie("orig", linkFrom)
		
	if (referLink == null)
		setCookie("refer", linkFrom, expDate)
	else
		setCookie("refer", referLink, expDate) //renew cookie to extend date

}

//**********************************************************************************************************************
//The following code is used to build the templates page
//


var imageCnt
var	imageRootName  
var imageWidth 
var	imageHeight 
var	imageSrcName 
var	formFieldName 


function buildPage(imageCount,imageRoot,imageWidth,imageHeight){
// This funtion builds the popup window table and fills it with all the images in rows with 4 columns.
// The parameters are imageCount which defines the number of images to display and imageRoot which is
// the root name for the image files including the path.  All images must have the same name and path
// with the only difference being a 3 digit sequence number on the trailing end just before the .jpg
// file type specifier.  imageWidth and imageHeight specify the size to display the images in the table.

	document.writeln("<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\">")  //define table to hold the images
	for (var i=0; i<=imageCount; i++){  		// display images
		if (i%4 == 0) {						// if this is the 1st image of a new row then output a <tr> tag
			document.writeln("<tr>")
			}
		if (i<10) {							// pad any necessary 0's on the front of the image sequence number
			imageIndex = "00" + i
			}
		else if (i<100) {
			imageIndex = "0" + i
			}
		else {
			imageIndex = i
			}
		imageSrc = imageRoot + imageIndex + ".jpg"		// build the correct image source name by added the sequence number and .jpg to the root		
						
		document.write("<td width=\"25%\" height=\"" + (imageHeight+25) + " valign=\"middle\" align=\"center\"><img name=\"img" + imageIndex + "\" border=\"1\" src=\""+ imageSrc + "\" ")	// display the image in the table  		
		document.writeln("onClick=sendValue(\""+ imageSrc +"\") width=\"" + imageWidth + "\" height=\"" + imageHeight +"\" ")			// set the event handler to send back the image name when clicked		
		document.writeln("onMouseOver=this.document.images.img" + imageIndex + ".id=\"hiLite_border\" ")								// set the event handeler to highlight the border when the mouse is over the image
        document.writeln("onMouseOut=this.document.images.img" + imageIndex + ".id=\"normal_border\"><br>&nbsp;</td>")					// set the event handler to un-highlight the border when the mouse is moved off of the image
        
		if (i%4 == 3) {						// if this is the last image in the row then output a </tr> tag
			document.writeln("</tr>")
			}
		}
	document.writeln("</table></center>")	// all the images have been displayed, so end the table
	}
	
function sendValue(s){
	eval("window.opener.document.sign_order_form." + formFieldName + ".value = s");
	eval("window.opener.document.images." + imageSrcName + ".src = s");
	window.close();
	}
	
function buildGallery(imageCount,imageRoot,imageWidth,imageHeight){
// This funtion builds the popup window table for the Gallery Page and fills it with all the images in rows with 4 columns.
// The parameters are imageCount which defines the number of images to display and imageRoot which is
// the root name for the image files including the path.  All images must have the same name and path
// with the only difference being a 3 digit sequence number on the trailing end just before the .jpg
// file type specifier.  imageWidth and imageHeight specify the size to display the images in the table.

	document.writeln("<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\">")  //define table to hold the images
	for (var i=0; i<=imageCount; i++){  		// display images
		if (i%4 == 0) {						// if this is the 1st image of a new row then output a <tr> tag
			document.writeln("<tr>")
			}
		if (i<10) {							// pad any necessary 0's on the front of the image sequence number
			imageIndex = "00" + i
			}
		else if (i<100) {
			imageIndex = "0" + i
			}
		else {
			imageIndex = i
			}
		imageSrc = imageRoot + imageIndex + ".jpg"		// build the correct image source name by added the sequence number and .jpg to the root		
						
		document.write("<td width=\"25%\" height=\"" + (imageHeight+25) + " valign=\"middle\" align=\"center\"><img name=\"img" + imageIndex + "\" border=\"1\" src=\""+ imageSrc + "\" ")	// display the image in the table  		
		document.writeln("onClick=zoomTemplate(\""+ imageSrc +"\") width=\"" + imageWidth + "\" height=\"" + imageHeight +"\" ")			// set the event handler to send back the image name when clicked		
		document.writeln("onMouseOver=this.document.images.img" + imageIndex + ".id=\"hiLite_border\" ")								// set the event handeler to highlight the border when the mouse is over the image
        document.writeln("onMouseOut=this.document.images.img" + imageIndex + ".id=\"normal_border\"><br>&nbsp;</td>")					// set the event handler to un-highlight the border when the mouse is moved off of the image
        
		if (i%4 == 3) {						// if this is the last image in the row then output a </tr> tag
			document.writeln("</tr>")
			}
		}
	document.writeln("</table></center>")	// all the images have been displayed, so end the table
	}

function zoomTemplate(s){
//	eval("window.opener.document.sign_order_form." + formFieldName + ".value = s");
//	eval("window.opener.document.images." + imageSrcName + ".src = s");
	window.close();
	}


//
//End of template page building code
//**********************************************************************************************************************

//**********************************************************************************************************************
//The following code is used to build the page for gathering sponsors' names
//

function orderformData(){
	this.reset1_button=""
	this.tournament_name=""; this.tournament_date=""; this.tournament_location=""; this.signs_required_by=""; this.contact_name=""; this.contact_phone=""; this.contact_email=""; 
	
	this.hole_large_qty="";			this.hole_small_qty="";			this.hole_template=""
	this.hio_large_qty="";			this.hio_small_qty="";			this.hio_template=""
	this.kp_large_qty="";			this.kp_small_qty="";			this.kp_template=""
	this.ld_large_qty="";			this.ld_small_qty="";			this.ld_template=""
	this.sd_large_qty="";			this.sd_small_qty="";			this.sd_template=""
	this.mulligan_large_qty="";		this.mulligan_small_qty="";		this.mulligan_template=""
	this.putt_large_qty="";			this.putt_small_qty="";			this.putt_template=""
	this.chip_large_qty="";			this.chip_small_qty="";			this.chip_template=""
	this.registration_large_qty="";	this.registration_small_qty="";	this.registration_template=""
	this.cart_large_qty="";			this.cart_small_qty="";			this.cart_template=""
	this.beverage_large_qty="";		this.beverage_small_qty="";		this.beverage_template=""
	this.breakfast_large_qty="";	this.breakfast_small_qty="";	this.breakfast_template=""
	this.lunch_large_qty="";		this.lunch_small_qty="";		this.lunch_template=""
	this.dinner_large_qty="";		this.dinner_small_qty="";		this.dinner_template=""
	this.cocktails_large_qty="";	this.cocktails_small_qty="";	this.cocktails_template=""
	this.blank_large_qty="";		this.blank_small_qty="";		this.blank_template=""
	
	this.banner_event_size="";				this.banner_event_qty="";				this.event_banner_template=""
	this.banner_premier_sponsor_size="";	this.banner_premier_sponsor_qty="";		this.premier_banner_template=""
	this.banner_sponsor_size="";			this.banner_sponsor_qty="";				this.sponsor_banner_template=""
	
	this.award_check_qty="";		this.award_check_template=""
	
	this.event_schedule_size="";	this.event_schedule_qty="";		this.event_schedule_template=""
	
	this.art_fee=""
	this.email_proof=false;	this.proof_fee=""
	this.wire_stakes=false;	this.stakes_fee=""
	this.rush=false;		this.rush_fee=""	
	this.other_fees_subtotal=""
	
	this.large_sign_total_qty="";	this.large_sign_total_price=""
	this.small_sign_total_qty="";	this.small_sign_total_price=""
	this.banner_total_qty="";		this.banner_total_price=""
	this.award_check_total_qty="";	this.award_check_total_price=""
	this.event_sign_total_qty="";	this.event_sign_total_price=""
	
	this.subtotal_price=""; this.other_total_price=""; this.package_discount=""; this.total_price_wo_ship_tax=""
	
	this.update_totals_button=""
	this.continue_button=""
	this.reset2_button=""
}

var orderformInput = new orderformData()
var orderformPropIndex = new Array()	

function reconstructOrderform(obj) {
	var formData = getCookie("orderform")
	if (formData == null) return null  // exit with a null return value if there is no orderform cookie
	
	var i=0	
	for (var prop in obj){
		obj[prop] = ""
		orderformPropIndex[i] = prop
		i += 1
	}
	
	var formDataElements = formData.split("!!")
	var dataElementIndex
	var dataElementValue
	for (var i=0; i<formDataElements.length-1; i++) {	
		dataElementIndex = parseInt(formDataElements[i].split(":")[0])
		dataElementValue = unescape(formDataElements[i].split(":")[1])
		obj[orderformPropIndex[dataElementIndex]] = dataElementValue
	}	
	return 1
}

function buildSponsorInputSection(signName,numberOfSponsors,imageName,sponsorNameRoot,signTypeIndex) {
	var sponsorIndex
	var numberOfSavedSponsorFields = 0
	var savedSponsorNames = new Array()
	var standardTemplate = true
	var tripleZero = /000/
	
	if (tripleZero.test(imageName))	standardTemplate = false
		
	document.writeln("<tr>")
	document.writeln("<td width=\"25%\" style=\"border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1\">" + signName + "</td>")
    document.writeln("<td width=\"25%\" style=\"border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1\">")
    document.writeln("<img border=\"1\" src=\"" + imageName + "\" width=\"150\" height=\"113\"></td>")
    document.writeln("<td width=\"50%\" style=\"border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1\">")
    
    var signCopyCookie = getCookie("signcopy")
    
	if (signCopyCookie != null){
		numberOfSavedSponsorFields = parseInt(signCopyCookie.split("!!")[0].split(":")[signTypeIndex])		// gets number of saved fields from cookie header
		savedSponsorNames = signCopyCookie.split("!!")[1].split("^")[signTypeIndex].split(":")				// gets array of saved field data values
	}
	
	if (standardTemplate){	//if the sign uses a standard template then prompt for sponsor names																							
			
		for (var i=1; i<=numberOfSponsors; i++){
			if (i<10) {							// pad any necessary 0's on the front of the sponsor sequence number
				sponsorIndex = "0" + i
			}
			else {
				sponsorIndex = i
			}
			document.write(sponsorIndex + " <input type=\"text\" name=\"" + sponsorNameRoot + i + "\" size=\"30\" ")
		
			if (i<=numberOfSavedSponsorFields){
				document.write("value=\"" + unescape(savedSponsorNames[i-1]) + "\"")
			}
			else {
				document.write("value=\"\"")
			}
			document.writeln("><br>")
		}
	}
	else{	//if the sign does not use a standard template then notify that the complete sign will have to be uploaded later
	
		document.writeln('<font color=\"#000000\" size=\"1\">You will be asked to upload <b>' + numberOfSponsors + '</b> design files after your order has been submitted.')
		document.writeln('Instructions on how to upload your files will be provided via e-mail.  Your order will not start production until all the files have been received.<br></font>')
	
		for (var i=1; i<=numberOfSponsors; i++){
			if (i<10) {							// pad any necessary 0's on the front of the sponsor sequence number
				sponsorIndex = "0" + i
			}
			else {
				sponsorIndex = i
			}
		//	document.writeln(sponsorIndex + " <input type=\"text\" name=\"" + sponsorNameRoot + i + "\" size=\"30\" value=\"SIGN-" + sponsorNameRoot + i + "\"><br>")
			document.writeln("<input type=\"hidden\" name=\"File:" + sponsorNameRoot + i + "\" size=\"30\" value=\"\">")

		}
	}
	document.writeln("</tr>")
}

function buildTextAreaInputSection(signName, numberOfTextAreas, imageName, imageHeight, imageWidth, textAreaRoot, textAreaNumberOfLines, signTypeIndex) {
	var textAreaIndex
	var numberOfSavedTextFields = 0
	var savedTextData = new Array()
	var standardTemplate = true
	var tripleZero = /000/
	
	if (tripleZero.test(imageName))	standardTemplate = false
		
	document.writeln("<tr>")
	document.writeln("<td width=\"25%\" style=\"border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1\">" + signName + "</td>")
    document.writeln("<td width=\"25%\" style=\"border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1\">")
    document.writeln("<img border=\"1\" src=\"" + imageName + "\" width=\"" + imageHeight + "\" height=\"" + imageWidth + "\"></td>")
    document.writeln("<td width=\"50%\" style=\"border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1\">")
    
    var signCopyCookie = getCookie("signcopy")
	if (signCopyCookie != null){
		numberOfSavedTextFields = parseInt(signCopyCookie.split("!!")[0].split(":")[signTypeIndex])		// gets number of saved fields from cookie header
		savedTextData = signCopyCookie.split("!!")[1].split("^")[signTypeIndex].split(":")				// gets array of saved field data values
	}
		
	if (standardTemplate){	//if the sign uses a standard template then prompt for sponsor names																							
			
		for (var i=1; i<=numberOfTextAreas; i++){
			if (i<10) {							// pad any necessary 0's on the front of the sponsor sequence number
				textAreaIndex = "0" + i
			}
			else {
				textAreaIndex = i
			}	
			document.write(textAreaIndex + " <textarea rows=\"" + textAreaNumberOfLines + "\" name=\"" + textAreaRoot + i + "\" cols=\"30\" wrap=off>")
			
			if (i<=numberOfSavedTextFields){
				document.write(unescape(savedTextData[i-1]))
			}
					
			document.writeln("</textarea><br>")
		}
	}
	else{	//if the sign does not use a standard template then notify that the complete sign will have to be uploaded later
	
		document.writeln('<font color=\"#000000\" size=\"1\">You will be asked to upload <b>' + numberOfTextAreas + '</b> design files after your order has been submitted.')
		document.writeln('Instructions on how to upload your files will be provided via e-mail.  Your order will not start production until all the files have been received.<br></font>')
	
		for (var i=1; i<=numberOfTextAreas; i++){
			if (i<10) {							// pad any necessary 0's on the front of the sponsor sequence number
				textAreaIndex = "0" + i
			}
			else {
				textAreaIndex = i
			}
			document.writeln("<input type=\"hidden\" name=\"File:" + textAreaRoot + i + "\" size=\"30\" value=\"\">")

		}
	}
	document.writeln("</tr>")
}

function clearSponsors(formObj){
	if (confirm('Are you sure that you want to delete all your sponsor names and other sign copy?\n\nClick \"Okay\" to clear the form or \"Cancel" to not delete it')){
		clearCookie("signcopy")
		clearFormData(formObj)
		return
	}
	else
		return 
}

var signCopyCookieHeader = ""		// initilize cookie header information so that it can be built during the construction of the form

function buildSponsorForm(){

	if (reconstructOrderform(orderformInput) == null){
		alert("Order form was blank or no cookie was saved.  Please enter a new order and make sre that your cookies are enabled")
		return
	}
	
	signCopyCookieHeader = ""		// re-init each time we build form
	
	var numberOfHoleSponsors=getQty(orderformInput.hole_large_qty)+getQty(orderformInput.hole_small_qty)
		if (numberOfHoleSponsors > 0) buildSponsorInputSection("Hole Sponsors", numberOfHoleSponsors, orderformInput.hole_template, "HSN", 0)
		signCopyCookieHeader += numberOfHoleSponsors + ":"

	var numberOfHIOSponsors=getQty(orderformInput.hio_large_qty)+getQty(orderformInput.hio_small_qty)
		if (numberOfHIOSponsors > 0) buildSponsorInputSection("Hole In One Sponsors", numberOfHIOSponsors, orderformInput.hio_template, "HION", 1)
		signCopyCookieHeader += numberOfHIOSponsors + ":"
		
	var numberOfKPSponsors=getQty(orderformInput.kp_large_qty)+getQty(orderformInput.kp_small_qty) 
		if (numberOfKPSponsors > 0) buildSponsorInputSection("Closest to The Pin Sponsors", numberOfKPSponsors, orderformInput.kp_template, "KPN", 2)
		signCopyCookieHeader += numberOfKPSponsors + ":"

	var numberOfLDSponsors=getQty(orderformInput.ld_large_qty)+getQty(orderformInput.ld_small_qty)  
		if (numberOfLDSponsors > 0) buildSponsorInputSection("Longest Drive Sponsors", numberOfLDSponsors, orderformInput.ld_template, "LDN", 3)
		signCopyCookieHeader += numberOfLDSponsors + ":"

	var numberOfSDSponsors=getQty(orderformInput.sd_large_qty)+getQty(orderformInput.sd_small_qty)  
		if (numberOfSDSponsors > 0) buildSponsorInputSection("Straightest Drive Sponsors", numberOfSDSponsors, orderformInput.sd_template, "SDN", 4)
		signCopyCookieHeader += numberOfSDSponsors + ":"

	var numberOfMulliganSponsors=getQty(orderformInput.mulligan_large_qty)+getQty(orderformInput.mulligan_small_qty)  
		if (numberOfMulliganSponsors > 0) buildSponsorInputSection("Mulligan Sponsors", numberOfMulliganSponsors, orderformInput.mulligan_template, "MULN", 5)
		signCopyCookieHeader += numberOfMulliganSponsors + ":"

	var numberOfPuttSponsors=getQty(orderformInput.putt_large_qty)+getQty(orderformInput.putt_small_qty)  
		if (numberOfPuttSponsors > 0) buildSponsorInputSection("Putting Contest Sponsors", numberOfPuttSponsors, orderformInput.putt_template, "PUTTN", 6)
		signCopyCookieHeader += numberOfPuttSponsors + ":"

	var numberOfChipSponsors=getQty(orderformInput.chip_large_qty)+getQty(orderformInput.chip_small_qty)  
		if (numberOfChipSponsors > 0) buildSponsorInputSection("Chipping Contest Sponsors", numberOfChipSponsors, orderformInput.chip_template, "CHIPN", 7)
		signCopyCookieHeader += numberOfChipSponsors + ":"

	var numberOfRegSponsors=getQty(orderformInput.registration_large_qty)+getQty(orderformInput.registration_small_qty)  
		if (numberOfRegSponsors > 0) buildSponsorInputSection("Registration Sponsors", numberOfRegSponsors, orderformInput.registration_template, "REGN", 8)
		signCopyCookieHeader += numberOfRegSponsors + ":"

	var numberOfCartSponsors=getQty(orderformInput.cart_large_qty)+getQty(orderformInput.cart_small_qty)  
		if (numberOfCartSponsors > 0) buildSponsorInputSection("Golf Cart Sponsors", numberOfCartSponsors, orderformInput.cart_template, "CARTN", 9)
		signCopyCookieHeader += numberOfCartSponsors + ":"

	var numberOfBevSponsors=getQty(orderformInput.beverage_large_qty)+getQty(orderformInput.beverage_small_qty)  
		if (numberOfBevSponsors > 0) buildSponsorInputSection("Beverage Cart Sponsors", numberOfBevSponsors, orderformInput.beverage_template, "BEVN", 10)
		signCopyCookieHeader += numberOfBevSponsors + ":"

	var numberOfBreakSponsors=getQty(orderformInput.breakfast_large_qty)+getQty(orderformInput.breakfast_small_qty)  
		if (numberOfBreakSponsors > 0) buildSponsorInputSection("Breakfast Sponsors", numberOfBreakSponsors, orderformInput.breakfast_template, "BREAKN", 11)
		signCopyCookieHeader += numberOfBreakSponsors + ":"

	var numberOfLunchSponsors=getQty(orderformInput.lunch_large_qty)+getQty(orderformInput.lunch_small_qty)  
		if (numberOfLunchSponsors > 0) buildSponsorInputSection("Lunch Sponsors", numberOfLunchSponsors, orderformInput.lunch_template, "LUNCHN", 12)
		signCopyCookieHeader += numberOfLunchSponsors + ":"

	var numberOfDinnerSponsors=getQty(orderformInput.dinner_large_qty)+getQty(orderformInput.dinner_small_qty)  
		if (numberOfDinnerSponsors > 0) buildSponsorInputSection("Dinner Sponsors", numberOfDinnerSponsors, orderformInput.dinner_template, "DINNERN", 13)
		signCopyCookieHeader += numberOfDinnerSponsors + ":"

	var numberOfCocktailSponsors=getQty(orderformInput.cocktails_large_qty)+getQty(orderformInput.cocktails_small_qty)  
		if (numberOfCocktailSponsors > 0) buildSponsorInputSection("Cocktail Sponsors", numberOfCocktailSponsors, orderformInput.cocktails_template, "COCKN", 14)
		signCopyCookieHeader += numberOfCocktailSponsors + ":"

	var numberOfBlankTextAreas=getQty(orderformInput.blank_large_qty)+getQty(orderformInput.blank_small_qty)  
		if (numberOfBlankTextAreas > 0) buildTextAreaInputSection("Custom Signs", numberOfBlankTextAreas, orderformInput.blank_template, 150, 113, "BLANKN", 7, 15)
		signCopyCookieHeader += numberOfBlankTextAreas + ":"

	var numberOfEventTextAreas=getQty(orderformInput.banner_event_qty)  
		if (numberOfEventTextAreas > 0) buildTextAreaInputSection("Event Banner", numberOfEventTextAreas, orderformInput.event_banner_template,150, 58, "EVENTN", 4, 16)
		signCopyCookieHeader += numberOfEventTextAreas + ":"

	var numberOfPremierTextAreas=getQty(orderformInput.banner_premier_sponsor_qty)  
		if (numberOfPremierTextAreas > 0) buildTextAreaInputSection("Premier Sponsor Banner", numberOfPremierTextAreas, orderformInput.premier_banner_template,150, 58, "PREMIERN", 4, 17)
		signCopyCookieHeader += numberOfPremierTextAreas + ":"

	var numberOfBannerTextAreas=getQty(orderformInput.banner_sponsor_qty)  
		if (numberOfBannerTextAreas > 0) buildTextAreaInputSection("Sponsor Banner", numberOfBannerTextAreas, orderformInput.sponsor_banner_template,150, 58, "BANNERN", 4, 18)
		signCopyCookieHeader += numberOfBannerTextAreas + ":"

	var numberOfAwardTextAreas=getQty(orderformInput.award_check_qty)  
		if (numberOfAwardTextAreas > 0) buildTextAreaInputSection("Award Check", numberOfAwardTextAreas, orderformInput.award_check_template,150, 76, "AWARDN", 4, 19)
		signCopyCookieHeader += numberOfAwardTextAreas + ":"

	var numberOfSchedTextAreas=getQty(orderformInput.event_schedule_qty)  
		if (numberOfSchedTextAreas > 0) buildTextAreaInputSection("Event Schedule", numberOfSchedTextAreas, orderformInput.event_schedule_template,150, 200, "SCHEDN", 10, 20)
		signCopyCookieHeader += numberOfSchedTextAreas + ":"

}

function saveSignCopy(formObj) {
	var formData = getSignData(formObj)
	var oneYear = 365 * 24 * 60 * 60 * 1000
	var expDate = new Date()
	expDate.setTime(expDate.getTime() + oneYear)
	setCookie("signcopy",formData,expDate)
}

function getSignData(formObj) {
	var signData = ""+signCopyCookieHeader+"!!"
	var numberOfElements = formObj.elements.length
	
	var numberOfDataFields = signCopyCookieHeader.split(":")
	var j=0
	var k=21
	
	for (var i=0; i<numberOfElements; i++){
		if ((formObj.elements[i].type == "text")||(formObj.elements[i].type == "textarea")||(formObj.elements[i].type =="hidden")){
			if (parseInt(numberOfDataFields[j]) == 0){
				signData += "^"
				++j; --i; --k
			}
			else{
				numberOfDataFields[j] = "" + (parseInt(numberOfDataFields[j])-1)		
				signData += escape(formObj.elements[i].value)+":"			
			}
		}			
	}
	while(k>0){
		signData += "^"
		--k
	}
	signData += "!!"
	return (signData)
}

//
//End of the sponsor name code
//***************************************************************************************************************************

//*****************************************************************************************
//The following Code is used to create the order confirmation pages
//

function buildOrderConfirmationPage(){

	if (reconstructOrderform(orderformInput) == null){
		alert("Order form was blank or no cookie was saved.  Please enter a new order and make sure that your cookies are enabled")
		return
	}
	
	//******************************************* start general tournament and contact infor section
	document.writeln('<table style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#111111\" height=\"73\" cellSpacing=\"0\" cellPadding=\"3\" width=\"540\" border=\"1\">')
    document.writeln('<tr>')
    document.writeln('<td align=\"left\" width=\"100%\"><p align=\"center\"><br></font><font size=\"2\">')
    document.writeln('<b>Tournament Signage Order Details</b></font></p><font size=\"1\"><br>')
    document.writeln('<b>Tournament Name:&nbsp;   </b>' + orderformInput.tournament_name + '<br>')
    document.writeln('<b>Tournament Location:  </b>' + orderformInput.tournament_location + '<br>')
    document.writeln('<b>Tournament Date:&nbsp;  </b>' + orderformInput.tournament_date + '<br>')            
    document.writeln('<b>Signs Required by:&nbsp;  </b>' + orderformInput.signs_required_by + '<br>')
    document.writeln('<b>Contact Person:&nbsp;  </b>' + orderformInput.contact_name + '<br>')
    document.writeln('<b>Contact Phone Number:  </b>' + orderformInput.contact_phone  + '<br>')
    document.writeln('<b>Contact Email:&nbsp; </b>' + orderformInput.contact_email  + '<br>')
  
    if (orderformInput.wire_stakes == "true"){
		document.writeln('<p><b>Wire Stakes for all Sponsor Signs is included with your order.</b></p>')
	}
	document.writeln('<p>')
    if (orderformInput.email_proof == "true"){
		if (orderformInput.rush =="true"){
			document.writeln('<b>You have requested a RUSH production order.</b>  A proof of your signs will be emailed to you within 1 business day.')
		}
		else {
			document.writeln('A proof of your signs will be emailed to you within 2-3 business days.')
		}
		document.writeln('Please review the proof <u>immediately</u> and reply with your approval or changes.')
		document.writeln('Production of your signs will <u>not</u> start untill we receive your approval e-mail.</p>')
	}
	else{
		if (orderformInput.rush =="true"){
			document.writeln('<b>You have requested a rush production order and have <u>not</u> requested a proof before production starts.</b>')	
			document.writeln('Your order will go to production immediately and <u>no</u> changes can be made without additional charges and scedule delays.')
		 	document.writeln('<input type=\"hidden\" name=\"\nRush Order\" value=\"YES\">')
		 }
		 else{
			document.writeln('<b>You have <u>not</u> requested a proof before production starts. </b>')
			document.writeln('Your order will go to production immediately and <u>no</u> changes can be made without additional charges and scedule delays.')
		 }		 	
    	}
    
    document.writeln('&nbsp;</font></td>')     		
    document.writeln('</tr>')      
    document.writeln('</table>') 
	//************************************************** end general tournament and contact section
	
	//************************************************** start sign type section
	document.writeln('<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"540\" height=\"73\">')
    document.writeln('<tr>')
    document.writeln('<td width=\"15%\" align=\"center\" bgcolor=\"#000000\" height=\"35\">')
    document.writeln('<font color=\"#FFFFFF\" size=\"1\"><b>Sign Type</b></font></td>')
    document.writeln('<td width=\"5%\" align=\"center\" bgcolor=\"#000000\" height=\"35\">')
    document.writeln('<font color=\"#FFFFFF\" size=\"1\"><b>Qty</b></font></td>')
    document.writeln('<td width=\"7%\" align=\"center\" bgcolor=\"#000000\" height=\"35\">')
    document.writeln('<font color=\"#FFFFFF\" size=\"1\"><b>Size</b></font></td>')
    document.writeln('<td width=\"12%\" align=\"center\" bgcolor=\"#000000\" height=\"35\">')
    document.writeln('<font color=\"#FFFFFF\" size=\"1\"><b>Background</b></font></td>')
    document.writeln('<td width=\"61%\" align=\"center\" bgcolor=\"#000000\" height=\"35\">')
    document.writeln('<font color=\"#FFFFFF\" size=\"1\"><b>Sponsor Name or Custom Text</b></font></td>')
    document.writeln('</tr>')
    
	buildSSLineItem("Hole Sponsor", getQty(orderformInput.hole_large_qty), getQty(orderformInput.hole_small_qty), orderformInput.hole_template, 0)	
	buildSSLineItem("HIO Sponsor", getQty(orderformInput.hio_large_qty), getQty(orderformInput.hio_small_qty), orderformInput.hio_template, 1)	
	buildSSLineItem("KP Sponsor", getQty(orderformInput.kp_large_qty), getQty(orderformInput.kp_small_qty), orderformInput.kp_template, 2)	
	buildSSLineItem("LD Sponsor", getQty(orderformInput.ld_large_qty), getQty(orderformInput.ld_small_qty), orderformInput.ld_template, 3)	
	buildSSLineItem("SD Sponsor", getQty(orderformInput.sd_large_qty), getQty(orderformInput.sd_small_qty), orderformInput.sd_template, 4)	
	buildSSLineItem("Mulligan Sponsor", getQty(orderformInput.mulligan_large_qty), getQty(orderformInput.mulligan_small_qty), orderformInput.mulligan_template, 5)	
	buildSSLineItem("Putt Sponsor", getQty(orderformInput.putt_large_qty), getQty(orderformInput.putt_small_qty), orderformInput.putt_template, 6)	
	buildSSLineItem("Chip Sponsor", getQty(orderformInput.chip_large_qty), getQty(orderformInput.chip_small_qty), orderformInput.chip_template, 7)	
	buildSSLineItem("Registration Sponsor", getQty(orderformInput.registration_large_qty), getQty(orderformInput.registration_small_qty), orderformInput.registration_template, 8)	
	buildSSLineItem("Cart Sponsor", getQty(orderformInput.cart_large_qty), getQty(orderformInput.cart_small_qty), orderformInput.cart_template, 9)	
	buildSSLineItem("Beverage Sponsor", getQty(orderformInput.beverage_large_qty), getQty(orderformInput.beverage_small_qty), orderformInput.beverage_template, 10)	
	buildSSLineItem("Breakfast Sponor", getQty(orderformInput.breakfast_large_qty), getQty(orderformInput.breakfast_small_qty), orderformInput.breakfast_template, 11)	
	buildSSLineItem("Lunch Sponsor", getQty(orderformInput.lunch_large_qty), getQty(orderformInput.lunch_small_qty), orderformInput.lunch_template, 12)	
	buildSSLineItem("Dinner Sponsor", getQty(orderformInput.dinner_large_qty), getQty(orderformInput.dinner_small_qty), orderformInput.dinner_template, 13)	
	buildSSLineItem("Cocktail Sponsor", getQty(orderformInput.cocktails_large_qty), getQty(orderformInput.cocktails_small_qty), orderformInput.cocktails_template, 14)
	buildSSLineItem("Custom Sign", getQty(orderformInput.blank_large_qty), getQty(orderformInput.blank_small_qty), orderformInput.blank_template, 15)
		
  	buildTSLineItem("Event Banner", getQty(orderformInput.banner_event_qty), orderformInput.banner_event_size, orderformInput.event_banner_template, 16)	
  	buildTSLineItem("Premier Banner", getQty(orderformInput.banner_premier_sponsor_qty), orderformInput.banner_premier_sponsor_size, orderformInput.premier_banner_template, 17)	
  	buildTSLineItem("Sponsor Banner", getQty(orderformInput.banner_sponsor_qty), orderformInput.banner_sponsor_size, orderformInput.sponsor_banner_template, 18)
  		
  	buildTSLineItem("Award Check", getQty(orderformInput.award_check_qty), "0", orderformInput.award_check_template, 19)	
  	buildTSLineItem("Event Schedule", getQty(orderformInput.event_schedule_qty), orderformInput.event_schedule_size, orderformInput.event_schedule_template, 20)	
    
    document.writeln('</table>')
    //*************************************** end of sign type setion
    
    //*************************************** begin special instructions section
	document.writeln('<form name=\"additional_info\">')
    document.writeln('<table style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#111111\" height=\"73\" cellSpacing=\"0\" cellPadding=\"3\" width=\"540\" border=\"1\">')
    document.writeln('<tr><td width=\"100%\" align\"center\">')
    document.writeln('</font><font size=\"2\">')            
    document.writeln('<b>Special Instructions:</b>')
    document.writeln('<p><i>If you have any special instructions or want to provide any additional information regarding your order, please include it in the box below.  Thank you!</i></p>')
    document.writeln('<center><textarea name=\"Special_Instructions\" cols=\"60\" rows=\"5\" wrap=off></textarea>')    
    document.writeln('<p><input type=\"button\" name=\"clear_special\" value=\"Clear\" onclick=\"clearSpecial(this.form)\"></p></center></td>')

    document.writeln('</tr></font></table></form>')
    
    var specialInstructions = getCookie("specialinstructions")
    if (specialInstructions != null) document.additional_info.Special_Instructions.value = unescape(specialInstructions)
    
    //*************************************** end special instructions section
    
    //*************************************** begin payment setion
    document.writeln('<form name=\"shipping_instructions\">')
    document.writeln('<table style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#111111\" height=\"73\" cellSpacing=\"0\" cellPadding=\"3\" width=\"540\" border=\"1\">')    
    document.writeln('<td width=\"65%\" align\"left\">')
    document.writeln('</font><font size=\"2\">')            
    document.writeln('<b>Shipment Preferences:<br></font><font size=\"1\">')
    document.writeln('<input type=\"radio\" value=\"Ship\" name=\"ShipPrefer\">Ship to address below') 
    document.writeln('<input type=\"radio\" name=\"ShipPrefer\" value=\"NoShip\" checked>I will pick up order when complete</b></font>')    
    document.writeln('<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" height=\"159\">')
    document.writeln('<tr><td width=\"100%\" colspan=\"4\" height=\"29\"><font size=\"1\"><b>Ship to:</b></font></td></tr>')
    document.writeln('<tr><td width=\"25%\" height=\"22\" align=\"right\"><font size=\"1\"><b>Name:</b></font></td><td width=\"75%\" colspan=\"3\" height=\"22\"><font size=\"1\"><b><input type=\"text\" name=\"ShipToName\" value=\"\" size=\"30\"></b></font></td></tr>')
    document.writeln('<tr><td width=\"25%\" height=\"22\" align=\"right\"><font size=\"1\"><b>Company:</b></font></td><td width=\"75%\" colspan=\"3\" height=\"22\"><font size=\"1\"><b><input type=\"text\" name=\"ShipToCompany\" size=\"30\"></b></font></td></tr>')
    document.writeln('<tr><td width=\"25%\" height=\"24\" align=\"right\"><font size=\"1\"><b>Street Address: <i>(no PO Boxes)</i></b></font></td><td width=\"75%\" colspan=\"3\" height=\"24\"><font size=\"1\"><b><input type=\"text\" name=\"ShipToStreetAddress\" size=\"30\"></b></font></td></tr>')
    document.writeln('<tr><td width=\"25%\" height=\"22\" align=\"right\"><font size=\"1\"><b>City:</b></font></td><td width=\"75%\" colspan=\"3\" height=\"22\"><font size=\"1\"><b><input type=\"text\" name=\"ShipToCity\" size=\"30\"></b></font></td></tr>')
    document.writeln('<tr><td width=\"25%\" height=\"21\" align=\"right\"><font size=\"1\"><b>State:</b></font></td><td width=\"19%\" height=\"21\"><select name=\"ShipToState\">')
	document.writeln('<option value=\"AL\">AL</option><option value=\"AK\">AK</option><option value=\"AZ\">AZ</option><option value=\"AR\">AR</option><option value=\"CA\">CA</option>')
	document.writeln('<option value=\"CO\">CO</option><option value=\"CT\">CT</option><option value=\"DE\">DE</option><option value=\"DC\">DC</option><option value=\"FL\">FL</option>')
	document.writeln('<option value=\"GA\">GA</option><option value=\"HI\">HI</option><option value=\"ID\">ID</option><option value=\"IL\">IL</option><option value=\"IN\">IN</option>')
	document.writeln('<option value=\"IA\">IA</option><option value=\"KS\">KS</option><option value=\"KY\">KY</option><option value=\"LA\">LA</option><option value=\"ME\">ME</option>')
	document.writeln('<option value=\"MD\">MD</option><option value=\"MA\">MA</option><option value=\"MI\">MI</option><option value=\"MN\">MN</option><option value=\"MS\">MS</option>')
	document.writeln('<option value=\"MO\">MO</option><option value=\"MT\">MT</option><option value=\"NE\">NE</option><option value=\"NV\">NV</option><option value=\"NH\">NH</option>')
	document.writeln('<option value=\"NJ\">NJ</option><option value=\"NM\">NM</option><option value=\"NY\">NY</option><option value=\"NC\">NC</option><option value=\"ND\">ND</option>')
	document.writeln('<option value=\"OH\">OH</option><option value=\"OK\">OK</option><option value=\"OR\">OR</option><option value=\"PA\">PA</option><option value=\"RI\">RI</option>')
	document.writeln('<option value=\"SC\">SC</option><option value=\"SD\">SD</option><option value=\"TN\">TN</option><option value=\"TX\">TX</option><option value=\"UT\">UT</option>')
	document.writeln('<option value=\"VT\">VT</option><option value=\"VA\">VA</option><option value=\"WA\">WA</option><option value=\"WV\">WV</option><option value=\"WI\">WI</option><option value=\"WY\">WY</option>')
    document.writeln('</select></td><td width=\"15%\" height=\"21\" align=\"right\"><font size=\"1\"><b>Zip:</b></font></td>')
    document.writeln('<td width=\"41%\" height=\"21\"><font size=\"1\"><b><input type=\"text\" name=\"ShipToZipCode\" size=\"10\"></b></font></td></tr></table>')

    //***************
    document.writeln('</td>')
    document.writeln('&nbsp;</font></td>')
         		
    document.writeln('<td align=\"left\" width=\"35%\"><p align=\"center\"><br><font size=\"1\">')
    
    document.writeln('<p><b>Order Price:&nbsp; </b>$' + parseFloat(orderformInput.total_price_wo_ship_tax).toFixed(2)  + '<br>')
    document.writeln('<input type=\"hidden\" name=\"Order_Price\" value=\"' + parseFloat(orderformInput.total_price_wo_ship_tax).toFixed(2) +'\">')
    
	var sh = '0.00'
    document.writeln('<b>Shipping & Handling:&nbsp; </b><div id=\"shfee\">$'+sh+'</div>')
    document.writeln('<input type=\"hidden\" name=\"Ship_Fee\" value=\"' + sh +'\">')

    var totalSalePrice = parseFloat(orderformInput.total_price_wo_ship_tax)+parseFloat(sh)    
    document.writeln('<b>Total Order Price:&nbsp; </b><div id=\"total_order_price_with_shipping\">$' + totalSalePrice.toFixed(2)  + '</div>')
    document.writeln('<input type=\"hidden\" name=\"Total_Sale_Price\" value=\"' + totalSalePrice.toFixed(2) +'\">')
    
    document.writeln('<b>Shipping Weight:&nbsp; </b>' + totalOrderWeight(orderformInput).toFixed(1) + 'lbs <br>')
    document.writeln('<input type=\"hidden\" name=\"Shipping_Weight\" value=\"' + totalOrderWeight(orderformInput).toFixed(1) +'\">')
    
    var boxText = ""
    var boxIndex = selectBox(orderformInput)
    if (boxIndex < 0){
		boxText = "Multiple Boxes"
		boxCost = $10 // just add some $$ for multiple boxes
	}
	else{
		boxText = ""+ shippingBoxes[boxIndex].boxType+shippingBoxes[boxIndex].boxLength+"x"+shippingBoxes[boxIndex].boxWidth+"x"+shippingBoxes[boxIndex].boxHeight
		boxCost = shippingBoxes[boxIndex].boxPrice
		if (orderformInput.wire_stakes == "true"){
			if (boxIndex == 2)
				boxCost += shippingBoxes[5].boxPrice // add the seperator pad if needed for wire stakes (36")
			else
				boxCost += shippingBoxes[6].boxPrice // add the seperator pad if needed for wire stakes (48")
		}
		if (parseInt(orderformInput.banner_total_qty) != 0){
			boxCost += shippingBoxes[7].boxPrice  // add the cost of the 6x6x48 banner box if there are any banners
		}
	}
    document.writeln('<b>Package Size:&nbsp; </b>' + boxText + '</p>')
    document.writeln('<input type=\"hidden\" name=\"Box_Type\" value=\"' + boxText +'\">')
    
    document.writeln('<p>Promo or Coupon Code: <input type=\"text\" name=\"PromoCode\" value=\"\"></p>')
    document.writeln('<input type=\"hidden\" name=\"DiscountAmount\" value=\"0\">')
    
    document.writeln('<p> <input type=\"button\" name=\"update_shipping\" value=\"Update Price\" onclick=\"updateSH(this.form)\">&nbsp')
    document.writeln('<input type=\"button\" name=\"clear_shipping\" value=\"Clear\" onclick=\"clearShipping(this.form)\"></p>')

 
    document.writeln('&nbsp;</font></td>')     		
    document.writeln('</tr>')      
    document.writeln('</table>')
    document.writeln('<br>&nbsp')
    document.writeln('</form>')
    
    var shippingInstructions = getCookie("shipping")
    if (shippingInstructions != null){
		var shipInstruction = shippingInstructions.split("!!")
		document.shipping_instructions.ShipPrefer[parseInt(shipInstruction[0])].checked = true
		document.shipping_instructions.ShipToName.value = unescape(shipInstruction[2])
		document.shipping_instructions.ShipToCompany.value = unescape(shipInstruction[3])
		document.shipping_instructions.ShipToStreetAddress.value = unescape(shipInstruction[4])
		document.shipping_instructions.ShipToCity.value = unescape(shipInstruction[5])
		document.shipping_instructions.ShipToState.selectedIndex = parseInt(shipInstruction[6])
		document.shipping_instructions.ShipToZipCode.value = unescape(shipInstruction[8])
		
		updateSH(document.shipping_instructions)
	}
}

function clearSpecial(formObj){
	if (confirm('Are you sure that you want to delete your Special Instructions?\n\nClick \"Okay\" to clear the form or \"Cancel" to not delete it')){
		clearCookie("specialinstructions")
		clearFormData(formObj)
		return
	}
	else
		return 
}

function clearShipping(formObj){
	if (confirm('Are you sure that you want to delete all your shipping information?\n\nClick \"Okay\" to clear the form or \"Cancel" to not delete it')){
		clearCookie("shipping")
		for (var i=0; i<formObj.ShipPrefer.length; i++){
			if (formObj.ShipPrefer[i].value == "NoShip")
				formObj.ShipPrefer[i].checked = true
			else
				formObj.ShipPrefer[i].checked = false
		}
		formObj.ShipToName.value = ""
		formObj.ShipToCompany.value = ""
		formObj.ShipToStreetAddress.value = ""
		formObj.ShipToCity.value = ""
		formObj.ShipToState.selectedIndex = 0
		formObj.ShipToZipCode.value = ""
		updateSH(formObj)
		return
	}
	else
		return 
}

boxCost = 0 // global variable

//*************************************** end payment section

function getRadioValue(radioObj){
	var value = null
	for (var i=0; i<radioObj.length; i++){
		if (radioObj[i].checked){
			value = radioObj[i].value
			break
		}
	}
	return value
}

function updateSH(formObj){
	var zipcode = formObj.ShipToZipCode.value
	var zipcodeFormat = /^\d{5}(-\d{4})?\x20*$/
	var nonUS48ZipCodeFormat = /^(99[5-9])|(96[78])|(00[6-9])/
	var weight = formObj.Shipping_Weight.value
	var price = "0.00"
	if (getRadioValue(formObj.ShipPrefer) == "Ship"){
		if (!zipcodeFormat.test(zipcode)){
			alert("Invalid ZipCode")
			formObj.ShipToZipCode.focus()
			formObj.ShipToZipCode.select()
			return false
		}
		price = (parseFloat(UPSshippingCharge(weight,zipcode))+boxCost).toFixed(2)
		
		if (price.substr(0,7) == "Invalid"){
			alert("Invalid ZipCode")
			formObj.ShipToZipCode.focus()
			formObj.ShipToZipCode.select()
			return false
		}
	}
	
	formObj.Ship_Fee.value = price
	document.getElementById("shfee").firstChild.nodeValue = '$'+formObj.Ship_Fee.value
	
	// if shipping in 48 states and order is $350 or more then free shipping
	
	if (parseFloat(formObj.Order_Price.value) >= 350){
		if (!nonUS48ZipCodeFormat.test(zipcode)){
			document.getElementById("shfee").firstChild.nodeValue = 'FREE SHIPPING'
			formObj.Ship_Fee.value = "0.00"
		}
	}
		
	//***************************************************************** Promo discount code
	var discount = discountPrice(formObj)
	if (discount < 0){
		alert("Invalid or expired promotional code or coupon")
		formObj.PromoCode.focus()
		formObj.PromoCode.select()
		formObj.DiscountAmount.value = "0.00"
		formObj.Total_Sale_Price.value = (parseFloat(formObj.Order_Price.value) + parseFloat(formObj.Ship_Fee.value)).toFixed(2)
		document.getElementById("total_order_price_with_shipping").firstChild.nodeValue = '$'+ formObj.Total_Sale_Price.value
	}
	else if (discount==0){
		formObj.DiscountAmount.value = "0.00"
		formObj.Total_Sale_Price.value = (parseFloat(formObj.Order_Price.value) + parseFloat(formObj.Ship_Fee.value)).toFixed(2)
		document.getElementById("total_order_price_with_shipping").firstChild.nodeValue = '$'+ formObj.Total_Sale_Price.value
	}
	else{
		formObj.DiscountAmount.value = discount.toFixed(2)
		formObj.Total_Sale_Price.value = (parseFloat(formObj.Order_Price.value) + parseFloat(formObj.Ship_Fee.value) - discount).toFixed(2)
		document.getElementById("total_order_price_with_shipping").firstChild.nodeValue = '$'+ formObj.Total_Sale_Price.value + ' (including discounts)'

	}
	//*****************************************************************
	//alert(zipcode+" "+weight+" "+formObj.Ship_Fee.value+" "+formObj.Total_Sale_Price.value)
	return true
}

function buildSSLineItem(signType, qtyLarge, qtySmall, bgTemplate, signTypeIndex){
	
	var savedSponsorNames = new Array()
	
	if ((qtyLarge + qtySmall) == 0) return 0
	 
	document.writeln('<tr>')
	document.writeln('<td width=\"15%\" height=\"18\" align=\"center\"><font size=\"1\">' + signType + '</font></td>')
        
    if ((qtyLarge != 0)&&(qtySmall==0)){
		document.writeln('<td width=\"5%\" height=\"18\" align=\"center\"><font size=\"1\">' + qtyLarge + '</font></td>')
		}
	else if ((qtyLarge == 0)&&(qtySmall != 0)){
			document.writeln('<td width=\"5%\" height=\"18\" align=\"center\"><font size=\"1\">' + qtySmall + '</font></td>')
			}
	else {
		document.writeln('<td width=\"5%\" height=\"18\" align=\"center\"><font size=\"1\">' + qtyLarge + '<br>' + qtySmall + '</font></td>')
		}	
				
    if ((qtyLarge != 0)&&(qtySmall==0))
		{document.writeln('<td width=\"7%\" height=\"18\" align=\"center\"><font size=\"1\">18x24</font></td>')}
	else if ((qtyLarge == 0)&&(qtySmall != 0))
		{document.writeln('<td width=\"7%\" height=\"18\" align=\"center\"><font size=\"1\">12x18</font></td>')}
	else
		{document.writeln('<td width=\"7%\" height=\"18\" align=\"center\"><font size=\"1\">18x24<br>12x18</font></td>')}
			
    document.write('<td width=\"12%\" height=\"18\" align=\"center\"><font size=\"1\">')
    document.write(bgTemplate.split('/')[1].split('.')[0])
    document.writeln('</font></td>')
        
    var signCopyCookie = getCookie("signcopy")
    
	if (signCopyCookie != null){
		savedSponsorNames = signCopyCookie.split("!!")[1].split("^")[signTypeIndex].split(":")				// gets array of saved field data values
	}	
																										
    document.write('<td width=\"61%\" height=\"18\" align=\"left\"><font size=\"1\">')
    
	var tripleZero = /000/	
	if (tripleZero.test(bgTemplate))	signTypeIndex=-1	// if the customer selected the "Upload" template then force the signtype to -1

    // check for "sponsor" signs that have text areas (eg: Blank Custom Sign) or that are to be uploaded designs.
    switch(signTypeIndex){
		case -1: // in this case the sign template was one that requires the customer to upload the design ... so there are no sponsor names or text to display
			var numberOfFiles = qtyLarge+qtySmall
			document.writeln('<font color=\"#000000\" size=\"1\">Customer to upload <b>' + numberOfFiles + '</b> design files after order has been submitted.')
			document.writeln('<br></font>')
			break
		case 15: // in this case "savedSponsorNames" is actually "savedTextAreas" ... sorry for the confusion
			document.writeln('<font size = \"1\"><i><b>PLEASE NOTE: </b>All your line spacing text formatting has been removed to save display space, but it will be included in the information sent to our production staff.</i></font><br>') 
			document.write('<hr />')
			for (var i=0; i<savedSponsorNames.length-1; i++){
				document.write(unescape(savedSponsorNames[i]) + '<hr />')
				}
			document.writeln(unescape(savedSponsorNames[i]))
			break
		default:			
			for (var i=0; i<savedSponsorNames.length-1; i++){
				document.write(unescape(savedSponsorNames[i]) + '<br>')
				}
			document.writeln(unescape(savedSponsorNames[i]))
			break
		}
			
	document.writeln('</font></td>')
    document.writeln('</tr>')
    
    return (qtyLarge+qtySmall)
}
	
function buildTSLineItem(signType, qty, signSize, bgTemplate, signTypeIndex){
	
	var savedTextAreas = new Array()

	if (qty == 0) return 0
	 
	document.writeln('<tr>')
	document.writeln('<td width=\"15%\" height=\"18\" align=\"center\"><font size=\"1\">' + signType + '</font></td>')
        
	document.writeln('<td width=\"5%\" height=\"18\" align=\"center\"><font size=\"1\">' + qty + '</font></td>')
	
	var	actualSize = ""
	var actualPrice = 0
	
	
	switch (signTypeIndex){
		case 16:
		case 17:
		case 18:
			switch (signSize){
				case "0":	actualSize = "4x15";	actualPrice = 180;	break
				case "1":	actualSize = "4x12";	actualPrice = 150;	break
				case "2":	actualSize = "3x10";	actualPrice = 90;	break
				case "3":	actualSize = "3x8";		actualPrice = 75;	break
				case "4":	actualSize = "3x6";		actualPrice = 60;	break
				case "5":	actualSize = "2x6";		actualPrice = 50;	break
				default:	actualSize = "?";		actualPrice = 0;	break
			}
			break
		case 19:	actualSize = "2x4";	actualPrice = 45; break
		case 20:
			switch (signSize){
				case "0":	actualSize = "3x2";		actualPrice = 45;	break
				case "1":	actualSize = "3x2";		actualPrice = 45;	break
				default:	actualSize = "??";		actualPrice = 0;	break
			}
			break
		default:	actualSize = "???"; actualPrice="0"; break
		}			
				
	document.writeln('<td width=\"7%\" height=\"18\" align=\"center\"><font size=\"1\">' + actualSize + '</font></td>')
	
			
    document.write('<td width=\"12%\" height=\"18\" align=\"center\"><font size=\"1\">')
    document.write(bgTemplate.split('/')[1].split('.')[0])
    document.writeln('</font></td>')
        
    var signCopyCookie = getCookie("signcopy")
    
	if (signCopyCookie != null){
		savedTextAreas = signCopyCookie.split("!!")[1].split("^")[signTypeIndex].split(":")				// gets array of saved field data values
	}	
	
	document.write('<td width=\"61%\" height=\"18\" align=\"left\">')

	var standardSign = true																								
	var tripleZero = /000/	
	if (tripleZero.test(bgTemplate))	standardSign = false	// if the customer selected the "Upload" template then set flag to false
	if (standardSign){
		document.writeln('<font size = \"1\"><i><b>PLEASE NOTE: </b>All your line spacing text formatting has been removed to save display space, but it will be included in the information sent to our production staff.</i></font><br>') 
		document.writeln('<font size=\"1\"><hr />')			
		for (var i=0; i<savedTextAreas.length-1; i++){
			document.write(unescape(savedTextAreas[i]) + '<hr />')
			}
		document.writeln(unescape(savedTextAreas[i]))
		document.writeln('</font></td>')
	}
	else{
		var numberOfFiles = qty
		document.writeln('<font color=\"#000000\" size=\"1\">Customer to upload <b>' + numberOfFiles + '</b> design files after order has been submitted.')
		document.writeln('<br></font></td>')
	}
		
	//var lineItemPrice = qty * actualPrice
  
    //document.writeln('<td width=\"11%\" height=\"18\" align=\"center\"><font size=\"1\">$'+ lineItemPrice.toFixed(2) + '</font></td>')
    document.writeln('</tr>')
    
    return (qty)
}

//
//End of order confirmation page code
//*****************************************************************************************

//******************************************************************************
// Start of code to build the transmit form (page)
//

function buildOrderTransmitPage(){

	if (reconstructOrderform(orderformInput) == null){
		alert("Order form was blank or no cookie was saved.  Please enter a new order and make sure that your cookies are enabled")
		return
	}
	var item_number = unescape(getCookie("itemnumber"))
	
	//******************************************* hidden info for form mailer
	document.writeln('<form name=\"transmit_order\" method=post action=\"sendorder.php\">')
	document.writeln('<input type=hidden name=\"subject\" value=\"Tournament Sign Order - ' + item_number + '\">')
	document.writeln('<input type=hidden name=\"email\" value=\"' + orderformInput.contact_email + '\">')
	document.writeln('<input type=hidden name=\"env_report\" value=\"REMOTE_HOST, HTTP_USER_AGENT\">')
	
	//******************************************* start general tournament and contact info section
    document.writeln('<input type=\"hidden\" name=\"TournamentName\" value=\"' + orderformInput.tournament_name +'\">')
    document.writeln('<input type=\"hidden\" name=\"TournamentLocation\" value=\"' + orderformInput.tournament_location + '\">')
    document.writeln('<input type=\"hidden\" name=\"TournamentDate\" value=\"' + orderformInput.tournament_date + '\">')
    document.writeln('<input type=\"hidden\" name=\"SignsRequiredBy\" value=\"' + orderformInput.signs_required_by + '\">')
    document.writeln('<input type=\"hidden\" name=\"ContactName\" value=\"' + orderformInput.contact_name + '\">')
    document.writeln('<input type=\"hidden\" name=\"ContactPhone\" value=\"' + orderformInput.contact_phone + '\">')
    document.writeln('<input type=\"hidden\" name=\"ContactEmail\" value=\"' + orderformInput.contact_email +'\">')    
  
    if (orderformInput.wire_stakes == "true"){
		document.writeln('<input type=\"hidden\" name=\"\nLarge Wire Stakes Qty\" value=\"' + orderformInput.large_sign_total_qty +'\">')
		document.writeln('<input type=\"hidden\" name=\"Small Wire Stakes Qty\" value=\"' + orderformInput.small_sign_total_qty +'\">')
	}
    if (orderformInput.email_proof == "true")
    	document.writeln('<input type=\"hidden\" name=\"\nE-mail Proof\" value=\"YES\">')
    else
    	document.writeln('<input type=\"hidden\" name=\"\nE-mail Proof\" value=\"NO\">')		 	
    
	if (orderformInput.rush =="true")
		 document.writeln('<input type=\"hidden\" name=\"Rush Order\" value=\"YES\">')
	else
	 	document.writeln('<input type=\"hidden\" name=\"Rush Order\" value=\"NO\">')    
	//************************************************** end general tournament and contact section
	
	//************************************************** start sign type section
	buildSSOrderItem("Hole Sponsor", getQty(orderformInput.hole_large_qty), getQty(orderformInput.hole_small_qty), orderformInput.hole_template, 0)	
	buildSSOrderItem("HIO Sponsor", getQty(orderformInput.hio_large_qty), getQty(orderformInput.hio_small_qty), orderformInput.hio_template, 1)	
	buildSSOrderItem("KP Sponsor", getQty(orderformInput.kp_large_qty), getQty(orderformInput.kp_small_qty), orderformInput.kp_template, 2)	
	buildSSOrderItem("LD Sponsor", getQty(orderformInput.ld_large_qty), getQty(orderformInput.ld_small_qty), orderformInput.ld_template, 3)	
	buildSSOrderItem("SD Sponsor", getQty(orderformInput.sd_large_qty), getQty(orderformInput.sd_small_qty), orderformInput.sd_template, 4)	
	buildSSOrderItem("Mulligan Sponsor", getQty(orderformInput.mulligan_large_qty), getQty(orderformInput.mulligan_small_qty), orderformInput.mulligan_template, 5)	
	buildSSOrderItem("Putt Sponsor", getQty(orderformInput.putt_large_qty), getQty(orderformInput.putt_small_qty), orderformInput.putt_template, 6)	
	buildSSOrderItem("Chip Sponsor", getQty(orderformInput.chip_large_qty), getQty(orderformInput.chip_small_qty), orderformInput.chip_template, 7)	
	buildSSOrderItem("Registration Sponsor", getQty(orderformInput.registration_large_qty), getQty(orderformInput.registration_small_qty), orderformInput.registration_template, 8)	
	buildSSOrderItem("Cart Sponsor", getQty(orderformInput.cart_large_qty), getQty(orderformInput.cart_small_qty), orderformInput.cart_template, 9)	
	buildSSOrderItem("Beverage Sponsor", getQty(orderformInput.beverage_large_qty), getQty(orderformInput.beverage_small_qty), orderformInput.beverage_template, 10)	
	buildSSOrderItem("Breakfast Sponor", getQty(orderformInput.breakfast_large_qty), getQty(orderformInput.breakfast_small_qty), orderformInput.breakfast_template, 11)	
	buildSSOrderItem("Lunch Sponsor", getQty(orderformInput.lunch_large_qty), getQty(orderformInput.lunch_small_qty), orderformInput.lunch_template, 12)	
	buildSSOrderItem("Dinner Sponsor", getQty(orderformInput.dinner_large_qty), getQty(orderformInput.dinner_small_qty), orderformInput.dinner_template, 13)	
	buildSSOrderItem("Cocktail Sponsor", getQty(orderformInput.cocktails_large_qty), getQty(orderformInput.cocktails_small_qty), orderformInput.cocktails_template, 14)
	buildSSOrderItem("Custom Sign", getQty(orderformInput.blank_large_qty), getQty(orderformInput.blank_small_qty), orderformInput.blank_template, 15)
		
  	buildTSOrderItem("Event Banner", getQty(orderformInput.banner_event_qty), orderformInput.banner_event_size, orderformInput.event_banner_template, 16)	
  	buildTSOrderItem("Premier Banner", getQty(orderformInput.banner_premier_sponsor_qty), orderformInput.banner_premier_sponsor_size, orderformInput.premier_banner_template, 17)	
  	buildTSOrderItem("Sponsor Banner", getQty(orderformInput.banner_sponsor_qty), orderformInput.banner_sponsor_size, orderformInput.sponsor_banner_template, 18)
  		
  	buildTSOrderItem("Award Check", getQty(orderformInput.award_check_qty), "0", orderformInput.award_check_template, 19)	
  	buildTSOrderItem("Event Schedule", getQty(orderformInput.event_schedule_qty), orderformInput.event_schedule_size, orderformInput.event_schedule_template, 20)	
    
    //*************************************** end of sign type setion
    
    //*************************************** begin special instructions section    
    var special = getCookie("specialinstructions")
    
	if (special != null){
		document.writeln('<input type=hidden name=\"\nSpecial_Instructions\" value=\"\n**** BEGIN COPY ****\n' + unescape(special) + '\n**** END COPY ****\">')
	}    
    //*************************************** end special instructions section

    //*************************************** begin payment setion
    
    var shipping = getCookie("shipping")
    var ship = shipping.split("!!")
    if (ship[1] == "Ship"){
		document.writeln('<input type=hidden name=\"\nShipping\" value=\"YES\">')
		document.writeln('<input type=hidden name=\"ShipToName\" value=\"'+ unescape(ship[2]) +'\">')
		document.writeln('<input type=hidden name=\"ShipToCompany\" value=\"'+ unescape(ship[3]) +'\">')
		document.writeln('<input type=hidden name=\"ShipToAddress\" value=\"'+ unescape(ship[4]) +'\">')
		document.writeln('<input type=hidden name=\"ShipToCity\" value=\"'+ unescape(ship[5]) +'\">')
		document.writeln('<input type=hidden name=\"ShipToState\" value=\"'+ unescape(ship[7]) +'\">')
		document.writeln('<input type=hidden name=\"ShipToZip\" value=\"'+ unescape(ship[8]) +'\">')
		document.writeln('<input type=hidden name=\"ShipWeight\" value=\"'+ unescape(ship[10]) +'\">')
		document.writeln('<input type=hidden name=\"ShipBoxType\" value=\"'+ unescape(ship[11]) +'\">')
		document.writeln('<input type=hidden name=\"ShipFee\" value=\"'+ parseFloat(unescape(ship[9])).toFixed(2) +'\">')		
    }
    else{
		document.writeln('<input type=hidden name=\"\nShipping:\" value=\"NO\">')
    }
    var promo = unescape(ship[12])
	if (promo != ""){
		document.writeln('<input type=hidden name=\"\nPromoCode\" value=\"'+ promo +'\">')
		document.writeln('<input type=hidden name=\"\DiscountAmount\" value=\"'+ parseFloat(unescape(ship[13])).toFixed(2) +'\">')
	}
	
	var referLink = getCookie("refer")
	var origLink = getCookie("orig")
	
	if (origLink != null) document.writeln('<input type=hidden name=\"\nCustomerOrigin\" value=\"'+ unescape(origLink) +'\">')
	if (referLink != null) document.writeln('<input type=hidden name=\"\nReferralSite\" value=\"'+ unescape(referLink) +'\">')
	
	var salesman = getCookie("S")
	if (salesman != null) document.writeln('<input type=hidden name=\"\nSalesman\" value=\"'+ salesman +'\">')
	
	var referrerCode = getCookie("R")
	if (referrerCode != null) document.writeln('<input type=hidden name=\"\nReferrer Code\" value=\"'+ referrerCode +'\">')
	
	document.writeln('<input type=hidden name=\"\nCookie Data\" value=\"'+ document.cookie +'\">')		
	

    //*************************************** end payment section
    
    document.writeln('</form>')

}

function buildSSOrderItem(signType, qtyLarge, qtySmall, bgTemplate, signTypeIndex){
	
	var savedSponsorNames = new Array()
	
	if ((qtyLarge + qtySmall) == 0) return 0
	 
    if ((qtyLarge != 0)&&(qtySmall==0)){
		document.writeln('<input type=hidden name=\"\n' + signType + ' Size:18x24 Qty\" value=\"' + qtyLarge +'\">')
		}
	else if ((qtyLarge == 0)&&(qtySmall != 0)){
			document.writeln('<input type=hidden name=\"\n' + signType + ' Size:12x18 Qty\" value=\"' + qtySmall +'\">')
			}
	else {
		document.writeln('<input type=hidden name=\"\n' + signType + ' Size:18x24 Qty\" value=\"' + qtyLarge +'\">')
		document.writeln('<input type=hidden name=\"' + signType + ' Size:12x18 Qty\" value=\"' + qtySmall +'\">')
		}	
				
    document.writeln('<input type=hidden name=\"' + signType + ' Template\" value=\"' + bgTemplate.split('/')[1].split('.')[0] + '\">')
        
    var signCopyCookie = getCookie("signcopy")
    
	if (signCopyCookie != null){
		savedSponsorNames = signCopyCookie.split("!!")[1].split("^")[signTypeIndex].split(":")				// gets array of saved field data values
	}	
	var standardSign = true																								
	var tripleZero = /000/	
	if (tripleZero.test(bgTemplate))	standardSign = false	// if the customer selected the "Upload" template then set flag to false
	if (standardSign){
		// check for "sponsor" signs that have text areas (eg: Blank Custom Sign)
		switch(signTypeIndex){
			case 15: // in this case "savedSponsorNames" is actually "savedTextAreas" ... sorry for the confusion
				for (var i=0; i<savedSponsorNames.length-1; i++){
					document.writeln('<input type=hidden name=\"' + signType + ' #' + (i+1) + '\" value=\"\n**** BEGIN COPY ****\n' + unescape(savedSponsorNames[i]) + '\n**** END COPY ****\">')
					}
				break
			default:			
				for (var i=0; i<savedSponsorNames.length-1; i++){
					document.writeln('<input type=hidden name=\"' + signType + ' #' + (i+1) + '\" value=\"' + unescape(savedSponsorNames[i]) + '\">')
					}
				break
			}
	}	
    return (qtyLarge+qtySmall)
}
	
function buildTSOrderItem(signType, qty, signSize, bgTemplate, signTypeIndex){
	
	var savedTextAreas = new Array()

	if (qty == 0) return 0
	 
	var	actualSize = ""
	var actualPrice = 0
	
	
	switch (signTypeIndex){
		case 16:
		case 17:
		case 18:
			switch (signSize){
				case "0":	actualSize = "4x15";	actualPrice = 180;	break
				case "1":	actualSize = "4x12";	actualPrice = 150;	break
				case "2":	actualSize = "3x10";	actualPrice = 90;	break
				case "3":	actualSize = "3x8";		actualPrice = 75;	break
				case "4":	actualSize = "3x6";		actualPrice = 60;	break
				case "5":	actualSize = "2x6";		actualPrice = 50;	break
				default:	actualSize = "?";		actualPrice = 0;	break
			}
			break
		case 19:	actualSize = "2x4";	actualPrice = 45; break
		case 20:
			switch (signSize){
				case "0":	actualSize = "4x2";		actualPrice = 45;	break
				case "1":	actualSize = "3x2";		actualPrice = 45;	break
				default:	actualSize = "??";		actualPrice = 0;	break
			}
			break
		default:	actualSize = "???"; actualPrice="0"; break
		}			
				
	document.writeln('<input type=hidden name=\"\n' + signType + ' Size:' + actualSize + ' Qty\" value=\"' + qty +'\">')
			
    document.writeln('<input type=hidden name=\"' + signType + ' Template\" value=\"' + bgTemplate.split('/')[1].split('.')[0] + '\">')
        
    var signCopyCookie = getCookie("signcopy")
    
	if (signCopyCookie != null){
		savedTextAreas = signCopyCookie.split("!!")[1].split("^")[signTypeIndex].split(":")				// gets array of saved field data values
	}
		
	var standardSign = true																								
	var tripleZero = /000/	
	if (tripleZero.test(bgTemplate))	standardSign = false	// if the customer selected the "Upload" template then set flag to false
	if (standardSign){
		for (var i=0; i<savedTextAreas.length-1; i++){
			document.writeln('<input type=hidden name=\"' + signType + ' #' + (i+1) + '\" value=\"\n**** BEGIN COPY ****\n' + unescape(savedTextAreas[i]) + '\n**** END COPY ****\">')
			}
    }
    return (qty)
}

//*****************  End of section that transmit the order

//***************************************************************************************************************************
//The following code is used to create the dynamic portions of the Order Form and is shared on other pages
//

function stopRKey(evt) { 
	var evt = (evt) ? evt : ((event) ? event : null); 
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text"))
		{return false;}
}

document.onkeypress = stopRKey;

function isInt(textObj) {
	var newValue = textObj.value
	var newLength = newValue.length
	for (var i = 0; i != newLength; i++) {
		aChar = newValue.substring(i,i+1)
		if (aChar < "0" || aChar > "9")
			return false
	}
		return true
}

	
function validDate(str) {
	var dateFormat = /^\d{1,2}[\/]\d{1,2}[\/]\d{2,4}/;
	if (!dateFormat.test(str)){
		return(false)
	}
	else {
		return(true)
	}
}

function dayToDays(inTime) {
	return (inTime.getTime()/(1000*60*60*24))
}

function daysTill(inDate) {
	var now = new Date()
	return (Math.round(dayToDays(inDate) - dayToDays(now)))
}

function checkDate(dateObj){
	var today = new Date()				
	if ((dateObj.value != "")&&(!validDate(dateObj.value)))		// check for valid format	
		{	// start of invalid date format handler
		alert("Please enter the date in the format mm/dd/yyyy.  Thank you!")
		//*dateObj.value = ""
		dateObj.focus()
		dateObj.select()
		return (-1)
		} 	// end of invalid date format handler
		
	else
		{	// start of valid date format handler
		
		if (dateObj.value != "") 	// check if date string is null
			{	// start of date string  is not null
			
			var year = dateObj.value.split("/")[2]
			if (year.length == 2){
				var newDateString = ""+dateObj.value.split("/")[0]+"/"+dateObj.value.split("/")[1]+"/20"+dateObj.value.split("/")[2]
				dateObj.value = newDateString
			}
			
			enteredDate = new Date(dateObj.value)
			
			if (enteredDate <= today)	// check if date entered has already passed (or is today)
				{	// start of date is in the past
				alert("The date you entered has already occurred.  You must enter a date after today's date")
				//*dateObj.value = ""
				dateObj.focus()
				dateObj.select()
				return (-1)
				}	// end of date is in the past
				
			else
				{	// start of date is not in the past
				return (daysTill(enteredDate))
				}	// end of date is not in the past
			}	// end of date string is not null
			
		else
			// date string is null
			return (-1)
					
		}	// end of valid date format handler
		
}	// end of function
	
function isNotNull(str) {
	if (str.length > 0 )
		return(true)
	else
		return(false)
}

function leadTime(dateObj){
	if (checkDate(dateObj) < 0)
		return
	else if (checkDate(dateObj) < standardProductionDays)
		{
		alert ("You have requested a date that is less than our "+standardProductionDays+" day\nStandard Production Lead Time.\n\nYou will be charged a production rush fee on this order\nand if we are shipping this order, there may be additional\nexpedited shipping fees applied based on the standard delivery\ntimes needed for your location.\n\nYou will be billed seperately for any added shipping costs\nprior to the order being shipped.")
		document.sign_order_form.rush.checked = true
		updateTotals(document.sign_order_form)
		return
		}
		document.sign_order_form.rush.checked = false
		updateTotals(document.sign_order_form)
	return
}

/*function validateEmail(emailObj){
	var	emailFormat = /^\w{1,}([!#$%&*+-_.]*\w*)*[^.]@(\w{1,}[-_]?){1,}(\.{1}(\w{1,}[-]?){1,})*\.(COM|NET|GOV|ORG|BIZ|EDU|MIL|CA|US)$/;
	if ((emailObj.value != "")&&(emailFormat.test(emailObj.value.toUpperCase()))) 
		return true
	else
		if (emailObj.value != ""){
			alert("The email address that you entered appears to be incorrect.  Please enter a correct email address")
			emailObj.focus()
			emailObj.select()
			return false
		}
		else
			return (-1)
}*/

function validateEmail(emailObj){
	if ((emailObj.value != "")&&(emailCheck(emailObj.value))) 
		return true
	else
		if (emailObj.value != ""){
//			alert("The email address that you entered appears to be incorrect.  Please enter a correct email address")
			emailObj.focus()
			emailObj.select()
			return false
		}
		else
			return (-1)
}


function emailCheck (emailStr) {

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
	return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid

	alert("The username doesn't seem to be valid.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	alert("This address is missing a hostname!");
	return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
	}

function validatePhone(phoneObj){
	var phoneFormat = /^\(?\d\d\d\)?[-. ]{1}\d\d\d[-. ]{1}\d\d\d\d$/
	if (((phoneObj.value) != "")&&(phoneFormat.test(phoneObj.value)))
		return true
	else
		if (phoneObj.value != ""){
			alert("The phone number that you entered appears to be incorrect.  Please re-enter.  Thank you!")
			phoneObj.focus()
			phoneObj.select()
			return false
		}
		else
			return (-1)
}

function validateQty(qtyObj) {

	if (isInt(qtyObj)) 		
		if (qtyObj.value>50) {			
			alert("You must enter a number between 0 and 50 in this field (or you may leave it blank)")
			qtyObj.value = ""
			qtyObj.focus()
			qtyObj.select()
			return
		}		
		else if (qtyObj.value == 0) {
				qtyObj.value = ""
				updateTotals(document.sign_order_form)
				return
				}		
			else {				 
				updateTotals(document.sign_order_form)
				return
			}
	else {
		alert("You must enter a number between 0 and 100 in this field (or you may leave it blank)")
		qtyObj.value = ""
		qtyObj.focus()
		qtyObj.select()
		return
	}
}

function sign(qty,totalPrice){
	this.qty = qty
	this.totalPrice = totalPrice
}

function getQty (qtyObj) {
	var qty
	
	if (qtyObj == "")
		return(0)
	else {
		qty = parseInt(qtyObj)
		if (qty == "NaN")
			return(0)
		else
			return(qty)
		}
}

function getBannerPrice(selObj){
	var bannerSize = /^\d*[xX]\d*/
	var bannerPrice = /\d*[.]?\d*$/
	return(bannerPrice.exec(selObj))
}

function getSelectValue(selectObject) {
	return selectObject.options[selectObject.selectedIndex].text
}

function updateSummaryQty(fieldId,qty) {
	document.getElementById(fieldId).firstChild.nodeValue = qty
	if (qty != 0)
		document.getElementById(fieldId).style.visibility = "visible"
	else
		document.getElementById(fieldId).style.visibility = "hidden"
}

function updateSummaryPrice(fieldId,qty) {
	document.getElementById(fieldId).firstChild.nodeValue = "$"+qty.toFixed(2)
	if (qty != 0)
		document.getElementById(fieldId).style.visibility = "visible"
	else
		document.getElementById(fieldId).style.visibility = "hidden"
}

function showBackgroundSelection(fieldId) {
	document.getElementById(fieldId).style.visibility = "visible"
}

function hideBackgroundSelection(fieldId) {
	document.getElementById(fieldId).style.visibility = "hidden"
}

function displayHide(qty1, qty2, fieldId) {
	if ((qty1 == "") && (qty2 == ""))
		hideBackgroundSelection(fieldId)
	else
		showBackgroundSelection(fieldId)
}

function updateBackgroundSelection(imageName,templateName) {
	
	if (document.getElementsByName(templateName)[0].value == ""){
		document.getElementsByName(imageName)[0].src = "/images/sponsor_no_background_selected.jpg"
	}
	else {
		document.getElementsByName(imageName)[0].src = document.getElementsByName(templateName)[0].value
	}
}

function resetForm(formObj){
	if (confirm("WARNING! - Are you sure that you want to reset the form.  All saved values will be lost.  This action is not reversable.")) {
		clearFormData(formObj)
		highlight("tournamentName",false)
		highlight("tournamentDate", false)
		highlight("tournamentLoc", false)
		highlight("signNeedDate", false)
		highlight("contactName", false)
		highlight("contactPhone", false)
		highlight("contactEmail", false)
		highlight("hole", false)
		highlight("hio", false)
		highlight("kp", false)
		highlight("ld", false)
		highlight("sd", false)
		highlight("mul", false)
		highlight("putt", false)
		highlight("chip", false)
		highlight("reg", false)
		highlight("cart", false)
		highlight("bev", false)
		highlight("break", false)
		highlight("lunch", false)
		highlight("din", false)
		highlight("cock", false)
		highlight("event", false)
		highlight("premier", false)
		highlight("banner", false)
		highlight("check", false)
		highlight("sched", false)
		updateTotals(formObj)
		clearCookie("orderform")
		clearCookie("signcopy")
		clearCookie("specialinstructions")
		clearCookie("shipping")
		clearCookie("itemnumber")
	}
}

function displayBackgroundSelections(formObj) {
	updateBackgroundSelection("hole_background", "hole_template")
	updateBackgroundSelection("hio_background", "hio_template")
	updateBackgroundSelection("kp_background", "kp_template")
	updateBackgroundSelection("ld_background", "ld_template")
	updateBackgroundSelection("sd_background", "sd_template")
	updateBackgroundSelection("mulligan_background", "mulligan_template")
	updateBackgroundSelection("putt_background", "putt_template")
	updateBackgroundSelection("chip_background", "chip_template")
	updateBackgroundSelection("registration_background", "registration_template")
	updateBackgroundSelection("cart_background", "cart_template")
	updateBackgroundSelection("beverage_background", "beverage_template")
	updateBackgroundSelection("breakfast_background", "breakfast_template")
	updateBackgroundSelection("lunch_background", "lunch_template")
	updateBackgroundSelection("dinner_background", "dinner_template")
	updateBackgroundSelection("cocktails_background", "cocktails_template")
	updateBackgroundSelection("blank_background", "blank_template")
	updateBackgroundSelection("award_check_background", "award_check_template")
	updateBackgroundSelection("event_banner_background", "event_banner_template")
	updateBackgroundSelection("premier_banner_background", "premier_banner_template")
	updateBackgroundSelection("sponsor_banner_background", "sponsor_banner_template")
	updateBackgroundSelection("event_schedule_background", "event_schedule_template")
	
	displayHide(formObj.hole_large_qty.value, formObj.hole_small_qty.value, "holeSponsorImage")	
	displayHide(formObj.registration_large_qty.value, formObj.registration_small_qty.value, "registrationSponsorImage")
	displayHide(formObj.mulligan_large_qty.value, formObj.mulligan_small_qty.value, "mulliganSponsorImage")
	displayHide(formObj.cart_large_qty.value, formObj.cart_small_qty.value, "cartSponsorImage")
	displayHide(formObj.beverage_large_qty.value, formObj.beverage_small_qty.value, "beverageSponsorImage")
	displayHide(formObj.breakfast_large_qty.value, formObj.breakfast_small_qty.value, "breakfastSponsorImage")
	displayHide(formObj.lunch_large_qty.value, formObj.lunch_small_qty.value, "lunchSponsorImage")
	displayHide(formObj.dinner_large_qty.value, formObj.dinner_small_qty.value, "dinnerSponsorImage")
	displayHide(formObj.cocktails_large_qty.value, formObj.cocktails_small_qty.value, "cocktailsSponsorImage")
	displayHide(formObj.hio_large_qty.value, formObj.hio_small_qty.value, "hioSponsorImage")
	displayHide(formObj.kp_large_qty.value, formObj.kp_small_qty.value, "kpSponsorImage")
	displayHide(formObj.ld_large_qty.value, formObj.ld_small_qty.value, "ldSponsorImage")
	displayHide(formObj.sd_large_qty.value, formObj.sd_small_qty.value, "sdSponsorImage")
	displayHide(formObj.putt_large_qty.value, formObj.putt_small_qty.value, "puttSponsorImage")
	displayHide(formObj.chip_large_qty.value, formObj.chip_small_qty.value, "chipSponsorImage")
	displayHide(formObj.blank_large_qty.value, formObj.blank_small_qty.value, "blankSponsorImage")
	displayHide(formObj.banner_event_qty.value, "", "bannerEventSponsorImage")
	displayHide(formObj.banner_premier_sponsor_qty.value, "", "bannerPremierSponsorImage")
	displayHide(formObj.banner_sponsor_qty.value, "", "bannerSponsorImage")
	displayHide(formObj.award_check_qty.value, "", "awardCheckImage")
	displayHide(formObj.event_schedule_qty.value, "", "eventScheduleImage")
}

function updateSummaryInfo(formObj) {		
	updateSummaryQty("largeSignTotalQty", parseInt(formObj.large_sign_total_qty.value))
	updateSummaryQty("smallSignTotalQty", parseInt(formObj.small_sign_total_qty.value))
	updateSummaryQty("bannerTotalQty", parseInt(formObj.banner_total_qty.value))
	updateSummaryQty("awardCheckTotalQty", parseInt(formObj.award_check_total_qty.value))
	updateSummaryQty("eventSignTotalQty", parseInt(formObj.event_sign_total_qty.value))
	updateSummaryPrice("artFee",parseFloat(formObj.art_fee.value))
	updateSummaryPrice("proofFee",parseFloat(formObj.proof_fee.value))
	updateSummaryPrice("stakesFee",parseFloat(formObj.stakes_fee.value))
	updateSummaryPrice("rushFee",parseFloat(formObj.rush_fee.value))
	updateSummaryPrice("otherFeesSubtotal",parseFloat(formObj.other_fees_subtotal.value))	
	updateSummaryPrice("largeSignTotalPrice", parseFloat(formObj.large_sign_total_price.value))
	updateSummaryPrice("smallSignTotalPrice", parseFloat(formObj.small_sign_total_price.value))
	updateSummaryPrice("bannerTotalPrice", parseFloat(formObj.banner_total_price.value))
	updateSummaryPrice("awardCheckTotalPrice", parseFloat(formObj.award_check_total_price.value))
	updateSummaryPrice("eventSignTotalPrice", parseFloat(formObj.event_sign_total_price.value))
	updateSummaryPrice("subTotalPrice", parseFloat(formObj.subtotal_price.value))
	updateSummaryPrice("otherTotalPrice", parseFloat(formObj.other_total_price.value))
	updateSummaryPrice("packageDiscount",parseFloat(formObj.package_discount.value))
	updateSummaryPrice("totalPriceWOShipTax",parseFloat(formObj.total_price_wo_ship_tax.value))
}
	
function updateTotals(formObj) {
	var signPrice
	var bannerQtyTemp
	var temp
	var subtotalTemp = 0  // Initialize the subtotal
	var subtotalSignsTemp = 0 	
	var largeSigns = new sign(0,0)
	var smallSigns = new sign(0,0)
	var banners = new sign(0,0)
	var awardCheck = new sign(0,0)
	var eventSigns = new sign(0,0)
	
	/***** Calculate the total number of large signs ordered *****/
	largeSigns.qty += getQty(formObj.hole_large_qty.value)
	largeSigns.qty += getQty(formObj.registration_large_qty.value)
	largeSigns.qty += getQty(formObj.mulligan_large_qty.value)
	largeSigns.qty += getQty(formObj.cart_large_qty.value)
	largeSigns.qty += getQty(formObj.beverage_large_qty.value)
	largeSigns.qty += getQty(formObj.breakfast_large_qty.value)
	largeSigns.qty += getQty(formObj.lunch_large_qty.value)
	largeSigns.qty += getQty(formObj.dinner_large_qty.value)
	largeSigns.qty += getQty(formObj.cocktails_large_qty.value)
	largeSigns.qty += getQty(formObj.hio_large_qty.value)
	largeSigns.qty += getQty(formObj.kp_large_qty.value)
	largeSigns.qty += getQty(formObj.ld_large_qty.value)
	largeSigns.qty += getQty(formObj.sd_large_qty.value)
	largeSigns.qty += getQty(formObj.putt_large_qty.value)
	largeSigns.qty += getQty(formObj.chip_large_qty.value)
	largeSigns.qty += getQty(formObj.blank_large_qty.value)
	
	formObj.large_sign_total_qty.value = ""+largeSigns.qty  // update hidden form field
	
	/***** Calculate the total non-discounted price for the large signs *****/
			
	largeSigns.totalPrice = largeSigns.qty * 18.00
	
	formObj.large_sign_total_price.value = ""+largeSigns.totalPrice  // update hidden form field
	
	/***** Calculate the total number of small signs ordered *****/
	smallSigns.qty += getQty(formObj.hole_small_qty.value)
	smallSigns.qty += getQty(formObj.registration_small_qty.value)
	smallSigns.qty += getQty(formObj.mulligan_small_qty.value)
	smallSigns.qty += getQty(formObj.cart_small_qty.value)
	smallSigns.qty += getQty(formObj.beverage_small_qty.value)
	smallSigns.qty += getQty(formObj.breakfast_small_qty.value)
	smallSigns.qty += getQty(formObj.lunch_small_qty.value)
	smallSigns.qty += getQty(formObj.dinner_small_qty.value)	
	smallSigns.qty += getQty(formObj.cocktails_small_qty.value)
	smallSigns.qty += getQty(formObj.hio_small_qty.value)
	smallSigns.qty += getQty(formObj.kp_small_qty.value)
	smallSigns.qty += getQty(formObj.ld_small_qty.value)
	smallSigns.qty += getQty(formObj.sd_small_qty.value)
	smallSigns.qty += getQty(formObj.putt_small_qty.value)
	smallSigns.qty += getQty(formObj.chip_small_qty.value)
	smallSigns.qty += getQty(formObj.blank_small_qty.value)
	
	formObj.small_sign_total_qty.value = ""+smallSigns.qty  // update hidden form field
	
	/***** Calculate the total non-discounted price for the small signs *****/
	
	smallSigns.totalPrice = smallSigns.qty * 13.25
	
	formObj.small_sign_total_price.value = ""+smallSigns.totalPrice  // update hidden form field
	
	/***** Calculate the total number of banners and the total price *****/
	bannerQtyTemp = getQty(formObj.banner_event_qty.value)
	banners.qty += bannerQtyTemp
	banners.totalPrice += getBannerPrice(getSelectValue(formObj.banner_event_size))*bannerQtyTemp
	
	bannerQtyTemp = getQty(formObj.banner_premier_sponsor_qty.value)
	banners.qty += bannerQtyTemp
	banners.totalPrice += getBannerPrice(getSelectValue(formObj.banner_premier_sponsor_size))*bannerQtyTemp
	
	bannerQtyTemp = getQty(formObj.banner_sponsor_qty.value)
	banners.qty += bannerQtyTemp
	banners.totalPrice += getBannerPrice(getSelectValue(formObj.banner_sponsor_size))*bannerQtyTemp
	
	formObj.banner_total_qty.value = ""+banners.qty  // update hidden form field
	formObj.banner_total_price.value = ""+banners.totalPrice  // update hidden form field

	/***** Calculate the Total number of award checks and event schedules and their respective prices *****/
	awardCheck.qty = getQty(formObj.award_check_qty.value)
	awardCheck.totalPrice = awardCheck.qty*45
	
	formObj.award_check_total_qty.value = ""+awardCheck.qty  // update hidden form field
	formObj.award_check_total_price.value = ""+awardCheck.totalPrice  // update hidden form field
	
	eventSigns.qty = getQty(formObj.event_schedule_qty.value)
	eventSigns.totalPrice = getBannerPrice(getSelectValue(formObj.event_schedule_size))*eventSigns.qty
	
	formObj.event_sign_total_qty.value = ""+eventSigns.qty  // update hidden form field
	formObj.event_sign_total_price.value = ""+eventSigns.totalPrice  // update hidden form field
	
	/***** Calculate fee for proofs and art setup *****/
	temp = largeSigns.qty + smallSigns.qty + banners.qty + awardCheck.qty + eventSigns.qty
	if (temp != 0) 			// intialize for art setup fee if there are any signs to be made
		subtotalTemp = 0
	else
		subtotalTemp = 0
		
	formObj.art_fee.value = ""+subtotalTemp
	
	if ((formObj.email_proof.checked) && (temp != 0)) {
		if (temp < 18)	
			temp = 18 * 2.5	//if the number of signs is less than 18 then charge the minimum 18 x $2.50 = $45.00 for the proofs, otherwise just multiply the number by $2.50
		else
			temp = temp * 2.5
		}
	else
		temp = 0
	formObj.proof_fee.value = ""+temp	
	
	subtotalTemp += temp // update running subtotal with proof fee
	
	
	/***** Calculate fee for wire stakes *****/ 
	if (formObj.wire_stakes.checked)
		temp = (largeSigns.qty * 1.75) + (smallSigns.qty * 1.25)
	else
		temp = 0
	formObj.stakes_fee.value = ""+temp
	
	subtotalTemp += temp // update running subtotal with stakes fee
	
	/***** Calculate fee for RUSH *****/
	/***** Rush Fee is a 20% add based on the total of all the signs so calculate the subtotal of all signs ordered  *****/
	subtotalSignsTemp = (largeSigns.totalPrice + smallSigns.totalPrice + banners.totalPrice + awardCheck.totalPrice + eventSigns.totalPrice)

	formObj.subtotal_price.value = ""+subtotalSignsTemp  // Store the subtotal in the form's hidden field
	
	if (subtotalSignsTemp != 0){
		if (formObj.rush.checked) {		
			temp = subtotalSignsTemp * standardRushFeePercent
			if (temp < 45)
				temp = 45
		}
		else
			temp = 0
	}
	else
		temp = 0
				
	formObj.rush_fee.value = ""+temp
	
	subtotalTemp += temp // update running subtotal with rush order fee
	
	formObj.other_fees_subtotal.value = ""+subtotalTemp
	formObj.other_total_price.value = ""+subtotalTemp
	
	// Calculate the package discount
	
	if (largeSigns.qty < 6)
		discount = 0
	else if (largeSigns.qty < 11)
		discount = 18.00 - 17.00
	else if (largeSigns.qty < 21)
		discount = 18.00 - 16.00
	else if (largeSigns.qty < 51)
		discount = 18.00 - 15.25
	else
		discount = 18.00 - 14.50
		4
	discountedPrice = discount * largeSigns.qty
	
	if (smallSigns.qty < 6)
		discount = 0
	else if (smallSigns.qty < 11)
		discount = 13.25 - 12.50
	else if (smallSigns.qty < 21)
		discount = 13.25 - 12.00
	else if (smallSigns.qty < 51)
		discount = 13.25 - 11.25
	else
		discount = 13.25 - 10.75
		
	discountedPrice += (discount * smallSigns.qty)
	
	if (banners.qty > 1)			
		discountedPrice += (banners.totalPrice * 0.10)
	
	if (awardCheck.qty > 1)
		discountedPrice += (awardCheck.totalPrice * 0.10)
		
	if (eventSigns.qty > 1)
		discountedPrice += (eventSigns.totalPrice * 0.10)
	
	formObj.package_discount.value = ""+discountedPrice
	
	formObj.total_price_wo_ship_tax.value = ""+(subtotalSignsTemp+subtotalTemp-discountedPrice)	

	updateSummaryInfo(formObj)		
		
	displayBackgroundSelections(formObj)
}


function setParms(imageSrcName,formFieldName,imageRootName,imageCnt,imageHeight,imageWidth){
	this.imageSrcName = imageSrcName
	this.formFieldName = formFieldName
	this.imageRootName = imageRootName
	this.imageCnt = imageCnt
	this.imageHeight = imageHeight
	this.imageWidth = imageWidth
}

function popup_templates(imageSrcName,formFieldName,imageRootName,imageCnt,imageHeight,imageWidth){
	
	parms = new setParms(imageSrcName,formFieldName,imageRootName,imageCnt,imageHeight,imageWidth)
	var windowWidth = 800
	var rows = (parseInt(imageCnt))/4
	var rowHeight = (parseInt(imageHeight))+10
	var windowHeight = Math.ceil(rows) * rowHeight + 230
	newWindow = window.open("templates.htm","backGrounds","width="+windowWidth+",height="+windowHeight+",resizable,scrollbars")
}

function show_templates(imageSrcName,formFieldName,imageRootName,imageCnt,imageHeight,imageWidth){
	
	parms = new setParms(imageSrcName,formFieldName,imageRootName,imageCnt,imageHeight,imageWidth)
	var windowWidth = 800
	var rows = (parseInt(imageCnt))/4
	var rowHeight = (parseInt(imageHeight))+10
	var windowHeight = Math.ceil(rows) * rowHeight + 230
	newWindow = window.open("show_templates.htm","backGrounds","width="+windowWidth+",height="+windowHeight+",resizable,scrollbars")
}

function gup(name){
	var regexS = "[\\?&]"+name+"=([^&#]*)"
	var regex = new RegExp(regexS)
	var tmpURL = window.location.href
	var results = regex.exec(tmpURL)
	if (results == null)
		return ""
	else
		return unescape(results[1])
}


function preFillForm(package){
	switch (package) {
		case "TheMasters":
			document.sign_order_form.hole_large_qty.value = 36
			document.sign_order_form.hio_large_qty.value = 1
			document.sign_order_form.kp_large_qty.value = 2
			document.sign_order_form.ld_large_qty.value = 2
			document.sign_order_form.sd_large_qty.value = 2
			document.sign_order_form.mulligan_large_qty.value = 1
			document.sign_order_form.putt_large_qty.value = 1
			document.sign_order_form.chip_large_qty.value = 1
			document.sign_order_form.registration_large_qty.value = 1
			document.sign_order_form.cart_large_qty.value = 1
			document.sign_order_form.beverage_large_qty.value = 2
			document.sign_order_form.lunch_large_qty.value = 1
			document.sign_order_form.cocktails_large_qty.value = 1
			document.sign_order_form.banner_event_size[1].selected = true
			document.sign_order_form.banner_event_qty.value = 1
			document.sign_order_form.banner_premier_sponsor_size[2].selected = true
			document.sign_order_form.banner_premier_sponsor_qty.value = 1
			document.sign_order_form.banner_sponsor_size[3].selected = true
			document.sign_order_form.banner_sponsor_qty.value = 1
			document.sign_order_form.award_check_qty.value = 2
			document.sign_order_form.event_schedule_size[1].selected = true
			document.sign_order_form.event_schedule_qty.value = 2
			document.sign_order_form.wire_stakes.checked = true
			break
		case "TheEagle":
			document.sign_order_form.hole_large_qty.value = 18
			document.sign_order_form.hio_large_qty.value = 1
			document.sign_order_form.kp_large_qty.value = 2
			document.sign_order_form.ld_large_qty.value = 2
			document.sign_order_form.sd_large_qty.value = 2
			document.sign_order_form.mulligan_large_qty.value = 1
			document.sign_order_form.putt_large_qty.value = 1
			document.sign_order_form.chip_large_qty.value = 1
			document.sign_order_form.registration_large_qty.value = 1
			document.sign_order_form.cart_large_qty.value = 1
			document.sign_order_form.beverage_large_qty.value = 1
			document.sign_order_form.lunch_large_qty.value = 1
			document.sign_order_form.cocktails_large_qty.value = 1
			document.sign_order_form.banner_event_size[2].selected = true
			document.sign_order_form.banner_event_qty.value = 1
			document.sign_order_form.banner_sponsor_size[3].selected = true
			document.sign_order_form.banner_sponsor_qty.value = 1
			document.sign_order_form.award_check_qty.value = 1
			document.sign_order_form.event_schedule_size[1].selected = true
			document.sign_order_form.event_schedule_qty.value = 2
			document.sign_order_form.wire_stakes.checked = true
			break
		case "TheBirdie":
			document.sign_order_form.hole_large_qty.value = 18
			document.sign_order_form.hio_large_qty.value = 1
			document.sign_order_form.kp_large_qty.value = 1
			document.sign_order_form.ld_large_qty.value = 1
			document.sign_order_form.mulligan_large_qty.value = 1
			document.sign_order_form.registration_large_qty.value = 1
			document.sign_order_form.cart_large_qty.value = 1
			document.sign_order_form.lunch_large_qty.value = 1
			document.sign_order_form.banner_event_size[2].selected = true
			document.sign_order_form.banner_event_qty.value = 1
			document.sign_order_form.banner_sponsor_size[3].selected = true
			document.sign_order_form.banner_sponsor_qty.value = 1
			document.sign_order_form.award_check_qty.value = 1
			document.sign_order_form.event_schedule_size[1].selected = true
			document.sign_order_form.event_schedule_qty.value = 1
			document.sign_order_form.wire_stakes.checked = true
			break
		case "ThePro":
			document.sign_order_form.hole_large_qty.value = 18
			document.sign_order_form.hio_large_qty.value = 1
			document.sign_order_form.kp_large_qty.value = 1
			document.sign_order_form.ld_large_qty.value = 1
			document.sign_order_form.banner_event_size[2].selected = true
			document.sign_order_form.banner_event_qty.value = 1
			document.sign_order_form.wire_stakes.checked = true
			break
		case "TheFrontNine":
			document.sign_order_form.hole_large_qty.value = 9
			document.sign_order_form.hio_large_qty.value = 1
			document.sign_order_form.kp_large_qty.value = 1
			document.sign_order_form.ld_large_qty.value = 1
			document.sign_order_form.banner_event_size[3].selected = true
			document.sign_order_form.banner_event_qty.value = 1
			document.sign_order_form.wire_stakes.checked = true
			break
		case "TheBackNine":
			document.sign_order_form.hole_small_qty.value = 9
			document.sign_order_form.hio_small_qty.value = 1
			document.sign_order_form.kp_small_qty.value = 1
			document.sign_order_form.ld_small_qty.value = 1
			document.sign_order_form.banner_event_size[5].selected = true
			document.sign_order_form.banner_event_qty.value = 1
			document.sign_order_form.wire_stakes.checked = true
			break
		default:
	}
}

var packageType = ""


function initForm(){

	if (getCookie("swVersion") == null){
		setCookie("swVersion",codeVersion[codeVersion.length-1])
	}
	else{
		if (getCookie("swVersion") != codeVersion[codeVersion.length-1]){
			downLevelScriptHandler()
		}
	}
	packageType = gup("packageType")
	if (packageType != ""){
		preFillForm(packageType)
		updateTotals(document.sign_order_form)
		if (getCookie("orderform") != null)
			{
			if (confirm("You have an existing order already started.\n\nClick on \"OK\" to load it or on \"Cancel\" to delete it and start a new order.")){
				clearFormData(document.sign_order_form)
				getFormElements(document.sign_order_form)
				return
			}
			else {
				clearCookie("signcopy")
				clearCookie("specialinstructions")
				clearCookie("itemnumber")
				return
			}				
		}
		else {
			return
		}				
	}
	else {			
		getFormElements(document.sign_order_form)
	}
}

function getFormData(formObj) {
	var fieldValue = ""
	var formData = ""
	var numberOfElements = formObj.elements.length
	for (var i=0; i<numberOfElements; i++){
		fieldValue = ""
		switch (formObj.elements[i].type){
			case "text":
			case "textarea":
			case "hidden":
				fieldValue = formObj.elements[i].value
				if (fieldValue != "")
					formData += i+":"+escape(fieldValue)+"!!"
				break
			case "select-one":
				fieldValue = formObj.elements[i].options.selectedIndex
				formData += i+":"+escape(fieldValue)+"!!"
				break
			case "checkbox":
				fieldValue = formObj.elements[i].checked
				formData += i+":"+escape(fieldValue)+"!!"
				break
			case "radio":
			case "select-multiple":
			case "password":
			case "fileupload":
			case "button":
			case "submit":
			case "reset":
			case "image":	
			default:
		}			
	}
	return (formData)
}

function clearFormData(formObj){
	for (var i=0; i<formObj.elements.length; i++) {	 
		switch (formObj.elements[i].type){
			case "text":
			case "textarea":
			case "hidden":
				formObj.elements[i].value = ""
				break
			case "select-one":
				formObj.elements[i].options.selectedIndex = 0
				break
			case "checkbox":
				formObj.elements[i].checked = false
				break
			case "radio":
			case "select-multiple":
			case "password":
			case "fileupload":
			case "button":
			case "submit":
			case "reset":
			case "image":
			default:
		}
	}
}

function restoreFormData(formObj,formData){
	var formDataElements = formData.split("!!")
	var dataElementIndex
	var dataElementValue
	for (var i=0; i<formDataElements.length-1; i++) {	
		dataElementIndex = parseInt(formDataElements[i].split(":")[0])
		dataElementValue = unescape(formDataElements[i].split(":")[1])
		switch (formObj.elements[dataElementIndex].type){
			case "text":
			case "hidden":
				formObj.elements[dataElementIndex].value = dataElementValue
				break
			case "select-one":
				formObj.elements[dataElementIndex].options.selectedIndex = dataElementValue
				break
			case "checkbox":			
				if (dataElementValue == "true")
					formObj.elements[dataElementIndex].checked = true
				else
					formObj.elements[dataElementIndex].checked = false
				break
			case "radio":
			case "select-multiple":
			case "password":
			case "fileupload":
			case "button":
			case "submit":
			case "reset":
			case "image":
			default:
		}
		
	}
}

function saveFormElements(formObj) {
	var formData = getFormData(formObj)
	var oneYear = 365 * 24 * 60 * 60 * 1000
	var expDate = new Date()
	expDate.setTime(expDate.getTime() + oneYear)
	setCookie("orderform",formData,expDate)
}

function getFormElements(formObj) {
	var formData = getCookie("orderform")
	if (formData != null)
		restoreFormData(formObj,formData)
	updateTotals(formObj)
}


//
// End of the dynamic code on the order form
//********************************************************************************************************************************************************

//********************************************************************************************************************************************************
// The following code is used to validate the order form when the "CONTINUE" button is clicked
//

function highlight(fieldId,state){
	if (state)
		document.getElementById(fieldId).style.color = "red"
	else
		document.getElementById(fieldId).style.color = "black"	
}

function validTextField(textObj,fieldId){
	if (textObj.value == ""){
		highlight(fieldId,true)
		return false
	}
	else{
		highlight(fieldId, false)
		return true
	}
}

function validImage(qtyObj1, qtyObj2, imageObj, fieldId){
	if ((getQty(qtyObj1.value)==0)&&((getQty(qtyObj2.value)==0))){
		highlight(fieldId,false)
		return true
	}
	else{
		if (imageObj.value==""){
			highlight(fieldId,true)
			return false
		}
		else{
			highlight(fieldId,false)
			return true
		}
	}
}

function submitOrderform(formObj){
	if (validateOrderform(formObj)) formObj.submit()
}	

function validateOrderform(formObj){
	var validFlag = true
	
var totalSignsOrdered = getQty(formObj.large_sign_total_qty.value)+
						getQty(formObj.small_sign_total_qty.value)+
						getQty(formObj.banner_total_qty.value)+
						getQty(formObj.award_check_total_qty.value)+
						getQty(formObj.event_sign_total_qty.value)
if (totalSignsOrdered <= 0){
	alert("YOUR ORDERFORM IS BLANK. \n\nPlease provide all the necessary information to process your order \nand then click on the \"Enter Sponsor Names\" button when finished.  \n\nThank you!!")
	validFlag = false
	return validFlag
}			
	if (!validTextField(formObj.tournament_name,"tournamentName")) validFlag=false
	if (!validTextField(formObj.tournament_location,"tournamentLoc")) validFlag=false
	if (!validTextField(formObj.contact_name,"contactName")) validFlag=false
	if (!validTextField(formObj.contact_phone,"contactPhone")) validFlag=false
	if (!validTextField(formObj.tournament_date,"tournamentDate")) validFlag=false
	if (!validTextField(formObj.signs_required_by,"signNeedDate")) validFag=false
	if (!validTextField(formObj.contact_email,"contactEmail")) validFlag=false
	
	if (!validImage(formObj.hole_large_qty, formObj.hole_small_qty,formObj.hole_template,"hole")) validFlag=false
	if (!validImage(formObj.hio_large_qty, formObj.hio_small_qty,formObj.hio_template,"hio")) validFlag=false
	if (!validImage(formObj.kp_large_qty, formObj.kp_small_qty,formObj.kp_template,"kp")) validFlag=false
	if (!validImage(formObj.ld_large_qty, formObj.ld_small_qty,formObj.ld_template,"ld")) validFlag=false
	if (!validImage(formObj.sd_large_qty, formObj.sd_small_qty,formObj.sd_template,"sd")) validFlag=false
	if (!validImage(formObj.mulligan_large_qty, formObj.mulligan_small_qty,formObj.mulligan_template,"mul")) validFlag=false
	if (!validImage(formObj.putt_large_qty, formObj.putt_small_qty,formObj.putt_template,"putt")) validFlag=false
	if (!validImage(formObj.chip_large_qty, formObj.chip_small_qty,formObj.chip_template,"chip")) validFlag=false
	if (!validImage(formObj.registration_large_qty, formObj.registration_small_qty,formObj.registration_template,"reg")) validFlag=false
	if (!validImage(formObj.cart_large_qty, formObj.cart_small_qty,formObj.cart_template,"cart")) validFlag=false
	if (!validImage(formObj.beverage_large_qty, formObj.beverage_small_qty,formObj.beverage_template,"bev")) validFlag=false
	if (!validImage(formObj.breakfast_large_qty, formObj.breakfast_small_qty,formObj.breakfast_template,"break")) validFlag=false
	if (!validImage(formObj.lunch_large_qty, formObj.lunch_small_qty,formObj.lunch_template,"lunch")) validFlag=false
	if (!validImage(formObj.dinner_large_qty, formObj.dinner_small_qty,formObj.dinner_template,"din")) validFlag=false
	if (!validImage(formObj.cocktails_large_qty, formObj.cocktails_small_qty,formObj.cocktails_template,"cock")) validFlag=false
	if (!validImage(formObj.blank_large_qty, formObj.blank_small_qty,formObj.blank_template,"blank")) validFlag=false
	
	if (!validImage(formObj.banner_event_qty,formObj.banner_event_qty,formObj.event_banner_template,"event")) validFlag=false
	if (!validImage(formObj.banner_premier_sponsor_qty,formObj.banner_premier_sponsor_qty,formObj.premier_banner_template,"premier")) validFlag=false
	if (!validImage(formObj.banner_sponsor_qty,formObj.banner_sponsor_qty,formObj.sponsor_banner_template,"banner")) validFlag=false
	if (!validImage(formObj.award_check_qty,formObj.award_check_qty,formObj.award_check_template,"check")) validFlag=false
	if (!validImage(formObj.event_schedule_qty,formObj.event_schedule_qty,formObj.event_schedule_template,"sched")) validFlag=false

	
	
if (!validFlag) alert("YOUR ORDERFORM IS INCOMPLETE. \n\nPlease provide all the necessary information to process your order \nand then click on the \"Enter Sponsor Names\" button when finished.  \nThe incomplete fields are highlighted in RED. \n\nThank you!!")

return validFlag
}

//
// End of form vaidation code
//*********************************************************************************************************************************************************

function itemNumber(){
	var oneDay = 1 * 24 * 60 * 60 * 1000
	var expDate = new Date()
	expDate.setTime(expDate.getTime() + oneDay)
	
	var item_number = "GTS"
	var today = new Date()
	var timeStamp = today.getTime()
		
	var orderFormCookie = getCookie("orderform")
	if (orderFormCookie != null){
		var formData = orderFormCookie.split("!!")
		for (var i=0; i<formData.length-1; i++){
			switch (parseInt(formData[i].split(":")[0])){
				case 78:
				case 80:
				case 82:
				case 84:
				case 86:	item_number += unescape(formData[i].split(":")[1])
							break
				default:
							break
			}
		}
	}
	item_number += "."+timeStamp
	setCookie("itemnumber",escape(item_number),expDate)
	return item_number
}



//**********************************************************************************************************************************************************
//Cookie handlers
//

function setCookie(name, value, expires, path, domain, secure) {
	//alert("Cookie:"+name+" Value:"+value+" Expires: "expires+" Path:"+path+domain+secure)
	//path = "/"							// force cookies to be available to all pages on the site
	domain = ".championgolfsigns.com"	// force cookies to only have two levels of domain qualification (don't worry about "www")
	var expString = ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
	var pathString = ((path == null) ? "" : ("; path=" + path));
	var domainString = ((domain == null) ? "" : ("; domain=" + domain));
	var secureString = ((secure == true) ? "; secure" :"");
	if ((name=="orderform")&&(value==emptyFormData)){
		clearCookie("orderform")
		clearCookie("signcopy")
		clearCookie("specialinstructions")
		clearCookie("shipping")
		clearCookie("itemnumber")
		return
	}
	else {
	document.cookie = name + "=" + escape(Base64.encode(value)) + expString + pathString + domainString + secureString
	}
}

function clearCookie(name) {
	var threeDays = 3 * 24 * 60 * 60 * 1000
	var expDate = new Date()
	expDate.setTime(expDate.getTime() - threeDays)
	document.cookie = name + "=ImOutOfHere; expires=" + expDate.toGMTString();
}

function getCookie(name) {
	var result = null
	var myCookie = " " + document.cookie + ";"
	var searchName = " " + name + "="
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie
	if (startOfCookie != -1) {
		startOfCookie += searchName.length;   // skip past cookie name
		endOfCookie = myCookie.indexOf(";", startOfCookie)
		result = Base64.decode(unescape(myCookie.substring(startOfCookie, endOfCookie)))
	}
	return result
}

function saveShippingInstructions(){
	var oneYear = 365 * 24 * 60 * 60 * 1000
	var expDate = new Date()
	expDate.setTime(expDate.getTime() + oneYear)
	
	var nonBlank = /\w/
	var specIns = document.additional_info.Special_Instructions.value
	if ((specIns != "")&&(specIns != null)&&(nonBlank.test(specIns))){
		specIns = escape(specIns)
		setCookie("specialinstructions",specIns,expDate)
	}
	else
		clearCookie("specialinstructions")
		
	/*
		shipping cookie format:
			0: Index of ShipPrefer radio button that is checked
			1: Value of ShipPrefer radio button that is checked
			2: ShipToName
			3: ShipToCompany
			4: ShipToStreetAddress
			5: ShipToCity
			6: Index of ShipToState option that was selected
			7: Value of ShipToState option that was selected
			8: ShipToZipCode
			9: ShippingFee
			10: ShippingWeight
			11: BoxType
			12: PromoCode
			13: DiscountAmount
	*/
		
	var shipData = ""
	for (var i=0; i<document.shipping_instructions.ShipPrefer.length; i++){
		if (document.shipping_instructions.ShipPrefer[i].checked){
			shipData += i+"!!"+document.shipping_instructions.ShipPrefer[i].value+"!!"
			break
		}
	}
	shipData += escape(document.shipping_instructions.ShipToName.value)+"!!"
	shipData += escape(document.shipping_instructions.ShipToCompany.value)+"!!"
	shipData += escape(document.shipping_instructions.ShipToStreetAddress.value)+"!!"
	shipData += escape(document.shipping_instructions.ShipToCity.value)+"!!"
	shipData += (document.shipping_instructions.ShipToState.selectedIndex)+"!!"
	shipData += escape(document.shipping_instructions.ShipToState.options[document.shipping_instructions.ShipToState.selectedIndex].value)+"!!"
	shipData += escape(document.shipping_instructions.ShipToZipCode.value)+"!!"	
	shipData += escape(document.shipping_instructions.Ship_Fee.value)+"!!"
	shipData += escape(document.shipping_instructions.Shipping_Weight.value)+"!!"
	shipData += escape(document.shipping_instructions.Box_Type.value)+"!!"
	shipData += escape(document.shipping_instructions.PromoCode.value)+"!!"
	shipData += escape(document.shipping_instructions.DiscountAmount.value)+"!!"
	setCookie("shipping",shipData,expDate)
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

//
//End of Cookie handlers
//***********************************************************************************************************************************************************


//***********************************************************************************************************************************************************
//Start of test code used to debug with
//

function testCode(p,d){
	var testWindow = window.open("","testCode","resizable, scrollbars")
	testWindow.document.writeln(p +":  " + d + "<br>")
}

function displayFormFields(formObj){                  // test routine 
	var testWindow = window.open("","testCode", "resizable, scrollbars")	
	for (var i=0; i<formObj.elements.length; i++){
	 	testWindow.document.writeln(""+i+":  "+formObj.elements[i].name+"<br>")

	}
}

function displayOrderformInputData(obj){
	reconstructOrderform(obj)
	
	var testWindow = window.open("","testCode", "resizable, scrollbars")
	
	for (var j=0; j<orderformPropIndex.length; j++){	
		testWindow.document.writeln("" + j + ": " + orderformPropIndex[j] + " = " + obj[orderformPropIndex[j]] + "<br>")
	}
	
}
//
//End of the test code
//***********************************************************************************************************************************************************

