function serializeObject(obj) {
	this.recursive = function(obj) {
		var str = "{";
		for (var i in obj) {
			if (typeof(obj[i]) == "string") {
				str += "'" + i + "':'" + obj[i] + "',";
			} else if (typeof(obj[i]) == "object") {
				str += "'" + i + "':" + this.recursive(obj[i]) + ",";
			} else {
				str += "'" + i + "':" + obj[i] + ",";
			}
		}
		if(str.charAt(str.length-1) == ",")
			str = str.substring(obj,str.length-1);
		str += "}";
		str = str.replace(/\s/g, '');
		return str;
	}
	return this.recursive(obj);
} 

function WoodOb() {
	this.pop = new Object();
	this.price = new Object();
	this.cutprice = new Object();
	this.spacer = new Object();
	this.cutspacer = new Object();
	this.imgsrc = new Object();
}

function ProfileOb() {
	this.pop = new Object();
	this.woodcode = new Object();
	this.options = new Object();
	this.price = new Object();
	this.cutprice = new Object();
	this.fin = new Object();
}

function MetalOb() {
	this.code = new Object();
	this.pop = new Object();
	this.lprice = new Object();
	this.cprice = new Object();
	this.gifsrc = new Object();
	this.item = new Object();
}

function JoinOb() {
	this.pop = new Object();
	this.img = new Object();
	this.price = new Object();
	this.item = new Object();
}

function SpacersWoodOb(name, woodcode, price, cutprice, osprice, oscutprice) {
	this.name = name;
	this.woodcode = woodcode;
	this.price = price;
	this.cutprice = cutprice;
	this.osprice = osprice;
	this.oscutprice = oscutprice;
	this.pop = new Object();
	this.spacer = new Object();
	this.cutspacer = new Object();
	this.imgsrc = new Object();
}


function StrainOb() {
	this.drill = new Object();
	this.img = new Object();
}


function MatOb(no, price, matcharge, boardcharge, size) {
//  Item #  |  price for size1  |  price size2
	this.itemno = no;
	this.price = price;
	this.matcutcharge = matcharge;
	this.boardcutcharge = boardcharge;
	this.size = size;
}

function PlyOb() {
	this.colpop = new Array();
	this.matobs = new Array();
}

// functions for Frame object

function setId(val) {
	this.id = val;
}

function setIsMetal(isMtl) {
	this.isMetal = isMtl;
}

function setHasFrame(isIt) {
	this.hasFrame = isIt;
	// can't really have a spacer without a frame
	if (!isIt && this.hasSpacer) {
		this.setHasSpacer(false);
	}
	if (!isIt && this.hasStrainer) {
		this.setHasStrainer(false);
	}
}

function setIsCut(cut) {
	this.isCut = cut;
}

function setPnum(val) {
	this.pnum = val;
	this.setDrillFromBack(true); // will only set to true if it's allowed
	// set the default floater size
	if (this.isFloater() && (this.floatSize == null || this.floatSize == 0 || this.floatSize == 0.03125 || this.floatSize == 0.125)) {
		this.setFloatSize(this.pnum == 125 ? 0.03125 : 0.125);
	}
}
function setFeetNeeded(feet) {
	this.feetNeeded = feet;
}
function setQuantity(qty) {
	this.quantity = qty;
}
function qty() {
	if (this.isCut) {
		return this.quantity;
	} else {
		return this.feetNeeded;
	}
}
function setHorizontal(hor) {
	this.horizontal = hor;
}
function setVertical(ver) {
	this.vertical = ver;
}
function setWood(w) {
	this.wood = w;
}
function setWoodCode(w) {
	this.woodCode = w;
}
function setFrameCutPrice(p) {
	this.frameCutPrice = p;
}
function setFrameLengthPrice(p) {
	this.frameLengthPrice = p;
}
function setFinish(f) {
	this.finish = f;
}
function setFinCutPrice(p) {
	this.finCutPrice = p;
}
function setFinLengthPrice(p) {
	this.finLengthPrice = p;
}
function setSpWood(w) {
	this.spWood = w;
}
function setSpWoodCode(w) {
	this.spWoodCode = w;
}
function setSpCutPrice(p) {
	this.spCutPrice = p;
}
function setSpLengthPrice(p) {
	this.spLengthPrice = p;
}
function setOsSpCutPrice(p) {
	this.osSpCutPrice = p;
}
function setOsSpLengthPrice(p) {
	this.osSpLengthPrice = p;
}
function setSpFinish(f) {
	this.spFinish = f;
}
function setSpFinCutPrice(p) {
	this.spFinCutPrice = p;
}
function setSpFinLengthPrice(p) {
	this.spFinLengthPrice = p;
}
function setJoining(j) {
	this.joining = j;
}
function setJoinItem(i) {
	this.joinItem = i;
}
function setJoinPrice(p) {
	this.joinPrice = p;
}
function setMetalHardwareItem(h) {
	this.metalHardwareItem = h;
}
function setMetalHardwareDescription(d) {
	this.metalHardwareDescription = d;
}
function setMetalHardwarePrice(p) {
	this.metalHardwarePrice = p;
}
function setStCutPrice(p) {
	this.stCutPrice = p;
}
function setStLengthPrice(p) {
	this.stLengthPrice = p;
}
function setStSize(s) {
	this.stSize = s;
}
function setStJoining(j) {
	this.stJoining = j;
}
function setStJoinItem(i) {
	this.stJoinItem = i;
}
function setStJoinPrice(p) {
	this.stJoinPrice = p;
}
function stJoinDesc() {
	var ret = "";
	if (this.stJoinItem.indexOf("WEDGE") != -1) {
		ret += "Wedge";
	} else {
		ret += "Standard";
	}
	ret += " Joining for Strainer";
	return ret;
}


