/* Author: Flavia Nascimento
   Date: February 21, 2002
   Developed for: Photo Features & Icruz Design
*/

// constants... price list... to facilitate the price list update...


_5x7_1=12.75	     // fist copy
_5x7_2to10=6.65    // price for second to tenth 
_5x7_11to25=4.75   // from 11th to 25th
_5x7_26to50=3.45   // frm 26th to 50th
_5x7_51to100=1.85  // from 51 th to 100th


_8x10_1=18.00
_8x10_2to10=7.70
_8x10_11to25=5.75
_8x10_26to50=4.25
_8x10_51to100=3.20

_11x14_1=31.50
_11x14_2to10=14.30
_11x14_11to25=8.75
_11x14_26to50=6.90
_11x14_51to100=6.10

_16x20_1=44.10
_16x20_2to10=24.50
_16x20_11to25=15.75
_16x20_26to50=13.00
_16x20_51to100=11.10

_20x24_1=66.25
_20x24_2to10=40.25
_20x24_11to25=34.00
_20x24_26to50=34.00
_20x24_51to100=34.00

_24x30_1=99.00
_24x30_2to10=60.50
_24x30_11to25=51.40
_24x30_26to50=51.40
_24x30_51to100=51.40

_30x40_1=132.50
_30x40_2to10=81.00
_30x40_11to25=69.00
_30x40_26to50=69.00
_30x40_51to100=69.00

match = 0.5
sepiaT = 10.00

se1=10
se2=6
se3=5
se4=4
se5=3

// price list B&W

bw4x5_1=4.25
bw4x5_2to10=3.45
bw4x5_11to25=3.25
bw4x5_26to50=2.50
bw4x5_51to100=1.60


bw5x7_1=7.50	     // fist copy
bw5x7_2to10=4.50    // price for second to tenth 
bw5x7_11to25=3.75   // from 11th to 25th
bw5x7_26to50=2.65   // frm 26th to 50th
bw5x7_51to100=1.85  // from 51 th to 100th


bw8x10_1=12.50
bw8x10_2to10=5.75
bw8x10_11to25=4.75
bw8x10_26to50=3.70
bw8x10_51to100=2.65

bw85x11_1=13.50
bw85x11_2to10=6.90
bw85x11_11to25=5.70
bw85x11_26to50=4.45
bw85x11_51to100=3.30

bw11x14_1=15.75
bw11x14_2to10=11.25
bw11x14_11to25=9.50
bw11x14_26to50=8.25
bw11x14_51to100=6.90

bw16x20_1=30.25
bw16x20_2to10=25.50
bw16x20_11to25=22.25
bw16x20_26to50=18.55
bw16x20_51to100=16.50

bw20x24_1=42.50
bw20x24_2to10=32.00
bw20x24_11to25=29.75
bw20x24_26to50=25.50
bw20x24_51to100=21.20



// variables declaration to hold the totals ---------------------------

highQColorPrintTotal_5x7= 0
highQColorPrintTotal_8x10= 0
highQColorPrintTotal_11x14 = 0
highQColorPrintTotal_16x20 = 0
highQColorPrintTotal_20x24 = 0
highQColorPrintTotal_24x30 = 0
highQColorPrintTotal_30x40 = 0
theGrandTotal = 0

bw_highQColorPrintTotal_5x7= 0
bw_highQColorPrintTotal_8x10= 0
bw_highQColorPrintTotal_11x14 = 0
bw_highQColorPrintTotal_16x20 = 0
bw_highQColorPrintTotal_20x24 = 0
bw_highQColorPrintTotal_4x5 = 0
bw_highQColorPrintTotal_85x11 = 0
bw_theGrandTotal = 0


// -------------------- FUNCTIONS -----------------------------

function clearVariables(){  // to empity the variables
// it is called on reset and on calculate

highQColorPrintTotal_5x7= 0
highQColorPrintTotal_8x10= 0
highQColorPrintTotal_11x14 = 0
highQColorPrintTotal_16x20 = 0
highQColorPrintTotal_20x24 = 0
highQColorPrintTotal_24x30 = 0
highQColorPrintTotal_30x40 = 0
theGrandTotal = 0


}// end func ---------------------------------------



