﻿/*
 * Calculate the Price of a Business Card — 1.0.0
 *
 * Copyright (c) 2009 Wayne Kolenchuk (wayne@kolenchuk.com)
 * $Date: 2009-02-21 
 * You can use or modify this script as long as you display this attribution
 * Variables :  size, quantity, sides, paper, rounded_corners, uv_coating
 * These can be passed to the shopping cart
 */


function BusinessCardPrice() //calculate business card price
{
		
	var buscard = new Array();
	//create a new array
	
	buscard[0] = [500,40,50,4,7.5];
    buscard[1] = [1000,40,80,5,12];
	buscard[2] = [2500,50,130,15,19.5];
	buscard[3] = [5000,50,190,4,28.5];
	buscard[4] = [10000,100,360,20,54];
	
	// put the values into a multi dimensional array
	// since there is always a quantity use the selected index value of quantity to determine secondary position in the array.
	     
    var base_price = buscard[document.getElementById('number_of_cards').selectedIndex][2];
	// get the basic price
	
	if (document.getElementById("rounded_corners").checked) {
	
	 var rounded_corners = buscard[document.getElementById('number_of_cards').selectedIndex][1];
	   }  
	   else {
		   
		var rounded_corners = 0;   
	   }
     // if rounded corners selected get price, otherwise set to 0


	if (document.getElementById("uv_coating").checked) {
	
	 var uv_coating = buscard[document.getElementById('number_of_cards').selectedIndex][3];
	   }  
	   else {
		   
		var uv_coating = 0;   
	   }
     // if uv_coating selected get price, otherwise set to 0
	
    if (document.getElementById("sides").value==2) {
	
	 var sides = buscard[document.getElementById('number_of_cards').selectedIndex][4];
	   }  
	   else {
		   
		var sides = 0;   
	   }
     // get extra cost for 2 sided card


	var total_price = (base_price + rounded_corners + uv_coating + sides).toFixed(2);
	
	document.getElementById("Price").value = total_price;
	//put the price in a form field and display it
	
   var description = (document.getElementById('number_of_cards').value) + "   " + (document.getElementById('size').value) + "   " +  "full color business cards," + "   " + (document.getElementById('sides').value) + "  " + "sided on" + "  " + (document.getElementById('paper').value) +",  " + "rounded corners = "  + (document.getElementById('rounded_corners').checked) + ",  " + "uv coating = " + (document.getElementById('uv_coating').checked) + " " + "printed with the precision 4 (CMYK) color offset process."
   // make a description of the item
   
	document.getElementById("msg_description").innerHTML = description;
	//put the description in a form field
}