function setStDrilling(d) {
	this.stDrilling = d;
}
function setStDrillItem(i) {
	this.stDrillItem = i;
}
function setStDrillPrice(p) {
	this.stDrillPrice = p;
}
function stDrillDesc() {
	return "Strainer drilling " + this.stDrilling.toLowerCase();
}

function setFloatSize(sz) {
	this.floatSize = sz;
}
function setSpSize(sz) {
	this.spSize = sz;
}

function subTotal(p) {
	return RoundToCent(p * (this.isCut ? this.quantity : this.feetNeeded));
}

function itemNo() {
	var ret = "";
	if (this.pnum) {
		if (this.isMetal) {
			ret += "N";
		}
		ret += this.pnum.toString();
		if (this.isMetal) {
			if ((this.pnum == 11 && this.finishNumber() != "02") || this.pnum == 15) {
				ret += "V";
			}
			ret += this.finishNumber();
		} else {
			ret += this.woodCode;
			
			// need to do a switch around for ultrathin frames
			var p = this.pnum.toString().indexOf("UT");
			if (p != -1) {
				ret = this.pnum.substring(0, p) + this.woodCode + "UT";
			}
			
			// need to do a switch around for cutback frames
			var p = this.pnum.toString().indexOf("CB");
			if (p != -1) {
				ret = this.pnum.substring(0, p) + this.woodCode + "CB";
			}
		}
		if (this.isCut) {
			ret += "C";
		}
	}
	return ret;
}

// short way to describe the entire frame grouping
function desc() {
	var ret = "";
	if (this.hasFrame) {
		if (this.isMetal) {
			ret += "N";
		}
		ret += this.pnum.toString() + ' ';
		if (this.isMetal) {
			ret += "Metal";
		} else {
			ret += this.wood;
		}
	} else {
		if (this.hasMat) {
			if (this.matStyle == 0 || this.matStyle == 2) {
				ret += "Mat";
			} else {
				ret += "Board";
			}
		} else if (this.hasFoam) {
			ret += "Board";
		} else if (this.hasAcrylic) {
			ret += "Plexi";
		}
	}
	if (ret != "") {
		ret += " - ";
		if (this.isCut) {
			ret += convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal);
		} else {
			ret += this.feetNeeded + " lengths";
		}
	} else {
		ret = "(Next Item)";
	}
	return ret;
}

function frameDesc() {
	var ret = "";
	var type;
	if (this.isMetal) {
		type = "Metal";
	} else {
		type = this.wood;
	}
	if (this.isCut) {
		ret += convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal) + " " + type + " frame";
		if (this.isMetal) {
			ret += " - " + this.finishName();
		}
		if (this.isFloater()) {
			ret += ", canvas " + convert2Fraction(this.vertical - (this.floatSize * 2)) + "x" + convert2Fraction(this.horizontal - (this.floatSize * 2)) + ", float " + convert2Fraction(this.floatSize) + ", frame";
		}
		ret += " (" + this.frameFeet() + "ft)";
	} else {
		ret += type + " lengths";
		if (this.isMetal) {
			ret += " - " + this.finishName() + " ";
		}
	}
	return ret;
}

function framePrice() {
	//alert ("framePrice() - " + this.frameCutPrice + " - " + this.frameFeet());
	return this.isCut ? RoundToCent(this.frameCutPrice * this.frameFeet()) : this.frameLengthPrice;
}

function frameSubtotal() {
	var prc = this.framePrice();
	if (this.isOverSize()) {
		prc += this.overSizePrice();
	}
	if (!this.isMetal) {
		if (this.finishNumber() != "00") {
			prc += this.finPrice();
		}
		prc += this.joinPrice;
		if (this.canRadiusTop() && this.radiusTop) {
			prc += this.radiusPrice();
		}
		if (!this.isMetal && this.blackInterior) {
			prc += this.blackInteriorPrice();
		}
		if (this.isCut && this.drillFromBack) {
			prc += this.drillFromBackPrice;
		}
	}
	if (this.isMetal) {
		prc += this.metalHardwarePrice;
	}
	return prc;
}

function spacerSubtotal() {
	var prc = this.spPrice();
	if (this.isOverSize()) { // oversized here is talking about the length of the frame
		prc += this.overSizeSpPrice(); // not the size of the spacer
	}
	if (parseInt(this.spFinishNumber(),10) > 0) {
		prc += this.spFinPrice();
	}
	return prc;
}

function strainerSubtotal() {
	var prc = this.stPrice();
	if (this.isOverSize()) {
		prc += this.overSizeStPrice();
	}
	if (this.isCut) {
		prc += this.stDrillPrice;
		prc += this.stJoinPrice;
	}
	return prc;
}

function matSubtotal() {
	var prc = 0;
	if (this.matStyle == 0 || this.matStyle == 2) {
		prc += this.matPrice();
	}
	if (this.matStyle == 1 || this.matStyle == 2) {
		prc += this.boardPrice();
	}
	return prc;
}

// this may be bad naming -- what I mean is all the subtotals before multiplying
// by the quantity. I already used the name "subtotal" for my qty multiplying 
// function. Whatever... I don't feel like renaming stuff right now. -nb
function allSubtotal() {
	var prc = 0;
	if (this.hasFrame) {
		prc += this.frameSubtotal();
		if (this.doesHaveSpacer()) {
			prc += this.spacerSubtotal();
		}
		if (this.doesHaveStrainer()) {
			prc += this.strainerSubtotal();
		}
	}
	if (this.hasMat && this.isCut && !this.isFloater()) {
		prc += this.matSubtotal();
	}
	if (this.hasAcrylic && this.isCut && !this.isFloater()) {
		prc += this.acrylicPrice();
	}
	if (this.hasFoam && this.isCut && !this.isFloater()) {
		prc += this.foamboardPrice();
	}
	return prc;
}