function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
return ("$" + num + "." + cents);
}

// Is it A positive integer?- validates the quantity entry
function isInt(elm, msg, maxQuant) {
	if (elm.value >= 0 && elm.value < maxQuant){
		return true
		
	}else if (elm.value > maxQuant){
		alert ("For this amount, please contact us at (613) 729-9076 for a special volume discount")
		elm.focus()
		elm.value = 0
		return false
	}else{
		alert ("Please enter a numeric value for the quantity of " + msg)
		elm.focus()
		elm.value = 0
		return false
		} // end if
	   	 
   }//end func ------------------------   
// checks weather the checkBox is selected or not. If it is gets the value 
	
	function getCheckBoxValue(checkBox, value){
	with (checkBox.form) {

	if (checkBox.checked == true)
	return eval(value);
	else
	return 0;
	}
	}// end func ----------------------------------

function verifyIfQuantIsNotZero(qt,chkBox){

if (qt.value == "0"){
alert ("Please enter a quantity");
chkBox.checked = false 
qt.focus();
return false;
}else{

return true
}


}// end function
	
function validateQuant(total){ // prompt the user a message if all quantities is Zero 

	if (total =="0" ){
		alert("Please enter the number of films to be processed")
		}else {
		}
		
}// end function
   
function getHighQColorPrice(quant,p1, p2, p3, p4, p5, cmatch){ // this is the basic formula
// p=price

	if (quant <101 && quant > 50){
		return ( p1 + (9*p2) + (15*p3) + (25*p4) + ((quant - 50)*p5) + (p1*cmatch));
	}else if (quant <51 && quant > 25){
		return (p1 + (9*p2) + (15*p3) + ((quant - 25)*p4) + (p1*cmatch));
	}else if (quant <26 && quant > 10){
		return  (p1 + (9*p2) + ((quant - 15)*p3) + (p1*cmatch));
	}else if (quant <11 && quant > 1){
		return  (p1 + ((quant - 1)*p2) + (p1*cmatch));
	}else if (quant <2 && quant > 0){
		return (p1 + (p1*cmatch));
	}else if (quant == 0){
		return 0;
	}else if (quant == ""){
		
		return 0;

	}// end if


}// end function -------------------------

function getPrice_5x7(Q){  // gets the total of
				
		highQColorPrintTotal_5x7 = getHighQColorPrice(Q, _5x7_1, _5x7_2to10, _5x7_11to25, _5x7_26to50, _5x7_51to100, getCheckBoxValue(document.frmCustPrintColor.chkMatch1, match));
		document.frmCustPrintColor.txtTotal1.value = formatCurrency(highQColorPrintTotal_5x7);
		document.frmCustPrintColor.txt_3dTotal1.value = formatCurrency(highQColorPrintTotal_5x7*1.5);
	  	document.frmCustPrintColor.txt_1dTotal1.value = formatCurrency(highQColorPrintTotal_5x7*2);

	
} // end func ------------------------------------

function getPrice_8x10(Q){  // gets the total of

		highQColorPrintTotal_8x10 = getHighQColorPrice(Q, _8x10_1, _8x10_2to10, _8x10_11to25, _8x10_26to50, _8x10_51to100, getCheckBoxValue(document.frmCustPrintColor.chkMatch2, match));
		document.frmCustPrintColor.txtTotal2.value = formatCurrency(highQColorPrintTotal_8x10);
		document.frmCustPrintColor.txt_3dTotal2.value = formatCurrency(highQColorPrintTotal_8x10*1.5);
		document.frmCustPrintColor.txt_1dTotal2.value = formatCurrency(highQColorPrintTotal_8x10*2);

			
} // end func ------------------------------------

function getPrice_11x14(Q){  // gets the total of

		highQColorPrintTotal_11x14 = getHighQColorPrice(Q, _11x14_1, _11x14_2to10, _11x14_11to25, _11x14_26to50, _11x14_51to100, getCheckBoxValue(document.frmCustPrintColor.chkMatch3, match));
		document.frmCustPrintColor.txtTotal3.value = formatCurrency(highQColorPrintTotal_11x14);
		document.frmCustPrintColor.txt_3dTotal3.value = formatCurrency(highQColorPrintTotal_11x14*1.5);
		document.frmCustPrintColor.txt_1dTotal3.value = formatCurrency(highQColorPrintTotal_11x14*2);

			

} // end func ------------------------------------

