var xmlHttp;
var chartPrice=0;
var bksnum=0;
var rpsnum=0;
var binding="";

function getPrice(b)
{
	//alert("Start to Get Price...");
	if (document.getElementById("ordBksNum").value=="" || parseInt(document.getElementById("ordBksNum").value)<200)
		return;
	else
		bksnum=parseInt(document.getElementById("ordBksNum").value);
	if (document.getElementById("ordRpsNum").value=="")
		return;
	else
		rpsnum=parseInt(document.getElementById("ordRpsNum").value);
	binding=document.getElementById("binding").options[document.getElementById("binding").selectedIndex].value;
	if (binding == "" || binding == null)
		binding="PC";
	if (b==true)
	{
	//alert("Get Price");
	//return;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url="GetPC.aspx";
		url=url+"?c="+bksnum;
		url=url+"&r="+rpsnum;
		url=url+"&b="+binding;
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else
	{
		if (document.getElementById("wcChartPrice"))
		{
			if (document.getElementById("wcChartPrice").value != "")
			{
				//alert(parseFloat(document.getElementById("wcChartPrice").value));
				chartPrice=parseFloat(document.getElementById("wcChartPrice").value);
				calculatePrice();
			}
			else
			{
				alert("Please enter Wire Casebound cookbook base price.");
				return;
			}
		}
		else
		{
			if (document.getElementById("txtPrice1").value == "")
			{
				alert("Please enter recipes number, books number and select one binding type.");
				return;
			}
			else
			{
				chartPrice=parseFloat(document.getElementById("txtPrice1").value)/bksnum;
				calculatePrice();
			}
		}
	}
}
function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{
		chartPrice=parseFloat(xmlHttp.responseText);
		//alert("ResposeText=" + xmlHttp.responseText);
		if (chartPrice == 999.99)
		{
			alert("Sorry, CANNOT get the base price. Please try again later.");
			return;
		}
		else
			calculatePrice();
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{  // Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function changeBind(n)
{
	var str=document.getElementById("binding").options[n].value
	if (str=="PW" || str=="EL")
	{
		var rps = document.getElementById("ordRpsNum").value;
		if (rps=="")
		{
			alert("Please enter the number or recipes.");
			document.getElementById("binding").selectedIndex=0
			return;
		}
		else 
		{
			if(str=="PW" && parseInt(rps)>300)
			{
				alert("Recipes CANNOT excess 300 for Plastic coil binder");
				document.getElementById("binding").selectedIndex=0
				return;
			}
			else if(str=="EL" && parseInt(rps)>300)
			{
				alert("The maximum recipe number for Ease.L.Back cookbook is 300");
				document.getElementById("binding").selectedIndex=0
				return;
			}
		}
	}
	if (str=="WC")
	{
		var bks = document.getElementById("ordBksNum").value;
		if (bks=="")
		{
			alert("Please enter the number or books.");
			document.getElementById("binding").selectedIndex=0
			return;
		}
		else 
		{
			if(parseInt(bks)<500)
			{
				alert("The minimum copy number for Wire Casebound cookbook is 500.");
				document.getElementById("binding").selectedIndex=0
				return;
			}
		}
	}
	var strHtml="";
	switch(n)
	{
		case 0:
		case 2: //PCB
			strHtml='<input type="CheckBox" name="binderWord" Value="Y" onClick="validateBW(this.checked)">Imprint on plastic comb binder (500 book minimum) - $0.40 per book';
			break;
		case 3: //TR
			strHtml='<input type="CheckBox" name="TRStand" value="Y" onClick="getPrice(false)">Three-Ring Binder cookbooks stand - $0.5 each';
			break;
		case 5: //Price
			strHtml='&nbsp;&nbsp; Wire Casebound cookbook base price $ <input type="TextBox" onkeyup="getPrice(false);" name="wcChartPrice" size="10" />';
			break;
		default:
			strHtml="";
			break;
	}
	document.getElementById("bind").innerHTML=strHtml;
	//if (n!=4)
		getPrice(true);
	return;
}

function changeCover(n)
{
	var strHtml="";
	switch(n)
	{
		case 0: //color1
			strHtml='Imprint color: <select name="icolor1" onChange="getPrice(false);">';
			strHtml=strHtml + '<option Value="black" selected>Black';
			strHtml=strHtml + '<option Value="standard">Standard imprint color';
			strHtml=strHtml + '<option Value="custom">Custom imprint color';
			strHtml=strHtml + '<option Value="foil">Metallic foil stamp emboss</select>';
			break;
		case 2: //color2
			strHtml='Imprint color: <select name="icolor2" onChange="getPrice(false);">';
			strHtml=strHtml + '<option Value="black" selected>Black';
			strHtml=strHtml + '<option Value="standard">Standard imprint color';
			strHtml=strHtml + '<option Value="custom">Custom imprint color';
			//strHtml=strHtml + '<option Value="raised">Print one-color cover with raised ink'
			//strHtml=strHtml + '<option Value="art">Clip art</select>';
			break;
		default:
			strHtml="";
			break;
	}
	document.getElementById("cover").innerHTML=strHtml;
	getPrice(false);
	return;
}

function changeAddCover(n)
{
	var strHtml="";
	switch(n)
	{
		case 1:
		case 2: //acover
			strHtml='<input type="CheckBox" onClick="getPrice(false)" name="aCover1" value="Y">Inside Front&nbsp;&nbsp;&nbsp; <input type="CheckBox" name="aCover2" onClick="getPrice(false)" value="Y">Inside Back&nbsp;&nbsp;&nbsp; <input type="CheckBox" name="aCover3" onClick="getPrice(false)" value="Y">Outside Back';
			break;
		default:
			strHtml="";
			break;
	}
	document.getElementById("addCover").innerHTML=strHtml;
	return;
}

function changeDivider(n)
{
	var strHtml="";
	switch(n)
	{
		case 1: 
			strHtml='Number of dividers: <input type="TextBox" name="divNum1" onKeyUp="getPrice(false)" size="10" /><br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv2" onClick="getPrice(false);" Value="none" checked>None <br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv2" onClick="getPrice(false);" Value="regular">Add regular tabs<br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv2" onClick="getPrice(false);" Value="round">Add round tabs<br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv2" onClick="getPrice(false);" Value="stock">Heavy white card stock, no tabs';
			break;
		case 2: 
			strHtml='Number of dividers: <input type="text" name="divNum2" onKeyUp="getPrice(false)" size="10" /><br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv3" onClick="getPrice(false);" Value="none" checked>None <br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv3" onClick="getPrice(false);" Value="regular">Add regular tabs<br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv3" onClick="getPrice(false);" Value="round">Add round tabs<br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv3" onClick="getPrice(false);" Value="stock">Heavy white card stock, no tabs';
			break;
		case 3: 
			strHtml='Number of dividers: <input type="text" name="divNum3" onKeyUp="getPrice(false)" size="10" /><br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv4" onClick="getPrice(false);" Value="none" checked>None <br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv4" onClick="getPrice(false);" Value="regular">Add regular tabs<br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv4" onClick="getPrice(false);" Value="round">Add round tabs<br />';
			strHtml=strHtml + '<input type="radio" name="tabDiv4" onClick="getPrice(false);" Value="stock">Heavy white card stock, no tabs<br />';
			strHtml=strHtml + 'Photos on custom black &amp; white divider set:<input type="text" name="divPhoto" onKeyUp="getPrice(false)" size="5"><BR />';
			strHtml=strHtml + '<input type="CheckBox" onClick="getPrice(false);" name="divInkColor" value="Y">Standard ink color, other than black<br />';
			strHtml=strHtml + '<input type="CheckBox" name="divPapercolor" onClick="getPrice(false);" value="Y">Standard paper color';
			break;
		default:
			strHtml='<input type="radio" name="tabDiv1" onClick="getPrice(false);" Value="none" checked>None <br />';
			strHtml=strHtml + '<input type="radio" onClick="getPrice(false);" name="tabDiv1" Value="regular">Add regular tabs<br />';
			strHtml=strHtml + '<input type="radio" onClick="getPrice(false);" name="tabDiv1" Value="round">Add round tabs';
			break;
	}
	document.getElementById("pldivider").innerHTML=strHtml;
	getPrice(false);
	return;
}

function changeFiller(n)
{
	var strHtml="";
	if (n==true)
	{
		strHtml='&nbsp;&nbsp;<input type="radio" name="filler" onClick="getPrice(false);" Value="none">None<br />';
		strHtml=strHtml + '&nbsp;&nbsp;<input type="radio" name="filler" onClick="getPrice(false);" Value="fcFiller">Standard text filler or art filler<br />';
		strHtml=strHtml + '&nbsp;&nbsp;<input type="radio" name="filler" onClick="getPrice(false);" Value="cusFiller">Custom text filler or art filler';
	}
	else
	{
		strHtml="";
	}
	document.getElementById("plFiller").innerHTML=strHtml;
	getPrice(false);
	return;
}

function validateBW(n)
{
	var bks = document.getElementById("ordBksNum").value;
	if (bks=="")
	{
		alert("Please enter the number of books.");
		document.getElementById("binderWord").checked=false;
		return;
	}
	else 
	{
		if(n==true && parseInt(bks)<500)
		{
			alert("Sorry, 500 copies is required for imprinting on plastic comb binder.");
			document.getElementById("binderWord").checked=false;
			return;
		}
		else
			getPrice(false);
		return;
	}
}

function validateCDNum()
{
	var cdnum = document.getElementById("CDNum").value;
	if (cdnum=="")
	{
		alert("Please enter the number of CDs.");
		return;
	}
	else 
	{
		if(parseInt(cdnum)<25)
		{
			alert("Sorry, the minimum number of copies for cookbooks on cd is 25, please reenter the quantity.");
			return;
		}
		else
			getPrice(false);
		return;
	}
}

function validateLam1()
{
	if (document.getElementById("laminate1").checked)
	{
		document.getElementById("laminate2").checked = false;
		document.getElementById("laminate3").checked = false;
	}
	getPrice(false);
}

function validateLam2()
{
	if (document.getElementById("laminate2").checked || document.getElementById("laminate3").checked)
	{
		document.getElementById("laminate1").checked = false;
	}
	getPrice(false);
}

function calculatePrice()
{
	var obj = new clsPrice();
	obj.recipeType=document.getElementById("recipeType").options[document.getElementById("recipeType").selectedIndex].value;
	obj.ordBksNum=bksnum;
	obj.binding=binding;
	obj.chartPrice=chartPrice;
	obj.ordRpsNum=rpsnum;
	if (document.getElementById("TRStand"))
		if (document.getElementById("TRStand").checked)
			obj.TRStand="Y";
		else
			obj.TRStand="";
	else
		obj.TRStand="";
		
	if (document.getElementById("binderWord"))
		if (document.getElementById("binderWord").checked)
			obj.binderWord="Y";
		else
			obj.binderWord="";
	else
		obj.binderWord="";
	
	obj.CoverDesign=document.getElementById("coverDesign").options[document.getElementById("coverDesign").selectedIndex].value;
	
	if (document.getElementById("icolor1"))
		obj.CoverImprintColor=document.getElementById("icolor1").options[document.getElementById("icolor1").selectedIndex].value;
	else
		if (document.getElementById("icolor2"))
			obj.CoverImprintColor=document.getElementById("icolor2").options[document.getElementById("icolor2").selectedIndex].value;

	obj.PlasticFBCover=document.getElementById("laminate2").checked ? "Y" : "N";
	obj.PlasticInsideCover=document.getElementById("laminate3").checked ? "Y" : "N";
	
	var i=0;
	if (document.getElementById("aCover1"))
	{
		if (document.getElementById("aCover1").checked) i=i+1;
		if (document.getElementById("aCover2").checked) i=i+1;
		if (document.getElementById("aCover3").checked) i=i+1;
	}
	obj.aCoverNum=i;
	
	obj.AdditionalCover=document.getElementById("additionalCover").options[document.getElementById("additionalCover").selectedIndex].value;
	switch (document.getElementById("divider").options[document.getElementById("divider").selectedIndex].value)
	{
        case "fcolor":
			obj.DivSetFCColor = 7;
            break;
        case "ccolor":
        	if (document.getElementById("divNum1") && document.getElementById("divNum1").value !="")
            		obj.DivSetCusColor = parseInt(document.getElementById("divNum1").value);
            	else
            		obj.DivSetCusColor = 0;
            break;
        case "fbw":
        	if (document.getElementById("divNum2") && document.getElementById("divNum2").value !="")
            		obj.DivSetFCBW = parseInt(document.getElementById("divNum2").value);
            	else
            		obj.DivSetFCBW = 0;
            break;
		case "cbw":
        	if (document.getElementById("divNum3") && document.getElementById("divNum3").value !="")
           		obj.DivSetCusBW = parseInt(document.getElementById("divNum3").value);
           	else
           		obj.DivSetCusBW=0;
           break;
    }
	var tab1=getCheckedValue(document.myprice.tabDiv1);//document.getElementById("tabDiv1"));
	var tab2=getCheckedValue(document.myprice.tabDiv2);//(document.getElementById("tabDiv2"));
	var tab3=getCheckedValue(document.myprice.tabDiv3);//(document.getElementById("tabDiv3"));
	var tab4=getCheckedValue(document.myprice.tabDiv4);//(document.getElementById("tabDiv4"));
	if (tab1 != "" && tab1 != "none")
		obj.divTab = tab1;
	else 
		if (tab2 != "" && tab2 != "none")
			obj.divTab = tab2;
        else
			if (tab3 != "" && tab3 != "none")
				obj.divTab = tab3;
            else
				if (tab4 != "" && tab4 != "none")
					obj.divTab = tab4;
	//alert("Tab Divider: " + obj.divTab);
	if(document.getElementById("divPhoto") && document.getElementById("divPhoto").value!="") 
		obj.divPhoto=parseInt(document.getElementById("divPhoto").value);
	else
		obj.divPhoto=0;
	
	if(document.getElementById("divInkColor")) 
		obj.divInkColor=document.getElementById("divInkColor").checked? "Y" : "N";
	
	if(document.getElementById("divPapercolor")) 
		obj.divPaperColor=document.getElementById("divPapercolor").checked? "Y" : "N";

	if (document.getElementById("txtCusDivBWBK") && document.getElementById("txtCusDivBWBK").value !="")
		obj.divBKPrintBW=parseInt(document.getElementById("txtCusDivBWBK").value);
	else
		obj.divBKPrintBW=0;
	if (document.getElementById("txtCusDivColrBK") && document.getElementById("txtCusDivColrBK").value !="")
		obj.divBKPrintColor=parseInt(document.getElementById("txtCusDivColrBK").value);
	else
		obj.divBKPrintColor=0;
	//this.LinerInk="";
	//this.RecipeInk="";
	if (document.getElementById("addPageNum") && document.getElementById("addPageNum").value !="")
		i = parseInt(document.getElementById("addPageNum").value);
	else
		i=0;
	if (i - 4 <= 0)
		obj.addPageNum = 0;
    	else
       		obj.addPageNum = i - 4;
       	if (document.getElementById("addPhotoNum") && document.getElementById("addPhotoNum").value!="")
		i = parseInt(document.getElementById("addPhotoNum").value);
	else
		i=0;
	if (i - 1 <= 0)
		obj.addPhotoNum = 0;
    else
       obj.addPhotoNum = i - 1;

	if (document.getElementById("colorPhotoNum") && document.getElementById("colorPhotoNum").value !="")
		obj.colorPhotoNum=parseInt(document.getElementById("colorPhotoNum").value);
	else
		obj.colorPhotoNum=0;
	if (document.getElementById("papeColor").checked)
		obj.recipePgColor="Y";
	if (document.getElementById("nonContinue").checked)
		obj.recipeNonCon="Y";
		
	obj.Filler=getCheckedValue(document.myprice.filler);//(document.getElementById("filler"));
	if (document.getElementById("recipeNotes").checked)
		obj.recipeNotes="Y";
	//this.RecipeFormat="";
	if (document.getElementById("recipePocket").checked)
		obj.recipePocket="Y";
	if (document.getElementById("CDNum") && document.getElementById("CDNum").value !="")
		obj.CDNum=parseInt(document.getElementById("CDNum").value);
	else
		obj.CDNum=0;
	if (document.getElementById("regAdPages") && document.getElementById("regAdPages").value !="")
		obj.adPgNum=parseInt(document.getElementById("regAdPages").value);
	else
		obj.adPgNum=0;
	if (document.getElementById("photoAdPages") && document.getElementById("photoAdPages").value !="")
		obj.adPhPgNum=parseInt(document.getElementById("photoAdPages").value);
	else
		obj.adPhPgNum=0;
	if (document.getElementById("IFAd").checked)
		obj.adInFrt="Y";
	if (document.getElementById("IBAd").checked)
		obj.adInBk="Y";
	if (document.getElementById("IFPAd").checked)
		obj.adPhoIF="Y";
	if (document.getElementById("IBPAd").checked)
		obj.adPhoIB="Y";
	var ad =getCheckedValue(document.myprice.OBAd);//(document.getElementById("OBAd"));
	if (ad =="OBAd")
		obj.adPgBack="Y";
	else
		if (ad == "OBPAd")
			obj.adPhoBak="Y";
	if (document.getElementById("isbn").checked)
		obj.isbn="Y";
	if (document.getElementById("displayBox") && document.getElementById("displayBox").value !="")
		obj.displayBox=parseInt(document.getElementById("displayBox").value);
	else
		obj.displayBox=0;
	//this.DesignPockEnv="";
	//this.EnvBxs=0;
	//this.ShippingBxs=0;
	obj.hcProof=getCheckedValue(document.myprice.proof);//(document.getElementById("proof"));
	if (obj.hcProof == "shortcutol")
		obj.SCOLProof="Y";
	
	//alert("Number of books: "+obj.ordBksNum);
	obj.GetPrice08();
	
	document.getElementById("txtPrice1").value=obj.OrderAmount.toFixed(2);
	document.getElementById("txtPrice2").value=obj.BindingAmount.toFixed(2);
	document.getElementById("txtPrice3").value=-obj.Discount.toFixed(2);
	document.getElementById("txtPrice4").value=obj.CoverAmount.toFixed(2);
	document.getElementById("txtPrice5").value=obj.DivAmount.toFixed(2);
	document.getElementById("txtPrice6").value=obj.CBAmount.toFixed(2);//obj.CBPgAmount + obj.SpPgAmount.toFixed(2);
	document.getElementById("txtPrice7").value=obj.addCBAmount.toFixed(2);
	document.getElementById("txtPrice8").value=obj.AdAmount.toFixed(2);
	document.getElementById("txtPrice9").value=obj.CBProofAmount.toFixed(2);
	document.getElementById("txtPrice10").value=obj.OrderCost.toFixed(2);
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "underfined";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function clsPrice()
{
	this.recipeType="";
	this.ordBksNum=0;
	this.binding="";
	this.chartPrice=0;
	this.ordRpsNum=0;
	this.TRStand="";
	this.binderWord="";
	this.CoverDesign="";
	this.CoverImprintColor="";
	this.PlasticFBCover="";
	this.PlasticInsideCover="";
	this.aCoverNum=0;
	this.AdditionalCover="";
	this.divTab="";
	this.DivSetFCColor=0;
	this.DivSetCusColor=0;
	this.DivSetFCBW=0;
	this.DivSetCusBW=0;
	this.divPhoto=0;
	this.divInkColor="";
	this.divPaperColor="";
	this.divBKPrintBW=0;
	this.divBKPrintColor=0;
	this.LinerInk="";
	this.RecipeInk="";
	this.recipePgColor="";
	this.recipeNonCon="";
	this.Filler="";
	this.recipeNotes="";
	this.RecipeFormat="";
	this.addPageNum=0;
	this.addPhotoNum=0;
	this.colorPhotoNum=0;
	this.recipePocket="";
	this.CDNum=0;
	this.adPgNum=0;
	this.adPhPgNum=0;
	this.adInFrt="";
	this.adInBk="";
	this.adPhoIF="";
	this.adPhoIB="";
	this.adPgBack="";
	this.adPhoBak="";
	this.isbn="";
	this.displayBox=0;
	this.DesignPockEnv="";
	this.EnvBxs=0;
	this.ShippingBxs=0;
	this.hcProof="";
	this.SCOLProof="";
	
	this.OrderAmount=0;
	this.BindingAmount=0;
	this.CoverAmount=0;
	this.DivAmount=0;
	this.CBPgAmount=0;
	this.SpPgAmount=0;
	this.addCBAmount=0;
	this.AdAmount=0;
	this.CBProofAmount=0;
	this.Discount=0;
	this.OrderCost=0;
	this.CBAmount = 0;
	
	this.GetPrice08=GetPrice08;
}

function GetPrice08()
{
	if(this.recipeType == "fundcraft")
		this.Discount = 0;
        else
		this.Discount = 0.25 * this.ordBksNum;
        if(this.Discount>300) this.Discount=300;
        
        this.OrderAmount = this.chartPrice * this.ordBksNum;
        
        ////binding
        var pb_scBindType = 0;
        var pb_TRStand = 0;
        var pb_BinderWord = 0;
        if (this.binding == "PW" || this.binding == "DW")
            pb_scBindType = 0.2;
        if (this.TRStand == "Y")
            pb_TRStand = 0.5;
        if (this.binderWord == "Y")
            pb_BinderWord = 0.4;
        this.BindingAmount = this.ordBksNum * (pb_scBindType + pb_TRStand + pb_BinderWord);

        ////Cover Options
        var pb_CoverDesign = 0;
        var po_CoverImprintColor = 0;
        var pb_PlasticFBCover = 0;
        var pb_PlasticInsideCover = 0;
        var pb_AdditionalCover = 0;
        if (this.CoverDesign == "ccolorCV" && this.binding != "WC")
           pb_CoverDesign = 0.25;
        if (this.CoverImprintColor == "standard" ) //|| this.CoverImprintColor == "black")
           po_CoverImprintColor = 25;
        else 
        {
        	if (this.CoverImprintColor == "custom")
                	po_CoverImprintColor = 75;
		else
		{
			if (this.CoverImprintColor == "foil")
                		po_CoverImprintColor = 250;
                }
        }
	if (this.PlasticFBCover == "Y")
                pb_PlasticFBCover = 0.15;
	if (this.PlasticInsideCover == "Y") 
		pb_PlasticInsideCover = 0.1;
	if (this.aCoverNum > 0)
	{
        	if (this.AdditionalCover == "bw")
             		pb_AdditionalCover = 0.15 * this.aCoverNum;
          	else
             		pb_AdditionalCover = 0.25 * this.aCoverNum;
	}
	this.CoverAmount = (pb_CoverDesign + pb_PlasticFBCover + pb_PlasticInsideCover + pb_AdditionalCover) * this.ordBksNum + po_CoverImprintColor

	////Divider Options
	var po_DivSetFCColor = 0;
	var po_DivSetFCBW = 0;
	var pb_DivSetCusColor = 0;
	var po_DivSetCusBW = 0;
	var pb_DivTab = 0;
	var po_DivPhoto = 0;
	var po_DivInkColor = 0;
	var po_DivPaperColor = 0;
	var po_DivBKPrint = 0;
	var pb_DivBKPrint = 0;
	pb_DivSetCusColor = 0.2 * this.DivSetCusColor;
	po_DivSetCusBW = 15 * this.DivSetCusBW;
	if (this.DivSetFCBW > 8)
        	po_DivSetFCBW = (this.DivSetFCBW - 8) * 15;
	else
           po_DivSetFCBW = 0;

	if (this.divTab != "")
	{
		if (this.DivSetFCColor > 0)
			pb_DivTab =pb_DivTab + (this.divTab == "regular")? 0.75:0.85;
        	if (this.DivSetCusColor > 0)
            	{
                	if (this.divTab == "regular")
                    		pb_DivTab =pb_DivTab + 0.15 * this.DivSetCusColor;
                	else
                	{
				if (this.divTab == "round")
                        		pb_DivTab =pb_DivTab + 0.2 * this.DivSetCusColor;
                    		else
				{
					if (this.divTab == "stock")
                        			pb_DivTab = pb_DivTab + 0.05 * this.DivSetCusColor;
                    		}
                	}
            	}
            	if (this.DivSetFCBW > 0 )
            	{
               		if (this.divTab == "regular")
                    		pb_DivTab = pb_DivTab + 0.1 * this.DivSetFCBW;
               		else
               		{
				if (this.divTab == "round")
                        		pb_DivTab = pb_DivTab + 0.15 * this.DivSetFCBW;
                    		else
                    		{ 
					if (this.divTab == "stock")
						pb_DivTab = pb_DivTab + 0.05 * this.DivSetFCBW;
				}
              		}
            	}
            	if (this.DivSetCusBW > 0 )
            	{
			if (this.divTab == "regular")
			{
                   		po_DivSetCusBW = 0;
                   		pb_DivTab =pb_DivTab + 0.15 * this.DivSetCusBW;
                	}
                	else 
                	{	
				if (this.divTab == "round")
				{
                        		po_DivSetCusBW = 0;
                        		pb_DivTab = pb_DivTab + 0.2 * this.DivSetCusBW;
                    		}
                    		else
                    		{
					if (this.divTab == "stock")
						pb_DivTab = pb_DivTab + 0.05 * this.DivSetCusBW;
                    		}
               		}
           	}
	}
        po_DivPhoto = 10 * this.divPhoto;
        if (this.divInkColor == "Y")  po_DivInkColor = 75;
        if (this.divPaperColor == "Y") po_DivPaperColor = 75;
        po_DivBKPrint = 15 * this.divBKPrintBW;
        pb_DivBKPrint = 0.2 * this.divBKPrintColor;
        this.DivAmount = (pb_DivSetCusColor + pb_DivTab + pb_DivBKPrint) * this.ordBksNum + 
                po_DivSetFCColor + po_DivSetFCBW + po_DivSetCusBW +
                po_DivPhoto + po_DivInkColor + po_DivPaperColor + po_DivBKPrint;

        ////Cookbook Page Options
        var pb_RecipeInk = 0;
        var pb_RecipePGColor = 0;
        var pb_RecipeNonCon = 0;
        var pb_Filler = 0;
        var pb_RecipeNotes = 0;
        var pb_RecipeFormat = 0;
        var pb_LinerInk = 0;
        var po_RpExtra = 0;
        if (this.LinerInk != "")
        	pb_LinerInk = 0.2;
        if (this.RecipeInk != "") 
        	pb_RecipeInk = 0.3;
        if (this.recipePgColor == "Y")
        	pb_RecipePGColor = 0.25;
        if (this.recipeNonCon == "Y")  pb_RecipeNonCon = 0.2;
        if (this.Filler != "")
        {
		if (this.Filler == "fcFiller")
                	pb_Filler = 0.15;
            	else
                    {
                    	if(this.Filler == "none")
                    		pb_Filler = 0.0;
                    	else
                    		pb_Filler = 0.2;
                    }
        }
        if (this.recipeNotes == "Y")  pb_RecipeNotes = 0.25;
        if (this.RecipeFormat == "2" || this.RecipeFormat == "4" || this.RecipeFormat == "11" || this.RecipeFormat == "12")
        {
		if (this.RecipeFormat == "2" || this.RecipeFormat == "4")
                    	pb_RecipeFormat = 0.2;
            	else
		{
			if (this.RecipeFormat == "11")
                    		pb_RecipeFormat = 0.3;
                	else
                    		pb_RecipeFormat = 0.6;
            	}
        }
	this.CBPgAmount = this.ordBksNum * (pb_RecipeInk + pb_RecipePGColor + 
                pb_RecipeNonCon + pb_Filler + pb_RecipeNotes + pb_RecipeFormat + pb_LinerInk) + 
                po_RpExtra;
                
	////special page
        var po_AddPageNum = 0;
        var po_AddPhotoNum = 0;
        var pb_ColorPhotoNum = 0;
        po_AddPageNum = this.addPageNum * 15;
        po_AddPhotoNum = 10 * this.addPhotoNum;
        if (this.binding != "WC")
            pb_ColorPhotoNum = 0.2 * this.colorPhotoNum;
        this.SpPgAmount = this.ordBksNum * pb_ColorPhotoNum + po_AddPageNum + po_AddPhotoNum;

	////Addtional Cookbook Options
        var pb_RecipePocket = 0;
        var po_CDNum = 0;
        if (this.recipePocket == "Y") pb_RecipePocket = 0.15;
        po_CDNum = 3.5 * this.CDNum;
        this.addCBAmount = this.ordBksNum * pb_RecipePocket + po_CDNum;

	////Cookbook Marketing Options
        var po_AdPgNum = 0;
        var po_adPhPgNum = 0;
        var po_adInFrt = 0;
        var po_adInBk = 0;
        var po_adPhoIF = 0;
        var po_adPhoIB = 0;
        var po_adPgBack = 0;
        var po_adPhoBak = 0;
        var po_ISBN = 0;
        var po_DisplayBox = 0;
        var pb_DesignPockEnv = 0;
        var po_EnvBxs = 0;
        var po_ShippingBxs = 0;

	po_AdPgNum = this.adPgNum * 40;
        po_adPhPgNum = this.adPhPgNum * 50;
        if (this.adInFrt == "Y") po_adInFrt = 50;
        if (this.adInBk == "Y") po_adInBk = 50;
        if (this.adPhoIF == "Y") po_adPhoIF = 60;
        if (this.adPhoIB == "Y") po_adPhoIB = 60;
        if (this.adPgBack == "Y") po_adPgBack = 50;
        if (this.adPhoBak == "Y") po_adPhoBak = 60;
        if (this.isbn == "Y") po_ISBN = 75;
        po_DisplayBox = this.displayBox * 1.5;
        if (this.DesignPockEnv == "Y") pb_DesignPockEnv = 0.2;
        po_EnvBxs = 15 * this.EnvBxs;
        po_ShippingBxs = 0.75 * this.ShippingBxs;
        this.AdAmount = po_AdPgNum + po_adPhPgNum + po_adInFrt + po_adInBk + po_adPhoIF +
                po_adPhoIB + po_adPgBack + po_adPhoBak + po_ISBN + po_DisplayBox + 
                po_EnvBxs + po_ShippingBxs + pb_DesignPockEnv * this.ordBksNum


        ////Cookbook Proofs
        var po_HCProof = 0;
        var po_SCOLProof = 0;
        if (this.hcProof != "")
        {
           	if (this.hcProof == "entire")
			po_HCProof = 35;
           	else
              		po_HCProof = 25;
       	}
       	else
       	{  
		if (this.SCOLProof == "Y" && this.recipeType == "shortcut") po_SCOLProof = 25;
	}
       this.CBProofAmount = po_HCProof + po_SCOLProof;
       this.CBAmount=this.CBPgAmount + this.SpPgAmount;
       this.OrderCost = this.OrderAmount + this.BindingAmount + this.CoverAmount + this.DivAmount + this.CBPgAmount + this.SpPgAmount + this.addCBAmount + this.AdAmount + this.CBProofAmount - this.Discount;
}