// JavaScript Document
// Copyright 2008-2009 Peter Fraterdeus
// Portions of this program are utilized under the GNU Public Licensed.
// Other portions are credited as to the source, with an assumption that this is enough.
// 


const myText=0;
const myValue=1;

function gMyDiscount(){
var currentDiscount=1.0;
howManyCards= document.orderdetails_form.howManyCards.value*1.0;

switch (howManyCards) {
    case 500: currentDiscount=1.09; break;
    case 750: currentDiscount=1.07; break;
    case 1000: currentDiscount=1.0; break;
    case 1500: currentDiscount=0.95; break;
    case 2000: currentDiscount=0.92; break;
    case 2500: currentDiscount=0.90; break;
}
return currentDiscount;

}


function getCouponCode(){

howManyCards= document.orderdetails_form.howManyCards.value*1.0;
secondColor= getInkSecondColor();
numSides= getNumSides();

myPaperStock = document.orderdetails_form.paperStock.value;
myPaperStock = myPaperStock.substr(myPaperStock.lastIndexOf('-')+1)*1.0;

myInkUpgrade = document.orderdetails_form.inkColor2.value;
myInkUpgrade = myInkUpgrade.substr(myInkUpgrade.lastIndexOf('-')+1)*1.0;


myCouponCode = document.orderdetails_form.couponCode.value.toLowerCase();
var discounts = new Array(2);

discounts['5']= [];
discounts['10']= [];
today=new Date();

offerExpires= new Date();
offerExpires.setFullYear(2011);
offerExpires.setMonth(03); //mar
offerExpires.setDate(01);

if (today.getTime() <= offerExpires.getTime()) {
discounts['25']= ['fcbk0229','atypi0229','spcl0229','twtr0229']; //expire 01feb11

//discounts['10']= ['fcbk1208','atypi1208','spcl1208'];//
}

for (var i in discounts) {

     for (var j in discounts[i]) {

		if (myCouponCode == discounts[i][j]) {
		
		    //if ( secondColor[1]>0  && (howManyCards > 500 && numSides[1]>0 ) )  return i*1.0; // discount on two-color two-side over 500 cards

		    if ( myInkUpgrade==0  && (howManyCards > 500 ) && (myPaperStock=='3'||myPaperStock=='16') )  return i*1.0; // discount on two-color over 500 cards
 //if ( secondColor[1]>0  && (howManyCards > 500 ) )  return i*1.0; // discount on two-color over 500 cards

		}
		

		
     }


    
}




return 0;//.substr(myCouponCode.lastIndexOf('-'));

}


function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }

function sprintf () {
/* Thanks to David Baird (unit test and patch).
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
	
	
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
}


// DOM check begins... so you can use this with IE 4/5.5/6/7 FF+ Moz+ & latest NS
var isALL = 0;
var isID = 0;
var isDHTML = 0;
if (document.getElementById) {isID = 1; isDHTML = 1;}
else if (document.all) {isALL = 1; isDHTML = 1;}

function checkDOM(object_id) {
if (isID) { return (document.getElementById(object_id).style) ; }
if (isALL) { return (document.all[object_id].style) ; }
}
// DOM check ends

var toggle_status = "on";

function toggle_display(id_name) {
if (toggle_status == "on") {
dom = checkDOM(id_name); //send id_name to use All or ID
dom.display = "none";
toggle_status = "on";
} else {
dom = checkDOM(id_name); //send id_name to use All or ID
dom.display = "block";
toggle_status = "off";
}
}

function set_display(id_name,display_status) {
if (display_status == "on") {
dom = checkDOM(id_name); //send id_name to use All or ID
dom.display = "block";
toggle_status = "on";
} else {
dom = checkDOM(id_name); //send id_name to use All or ID
dom.display = "none";
toggle_status = "off";
}
}


// to write content to a layer/div
// from http://www.pageresource.com/dhtml/ryan/part4-6.html
function writeLayer(layerID,txt){
               if(document.getElementById){
                         document.getElementById(layerID).innerHTML=txt;
               }else if(document.body.getAttributeNode){
                         node = document.getElementById(layerID);
                         var newRange = document.createRange();
                         newRange.selectNodeContents(node);
                         newRange.deleteContents();
                         var newHTML = newRange.createContextualFragment(txt);
                         node.appendChild(newHTML);
               }else if(document.getElementById){
                         document.getElementById(layerID).innerHTML=txt;
               }else if(document.all){
                         document.all[layerID].innerHTML=txt; 
               }else if(document.layers){
                        with(document.layers[layerID].document){
                                   open();
                                   write(txt);
                                   close();
                         }
               }
     }


//Set constant values

//Initialize variables


function getCurrency(){

	var found_it;

	var myCurrency=[["$",1],["&euro;",.78]];

	for (var i=0; i < document.orderdetails_form.currency.length; i++){
		if (document.orderdetails_form.currency[i].checked==true) {

            return myCurrency[i];
		}
	}
	
	return myCurrency[0];

}


//Get number of Cards

function getCardsOrdered(){


// myBaseCost "number of cards":$price
var myBaseCost = {
				"500":265,
                "750":295,
				"1000":325,
				"1500":375,
				"2000":435,
				"2500":485,
				"---":0} 

myBaseCostText=document.orderdetails_form.howManyCards.options[document.orderdetails_form.howManyCards.selectedIndex].text;



return  [myBaseCostText,myBaseCost[document.orderdetails_form.howManyCards.value]*gMyDiscount()];

}

// Get number of Sides


function getNumSides(){

	oneColor=135;
	twoColor=165;
	var myNumSides=[['1s 1c (1/0) +',0],['2s 1c (1/1) +',oneColor]];
	
	if (getInkSecondColor()[1]>0) {
		myNumSides=[['1s 2c (2/0) +',0],['2s 2c (2/2) +',twoColor]];
	}
	
	for (var i=0; i < document.orderdetails_form.numSides.length; i++){
		if (document.orderdetails_form.numSides[i].checked==true) {

            return myNumSides[i];
		}
	}
	
	return myNumSides[0];

}



//Calc ink upgrade

function getInkUpgrade(){

var howManyCards = document.orderdetails_form.howManyCards.value*1.0;

myInkUpgrade = document.orderdetails_form.inkColor.value;
myInkUpgrade = myInkUpgrade.substr(myInkUpgrade.lastIndexOf('-')+1)*1.0;
myInkUpgradeText=document.orderdetails_form.inkColor.options[document.orderdetails_form.inkColor.selectedIndex].text;

if (howManyCards<500 ) { //updated to flat rate pricing, left the decision tree for future use if desired.
	standardPantone=45;
	secondaryPantone=65;
	customPantone=85;} else if (howManyCards<=750) {
		standardPantone=0;
		secondaryPantone=10;
		customPantone=25;} else {
		standardPantone=0;
		secondaryPantone=0;
		customPantone=15;}

if (myInkUpgrade >0 && myInkUpgrade < 49) { return [myInkUpgradeText,standardPantone] ;}
	else if (myInkUpgrade >50 && myInkUpgrade < 99) { return [myInkUpgradeText,secondaryPantone] ;}
	else if (myInkUpgrade == 99) { return [myInkUpgradeText,customPantone];} 
    
return [myInkUpgradeText,0]; 

}

//Get second color

function getInkSecondColor(){

var howManyCards = document.orderdetails_form.howManyCards.value*1.0;

secondColorUpgrade=135;

myInkUpgrade = document.orderdetails_form.inkColor2.value;
myInkUpgrade = myInkUpgrade.substr(myInkUpgrade.lastIndexOf('-')+1)*1.0;
myInkUpgradeText=document.orderdetails_form.inkColor2.options[document.orderdetails_form.inkColor2.selectedIndex].text;

if (myInkUpgrade >0 ) { return [myInkUpgradeText,secondColorUpgrade] ;}
return [myInkUpgradeText,0]; 

}	
//Calc paper cost upgrade

function getPaperUpgrade(){

  function checkMinimum(howManyCards,minCards){ // local function

  if (howManyCards < minCards ) { //minimum of 500 cards
           alert("Minimum of "+minCards+" cards for this paper choice!");
           document.orderdetails_form.howManyCards.value = minCards;
           setField();
		   return 1;}
          }

var myPaperCost = new Object;
set_display('bugra_selection','off');
set_display('classicColumns_selection','off');


howManyCards= document.orderdetails_form.howManyCards.value*1.0;

myPaperStock = document.orderdetails_form.paperStock.value;

myPaperStock= myPaperStock.substr(myPaperStock.lastIndexOf('-')+1)*1.0;

myPaperStockText=document.orderdetails_form.paperStock.options[document.orderdetails_form.paperStock.selectedIndex].text;


if (myPaperStock>=2 && myPaperStock<=4) { //Crane Lettra 300gsm
 myPaperCost ={"250":40,"500":65,"750":70,"1000":75,"1500":115,"2000":150,"2500":175}; }

  else if (myPaperStock>=5 && myPaperStock<=7) { //Crane Lettra 600gsm
 myPaperCost ={"500":135,"750":165,"1000":215,"1500":325,"2000":425,"2500":535}; 
           checkMinimum(howManyCards, 500);
          }

  else if (myPaperStock==8 || myPaperStock==10) { //Copperplate or German Etching 300
 myPaperCost ={"500":70,"750":85,"1000":110,"1500":165,"2000":215,"2500":275}; 
           checkMinimum(howManyCards, 500);
          }

  else if (myPaperStock==9) { //Copperplate Etching 600
 myPaperCost ={"500":145,"750":165,"1000":215,"1500":325,"2000":425,"2500":535}; 
           checkMinimum(howManyCards, 500);

          }

 else if (myPaperStock==11) { //Bugra Duplex
			myPaperCost ={"500":150,"750":140,"1000":165,"1500":225,"2000":255,"2500":330}; 
           checkMinimum(howManyCards, 750);
           set_display('bugra_selection','on');
		   myPaperStockText=myPaperStockText+" "+document.orderdetails_form.bugraDuplexFront.value+"/"+document.orderdetails_form.bugraDuplexBack.value;
          }
 else if (myPaperStock==17) { //Bugra triplex
 myPaperCost ={"500":190,"750":170,"1000":195,"1500":275,"2000":375,"2500":460}; 
           checkMinimum(howManyCards, 750);
           set_display('bugra_selection','on');
		   myPaperStockText=myPaperStockText+" "+document.orderdetails_form.bugraDuplexFront.value+"/"+document.orderdetails_form.bugraDuplexBack.value;
          }
 else if (myPaperStock>=12 && myPaperStock<=14) { //Classic Crest Cover
			myPaperCost ={"250":35,"500":45,"750":55,"1000":65,"1500":95,"2000":125,"2500":195}; }

 else if (myPaperStock==15) { //Strathmore 110# Writing Cover
 			myPaperCost ={"250":35,"500":45,"750":55,"1000":65,"1500":85,"2000":105,"2500":125}; 
			checkMinimum(howManyCards, 500); }

else if (myPaperStock==16) { //Strathmore 130# Writing Cover
 			myPaperCost ={"250":35,"500":50,"750":60,"1000":70,"1500":90,"2000":110,"2500":135}; 
			checkMinimum(howManyCards, 500); }


else if (myPaperStock==21 ) { //Legion Bamboo 265gsm
			myPaperCost ={"250":40,"500":65,"750":70,"1000":75,"1500":115,"2000":150,"2500":175}; 
			checkMinimum(howManyCards, 500); }

else if (myPaperStock==22 ) { //Legion Bamboo 530gsm
			myPaperCost ={"500":135,"750":165,"1000":215,"1500":325,"2000":425,"2500":535}; 
 			checkMinimum(howManyCards, 500); }

else if (myPaperStock>=31&& myPaperStock<=34) { //Neenah Classic Columns Duplex
			myPaperCost ={"500":65,"750":85,"1000":95,"1500":145,"2000":165,"2500":195}; 
           checkMinimum(howManyCards, 1000);
           set_display('classicColumns_selection','on');
		   myPaperStockText=myPaperStockText+" "+document.orderdetails_form.bugraDuplexFront.value+"/"+document.orderdetails_form.bugraDuplexBack.value;
          }

return [myPaperStockText,myPaperCost[document.orderdetails_form.howManyCards.value]*gMyDiscount()||0];



}


//Calc format upgrade

function getCardFormat(){

myCardFormat = document.orderdetails_form.cardFormat.value;

myCardFormatText=document.orderdetails_form.cardFormat.options[document.orderdetails_form.cardFormat.selectedIndex].text;

cardFormat = myCardFormat.substr(myCardFormat.lastIndexOf('-')+1)*1.0;

if (cardFormat==3) {myCardFormat=75;} 
else if (cardFormat==2) {myCardFormat=35;}
else myCardFormat=0;

return [myCardFormatText,myCardFormat];

}


//Get Expedite my Order

function getExpedite(){

// returns multiplier for expedite order charge

var myPaperCost=getPaperUpgrade()[1];

//writeLayer("OrderWidgetContainer", "myPaperCost= "+ myPaperCost);

if (getTotalNet()<300) {
standard=0;
express=.25;
special=2.0; } else {
	
standard=0;
express=0;
special=1.0; 

}

myExpedite =['',standard,express,special]
  
myExpediteOrder = document.orderdetails_form.expediteMyOrder.value;
myExpediteOrder= myExpediteOrder.substr(myExpediteOrder.lastIndexOf('-')+1)*1.0;


myExpediteOrderText=document.orderdetails_form.expediteMyOrder.options[document.orderdetails_form.expediteMyOrder.selectedIndex].text;


return  [myExpediteOrderText,myExpedite[myExpediteOrder]]; //

 
}


var expediteNoticeConfirmed=0;

function confirmExpedite() {

if (expediteNoticeConfirmed==0) {

var answer = confirm("Expedited Service is a 'Best Effort' service.\nYou understand that our only guarantee is to refund in part or in whole the expedited service surcharge if we are unable, for any reason, to deliver on the expedited schedule");

  if (answer) {

	expediteNoticeConfirmed=1;

	} else {

	document.orderdetails_form.expediteMyOrder.value="Standard-0";
	//setField();
	return 0; 
	}

//setField();
return 1;

}
}
//Get Add Tag Line

function getTagLine(){
/*
howManyCards= document.orderdetails_form.howManyCards.value*1.0;

myAddTagLine = document.orderdetails_form.tagLineYes_hidden.value*1.0;

if (howManyCards >= 500 ) return 5.0 * myAddTagLine;

else return 0;//.substr(myAddTagLine.lastIndexOf('-'));
*/
return 0; // tag-line discount discontinued 
}



