// Copyright 2005-2009 ICWUSA.COM, Inc.
// Written by David Finch





var modgroups={ //insertion of spaces affects sorting, but not display
	"A":"Arms",
	"C":" Mount",
	"X":" Mount Extension",
	"CPU":" Mount",
	"FM":" Mount",
	"FS":" Mount",
	"D":" Mount",
	"P1":" Mount",
	"P2":" Mount",
	"PT":" Mount",
	"PH":" Mount",
	"PM":" Mount",
	"R":" Mount",
	"CC":" Mount",
	"GM":" Mount",
	"K":" Tray",
	"KH":"Accessories",
	"HT":"Accessories",
	"TB":"Color",
	"QG":"Color",
	"MW":"Color",
	"T":"Color",
	"P":"Color",
	"G":"Color",
	"B":"Color",
	"S":"Color",	
	"T19":" Mount",
	"T36":" Mount",
	"TM19":" Mount",
	"TM36":" Mount",
	"W":" Mount",
	"EL":"   Series",
	"UL":"   Series",
	"T2":"   Series",
	"TE":"   Series",
	"TI":"   Series",
	"TR":"   Series",
	"RX":"   Series",
	"EV":"   Series",
	"GX":"   Series",
	"RN":"   Series",
	"VM":"   Series",
	"PL":"   Series",
	"PS":"   Series",
	"T24WM":" Mount",
	"LTX":" Tray",
	"EV":"   Series",
	"LT":" Tray",
	"F8":" Mount",
	"MDR18":"   Series",
	"MDX18":"   Series",
	"MDP18":"   Series",
	"MD18":"   Series"
};

function getModGroup(m) {
	while(m.length>0) {
		var g=modgroups[m];
		if(g) return g;
		m=m.slice(0,-1);
	}
}

var products=[];
var mproducts={};