function getPrice_16x20(Q){  // gets the total of

		highQColorPrintTotal_16x20 = getHighQColorPrice(Q, _16x20_1, _16x20_2to10, _16x20_11to25, _16x20_26to50, _16x20_51to100, getCheckBoxValue(document.frmCustPrintColor.chkMatch4, match));
		document.frmCustPrintColor.txtTotal4.value = formatCurrency(highQColorPrintTotal_16x20);
		document.frmCustPrintColor.txt_3dTotal4.value = formatCurrency(highQColorPrintTotal_16x20*1.5);
		document.frmCustPrintColor.txt_1dTotal4.value = formatCurrency(highQColorPrintTotal_16x20*2);



} // end func ------------------------------------

function getPrice_20x24(Q){  // gets the total of

		highQColorPrintTotal_20x24 = getHighQColorPrice(Q, _20x24_1, _20x24_2to10, _20x24_11to25, _20x24_26to50, _20x24_51to100, getCheckBoxValue(document.frmCustPrintColor.chkMatch5, match));
		document.frmCustPrintColor.txtTotal5.value = formatCurrency(highQColorPrintTotal_20x24);
		document.frmCustPrintColor.txt_3dTotal5.value = formatCurrency(highQColorPrintTotal_20x24*1.5);
		document.frmCustPrintColor.txt_1dTotal5.value = formatCurrency(highQColorPrintTotal_20x24*2);


} // end func ------------------------------------

function getPrice_24x30(Q){  // gets the total of

		highQColorPrintTotal_24x30 = getHighQColorPrice(Q, _24x30_1, _24x30_2to10, _24x30_11to25, _24x30_26to50, _24x30_51to100, getCheckBoxValue(document.frmCustPrintColor.chkMatch6, match));
		document.frmCustPrintColor.txtTotal6.value = formatCurrency(highQColorPrintTotal_24x30);
		document.frmCustPrintColor.txt_3dTotal6.value = formatCurrency(highQColorPrintTotal_24x30*1.5);
		document.frmCustPrintColor.txt_1dTotal6.value = formatCurrency(highQColorPrintTotal_24x30*2);


} // end func ------------------------------------


function getPrice_30x40(Q){  // gets the total of

		highQColorPrintTotal_30x40 = getHighQColorPrice(Q, _30x40_1, _30x40_2to10, _30x40_11to25, _30x40_26to50, _30x40_51to100, getCheckBoxValue(document.frmCustPrintColor.chkMatch7, match));
		document.frmCustPrintColor.txtTotal7.value = formatCurrency(highQColorPrintTotal_30x40);
		document.frmCustPrintColor.txt_3dTotal7.value = formatCurrency(highQColorPrintTotal_30x40*1.5);
		document.frmCustPrintColor.txt_1dTotal7.value = formatCurrency(highQColorPrintTotal_30x40*2);



} // end func ------------------------------------



function getTheGrandTotal(){ // adds up all  totals

theGrandTotal = highQColorPrintTotal_5x7 + highQColorPrintTotal_8x10 +
highQColorPrintTotal_11x14 + highQColorPrintTotal_16x20 +
highQColorPrintTotal_20x24 + highQColorPrintTotal_24x30 + 
highQColorPrintTotal_30x40;

document.frmCustPrintColor.txtGrandTotal.value = formatCurrency(theGrandTotal);
document.frmCustPrintColor.txt_3dGrandTotal.value = formatCurrency(theGrandTotal*1.5);
document.frmCustPrintColor.txt_1dGrandTotal.value = formatCurrency(theGrandTotal*2);

}// end func ---------------------------------------------------

