// Javascripts for the BreezeBrowser "EOS" template

// Read parameters from URL
var parsed = window.location.search.substring(1)
var order  = getParm(parsed,"order")
var page   = getParm(parsed,"page")
var starts = getParm(parsed,"starts")	// first image in section
var ends   = getParm(parsed,"ends")	// last  image in section
var slide  = getParm(parsed,"slide")
var delay  = getParm(parsed,"delay")
var printme= getParm(parsed,"print")

// various
var maxItemLength = item.length + specialItem.length
var onMouseOver = "this.style.backgroundColor='" + mouseOverColor + "'"
var onMouseOut  = "this.style.backgroundColor=''"
var itemQty = new Array()
var TextFile = ""
var TagFile  = ""
var useStyle = ""
var loadScript = ""
var subTotal = 0
var totalVal = 0
var percentDiscountByTotal = 0
var itemOrderString = ""
var returnLink = ""	// not used
if(delay == "") delay = defaultDelay
if(imagePath != "") imagePath = imagePath.replace(/\/$/,"") + "/"

// address formatting (ZIP code first or last)
if(addr_format == "zcs") {		// zip code   city
	var zip_del   = " "
	var city_del  = "\n"
	var state_del = "\n"
} else {				// city, ST   zip code
	var city_del  = ", "
	var state_del = " "
	var zip_del   = "\n"
}
// workaround b/c &euro; does not show up as symbol
currTxt = currency	
if(currency == "&euro;")  currTxt = "EUR"
if(currency == "&pound;") currTxt = "GBP"


// -----------------------------------------
//
// Scripts for the   H E A D E R   F R A M E
//
// -----------------------------------------

// Alert & forward to homepage
function back2home(noi, www_addr) {
	if(noi > 0) {
		if(confirm(alert_home))
			parent.location.href = www_addr
	} else		parent.location.href = www_addr
}

// Alert & forward to galleries
function back2galleries(noi) {
	if(noi > 0) {
		if(confirm(alert_gallery))
			parent.location.href = galleryIndex
	} else		parent.location.href = galleryIndex
}

// Forward to checkout (if cart not empty)
function go2cart(noi) {
	//if(noi == 0) {
	//	alert("Your cart is empty!")
	//} else
		parent.frames[1].location.href = "index2.htm?order=html"
}

// print instructions file as popup
function show_instructions (jump) {
        Size	= "width=340,height=600,left=20,top=20"
        Options = "status=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes," + Size
        instructions_file = "instructions_" + language + ".htm"
        InstrWin= open(instructions_file, instructions_title, Options)
        InstrWin.focus()
}

// print instructions file as popup
function correct_StartIndexPage () {
	StartIndexPage += ""
	// 0 = no sections used
	if(useSections == 0) {
		StartIndexPage = StartIndexPage.replace(/[ s]/,"")
		if(StartIndexPage == "") StartIndexPage = 1
		if(StartIndexPage == 0)  StartIndexPage = 1
	}
	// 1 = sections instead of pages
	if(useSections == 1) {
		if(StartIndexPage == "")  StartIndexPage = "s0"
		StartIndexPage = "s" + StartIndexPage.replace("s","")
	}
	// 2 = sections and pages available
	if(useSections == 2) {
		if(StartIndexPage == "")  StartIndexPage = "s0"
	}
}

// go to last page if password is incorrect
function galleryCheck () {
	if(order == "hidden" && pwFile != "" && galleryCode != "")
	{
		var password = prompt("Password:", "")
		if(password == null || password == "")		// null = Cancel
		   	top.location.href = errorPage
		else if(password != galleryCode) {
			alert("wrong password")
			galleryCheck()				// try again
		}
	}
}
// -------------------------------------
//
// Scripts for the   I N D E X   P A G E
//
// -------------------------------------

// print index navigation bar
function printNavigation(dropDown) {
	if(numPages == 1) return

	indexPage = "index3.htm?page="
	if(dropDown == 1) document.write('<FORM>')
	else		  document.write('<table border="0" cellpadding="5"><tr><td class="navigation">')
	
	//left part
	if (page > 1) {
	   prevPage = page - 1
	   document.write('<a href="' + indexPage + prevPage + '">')
	   document.write('<img src="' + gif_prev + '" border="0" alt="' + prevPage + '" hspace="5"></a>')
	}
	//middle part
	if(dropDown == 1) {
		document.write(index_pages + ' <select onChange="location.href=this.options[this.selectedIndex].value">')
		for(i=1; i<=numPages; i++) {
		   	if(i==page) sel = " selected"
		   	else	    sel = ""
		   	document.write('\n<option value="index3.htm?page=' +i+ '&delay=' + delay + '"' + sel+'>'+i)
		}
		if (numPages > 1) {
		   	if(page=="all")	sel = " selected"
		   	else		sel = ""
		   	document.write('\n<option value="index3.htm?page=all&delay=' + delay + '"' + sel+'>'+ index_all)
		}
		document.write('</select>')
	} else {
		document.write('</td>\n<td class="navigation" align="center">' + index_pages + ' ')
		for(i=1; i<=numPages; i++) {
		   	if(i==page) document.write('<span class="currentPage">'+i+'</span> | ')
		   	else	    document.write('<a href="' + indexPage + i + '">'+i+'</a> | ')
		}
		if (numPages > 1) {
		   if(page=="all")	document.write('<span class="currentPage">' + index_all + '</span>')
		   else			document.write('<a href="' + indexPage + 'all">' + index_all + '</a>')	    
		}
		document.write('</td><td class="navigation">')
	}	
	//right part
	if (page < numPages && page > 0) {
		nextPage = page
		nextPage++
		document.write('&nbsp;&nbsp;<a href="' + indexPage + nextPage + '">')
		document.write('<img src="' + gif_next + '" border="0" alt="' + nextPage + '"></a>')
	}
	if(dropDown == 1) document.write('</form>\n')
	else		  document.write('</td></tr></table>\n')
}

// print index section drop-down/links
function printSectionNavigation(dropDown) {

	var lastOne		= "==empty=="
	var count		= 0
	var section_counter	= 0
	var section_page 	= ""
	var sel			= ""
	var my_section		= 0
	next_section 		= 0
	var section_delimiter	= " | "		// use "<br>" for new lines


	if(dropDown == 1) {
		document.write('<FORM>')
		// print arrow to next section
		prev_section = page.replace("s","") - 1
		if (prev_section >= 0) {
			document.write('<a href="index3.htm?page=s' + prev_section + '&delay=' + delay + '">')
			document.write('<img src="' + gif_prev + '" border="0" hspace="10" align="absmiddle"></a>')
		}
	
		document.write('<select onChange="location.href=this.options[this.selectedIndex].value">')
		document.write('<option value="index3.htm?page=s0"' + sel + '&delay=' + delay + '><b>' + overview + '</b>\n')
	}
	else {
		document.write('<TABLE width="800"><tr><td class="navigation">')
		if(page == "s0")
			document.write('<span class="currentPage">' + overview + '</span>')
		else	document.write('<a href="index3.htm?page=s0&delay=' + delay + '">' + overview + '</a>')
		document.write(section_delimiter)
	}
	for(i=0; i<allSections.length; i++) {
		if(allSections[i] != lastOne) {
			section_counter++
			section_page = "s" + section_counter
	
			// write # of images to previous section
			if(count > 0) {
				if(showCount == 1) document.write(' (' + count + ')\n')
				if(dropDown == 0)  document.write(section_delimiter)
			}
			// remember last image of section to display
			if(count > 0 && my_section == 1) {
				endImage = i
				my_section = 0
				next_section = section_counter
			}
			// note start image of section to display
			if(page == section_page) {
				startImage = i+1
				my_section = 1
				sel = " selected"
				curr_section = '<span class="currentPage">'
			}
			else {
				sel = ""
				curr_section = ""
			}	

			if(numberSections == 1)	count_str = section_counter + ". "
			else			count_str = ""
			
			if(dropDown == 1) {
				document.write('<option value="index3.htm?page=' + section_page + '&delay=' + delay + '"')
				document.write(sel + '>' + count_str + allSections[i])
			} else {
				// print links instead of drop down
				if(page == section_page)
					document.write('<span class="currentPage">' + count_str + allSections[i] + '</span>')
				else {
					document.write('<a href="index3.htm?page=' + section_page + '&delay=' + delay + '">')
					document.write(count_str + allSections[i] + '</a>')
				}
			}
			count = 0
			sel = ""
		}
		lastOne = allSections[i]
		count++
	}
	if(showCount == 1) document.write(' (' + count + ')\n')
	if(endImage == 0)  endImage = numImages
	
	// write "all" option at last
	if (page == "sall") {
		startImage = 1
		endImage   = numImages
		sel = " selected"
	}
	if(dropDown == 1) {
		document.write('<option value="index3.htm?page=sall&delay=' + delay + '"' + sel + '>' + index_all)
		document.write(' (' + numImages + ')\n')
		document.write('</select>')
	
		// print arrow to next section
		if (page == "s0") next_section = 1
		if (next_section > 0) {
			document.write('<a href="index3.htm?page=s' + next_section + '&delay=' + delay + '">')
			document.write('<img src="' + gif_next + '" border="0" hspace="10" align="absmiddle"></a>')
		}
		document.write('</form>')
	}
	else {
		document.write('</td></tr></table>')
	}
}