var modules={
	"A1":"11\" arm",
	"A2":"20\" double-arm",
	"A3":"11\" arm and a 20\" double-arm",
	"A4":"Two 20\" double-arms",
	"A5":"11\" arm",
	"AT1":"T2 arm",
	"AT12":"12 Short single arm",
	"AT1212":"1212 Short double arm",
	"AT1220":"1220 Medium double arm",
	"AT20":"20 Long single arm",
	"AT2020":"2020 Long double arm",
	"B":"Black",
	"C8X":"Ceiling mount, 8x8 plate",
	"C8X12":"8x8 ceiling plate with 12\" ext",
	"C8X24":"8x8 ceiling plate with 24\" ext",
	"C8X36":"8x8 ceiling plate with 36\" ext",
	"C8X5":"8x8 ceiling plate with  5\" ext",
	"C8X5":"8x8 ceiling plate",
	"CC":"Desk edge clamp",
	"CE":"Ceiling mount, stud",
	"CE12":"Stud/rafter ceiling plate with 12\" ext",
	"CE24":"Stud/rafter ceiling plate with 24\" ext",
	"CE36":"Stud/rafter ceiling plate with 36\" ext",
	"CE5":"Stud/rafter ceiling plate with  5\" ext",
	"CPU2.8":"Frame style, fitting 2.8\"-5\" CPU's",
	"CPU5":"Frame style, fitting 5\"-7\" CPU's",
	"CPU7":"Frame style, fitting 7\"-11\" CPU's",
	"CPUFF":"Clamp style, fitting 4.6\"-8\" CPU's",
	"CPUSF":"Clamp style, fitting 2\"-4.7\" CPU's",
	"CU":"Ceiling mount",
	"CU2":"Ceiling mount",
	"D":"Desk mount",
	"DC":"Desk edge clamp",
	"DM":"Desk mount",
	"DMX":"Desk mount with 18\" extension",
	"DT":"Desk mount",
	"DT2":"Desk mount",
	"DU1":"Desk riser, 1\"",
	"DU3":"Desk riser, 3\"",
	"DU5":"Desk riser, 5\"",
	"DU7":"Desk riser, 7.5\"",
	"DV3":"Desk riser, 3\"",
	"DV5":"Desk riser, 5\"",
	"DV75":"Desk riser, 7.5\"",
	"EL5120":"Elite 5120 single arm laptop mount",
	"EL5120LT":"Elite 5120 single arm laptop mount",
	"EL5220":"Elite 5220 double arm laptop mount",
	"EL5220LT":"Elite 5220 double arm laptop mount",
	"ELR5120":"Elite 5120 T-Rex single arm LCD mount",
	"ELR5220":"Elite 5220 T-Rex double arm LCD mount",
	"ELX5120":"Elite 5120 Rex single arm LCD mount",
	"ELX5220":"Elite 5220 Rex double arm LCD mount",
	"EV610":"ErgoVision 610 LCD mount",
	"EV65":"ErgoVision 65 LCD mount",
	"EV65X2":"EV65 dual monitor LCD mount",
	"EV65X2H":"EV65 dual monitor horizontal LCD mount",
	"EV65X2HT24WM":"EV65 dual monitor horizontal LCD on a 24\" track",
	"F8X36":"Floor pedestal, 36\"",
	"F8X48":"Floor pedestal, 48\"",
	"FM25":"2\" fixed LCD wall mount, VESA75",
	"FM26":"1\" fixed LCD wall mount, VESA75",
	"FM30":"2\" fixed LCD wall mount, VESA100",
	"FM31":"1\" fixed LCD wall mount, VESA100",
	"FS":"Free standing desk mount",
	"G":"Gray",
	"GM":"Desk grommet mount",
	"GX150":"Galaxy compact wall mount<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Limited quantities</b>",
	"GX250":"Galaxy pivoting compact wall mount arm<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Limited quantities</b>",
	"GX170":"<img src='http://www.icwusa.com/images/n.gif'>Galaxy compact wall mount",
	"GX270":"<img src='http://www.icwusa.com/images/n.gif'>Galaxy pivoting compact wall mount arm",
	"HTR":"T-Rex handle",
	"K12":"Mini keyboard tray, 12\"",
	"K12F":"Mini flat keyboard tray, 12\"",
	"KB":"Bent keyboard tray",
	"KC":"Composite keyboard tray",
	"KF":"Flat keyboard tray",
	"KHANDLE":"Keyboard handle",
	"KRX12":"Mini keyboard tray, 12\"",
	"KRX12F":"Mini flat keyboard tray, 12\"",
	"KRXB":"Bent keyboard tray",
	"KRXC":"Composite keyboard tray",
	"KRXF":"Flat keyboard tray",
	"K12PL":"Paralink mini keyboard tray, 12\"",
	"K12FPL":"Paralink mini flat keyboard tray, 12\"",
	"KP12":"Paralink mini keyboard tray, 12\"",
	"KP12F":"Paralink mini flat keyboard tray, 12\"",
	"KU12":"Ultra mini keyboard tray, 12\"",
	"KU12EL":"Ultra mini keyboard tray, 12\"",
	"KU12F":"Ultra mini flat keyboard tray, 12\"",
	"KU12FEL":"Ultra mini flat keyboard tray, 12\"",
	"KU12FMD":"Ultra mini flat keyboard tray, 12\"",
	"KU12FT2":"Ultra mini flat keyboard tray, 12\"",
	"KU12MD":"Ultra mini keyboard tray, 12\"",
	"KU12T2":"Ultra mini keyboard tray, 12\"",
	"KUB":"Ultra bent keyboard tray",
	"KUBEL":"Ultra bent keyboard tray",
	"KUBMD":"Ultra bent keyboard tray",
	"KUBT2":"Ultra bent keyboard tray",
	"KUC":"Ultra composite keyboard tray",
	"KUCEL":"Ultra composite keyboard tray",
	"KUCMD":"Ultra composite keyboard tray",
	"KUCT2":"Ultra composite keyboard tray",
	"KUF":"Ultra flat keyboard tray",
	"KUFEL":"Ultra flat keyboard tray",
	"KUFMD":"Ultra flat keyboard tray",
	"KUFT2":"Ultra flat keyboard tray",
	"LTRX":"Rex laptop tray",
	"LTX":"Laptop tray",
	"MD18":"MD Arm with laptop tray",
	"MDR18":"MD Arm with T-Rex",
	"MDX18":"MD Arm with Rex",
	"MW":"<img  src='../images/s/white.png'>Medical White",
	"P":"<img src='../images/s/putty.png'>Putty (+$15, +2 week lead time)<BR> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Matches Pelton &amp; Crane products</b><BR> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Custom Color</b> Not Returnable",
	"P15":"Pole mount, 1.5\"",
	"P17":"Pole mount, 1.75\"",
	"P2":"Pole mount, 2\"",
	"PM2":"Pole mount, 2\"",
	"PH2":"Horizontal pole mount, 2\"",
	"PHV2":"Horizontal pole mount, 2\"",
	"PT2":"Pole mount, 2\"",
	"PT215":"Pole mount, 1.5\"",
	"QG":"<img src='../images/s/gray.png'>Gray<BR> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Limited time only</b>",
	"R2":"Radius mount, 2\"",
	"RNB1":"RN double arm",
	"RNB2":"RN long arm",
	"RNB3":"RN short arm",
	"RNB4":"RN dual monitor arms",
	"RNB5":"RN LCD stand",
	"RT2":"Radius mount, 2\"",
	"RX":"Rex",
	"S":"Silver",	
	"T":"<img src='../images/s/tan.png'>Tan (+$15, +2 week lead time)<BR> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Matches A-dec products</b><BR> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b>Custom Color</b> Not Returnable",
	"T19":"Wall track slider, 19\"",
	"T2":"T2 Laptop mount",
	"T21212":"Short T2 Laptop mount",
	"T21220":"Medium T2 Laptop mount",
	"T22020":"Long T2 Laptop mount",
	"T2E":"T2 Elite LCD mount",
	"T2ER":"T2 Elite T-Rex LCD mount",
	"T2EX":"T2 Elite Rex LCD mount",
	"T2K":"T2 keyboard mount",
	"T2K12":"Short single arm T2 keyboard mount",
	"T2K1212":"Short T2 keyboard mount",
	"T2K1220":"Medium T2 keyboard mount",
	"T2K20":"Long single arm T2 keyboard mount",
	"T2K2020":"Long T2 keyboard mount",
	"T2R":"T2 T-Rex LCD mount",
	"T2R12":"Short single arm T2 T-Rex LCD mount",
	"T2R1212":"Short T2 T-Rex LCD mount",
	"T2R1220":"Medium T2 T-Rex LCD mount",
	"T2R20":"Long  single arm T2 T-Rex LCD mount",
	"T2R2020":"Long T2 T-Rex LCD mount",
	"T2X":"T2 Rex LCD mount",
	"T2X12":"Short single arm T2 Rex LCD mount",
	"T2X1212":"Short T2 Rex LCD mount",
	"T2X1220":"Medium T2 Rex LCD mount",
	"T2X20":"Long single arm T2 Rex LCD mount",
	"T2X2020":"Long T2 Rex LCD mount",
	"T36":"Wall track slider, 36\"",
	"TB":"<img src='../images/s/black.png'>Black Texture",
	"TM19":"Track mount w/ 19\" track",
	"TM36":"Track mount w/ 36\" track",
	"T24WM":"24\" track on a wall plate",
	"TR2M":"Double T-Rex",
	"TRM":"T-Rex",
	"TRX":"T-Rex",
	"UL100":"Ultra 100 Laptop/CRT mount",
	"UL110":"Ultra 110 LCD mount",
	"UL200":"Ultra 200 Laptop/CRT mount",
	"UL205":"Ultra 205 LCD mount",
	"UL210":"Ultra 210 LCD mount",
	"UL280":"Ultra 280 flipped LCD mount",
	"UL300":"Ultra 300 CRT mount",
	"UL390":"Ultra 390 LCD mount",
	"UL90":"Ultra 90 LCD mount",
	"UL95":"Ultra 95 LCD mount",
	"ULKB":"Keyboard-only mount",
	"VM300":"Viewmaster 300 LCD arm",
	"VM5518":"Viewmaster 5518 LCD arm",
	"VM5518LT":"Viewmaster 5518 laptop arm",
	"VMD24":"Viewmaster 24 LCD arm",
	"VMD30":"Viewmaster 30 LCD arm",
	"VMLT30":"Viewmaster 30 laptop arm",
	"VMPLA":"Viewmaster plasma mount",
	"VMT5518":"Viewmaster 5518 laptop arm",
	"VMT6512":"Viewmaster 6512 laptop arm",
	"W2":"Wall mount",
	"W3":"Wall mount",
	"WM":"Wall mount",
	"WMD":"wall mount",
	"WT":"Wall mount",
	"WT2":"Wall mount",
	"X12":"Ceiling ext, 12\"",
	"X24":"Ceiling ext, 24\"",
	"X36":"Ceiling ext, 36\"",
	"X5":"Ceiling ext,  5\"",
	"XE12":"Ceiling ext, 12\"",
	"XE24":"Ceiling ext, 24\"",
	"XE36":"Ceiling ext, 36\"",
	"XE5":"Ceiling ext,  5\"",

"ELP5120":"Elite 5120 Paralink single arm LCD mount",
"ELP5220":"Elite 5220 Paralink double arm LCD mount",
"ELS5120":"Elite 5120 Paralink Swivel single arm LCD mount",
"ELS5280":"Elite 5280 (Inverted) Paralink Swivel double arm LCD mount",

"KP12C":"Paralink mini composite keyboard tray, 12\"",
"KPB":"Paralink bent keyboard tray",
"KPC":"Paralink composite keyboard tray",
"K12CPL":"Paralink mini composite keyboard tray, 12\"",
"KBPL":"Paralink bent keyboard tray",
"KCPL":"Paralink composite keyboard tray",
"KU12C":"Ultra mini composite keyboard tray, 12\"",

"MDP18":"MD LCD Arm with Paralink",

"LTPL":"Laptop Tray with a Paralink lift and stow system",
"LTU":"Laptop Tray with an Ultra flip-up stowing system",

"T2P":"T2 Paralink",
"T2S":"T2 Paralink Swivel with no arms",
"PL":"Paralink",
"PS":"Paralink Swivel",

"T2EP":"T2 Elite Paralink LCD mount",
"T2ES":"T2 Elite Paralink Swivel LCD mount",

"T2P12":"Short single arm T2 Paralink LCD mount",
"T2P1212":"Short T2 Paralink LCD mount",
"T2P1220":"Medium T2 Paralink LCD mount",
"T2P20":"Long  single arm T2 Paralink LCD mount",
"T2P2020":"Long T2 Paralink LCD mount",

"T2S12":"Short single arm T2 Paralink Swivel LCD mount",
"T2S1212":"Short T2 Paralink Swivel LCD mount",
"T2S1220":"Medium T2 Paralink Swivel LCD mount",
"T2S20":"Long  single arm T2 Paralink Swivel LCD mount",
"T2S2020":"Long T2 Paralink Swivel LCD mount",

"UL115":"Ultra 115 Paralink LCD mount",
"UL215":"Ultra 215 Paralink LCD mount",
"UL285":"Ultra 285 Paralink LCD mount",
"UL395":"Ultra 395 Paralink LCD mount"	
	
};