// this is the calculated feet for a cut frame, not to be confused with
// feetNeeded, which is the entered quantity of 1 foot lengths when ordering
// an uncut length moulding
function frameFeet() {
	var feet = (this.horizontal + this.vertical) * 2 / 12;
	if (this.isMetal && feet < 3) {
		feet = 3;
	}
	if (!this.isMetal && feet < 4) {
		feet = 4;
	}
	return RoundIt(feet, 2);
}

// hack for converting to LineObs
function feet4Ord() {
	if (this.isCut) {
		return this.frameFeet();
	} else {
		return 0;
	}
}

// limitations of ees means I need to duplicate dimension info into the note portion
function note4Ord() {
	if (this.isCut) {
		return convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal);
	} else {
		return "";
	}
}

function isOverSize() {
	return this.isCut && !this.isMetal && this.frameFeet() > 15;
}
function overSizeItemNo() {
	return "OSFRAME";
}
function overSizeDesc() {
	return "Frames over 15 feet additional 20% charge";
}
function overSizePrice() {
	return RoundToCent(this.framePrice() * .2);
}
function overSizeSpItemNo() {
	return "OSSPACER";
}
function overSizeSpDesc() {
	return "Spacers over 15 feet additional 20% charge";
}
function overSizeSpPrice() {
	return RoundToCent(this.spPrice() * .2);
}
function overSizeStItemNo() {
	return "OSSTRAINER";
}
function overSizeStDesc() {
	return "Strainers over 15 feet additional 20% charge";
}
function overSizeStPrice() {
	return RoundToCent(this.stPrice() * .2);
}

function finItemNo() {
	var ret = this.finishNumber();
	if (this.isCut) {
		ret += "C";
	}
	return ret;
}

function finDesc() {
	var ret = this.finishName() + " Finish ";
	if (this.isCut) {
		ret += "(" + this.frameFeet() + "ft)";
	} else {
		ret += "for lengths";
	}
	return ret;
}

function finPrice() {
	return this.isCut ? RoundToCent(this.finCutPrice * this.frameFeet()) : this.finLengthPrice;
}

function spSizeNo() {
	if (this.spSize) {
		var frac = this.spSize.substring(0, 3);
		if (frac == "1/4") {
			return "25";
		} else if (frac == "3/4") {
			return "75";
		} else if (frac == "1/2") {
			return "50";
		} else if (frac == "1 1") {
			return "150";
		} else {
			return "200";
		}
	} else {
		return "";
	}
}

function spItemNo() {
	var ret = "SP" + this.spSizeNo() + this.spWoodCode;
	if (this.isCut) {
		ret += "C";
	}
	return ret;
}
function spDesc() {
	var ret;
	var p = this.spSize.indexOf("inch") + 2;
	var sp = this.spWood  + " Spacer " + this.spSize.substring(0, p) + " ";
	if (this.isCut) {
		ret = convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal) + " " + sp + "(" + this.frameFeet() + "ft)";
	} else {
		ret = sp + "lengths";
	}
	return ret;
}

function spPrice() {
	isOS = (this.spSizeNo() == "150" || this.spSizeNo() == "200"); // oversize here is talking about the size of the spacer, not the frame
	cut = (isOS ? this.osSpCutPrice : this.spCutPrice);
	lgth = (isOS ? this.osSpLengthPrice : this.spLengthPrice);
	return this.isCut ? RoundToCent(cut * this.frameFeet()) : lgth;
}

function spFinItemNo() {
	var ret = this.spFinishNumber() + "S";
	if (this.isCut) {
		ret += "C";
	}
	return ret;
}
function spFinDesc() {
	var ret = this.spFinishName() + " Finish for Spacer ";
	if (this.isCut) {
		ret += "(" + this.frameFeet() + "ft)";
	} else {
		ret += " lengths";
	}
	return ret;
}

function spFinPrice() {
	return this.isCut ? RoundToCent(this.spFinCutPrice * this.frameFeet()) : this.spFinLengthPrice;
}

function stItemNo() {
	var ret = "STR";
	if (this.stSize == "1/2in") {
		ret += "50";
	} else {
		ret += "150";
	}
	ret += "BW";
	if (this.isCut) {
		ret += "C";
	}
	return ret;
}
function stDesc() {
	var ret;
	var st = "Strainer " + this.stSize;
	if (this.isCut) {
		ret = convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal) + " " + st + " (" + this.frameFeet() + "ft)";
	} else {
		ret = st + " lengths";
	}
	return ret;
}

function stPrice() {
	return this.isCut ? RoundToCent(this.stCutPrice * this.frameFeet()) : this.stLengthPrice;
}

function finishNumber() {
	var p = this.finish.indexOf(" ");
	if (p < 0) {
		return "";
	}
	return this.finish.substring(0, p);	// ID of finish
}
function finishName() {
	var p = this.finish.indexOf(" ");
	if (p < 0) {
		return "";
	}
	return this.finish.substring(p+1); // name without the ID
}

function spFinishNumber() {
	var p = this.spFinish.indexOf(" ");
	if (p < 0) {
		return "";
	}
	return this.spFinish.substring(0, p);	// ID of finish
}
function spFinishName() {
	var p = this.spFinish.indexOf(" ");
	if (p < 0) {
		return "";
	}
	return this.spFinish.substring(p+1); // name without the ID
}

function isFloater() {
	return (!this.isMetal && (this.pnum == 120 || this.pnum == 121 || this.pnum == 122 || this.pnum == 123 || this.pnum == 124 || this.pnum == 125)) || (this.isMetal && (this.pnum == 13 || this.pnum == 14));
}

function isUltraThin() {
	return (this.pnum.toString().indexOf("UT") != -1);
}

function isStandard() {
	return (!this.isMetal && (this.pnum == 101 || this.pnum == 106 || this.pnum == 105 || this.pnum == 116 || this.pnum == 115 || this.pnum == 104));
}