// get order status from form
function checkOrderStatus(imageNumber) {
	var my_itemOrderString = eval('parent.frames[0].document.forms[0].items_of_image_' + imageNumber + '.value')
	// 0=1;4=2   ->   itemOrdered[1] = "4=2"  ->   itemQty[4] = 2
	if(my_itemOrderString != "") {
		orderTxt = ordered + ":"
		frameCol = "ordered"
		itemOrdered = my_itemOrderString.split(";")
		// reset qty array
		for(i=0; i<maxItemLength; i++) itemQty[i] = 0
		for(i=0; i<itemOrdered.length-1; i++) {
			item_qty_pair    = itemOrdered[i].split("=")		// "4=2"
			item_no          = item_qty_pair[0]
			itemQty[item_no] = parseInt(item_qty_pair[1], 10)
			imageQty 	+= itemQty[i]
		}
		// print ordered items
		for(i=0; i<item.length; i++) {
			if(itemQty[i] > 0)
				orderTxt += "\n" + itemQty[i] + "x  " + replaceHTMLtags(item[i]["text"])
		}
		for(j=0; j<specialItem.length; j++) {
			if(itemQty[i+j] > 0)
				orderTxt += "\n" + itemQty[i+j] + "x  " + replaceHTMLtags(specialItem[j]["text"])
		}
	}
}


// -------------------------------------------
//
// Scripts for the   F U L L S I Z E   P A G E
//
// -------------------------------------------

// print fullsize navigation
function printFullsizeNavigation() {
	
	// determine which index page we belong to
	if(page.indexOf("s") == 0) {			// sections used
		if(starts == "") starts = 1
		if(ends   == "") ends   = numImages
		// check if start or end of section
		if(imageNumber <= starts) prevUrl = "index3.htm"
		if(imageNumber >= ends)   nextUrl = "index3.htm"
		// ignore section end for slideshow
		if(imageNumber >= ends && slide == "on" && slideshowAllSections == 1) {
			starts = 1; ends = numImages	// whole gallery
			page = "s0"			// back to overview
		}
		section_nav = "&starts=" + starts + "&ends=" + ends
	} else {					// no sections used
		// check if end of gallery
		if(prevUrl == "") prevUrl = "index3.htm"
		if(page != "all") {
			page = 0
			while (page * numColumns * numRows < imageNumber) page++
		}
		if(useSections == 1) page = "s0"	// sections only
		section_nav = ""
	}
	if(nextUrl == "") nextUrl = "index3.htm"

	// print navigation
	document.write('<TABLE width="' + navigationBar_width + '" border="0"><tr>')
	document.write('<td class="navigation" align="left"   width="33%">')
	printFullsizeNavigationHref(prevUrl, page, delay, section_nav, imageNumber)
	document.write('<img src="' + gif_prev + '" border="0" hspace="3" align="absmiddle">' + previous_link + '</a></td>')
	
	document.write('<td class="navigation" align="center" width="33%">')
	printFullsizeNavigationHref("index3.htm", page, delay, section_nav)
	document.write(back_to_index + '</a></td>')
	
	document.write('<td class="navigation" align="right"  width="33%">')
	printFullsizeNavigationHref(nextUrl, page, delay, section_nav)
	document.write(next_link + '<img src="' + gif_next + '" border="0" hspace="4" align="absmiddle"></a></td>')
	document.write('</tr></table>')
}

// print fullsize navigation
function printFullsizeNavigationHref(nav_url, page, delay, section_nav) {
	nav_url = '<a href="' + nav_url
	nav_url+= '?page=' + page + section_nav
	nav_url+= '&delay=' + delay
	nav_url+= '&slide=" '
	nav_url+= 'onClick="updateOrder(imageNumber, old_noi, imageQty, 0)">'
	document.write(nav_url)
}


// start/stop the slideshow
function start_stop(f) {
	if (slide == "on") {
		// disable the slideshow
		slide = ""
		f.ss_button.value = slideshow_start
		// Remove the "&slide=on" from the page history
		thisUrl = location.href.replace("&slide=on","")
		if (document.images) location.replace(thisUrl);
	}
	else {
		// restart the slideshow
		slide = "on"
		setTimeout('next()', 1000)
		f.ss_button.value = slideshow_stop
	}
	return false
}

// check if image has loaded
function poll() {
	if (slide == "on") {
		if (thePhoto.complete) setTimeout('next()', 1000 * delay)
		else setTimeout('poll()', 500)
	}
}

// slideshow: go to the next page
function next() {
	nextUrl += '?page=' + page + section_nav + '&delay=' + delay + '&slide=on'
	document.location.href = nextUrl
}

// print the item's input fields
function printItemForm(i, imageNumber, qty, text, price) {
	price = price * 100
	document.write('<tr>')
	document.write('<td><input type="button" value="<" onClick="if(this.form.item_'+i+'.value>0)this.form.item_'+i+'.value=--this.form.item_'+i+'.value">&nbsp;')
	document.write('<input class="textfield" type="text" name="item_'+i+'" size="3" value="'+qty+'" ')
	document.write(' onClick="newVal=this.value; if(this.value==0)newVal=1; if(this.value==1)newVal=0; this.value=newVal" ')
	document.write(' onChange="this.value=onlyNumbers(this.value)">&nbsp;')
	document.write('<input type="button" value=">" onClick="this.form.item_'+i+'.value=++this.form.item_'+i+'.value"></td>')
	document.write('<td class="itemlist"><b>' + text + '</b></td>')
	document.write('<td class="itemlist" align="right">' + currency.replace(" ","&nbsp;") + price2Strg(price) + '</td></tr>')
}

// add an item to the shopping cart
function updateOrder(imageNumber, old_noi, old_qty_thisImage, from_buttom) {
	if(noOrderFunction == 1) return

	old_itemOrderString = itemOrderString
	itemOrderString     = ""
	var itemsLength = document.form_items.length / 3
	var qty_thisImage = 0
	for(i=0; i<itemsLength; i++) {
		j = 3*i + 1					// 1,4,7,10,... to skip the < and > buttons!
		qty = document.form_items.elements[j].value
		qty = parseInt(qty ,10)
		if(qty > 0) {
			qty_thisImage += qty
			itemPosition = document.form_items.elements[j].name.replace("item_","")
			itemOrderString += itemPosition + "=" + qty + ";"
		}
	}
	
	// check if order has changed
	if(itemOrderString != old_itemOrderString) {
		eval('parent.frames[0].document.forms[0].items_of_image_'+imageNumber+'.value = itemOrderString')
		
		// update number of items in cart field
		delta_qty_thisImage = qty_thisImage - old_qty_thisImage
		val = old_noi + delta_qty_thisImage
		parent.frames[0].document.forms[0].noi.value = val

		// show confirmation message
		if(showUpdateAlert == 2 ||
	  	  (showUpdateAlert == 1 && from_buttom == 1)) {alertUpdateMsg(delta_qty_thisImage)}
	}
}

// functions to disable right-click on the fullsize images
function trap() {
	if(noImageRightClick == 1) {
		if(document.images) {
			for(i=0;i<document.images.length;i++) {
				document.images[i].onmousedown = right;
				document.images[i].onmouseup   = right;
			}
		}
	}
}

function right(e) {
	if (navigator.appName == 'Netscape' && e.which == 3) {
		alert(no_right_click);
		return false;
	}
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		alert(no_right_click);
		return false;
	}
	return true;
}


// -------------------------------------------
//
// Scripts for the   C H E C K O U T   P A G E
//
// -------------------------------------------