function expandsub(p) {
	//we want to treat the T2 families as two options.
	//so  T2P1220-WT2-KCPL-MW would become  T2P-1220-WT2-KCPL-MW
	if(p.slice(0,2)=="T2") {
		var a=p.split("-");
		var f=a[0];
		var c=f.charAt(2);
		var i;
		if("KRXPS".indexOf(c)>=0) i=3; else i=2;
		var a1=f.slice(0,i);
		var a2="AT"+f.slice(i);
		if(modules[a1]&&modules[a2]) {
			a[0]=a1+"-"+a2
			p=a.join("-");
		}
	}
	if(p.indexOf("-CE")>=0 && p.indexOf("-CE-")<0) {
		p=p.split("-CE").join("-CE-X");
	}
	if(p.indexOf("-C8X")>=0 && p.indexOf("-C8X-")<0) {
		p=p.split("-C8X").join("-C8X-X");
	}
	if(p.slice(0,5)=="LTRX-") {
		p="RX-LTX-"+p.slice(5);
	}
	if(p.indexOf("X18-DM")>=0) {
		p=p.split("X18-DM").join("DMX");
	}
	if(p.charAt(0)=="K") {
		p="ULKB-"+p;
	}
	
	return p;
}

var moddesc={
	"A1":"with an 11\" arm",
	"A2":"with a 20\" double-arm",
	"A3":"with an 11\" arm and 20\" double-arm",
	"A4":"with two 20\" double-arms",
	"A5":"with an 11\" arm",
	"B":"Black",
	"C8X12":"ceiling mount with a 12\" ext",
	"C8X24":"ceiling mount with a 24\" ext",
	"C8X36":"ceiling mount with a 36\" ext",
	"C8X5":"ceiling mount with a 5\" ext",
	"CC":"desk edge mount",
	"CE":"ceiling mount",
	"CE12":"stud ceiling mount with a 12\" ext",
	"CE24":"stud ceiling mount with a 24\" ext",
	"CE36":"stud ceiling mount with a 36\" ext",
	"CE5":"stud ceiling mount with a 5\" ext",
	"CPU2.8":"CPU wall mount, 2.8\"-5\"",
	"CPU5":"CPU wall mount, 5\"-7\"",
	"CPU7":"CPU wall mount, 7\"-11\"",
	"CPUFF":"Large EZMount CPU wall mount, 4\"-8.1\"",
	"CPUSF":"Small EZMount CPU wall mount, 2\"-4.6\"",
	"CU":"ceiling mount",
	"CU2":"ceiling mount",
	"D":"desk mount",	
	"DC":"desk edge clamp",
	"DM":"desk mount",
	"DT":"desk mount",
	"DT2":"desk mount",
	"DU1":"desk mount with a 1\" riser",
	"DU3":"desk mount with a 3\" riser",
	"DU5":"desk mount with a 5\" riser",
	"DU7":"desk mount with a 7.5\" riser",
	"DV3":"desk mount with a 3\" riser",
	"DV5":"desk mount with a 5\" riser",
	"DV75":"desk mount with a 7.5\" riser",
	"EL5120":"Elite 5120 single arm laptop mount",
	"EL5120LT":"Elite 5120 single arm laptop mount",
	"EL5220":"Elite 5220 double arm laptop mount",
	"EL5220LT":"Elite 5220 double arm laptop mount",
	"ELR5120":"Elite 5120 T-Rex single arm LCD",
	"ELR5220":"Elite 5220 T-Rex double arm LCD",
	"ELX5120":"Elite 5120 Rex single arm LCD",
	"ELX5220":"Elite 5220 Rex double arm LCD",
	"EV610":"ErgoVision 610 LCD",
	"EV65":"ErgoVision 65 LCD",
	"EV65X2":"ErgoVision 65 dual monitor LCD",
	"EV65X2H":"ErgoVision 65 dual monitor horizontal LCD",
	"F8X36":"with a 36\" floor pedestal",
	"F8X48":"with a 48\" floor pedestal",
	"FM25":"2\" fixed VESA75 LCD wall mount",
	"FM26":"1\" fixed VESA75 LCD wall mount",
	"FM30":"2\" fixed VESA100 LCD wall mount",
	"FM31":"1\" fixed VESA100 LCD wall mount",
	"FS":"desk stand",
	"G":"Gray",
	"GM":"desk grommet mount",
	"GX150":"Galaxy compact",
	"GX250":"Galaxy pivoting compact arm",
	"GX170":"Galaxy compact",
	"GX270":"Galaxy pivoting compact arm",
	"HTR":"with a Rex handle",
	"K12":"with a 12\" keyboard tray",
	"K12F":"with a 12\" flat keyboard tray",
	"KB":"with a bent keyboard tray",
	"KC":"with a composite keyboard tray",
	"KF":"with a flat keyboard tray",
	"KHANDLE":"with a keyboard handle",
	"KRX12":"with a 12\" keyboard tray",
	"KRX12F":"with a 12\" flat keyboard tray",
	"KRXB":"with a bent keyboard tray",
	"KRXC":"with a composite keyboard tray",
	"KRXF":"with a flat keyboard tray",
	"KU12":"with a 12\" keyboard tray",
	"KU12EL":"with a 12\" Ultra keyboard tray",
	"KU12F":"with a 12\" flat keyboard tray",
	"KU12FEL":"with a 12\" Ultra flat keyboard tray",
	"KU12FMD":"with a 12\" Ultra flat keyboard tray",
	"KU12FT2":"with a 12\" Ultra flat keyboard tray",
	"KU12MD":"with a 12\" Ultra keyboard tray",
	"KU12T2":"with a 12\" Ultra keyboard tray",
	"KUB":"with a bent keyboard tray",
	"KUBEL":"with a bent Ultra keyboard tray",
	"KUBMD":"with a bent Ultra keyboard tray",
	"KUBT2":"with a bent Ultra keyboard tray",
	"KUC":"with a composite keyboard tray",
	"KUCEL":"with a composite keyboard tray",
	"KUCMD":"with a composite keyboard tray",
	"KUCT2":"with a composite keyboard tray",
	"KUF":"with a flat keyboard tray",
	"KUFEL":"with a flat Ultra keyboard tray",
	"KUFMD":"with a flat Ultra keyboard tray",
	"KUFT2":"with a flat Ultra keyboard tray",
	"LTRX":"Rex laptop tray",
	"LTX":"with a laptop tray",
	"MD18":"MD Arm",
	"MDR18":"MD Arm with T-Rex",
	"MDX18":"MD Arm with Rex",
	"MW":"Medical white",
	"NC":"Color%",
	"P":"Putty",
	"P15":"mount for a 1.5\" pole",
	"P17":"mount for a 1.75\" pole",
	"P2":"mount for a 2\" pole",
	"PH2":"mount for a 2\" horizontal pole",
	"PHV2":"mount for a 2\" horizontal pole",
	"PM2":"mount for a 2\" pole",
	"PT2":"mount for a 2\" pole",
	"PT215":"mount for a 2\" pole",
	"QG":"Gray",
	"R2":"mount for a 2\" radius",
	"RNB1":"RN double arm",
	"RNB2":"RN long arm",
	"RNB3":"RN short arm",
	"RNB4":"RN dual monitor arms",
	"RNB5":"RN LCD stand",
	"RT2":"mount for a 2\" radius",
	"RX":"Rex",
	"S":"Silver",
	"T":"Tan",
	"T19":"mount on a 19\" wall track slider",
	"T21212":"Short T2 LCD mount",
	"T21220":"Medium T2 LCD mount",
	"T22020":"Long T2 LCD mount",
	"T2E":"T2 Elite LCD",
	"T2ER":"T2 Elite T-Rex LCD",
	"T2EX":"T2 Elite Rex LCD",
	"T2K12":"Short single arm T2 keyboard mount",
	"T2K1212":"Short T2 keyboard mount",
	"T2K1220":"Medium T2 keyboard mount",
	"T2K20":"Long single arm T2 keyboard mount",
	"T2K2020":"Long T2 keyboard mount",
	"T2R":"Long T2 T-Rex LCD arm",
	"T2R12":"Short single arm T2 T-Rex LCD mount",
	"T2R1212":"Short T2 T-Rex LCD arm",
	"T2R1220":"Medium T2 T-Rex LCD arm",
	"T2R20":"Long single arm T2 T-Rex LCD mount",
	"T2R2020":"Long T2 T-Rex LCD arm",
	"T2X12":"Short single arm T2 Rex LCD mount",
	"T2X1212":"Short T2 Rex LCD arm",
	"T2X1220":"Medium T2 Rex LCD arm",
	"T2X20":"Long single arm T2 Rex LCD mount",
	"T2X2020":"Long T2 Rex LCD arm",
	"T36":"mount on a 36\" wall track slider",
	"T24WM":"mount on a 24\" track on a wall plate",
	"TB":"Black",
	"TM19":"mount on a 19\" track slider",
	"TM36":"mount on a 36\" track slider",
	"TR2M":"double T-Rex",
	"TRM":"T-Rex",
	"TRX":"T-Rex",
	"UL100":"UL100 CRT",
	"UL110":"Ultra 110 LCD",
	"UL200":"Ultra 200 CRT",
	"UL205":"Ultra 205 LCD",
	"UL210":"Ultra 210 LCD",
	"UL280":"Ultra 280 flipped LCD",
	"UL300":"Ultra 300 CRT",
	"UL390":"Ultra 390 LCD",
	"UL90":"Ultra 90 LCD",
	"UL95":"Ultra 95 LCD",
	"ULKB":"Keyboard",
	"VM1X2":"Viewmaster dual monitor",
	"VM300":"Viewmaster 300 LCD arm",
	"VM5518":"Viewmaster LCD arm",
	"VMT5518":"Viewmaster LCD arm",
	"VMT6512":"Viewmaster LCD arm",
	"VM5518LT":"Viewmaster laptop arm",
	"VMD24":"Viewmaster 24 LCD arm",
	"VMD30":"Viewmaster LCD stand",
	"VMLT30":"Viewmaster laptop stand",
	"VMPLA":"Viewmaster plasma mount",
	"W2":"wall mount",
	"W3":"wall mount",
	"WM":"wall mount",
	"WMD":"MD style wall mount",
	"WT":"wall mount",
	"WT2":"wall mount",
	"X12":"with a 12\" ext",
	"X24":"with a 24\" ext",
	"X36":"with a 36\" ext",
	"X5":"with a 5\" ext",
	"XE12":"with a 12\" ext",
	"XE24":"with a 24\" ext",
	"XE36":"with a 36\" ext",
	"XE5":"with a 5\" ext",
	"X18":"with an 18\" ext",
	
	
	
"ELP5120":"Elite 5120 Paralink single arm LCD",
"ELP5220":"Elite 5220 Paralink double arm LCD",
"ELS5120":"Elite 5120 Paralink Swivel single arm LCD",
"ELS5280":"Elite 5280 (Inverted) Paralink Swivel double arm LCD",

"K12C":"with a 12\" composite keyboard tray",
"KP12C":"with a 12\" composite paralink keyboard tray",
"KPB":"with a bent paralink keyboard tray",
"KPC":"with a composite paralink keyboard tray",
"K12CPL":"with a 12\" composite paralink keyboard tray",
"KBPL":"with a bent paralink keyboard tray",
"KCPL":"with a composite paralink keyboard tray",
"KU12C":"with a 12\" Ultra flip-up composite keyboard tray",
"LTP":"with a laptop tray made adjustable by a Paralink lift and stow system",
"LTU":"with a laptop tray made adjustable by an Ultra flip-up stowing system",

"MDP18":"MD Arm with Paralink",

"T2P":"Paralink",
"T2S":"Paralink Swivel",
"PL":"Paralink",
"PS":"Paralink Swivel",

"T2EP":"T2 Elite Paralink LCD mount",
"T2ES":"T2 Elite Paralink Swivel LCD mount",

"T2P12":"Short single arm T2 Paralink LCD arm",
"T2P1212":"Short T2 Paralink LCD arm",
"T2P1220":"Medium T2 Paralink LCD arm",
"T2P20":"Long  single arm T2 Paralink LCD arm",
"T2P2020":"Long T2 Paralink LCD arm",

"T2S12":"Short single arm T2 Paralink Swivel LCD arm",
"T2S1212":"Short T2 Paralink Swivel LCD arm",
"T2S1220":"Medium T2 Paralink Swivel LCD arm",
"T2S20":"Long  single arm T2 Paralink Swivel LCD arm",
"T2S2020":"Long T2 Paralink Swivel LCD arm",

"UL115":"Ultra 115 Paralink LCD",
"UL215":"Ultra 215 Paralink LCD",
"UL285":"Ultra 285 Paralink LCD",
"UL395":"Ultra 395 Paralink LCD"

	
};