function isThin() {
	return (!this.isMetal && (this.pnum == 102 || this.pnum == 114 || this.pnum == 110));
}

function isWide() {
	return (!this.isMetal && (this.pnum == 111 || this.pnum == 112 || this.pnum == "112CB" || this.pnum == 113 || this.pnum == "113CB" || this.pnum == 117 || this.pnum == "117CB"));
}

function frameType() {
	var ret;
	if (this.isMetal) {
		ret = "Metal";
	} else {
		if (this.isFloater()) {
			if (this.pnum == 125) {
				ret = "Panel";
			} else {
				ret = "Floater";
			}
		} else if (this.isStandard()) {
			ret = "Standard";
		} else if (this.isThin()) {
			ret = "Thin";
		} else if (this.isUltraThin()) {
			ret = "UltraThin";
		} else if (this.isWide()) {
			ret = "Wide";
		}
	}
	return ret;
}

function canHaveSpacer() {
	return (!this.isMetal && (this.pnum == 116 || this.pnum == 115 || this.pnum == 101 || this.pnum == 106 || this.pnum == 105 || this.pnum == 117 || this.pnum == '117CB' || this.pnum == 102 || this.pnum == 114 || this.pnum == '102UT' || this.pnum == '114UT' || this.pnum == 111));
}
function setHasSpacer(isIt) {
	this.hasSpacer = isIt;
	// can't really have a spacer without a frame
	if (isIt && !this.hasFrame) {
		this.setHasFrame(true);
	}
}
function doesHaveSpacer() {
	return this.hasSpacer && this.hasFrame && this.canHaveSpacer();
}

function canHaveStrainer() {
	return (!this.isMetal && (this.pnum == 116 || this.pnum == 115 || this.pnum == 101 || this.pnum == 106 || this.pnum == 105 || this.pnum == 102 || this.pnum == 114 || this.pnum == '102UT' || this.pnum == '114UT' || this.pnum == 111));
}
function setHasStrainer(isIt) {
	this.hasStrainer = isIt;
	// can't really have a strainer without a frame
	if (isIt && !this.hasFrame) {
		this.setHasFrame(true);
	}
}
function doesHaveStrainer() {
	return this.hasStrainer && this.hasFrame && this.canHaveStrainer();
}

function canDrillFromBack() {
	return (!this.isMetal && this.isFloater() && this.pnum != 125);
}
function setDrillFromBack(isIt) {
	this.drillFromBack = isIt && this.canDrillFromBack();
}
function setDrillFromBackPrice(p) {
	this.drillFromBackPrice = p;
}
function drillFromBackItemNo() {
	return "DRILLFLOATER";
}
function drillFromBackDesc() {
	return "Custom Floater Frame Drilling";
}

function canHaveBlackInterior() {
	return (!this.isMetal && this.isFloater());
}
function mustHaveBlackInterior() {
	return (this.canHaveBlackInterior() && (this.finishNumber() == "13A" || this.finishNumber() == "13" || this.finishNumber() == "14"));
}
function setBlackInterior(isIt) {
	this.blackInterior = isIt && this.canHaveBlackInterior();
}
function setBlackIntPrice(p) {
	this.blackIntPrice = p;
}
function blackInteriorPrice() {
	return this.isCut ? RoundToCent(this.blackIntPrice * this.frameFeet()) : this.blackIntPrice;
}
function blackIntItemNo() {
	var ret = "BLACKINTERIOR";
	if (this.isCut) {
		ret += "C";
	}
	return ret;
}

function blackIntDesc() {
	var ret = "Black Interior";
	if (this.isCut) {
		ret += " (" + this.frameFeet() + "ft)";
	} else {
		ret += " for lengths";
	}
	return ret;
}

function canRadiusTop() {
	return (!this.isMetal && !this.isFloater());
}
function setRadiusTop(isIt) {
	this.radiusTop = isIt && this.canRadiusTop();
}
function setRadiusTopPrice(p) {
	this.radiusTopPrice = p;
}
function radiusPrice() {
	return this.isCut ? RoundToCent(this.radiusTopPrice * this.frameFeet()) : this.radiusTopPrice;
}
function radiusItemNo() {
	return "RADIUS";
}
function radiusDesc() {
	var ret = "Radius Top";
	if (this.isCut) {
		ret += " (" + this.frameFeet() + "ft)";
	} else {
		ret += " for lengths";
	}
	return ret;
}

function setHasMat(isIt) {
	this.hasMat = isIt && this.isCut;
}
function setMatStyle(val) {
	this.matStyle = val;
}
function setMatItemNumber(val) {
	this.matItemNumber = val;
}
function setMatOSItemNumber(val) {
	this.matOSItemNumber = val;
}
function setMatboard(val) {
	this.matboard = val;
}
function setMatPly(val) {
	this.matPly = val;
}
function setMatColor(val) {
	this.matColor = val;
}
function setMatTop(val) {
	this.matTop = val;
}
function setMatLeft(val) {
	this.matLeft = val;
}
function setMatBottom(val) {
	this.matBottom = val;
}
function setMatRight(val) {
	this.matRight = val;
}
function setMatPrice(p) {
	this.matPricePerInch = p;
}
function setMatPriceOS(p) {
	this.matPricePerInchOS = p;
}
function setMatCutCharge(p) {
	this.matCutCharge = p;
}
function setMatCutChargeOS(p) {
	this.matCutChargeOS = p;
}
function setBoardPrice(p) {
	this.boardPricePerInch = p;
}
function setBoardPriceOS(p) {
	this.boardPricePerInchOS = p;
}
function setBoardCutCharge(p) {
	this.boardCutCharge = p;
}
function setBoardCutChargeOS(p) {
	this.boardCutChargeOS = p;
}
function setAcrylic(val) {
	this.acrylic = val;
}
function setAcrPrice(p) {
	this.acrPrice = p;
}
function setAcrCutCharge(p) {
	this.acrCutCharge = p;
}
function setFoamboard(val) {
	this.foamboard = val;
}
function setFoamPrice(p) {
	this.foamPrice = p;
}
function setFoamPriceOS(p) {
	this.foamPriceOS = p;
}
function setFoamCutCharge(p) {
	this.foamCutCharge = p;
}
function setFoamCutChargeOS(p) {
	this.foamCutChargeOS = p;
}

