//###### monthly promo ######
//1. at auto_calculate(), we call monthly_promo()
//2. at calcpromo(), we call calc_monthly_promo() & valid_monthly_promo()

/*  monthly promo for non-shipping related
function calc_monthly_promo(rush_total)
{
	// june 2007: code 'jun7': set normal & rush the same price
		//var rush_total = gtotal1;
		
		if(document.Forminfo.prospeed.options[2].selected == true)
		{
			
			var normal_total_noqda = (rush_total - proofc + qda) / rushrate;
			
			if (QDISRATE == "Y") { 
				normal_qda = calcdis(normal_total_noqda);
			} else {
				normal_qda = 0;
			}
	
			var normal_total = normal_total_noqda - normal_qda + proofc;
			var the_discount = rush_total - normal_total;
	
			var normal_discount = Array(normal_total, the_discount);
			
			return normal_discount;
		}
		else
		{
			return false;
		}
}
function monthly_promo()
{
	if(valid_monthly_promo())
	{
		document.Forminfo.prospeed.options[2].selected = true;
		turnaround_action();
		//chgrushrate(2); //choiceValue, choiceName, choiceIndex
	}
}
*/
// Show a tabs content and hide all others
function showTab(strTabName) {
  for (var i = 0; i < arrTabs.length; i++) {
    // show the content and tab
    var objContent = document.getElementById("tabcontent-" + arrTabs[i]);
    var objTab = document.getElementById("tab-" + arrTabs[i]);

    if (arrTabs[i] == strTabName) {
      // This is the newly active tab
      objContent.style.display = "block";
      objTab.className = "active";
    } else {
      // Make this tab inactive
      objContent.style.display = "none";
      objTab.className = "";
    }
  }
}
//check the MONTHLY_FOR array and see if any product match for promo
function is_valid_product(valid_array, single_product)
{
	for(var i=0; i<valid_array.length; i++)
	{
		if(valid_array[i].toLowerCase() == single_product.toLowerCase())
		{
			//alert('Product: '+valid_array[i]+' single_product: '+single_product)
			return true;
		}
	}
	return false;
}

function valid_monthly_promo()
{
	var current_date = new Date();
	var valid_products = MONTHLY_FOR.split(',');
	
	if(document.Forminfo.promo.value.toUpperCase() == MONTHLY_PROMO && Date.parse(MONTHLY_EXP) >= current_date && current_date >= Date.parse(MONTHLY_START) && is_valid_product(valid_products, this_product))
	{
		//alert('valid! '+this_product+' end');
		return true;
	}
	else
	{
		//alert('not valid!'+this_product+' end');
		return false;
	}	
}

//------ promo message ------
function popPromo()
{
	var pName = getProductName();
	if(pName && $_promopop[this_product] != '')
	{
		var amt_code = $_promopop[this_product].split(',');
		document.getElementById('popupid').innerHTML = genPromoDiv(pName, amt_code[0], amt_code[1]);
	}
}

function genPromoDiv(productNamePromo, proPercentAmt, proCode)
{
var bg_location = 'http://www.print-designing-studio.com/images/promo-ybg.gif';
var left_pos = '37%';
var top_pos = '20';
var width_box = '320';
var showHide = 'visible';
var opacity_box = '0.95';
var heght_box = '100';

var title_color = '03369c';
var title_off = proPercentAmt+'%';
var title_product = productNamePromo;

var body_color = '333';
var body_txt = 'Use promotional code <strong>'+proCode+'</strong>. May not be combined with any other offer. Valid on your 1st order only. Discount does not apply to mailing services or shipping.';

var promoDiv = '<div id="SpecialPromo" style="position: absolute; z-index: 1009; left: '+left_pos+'; top: '+top_pos+'px; width: '+width_box+'px; visibility: '+showHide+'; opacity: '+opacity_box+'; height: '+heght_box+'px;">';
promoDiv += '<table width="'+width_box+'" cellspacing="0" cellpadding="0" border="0" style="border:solid 2px #ffcc00; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">';
promoDiv += '<tbody>';
promoDiv += '<tr>';
promoDiv += '<td width="'+width_box+'" height="'+heght_box+'" valign="top">';
promoDiv += '  <table width="100%" cellspacing="2" cellpadding="10" border="0" style="background-image:url('+bg_location+')">';
promoDiv += '  <tbody>';
promoDiv += '  <tr>';
promoDiv += '  <td width="292" height="38" align="center" style="padding: 1px; color:#'+title_color+'; text-align: center; font-size:16px; font-family:Verdana; font-weight:bold;"><p>New Customers '+title_off+' OFF <br>'+title_product+'</p></td>';
promoDiv += '  </tr>';
promoDiv += '  <tr>';
promoDiv += '    <td height="44" align="left" valign="top" style="padding: 1px; padding-left: 8px; padding-right: 8px; text-align: left; font-size:12px; font-family:Verdana; color:#'+body_color+';">'+body_txt+'</td>';
promoDiv += '  </tr>';
promoDiv += '  <tr>';
promoDiv += '    <td height="12" style="padding: 1px;text-align: center; font-size:10px; font-family:Verdana; color:#666;cursor:pointer;" onclick="hidePromoPopUp()">x close</td>';
promoDiv += '  </tr>';
promoDiv += '  </tbody>';
promoDiv += '  </table></td>';
promoDiv += '</tr>';
promoDiv += '</tbody>';
promoDiv += '</table>';
promoDiv += '</div>';

return promoDiv;
}

function hidePromoPopUp()
{
	document.getElementById('SpecialPromo').style.visibility = 'hidden';
}

function getProductName()
{
	switch (this_product) 
	{
		case 'brochures':
			return 'Brochures / Flyers / Newsletters';
			break;
		case 'flyers':
			return 'Flyers';
			break;
		case 'newsletters':
			return 'Newsletters';
			break;
		case 'posters':
			return 'Posters';
			break;
		case 'rack_brochures':
			return 'Rack Brochures';
			break;
		case 'catalogs':
			return 'Catalogs / Booklets';
			break;
		case '28_calendars':
			return '28 Page Calendars';
			break;
		case 'wall_calendars':
			return 'Wall Calendars';
			break;
		case '49_calendars':
			return '4 x 9 Calendars';
			break;
		case 'table_tent_calendars':
			return 'Table Tent Calendars';
			break;
		case 'postcards':
			return 'Postcards';
			break;
		case 'greeting_note_cards':
			return 'Greeting & Note Cards';
			break;
		case 'rack_cards':
			return 'Rack Cards / Rip Cards';
			break;
		case 'jumbo_postcards':
			return 'Jumbo Postcards';
			break;
		case 'door_hangers':
			return 'Door Hangers / Rip Card Hangers';
			break;
		case 'letterhead_envelopes':
			return 'Letterhead & Envelope';
			break;
		case 'commercial_envelopes':
			return 'Commercial Envelopes';
			break;
		case 'announcement_envelopes':
			return 'Announcement Envelopes';
			break;
		case 'business_cards':
			return 'Business Cards';
			break;
		case 'presentation_folders':
			return 'Presentation Folders';
			break;
		case 'dvd_case_cover':
			return 'Dvd Case Cover';
			break;
		default:
			return 0;	
	}
}