var comments={
	"CPUFF-QG":"New! Easy to install",
	"CPUSF-QG":"New! Easy to install",
	"CPUFF-TB":"New! Easy to install",
	"CPUSF-TB":"New! Easy to install",
	"T2EP-CE5-QG":"Ideal for dental offices",
	"ELP5220-WT-QG":"Ideal for dental offices",
	"ELP5220-WT-KUB-QG":"Very popular",
	"UL215-W3-QG":"Ideal for dental offices",
	"UL215-W3-KUB-QG":"Very popular",
	"UL95-CU-QG":"Popular",
	"T2P2020-WT2-QG":"Popular",
	"T2P1212-WT2-QG":"Great for small space requirements",
	"UL115-P2-A5-QG":"Popular",
	"UL215-P2-QG":"Popular",
	"UL215-W3-KUB-TB":"Popular",
	"UL90-W2-QG":"Popular",
	"UL395-T36-KB-A4-QG":"Ideal for hospitals",
	"UL395-T36-KB-QG":"Ideal for hospitals"
};


var subnotes={
	"U":"an Ultra monitor adjuster instead of a Paralink monitor adjuster",
	"P":"a T-Rex monitor adjuster instead of a Paralink monitor adjuster",
	"P2":"a Rex monitor adjuster instead of a Paralink monitor adjuster",
	"P3":"a T-Rex monitor adjuster instead of a Paralink Swivel monitor adjuster",
	"PLT":"a Rex tray adjuster instead of a Paralink tray adjuster",
	"ULT":"a Rex tray adjuster instead of an Ultra tray adjuster",
	"C":"a flat aluminum keyboard tray instead of a composite keyboard tray",
	"R":"keyboard tray on a Rex adjuster instead of an Ultra flip-up",
	"RC":"a flat metal keyboard tray on a Rex adjuster instead of a composite keyboard tray on an Ultra flip-up"
}
var oldmodsubUL={
	"K12CPL":"KU12F,C",
	"K12PL":"KU12",
	"KBPL":"KUB",
	"KCPL":"KUF,C",
	"KU12C":"KU12F,C",
	"KUC":"KUF,C"
};
var oldmodsubNotUL={
	"KUB":"KRXB,R",
	"KUC":"KRXF,RC",
	"KU12":"KRX12,R",
	"KU12C":"KRX12F,RC"
};
var oldmodsub={
	"K12C":"K12F,C",
	"K12CPL":"KRX12F,C",
	"K12FPL":"KRX12F",
	"K12PL":"KRX12",
	"KBPL":"KRXB",
	"KCPL":"KRXF,C",

	"ELP5120":"ELR5120,P",
	"ELP5220":"ELR5220,P",
	"ELS5120":"ELR5120,P3",
	"ELS5280":"ELX5220,P3",
	"MDP18":"MDR18,P",
	"PL":"TRX,P",
	"PS":"RX,P2",
	"T2P":"TRX,P",
	"T2S":"RX,P2",
	"T2EP":"T2ER,P",
	"T2ES":"T2ER,P",
	"T2P12":"T2R12,P",
	"T2P1212":"T2R1212,P",
	"T2P1220":"T2R1220,P",
	"T2P20":"T2R20,P",
	"T2P2020":"T2R2020,P",
	"T2S12":"T2R12,P3",
	"T2S1212":"T2R1212,P3",
	"T2S1220":"T2R1220,P3",
	"T2S20":"T2R20,P3",
	"T2S2020":"T2R2020,P3",
	"UL115":"UL110,U",
	"UL215":"UL210,U",
	"UL285":"UL280,U",
	"UL395":"UL390,U",
	"LTPL":"LTRX,PLT",
	"LTUPL":"LTRX,ULT",
	"LTU":"LTRX,ULT",
	"KC":"KF,C"
};