// print the item's quantity & price
function printItemOrder(filename, qty, text, price) {
	price = price * 100
	cost  = price * qty
	document.write('<tr class="itemlist"><td>' + text + '</td>')
	document.write('<td align="right">' + currency.replace(" ","&nbsp;") + price2Strg(price) + '</td>')
	document.write('<td align="right">' + qty + '</td>')
	document.write('<td align="right">' + currency.replace(" ","&nbsp;") + price2Strg(cost))
	document.write('<input type="hidden" name="' + stripFileExtension(filename) + text + ': " value="' + qty + '"></td></tr>')

	if(useDiscountByCopies == 1) {
		amountDiscountByCopies = cost * calcDiscountByCopies(qty) / 100
		if(amountDiscountByCopies != 0) {
			minussign = '- '			// forces line break!
			// minus sign workarounds:
			minussign = '<img src="minus.gif" width="5" height="1" hspace="5" align="absmiddle">'
			cost -= amountDiscountByCopies
			document.write('<tr align="right" class="itemlist"><td><a href="javascript:discountByCopiesRules()">')
			document.write(txt_discount + '</a></td>')
			document.write('<td>&nbsp;</td>')
			document.write('<td>' + calcDiscountByCopies(qty) + '%</td>')
			document.write('<td align="right">' + minussign + currency.replace(" ","&nbsp;") + price2Strg(amountDiscountByCopies) + '</td></tr>')
		}
	}
	subTotal += cost
	
	// details in text file
	TextFile += qty + " x " + text + " (" + currency.replace(" ","&nbsp;") + price2Strg(cost) + ")\n"
}


// calculate total price
function calcTotal() {
	newSubtotal  = 0
	var newSubtotal2 = 0
	var newSubtotal3 = 0
	var newSubtotal4 = 0
	var newSubtotal5 = 0
	detailsTxt  = calc_details + ":\n\n"
	detailsTxt += txt_subtotal + " = " + price2Strg(subTotal) + "\n"
	
	// calculate discount by total
	amountDiscountByTotal = 0
	newSubtotal = subTotal
	if(useDiscountByTotal == 1) {
		percentDiscountByTotal = calcDiscountByTotal(subTotal)
		amountDiscountByTotal  = subTotal * percentDiscountByTotal / 100
		
		newSubtotal = subTotal - amountDiscountByTotal
		detailsTxt += txt_discount + " = " + percentDiscountByTotal + "% of " + price2Strg(subTotal) + " = " + price2Strg(amountDiscountByTotal) + "\n"
		detailsTxt += "New " + txt_subtotal + " = " + price2Strg(subTotal) + ' - ' + price2Strg(amountDiscountByTotal) + ' = ' + price2Strg(newSubtotal) + "\n\n"
	}
	
	// calculate postage
	postage      = 0
	theo_postage = 0		// theoretical postage (need for pickup feature)
	if(shippingPercentage + shippingFixAmount + shippingPerItem > 0) {
		subTotalCalcVal = subTotal - amountDiscountByTotal
		if(shippingPercentage > 0) theo_postage += shippingPercentage * subTotalCalcVal / 100
		if(shippingPerItem    > 0) theo_postage += shippingPerItem    * numberOfItems * 100
		if(shippingFixAmount  > 0) theo_postage += shippingFixAmount  * 100

		myPickupVal = parent.frames[0].document.forms[0].pickup.value
		if(myPickupVal == "") {
			postage = theo_postage
		}

		newSubtotal2 = eval(newSubtotal + postage)
		detailsTxt += "Shipping = " + price2Strg(postage) + " (for details click on S&H)\n"
		//detailsTxt += "new subtotal = " + price2Strg(newSubtotal) + ' + ' + price2Strg(postage) + ' = ' + price2Strg(newSubtotal2) + "\n\n"
	}
	
	// calculate additional postage
	morePostage = 0
	for(i=0; i<shipOption.length; i++) {
		if(shipOption[i]["used"] == 1) {
			myADDval = eval('parent.frames[0].document.forms[0].shipOption_' + i + '.value')
			myADDval = parseInt(myADDval, 10) * 100
			morePostage += myADDval
			
			detailsTxt += shipOption[i]["title"] + " = " + price2Strg(myADDval) + "\n"
		}
	}
	newSubtotal3 = eval(postage + morePostage)
	detailsTxt += "\n"
	
	// calculate tax 1
	tax = 0
	if(taxPercentage > 0) {
		taxCalcVal = subTotal - amountDiscountByTotal
		if(tax_inclShipping == 1) taxCalcVal += postage + morePostage
		taxAmount = taxPercentage * taxCalcVal / 100				// value in case tax option is set
		myTax = parent.frames[0].document.forms[0].customerTax.value		// tax option (taxPercentage or 0)
		if(myTax != 0) tax = taxAmount
		
		newSubtotal4 = newSubtotal3 + tax
		detailsTxt += "Tax = " + myTax + "% of " + price2Strg(taxCalcVal) + " = " + price2Strg(tax) + "\n"
		if(tax_inclShipping == 1) detailsTxt += "(tax includes shipping costs)\n\n"
		else			  detailsTxt += "(tax does not include shipping costs)\n\n"
		//detailsTxt += "new subtotal = " + price2Strg(newSubtotal3) + ' + ' + price2Strg(tax) + ' = ' + price2Strg(newSubtotal4) + "\n\n"
	}
	
	// calculate tax 2
	tax2 = 0
	if(tax2Percentage > 0) {
		tax2CalcVal = subTotal - amountDiscountByTotal + tax
		if(tax_inclShipping == 1) tax2CalcVal += postage + morePostage
		tax2Amount = tax2Percentage * tax2CalcVal / 100				// value in case tax option is set
		myTax2 = parent.frames[0].document.forms[0].customerTax2.value		// tax option (tax2Percentage or 0)
		if(myTax2 != 0) tax2 = tax2Amount
		
		newSubtotal5 = newSubtotal4 + tax2
		detailsTxt += "Tax 2 = " + myTax2 + "% of " + price2Strg(tax2CalcVal) + " = " + price2Strg(tax2) + "\n"
		if(tax_inclShipping == 1) detailsTxt += "(tax 2 includes shipping costs)\n\n"
		else			   detailsTxt += "(tax 2 does not include shipping costs)\n\n"
		//detailsTxt += "new subtotal = " + price2Strg(newSubtotal3) + ' + ' + price2Strg(tax) + ' = ' + price2Strg(newSubtotal4) + "\n\n"
	}
	
	// total value
	totalVal = subTotal - amountDiscountByTotal + postage + morePostage + tax + tax2
	
	detailsTxt += "TOTAL = " 
	detailsTxt 			+=       price2Strg(newSubtotal)
	if(postage > 0)	    detailsTxt	+= "+" + price2Strg(postage)
	if(morePostage > 0) detailsTxt	+= "+" + price2Strg(morePostage)
	if(tax > 0)	    detailsTxt	+= "+" + price2Strg(tax)
	if(tax2 > 0)	    detailsTxt	+= "+" + price2Strg(tax2)
	detailsTxt			+= " = "+price2Strg(totalVal) + "\n\n"
}

// print sub total
function printSubTotal() {
	if(subTotal != totalVal) {
		txt = '<td class="total tableGrad_1">' + txt_subtotal + ':</td>'
		txt+= '<td class="total" align="right">' + currency + price2Strg(subTotal) + '</td>'
		txt+= '<td></td>'
		document.write('<tr>' + txt + '</tr>\n')
	}
}

// print discount (by sub total)
function printDiscount() {
	minussign = '- '			// does not align vertical!
	// minus sign workarounds:
	minussign = '&ndash; '
	minussign = '<img src="minus.gif" width="6" height="2" hspace="6" align="absmiddle">'
	if(useDiscountByTotal == 1 && amountDiscountByTotal > 0) {
		txt = '<td class="total tableGrad_1"><a href="javascript:discountByTotalRules()">'
		txt+= txt_discount + '</a> (' + percentDiscountByTotal + '%):</td>'
		txt+= '<td class="total" align="right">' + minussign + currency + price2Strg(amountDiscountByTotal) + '</td>'
		txt+= '<td></td>'
		document.write('<tr>' + txt + '</tr>\n')
	}
}