function getShipping(){

myShipping = document.orderdetails_form.shipping.value;
myShippingText=document.orderdetails_form.shipping.options[document.orderdetails_form.shipping.selectedIndex].text;


//writeLayer("OrderWidgetContainer", "myPaperCost= "+ myPaperCost);

if (getTotalNet()<250) { // 

    usps_priority=15;

    } else {

    usps_priority=0;} 

usps_express=50;
fed_ex_second=50;
intl_std=45;
intl_express=100;


shippingCost = ['',usps_priority,usps_express,fed_ex_second,intl_std,intl_express];


return [myShippingText,shippingCost[myShipping.substr(myShipping.lastIndexOf('-')+1)]];



}

function testAlert(){
myAlert=getCardsOrdered()+" | "+getInkUpgrade()+" | "+getPaperUpgrade()+" | "+getExpedite()+" | "+getTagLine();


alert(myAlert);
return 0; }

/*function buildOrderDisplay(layerID, text) {
	
		writeLayer(layerID, text);
		addHiddenVar(layerID, text);
	
		return 0;
	}
	
*/


function getTotalNet(){


//orderTotal= getCardsOrdered()+getInkUpgrade()+getPaperUpgrade()+getCardFormat();
//writeLayer("OrderData_Subtotal", "Current Order= "+ orderTotal);

basePrice= getCardsOrdered();
//writeLayer("OrderData_Base", "Cards Ordered: "+ basePrice[myText]);

numberofSides=getNumSides();

inkUpgrade= getInkUpgrade();
//writeLayer("OrderData_Ink", "Ink: "+ inkUpgrade[myText]+" $"+inkUpgrade[myValue]);

inkUpgrade2=getInkSecondColor();

paperUpgrade= getPaperUpgrade();
//writeLayer("OrderData_Paper", "Paper: "+ paperUpgrade[myText]+" $"+paperUpgrade[myValue]);

formatUpgrade=getCardFormat();
//writeLayer("OrderData_Format", "Format= "+formatUpgrade[myText]+" $"+formatUpgrade[myValue]);

orderTotal= basePrice[myValue]+numberofSides[myValue]+inkUpgrade[myValue]+inkUpgrade2[myValue]+paperUpgrade[myValue]+formatUpgrade[myValue];

return orderTotal;
}