function isMatOversized() {
// Figure out if its over 32 x 40
	var msd=32;	// max small dim
	var mbd=40;	// max big dim
	if (this.horizontal > this.vertical){
		var sd = this.vertical;
		var bd = this.horizontal;
	} else {
		var sd = this.horizontal;
		var bd = this.vertical;
	}
	return ((sd > msd) || (bd > mbd));
}

function matItemNo() {
	if (this.matStyle == 0 || this.matStyle == 2) {
		return "J" + (this.isMatOversized() ? this.matOSItemNumber : this.matItemNumber);
	//	return "CUSTOMMAT" + (this.isMatOversized() ? "OS" : "");
	} else {
		return "";
	}
}
function matDesc() {
	var ret = convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal) + " Custom Mat ";
	ret += this.matboard + " " + this.matPly + " " + this.matColor;
	ret += ", vert i.d. " + convert2Fraction(this.vertical - this.matTop - this.matBottom);
	ret += ", top=" + convert2Fraction(this.matTop) + " bottom=" + convert2Fraction(this.matBottom);
	ret += ", horizontal i.d. " + convert2Fraction(this.horizontal - this.matLeft - this.matRight);
	ret += ", left=" + convert2Fraction(this.matLeft) + " right=" + convert2Fraction(this.matRight);
	return ret;
}
function matPrice() {
	if (this.isMatOversized()) {
		return RoundToCent((this.matPricePerInchOS * this.horizontal * this.vertical) + this.matCutChargeOS);
	} else {
		return RoundToCent((this.matPricePerInch * this.horizontal * this.vertical) + this.matCutCharge);
	}
}

function boardItemNo() {
	if (this.matStyle == 1 || this.matStyle == 2) {
		return "J" + (this.isMatOversized() ? this.matOSItemNumber : this.matItemNumber);
		//return "SIZEDBOARDS" + (this.isMatOversized() ? "OS" : "");
	} else {
		return "";
	}
}
function boardDesc() {
	var ret = convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal) + " Sized Board ";
	ret += this.matboard + " " + this.matPly + " " + this.matColor;
	return ret;
}
function boardPrice() {
	if (this.isMatOversized()) {
		return RoundToCent((this.boardPricePerInchOS * this.horizontal * this.vertical) + this.boardCutChargeOS);
	} else {
		return RoundToCent((this.boardPricePerInch * this.horizontal * this.vertical) + this.boardCutCharge);
	}
}

function setHasAcrylic(isIt) {
	this.hasAcrylic = isIt;
}
function acrItemNo() {
	return "SIZEDPLEXI";
}
function acrDesc() {
	return convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal) + " Cut Acrylic " + this.acrylic;
}
function acrylicPrice() {
	return RoundToCent((this.acrPrice * this.horizontal * this.vertical) + this.acrCutCharge);
}

function setHasFoam(isIt) {
	this.hasFoam = isIt;
}
function foamItemNo() {
	return "SIZEDBOARDS" + (this.isMatOversized() ? "OS" : "");
}
function foamDesc() {
	return convert2Fraction(this.vertical) + "x" + convert2Fraction(this.horizontal) + " Cut Foam Board " + this.foamboard;
}
function foamboardPrice() {
	if (this.isMatOversized()) {
		return RoundToCent((this.foamPriceOS * this.horizontal * this.vertical) + this.foamCutChargeOS);
	} else {
		return RoundToCent((this.foamPrice * this.horizontal * this.vertical) + this.foamCutCharge);
	}
}

function startNew() {
	var d = new Date();
	this.setId('mpf_' + d.getTime().toString());
	this.setHasFrame(false);
	this.setHasSpacer(false);
	this.setHasStrainer(false);
	this.setHasMat(false);
	this.setHasAcrylic(false);
	this.setHasFoam(false);
}

function loadJSONString(json) {
	if (json != null && json != "") {
		var jsonOb = eval("(" + json + ")");
		for (key in jsonOb) {
			this[key] = jsonOb[key];
		}
	}
}