// print shipping & handling
function printPostage(textonly) {
	if(shippingPercentage + shippingFixAmount + shippingPerItem == 0) return
	
	myPickupVal = parent.frames[0].document.forms[0].pickup.value
	if(textonly == 1 || selfPickup == 0) {
		txt = '<td class="total tableGrad_1">'
		txt+= '<a href="javascript:shippingRules()">' + txt_s_h + '</a>:</td>'
		txt+= '<td class="total" align="right">'
		txt+= currency + price2Strg(postage) + '</td>'
		txt+= '<td></td>'
	} else {
		if(myPickupVal == "")			// remember last setting
			selectPickup = ""
		else 	selectPickup = " selected"
		txt = '<td class="total tableGrad_1">'
		txt+= '<a href="javascript:shippingRules()">' + txt_s_h + '</a>:</td>'
		txt+= '<td class="total" align="right">'
		txt+= currency + '<select name="pickupSel" class="textfield" '
		txt+= 'onChange="thisPickup=this.options[this.selectedIndex].value; '
		txt+= '  parent.frames[0].document.forms[0].pickup.value=thisPickup; '
		txt+= '  calcTotal(); updateTaxFields(); updateTotalField()">'
		txt+= '<option value="">' + price2Strg(theo_postage) + '</option>'
		txt+= '<option value="y"' + selectPickup + '>' + txt_no_extra + '</option>'
		txt+= '</select></td>'
		if(textonly != 1) {
			txt+= '<td class="mini"> &larr; ' + pickup_note1 + '<br>'
			txt+= ' &larr; ' + pickup_note2 + '</td>'
		}
		else	txt+= '<td></td>'
	}
	document.write('<tr>' + txt + '</tr>\n')
}

// print all shipping options (w/ extra cost)
function printAllShipOptions(textonly) {
	for(i=0; i<shipOption.length; i++)
		if(shipOption[i]["used"] == 1) printShipOption(textonly, i)
}

// print one shipping option with selection field
function printShipOption(textonly, i) {
	txt = ""
	myADDval = eval('parent.frames[0].document.forms[0].shipOption_' + i + '.value')
	myADDval = parseInt(myADDval, 10) * 100			// selected value
	price    = parseInt(shipOption[i]["price"], 10) * 100	// default price
	if(textonly == 1) {
		if(myADDval > 0) {
			txt = '<td class="total tableGrad_1">' + shipOption[i]["title"] + ':</td>'
			txt+= '<td class="total" align="right">'
			txt+= currency + price2Strg(myADDval) + '</td>'
			txt+= '<td></td>'
		}
	} else {
		if(myADDval == 0)				// remember last setting
			selectNoADDval = " selected"
		else	selectNoADDval = ""
		txt = '<td class="total tableGrad_1">' + shipOption[i]["title"] + ':</td>'
		txt+= '<td class="total" align="right">'
		txt+= currency + '<select name="shipOption_' + i + '" class="textfield" '
		txt+= 'onChange="thisVal=this.options[this.selectedIndex].value; '
		txt+= '  parent.frames[0].document.forms[0].shipOption_' + i + '.value=thisVal; '
		txt+= '  calcTotal(); updateTaxFields(); updateTotalField()">'
		txt+= '<option value="' + shipOption[i]["price"] + '">' + price2Strg(price) + '</option>'
		txt+= '<option value="0"' + selectNoADDval + '>' + txt_no_extra + '</option>'
		txt+= '</select></td>'
		txt+= '<td></td>'
	}
	if(txt != "") document.write('<tr>' + txt + '</tr>\n')
}

// print tax
function printTax(textonly) {
	txt = ""
	if(taxPercentage > 0) {
		myTax = parent.frames[0].document.forms[0].customerTax.value
		if(textonly == 1) {
			if(myTax > 0) {
				txt = '<td class="total tableGrad_1">' + txt_tax + ' (' + taxPercentage + '%):</td>'
				txt+= '<td class="total" align="right">'
				txt+= currency + price2Strg(tax) + '</td>'
				txt+= '<td></td>'
			}
		} else {
		    if(taxAlways == 1) {
			txt = '<td class="total tableGrad_1">' + txt_tax + ' (' + taxPercentage + '%):</td>'
			txt+= '<td class="total" align="right">'
			txt+= currency + '<select name="tax" class="textfield">'
			txt+= '<option value="'+ taxPercentage +'">' + price2Strg(tax) + '</option>'
			txt+= '</select></td>'
			txt+= '<td></td>'
		    } else {
			if(myTax == 0) {				// remember last setting
					selectTaxNO  = " selected"
					selectTaxYES = ""
			} else {	selectTaxYES = " selected"
					selectTaxNO = ""
			}
			txt = '<td class="total tableGrad_1">' + txt_tax + ' (' + taxPercentage + '%):</td>'
			txt+= '<td class="total" align="right">'
			txt+= currency + '<select name="tax" class="textfield" '
			txt+= 'onChange="thisTax=this.options[this.selectedIndex].value; '
			txt+= '  parent.frames[0].document.forms[0].customerTax.value=thisTax; '
			txt+= '  calcTotal(); updateTotalField()">'
			txt+= '<option value="'+ taxPercentage +'"' + selectTaxYES + '>' + price2Strg(tax) + '</option>'
			txt+= '<option value="0"' + selectTaxNO + '>' + price2Strg(0) + '</option>'
			txt+= '</select></td>'
			if(taxCountry != "") {
				txt+= '<td class="mini"> &larr; ' + tax_note1 +' '+ price2Strg(0) +' '+ tax_note2 + '<br>'
				txt+= ' &larr; ' + tax_note3 +' '+ taxCountry + '.</td>'
			}
		    }
		}
	}
	if(txt != "") document.write('<tr>' + txt + '</tr>\n')
	
	printTax2(textonly)
}

// print tax 2
function printTax2(textonly) {
	txt = ""
	if(tax2Percentage > 0) {
		myTax2 = parent.frames[0].document.forms[0].customerTax2.value
		if(textonly == 1) {
			if(myTax2 > 0) {
				txt = '<td class="total tableGrad_1">' + txt_tax2 + ' (' + tax2Percentage + '%):</td>'
				txt+= '<td class="total" align="right">'
				txt+= currency + price2Strg(tax2) + '</td>'
				txt+= '<td></td>'
			}
		} else {
		    if(tax2Always == 1) {
			txt = '<td class="total tableGrad_1">' + txt_tax2 + ' (' + tax2Percentage + '%):</td>'
			txt+= '<td class="total" align="right">'
			txt+= currency + '<select name="tax2" class="textfield">'
			txt+= '<option value="'+ tax2Percentage +'">' + price2Strg(tax2) + '</option>'
			txt+= '</select></td>'
			txt+= '<td></td>'
		    } else {
			if(myTax2 == 0) {				// remember last setting
					selectTaxNO  = " selected"
					selectTaxYES = ""
			} else {	selectTaxYES = " selected"
					selectTaxNO = ""
			}
			txt = '<td class="total tableGrad_1">' + txt_tax2 + ' (' + tax2Percentage + '%):</td>'
			txt+= '<td class="total" align="right">'
			txt+= currency + '<select name="tax2" class="textfield" '
			txt+= 'onChange="thisTax=this.options[this.selectedIndex].value; '
			txt+= '  parent.frames[0].document.forms[0].customerTax2.value=thisTax; '
			txt+= '  calcTotal(); updateTotalField()">'
			txt+= '<option value="'+ tax2Percentage +'"' + selectTaxYES + '>' + price2Strg(tax2) + '</option>'
			txt+= '<option value="0"' + selectTaxNO + '>' + price2Strg(0) + '</option>'
			txt+= '</select></td>'
			if(tax2Country != "") {
				txt+= '<td class="mini"> &larr; ' + tax_note1 +' '+ price2Strg(0) +' '+ tax_note2 + '<br>'
				txt+= ' &larr; ' + tax_note3 +' '+ tax2Country + '.</td>'
			}
		    }
		}
	}
	if(txt != "") document.write('<tr>' + txt + '</tr>\n')
}

// print total
function printTotal(textonly) {
	if(textonly == 1) lineSep = ' style="border-top:2px solid black"'
	else 		  lineSep = ''
	txt = '<td class="total"' + lineSep + '>' + txt_total + ':</td>'
	txt+= '<td class="total"' + lineSep + ' align="right">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
	if(textonly == 1) {
		txt+= currency + price2Strg(totalVal) + '</td>'
		txt+= '<td></td>'
	} else {
		totalStrg = price2Strg(totalVal)
		txt+= currency + '<input type="text" name="total" size="' + totalStrg.length + '" class="textfield"'
		txt+= ' value="' + totalStrg + '" onFocus="this.blur()"></td>'
	}
	txt+= '<td></td>'
	document.write('<tr>' + txt + '</tr>\n')
	
	if(textonly != 1 && showCalcDetails == 1)
	document.write('<tr><td class="mini tableGrad_2" colspan="2" align="right"><a href="javascript:alert(detailsTxt)">' + calc_details + '</a></td><td></td></tr>')
}

// update tax field (if calculated with postage)
function updateTaxFields() {
	if(tax_inclShipping == 1) {
		if(taxPercentage > 0) {
			document.forms[0].tax.options[0].text  = price2Strg(taxAmount)
			document.forms[0].tax.options[0].value = taxPercentage		// set value after text change!
		}
		if(tax2Percentage > 0) {
			document.forms[0].tax2.options[0].text  = price2Strg(tax2Amount)
			document.forms[0].tax2.options[0].value = tax2Percentage		// set value after text change!
		}
	}
}

