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

// variables declaration - to easely update price list
// 1 hour processing
// po = process Only  |pp = process & proof | ss = second set | ind = index | ann=annotation

po1= 5.30
pp1 = 15.38
ss1 = 3.60
po2 = 6.50
pp2 = 21.62
ss2 = 5.40
po3 =5.80
pp3 = 16.50
ss3 = 3.60
po4 =6.50
pp4 = 21.62
ss4=5.40
ind= 2.00
ann= 2.00



// variable to hold the selected process value (if p.only or p. & proofs)
proce1=po1
proce2=po2
proce3=po3
proce4=po4

// variables to hold the totoal by line (depending on the film type)
totalline1 =0
totalline2 = 0
totalline3 =0
totalline4 =0
totalProcessing = 0



// 1 to 4 days services

po1_1to4= 5.05
pp1_1to4 = 13.45
ss1_1to4 = 2.88
po2_1to4 = 6.25
pp2_1to4 = 18.85
ss2_1to4 = 4.32
po3_1to4 =5.50
pp3_1to4 =17.65
ss3_1to4 = 2.88
po4_1to4 =6.25
pp4_1to4=18.85
ss4_1to4=4.32

po5_1to4= 5.05
pp5_1to4 = 28.81
ss5_1to4 = 14.40
po6_1to4 = 6.25
pp6_1to4 = 41.89
ss6_1to4 = 21.60

ind_1to4 = 1.50
ann_1to4 = 1.50


// variable to hold the selected process value (if p.only or p. & proofs)
proce1_1to4=po1_1to4
proce2_1to4=po2_1to4
proce3_1to4=po3_1to4
proce4_1to4=po3_1to4
proce5_1to4=po5_1to4
proce6_1to4=po6_1to4


// variables to hold the totoal by line (depending on the film type)

totalline1_1to4 =0
totalline2_1to4 = 0
totalline3_1to4 =0
totalline4_1to4 =0
totalProcessing_1to4 = 0
totalline5_1to4 =0
totalline6_1to4=0


//------------------------------ functions --------------------------


	// 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;
		}
	}
	
// -------------------------------------




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 ------------------------
   
function disableCheck(elm1, elm2, elm3){
// diselect the sset, index and annotation checkboxes on the selection of process only radio button
// it is called by the process only radio butt. (onClick)
	elm1.checked = 0
	elm2.checked = 0
	elm3.checked = 0
	}// end func

// -------------------

function disableCheck_oneArg(radioP, elm1){
// diselect the sset, index and annotation checkboxes on the selection of process only radio button
// it is called by the process only radio butt. (onClick)


	elm1.checked = 0
	
	}// end func

// -------------------