//return [part,notes]
function FindSubstitute(part) {
	var ma=part.split("-");
	var isUL=part.charAt(0)=="U";
	var sub;
	var notes=[];
	var info="";
	if("PTBQG".indexOf(ma[ma.length-1])>=0) {
		//simple color change
		ma[ma.length-1]="MW";
		notes.push("white or gray coating");
	} else {
		for(var i=0;i<ma.length;i++) {
			var m=ma[i];
			var sub=(isUL?oldmodsubUL:oldmodsubNotUL)[m] || oldmodsub[m];
			if(sub) {
				sub=sub.split(",");
				if(sub.length>1) notes.push(subnotes[sub[1]]);
				ma[i]=sub[0];
			}
		}
		info="<a href='../paralink.html' target='_blank' style='text-decoration:underline;color:blue;'>More info and images</a>"
	}
	var newpart=ma.join("-");
	if(newpart==part) return false;
	
	if(notes.length>0) {
		if(notes.length>2) {
			notes[notes.length-1]="and "+notes[notes.length-1];
			notes=notes.join(", ");
		} else {
			notes=notes.join(" and ")
		}
		notes="Exact image not yet available. Shown with "+notes+". "+info;
	} else {
		notes=""; //this shouldn't happen
	}
	return [newpart,notes];
}