function getTotalGross() {

myText=0;
myValue=1;

orderTotal = getTotalNet();


shipping= getShipping();
//writeLayer("OrderData_Ship", "Shipping= "+ shipping);


expedites= getExpedite();
//writeLayer("OrderData_Expedite", "Expedites= "+ expedites);


discounts= (Math.max(getCouponCode(),getTagLine()) /100);
//writeLayer("OrderData_Discounts", "Discounts= "+ discounts);


calcTotal = orderTotal-(orderTotal*discounts)+(orderTotal*expedites[myValue])+shipping[myValue];

return calcTotal;

}

function setField(){
	

myText=0;
myValue=1;
//orderTotal= getCardsOrdered()+getInkUpgrade()+getPaperUpgrade()+getCardFormat();
//writeLayer("OrderData_Subtotal", "Current Order= "+ orderTotal);
/* 
basePrice= getCardsOrdered();
//writeLayer("OrderData_Base", "Cards Ordered: "+ basePrice[myText]);

inkUpgrade= getInkUpgrade();
//writeLayer("OrderData_Ink", "Ink: "+ inkUpgrade[myText]+" $"+inkUpgrade[myValue]);

paperUpgrade= getPaperUpgrade();
//writeLayer("OrderData_Paper", "Paper: "+ paperUpgrade[myText]+" $"+paperUpgrade[myValue]);

formatUpgrade=getCardFormat();
//writeLayer("OrderData_Format", "Format= "+formatUpgrade[myText]+" $"+formatUpgrade[myValue]);

shipping= getShipping();
//writeLayer("OrderData_Ship", "Shipping= "+ shipping);


expedites= getExpedite();
//writeLayer("OrderData_Expedite", "Expedites= "+ expedites);


discounts= (Math.max(getCouponCode(),getTagLine()) /100);
//writeLayer("OrderData_Discounts", "Discounts= "+ discounts);

orderTotal= basePrice[myValue]+inkUpgrade[myValue]+paperUpgrade[myValue]+formatUpgrade[myValue];

calcTotal = orderTotal-(orderTotal*discounts)+(orderTotal*expedites[myValue])+shipping[myValue];
//writeLayer("OrderData_Total", "Current Order= "+ calcTotal);

*/

orderTotal=getTotalNet();
calcTotal=getTotalGross();

currencySymbol= getCurrency()[myText];
currencyFactor= getCurrency()[myValue];



var orderWidgetHead = '<div id="OrderWidget" class="OrderWidget draggable" > ';

/* style="background-attachment:scroll; \
background-color:ivory;\
background-image:none;\
background-position:0 0;\
\
position:fixed;\
padding:1em;\
font-size:85%;\
left:880px;\
bottom:10px;\
width:240px;" */

var orderWidgetShadow = '<div id="OrderWidgetShadow" class="OrderWidgetShadow draggable" >\
        <div class="shadow1">\
            <div class="shadow2">\
                <div class="shadow3">\
                </div>\
            </div>\
          </div></div>'; 


var orderWidgetDivs = "<div class=\"OrderTitle\"><h3>Almost Free Letterpress&trade;<br />Order Details</h3></div>";
 
orderWidgetDivs += "<table style=\"font-size:95%;\">"
orderWidgetDivs += "   <tr><div id=\"OrderCurrency\" class=\"order even\">"+"<td>Currency</td><td>"+ currencySymbol+"</td></div>";
orderWidgetDivs += "   <tr><div id=\"OrderData_Base\" class=\"order odd\">"+"<td>Cards Ordered</td><td>"+ basePrice[myText]+" "+  currencySymbol+sprintf("%5.2f",basePrice[myValue]*currencyFactor)+"</td></div>";

orderWidgetDivs += "   <tr><div id=\"OrderData_Sides\" class=\"order odd\">"+"<td>Number of Sides</td><td>"+ numberofSides[myText]+" "+  currencySymbol+sprintf("%5.2f",numberofSides[myValue]*currencyFactor)+"</td></div>";

orderWidgetDivs += "   <tr><div id=\"OrderData_Ink\" class=\"order even\">"+"<td>First Ink</td><td>"+ inkUpgrade[myText]+" "+  currencySymbol+sprintf("%5.2f",inkUpgrade[myValue]*currencyFactor)+"</td></div>";
orderWidgetDivs += "   <tr><div id=\"OrderData_Ink2\" class=\"order even\">"+"<td>Second Ink</td><td>"+ inkUpgrade2[myText]+" "+  currencySymbol+sprintf("%5.2f",inkUpgrade2[myValue]*currencyFactor)+"</td></div>";
orderWidgetDivs += "   <tr><div id=\"OrderData_Paper\" class=\"order odd\">"+"<td>Paper</td><td>"+ paperUpgrade[myText]+" "+ currencySymbol+sprintf("%5.2f",paperUpgrade[myValue]*currencyFactor)+"</td></div>";
orderWidgetDivs += "   <tr><div id=\"OrderData_Format\" class=\"order even\">"+"<td>Format</td><td>"+formatUpgrade[myText]+" "+  currencySymbol+sprintf("%5.2f",formatUpgrade[myValue]*currencyFactor)+"</td></div>";

orderWidgetDivs += "   <tr><div id=\"OrderData_Ship\" class=\"order odd\">"+"<td>Shipping</td><td>"+ shipping[myText]+"</td></div>";
orderWidgetDivs += "   <tr><div id=\"OrderData_Expedite\" class=\"order even\">"+"<td>Expedites</td><td>"+ expedites[myText]+"</td></div>";
orderWidgetDivs += "   <tr><div id=\"OrderData_Discounts\" class=\"order odd \">"+"<td>Discounts</td><td>"+ discounts*100+"%</td></div>";
orderWidgetDivs += "   <tr><div id=\"OrderData_Total\" class=\"order even\">"+"<td>Current Order</td><td style=\"font-style:bold;font-size:125%\">"+ currencySymbol+sprintf("%5.2f",calcTotal*currencyFactor)+" ("+ currencySymbol+sprintf("%5.3f",(calcTotal*currencyFactor)/document.orderdetails_form.howManyCards.value)+" per card)</td></div></table>";

//orderWidgetDivs += "   <!--<div id=\"OrderData\" class=\"order\"></div> -->";

var orderWidgetHidden = "<input type=\"hidden\" name=\"OrderDataBase\" value=\""+sprintf("%5.2f",basePrice[myValue]*currencyFactor)+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderCurrency\" value=\""+currencySymbol+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataSides\" value=\""+sprintf("%5.2f",numberofSides[myValue]*currencyFactor)+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataInk\" value=\""+sprintf("%5.2f",inkUpgrade[myValue]*currencyFactor)+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataInk2\" value=\""+sprintf("%5.2f",inkUpgrade2[myValue]*currencyFactor)+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataPaper\" value=\""+sprintf("%5.2f",paperUpgrade[myValue]*currencyFactor)+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataFormat\" value=\""+sprintf("%5.2f",formatUpgrade[myValue]*currencyFactor)+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataShip\" value=\""+sprintf("%5.2f",shipping[myValue]*currencyFactor)+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataExpedite\" value=\""+expedites[myText]+"\"  />";
orderWidgetHidden += "<input type=\"hidden\" name=\"OrderDataDiscounts\" value=\""+discounts+"\"  />";
orderWidgetHidden += "<input type=\"hidden\"  name=\"OrderDataTotal\" id=\"OrderDataTotal\" value=\""+sprintf("%5.2f",calcTotal*currencyFactor)+"\"  />";

var orderWidgetClose = "  </div>";

writeLayer("OrderWidgetContainer",orderWidgetHead+orderWidgetDivs+orderWidgetHidden+orderWidgetClose);

writeLayer("CostPerCard"," "+currencySymbol+sprintf("%5.2f",(basePrice[myValue]*currencyFactor))+" ("+currencySymbol+sprintf("%5.2f",((basePrice[myValue]*currencyFactor)/basePrice[myText]*1))+" per card)");


function writePPbutton()  { 

var ppButtonFields = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">\
  <input type="hidden" name="cmd" value="_cart">\
  <input type="hidden" name="upload" value="1">\
  <input type="hidden" name="business" value="sales@exquisiteletterpress.com">\
  <input type="hidden" name="item_name_1" value="Aggregated items">';
  
 ppButtonFields+= '<input type="hidden" name="amount_1" value="'+OrderDataTotal+'">\
  <input type="submit" value="PayPal">\
  </form>';

 writeLayer ("ppButtonContainer",ppButtonFields);

return 0;
}

// debug view 

//myData="$ for # ordered "+getCardsOrdered()+" | ink "+getInkUpgrade()+" | paper "+getPaperUpgrade()+" | expedite"+getExpedite()+" | tag "+getTagLine()+" | format "+getCardFormat()+" | shipping "+getShipping()+" | coupon"+getCouponCode();


//writeLayer("OrderData", "Current Order= "+ myData);

//document.orderdetails_form.myData.value =myData;


return 0; }

