CitrixProductSelector = function(name, func) {
	var self = this;

	this.cpList = {
					'Access Essentials' : {
				'3.0' : {
					'' : '770'
				},
				'2.0' : {
					'' : '770'
				},
				'1.5' : {
					'' : '770'
				}
			},
			'Access Gateway' : {
				'9.0 Enterprise Edition' : {
					'' : '771'
				},
				'8.1 Enterprise Edition' : {
					'' : '771'
				},
				'8.0 Enterprise Edition' : {
					'' : '771'
				},
				'4.5 Standard Edition' : {
					'' : '771'
				},
				'4.5 Advanced Edition' : {
					'' : '771'
				}
			},
			'Branch Repeater' : {
				'with Windows Server 2.0' : {
					'' : '841'
				},
				'5.5' : {
					'' : '841'
				},
				'5.0' : {
					'' : '841'
				}
			},
			'Branch Repeater with Windows Server' : {
				'1.5' : {
					'' : '841'
				}
			},
			'Essentials for Microsoft Hyper-V' : {
				'1.0' : {
					'' : '778'
				}
			},
			'Essentials for XenServer' : {
				'5.5' : {
					'' : '778'
				},
				'5.0' : {
					'' : '778'
				}
			},
			'NetScaler Application Delivery' : {
				'9.1' : {
					'' : '772'
				},
				'9.0' : {
					'' : '772'
				},
				'8.1' : {
					'' : '772'
				},
				'8.0' : {
					'' : '772'
				},
				'7.0' : {
					'' : '772'
				}
			},
			'NetScaler VPX' : {
				'9.1' : {
					'' : '772'
				}
			},
			'Password Manager' : {
				'4.6' : {
					'' : '773'
				},
				'4.5' : {
					'' : '773'
				}
			},
			'Provisioning Server' : {
				'5.0' : {
					'' : '774'
				},
				'4.5' : {
					'' : '774'
				}
			},
			'Receiver' : {
				'for Windows' : {
					'' : '842'
				}
			},
			'StorageLink' : {
				'1.0' : {
					'' : '778'
				}
			},
			'WANScaler' : {
				'4.x' : {
					'' : '775'
				},
				'3.x' : {
					'' : '775'
				}
			},
			'XenApp (Presentation Server)' : {
				'5.0' : {
					'Streamed for Windows Server 2008' : '777',
					'Hosted for Windows Server 2008' : '777',
					'Streamed for Windows Server 2003' : '777',
					'Hosted for Windows Server 2003' : '777',
					'Streamed to Windows XP' : '777',
					'Streamed to Windows Vista' : '777'
				},
				'4.5' : {
					'Streamed for Windows Server 2003' : '777',
					'Hosted for Windows Server 2003' : '777',
					'Streamed to Windows XP' : '777',
					'Streamed to Windows Vista' : '777'
				},
				'4.0' : {
					'Hosted for Windows Server 2003' : '777',
					'UNIX for AIX' : '777',
					'UNIX for Solaris' : '777',
					'UNIX for HP-UX' : '777'
				}
			},
			'XenApp Fundamentals' : {
				'3.0' : {
					'' : '770'
				}
			},
			'XenDesktop' : {
				'4' : {
					'' : '776'
				},
				'3.0' : {
					'' : '776'
				},
				'2.1' : {
					'' : '776'
				},
				'2.0' : {
					'' : '776'
				}
			},
			'XenServer' : {
				'5.5' : {
					'' : '778'
				},
				'5.0' : {
					'' : '778'
				},
				'4.1' : {
					'' : '778'
				}
			}
	};

	this.open = function() {
		self.product.selectedIndex = 0;
		self.updateVersion(self.product);
		self.dlg.css({top:300, left:400});	// adjust dialog to center
		self.dlg.show();
	};

	this.close = function() {
		self.dlg.hide();
	};

	this.setTitle = function(txt) {
		$('#'+name+'_dlg_title').html(txt);
	};

	this.exec = function() {
		if (self.product.selectedIndex<=0) {
			self.showError('Please select product');
			return;
		}
		if (self.version.options.length>0 && self.version.selectedIndex<=0) {
			self.showError('Please select version');
			return;
		}
		if (self.platform.options.length>0 && self.platform.selectedIndex<=0) {
			self.showError('Please select platform');
			return;
		}

		self.dlg.hide();

		var productName = self.product.options[self.product.selectedIndex].text;
		var versionName = self.version.selectedIndex>0 ? self.version.options[self.version.selectedIndex].text : '';
		var platformName = self.platform.selectedIndex>0 ? self.platform.options[self.platform.selectedIndex].text : '';
		func(productName, versionName, platformName);
	};

	this.updateVersion = function() {
		var versionList = self.cpList[self.product.options[self.product.selectedIndex].text];

		if (!versionList) {
			self.version.options.length = 0;
			self.version.style.display = 'none';
			self.updatePlatform();
			return;
		}

		self.version.options.length = 1;
		self.version.options[0].text = '---- Select One ----';
		self.version.selectedIndex = 0;
		for (var v in versionList) {
			++self.version.options.length;
			self.version.options[self.version.options.length-1].text = v;
		}
		self.version.style.display = 'block';
		self.updatePlatform();
	}

	this.updatePlatform = function() {
		var versionList = self.cpList[self.product.options[self.product.selectedIndex].text];
		var platformList = null;
		if (versionList && self.version.selectedIndex>=0) {
			platformList = versionList[self.version.options[self.version.selectedIndex].text];
		}
		var noPlatform = true;
		if (platformList) {
			for (var p in platformList) {
				if (p!='') {
					noPlatform = false;
					break;
				}
			}
		}
		if (noPlatform) {
			self.platform.options.length = 0;
			self.platform.style.display = 'none';
			return;
		}

		self.platform.options.length = 1;
		self.platform.options[0].text = '---- Select One ----';
		self.platform.selectedIndex = 0;
		for (var p in platformList) {
			++self.platform.options.length;
			self.platform.options[self.platform.options.length-1].text = p;
		}
		self.platform.style.display = 'block';
	};

	this.showError = function(msg) {
		alert(msg);
	};

	this.setup = function() {
		var		div = document.createElement('div');
		div.innerHTML = '<form name="'+name+'_form"><table>'+
							'<tr><td colspan="2" id="'+name+'_dlg_title"></td></tr>'+
							'<tr>'+
								'<td>Product</td>'+
								'<td><select name="product" size="1"></select></td>'+
							'</tr>'+
							'<tr>'+
								'<td>Version</td>'+
								'<td><select name="version" size="1"></select></td>'+
							'</tr>'+
							'<tr>'+
								'<td>Platform</td>'+
								'<td><select name="platform" size="1"></select></td>'+
							'</tr>'+
							'<tr>'+
								'<td>&nbsp;</td>'+
								'<td>'+
									'<input type="button" name="ok" value="add" />'+
									'<input type="button" name="cancel" value="cancel" />'+
								'</td>'+
							'</tr>'+
						'</table></form>';

		div.id = name+'_dlg';
		div.style.display = 'none';
		div.style.position = 'absolute';
		div.style.background = '#ccc';
		div.style.margin = '10px';
		div.style.zIndex = 9999;

		document.body.appendChild(div);
	};

	self.setup();
}