var rtrim=/(^\s*)|(\s*$)/g;
function trim(s) {
	return s.replace(rtrim,"");
}



function AutoPartDesc(n,light) {
	try {
		var m=n.split("-");
		var d="";
		m=m.slice(-1).concat(m.slice(0,-1));
		var rare=false;
		for(var j=0;j<m.length;j++) {
			var mod=moddesc[m[j]];
			if(mod) d+=" "+mod; else d+=" ["+m[j]+"]";
		}

		m=d.split("with");
		m=[m.slice(0,2).join("with")].concat(m.slice(2));
		if(m.length>2) {
			d=[m.slice(0,-1).join(", ")].concat(m.slice(-1)).join(", and");
		} else {
			d=m.join("and");
		}
		d=d.split(" , ").join(", ");
		d=d.split("  ").join(" ");
		d=trim(d);
		
		if(d.slice(0,7)=="with a ") d=d.slice(7);
		if(d.slice(0,8)=="with an ") d=d.slice(8);
		
		d=d.slice(0,1).toUpperCase()+d.slice(1)+".";
		if(!light) {
			var c=comments[n];
			if(c) d+=" "+c+".";
		}
		
		return d;
	} catch(e) {
		return "["+(e.message||e.Description)+"]";
	}
}

function repl(a,b,c) {
	if(a.indexOf(b)>=0) return a.split(b).join(c);
	return a;
}