function getTotals(){ // call the functions to get each total
// it is called by the "calculate" Botton
// validates the quantity entry

clearVariables() // clear old values


if (isInt(document.frmCustPrintColor.txtQuant1, "5 x 7 or Smaller",101)==false
|| isInt(document.frmCustPrintColor.txtQuant2, "8 x 10",101)==false
|| isInt(document.frmCustPrintColor.txtQuant3, "11 x 14",101)==false
|| isInt(document.frmCustPrintColor.txtQuant4, "16 x 20",101)==false
|| isInt(document.frmCustPrintColor.txtQuant5, "20 x 24",101)==false
|| isInt(document.frmCustPrintColor.txtQuant6, "24 x 30",101)==false
|| isInt(document.frmCustPrintColor.txtQuant7, "30 x 40",101)==false){

return false
}else{

getPrice_5x7(document.frmCustPrintColor.txtQuant1.value);   
getPrice_8x10(document.frmCustPrintColor.txtQuant2.value);
getPrice_11x14(document.frmCustPrintColor.txtQuant3.value);
getPrice_16x20(document.frmCustPrintColor.txtQuant4.value); 
getPrice_20x24(document.frmCustPrintColor.txtQuant5.value); 
getPrice_24x30(document.frmCustPrintColor.txtQuant6.value); 
getPrice_30x40(document.frmCustPrintColor.txtQuant7.value);   
getTheGrandTotal();
validateQuant(theGrandTotal);

}//end if
}// end func -----------------------------

// BLACK AND WHITE ----------------------------------

function bw_clearVariables(){  // to empity the variables
// it is called on reset and on calculate
bw_highQColorPrintTotal_5x7= 0
bw_highQColorPrintTotal_8x10= 0
bw_highQColorPrintTotal_11x14 = 0
bw_highQColorPrintTotal_16x20 = 0
bw_highQColorPrintTotal_20x24 = 0
bw_highQColorPrintTotal_4x5 = 0
bw_highQColorPrintTotal_85x11 = 0
bw_theGrandTotal = 0


}// end func ---------------------------------------


function bw_validateQuant(total){ // prompt the user a message if all quantities is Zero 

	if (total =="0" ){
		alert("Please enter the number of films to be processed")
		}else {
		}
		
}// end function-----------------
	


function getSepiaValue(qt, s1,s2,s3,s4,s5, checkBox){

var sep = 0
	if (checkBox.checked == true){

		if (qt> 0 && qt<4)
			sep =  25;
		else if (qt > 3 && qt <11)
			sep =  (s1 + ((qt - 1)*s2));
		else if(qt > 10 && qt < 26)
			sep =  (s1 + (9*s2) + ((qt - 15)*s3));
		else if (qt >25 && qt < 51)
			sep = (s1 + (9*s2) + (15*s3) + ((qt - 25)*s4));
		else if (qt>50 && qt<101)
			sep = (s1 + (9*s2) + (15*s3) + (25*s4) + ((quant - 50)*s5));
		else if (qt == 0)
		sep =  0;
		else if (qt == "")
		sep =  0;
		
		
		
	}else {
	sep= 0;
	}// end if
	//return formatCurrency(sep);
	return sep;


}// end func ----------------------------------

	
function bw_getHighQColorPrice(quant,p1, p2, p3, p4, p5, sep){ // this is the basic formula
var price =0;

	if (quant <101 && quant > 50){
		price = ( p1 + (9*p2) + (15*p3) + (25*p4) + ((quant - 50)*p5) + sep);
	}else if (quant <51 && quant > 25){
		price = (p1 + (9*p2) + (15*p3) + ((quant - 25)*p4) + sep);
	}else if (quant <26 && quant > 10){
		price =  (p1 + (9*p2) + ((quant - 15)*p3) + sep);
	}else if (quant <11 && quant > 1){
		price =  (p1 + ((quant - 1)*p2) + sep);
	}else if (quant <2 && quant > 0){
		price = (p1 + sep);
	}else if (quant == 0){
		price = 0;
	}else if (quant == ""){
		price = 0;

		
	}// end if
	
	//return formatCurrency(price);
	return price;



}// end function -------------------------