// update total field
function updateTotalField() {
	document.forms[0].total.value = price2Strg(totalVal)
}

// print contact information as Text
function printContactText() {
	txt = ""
	if(myName	!= "") txt+= myName	+ "\n"
	if(myStreet	!= "") txt+= myStreet	+ "\n"
	if(zip_del == " ")
	if(myZip	!= "") txt+= myZip	+ zip_del
	if(myCity	!= "") txt+= myCity	+ city_del
	if(myState	!= "") txt+= myState	+ state_del
	if(zip_del != " ")
	if(myZip	!= "") txt+= myZip	+ zip_del
	if(myCountry	!= "") txt+= myCountry	+ "\n"
	if(myPhone1	!= "") txt+= txt_phone + ": "  + myPhone1	+ "\n"
	if(myPhone2	!= "") txt+= "       "  + myPhone2	+ "\n"
	if(myFax	!= "") txt+= txt_fax + ":   "  + myFax		+ "\n"
	if(myEmail	!= "") txt+= myEmail	+ "\n"
	if(myWWW	!= "") txt+= myWWW	+ "\n"
	return(txt)
}

// print contact information in HTML
function printContactHtml(style) {
	// change \n to <br>
	zip_del_br   = (zip_del.indexOf("\n")   >= 0) ? "<br>" : zip_del
	city_del_br  = (city_del.indexOf("\n")  >= 0) ? "<br>" : city_del
	state_del_br = (state_del.indexOf("\n") >= 0) ? "<br>" : state_del

	txt = ""
	txt+= '<p class="' + style + '">'
	if(myName	!= "") txt+= "<b>"      + myName	+ "</b><br>\n"
	if(myStreet	!= "") txt+= myStreet	+ "<br>\n"
	if(zip_del == " ")
	if(myZip	!= "") txt+= myZip	+ zip_del_br
	if(myCity	!= "") txt+= myCity	+ city_del_br
	if(myState	!= "") txt+= myState	+ state_del_br
	if(zip_del != " ")
	if(myZip	!= "") txt+= myZip	+ zip_del_br
	if(myCountry	!= "") txt+= myCountry	+ "<br>\n"
	if(myPhone1	!= "") txt+= txt_phone + ": "  + myPhone1	+ "<br>\n"
	if(myPhone2	!= "") txt+= myPhone2	+ "<br>\n"
	if(myFax	!= "") txt+= txt_fax + ": "    + myFax		+ "<br>\n"
	if(myEmail	!= "") txt+= txt_email + ': <a href="mailto:' + myEmail + '">' + myEmail + '</a><br>\n'
	if(myWWW	!= "") txt+= '<a href="http://' + myWWW + '" target="_blank">' + myWWW + '</a><br>\n'
	txt+= "</p>"
	document.write(txt)
}