function colorsubst(text,suffix) {
	var a,b,c,d;
	switch(suffix) {
	case "-TB":
		a="black"; b="Black"; c="textured black"; d="Textured black";
		break;
	case "-QG":
		a="gray"; b="Gray"; c="quartz gray"; d="Quartz gray";
		break;
	case "-MW":
		a="white"; b="White"; c="gloss white"; d="Gloss white";
		break;
	case "-T":
		a="tan"; b="Tan"; c="tan"; d="Tan";
		break;
	case "-P":
		a="putty"; b="Putty"; c="putty"; d="Putty";
		break;
	}
	text=repl(text,"color%",a);
	text=repl(text,"Color%",b);
	text=repl(text,"colour%",c);
	text=repl(text,"Colour%",d);
	return text;
}
function fullProduct(p) {
	if(typeof(p)=="string") p=products[p];
	if(!p.desc) { //assume that anything without description is an empty colored version of a "-NC" base
		var temp=p.stockcode.split("-");
		var suffix="-"+temp.pop();
		var ncname=temp.join("-");
		var nc=mproducts[ncname];
		if(nc) {
			for(var n in nc) {
				if(!p[n]) {
					var v=nc[n];
					if(typeof(v)=="string") v=colorsubst(v,suffix);
					p[n]=v;
				}
			}
		}
		
	}
	return p;
}


var mods=[];
var temp=[];
var choices=[];
var mlist=[];

function modinit(rep,base) {
	var count=0;
	/*var bc=0,rc=0;*/
	var groups;
	for(var i in products) {
		var p=products[i];
		var def=p.stockcode==rep;
		var m=expandsub(p.stockcode).split("-"); //remember this T2 expansion and test it
		
		if(def) {
			current=p;
		
			//diff stuff
			//alert(el("desc").innerHTML);
			//alert(el("title").innerHTML);
			//alert(el("specs").innerHTML);
			//el("desc").innerHTML=diff(p.desc,el("desc").innerHTML);
			//el("title").innerHTML=diff(p.title,el("title").innerHTML);
			//el("specs").innerHTML=diff(p.specs,el("specs").innerHTML);
		}


		/*if((p.basecode==base && (bc<4||count<7)) || (p.basecode!=base && rc<3)) {
			document.write("<img src='../med_mfg/products_med-mfg/a/72x64a/"+p.stockcode+".jpg'> ");
			if(p.basecode==base) bc++; else rc++;
		}*/
		count++;


		groups=[];
		p.mods=[];
		for(var j=0;j<m.length;j++) {
			var mm=m[j];
			
			//patches
			if(mm=="CE" && m[j+1].slice(0,2)=="XE") continue;
			if(mm=="CU2" && m[j+1].slice(0,2)=="XE") continue;
			
			//DEBUG
			//if(!modules[mm]) document.write("Missing module["+mm+"]<br>");
			//if(!getModGroup(mm)) document.write("Missing getModGroup("+mm+")<br>");
			//if(!moddesc[mm]) document.write("Missing moddesc["+mm+"]<br>");
			
			var g=getModGroup(mm);
			groups[g]=1;
			var o=g+" : "+modules[mm];
			if(!mods[o]) mods[o]=[];
			//document.write("match "+o+" "+m[j]+"<br>");
			mods[o].push(p);
			p.mods[o]=1;
			if(def) choices[o]=1;
		}
		for(var n in modgroups) {
			var g=modgroups[n];
			if(!groups[g]) {
				var o=g+" :  None";
				if(!mods[o]) mods[o]=[];
				mods[o].push(p);
				p.mods[o]=1;
				if(def) choices[o]=1;
				groups[g]=1;
			}
		}
	}
	
	for(var n in mods) {
		var m=mods[n];
		if(m.length<count) {
			temp[n]=m;
		} else {
			//document.write("dropping "+n+"<br>");
		}
	}
	mods=temp;

	
	for(var n in mods) {
		//document.write(n+"<br>");
		mlist.push(n);
	}
	mlist.sort();
	var pg="";
	var ct=0,mct=0,ct2=0;
	var boxtype=window.opera?"checkbox":"radio";
	for(var i=0;i<mlist.length;i++) {
		var m=mlist[i];
		var ma=m.split(" : ");
		var g=ma[0];
		var o=ma[1];
		if(g!=pg) {
			if(i>0) {
				//if(ct>mct) mct=ct;
				//while(ct++<mct) { document.write("<big> <br></big>"); }
				//document.write("<span style='font-size:"+(ct2*2+2)+"pt;'> <br></span>");
				document.write("</div>");
				//ct2++;
			}
			document.write("<div class='optionheader'>"+g+"<br>");
			ct=0;
		}
		var ms=escape(m);
		document.write("<label class='optionitem' for='"+ms+"'><input class='optionbox' type='"+boxtype+"' id='"+ms+"' onclick='choose(unescape(\""+ms+"\"))'>&nbsp;"+trim(o) /*.replace(/[ ]/g," ")*/ +"</label><br>");
		ct++;
		pg=g;
	}
	document.write("</div>");
	document.write("<br><center><small><a href='#"+rep+"' id='linktothis'><u>Link to selected product</u></a><br><font color='gray'>(right click, \"Copy "+(document.all?"Shortcut":"Link")+"\")</font></small></center>");
}	
	