function bw_getPrice_5x7(Q){  // gets the total of
																																		
		bw_highQColorPrintTotal_5x7 = bw_getHighQColorPrice(Q, bw5x7_1, bw5x7_2to10, bw5x7_11to25, bw5x7_26to50, bw5x7_51to100, getSepiaValue(document.frmCustPrintBW.txtQuant2.value, se1,se2,se3,se4,se5, document.frmCustPrintBW.chkSepia2));
		document.frmCustPrintBW.txtTotal2.value = formatCurrency(bw_highQColorPrintTotal_5x7);
		document.frmCustPrintBW.txt_3dTotal2.value = formatCurrency(bw_highQColorPrintTotal_5x7*1.5);
	  	document.frmCustPrintBW.txt_1dTotal2.value = formatCurrency(bw_highQColorPrintTotal_5x7*2);

	
} // end func ------------------------------------

function bw_getPrice_8x10(Q){  // gets the total of

		bw_highQColorPrintTotal_8x10 = bw_getHighQColorPrice(Q, bw8x10_1, bw8x10_2to10, bw8x10_11to25, bw8x10_26to50, bw8x10_51to100, getSepiaValue(document.frmCustPrintBW.txtQuant3.value, se1,se2,se3,se4,se5, document.frmCustPrintBW.chkSepia3));
		document.frmCustPrintBW.txtTotal3.value = formatCurrency(bw_highQColorPrintTotal_8x10);
		document.frmCustPrintBW.txt_3dTotal3.value = formatCurrency(bw_highQColorPrintTotal_8x10*1.5);
		document.frmCustPrintBW.txt_1dTotal3.value = formatCurrency(bw_highQColorPrintTotal_8x10*2);

			
} // end func ------------------------------------

function bw_getPrice_11x14(Q){  // gets the total of

		bw_highQColorPrintTotal_11x14 = bw_getHighQColorPrice(Q, bw11x14_1, bw11x14_2to10, bw11x14_11to25, bw11x14_26to50, bw11x14_51to100, getSepiaValue(document.frmCustPrintBW.txtQuant5.value, se1,se2,se3,se4,se5, document.frmCustPrintBW.chkSepia5));
		document.frmCustPrintBW.txtTotal5.value = formatCurrency(bw_highQColorPrintTotal_11x14);
		document.frmCustPrintBW.txt_3dTotal5.value = formatCurrency(bw_highQColorPrintTotal_11x14*1.5);
		document.frmCustPrintBW.txt_1dTotal5.value = formatCurrency(bw_highQColorPrintTotal_11x14*2);

			

} // end func ------------------------------------

function bw_getPrice_16x20(Q){  // gets the total of

		bw_highQColorPrintTotal_16x20 = bw_getHighQColorPrice(Q, bw16x20_1, bw16x20_2to10, bw16x20_11to25, bw16x20_26to50, bw16x20_51to100, getSepiaValue(document.frmCustPrintBW.txtQuant6.value, se1,se2,se3,se4,se5, document.frmCustPrintBW.chkSepia6));
		document.frmCustPrintBW.txtTotal6.value = formatCurrency(bw_highQColorPrintTotal_16x20);
		document.frmCustPrintBW.txt_3dTotal6.value = formatCurrency(bw_highQColorPrintTotal_16x20*1.5);
		document.frmCustPrintBW.txt_1dTotal6.value = formatCurrency(bw_highQColorPrintTotal_16x20*2);



} // end func ------------------------------------

function bw_getPrice_20x24(Q){  // gets the total of

		bw_highQColorPrintTotal_20x24 = bw_getHighQColorPrice(Q, bw20x24_1, bw20x24_2to10, bw20x24_11to25, bw20x24_26to50, bw20x24_51to100, getSepiaValue(document.frmCustPrintBW.txtQuant7.value, se1,se2,se3,se4,se5, document.frmCustPrintBW.chkSepia7));
		document.frmCustPrintBW.txtTotal7.value = formatCurrency(bw_highQColorPrintTotal_20x24);
		document.frmCustPrintBW.txt_3dTotal7.value = formatCurrency(bw_highQColorPrintTotal_20x24*1.5);
		document.frmCustPrintBW.txt_1dTotal7.value = formatCurrency(bw_highQColorPrintTotal_20x24*2);


} // end func ------------------------------------