function toJSONString() {
	var ret = '{' +
	'"id":"' + this.id + '",' +
	'"isMetal":' + (this.isMetal ? "true" : "false") + ',' +
	'"hasFrame":' + (this.hasFrame ? "true" : "false") + ',' +
	'"pnum":"' + this.pnum + '",' +
	'"isCut":' + (this.isCut ? "true" : "false") + ',' +
	'"feetNeeded":"' + this.feetNeeded + '",' +
	'"quantity":' + this.quantity + ',' +
	'"horizontal":' + this.horizontal + ',' +
	'"vertical":' + this.vertical + ',' +
	'"wood":"' + this.wood + '",' +
	'"woodCode":"' + this.woodCode + '",' +
	'"frameCutPrice":' + this.frameCutPrice + ',' +
	'"frameLengthPrice":' + this.frameLengthPrice + ',' +
	'"finish":"' + this.finish + '",' +
	'"finCutPrice":' + this.finCutPrice + ',' +
	'"finLengthPrice":' + this.finLengthPrice + ',' +
	'"joining":"' + this.joining + '",' +
	'"joinItem":"' + this.joinItem + '",' +
	'"joinPrice":' + this.joinPrice + ',' +
	'"metalHardwareItem":"' + this.metalHardwareItem + '",' +
	'"metalHardwareDescription":"' + this.metalHardwareDescription + '",' +
	'"metalHardwarePrice":' + this.metalHardwarePrice + ',' +
	'"floatSize":' + this.floatSize + ',' +
	'"drillFromBack":' + (this.drillFromBack ? "true" : "false") + ',' +
	'"drillFromBackPrice":' + this.drillFromBackPrice + ',' +
	'"blackInterior":' + (this.blackInterior ? "true" : "false") + ',' + 
	'"blackIntPrice":' + this.blackIntPrice + ',' +
	'"radiusTop":' + (this.radiusTop ? "true" : "false") + ',' +
	'"radiusTopPrice":' + this.radiusTopPrice + ',' +
	'"hasSpacer":' + (this.hasSpacer ? "true" : "false") + ',' +
	'"spWood":"' + this.spWood + '",' +
	'"spWoodCode":"' + this.spWoodCode + '",' +
	'"spFinish":"' + this.spFinish + '",' +
	'"spSize":"' + this.spSize + '",' +
	'"spCutPrice":' + this.spCutPrice + ',' +
	'"spLengthPrice":' + this.spLengthPrice + ',' +
	'"osSpCutPrice":' + this.osSpCutPrice + ',' +
	'"osSpLengthPrice":' + this.osSpLengthPrice + ',' +
	'"spFinCutPrice":' + this.spFinCutPrice + ',' +
	'"spFinLengthPrice":' + this.spFinLengthPrice + ',' +
	'"hasStrainer":' + (this.hasStrainer ? "true" : "false") + ',' +
	'"stDrillItem":"' + this.stDrillItem + '",' +
	'"stDrilling":"' + this.stDrilling + '",' + 
	'"stDrillPrice":' + this.stDrillPrice + ',' +
	'"stJoining":"' + this.stJoining + '",' +
	'"stJoinItem":"' + this.stJoinItem + '",' +
	'"stJoinPrice":' + this.stJoinPrice + ',' +
	'"stCutPrice":' + this.stCutPrice + ',' +
	'"stLengthPrice":' + this.stLengthPrice + ',' +
	'"stSize":"' + this.stSize + '",' +
	'"hasMat":' + (this.hasMat ? "true" : "false") + ',' +
	'"matStyle":' + this.matStyle + ',' +
	'"matItemNumber":"' + this.matItemNumber + '",' +
	'"matOSItemNumber":"' + this.matOSItemNumber + '",' +
	'"matboard":"' + this.matboard + '",' +
	'"matPly":"' + this.matPly + '",' +
	'"matColor":"' + this.matColor + '",' +
	'"matTop":"' + this.matTop + '",' +
	'"matLeft":"' + this.matLeft + '",' + 
	'"matBottom":"' + this.matBottom + '",' +
	'"matRight":"' + this.matRight + '",' +
	'"matPricePerInch":' + this.matPricePerInch + ',' +
	'"matPricePerInchOS":' + this.matPricePerInchOS + ',' +
	'"matCutCharge":' + this.matCutCharge + ',' +
	'"matCutChargeOS":' + this.matCutChargeOS + ',' +
	'"boardPricePerInch":' + this.boardPricePerInch + ',' +
	'"boardPricePerInchOS":' + this.boardPricePerInchOS + ',' +
	'"boardCutCharge":' + this.boardCutCharge + ',' +
	'"boardCutChargeOS":' + this.boardCutChargeOS + ',' +
	'"hasAcrylic":' + (this.hasAcrylic ? "true" : "false") + ',' +
	'"acrylic":"' + this.acrylic + '",' +
	'"acrPrice":' + this.acrPrice + ',' +
	'"acrCutCharge":' + this.acrCutCharge + ',' +
	'"hasFoam":' + (this.hasFoam ? "true" : "false") + ',' +
	'"foamboard":"' + this.foamboard + '",' +
	'"foamPrice":' + this.foamPrice + ',' +
	'"foamPriceOS":' + this.foamPriceOS + ',' +
	'"foamCutCharge":' + this.foamCutCharge + ',' +
	'"foamCutChargeOS":' + this.foamCutChargeOS + ',' +
	'"collapsed":' + (this.collapsed ? "true" : "false") +
	'}';
	return ret;
}