//------ pricing table ------
var pt_quant_max = 999999999;
var pt_quant_min = BASEQ;

var pt_stepup_max = 10000;
var pt_stepup_min = 50;
var pt_stepup_gap = 50;

//set drop down menu
function pt_set_field_index(field_name, the_index)
{
	document.Forminfo[field_name].options[the_index].selected = true;
}

//set text field
function pt_set_text_field(field_name, the_value)
{
	document.Forminfo[field_name].value = the_value;
}

//check the existance of an index of a drop down menu
function isIndexExist(field_name, query_index)
{
	try
	{
		if(document.Forminfo[field_name].options[query_index] != null)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	catch(e)
	{
		return false;
	}
}

function pt_set_stepup_array(the_start, the_stepup)	//reset the pt_quant_array
{
	//check value & data
	var user_stepup = pt_validate_input(the_stepup, pt_stepup_min);
	user_stepup = pt_validate_data(the_stepup, pt_stepup_min, pt_stepup_max);
	
	var user_quant = pt_validate_input(the_start, pt_quant_min);
	user_quant = pt_validate_data(the_start, pt_quant_min, pt_quant_max);
	

	var array_length = pt_quant_array.length;
	
	pt_quant_array[0] = user_quant;
	
	for (var i=0; i<array_length-1; i++)
	{
		pt_quant_array[i+1] = pt_quant_array[i] + user_stepup;
	}
}
//this function will set / reset the global pricing array whenever called
//the_color: 0,1,2 = 4/4, 4/1, 4/0
function pt_set_price_array(the_color)
{
	var array_length = pt_quant_array.length;
	for (var i=0; i<array_length; i++)
	{
		pt_price_array[i] ='$'+pt_check_price(pt_quant_array[i], the_color)[0];	//[0] is the base price, [1] is the unit price
	}
}

// set the td tag when the page load, it is used in the html body
//the tag is the index of the pull down menu at a real quote page so when user click on a price, it knows what color it is
function pt_set_td_tag(the_array, the_tag)	
{
	var array_length = the_array.length;
	var span_tag = '';
	
	for (var i=0; i<array_length; i++)
	{
		span_tag = the_tag + '_' + i;
		document.write('<td><a><span id='+span_tag+' onclick="pt_get_id(this);"></span></a></td>');
	}
}
function pt_goto_URL(the_page_url)
{
	top.location.href = the_page_url;
}
// set a single data, called by pt_set_all_price() to set all data
function pt_set_price_data(the_array, the_tag)	
{
	var array_length = the_array.length;
	var span_tag_ID = '';
	
	for (var i=0; i<array_length; i++)
	{
		span_tag_ID = the_tag + '_' + i;
		document.getElementById(span_tag_ID).innerHTML = the_array[i];
	}
}
//check if user input is valid
function pt_validate_input(user_value, default_value)
{
	if(!user_value || user_value == '' || user_value == null || !IsNumeric(user_value))
	{
		return default_value;
	}
	else
	{
		return user_value;
	}
}
//check if user input meet the min. value requirement
function pt_validate_data(user_value, min_value, max_value)
{
	if(user_value < min_value)
	{
		return min_value;
	}
	else if(user_value > max_value)
	{
		return max_value;
	}
	else
	{
		return user_value;
	}
}
//clicking the button left & right to increase or decrease the stepup
function pt_alt_stepup(the_mode)
{
	var user_stepup = parseInt(document.Forminfo.stepup_quant.value,10);
	
	//check value
	user_stepup = pt_validate_input(user_stepup, pt_stepup_min);
	
	if(the_mode == 'inc')
	{
		var new_stepup = user_stepup + pt_stepup_gap;
	}
	else
	{
		var new_stepup = user_stepup - pt_stepup_gap;
	}
	
	new_stepup = pt_validate_data(new_stepup, pt_stepup_min, pt_stepup_max);
	
	pt_set_text_field('stepup_quant', new_stepup);	
}

//clicking the button up & down to increase or decrease the quantity
function pt_alt_quant(the_mode)
{
	var user_stepup = parseInt(document.Forminfo.stepup_quant.value,10);
	var user_quant = parseInt(document.Forminfo.quant.value,10);

	//check value
	user_stepup = pt_validate_input(user_stepup, pt_stepup_min);
	user_stepup = pt_validate_data(user_stepup, pt_stepup_min, pt_stepup_max);
	user_quant = pt_validate_input(user_quant, pt_quant_min);
	
	if(the_mode == 'inc')
	{
		var new_quant = user_quant + user_stepup;
	}
	else
	{
		var new_quant = user_quant - user_stepup;
	}
	
	new_quant = pt_validate_data(new_quant, pt_quant_min, pt_quant_max);
	
	pt_set_text_field('quant', new_quant);
}
// image effects
function pt_set_button(the_mode)
{
	show_image('general','process_button'+the_mode, 'gif', 'function_button');
}

//set the quant and stepup field
function pt_set_quant_stepup()
{
	pt_set_text_field('quant', pt_quant_array[0]);
	pt_set_text_field('stepup_quant', (pt_quant_array[1] - pt_quant_array[0]));
}

//------ form related ------
function quote_status(saved_or_notsaved)
{
	if (document.Forminfo.quote_saved)	//if submit_type hidden field exist, do the following
	{
		document.Forminfo.quote_saved.value = saved_or_notsaved;	//when clicking a submit button, check which button is hitted
	}
	reset_quotenum('');
	close_formframe();
}
function reset_quotenum(the_num)
{
	if (parent.document.Forminfo.quote_number)
	{
		parent.document.Forminfo.quote_number.value = the_num;
	}
}
function fields_status(fields_id, fields_className)
{
	obj_fields = document.getElementById(fields_id);
	if(obj_fields.className == fields_className)
	{
		return true;
	}
}

//hide formframe if it already show
function close_formframe()
{
	if(fields_status("formframe_0", "quoter_background"))
	{
		table_expand('formframe','hide_table');
		if(document.getElementById('formframe').src)
		{
			document.getElementById('formframe').src = '';
		}
	}
}

// ------ check which button clicked on quote page and direct the call ------
var buttonClicked = '';

function submit_it(submit_to, target_frame)
{
	return submit_q(submit_to, target_frame, buttonClicked);
}
//**** make sure if those using old shipping system will need a separate submit_q function

function submit_q(submit_to, target_frame, submit_type)	//activate when click on the the submit quote
{
		if (validateit())
		{
			if (document.Forminfo.quote_saved.value == "saved")
			{
				alert("Quote already processed!");
				return false;
			}
			else
			{
				if (document.Forminfo.submit_type)	//if submit_type hidden field exist, do the following
				{
					document.Forminfo.submit_type.value = submit_type;	//when clicking a submit button, check which button is hitted
				}
				
				quote_status("saved");	//mark the user saved the quote so it will not be save again
				document.Forminfo.action = submit_to;
				if((detbrowser == "Internet Explorer" && decOS == "Mac") || detbrowser == "Old Netscape")
				{
					document.Forminfo.target = "_self";
				}
				else
				{
					document.Forminfo.target = target_frame;
				}
			
				//show formframe
				table_expand('formframe','quoter_background');
			
				return true;
			}
		}
		else
		{
			return false;	
		}
}

//sync 2 text fields content
//how to call: text_sync(this, 'username_order');
function text_sync(the_field, syn_to_field_name) //not using
{
	the_field.form[syn_to_field_name].value = the_field.value;
}
//expand hidden table, the table is hidden by css, and show by css
function table_expand(id, newClass) {
	var i=0;
	var obj;
	while (obj = document.getElementById(id+"_"+i)) {	//the "i" for the id need to start from "0"
 		if (newClass) 
		{
			obj.className = newClass; 
		} 
		i++;
	}
}

//------ misc -------
function disableFields()
{
	document.Forminfo.shipgroup.disabled=true;
}

function enableFields()
{
	if (document.Forminfo.zipc.value != "")
	{
		document.Forminfo.shipgroup.disabled=false;
	}
	else
	{
		disableFields();
	}
}

function clickToChangeQuantity(whichButton, upper_quantity_limit)	//orginally when user click on the additional quantity button, they will change the whole price, now only change the text field, can uncomment them to make them work again.
// upper_quantity_limit only used in business card now, it is an optional argument
// clickToChangeQuantity get called in a quote page with the increase quantity button
{
	
	switch(whichButton)	
	{
		case 'increase_quantity':
			if (upper_quantity_limit == null)	//check is this argument exist, if not, set it
			{
				var upper_quantity_limit = 	999999999;
			} 
			if (document.getElementById("third_quantity").innerHTML < upper_quantity_limit)	//make sure the quantity is less than upper_quantity_limit, if it is greater, won't able to add quantity for better price anymore
			{
				calculateAdditionalQuantity(document.getElementById("third_quantity").innerHTML, "increase_quantity");
			}
			break;
		case 'decrease_quantity':
			calculateAdditionalQuantity(document.getElementById("first_quantity").innerHTML, "decrease_quantity");
			break;
	}
	
}

function decrease_quantity(the_quantity, popularQuote, increase_value)	// we are looking at the first value among 3 of them from the extra quote
{
		var last_popularQuote_index = popularQuote.length-1;
		var max_popularQuote = popularQuote[last_popularQuote_index];	//get the last element of the popularQuote
		var new_quantity = the_quantity;
		var the_position = last_popularQuote_index;	//the_postion points to the last position to start with
		
		for (i=0; i<=3; i++)
		{
			var quant_diff = new_quantity - max_popularQuote;	//get the different between the_quantity & the max_popularQuote
			//in this case, the quantity is larger than the max_popularQuote, it means we only need to reduce the quote by the increase_value
			//it may keep in this "if condition" for 3 times if it didn't fall lower than the max popular, otherwise, it will get into else if
			if (quant_diff > 0)
			{
				new_quantity = new_quantity - increase_value;
			}
			else if (quant_diff == 0)	//quantity is equal to the max popular quote, so what we need to do is it go up 3 elements from the last element of the array
			{
				if (popularQuote.length >=3)	//making sure the popularQuote have at least 3 elements to begin with
				{
					for (i=0; i<=2; i++)
					{
						new_quantity = popularQuote[the_position-1];
						the_position--;
					}
					break;
				}
				else
				{
					new_quantity = popularQuote[0];
					break;
				}
			}
			else	//this case only take care if the quantity start with less than the max popular quote, it will not loop if fall in this case & it will not fall in this case once it falls into the above cases
			{
				var position_index = 0;
				for (the_element in popularQuote)	//searching for the index of the quantity
				{
					if (new_quantity == popularQuote[the_element])
					{
						position_index = the_element;
						break;
					}
				}
				
				if (position_index > 3)
				{
					new_quantity = popularQuote[position_index - 4];
					break;
				}
				else
				{
					new_quantity = popularQuote[0];
					break;
				}
			}
		}

		if(new_quantity < BASEQ) //make sure buymore and save will never go pass the min quanity
		{
			new_quantity = BASEQ;
		}
		return new_quantity;
}

/* the following data go to separate js file for different quote pages
	var popularQuote = new Array(250,500,1000,1500,2000,3500,4000);
	//var popularQuote = new Array(250,500);
	var increase_value = 2000;	//this is a value where you set to increase after the last value of popularQuote, 4000 in this case
*/
function calculateAdditionalQuantity(userQuant, increaseOrDecrease)
{
		if (increaseOrDecrease == "decrease_quantity")
		{
				userQuant = decrease_quantity(userQuant, popularQuote, increase_value);
		}
		additionalQuantity = setOtherQuantity(userQuant, popularQuote, 3, increase_value);
				
		document.getElementById("first_quantity").innerHTML = additionalQuantity[0];
		document.getElementById("second_quantity").innerHTML = additionalQuantity [1];
		document.getElementById("third_quantity").innerHTML = additionalQuantity [2];
		
		qqq1 = calcaddprintprice (additionalQuantity[0]);	//array is returned (sub-total, unit price)
		qqq2 = calcaddprintprice (additionalQuantity[1]);
		qqq3 = calcaddprintprice (additionalQuantity[2]);
		
		document.getElementById("first_sub_total").innerHTML = "$" + qqq1[0];
		document.getElementById("second_sub_total").innerHTML = "$" + qqq2[0];
		document.getElementById("third_sub_total").innerHTML = "$" + qqq3[0];

		document.getElementById("first_unit_price").innerHTML = "$" + qqq1[1] + " ea.";
		document.getElementById("second_unit_price").innerHTML = "$" + qqq2[1] + " ea.";
		document.getElementById("third_unit_price").innerHTML = "$" + qqq3[1] + " ea.";		
}

function format_num(the_input)
{
	the_output = round_decimals(the_input, 2);	//2 means 2 decmial places
	return the_output;
}

function format_num_vary(the_input, the_dp)
{
	the_output = round_decimals(the_input, the_dp);	//the_dp mean the decmial places
	return the_output;
}

/* This script is Copyright (c) Paul McFedries and 
Logophilia Limited (http://www.mcfedries.com/).
Permission is granted to use this script as long as 
this Copyright notice remains in place.*/

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function clickToSetQuantityField(whichButton)	//user click the pic under the price and it will set the quant field to the first quantity
{
	switch(whichButton)
	{
		case 'first_quantity_button':
			document.Forminfo.quant.value = document.getElementById("first_quantity").innerHTML;
			calcprintprice ();
			break;
		case 'second_quantity_button':
			document.Forminfo.quant.value = document.getElementById("second_quantity").innerHTML;
			calcprintprice ();
			break;
		case 'third_quantity_button':
			document.Forminfo.quant.value = document.getElementById("third_quantity").innerHTML;
			calcprintprice ();
			break;			
	}
}

//format: oriQuantity=quantity input from user | popularQuantity = an array | numQuote = a number, num of quote you want
//how to call:
//var pq = new Array(500,1000,1500, 2000, 3500);
//kk = setOtherQuantity(2500, pq, 3, 1000);

function setOtherQuantity(orgQuantity, popularQuantity, numQuote, numStepUp)	
{
		var theQuantity = parseInt(orgQuantity);	//the original quantity, make sure it is an integer (parseInt)		
		
		var propular_quantity = popularQuantity;	//var propular_quantity = new Array(500,1000,1500, 2000); //can be input from outside
		
		var numOfAdditionalQuote = numQuote;	//var numOfAdditionalQuote = 3;	//how many additional quotes we give

		var stepUpvalue = numStepUp;	//var stepUpvalue = 1000;	//how much you wanna the next quantity if the array out of bound
		var display_quantity = new Array(numOfAdditionalQuote);	// array that will be displayed

		var counter = 0;	//counter for the propular_quantity array index
		
		for (quan=0; quan < propular_quantity.length; quan++)	//quan = 0,1,2,... in this case
		{
			if (theQuantity >= propular_quantity[propular_quantity.length-1])//means the quantity is bigger than all of the preset quantity
			{
				startIndex = 0;
				display_quantity[startIndex] = theQuantity + stepUpvalue;	//set the user quantity + 1000 to start with
				for (i=0; i<numOfAdditionalQuote-1; i++)	//loop only 2 times cause the first element is assigned above
				{
					startIndex++;
					display_quantity[startIndex] = display_quantity[startIndex-1] + stepUpvalue;
				}
				break; //if you are in this case, you don't want to do the previous for-loop again
			}
			else if (theQuantity >= propular_quantity[quan])	//try to find out the first popular quantity that is bigger than the org. quantity, then goto else case below
			{
				counter++;
				continue;
			}
			else	//in this case we get the original quantity that is smaller than the first popular quantity
			{
				startIndex = 0;
				for (i=0; i<numOfAdditionalQuote; i++)	//loop 3 times
				{
					if (propular_quantity[counter])	//if out of bound, will goto else case
					{
						display_quantity[startIndex] = propular_quantity[counter];
					}
					else
					{
						display_quantity[startIndex] = display_quantity[startIndex-1] + stepUpvalue; //if out of bound, the last value will eg.+1000
					}
					startIndex++;
					counter++;
				}
				break; //if you are in this else, you don't want to do the previous for-loop again
			}
		}
		return display_quantity;
}

function printfriendly()	//print order summary
{ 
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no,"; 
      disp_setting+="scrollbars=auto,width=320, height=310, left=100, top=25"; 
  var content_value = document.getElementById("print_content").innerHTML;
  var quote_type = parent.document.Forminfo.ftype.value;
  
  var quote_title = 'Quote Summary for ';
  var additional_notices = '';
  var quote_or_summary = 'quote';
  
  var company_phone = "1.800.995.1555";
  var company_fax = "406.771.7777";
  var company_email = "support@printingcenterusa.com";
  
  var quote_number = parent.document.Forminfo.quote_number.value;
  if (quote_number == '')
  {
	  quote_or_summary = 'summary';
	  quote_title = 'Summary for ';
	  additional_notices = 'To submit a copy of this quote and obtain a quote number, please go back and click "email and save your quote".';
	  //quote_number = 'N/A';
  }
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Quote :: ' + quote_type + '</title>');
   docprint.document.write('<link href="../CSS/quote_page.css" rel="stylesheet" type="text/css">');
   docprint.document.write('<link href="../CSS/css_common.css" rel="stylesheet" type="text/css">');
   docprint.document.write('<script>');
   docprint.document.write('function printme() {');
   docprint.document.write('if (window.print) ');
   docprint.document.write('{');
   docprint.document.write('window.print(); ');
   docprint.document.write('self.close(); ');
   docprint.document.write('}');
   docprint.document.write('else ');
   docprint.document.write('{');
   docprint.document.write('alert("Sorry, your browser is not supporting auto print, please use CTRL-P or APPLE-P to print!"); ');
   docprint.document.write('}');
   docprint.document.write('} ');
   docprint.document.write('</script>');
   docprint.document.write('</head><body onLoad="printme()" style="background-color:#FFF">');
   
   docprint.document.write('<table width="300" border="0" align="center" cellpadding="0" cellspacing="0" class="quoter_background">');
   
   docprint.document.write('<tr><td height="65" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">');
   docprint.document.write('<tr><td width="4" height="35">&nbsp;</td><td width="290" valign="top">');
   docprint.document.write('<p><img src="../Images/general/pcusa-logo-public-small.gif" width="176" height="35" /></p></td><td width="4">&nbsp;</td></tr><tr>');
   docprint.document.write('<td height="25"></td><td valign="top" class="print_quote_title">' + quote_title + quote_type + '</td>');
   docprint.document.write('<td></td></tr><tr><td height="5"></td><td></td><td></td></tr></table></td></tr>');
   docprint.document.write('<tr><td width="4" height="15"></td><td width="288" class="print_notice">This '+quote_or_summary+' is valid for 30 days from: ' + Date() + '<br>' + additional_notices + '</td><td width="4" height="15"></td>');
   docprint.document.write('</tr><tr><td height="12"></td><td>&nbsp;</td></tr><tr><td height="255"></td><td valign="top">');

	if (quote_number != '')
	{
   		docprint.document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="119" height="15" valign="top" class="quote_summary_nobold_v2">quote number</td><td width="171" valign="top" class="quote_summary_nobold_value_v2"><span id="summary_quote_num">'+quote_number+'</span></td></tr></table>');
	}

   docprint.document.write(content_value);
   
   docprint.document.write('</td></tr><tr><td height="10"></td><td></td></tr><tr>');
   docprint.document.write('<td height="26" colspan="2" valign="top"><p class="page_pic">phone: ' + company_phone + ' | fax: ' + company_fax + '<br />');
   docprint.document.write('<a href="mailto:' + company_email + '">email: ' + company_email + '</a></p></td>');
   docprint.document.write('</tr><tr><td height="4"></td><td></td></tr></table></body></html>');
   docprint.document.close(); 
   docprint.focus(); 
}

function print_help_text(img_name, img_width, img_height)	//print help_text
{ 
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no,"; 
      disp_setting+="scrollbars=auto,width=539, height=310, left=100, top=25"; 
  var site_address = "http://www.printingcenterusa.com/";
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Quotalator Description</title>');
   docprint.document.write('<script>');
   docprint.document.write('function printme() {');
   docprint.document.write('if (window.print) ');
   docprint.document.write('{');
   docprint.document.write('window.print(); ');
   docprint.document.write('self.close(); ');
   docprint.document.write('}');
   docprint.document.write('else ');
   docprint.document.write('{');
   docprint.document.write('alert("Sorry, your browser is not supporting auto print, please use CTRL-P or APPLE-P to print!"); ');
   docprint.document.write('}');
   docprint.document.write('} ');
   docprint.document.write('</script>');
   docprint.document.write('</head><body onLoad="printme()" style="background-color:#FFF">');
   
   docprint.document.write('<img src="'+site_address+'images/general/'+img_name+'" width="'+img_width+'" height="'+img_height+'" hspace=5 vspace=5 border="0">');
   
   docprint.document.write('</body></html>');
   
   docprint.document.close(); 
   docprint.focus(); 
}

//onclick, highlight all text in the textbox
//how to call: onclick="selectall(all);"
function selectAll(theField)
{
	theField.focus();
	theField.select();
}

// ------ create auto. pull down menu ----- //
function auto_pulldown(selectCtrl, itemArray, current_selected, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null; 
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1]; 
}
j++;
}
// select first item (prompt) for sub list