// print customer information as Text
function printCustomerInfoText(f) {
	zip_del_bl   = (zip_del.indexOf("\n")   >= 0) ? "\n  " : zip_del
	city_del_bl  = (city_del.indexOf("\n")  >= 0) ? "\n  " : city_del
	state_del_bl = (state_del.indexOf("\n") >= 0) ? "\n  " : state_del

	txt = "  "
	if(f.realname.value	!= "") txt+= f.realname.value	+ "\n  "
	if(f.addr1.value	!= "") txt+= f.addr1.value	+ "\n  "
	if(f.addr2.value	!= "") txt+= f.addr2.value	+ "\n  "
	if(zip_del == " ")
	if(f.zip.value		!= "") txt+= f.zip.value	+ zip_del_bl
	if(f.city.value		!= "") txt+= f.city.value	+ city_del_bl
	if(f.state.value	!= "") txt+= f.state.value	+ state_del_bl
	if(zip_del != " ")
	if(f.zip.value		!= "") txt+= f.zip.value	+ zip_del_bl
	if(f.country.value	!= "") txt+= f.country.value	+ "\n  "
	if(f.phone.value	!= "") txt+= txt_phone + ": "  + f.phone.value	+ "\n  "
	if(f.phone2.value	!= "") txt+= "       "  + f.phone2.value+ "\n  "
	if(f.fax.value		!= "") txt+= txt_fax + ":   "  + f.fax.value	+ "\n  "
	if(f.email.value	!= "") txt+= f.email.value	+ "\n  "
	if(f.email2.value	!= "") txt+= f.email2.value	+ "\n  "
	if(parent.frames[0].document.forms[0].ccc.value != "") {
	  			       txt+= "\n" + txt_cc + ":\n  "
	  			       txt+= f.ccname.value + "\n  "
	  			       txt+= parent.frames[0].document.forms[0].ccc.value
	  			       txt+= " #" + f.ccnum.value.substring(0,4) + " ____ ____ ____\n  "
	  			       txt+= txt_ccexp + ": " + f.ccexp.value + "\n  "
	  			       txt+= txt_cc3dc + ": " + f.cc3dc.value + "\n"
	}
	// feature for DQ
	if(CheckboxInfo1.indexOf("#finishing") > 0)
		CheckboxInfo1_txt = CheckboxInfo1.replace(/<br><a href.*#finishing.*a>/g, "")
	else	CheckboxInfo1_txt = CheckboxInfo1
	// end
	if(parent.frames[0].document.forms[0].info1.value	!= "") txt+= "\n" + CheckboxInfo1_txt + "\n"
	if(parent.frames[0].document.forms[0].info2.value	!= "") txt+= "\n" + CheckboxInfo2 + "\n"
	if(parent.frames[0].document.forms[0].info3.value	!= "") txt+= "\n" + CheckboxInfo3 + "\n"
	if(f.comments.value	!= "") txt+= "\n" + txt_comment + ":\n"	+ f.comments.value + "\n\n"
	return(txt)
}

// print customer information in HTML
function printCustomerInfo(f) {
	// change \n to <br>
	zip_del_br   = (zip_del.indexOf("\n")   >= 0) ? "<br>" : zip_del
	city_del_br  = (city_del.indexOf("\n")  >= 0) ? "<br>" : city_del
	state_del_br = (state_del.indexOf("\n") >= 0) ? "<br>" : state_del

	txt = ""
	if(f.realname.value	!= "") txt+= f.realname.value	+ "<br>\n"
	if(f.addr1.value	!= "") txt+= f.addr1.value	+ "<br>\n"
	if(f.addr2.value	!= "") txt+= f.addr2.value	+ "<br>\n"
	if(zip_del == " ")
	if(f.zip.value		!= "") txt+= f.zip.value	+ zip_del_br
	if(f.city.value		!= "") txt+= f.city.value	+ city_del_br
	if(f.state.value	!= "") txt+= f.state.value	+ state_del_br
	if(zip_del != " ")
	if(f.zip.value		!= "") txt+= f.zip.value	+ zip_del_br
	if(f.country.value	!= "") txt+= f.country.value	+ "<br>\n"
	if(f.phone.value	!= "") txt+= txt_phone + ": "  + f.phone.value	+ "<br>\n"
	if(f.phone2.value	!= "") txt+= f.phone2.value	+ "<br>\n"
	if(f.fax.value		!= "") txt+= txt_fax + ": "    + f.fax.value	+ "<br>\n"
	if(f.email.value	!= "") txt+= txt_email + ': <a href="mailto:' + f.email.value + '">' + f.email.value + '</a><br>\n'
	if(f.email2.value	!= "") txt+= '<a href="mailto:' + f.email2.value + '">' + f.email2.value + '</a><br>\n'
	if(parent.frames[0].document.forms[0].ccc.value != "") {
	  			       txt+= "<br>" + txt_cc + ":<br>\n"
	  			       txt+= f.ccname.value + "<br>\n"
	  			       txt+= parent.frames[0].document.forms[0].ccc.value
	  			       txt+= " #" + f.ccnum.value.substring(0,4) + " ____ ____ ____<br>\n"
	  			       txt+= txt_ccexp + ": " + f.ccexp.value + "<br>\n"
	  			       txt+= txt_cc3dc + ": " + f.cc3dc.value + "<br>\n"
	}
	if(parent.frames[0].document.forms[0].info1.value	!= "") txt+= "<br>" + CheckboxInfo1 + "<br>"
	if(parent.frames[0].document.forms[0].info2.value	!= "") txt+= "<br>" + CheckboxInfo2 + "<br>"
	if(parent.frames[0].document.forms[0].info3.value	!= "") txt+= "<br>" + CheckboxInfo3 + "<br>"
	if(f.comments.value	!= "") txt+= '<br>' + txt_comment + ':<br><table border="1" cellspacing="0" cellpadding="5"><tr><td><pre>' + f.comments.value + '</pre></td></tr></table>\n'
	document.write(txt)
}

// print customer information hidden fields (in top frame)
function printCustomerHiddenFields() {
	txt = ""
	txt+= '<input type="hidden" name="realname"	value="">\n'
	txt+= '<input type="hidden" name="addr1"	value="">\n'
	txt+= '<input type="hidden" name="addr2"	value="">\n'
	txt+= '<input type="hidden" name="city"		value="">\n'
	txt+= '<input type="hidden" name="state"	value="">\n'
	txt+= '<input type="hidden" name="zip"		value="">\n'
	txt+= '<input type="hidden" name="country"	value="">\n'
	txt+= '<input type="hidden" name="phone"	value="">\n'
	txt+= '<input type="hidden" name="phone2"	value="">\n'
	txt+= '<input type="hidden" name="fax"		value="">\n'
	txt+= '<input type="hidden" name="email"	value="">\n'
	txt+= '<input type="hidden" name="email2"	value="">\n'
	txt+= '<input type="hidden" name="info1"	value="">\n'
	txt+= '<input type="hidden" name="info2"	value="">\n'
	txt+= '<input type="hidden" name="info3"	value="">\n'
	txt+= '<input type="hidden" name="pickup"	value="">\n'
	txt+= '<input type="hidden" name="ccc"		value="">\n'
	txt+= '<input type="hidden" name="ccname"	value="">\n'
	txt+= '<input type="hidden" name="ccnum"	value="">\n'
	txt+= '<input type="hidden" name="ccexp"	value="">\n'
	txt+= '<input type="hidden" name="cc3dc"	value="">\n'
	txt+= '<input type="hidden" name="comments"	value="">\n'
	for(i=0; i<shipOption.length; i++)
		txt+= '<input type="hidden" name="shipOption_' + i + '"  value="0">\n'
	txt+= '<input type="hidden" name="customerTax"  value="' + taxPercentage + '">\n'
	txt+= '<input type="hidden" name="customerTax2" value="' + tax2Percentage + '">\n'
	document.write(txt)
}

// copy customer information to hidden fields in top frame
function saveCustomerInfo(from,to) {
	if(parent.frames[0].document.forms[0].noi.value > 0) {
		to.realname.value	= from.realname.value
		to.addr1.value		= from.addr1.value
		to.addr2.value		= from.addr2.value
		to.city.value		= from.city.value
		to.state.value		= from.state.value
		to.zip.value		= from.zip.value
		to.country.value	= from.country.value
		to.phone.value		= from.phone.value
		to.phone2.value		= from.phone2.value
		to.fax.value		= from.fax.value
		to.email.value		= from.email.value
		to.email2.value		= from.email2.value
		to.ccname.value		= from.ccname.value
		to.ccnum.value		= from.ccnum.value
		to.ccexp.value		= from.ccexp.value
		to.cc3dc.value		= from.cc3dc.value
		to.comments.value	= from.comments.value
	}
}

// print the customer input fields
function printCustomerInputFields() {
	printCustomerInputData(txt_name       ,"realname")
	printCustomerInputData(txt_addr+" 1"  ,"addr1"   )
	printCustomerInputData(txt_addr+" 2"  ,"addr2"   )
	printCustomerInputData(txt_city       ,"city"    )
	printCustomerInputData(txt_state      ,"state"   )
	printCustomerInputData(txt_zip        ,"zip"     )
	printCustomerInputData(txt_country    ,"country" )
	printCustomerInputData(txt_phone      ,"phone"   )
	printCustomerInputData(txt_phone+" 2" ,"phone2"  )
	printCustomerInputData(txt_fax        ,"fax"     )
	printCustomerInputData(txt_email      ,"email"   )
	printCustomerInputData(txt_email+" 2" ,"email2"  )
	// Credit Card
	printCustomerInputCreditcard()
	// Checkboxes
	printCustomerInputCheckbox(CheckboxInfo1  ,"info1" )
	printCustomerInputCheckbox(CheckboxInfo2  ,"info2" )
	printCustomerInputCheckbox(CheckboxInfo3  ,"info3" )
	// Comments
	document.write('<tr><td valign="top">' + txt_comment + ': </td>')
	document.write('    <td><TEXTAREA name="comments" rows="5" cols="30" wrap="hard">')
	document.write(parent.frames[0].document.forms[0].comments.value + '</textarea></td></tr>')
}

// print the customer input fields
function printCustomerInputData(fieldname, varname) {
	customer_realname = 2		// always mandatory!
	varvalue = eval('parent.frames[0].document.forms[0].' + varname + '.value')
	prio = eval('customer_' + varname)
	if(prio > 0) {
		txt = '<tr><td valign="top"> ' + fieldname + ':</td>'
		txt+= '<td><input type="text" size="32" name="' + varname + '" '
		txt+= 'class="textfield" value="' + varvalue + '">'
		if(prio == 2) txt+= ' *'
		txt+= '</td></tr>\n'
		document.write(txt)
	} else {
		document.write('<input type="hidden" name="' + varname + '" value="">')
	}
}

// print the customer input checkbox(es)
function printCustomerInputCheckbox(fieldname, varname) {
	if(fieldname != "") {
		varvalue = eval('parent.frames[0].document.forms[0].' + varname + '.value')
		if(varvalue != "") chk = " checked"
		else		   chk = ""
		txt = '<tr><td valign="top" align="right"><input type="checkbox" name="' + varname + '_box"'
		txt+= chk + ' onClick="if(this.checked) parent.frames[0].document.forms[0].' + varname + '.value=\'y\'; '
		txt+= 'else parent.frames[0].document.forms[0].' + varname + '.value=\'\'"></td>'
		txt+= '<td>' + fieldname + '</td></tr>\n'
		document.write(txt)
	}
}

// print the customer credit card fields
function printCustomerInputCreditcard() {
	if(acceptCC != "") {
		varvalue = parent.frames[0].document.forms[0].ccc.value
		txt = '<tr><td> ' + txt_cc + ':</td>'
		txt+= '<td><select class="textfield" onChange="parent.frames[0].document.forms[0].ccc.value='
		txt+= 'this.options[this.selectedIndex].value">'
		txt+= '<option value="">--------</option>'
		i = 0
		ccc_name = acceptCC.split(",")
		while (i < ccc_name.length) {
			if(ccc_name[i] == varvalue) sel = " selected"
			else			    sel = ""
			if(ccc_name[i] != "") {
				txt+= '<option value="' + ccc_name[i] + '"' + sel + '>' + ccc_name[i] + '</option>'
			}
			i++
		}
		txt+= '</select></td></tr>\n'

		varvalue = parent.frames[0].document.forms[0].ccname.value
		txt+= '<tr><td> ' + txt_ccname + ':</td>'
		txt+= '<td valign="top"><input type="text" size="32" name="ccname" '
		txt+= 'class="textfield" value="' + varvalue + '">'
		txt+= '</td></tr>\n'

		varvalue = parent.frames[0].document.forms[0].ccnum.value
		txt+= '<tr><td> ' + txt_ccnum + ':</td>'
		txt+= '<td valign="top"><input type="text" size="32" name="ccnum" '
		txt+= 'class="textfield" value="' + varvalue + '">'
		txt+= '</td></tr>\n'
		
		varvalue = parent.frames[0].document.forms[0].ccexp.value
		if(varvalue == "") varvalue = "mm/yyyy"
		txt+= '<tr><td> ' + txt_ccexp + ':</td>'
		txt+= '<td valign="top"><input type="text" size="32" name="ccexp" '
		txt+= 'class="textfield" value="' + varvalue + '" '
		txt+= 'onFocus="if(this.value==\'mm/yyyy\') this.value=\'\'">'
		txt+= '</td></tr>\n'
		
		varvalue = parent.frames[0].document.forms[0].cc3dc.value
		txt+= '<tr><td> ' + txt_cc3dc + ':<br><span class="mini">' + txt_cc3dc_info + '</span></td>'
		txt+= '<td valign="top"><input type="text" size="32" name="cc3dc" '
		txt+= 'class="textfield" value="' + varvalue + '">'
		txt+= '</td></tr>\n'
		
		document.write(txt)
	} else {
		document.write('<input type="hidden" name="ccname" value="">')
		document.write('<input type="hidden" name="ccnum" value="">')
		document.write('<input type="hidden" name="ccexp" value="">')
		document.write('<input type="hidden" name="cc3dc" value="">')
	}
}

// calculate discount by copies
function calcDiscountByCopies(qty) {
	var percentDiscount = 0
	for(copies in discountByCopies) {
		if(qty >= copies && discountByCopies[copies] > percentDiscount)
			percentDiscount = discountByCopies[copies]
	}
	return percentDiscount
}

// calculate discount after total
function calcDiscountByTotal(subtotal) {
	var percentDiscount = 0
	for(value in discountByTotal) {
		if(subtotal >= value*100 && discountByTotal[value] > percentDiscount)
			percentDiscount = discountByTotal[value]
	}
	return percentDiscount
}

// alert with the shipping rules
function shippingRules() {
	txt = s_h_calculation + ":\n\n"
	if(shippingPercentage > 0) txt += shippingPercentage + "% " + txt_sh_perc + "\n"
	if(shippingPerItem    > 0) txt += currTxt + shippingPerItem + " " + txt_sh_item + "\n"
	if(shippingPercentage > 0 ||
	   shippingPerItem    > 0) if(shippingFixAmount  > 0) txt += txt_sh_plus + " "
	if(shippingFixAmount  > 0) txt += txt_sh_fix + " " + currTxt + shippingFixAmount + "\n\n"
	alert(txt)
}

// alert with the discount (by total) rules
function discountByTotalRules() {
	txt = discount_sub + ":\n\n"
	for(value in discountByTotal) {
		txt += disc_sub1 +" "+ currTxt + value +" "+ disc_sub2 +" "+ discountByTotal[value] + "% " + disc_sub3 + "\n"
	}
	alert(txt + "\n")
}

// alert with the discount (by copies) rules
function discountByCopiesRules() {
	txt = discount_copies + ":\n\n"
	for(copies in discountByCopies) {
		txt += copies + " " + disc_cop1 + ": " + discountByCopies[copies] + "% " + disc_cop2 + "\n"
	}
	alert(txt + "\n")
}

// print text file as popup
function show_TextFile () {
	txt = "<html><title>" + order_prefix + orderTitle + "</title><body><pre>"
	txt+= format_order()
	txt+= "</pre></body></html>"
	
        Size    = "width=340,height=600,left=0,top=0"
        Options = "status=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes," + Size
        TextWin    = open("", "TextOrder", Options)
	TextWin.document.write(txt)
        TextWin.document.close()
        TextWin.focus()
}

// misc. Validation functions
function checkCustomerForm() {
	var errMsg = ""	
	errMsg += checkCustomerData(txt_name      ,"realname")
	errMsg += checkCustomerData(txt_addr+" 1" ,"addr1"   )
	errMsg += checkCustomerData(txt_addr+" 2" ,"addr2"   )
	errMsg += checkCustomerData(txt_city      ,"city"    )
	errMsg += checkCustomerData(txt_zip       ,"zip"     )
	errMsg += checkCustomerData(txt_state     ,"state"   )
	errMsg += checkCustomerData(txt_country   ,"country" )
	errMsg += checkCustomerData(txt_phone     ,"phone"   )
	errMsg += checkCustomerData(txt_phone+" 2","phone2"  )
	errMsg += checkCustomerData(txt_fax       ,"fax"     )
	errMsg += checkCustomerData(txt_email     ,"email"   )
	errMsg += checkCustomerData(txt_email+" 2","email2"  )

	errMsg += checkCreditcardData()

	if (errMsg != "") {
		alert(errMsg)
		return false
	}
	else	return true
}

// misc. Validation functions
function checkCustomerData(fieldname, varname) {
	var err = ""
	customer_realname = 2		// always mandatory!
	varvalue = eval('document.forms[0].' + varname + '.value')
	prio = eval('customer_' + varname)
	if(prio == 2) {
		if(varname.indexOf("phone") >= 0) {
			err += checkPhone(varvalue, fieldname)
		} else {
		  if(varname.indexOf("email") >= 0)
			err += checkEmail(varvalue, fieldname)
		  else
			err += isEmpty(varvalue, fieldname)
		}
		//err += checkDropdown(f.choose.selectedIndex)
	}
	return err
}

// CC validation function
function checkCreditcardData() {
	var err = ""
	return err
}

// Print form for eosmail script
function printEOSform() {
	document.write('<FORM action="' + eosmail_script + '" method="POST" name="eosmail" target="eosmail">')
	document.write('<input type="hidden" name="email_address" value="' + email_address + '">')
	document.write('<input type="hidden" name="email_subject" value="' + email_subject + '">')
	document.write('<input type="hidden" name="gallery_title" value="' + orderTitle    + '">')
	document.write('<input type="hidden" name="myName"	  value="' + myName        + '">')
	document.write('<input type="hidden" name="myEmail"	  value="' + myEmail       + '">')
	document.write('<input type="hidden" name="ppCurrency"	  value="' + ppCurrency    + '">')
	document.write('<input type="hidden" name="paypalAccount" value="' + paypalAccount + '">')
	document.write('<input type="hidden" name="sid_2checkout" value="' + sid_2checkout + '">')
	document.write('<input type="hidden" name="demo_2checkout" value="'+ demo_2checkout+ '">')
	document.write('<input type="hidden" name="items"	  value="">')
	document.write('<input type="hidden" name="total"	  value="">')
	document.write('<input type="hidden" name="subtotal"	  value="">')
	document.write('<input type="hidden" name="shipping"	  value="">')
	document.write('<input type="hidden" name="tax"		  value="">')
	
	document.write('<input type="hidden" name="cust_name"	  value="">')
	document.write('<input type="hidden" name="cust_addr1"	  value="">')
	document.write('<input type="hidden" name="cust_addr2"	  value="">')
	document.write('<input type="hidden" name="cust_city"	  value="">')
	document.write('<input type="hidden" name="cust_state"	  value="">')
	document.write('<input type="hidden" name="cust_zip"	  value="">')
	document.write('<input type="hidden" name="cust_country"  value="">')
	document.write('<input type="hidden" name="cust_phone"	  value="">')
	document.write('<input type="hidden" name="cust_phone2"	  value="">')
	document.write('<input type="hidden" name="cust_fax"	  value="">')
	document.write('<input type="hidden" name="cust_email"	  value="">')
	document.write('<input type="hidden" name="cust_email2"	  value="">')
	document.write('<input type="hidden" name="cust_ccc"	  value="">')
	document.write('<input type="hidden" name="cust_ccname"	  value="">')
	document.write('<input type="hidden" name="cust_ccnum"	  value="">')
	document.write('<input type="hidden" name="cust_ccexp"	  value="">')
	document.write('<input type="hidden" name="cust_cc3dc"	  value="">')
                                                                            
	document.write('<input type="hidden" name="checkout"	  value="">')
	document.write('<input type="hidden" name="returnLink"    value="">')		// document.location.href + "_end"
	document.write('<input type="hidden" name="info1"	  value="">')
	document.write('<input type="hidden" name="info2"	  value="">')
	document.write('<input type="hidden" name="info3"	  value="">')
	document.write('<input type="hidden" name="order_text"    value="">')
	document.write('<input type="hidden" name="tagged"        value="">')
	document.write('</form>')
}

// alert message before submitting online
function submit_online (checkout) {
	if (document.location.href.indexOf("http://www.peterberger.at") == 0) {
		mailAlert = "This is a demo version, no e-mail will be sent.\n"
		mailAlert+= "But you will see in a new window how it would look like.\n\n"
		mailAlert+= "Please press \"OK\" to proceed.\n"
		
		paypalAlert = "This is a demo version, no e-mail will be sent.\n"
		paypalAlert+= "But you will be forwarded to the paypal site.\n"
		paypalAlert+= "Do not pay - none of the pictures are for sale!\n\n"
		paypalAlert+= "Please press \"OK\" to proceed.\n"
		
		_2checkoutAlert = "This is a demo version, no e-mail will be sent.\n"
		_2checkoutAlert+= "But you will be forwarded to the 2checkout site.\n"
		_2checkoutAlert+= "You can even pay - the transaction is in demo mode!\n\n"
		_2checkoutAlert+= "Please press \"OK\" to proceed.\n"
		
		if(checkout == "eosmail")	checkout = "test"
		if(checkout == "paypal")	checkout = "paypal0"
		if(checkout == "2checkout")	checkout = "2checkout0"
	}

	txt = ""
	if(checkout == "formmail") txt = mailAlert
	if(checkout == "eosmail" || checkout == "test") txt = mailAlert
	if(checkout.indexOf("paypal")    == 0)          txt = paypalAlert
	if(checkout.indexOf("2checkout") == 0)          txt = _2checkoutAlert
	if(txt == "" || confirm(txt)) {
		if(checkout == "formmail")
			document.orders.submit()
		else {
			document.eosmail.items.value		= parent.frames[0].document.forms[0].noi.value
			document.eosmail.total.value		= price2Strg(totalVal)
			document.eosmail.subtotal.value		= price2Strg(newSubtotal)	// incl. discount calc.
			document.eosmail.shipping.value		= price2Strg(postage+morePostage+0)
			document.eosmail.tax.value		= price2Strg(tax+tax2+0)
			
			document.eosmail.cust_name.value	= document.orders.realname.value
			document.eosmail.cust_addr1.value	= document.orders.addr1.value
			document.eosmail.cust_addr2.value	= document.orders.addr2.value
			document.eosmail.cust_city.value	= document.orders.city.value
			document.eosmail.cust_state.value	= document.orders.state.value
			document.eosmail.cust_zip.value		= document.orders.zip.value
			document.eosmail.cust_country.value	= document.orders.country.value
			document.eosmail.cust_phone.value	= document.orders.phone.value
			document.eosmail.cust_phone2.value	= document.orders.phone2.value
			document.eosmail.cust_fax.value		= document.orders.fax.value
			document.eosmail.cust_email.value	= document.orders.email.value
			document.eosmail.cust_email2.value	= document.orders.email2.value
			document.eosmail.cust_ccc.value		= parent.frames[0].document.forms[0].ccc.value
			document.eosmail.cust_ccname.value	= document.orders.ccname.value
			document.eosmail.cust_ccnum.value	= document.orders.ccnum.value
			if(document.orders.ccexp.value != "mm/yyyy")
			document.eosmail.cust_ccexp.value	= document.orders.ccexp.value
			document.eosmail.cust_cc3dc.value	= document.orders.cc3dc.value

			document.eosmail.checkout.value		= checkout			// eosmail, 2checkout, paypal, test
			document.eosmail.returnLink.value	= returnLink
			document.eosmail.info1.value		= parent.frames[0].document.forms[0].info1.value
			document.eosmail.info2.value		= parent.frames[0].document.forms[0].info2.value
			document.eosmail.info3.value		= parent.frames[0].document.forms[0].info3.value
			document.eosmail.tagged.value		= TagFile
			document.eosmail.order_text.value	= replaceHTMLtags(format_order())
			document.eosmail.submit()
		}
	}
} 
 
// Pop up a local e-mail client window
function popup_email() {  
	var to		= myEmail
	var subject	= email_subject + ' ' + orderTitle
	var body	= replaceHTMLtags(format_order())
	
	if(navigator.appName == "Netscape") body = body.replace(/\n/g, "<br>")

	var doc	= "mailto:" + to + "?subject=" + escape(subject) + "&body=" + escape(body) 
	window.location = doc
}

// format the order
function format_order () {
	del = "-------------------------\n"
	TaxStr = txt_tax  + " (" + taxPercentage  + "%):"
	Tax2Str= txt_tax2 + " (" + tax2Percentage + "%):"
	DscStr = txt_discount + "/" + percentDiscountByTotal + "%:"

	txt = ""
	txt+= '\n' + order_prefix + '\n"' + orderTitle + '"\n'
	txt+= del
	txt+= TextFile + "\n" + del
	// summary
	if(subTotal < totalVal)
	txt+= middlePad(txt_subtotal+":", currency + price2Strg(subTotal)) + "\n"
	if(amountDiscountByTotal > 0)
	txt+= middlePad(DscStr, "-" + currency + price2Strg(amountDiscountByTotal)) + "\n"		
	if(postage > 0)
	txt+= middlePad(txt_s_h+":"    , currency + price2Strg(postage)) + "\n"
	for(var i=0; i<shipOption.length; i++) {
		if(shipOption[i]["used"] == 1) {
			myADDval = eval('parent.frames[0].document.forms[0].shipOption_' + i + '.value')
			myADDval = parseInt(myADDval, 10) * 100
			if(myADDval > 0)	// show only if selected
			  txt+= middlePad(shipOption[i]["title"], currency + price2Strg(myADDval)) + "\n"
		}
	}
	if(tax > 0)
	txt+= middlePad(TaxStr      , currency + price2Strg(tax)) + "\n"
	if(tax2 > 0)
	txt+= middlePad(Tax2Str     , currency + price2Strg(tax2)) + "\n"
	txt+= del
	txt+= middlePad(txt_total+":"    , currency + price2Strg(totalVal)) + "\n"
	txt+= del
	txt+= "\n" + customer_info + ":\n"
	txt+= printCustomerInfoText(document.forms[0])
	txt+= "\n"
	txt+= del
	txt+= thank_you + "\n"
	txt+= del
	txt+= printContactText()

	return (txt)
}

// -------------------------------
//
//  V A R I O U S   Scripts
//
// -------------------------------

function alertUpdateMsg(diff) {
	alert(update_alert)
}

function stripFileExtension(fn) {
	lastDot = fn.lastIndexOf('.')
	if(noFileExtension == 1 && lastDot > 0) 
		return fn.substring(0, fn.lastIndexOf('.'))
	else	return fn
}

function replaceHTMLtags(txt) {
	txt = txt.replace(/&amp;/g,   "&")
	txt = txt.replace(/<br>/g,    "\n")
	txt = txt.replace(/&nbsp;/g,  " ")
	txt = txt.replace(/&euro;/g,  "EUR ")
	txt = txt.replace(/&pound;/g, "GBP ")
	return txt
}

function isEmpty(arg, fieldname) {
	var err = ""
	if (arg.length == 0) {
		err = txt_the + " " + fieldname + " " + txt_is_empty + "\n"
	}
	return err
}

function checkDropdown(choice) {
	var err = ""
	if (choice == 0) {
		err = "You didn't choose an option from the drop-down list.\n"
	}
	return err
}

function checkPhone (arg, fieldname) {
	var err = ""
	if (arg == "") {
		err = txt_the + " " + fieldname + " " + txt_is_empty + "\n"
		return err
	}

	var stripped = arg.replace(/[\(\)\.\-\ ]/g, '') 	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
		err = txt_the + " " + fieldname + " " + txt_no_number + "\n"
	}
	//    if (!(stripped.length == 10)) {
	//	err = "The phone number is the wrong length. Make sure you included an area code.\n"
	//    }
	return err
}