function Frame(isMtl, num, cut) {
	
	this.setId = setId;
	this.collapsed = true;
	
	this.setIsMetal = setIsMetal;
	this.setIsCut = setIsCut;
	
	this.setHasFrame = setHasFrame;
	this.setPnum = setPnum;
	this.setFeetNeeded = setFeetNeeded;
	this.setQuantity = setQuantity;
	this.qty = qty;
	this.setHorizontal = setHorizontal;
	this.setVertical = setVertical;
	this.setWood = setWood;
	this.setWoodCode = setWoodCode;
	this.setFrameCutPrice = setFrameCutPrice;
	this.setFrameLengthPrice = setFrameLengthPrice;
	this.setFinish = setFinish;
	this.setFinCutPrice = setFinCutPrice;
	this.setFinLengthPrice = setFinLengthPrice;
	this.setSpWood = setSpWood;
	this.setSpWoodCode = setSpWoodCode;
	this.setSpCutPrice = setSpCutPrice;
	this.setSpLengthPrice = setSpLengthPrice;
	this.setOsSpCutPrice = setOsSpCutPrice;
	this.setOsSpLengthPrice = setOsSpLengthPrice;
	this.setSpFinish = setSpFinish;
	this.setSpFinCutPrice = setSpFinCutPrice;
	this.setSpFinLengthPrice = setSpFinLengthPrice;
	this.setStSize = setStSize;
	this.setJoining = setJoining;
	this.setJoinItem = setJoinItem;
	this.setJoinPrice = setJoinPrice;
	this.setStCutPrice = setStCutPrice;
	this.setStLengthPrice = setStLengthPrice;
	this.setStJoining = setStJoining;
	this.setStJoinItem = setStJoinItem;
	this.setStJoinPrice = setStJoinPrice;
	this.stJoinDesc = stJoinDesc;

	this.setMetalHardwareItem = setMetalHardwareItem;
	this.setMetalHardwareDescription = setMetalHardwareDescription;
	this.setMetalHardwarePrice = setMetalHardwarePrice;
	
	this.setStDrilling = setStDrilling;
	this.setStDrillItem = setStDrillItem;
	this.setStDrillPrice = setStDrillPrice;
	this.stDrillDesc = stDrillDesc;
	
	this.setFloatSize = setFloatSize;
	this.setSpSize = setSpSize;
	
	this.desc = desc;
	this.subTotal = subTotal;
	this.itemNo = itemNo;
	this.frameDesc = frameDesc;
	this.framePrice = framePrice;
	this.frameFeet = frameFeet;
	this.feet4Ord = feet4Ord;
	this.note4Ord = note4Ord;
	
	this.isOverSize = isOverSize;
	this.overSizeItemNo = overSizeItemNo;
	this.overSizeDesc = overSizeDesc;
	this.overSizePrice = overSizePrice;
	this.overSizeSpItemNo = overSizeSpItemNo;
	this.overSizeSpDesc = overSizeSpDesc;
	this.overSizeSpPrice = overSizeSpPrice;
	this.overSizeStItemNo = overSizeStItemNo;
	this.overSizeStDesc = overSizeStDesc;
	this.overSizeStPrice = overSizeStPrice;
	
	this.finItemNo = finItemNo;
	this.finDesc = finDesc;
	this.finPrice = finPrice;
	
	this.spSizeNo = spSizeNo;
	
	this.spItemNo = spItemNo;
	this.spDesc = spDesc;
	this.spPrice = spPrice;
	
	this.spFinItemNo = spFinItemNo;
	this.spFinDesc = spFinDesc;
	this.spFinPrice = spFinPrice;
	
	this.stItemNo = stItemNo;
	this.stDesc = stDesc;
	this.stPrice = stPrice;
	
	this.finishNumber = finishNumber;
	this.finishName = finishName;
	
	this.spFinishNumber = spFinishNumber;
	this.spFinishName = spFinishName;

	this.isFloater = isFloater;
	this.isUltraThin = isUltraThin;
	this.isStandard = isStandard;
	this.isThin = isThin;
	this.isWide = isWide;
	
	this.frameType = frameType;
	
	this.canHaveSpacer = canHaveSpacer;
	this.setHasSpacer = setHasSpacer;
	this.doesHaveSpacer = doesHaveSpacer;
	
	this.canHaveStrainer = canHaveStrainer;
	this.setHasStrainer = setHasStrainer;
	this.doesHaveStrainer = doesHaveStrainer;
	
	this.canDrillFromBack = canDrillFromBack;
	this.setDrillFromBack = setDrillFromBack;
	this.setDrillFromBackPrice = setDrillFromBackPrice;
	this.drillFromBackItemNo = drillFromBackItemNo;
	this.drillFromBackDesc = drillFromBackDesc;
	
	this.canHaveBlackInterior = canHaveBlackInterior;
	this.mustHaveBlackInterior = mustHaveBlackInterior;
	this.setBlackInterior = setBlackInterior;
	this.setBlackIntPrice = setBlackIntPrice;
	this.blackInteriorPrice = blackInteriorPrice;
	this.blackIntItemNo = blackIntItemNo;
	this.blackIntDesc = blackIntDesc;
	
	this.canRadiusTop = canRadiusTop;
	this.setRadiusTop = setRadiusTop;
	this.setRadiusTopPrice = setRadiusTopPrice;
	this.radiusPrice = radiusPrice;
	this.radiusItemNo = radiusItemNo;
	this.radiusDesc = radiusDesc;
	
	this.setHasMat = setHasMat;
	this.setMatStyle = setMatStyle;
	this.setMatItemNumber = setMatItemNumber;
	this.setMatOSItemNumber = setMatOSItemNumber;
	this.setMatboard = setMatboard;
	this.setMatPly = setMatPly;
	this.setMatColor = setMatColor;
	this.setMatTop = setMatTop;
	this.setMatLeft = setMatLeft;
	this.setMatBottom = setMatBottom;
	this.setMatRight = setMatRight;
	this.setMatPrice = setMatPrice;
	this.setMatPriceOS = setMatPriceOS;
	this.setMatCutCharge = setMatCutCharge;
	this.setMatCutChargeOS = setMatCutChargeOS;
	this.setBoardPrice = setBoardPrice;
	this.setBoardPriceOS = setBoardPriceOS;
	this.setBoardCutCharge = setBoardCutCharge;
	this.setBoardCutChargeOS = setBoardCutChargeOS;
	this.setAcrylic = setAcrylic;
	this.setAcrPrice = setAcrPrice;
	this.setAcrCutCharge = setAcrCutCharge;
	this.setFoamboard = setFoamboard;
	this.setFoamPrice = setFoamPrice;
	this.setFoamPriceOS = setFoamPriceOS;
	this.setFoamCutCharge = setFoamCutCharge;
	this.setFoamCutChargeOS = setFoamCutChargeOS;
	
	this.isMatOversized = isMatOversized;
	
	this.matItemNo = matItemNo;
	this.matDesc = matDesc;
	this.matPrice = matPrice;
	
	this.boardItemNo = boardItemNo;
	this.boardDesc = boardDesc;
	this.boardPrice = boardPrice;
	
	this.setHasAcrylic = setHasAcrylic;
	this.acrItemNo = acrItemNo;
	this.acrDesc = acrDesc;
	this.acrylicPrice = acrylicPrice;
	
	this.setHasFoam = setHasFoam;
	this.foamItemNo = foamItemNo;
	this.foamDesc = foamDesc;
	this.foamboardPrice = foamboardPrice;
	
	this.frameSubtotal = frameSubtotal;
	this.spacerSubtotal = spacerSubtotal;
	this.strainerSubtotal = strainerSubtotal;
	this.matSubtotal = matSubtotal;
	this.allSubtotal = allSubtotal;

	this.toJSONString = toJSONString;
	this.loadJSONString = loadJSONString;
	
	this.startNew = startNew;
	
	var d = new Date();
	this.setId('mpf_' + d.getTime().toString());
	this.setIsMetal(isMtl);
	this.setHasFrame(false);
	this.setPnum(num);
	this.setIsCut(cut);
	this.setFeetNeeded("10");
	this.setQuantity(1);

	if (num==105 || num==114) {
		this.setHorizontal(16);
		this.setVertical(10);
	} else if (num==110 || num==125) {
		this.setHorizontal(11);
		this.setVertical(14);
	} else {
		this.setHorizontal(24);
		this.setVertical(36);
	}
	this.setWood("Maple");
	this.setWoodCode("MP");
	this.setFrameCutPrice(0);
	this.setFrameLengthPrice(0);
	this.setFinish("01 Clear Lacquer");
	this.setFinCutPrice(0);
	this.setFinLengthPrice(0);
	this.setJoining(this.isUltraThin() ? "Cut to Size" : "Standard Joining");
	this.setJoinItem(this.isUltraThin() ? "" : "JOIN");
	this.setJoinPrice(0);
	
	this.setMetalHardwareItem("");
	this.setMetalHardwareDescription("");
	this.setMetalHardwarePrice(0);
	
	this.setFloatSize(this.isFloater() ? (this.pnum == 125 ? 0.03125 : 0.125) : 0);
	this.setDrillFromBack(true); // will only set those that can have it
	this.setDrillFromBackPrice(0);
	this.setBlackInterior(false);
	this.setBlackIntPrice(0);
	this.setRadiusTop(false);
	this.setRadiusTopPrice(0);
	
	this.setHasSpacer(false);
	this.setSpWood("");
	this.setSpWoodCode("");
	this.setSpFinish("");
	this.setSpSize("1/2inch");
	this.setSpCutPrice(0);
	this.setSpLengthPrice(0);
	this.setOsSpCutPrice(0);
	this.setOsSpLengthPrice(0);
	this.setSpFinCutPrice(0);
	this.setSpFinLengthPrice(0);
	this.setHasStrainer(false);
	this.setStDrilling("");
	this.setStDrillItem(0);
	this.setStDrillPrice(0);
	this.setStJoining("");
	this.setStJoinItem("");
	this.setStJoinPrice(0);
	this.setStCutPrice(0);
	this.setStLengthPrice(0);
	this.setStSize("3/4in");
	this.setHasMat(false);
	this.setMatStyle(0);
	this.setMatboard("");
	this.setMatItemNumber("");
	this.setMatOSItemNumber("");
	this.setMatPly("");
	this.setMatColor("");
	this.setMatTop("3");
	this.setMatLeft("3");
	this.setMatBottom("3");
	this.setMatRight("3");
	this.setMatPrice(0);
	this.setMatPriceOS(0);
	this.setMatCutCharge(0);
	this.setMatCutChargeOS(0);
	this.setBoardPrice(0);
	this.setBoardPriceOS(0);
	this.setBoardCutCharge(0);
	this.setBoardCutChargeOS(0);
	this.setHasAcrylic(false);
	this.setAcrylic("");
	this.setAcrPrice(0);
	this.setAcrCutCharge(0);
	this.setHasFoam(false);
	this.setFoamboard("");
	this.setFoamPrice(0);
	this.setFoamPriceOS(0);
	this.setFoamCutCharge(0);
	this.setFoamCutChargeOS(0);
}