if (selectCtrl.options[current_selected])	//check if the current choice will still be valid if the new pull down generate
{
	selectCtrl.options[current_selected].selected = true;
}
else
{
	selectCtrl.options[0].selected = true;
}
	}
}
//  End -->

function hideSelectBoxes(){
for(var i=0;i<document.forms.length;i++){
for(var e=0;e<document.forms[i].length;e++){
if(document.forms[i].elements[e].tagName=="SELECT"){
document.forms[i].elements[e].style.visibility="hidden";
}
}
}
}
function displaySelectBoxes(){
for(var i=0;i<document.forms.length;i++){
for(var e=0;e<document.forms[i].length;e++){
if(document.forms[i].elements[e].tagName=="SELECT"){
document.forms[i].elements[e].style.visibility="visible";
}
}
}
}

function get_position(the_array, position_name)	// search for new position in new generated pull down according to the selected name of this pull down menu
{
	var the_result = "not found";
	
	for (i = 0; i < the_array.length; i++)
	{
		if (the_array[i][0] == position_name)
		{
			the_result = i;
			break;
		}
	}
	
	if (the_result == "not found")
	{
		return 0;
	}
	else
	{
		return the_result;
	}
}

/*
how to call:
var myresult = 	word_search("4 color front, 1color inside", "4");
if (myresult)
{
	document.write("There was a match");
}
else
{
	document.write("There was no match in the string");
}
*/
function word_search(input_string, input_RegExp)
{
	var the_string = input_string;
	
	if (the_string == null)
	{
		return false;	
	}

	var the_RegExp = input_RegExp.toString();
	var the_search_result = the_string.search(the_RegExp);
	
	if(the_search_result != -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function IsNumeric(sText)	//check if the sText is a number or not // for quote pages //check zip code

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


//how to call: auto_calculate(this)
function auto_calculate(field_obj)	//auto run function after certain time
{
	var the_id = field_obj.id;
	var the_value = field_obj.value;
	
	if(the_id == 'zipc')
	{
		var time_period = 0;
		var function_call = 'check_zip_onkeyup()';
	}
	else if(the_id == 'promo')
	{
		var time_period = 1;
		var function_call = 'calcprintprice()';
	/*	monthly promo for non-shipping related	
		var function_call_2 = 'monthly_promo()';
	*/
	}
	else	//additional sheet or envelopes
	{
		var time_period = 10000;
		var function_call = "check_quant_onkeyup('"+the_id+"','"+the_value+"')";	
	}
	/*	monthly promo for non-shipping related	
	
	if(function_call_2)	//monthly promo
	{
		var t2 = setTimeout(function_call_2,time_period);
	}
	*/	
	var t=setTimeout(function_call,time_period);	
}

//how to call: check_quant_onkeyup(id, value)
function check_quant_onkeyup(the_id, the_value)	// for quote pages
{
	if (IsNumeric(parseInt(the_value)))
	{
		//onChange, this is located at xyz_general.js
		//the field_name have to be the same as the_id
		onChange(the_id);	
	}
}


function check_zip_onkeyup()	// for quote pages
{
	var zip_field = document.Forminfo.zipc;
	var ship_field = document.Forminfo.shipgroup;
	
	if (zip_field.getAttribute && zip_field.value.length==zip_field.getAttribute("maxlength") && IsNumeric(zip_field.value))
	{
		onChange('zipc');	//calculate the shipping cost
		ship_field.disabled=false;
		ship_field.focus();
	}
	else if (zip_field.getAttribute && zip_field.value.length==0)	//when user erase the zip code, it disable the shipping method field
	{
		//document.Forminfo.shipgroup.selectedIndex = 0;
		ship_field.disabled=true;
	}
	else
	{
		//do nothing
	}
	
}

function check_zip_onchange()	//check if the zip code is less than 5 digits // for quote pages
{
	var zip_field = document.Forminfo.zipc;
	var ship_field = document.Forminfo.shipgroup;
	
	if (zip_field.value.length < 5)
	{
		showPopWin('../help_text/general/help_text_wrong_zip.html', 510, 200);
		ship_field.disabled=true;
	}		
}

function check_quantity()	//remove everythings beside numbers from the text field // for quote pages
{
	var quantity_field = document.Forminfo.quant;
	
	if (!IsNumeric(quantity_field.value))
	{
		var char_lenght = quantity_field.value.length;
		var last_char = quantity_field.value.charAt(char_lenght -1);
		quantity_field.value = quantity_field.value.replace(last_char,"");
		if (!IsNumeric(quantity_field.value))	//check again if the quantity the user entered are all numbers
		{
			quantity_field.value = "";
		}
		quantity_field.focus();
	}
}

//how to call: check_quant(this)
function check_quant(form_object)	//check if the input are numbers// should remove the above function & use this one!
{
	var quantity_field = form_object;
	if (!IsNumeric(quantity_field.value))
	{
		var char_lenght = quantity_field.value.length;
		var last_char = quantity_field.value.charAt(char_lenght -1);
		quantity_field.value = quantity_field.value.replace(last_char,"");
		if (!IsNumeric(quantity_field.value))	//check again if the quantity the user entered are all numbers
		{
			quantity_field.value = "";
		}
		quantity_field.focus();
	}
}


function autoZip(session_zip)	//fill out zip code with session variables	// not using
{
	var zip_field = document.Forminfo.zipc;
	var ship_field = document.Forminfo.shipgroup;
	if (zip_field.value == "")	//if there is already stuff there, don't change the zip
	{
		zip_field.value = session_zip;
		onChange('zipc');
		ship_field.disabled=false;
		ship_field.focus()
	}
}

//------ shipping ------ goal: put calshipping here too
function file2speczone (CurrentValue) 
{
	zone = 0;
	for (i=0;i<74;i++) 
	{
		if (z2spec[i] == ziptot) 
		{
			if (CurrentValue == 4) 
			{	//next day - test case zip eg. 96858
				ratea = z124;
				zone = 124;
				break;
			} 
			else 
			{	//2nd day - test case zip eg. 96858
				ratea = z224;
				zone = 224;
				break;
			}
		} 
	}
	if (zone == 0) 
	{
		if (CurrentValue == 4) 
		{	//next day	- test case zip eg. 96864
			ratea = z126;
			zone = 126;
		} 
		else 
		{	//2nd day - test case zip eg. 96864
			ratea = z226;
			zone = 226;
		}
	}
}

function file3speczone (CurrentValue) 
{
	zone = 0;
	for (i=0;i<56;i++) 
	{
		if (z3spec[i] == ziptot) 
		{
			if (CurrentValue == 4) 
			{	//next day air - test case zip eg. 99703
				ratea = z124;
				zone = 124;
				break;
			} 
			else 
			{	// 2nd day - test case zip eg. 99703
				ratea = z224;
				zone = 224;
				break;
			}
		}
	}
	if (zone == 0) 
	{
		if (CurrentValue == 4) 
		{	//next day air - test case zip eg. 99704
			ratea = z126;
			zone = 126;
		} 
		else 
		{	// 2nd day - test case zip eg. 99704
			ratea = z226;
			zone = 226;
		}
	}
}

function fixsm(choiceValue, choiceName) 
{
	document.Forminfo.sm.value = choiceValue;
	document.Forminfo.shipc.value = choiceName;
}

function filezone () 
{
	i = 0;
	while (ZO[i] [0] <= zippre) 
	{
		i++;
	}

	i--;

	zone = ZO[i] [sm];

	switch (zone) 
	{
		case 2: ratea = z2c; break;
		case 3: ratea = z3c; break;
		case 4: ratea = z4c; break;
		case 5: ratea = z5c; break;
		case 6: ratea = z6c; break;
		case 7: ratea = z7c; break;
		case 8: ratea = z8c; break;
		case 102: ratea = z102; break;
		case 103: ratea = z103; break;
		case 104: ratea = z104; break;
		case 105: ratea = z105; break;
		case 106: ratea = z106; break;
		case 107: ratea = z107; break;
		case 108: ratea = z108; break;
		case 124: ratea = z124; break;
		case 125: ratea = z125; break;
		case 126: ratea = z126; break;
		case 202: ratea = z202; break;
		case 203: ratea = z203; break;
		case 204: ratea = z204; break;
		case 205: ratea = z205; break;
		case 206: ratea = z206; break;
		case 207: ratea = z207; break;
		case 208: ratea = z208; break;
		case 224: ratea = z224; break;
		case 225: ratea = z225; break;
		case 226: ratea = z226; break;
		case 302: ratea = z302; break;
		case 303: ratea = z303; break;
		case 304: ratea = z304; break;
		case 305: ratea = z305; break;
		case 306: ratea = z306; break;
		case 307: ratea = z307; break;
		case 308: ratea = z308; break;
	}
}

//------ promo ------
function calcpromo(promo_type, the_total, the_quant)
{
	tdate = new Date();
	
	var promo_code = '';	//hidden promo code field
	var promo_amount = 0;	//discount amount
	var promo_minimum = 0;	//minimum $ or quantity
	var promo_by = '';		//by dollar or quantity
	var promo_in = '';		//in $ or %
	var final_promo_amount = 0;
	var final_promo_code = '';
	
	var user_promocode = document.Forminfo.promo.value.toUpperCase();
	var user_zipcode = document.Forminfo.zipc.value;
	var user_quantity = the_quant;
	var grand_total = the_total;

	if(user_promocode)
	{
	//search if the promo code exist & asign it to variables
		for (i=0;i<PROMO.length;i++) //aitems is in the promo js
		{
			if ( user_promocode == PROMO[i] [0] && PROMO[i] [promo_type] == 1 && Date.parse(PROMO[i] [19]) >= tdate) 
			{
				//alert('getit');
				promo_code = PROMO[i] [0];
				promo_amount = PROMO[i] [1];
				promo_minimum = PROMO[i] [2];
				promo_by = PROMO[i] [3];
				promo_in = PROMO[i] [4];
				break;
			}
		}
		if(promo_code && promo_by == 'D' && grand_total >= promo_minimum)	//correct promo & by dollar & > minimum
		{
			if(promo_in == 'F')
			{
				//case 1
				grand_total = grand_total - promo_amount;
				final_promo_amount = format_num(promo_amount);
				final_promo_code = promo_code;
			}
			else if(promo_in == 'P')
			{
				//case 2
				da = grand_total * promo_amount;
				grand_total = grand_total - da;
				final_promo_amount = format_num(da);
				final_promo_code = promo_code;
			}
			else if(promo_in == 'M')
			{
				//case 3
				da = grand_total * promo_amount;
				if ( da > promo_minimum) 
				{
					da = promo_minimum;
				}
				grand_total = grand_total - da;
				final_promo_amount = format_num(da);
				final_promo_code = promo_code;
			}
			else
			{
				//do nothing
			}
		}
		else if(promo_code && promo_by == 'Q' && user_quantity >= promo_minimum)//correct promo & by quantity & > minimum
		{
			if(promo_in == 'F')
			{
				//case 1
				grand_total = grand_total - promo_amount;
				final_promo_amount = format_num(promo_amount);
				final_promo_code = promo_code;
			}
			else if(promo_in == 'P')
			{
				//case 2
				da = grand_total * promo_amount;
				grand_total = grand_total - da;
				final_promo_amount = format_num(da);
				final_promo_code = promo_code;
			}
			else if(promo_in == 'M')
			{
				//case 3
				da = grand_total * promo_amount;
				if ( da > promo_minimum) 
				{
					da = promo_minimum;
				}
				grand_total = grand_total - da;
				final_promo_amount = format_num(da);
				final_promo_code = promo_code;
			}
			else
			{
				//do nothing
			}
		}
		else if((user_promocode == SHIPPROMOC || user_promocode == SHIPFREE || user_promocode == SHIPMONTHLY) && user_zipcode)	//special shipping promo
		{
			oldsm = document.Forminfo.sm.value;
			sm = 1;
			calcshipping();
			discrate = rate;
			if (discrate >= 250) {
				discrate = 250;
			}
			rate = oldrate - discrate;
			sm = oldsm;
			document.Forminfo.hshipcost.value = format_num(rate);
			document.getElementById('real_shipping_cost').innerHTML = '$' + format_num(rate);
			document.getElementById('summary_shipping_cost').innerHTML = '$' + format_num(rate);
			final_promo_amount = format_num(discrate);
			final_promo_code = user_promocode;
		}
		else if(valid_monthly_promo() && user_zipcode)	//monthly shipping promo
		{
			oldsm = document.Forminfo.sm.value;
			sm = 1;
			calcshipping();
			discrate = rate;
			if (discrate >= 250) {
				discrate = 250;
			}
			rate = oldrate - discrate;
			sm = oldsm;
			document.Forminfo.hshipcost.value = format_num(rate);
			document.getElementById('real_shipping_cost').innerHTML = '$' + format_num(rate);
			document.getElementById('summary_shipping_cost').innerHTML = '$' + format_num(rate);
			final_promo_amount = format_num(discrate);
			final_promo_code = MONTHLY_PROMO;
		}
		
/*		monthly promo for non-shiping related
		else if (valid_monthly_promo()) //monthly promo
		{
			var monthly_promo_info = calc_monthly_promo(grand_total);
			if(monthly_promo_info)
			{
				grand_total = monthly_promo_info[0];
				final_promo_amount = format_num(monthly_promo_info[1]);
				final_promo_code = MONTHLY_PROMO;
			}
		}
*/		
		else
		{
			//do nothing
		}
	}
	//reset hidden field
	document.Forminfo.promod.value = promo_code;
	document.Forminfo.promoa.value = promo_amount;
	document.Forminfo.promom.value = promo_minimum;
	document.Forminfo.promot.value = promo_by;
	document.Forminfo.promof.value = promo_in;
	document.Forminfo.promoda.value = final_promo_amount;
	document.Forminfo.procode.value = final_promo_code;
	//alert('promo return gtotal: '+grand_total);
	return grand_total;
}
//------ get city & state ------
//call getCityState.asp and pass zip code as queue string, getCityState.asp check database and return city and state
function getCityState()
{
	//check input variable
	var my_zip = document.Forminfo.zipc.value;
	if(my_zip == "" || my_zip == null)
	{
		return;
	}
	
	//register & check xmlhttp object
	var xmlHttp=getXmlHttpObject();
	if(xmlHttp==null)
	{
		return; //browser doesn't support xmlHttp
	}
	
	//processing ajax core
	var asp_url = "http://www.print-designing-studio.com/="+my_zip;
	xmlHttp.onreadystatechange=
	function ()
	{
    	// only if req shows "loaded"
    	if (xmlHttp.readyState == 4) 
		{
        	// only if "OK"
        	if (xmlHttp.status == 200) 
			{
				document.getElementById("summary_city_state").innerHTML = xmlHttp.responseText;
    		} 
			else
			{
            	alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
        	}
    	}
	}

	xmlHttp.open("GET",asp_url,true);
    xmlHttp.send(null);
}
//------ additional envelopes ------
//envw: envelope weight: global: used by cal shipping function
//envprc: envelope price: local
//envelope_field: text fields name for the envelopes or sheets quantity
//min_quant: minimum quantity for the additional envelopes or sheets
function calcenvelope (envelope_field, min_quant, unit_weight, unit_price)
{
	var envq = parseInt(envelope_field.value);
	if (envq > 0) 
	{
		if (envq < min_quant) 
		{
			envelope_field.value = min_quant;
			envq = min_quant;
		}
		
		envw = envq * 1
		envw = envq * unit_weight;
		var envprc = envq * unit_price;
	} 
	else 
	{
		envelope_field.value = 0;
		envw = 0;
		var envprc = 0;
	}
	return envprc;
}
//------ calculate discount ------
function calcdis(tamt) 
{
	if (tamt >= 1500) 
	{
		if ((tamt - 1500) >= 1000) 
		{
			tdamt = tamt * GDISRATE;
		} 
		else 
		{
			difa = (tamt - 1500) / 1000;
			difb = GDISRATE * difa;
			tdamt = tamt * difb;
		}
	} 
	else 
	{
		tdamt = 0
	}
	return tdamt;
}
//------ check quantity: making sure it's in baseq and in multiple of baseq_up ------	//commercial envelopes
function check_quantity(the_quantity)
{
	if (the_quantity < BASEQ) 
	{
		the_quantity = BASEQ;
	} 
	else 
	{
		bvar = BASEQ;
		do 
		{
			if (bvar < the_quantity) 
			{
				bvar = bvar + BASEQ_UP;
			} 
			else 
			{
				the_quantity = bvar;
			}
		} 
		while (bvar != the_quantity)
	}
	return the_quantity;
}
//------ die cutting ------
function die_cutting(user_quant)
{
	return (user_quant * DC[1]) + DC[0];
}
//------ tag ------
function checktag()  {	//not using

	if (document.Forminfo.taglinebox.checked == true) {
		document.Forminfo.tagvar.value = 10;
	} else {
		document.Forminfo.tagvar.value = 0;
	}
	//calcprintprice ();
}
//------ locate price array ------ //calendars & catalogs
function locateprices(array_name) 
{
	var price_array = window[array_name];	//same as using eval(array_name) but better
	return price_array;
}

//------ calculatet paper adjustment ------// not using, was in catalog, 28 page calendars
function calcpapadji(qt,pt) {	

	if (sizepos == 0) {
		tv1 = (qt * PAP[sizepos] [pt] [0]) * MU[sizepos] [npg] [0];
		tv2 = (qt * PAP[sizepos] [pt] [1]) * (MU[sizepos] [npg] [1] );
	} else {
		tv1 = 0;
		tv2 = (qt * PAP[sizepos] [pt] [1]) * (MU[sizepos] [npg] [1] );
	}
	return tv1+tv2;
}
//------ not using function from postcard ------
function calcfprc(qt,fp,pp,pau) {
			
	if (pp > 0) {
		if ( fp < 3) {
			rvar = (FA[0] [pau] * qt) + FA[0] [3];
		} else {
			rvar = (FA[1] [pau] * qt) + FA[1] [3];
		}
	} else {
		rvar = 0;
	}
	return rvar;					
}
//------ another not using function from postcard ------
function calcpp(pp,sp) {
				
	switch (pp) {
		case "0" :
			rvar = 0;
			break;
		case "1":
			rvar = proofprc = PP[0] [sp];
			break;
		case "2":
			rvar = proofprc = PP[1] [sp];
			break;
	}
	return rvar;
}
//------ calculate varnish ------ // only using in brochures & posters
function calc_varnish(varnish_choice, size_choice, the_quant)
{
	if(varnish_choice == 0)	//no varnish
	{
		var varnish_price = 0;
	}
	else if(varnish_choice == 1)	//varnish 1 side
	{
		var varnish_price = varnish_it(size_choice, the_quant, VA_min_quant_1side[size_choice], 1);
	}
	else	//varnish 2 sides (both sides)
	{
		var varnish_price = varnish_it(size_choice, the_quant, VA_min_quant[size_choice], 2);
	}
	return varnish_price;
}
//------ use by the calc_varnish function ------
function varnish_it(size_option, my_quant, min_quant, the_sides)
{
	if (my_quant > min_quant) 
	{
		var varnish_cost = ((the_sides * (my_quant - min_quant) / VA_paper_per_sheet[size_option]) * VA_unit_price[size_option]) + VA_setup_fee[size_option];
	} 
	else 
	{
		var varnish_cost = VA_setup_fee[size_option];
	}
	return 	varnish_cost;
}
//------ locate quant in BASEQ ------//compare from the biggest quant in BASEQ, get the first smaller value
//------ get the overbase ------
function quant_locator(the_array, the_value)//4x9, rack_card, jumbo postcard
{
	for (var i=the_array.length-1; i>0; i--)
	{
		if (the_value >= the_array[i])
		{
			break;
		}
		else
		{
			continue;
		}
	}
	return i;
}

//------ product type ------ // letterhead & envelope
function chgproduct(choiceValue, choiceName)  
{
	document.Forminfo.product_pos.value = choiceValue;
	document.Forminfo.product_type.value = choiceName;					
}

//------ number of pages ------ // catalog
function chgnump(choiceValue, choiceName)  
{
	document.Forminfo.npg.value = choiceValue;
	document.Forminfo.hnumpg.value = choiceName;
}
//------ bound & staple ------ // catalog
function chgstaple(choiceValue, choiceName)  
{	//not using for pricing, only for DB and email
	document.Forminfo.staplepos.value = choiceValue;
	document.Forminfo.staplec.value = choiceName;
}
//------ ink (onside)------ //brochures
function chgink(choiceValue, choiceName)  
{
	document.Forminfo.binkpos.value = choiceValue;
	document.Forminfo.finkc.value = choiceName;
	document.Forminfo.binkc.value = choiceName;
}
//------ back page ------//business card
function chgbackpage(choiceValue, choiceName)
{
	document.Forminfo.binkpos.value = choiceValue;
	document.Forminfo.hbackpage.value = choiceName;
}
//------ cover outside color ------	//catalog
function chgfbink(choiceValue, choiceName)  
{
	document.Forminfo.hcink.value = choiceName;
}

//------ cover inside color ------ //catalog
function chgcink(choiceValue, choiceName)  
{
	document.Forminfo.hcink.value = choiceName;
}

//------ inside color ------ //catalog
function chgiink(choiceValue, choiceName)  
{
	document.Forminfo.iinkpos.value = choiceValue;
	document.Forminfo.hiink.value = choiceName;
}

//------ front ink ------	//poster
function chgfink(choiceValue, choiceName)  
{
	document.Forminfo.finkpos.value = choiceValue;
	document.Forminfo.finkc.value = choiceName;
}
//------ back ink ------	//poster
function chgbink(choiceValue, choiceName)  
{
	document.Forminfo.binkpos.value = choiceValue;
	document.Forminfo.binkc.value = choiceName;
}
//------ paper size ------
function chgpapsize(choiceValue, choiceName)  
{
	document.Forminfo.sizepos.value = choiceValue;
	document.Forminfo.psizec.value = choiceName;
}
//------ additional paper ------	//was in poster, but not using
function calcaddpaper(qt,sp,pp) //wall calendars
{
	return qt * PA[sp] [pp] [1];
}
//------ paper type ------// normal
function chgpaptype(choiceValue, choiceName)  
{
	document.Forminfo.paperpos.value = choiceValue;	
	document.Forminfo.ptypec.value = choiceName;
}
//------ cover paper type ------// catalog
function chgpaptypec(choiceValue, choiceName)  
{
	document.Forminfo.pcpos.value = choiceValue;	
	document.Forminfo.hcpap.value = choiceName;
}
//------ inside paper type ------// catalog
function chgpaptypei(choiceValue, choiceName)  
{
	document.Forminfo.pipos.value = choiceValue;
	document.Forminfo.hipap.value = choiceName;
}
//------ security / not seecurity envelope ------// commercial envelope
function chgtint(choiceValue, choiceName)  {	//security or not

	document.Forminfo.tintpos.value = choiceValue;
	document.Forminfo.tintc.value = choiceName;
}
//------ window or not window envelope ------//commercial envelope
function chgstylet(choiceValue, choiceName)  {	//window or no window

	document.Forminfo.stylepos.value = choiceValue;
	document.Forminfo.stylec.value = choiceName;
}

//------ pockets ------// presentation folder
function chgpocket(choiceValue, choiceName)  {	//Pockets

	document.Forminfo.pocketpos.value = choiceValue;
	document.Forminfo.pocketc.value = choiceName;
}
//------ business card slit ------// presentation folder
function chgbcs(choiceValue, choiceName)  {	//Bus. Card Slit

	document.Forminfo.bcspos.value = choiceValue;
	document.Forminfo.bcsc.value = choiceName;	//eg. both side
}
//------ cd slit ------// presentation folder
function chgcdpos(choiceValue, choiceName)  {	//CD Slit

	document.Forminfo.cdpos.value = choiceValue;
	document.Forminfo.cdc.value = choiceName;
}
//------ folding ------
function chgfold(choiceValue, choiceName)  //folding
{	
	document.Forminfo.foldpos.value = choiceValue;
	document.Forminfo.foldc.value = choiceName;
}//------ varnish ------
function chgvarnpos(choiceValue, choiceName)  
{
	document.Forminfo.varnpos.value = choiceValue;
	document.Forminfo.varnc.value = choiceName;
}
//------ turnaround ------
function chgrushrate(choiceValue, choiceName, choiceIndex)  
{
	document.Forminfo.rushrate.value = RR[choiceValue];
	document.Forminfo.rushc.value = choiceName;
	document.Forminfo.rushpos.value = choiceIndex;
}
//------ proof ------
function chgproof(choiceValue, choiceName)  
{
	proofprc = 0;
	document.Forminfo.proofpos.value = choiceValue;
	document.Forminfo.proofc.value = choiceName;
}