//function el(n) { return document.all?document.all[n]:document.getElementById(n); }
function el(n,f) {
	if(f) return document.forms[n][f];
	else return document.all?document.all[n]:document.getElementById(n);
}
	
function updateboxes() {
	for(var m in mods) {
		var e=el(escape(m));
		if(choices[m]) e.checked=true;
		else e.checked=false;
	}
}

var current;

function addOne() {
	current=fullProduct(current.stockcode);
	addCart(current.stockcode,current.msrp,1);
}

function choose(m) {
	choices[m]=choices[m]?0:1;
	var ch=choices[m];
	var mc=mods[m];
	var pr=ch?mc:products;
	if(ch) m="!"+m;
	for(var i in pr) {
		var p=pr[i];
		p.choice=m;
		p.score=-p.rank/20000;
		if(p.basecode==lastbase) p.score+=0.5;
	}
	if(!ch) {
		for(var i in mc) {
			var p=mc[i];
			p.score-=10000;
		}
	}
	
	var count;
	for(var c in choices) {
		if(choices[c]) {
			count=0;
			var mod=mods[c];
			for(var i in mod) {
				var p=mod[i];
				if(p.choice==m) {
					p.score++;
					count++;
				}
			}
			//if(count==0) choices[c]=0;
		}
	}
	var ms=-1;
	var best;
	for(var i in pr) {
		var p=pr[i];
		if(p.score>ms || !best) {
			ms=p.score;
			best=p;
		}
	}
	
	current=best;
	setproduct(best.stockcode);
}

var lastbase="";
function setproduct(s) {
	var p=fullProduct(s);
	current=p;
	el("imgnotes").innerHTML="";
	el("bigphoto").src=cache("../images/product_images/225x225f/"+p.stockcode+".jpg");
	el("stockcode").innerHTML=p.stockcode;
	el("msrp").innerHTML=p.msrp;
	el("title").innerHTML=p.title;
	el("desc").innerHTML=p.desc;
	el("specs").innerHTML=p.specs;
	
	var linky=el("linktothis");
	if(linky) {
		var u=""+document.location.href;
		if(u.indexOf("#")) u=u.split("#")[0];
		linky.href=u+"#"+p.stockcode;
	}

	for(var c in mods) {
		if(p.mods[c]) {
			choices[c]=1;
		} else {
			choices[c]=0;
		}
	}
	
	updateboxes();
	if(p.basecode!=lastbase) {
		try {
			lastbase=p.basecode;
			loadopt(p.basecode);
			updatesidebar("blah");
		} catch(e) {}
	}
}


var ErrBeforeLoad;
function ImageError() {
	if(!loaded) {
		ErrBeforeLoad=true;
		//alert("delaying");
		return;
	}

	var img=el("bigphoto");
	var oldsrc=""+img.src;
	var newsrc='../images/product_images/225x225f/placeholder225.gif';
	var notes="";
	if(oldsrc.indexOf(current.stockcode)>=0) {
		var sub=FindSubstitute(current.stockcode);
		if(sub) {
			//alert(sub[0]);
			newsrc='../images/product_images/225x225f/'+sub[0]+'.jpg';
			notes=sub[1];
		} else {
			//notes="no substitute";
		}
	}
	if(oldsrc!=newsrc) {
		img.src=cache(newsrc);
		//alert(newsrc);
	} else {
		notes="";
	}
	el("imgnotes").innerHTML=notes;
}

var loaded;
function pageinit() {
	var url=(""+document.location.href).split("#");
	if(url.length>1 && url[1].length>0) {
		var part=url[1];
		setproduct(part);
		ErrBeforeLoad=false;
	} else {
		updateboxes();
	}
	displaycart();
	loaded=true;
	if(ErrBeforeLoad) ImageError();
}