// order functions

function addFrame(id) {
//	alert ("start cnt = " + this.frameCnt);
	this.frames[this.frameCnt] = id;
	this.frameCnt++;
//	alert ("end cnt = " + this.frameCnt);
}

function removeFrame(id) {
	// I'm just gonna clear the whole array and redo it
	var tmp = this.frames;
	var cnt = this.frameCnt;
	this.frameCnt = 0;
	this.frames = new Object();
	for (i=0 ; i<cnt; i++) {
		if (tmp[i] != id) {
			this.addFrame(tmp[i]);
		}
	}
}

function ordToJSONString() {
	var ret = "[";
	if (this.frameCnt > 0) {
		for (i=0; i<this.frameCnt; i++) {
			ret += this.frames[i] + ",";
		}
		ret = ret.substring(0, ret.length-1); // strip off that last comma
	}
	ret += "]";
	return ret;
}

function loadOrdJSONString(json) {
	if (json && json != "()") {
	// strip off square brackets that it should always have
	// note: this should really do some testing to make sure the
	// string is valid, but I'm going the quick way for now
		json = json.substring(1, json.length-1);
		var p = json.indexOf(",");
		while (p != -1) {
			this.addFrame(json.substring(0, p));
			json = json.substring(p+1);
			p = json.indexOf(",");
		}
		if (json) {
			this.addFrame(json);
		}
	}
}

function containsFrame(id) {
	var ret = false;
	for (i=0; i<this.frameCnt; i++) {
		if (id == this.frames[i]) {
			ret = true;
			break;
		}
	}
	return ret;
}

function Order() {
	this.frames = Object();
	this.frameCnt = 0;
	this.addFrame = addFrame;
	this.removeFrame = removeFrame;
	this.toJSONString = ordToJSONString;
	this.loadJSONString = loadOrdJSONString;
	this.containsFrame = containsFrame;
}
