function clsPrice()
{
	this.strPaperType="";
	this.strPageSize="";
	this.intNumPages=0;
	this.intNumCopies=0;
	this.intNumColorPages=0;
	this.intNumBWPages=0;
	this.strBinding="";
	this.strCover="";
	this.strLaminate="";
	this.print_bcwording = "";
	this.BWColor="";
	this.ProofRequested="";
	this.IPC="";
	this.PrintingInsideCover="";
	this.CvInside="";
	this.Reorder_Requested="";
	this.HaveISBN="";
	this.r_NumCopies=0;
	this.ISBNNum="";
	this.Dust="";
	this.TrimSize="";
	this.Marketingkit="";
	this.SpineDesign="";
	this.FService="";
	
	this.bookcost = 0;
	this.PaperCost = 0;
	this.CoverCost = 0;
	this.dblCustomSize = 0;
	this.bcwordingCost = 0;
	this.BindingCost=0;
	this.ProofCost = 0;
	this.PrintingInsideCoverCostPerBook = 0;
    this.printingInsideCoverColor = 0;
	this.CustomDesignCost = 0;
    this.isbnCost = 0;
    this.mkCost=0;
	this.serviceCost=0;
	this.TotalCostPerBook=0;
	this.TotalCostAllBooks=0;
	this.TotalOrder=0;
	
	this.GetPrice=GetPrice;
}
function GetPrice()
{
		var baserate = 0;
        if (this.strPageSize == "4" || this.strPageSize == "5")
        {    baserate = 0.015;	}
        else{
			if (this.strPageSize == "6")
				baserate = 0.02;
			else
				baserate = 0.0225;
        }
		//var bookcost = 0;
		//alert("numPaper=" + this.intNumPages + "; NumCopies=" + this.intNumCopies + "; baserate=" + baserate)
        this.bookcost = CalcPrice(this.intNumPages, this.intNumCopies, baserate);
        if (this.intNumCopies <= 99)
		{
            this.bookcost = this.bookcost + Math.round(2395 / this.intNumCopies)/100;
        }
		var dustcost=0;
		if (this.Dust == "Y")
		{
			if (this.strPageSize =="5" ||this.strPageSize=="6")
			{
				if (this.intNumCopies<250)
				{
					dustcost = 0.8;
				}
				else if (this.intNumCopies>=250 && this.intNumCopies<500)
				{
					dustcost = 0.55;
				}
				else
				{
					dustcost = 0.45;
				}
			}
			else if (this.strPageSize == "8")
			{
				if (this.intNumCopies<250)
				{
					dustcost = 1.5;
				}
				else if (this.intNumCopies>=250 && this.intNumCopies<500)
				{
					dustcost = 0.65;
				}
				else
				{
					dustcost = 0.55;
				}
			}
		}
		this.bookcost = this.bookcost + dustcost;
		
//		if(this.TrimSize !="")
//			this.bookcost = this.bookcost + 0.1;

		if(this.TrimSize != "")
		{
			if(this.intNumCopies >=250)
				this.dblCustomSize = 250*0.25 + (this.intNumCopies-250)*0.1;
			else
				this.dblCustomSize = this.intNumCopies*0.25;
		}
		
        if (this.strCover != null && this.strCover != "")
        {
            var i = this.strCover.indexOf("|");
            if (i > 0 )
            {
                this.CoverCost = this.strCover.substring(0, i)*1;
                //if (this.CoverCost == 0.1) this.CoverCost = 0.25;
                if (this.CoverCost == 0.99 || this.CoverCost == 0.98)
                {
 //                   if (this.intNumCopies < 501)
 //                 {
                        this.CoverCost = 0.25;
 //                   }
//                    else
//                    {
//                        this.CoverCost = 0.2
//                    }
                }
            }
            else
            {
                this.CoverCost = 0
            }
            if (this.strLaminate == "Y" && this.strBinding.indexOf("CA") <= 0 && this.strBinding.indexOf("3R") <= 0)
            {
                this.CoverCost = this.CoverCost + 0.25;
            }
        }
        if (this.print_bcwording == "Y" && this.Reorder_Requested != "Y")
        {
            this.bcwordingCost = 20;
        }
        else
        {
            this.bcwordingCost = 0;
        }
        
        if (this.strBinding != null && this.strBinding != "" )
        {
            if (this.strBinding.indexOf("CA") > 0 || this.strBinding.indexOf("CHU") > 0 || this.strBinding.indexOf("CHB") > 0 )
            {
                if (this.strPageSize == "8")
                {
					if (this.intNumCopies < 50)
                    {
                        this.BindingCost = 7;
                    }
                    else if (this.intNumCopies < 500)
                    {
                        this.BindingCost = 6;
                    }
                    else if (this.intNumCopies > 499 && this.intNumCopies < 1000)
                    {
                        this.BindingCost = 4;
                    }
                    else
                    {
                        this.BindingCost = 3;
                    }
                }
                else
                {
                    if (this.intNumCopies < 50)
                        this.BindingCost = 5;
                    else if (this.intNumCopies < 500 )
                        this.BindingCost = 4;
                    else if (this.intNumCopies > 499 && this.intNumCopies < 1000)
                        this.BindingCost = 3;
                    else
                        this.BindingCost = 2;
                }
				if (this.strBinding.indexOf("CHU") > 0 || this.strBinding.indexOf("CHB") > 0)
					this.BindingCost = this.BindingCost + 1.2;
            }
            else
            {
                if (this.strBinding.substring(0, 2) == "0|")
                    this.BindingCost = 0;
                else
                    this.BindingCost = this.strBinding.substring(0, 3)*1;
            }
        }
        else
        {
            this.BindingCost = 0;
        }

        var ColorPaper = 0;
        var ColorPrint = 0;
        var BWPrint = 0;
        if (this.BWColor == "Color")
        {
            if (this.strPageSize == "4" || this.strPageSize == "5")
            {
                if (this.intNumCopies <= 99 )
                    ColorPrint = 0.06;
                else if (this.intNumCopies <= 199)
                    ColorPrint = 0.04;
                else
                    ColorPrint = 0.03;

                if (this.strPaperType != "Off-White" && this.strPaperType != "White")
				{
					if (this.strPaperType == "C2S")
					{
						ColorPaper = 0.08;
					}
					else
					{
						if (this.strPaperType == "EHG" || this.strPaperType == "EWM")
							ColorPaper = 0.008 + 0.01;
						else
                    		ColorPaper = 0.008;
					}
				}
                else
                {
                    ColorPaper = 0;
                    BWPrint = 0.02;
                }
            }
            else if (this.strPageSize == "6")
            {
                if (this.intNumCopies <= 99)
                    ColorPrint = 0.077;
                else if (this.intNumCopies <= 199)
                    ColorPrint = 0.05;
                else
                    ColorPrint = 0.04;
                
                if (this.strPaperType != "Off-White" && this.strPaperType != "White")
 					if (this.strPaperType == "C2S")
					{
						ColorPaper = 0.08;
					}
					else
					{
						if (this.strPaperType == "EHG" || this.strPaperType == "EWM")
							ColorPaper = 0.01 + 0.01;
						else
                    		ColorPaper = 0.01;
					}
                else
                {
                    ColorPaper = 0;
                    BWPrint = 0.02;
                }
            }
            else if (this.strPageSize == "8")
			{
                if (this.intNumCopies <= 99)
                    ColorPrint = 0.086;
                else if (this.intNumCopies <= 199)
                    ColorPrint = 0.06;
                else
                    ColorPrint = 0.05;

                if (this.strPaperType != "Off-White" && this.strPaperType != "White")
 					if (this.strPaperType == "C2S")
					{
						ColorPaper = 0.08;
					}
					else
					{
						if (this.strPaperType == "EHG" || this.strPaperType == "EWM")
							ColorPaper = 0.015 + 0.01;
						else
                    		ColorPaper = 0.015;
					}
                else
                {
                    ColorPaper = 0;
                    BWPrint = 0.02;
                }
            }
        }
		else
		{
            if (this.strPageSize == "4" || this.strPageSize == "5")
            {
                if (this.strPaperType != "Off-White" && this.strPaperType != "White")
				{
					if (this.strPaperType == "C2S")
					{
						ColorPaper = 0.08;
					}
					else
					{
						if (this.strPaperType == "EHG" || this.strPaperType == "EWM")
							ColorPaper = 0.008 + 0.01;
						else
                    		ColorPaper = 0.008;
					}
				}
                else
                {
                    ColorPaper = 0;
                }
            }
            else if (this.strPageSize == "6")
            {
                if (this.strPaperType != "Off-White" && this.strPaperType != "White")
 					if (this.strPaperType == "C2S")
					{
						ColorPaper = 0.08;
					}
					else
					{
						if (this.strPaperType == "EHG" || this.strPaperType == "EWM")
							ColorPaper = 0.01 + 0.01;
						else
                    		ColorPaper = 0.01;
					}
                else
                {
                    ColorPaper = 0;
                }
            }
            else if (this.strPageSize == "8")
			{
                if (this.strPaperType != "Off-White" && this.strPaperType != "White")
 					if (this.strPaperType == "C2S")
					{
						ColorPaper = 0.08;
					}
					else
					{
						if (this.strPaperType == "EHG" || this.strPaperType == "EWM")
							ColorPaper = 0.015 + 0.01;
						else
                    		ColorPaper = 0.015;
					}
                else
                {
                    ColorPaper = 0;
                }
            }
		}
		//alert("color printing: " + ColorPrint + ", color page:" + this.intNumColorPages + ", BW printing: " + BWPrint + ", BW page:" + this.intNumBWPages);

        this.bookcost = this.bookcost + Math.round(ColorPrint * this.intNumColorPages*100)/100 + Math.round(BWPrint * this.intNumBWPages*100)/100;
        //alert ("bookcost=" + this.bookcost);
        this.PaperCost = Math.round(ColorPaper * this.intNumPages*100)/100;
        //alert ("PaperCost=" + this.PaperCost);
        if (this.ProofRequested == "Y")
        {
            if (this.IPC != "Y")
            {
                if (this.intNumCopies < 200)
                    this.ProofCost = 50;
                else
                    this.ProofCost = 30;
            }
            else
            {
                if (this.BWColor == "Color")
                    this.ProofCost = 50;
                else
                {
                   // if (this.BWColor == "BW")
                    //{
                        if (this.intNumCopies < 200)
                            this.ProofCost = 50;
                        else
                            this.ProofCost = 30;
                   // }
                }
            }
        }
        else
        {
        	if(this.ProofRequested == "E")
        	{
             		if (this.IPC != "Y")
            		{
                		if (this.intNumCopies < 200)
                    			this.ProofCost = 70;
                		else
                    			this.ProofCost = 50;
            		}
            		else
            		{
                		if (this.BWColor == "Color")
                    			this.ProofCost = 70;
                		else
                		{
                        		if (this.intNumCopies < 200)
                            			this.ProofCost = 70;
                        		else
                            			this.ProofCost = 50;
                		}
            		}
       		}
        }

        if (this.PrintingInsideCover == "Y")
            this.PrintingInsideCoverCostPerBook = 0.1;

        if (this.CvInside == "Y")
            this.printingInsideCoverColor = 0.25;
        else
            this.printingInsideCoverColor = 0;
	if (this.strCover !=null)
	{
		if (this.strCover.toUpperCase().indexOf("SIPCUSTOM") > 0 && this.Reorder_Requested != "Y")
				this.CustomDesignCost = 65;
	        else
	        {
			if (this.strCover.toUpperCase().indexOf("PIPCUSTOM") > 0 && this.Reorder_Requested != "Y")
					this.CustomDesignCost = 120;
	        }

	        if (this.SpineDesign == "Y" && this.Reorder_Requested != "Y") this.CustomDesignCost = this.CustomDesignCost + 15;
			
	}
		
        if (this.HaveISBN == "Y" && this.r_NumCopies <= 0)
        {
            if (this.ISBNNum != "")
                this.isbnCost = 15.0;
            else
                this.isbnCost = 0;
		}
        this.TotalCostPerBook = this.bookcost + this.CoverCost + this.BindingCost + this.PrintingInsideCoverCostPerBook + this.PaperCost + this.printingInsideCoverColor;
        this.TotalCostPerBook = Math.round(this.TotalCostPerBook*100)/100;
        //alert(this.TotalCostPerBook);
        this.TotalCostAllBooks= (this.TotalCostPerBook * this.intNumCopies) + this.ProofCost + this.CustomDesignCost + this.bcwordingCost + this.isbnCost + this.dblCustomSize;
		//alert(this.intNumCopies);
		//alert(this.TotalCostAllBooks);
		//alert(this.bcwordingCost);
		this.TotalCostAllBooks = Math.round(this.TotalCostAllBooks*100)/100;
		if (this.Marketingkit=="B")
			this.mkCost = 75;
		else if(this.Marketingkit == "X")
			this.mkCost = 175;
		else
			this.mkCost=0;
			
		this.TotalOrder = this.TotalCostAllBooks + this.mkCost;
		if(this.FService=="Y")
		{
			this.serviceCost = this.TotalOrder*0.1;
			if (this.serviceCost<100)
				this.serviceCost=100;
			this.TotalOrder = this.TotalOrder + this.serviceCost;
		}
}	
function CalcPrice(pages, quantity, baseprice)
{
        var pprice =new Array(14);
        pprice[0] = 0
        pprice[1] = 1.45
        pprice[2] = 1
        pprice[3] = 0.8
        pprice[4] = 0.75
        pprice[5] = 0.7
        pprice[6] = 0.66
        pprice[7] = 0.64
        pprice[8] = 0.6
        pprice[9] = 0.6
        pprice[10] = 0.6
        pprice[11] = 0.6
        pprice[12] = 0.6
        pprice[13] = 0.6

        if (pages < 60) pages = 60;
        if (quantity < 25) quantity = 25;
        var qprice;
        if (quantity < 50)
			{
				qprice = 2.25;
            }
        else if (quantity < 100)
            {
				qprice = 1.9;
			}
        else if (quantity < 250)
			{
				qprice = 1.4;
			}
        else if (quantity < 500)
			{
				qprice = 1;
			}
        else if (quantity < 750)
			{
				qprice = 0.82;
			}
        else if (quantity < 1000)
			{
				qprice = 0.75;
			}
        else if (quantity < 2000)
			{
				qprice = 0.69;
			}
        else if (quantity < 3000)
			{
				qprice = 0.59;
			}
        else if (quantity < 5000)
			{
				qprice = 0.53;
			}
        else
			{
				qprice = 0.53;
			}

        var PageTotal = 0;
        var PageStep = 0;
        var NumberPages = pages;
        PageStep = NumberPages - 99
        if (PageStep < 0 )
			{
				PageStep = NumberPages;
				PageTotal = NumberPages;
			}
        else
			{
				PageStep = 99;
				PageTotal = PageStep;
			}
		//alert("PageTotal=" + PageTotal + ";NumberPages=" + pages + ";baseprice=" +baseprice);
        var Price = 0;
        var i = 1;
        var AllDone = "N"
        while (PageTotal <= NumberPages)
        {
            Price = Price + (baseprice * qprice * PageStep * pprice[i]);
            PageStep = 50;
            PageTotal = PageTotal + PageStep;
            if (PageTotal > NumberPages && AllDone == "N")
            {
                PageTotal = PageTotal - PageStep;
                PageStep = NumberPages - PageTotal;
                PageTotal = NumberPages;
                AllDone = "Y";
            }
            i++;
            if (i > 10) i = 10;
        }
        Price = Math.round(Price*100);
        return Price/100;
}