function verifyProcess(radioProcess, checkBox){

// do not allow selection of sset, index and annotation checkboxes, if process only is selected
// it is called on the onBlur method of the checkboxes

	rProcess= -1
	for (i=0; i<radioProcess.length; i++){

		if (radioProcess[i].checked){
		 rProcess = i
		} // end loop

		}
		if (rProcess== 0){
		alert("Please select Process & Proofs, to be able to select this item.")
		checkBox.checked = false
		}else if (rProcess==1){
		//checkBox.checked = true
	}

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


function checkQt(qt, rad){
	

	if(qt.value == "0"){
	alert ("Please enter a quantity")
	qt.focus()
	rad.checked = false;
	rad[0].checked = true;
	proce1=po1; 
	proce1_1to4=po1_1to4;

	return false
	
	}else{
	return true
	}


}// end function

function checkQt2(qt, rad){
	

	if(qt.value == "0"){
	alert ("Please enter a quantity")
	qt.focus()
	rad.checked = false;
	rad[0].checked = true;
	proce2=po2; 
	proce2_1to4=po2_1to4;

	return false
	
	}else{
	return true
	}


}// end function

function checkQt3(qt, rad){
	

	if(qt.value == "0"){
	alert ("Please enter a quantity")
	qt.focus()
	rad.checked = false;
	rad[0].checked = true;
	proce3=po3; 
	proce3_1to4=po3_1to4;

	return false
	
	}else{
	return true
	}


}// end function

function checkQt4(qt, rad){
	

	if(qt.value == "0"){
	alert ("Please enter a quantity")
	qt.focus()
	rad.checked = false;
	rad[0].checked = true;
	proce4=po4; 
	proce4_1to4=po4_1to4;

	return false
	
	}else{
	return true
	}


}// end function

function checkQt5(qt, rad){
	

	if(qt.value == "0"){
	alert ("Please enter a quantity")
	qt.focus()
	rad.checked = false;
	rad[0].checked = true;

	proce5_1to4=po5_1to4;

	return false
	
	}else{
	return true
	}


}// end function

function checkQt6(qt, rad){
	

	if(qt.value == "0"){
	alert ("Please enter a quantity")
	qt.focus()
	rad.checked = false;
	rad[0].checked = true;
	proce6_1to4= po6_1to4	


	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")}
		//frmMiniLab.txtQuant1.focus()
		
}// end function ---------------------------------


function totalbyline(quant, processing, sset, ind, ann){ // this is the basic formula

	return quant * (processing + sset + ind + ann);
	
}// end func


//-------------- 1 hour services  ------------------------------
//--------------------------------------------------------------



function getTotalLine1(){

totalline1 = totalbyline(eval(document.frmMiniLab.txtQuant1.value), proce1, getCheckBoxValue(document.frmMiniLab.chkSset1, ss1), getCheckBoxValue(document.frmMiniLab.chkInd1, ind), getCheckBoxValue(document.frmMiniLab.chkAnn1, ann)); 
document.frmMiniLab.txtTotalLine1.value = formatCurrency(totalline1);

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

function getTotalLine2(){

totalline2 = totalbyline(eval(document.frmMiniLab.txtQuant2.value), proce2, getCheckBoxValue(document.frmMiniLab.chkSset2, ss2), getCheckBoxValue(document.frmMiniLab.chkInd2, ind), getCheckBoxValue(document.frmMiniLab.chkAnn2, ann)); 
document.frmMiniLab.txtTotalLine2.value = formatCurrency(totalline2);

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

function getTotalLine3(){

totalline3 = totalbyline(eval(document.frmMiniLab.txtQuant3.value), proce3, getCheckBoxValue(document.frmMiniLab.chkSset3, ss3), 0, 0); 
document.frmMiniLab.txtTotalLine3.value = formatCurrency(totalline3);

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

function getTotalLine4(){

totalline4 = totalbyline(eval(document.frmMiniLab.txtQuant4.value), proce4, getCheckBoxValue(document.frmMiniLab.chkSset4, ss4), 0, 0); 
document.frmMiniLab.txtTotalLine4.value = formatCurrency(totalline4);

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

function getTotal(){

totalProcessing = totalline1 + totalline2 + totalline3 + totalline4;
document.frmMiniLab.txtTotal1Hour.value = formatCurrency(totalProcessing);

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


//-------------- 2 to 4 Days services  ------------------------------
//--------------------------------------------------------------



function getTotalLine1_1to4(){

totalline1_1to4 = totalbyline(eval(document.frmMiniLab.txtQuant1.value), proce1_1to4, getCheckBoxValue(document.frmMiniLab.chkSset1, ss1_1to4), getCheckBoxValue(document.frmMiniLab.chkInd1, ind_1to4), getCheckBoxValue(document.frmMiniLab.chkAnn1, ann_1to4)); 
document.frmMiniLab.txtTotalLine1_1to4.value = formatCurrency(totalline1_1to4);

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

function getTotalLine2_1to4(){

totalline2_1to4 = totalbyline(eval(document.frmMiniLab.txtQuant2.value), proce2_1to4, getCheckBoxValue(document.frmMiniLab.chkSset2, ss2_1to4), getCheckBoxValue(document.frmMiniLab.chkInd2, ind_1to4), getCheckBoxValue(document.frmMiniLab.chkAnn2, ann_1to4)); 
document.frmMiniLab.txtTotalLine2_1to4.value = formatCurrency(totalline2_1to4);

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

function getTotalLine3_1to4(){

totalline3_1to4 = totalbyline(eval(document.frmMiniLab.txtQuant3.value), proce3_1to4, getCheckBoxValue(document.frmMiniLab.chkSset3, ss3_1to4), 0, 0); 
document.frmMiniLab.txtTotalLine3_1to4.value = formatCurrency(totalline3_1to4);

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

function getTotalLine4_1to4(){

totalline4_1to4 = totalbyline(eval(document.frmMiniLab.txtQuant4.value), proce4_1to4, getCheckBoxValue(document.frmMiniLab.chkSset4, ss4_1to4), 0, 0); 
document.frmMiniLab.txtTotalLine4_1to4.value = formatCurrency(totalline4_1to4);


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

function getTotalLine5_1to4(){

totalline5_1to4 = totalbyline(eval(document.frmMiniLab.txtQuant5.value), proce5_1to4, getCheckBoxValue(document.frmMiniLab.chkSset5, ss5_1to4), getCheckBoxValue(document.frmMiniLab.chkInd5, ind_1to4), getCheckBoxValue(document.frmMiniLab.chkAnn5, ann_1to4)); 
document.frmMiniLab.txtTotalLine5_1to4.value = formatCurrency(totalline5_1to4);


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

function getTotalLine6_1to4(){

totalline6_1to4 = totalbyline(eval(document.frmMiniLab.txtQuant6.value), proce6_1to4, getCheckBoxValue(document.frmMiniLab.chkSset6, ss6_1to4), getCheckBoxValue(document.frmMiniLab.chkInd6, ind_1to4), getCheckBoxValue(document.frmMiniLab.chkAnn6, ann_1to4)); 
document.frmMiniLab.txtTotalLine6_1to4.value = formatCurrency(totalline6_1to4);


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


function getTotal(){

totalProcessing = totalline1 + totalline2 + totalline3 + totalline4;
document.frmMiniLab.txtTotal1Hour.value = formatCurrency(totalProcessing);

}// end func ---------------
function getTotal_1to4(){

totalProcessing_1to4 = totalline1_1to4 + totalline2_1to4 + totalline3_1to4 + totalline4_1to4 + totalline5_1to4 + totalline6_1to4;
document.frmMiniLab.txtTotal_1to4.value = formatCurrency(totalProcessing_1to4);

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

function getTotals(){
	clearVariables();
	
	if (isInt(document.frmMiniLab.txtQuant1, "35mm - 24 Exp.", 51)==false
	|| isInt(document.frmMiniLab.txtQuant2, "35mm - 36 Exp.", 51)==false
	|| isInt(document.frmMiniLab.txtQuant3, "APS - 25 Exp.", 51)==false
	|| isInt(document.frmMiniLab.txtQuant4, "APS - 40 Exp.", 51)==false
	|| isInt(document.frmMiniLab.txtQuant5, "35mm - 24 Exp.", 51)== false
	|| isInt(document.frmMiniLab.txtQuant6, "35mm - 36 Exp.", 51)== false){
	return false

	}else{

	getTotalLine1();
	getTotalLine2();
	getTotalLine3();
	getTotalLine4();
	getTotal();
	getTotalLine1_1to4();
	getTotalLine2_1to4();
	getTotalLine3_1to4();
	getTotalLine4_1to4();
	getTotalLine5_1to4();
	getTotalLine6_1to4();
	getTotal_1to4();


	validateQuant(totalProcessing_1to4);
}//end if



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

function clearVariables(){
// set the variables values to zero

totalline1 =0
totalline2 = 0
totalline3 =0
totalline4 =0

totalline1_1to4 =0
totalline2_1to4 = 0
totalline3_1to4 =0
totalline4_1to4 =0

totalline5_1to4 =0
totalline6_1to4=0

totalProcessing = 0
totalProcessing_1to4 = 0

}// end func
function setIniValues(){
// sets the process value to Proc. Only

proce1=po1
proce2=po2
proce3=po3
proce4=po4
proce1_1to4=po1_1to4
proce2_1to4=po2_1to4
proce3_1to4=po3_1to4
proce4_1to4=po3_1to4
proce5_1to4=po5_1to4
proce6_1to4=po6_1to4


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

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

// _SIZE_QUANTITY...
_4x6_1=1   // so this is size 4x6 quantity 1
_4x6_2to10=0.9   // so this is size 4x6 quantity from 2 to 10
_4x6_11to25=0.75 // so this is size 4x6 quantity from 11 to 25 ...
_4x6_26to50=0.65
	
_5x7_1=3.95
_5x7_2to10=2.7  // so this is size 5x7 quantity from 2 to 10  ...
_5x7_11to25=2.45  
_5x7_26to50=2.2
	
_8x12_1=8.95
_8x12_2to10=7.5
_8x12_11to25=6.6
_8x12_26to50=5.6

pan_1=1.5
pan_2to10=1.35
pan_11to25=1.15 // so this is size pan quantity from 11 to 25
pan_26to50=0.95
	
_8x10_1=7.95
_8x10_2to10=6.5 // so this is size 8x10 quantity from 2 to 10
_8x10_11to25=5.5
_8x10_26to50=4.6
	
digital_1=3.50
digital_2to10=2.50
digital_11to25=2.00
digital_26to50=1.50

// end price list -----------------------------------------------------

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

reprintPrice_4x6 = 0
reprintPrice_pan = 0
reprintPrice_5x7 = 0
reprintPrice_8x10 = 0
reprintPrice_8x12 = 0
reprintPrice_digital = 0
rep_theGrandTotal = 0

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

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

reprintPrice_4x6 = 0
reprintPrice_pan = 0
reprintPrice_5x7 = 0
reprintPrice_8x10 = 0
reprintPrice_8x12 = 0
reprintPrice_digital = 0
rep_theGrandTotal = 0

}// end func


function getReprintPrice(quant,unitPrice){ // this is the basic formula

return quant * unitPrice;

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

function getPrice_4x6(Q){  // gets the total of reprints for the 4 x6 35 mm film



// the conditional stmt is because the price depends on the quantity
var unitPrice = 0;

		if (Q<2) 
			unitPrice = _4x6_1;
		else if (Q > 1 && Q < 11)
			unitPrice = _4x6_2to10;
		else if (Q > 10 && Q < 26)
			unitPrice = _4x6_11to25;
		else if (Q > 25 && Q < 51)
			unitPrice = _4x6_26to50;
				
		reprintPrice_4x6 = getReprintPrice(Q,unitPrice);
		document.frmReprints.txtTotalR4x6.value = formatCurrency(reprintPrice_4x6);
				
	
} // end func ------------------------------------


function getPrice_pan(Q){  // gets the total of reprints for the Pan 35 mm film

var unitPrice = 0;

		if (Q<2) 
		unitPrice = pan_1;
		else if (Q > 1 && Q < 11)
		unitPrice = pan_2to10;
		else if (Q > 10 && Q < 26)
		unitPrice = pan_11to25;
		else if (Q > 25 && Q < 51)
		unitPrice = pan_26to50;
		reprintPrice_pan = getReprintPrice(Q,unitPrice);
		document.frmReprints.txtTotalRpan.value = formatCurrency(reprintPrice_pan);

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

function getPrice_5x7(Q){  // gets the total of reprints for the 5 x 7 35 mm film

var unitPrice = 0;

		if (Q<2) 
		unitPrice = _5x7_1;
		else if (Q > 1 && Q < 11)
		unitPrice = _5x7_2to10;
		else if (Q > 10 && Q < 26)
		unitPrice = _5x7_11to25;
		else if (Q > 25 && Q < 51)
		unitPrice = _5x7_26to50;
		reprintPrice_5x7 = getReprintPrice(Q,unitPrice);
		document.frmReprints.txtTotalR5x7.value = formatCurrency(reprintPrice_5x7);
		
} // end func --------------------------------------------

function getPrice_8x10(Q){  // gets the total of reprints for the 8 x 10 35 mm film

var unitPrice = 0;

		if (Q<2) 
		unitPrice = _8x10_1;
		else if (Q > 1 && Q < 11)
		unitPrice = _8x10_2to10;
		else if (Q > 10 && Q < 26)
		unitPrice = _8x10_11to25;
		else if (Q > 25 && Q < 51)
		unitPrice = _8x10_26to50;
		reprintPrice_8x10 = getReprintPrice(Q,unitPrice);
		document.frmReprints.txtTotalR8x10.value = formatCurrency(reprintPrice_8x10);

} // end func

//----------------------------

function getPrice_8x12(Q){  // gets the total of reprints for the 8 x 12 35 mm film

var unitPrice = 0;

		if (Q<2) 
		unitPrice = _8x12_1;
		else if (Q > 1 && Q < 11)
		unitPrice = _8x12_2to10;
		else if (Q > 10 && Q < 26)
		unitPrice = _8x12_11to25;
		else if (Q > 25 && Q < 51)
		unitPrice = _8x12_26to50;
		reprintPrice_8x12 = getReprintPrice(Q,unitPrice);
		document.frmReprints.txtTotalR8x12.value = formatCurrency(reprintPrice_8x12);

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

function getPrice_digital_4x6(Q){  // gets the total of reprints for the 4 x6 35 mm - digital file



var unitPrice = 0;

		if (Q<2) 
		unitPrice = digital_1;
		else if (Q > 1 && Q < 11)
		unitPrice = digital_2to10;
		else if (Q > 10 && Q < 26)
		unitPrice = digital_11to25;
		else if (Q > 25 && Q < 51)
		unitPrice = digital_26to50;
		reprintPrice_digital = getReprintPrice(Q,unitPrice);
		document.frmReprints.txtTotalRdigital.value = formatCurrency(reprintPrice_digital);
		
} // end func  -------------------------------------------

function getRep_TheGrandTotal(){ // adds up all reprints totals

rep_theGrandTotal = reprintPrice_4x6 + reprintPrice_pan + reprintPrice_5x7 + reprintPrice_8x10 + reprintPrice_8x12 + reprintPrice_digital;
document.frmReprints.txtTotalReprints.value = formatCurrency(rep_theGrandTotal);

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

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

rep_clearVariables() // clear old values

if (isInt(document.frmReprints.txtQuantR4x6, "4 x 6", 51)==false 
|| isInt(document.frmReprints.txtQuantRpan, "Pan", 51)==false 
|| isInt(document.frmReprints.txtQuantR5x7, "5 x 7", 51)==false
|| isInt(document.frmReprints.txtQuantR8x10, "8 x 10", 51)==false
|| isInt(document.frmReprints.txtQuantR8x12, "8 x 12", 51)==false
|| isInt(document.frmReprints.txtQuantRdigital, "Digital 4 x 6", 51)==false){

return false
}else{

getPrice_4x6(document.frmReprints.txtQuantR4x6.value);
getPrice_pan(document.frmReprints.txtQuantRpan.value);
getPrice_5x7(document.frmReprints.txtQuantR5x7.value);
getPrice_8x10(document.frmReprints.txtQuantR8x10.value);
getPrice_8x12(document.frmReprints.txtQuantR8x12.value);
getPrice_digital_4x6(document.frmReprints.txtQuantRdigital.value);
getRep_TheGrandTotal();


validateQuant(rep_theGrandTotal);


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