function bw_getPrice_4x5(Q){  // gets the total of

		bw_highQColorPrintTotal_4x5 = bw_getHighQColorPrice(Q, bw4x5_1, bw4x5_2to10, bw4x5_11to25, bw4x5_26to50, bw4x5_51to100, getSepiaValue(document.frmCustPrintBW.txtQuant1.value, se1,se2,se3,se4,se5, document.frmCustPrintBW.chkSepia1));
		document.frmCustPrintBW.txtTotal1.value = formatCurrency(bw_highQColorPrintTotal_4x5);
		document.frmCustPrintBW.txt_3dTotal1.value = formatCurrency(bw_highQColorPrintTotal_4x5*1.5);
		document.frmCustPrintBW.txt_1dTotal1.value = formatCurrency(bw_highQColorPrintTotal_4x5*2);
	

} // end func ------------------------------------


function bw_getPrice_85x11(Q){  // gets the total of

		bw_highQColorPrintTotal_85x11 = bw_getHighQColorPrice(Q, bw85x11_1, bw85x11_2to10, bw85x11_11to25, bw85x11_26to50, bw85x11_51to100, getSepiaValue(document.frmCustPrintBW.txtQuant4.value, se1,se2,se3,se4,se5, document.frmCustPrintBW.chkSepia4));
		document.frmCustPrintBW.txtTotal4.value = formatCurrency(bw_highQColorPrintTotal_85x11);
		document.frmCustPrintBW.txt_3dTotal4.value = formatCurrency(bw_highQColorPrintTotal_85x11*1.5);
		document.frmCustPrintBW.txt_1dTotal4.value = formatCurrency(bw_highQColorPrintTotal_85x11*2);



} // end func ------------------------------------



function bw_getTheGrandTotal(){ // adds up all  totals

bw_theGrandTotal = bw_highQColorPrintTotal_5x7 + bw_highQColorPrintTotal_8x10 +
bw_highQColorPrintTotal_11x14 + bw_highQColorPrintTotal_16x20 +
bw_highQColorPrintTotal_20x24 + bw_highQColorPrintTotal_4x5 + 
bw_highQColorPrintTotal_85x11;

document.frmCustPrintBW.txtGrandTotal.value = formatCurrency(bw_theGrandTotal);
document.frmCustPrintBW.txt_3dGrandTotal.value = formatCurrency(bw_theGrandTotal*1.5);
document.frmCustPrintBW.txt_1dGrandTotal.value = formatCurrency(bw_theGrandTotal*2);

}// end func ---------------------------------------------------

function bw_getTotals(){ // call the functions to get each total
// it is called by the "calculate" Botton
// validates the quantity entry

bw_clearVariables() // clear old values

if(isInt(document.frmCustPrintBW.txtQuant2, "5 x 7 or Smaller",101)==false
|| isInt(document.frmCustPrintBW.txtQuant3, "8 x 10",101)==false
|| isInt(document.frmCustPrintBW.txtQuant5, "11 x 14",101)==false
|| isInt(document.frmCustPrintBW.txtQuant6, "16 x 20",101)==false
|| isInt(document.frmCustPrintBW.txtQuant7, "20 x 24",101)==false
|| isInt(document.frmCustPrintBW.txtQuant1, "4 x 5",101)==false
|| isInt(document.frmCustPrintBW.txtQuant4, "8.5 x 11",101)==false){
return false

}else{

bw_getPrice_5x7(document.frmCustPrintBW.txtQuant2.value);   
bw_getPrice_8x10(document.frmCustPrintBW.txtQuant3.value);
bw_getPrice_11x14(document.frmCustPrintBW.txtQuant5.value);
bw_getPrice_16x20(document.frmCustPrintBW.txtQuant6.value); 
bw_getPrice_20x24(document.frmCustPrintBW.txtQuant7.value); 
bw_getPrice_4x5(document.frmCustPrintBW.txtQuant1.value); 
bw_getPrice_85x11(document.frmCustPrintBW.txtQuant4.value);   
bw_getTheGrandTotal();
bw_validateQuant(bw_theGrandTotal);

}//end if
}// end func -----------------------------