function checkEmail (arg, fieldname) {
	var err = ""
	if (arg == "") {
		err = txt_the + " " + fieldname + " " + txt_is_empty + "\n"
		return err;
	}

	var emailFilter=/^.+@.+\..{2,3}$/
	if (!(emailFilter.test(arg))) {
		err = txt_no_email + " " + fieldname + ".\n"
	}
	else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (arg.match(illegalChars)) {
		   err = txt_the + " " + fieldname + " " + txt_ill_char + "\n"
		}
	}
	return err;
}

function isValidEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress)
}

function onlyNumbers(arg) {
	arg    = arg.replace(/\s+/g,"");	// delete all spaces
	if (! /^\d+$/.test(arg)) {
		alert('"' + arg + '" ' + qty_no_number + '\n')
		return "0"
	}
	else	return arg
}


// format price string: 12350 -> 123.50 or 123,50
function price2Strg(x) {
	priceStr = Math.round(x) + ""
	len = priceStr.length
	if(len==2) priceStr =  "0" + priceStr
	if(len==1) priceStr = "00" + priceStr
	len = priceStr.length
	priceStr = priceStr.substring(0,len-2) + decimal + priceStr.substring(len-2)
	return (priceStr)
}

// add blanks for padding the price string in the text view
function middlePad(str1, str2) {
	lineLength = 25
	if(currency.indexOf("&") == 0) lineLength += currency.length - 1	// &euro; -> 1 char
	if(str1.indexOf("&amp;") >= 0) lineLength += 4				// &amp;  -> 1 char
	blanksAdd  = lineLength - str1.length - str2.length
	blanksStr  = ""
	for(var i=0; i<blanksAdd; i++) blanksStr += " "
	return (str1 + blanksStr + str2)
}

// reading a variable in the parsed string
function getParm(string,parm) {
	var startPos= string.indexOf(parm+"=")
	if (startPos> -1) {
		startPos= startPos+parm.length+1
		var endPos= string.indexOf("&",startPos)
		if (endPos== -1) endPos= string.length
		return unescape(string.substring(startPos,endPos))
	}
	return ''
}

// reset all fields
function resetAll() {
	for(i=0; i<document.forms[0].length; i++)
		document.forms[0].elements[i].value = 0
	window.location.reload()
}

// ----------------------  end  ---------------------------

