function StartUpManager() {
	this.installManager = null;	
	this.xpHelper = null;
	var cruiseWin = null;
	this.enabled = true;
	var certificates=[];
	
	this.initialize = function () {	
		this.xpHelper = new XPHelper();
		this.installManager = new InstallManager();
		this.installManager.initialize();
		top.document.title  = "Amadeus Cruise";
		var lang = langManager.getLanguage();
		if (params.isXPSP2() && params.isInstalled()) {
			if (params.useLauncher())
				this.xpHelper.removeXPSP2Patch();
			else
				this.xpHelper.applyXPSP2Patch();
		}
		if (params.isAutoStart())
			this.execute();
		this.refreshFrames(lang);
		this.installManager.validate();
	}

	this.refreshFrames = function (a_language) {
		top.bannerFrame.location.href = "common/mainmenu.asp?LANG=" + a_language + "&VER="+params.siteVersion;
		top.iconFrame.location.href = "common/icon.asp?LANG=" + a_language + "&VER="+params.siteVersion;
		top.headerFrame.location.href = "common/header.asp?LANG=" + a_language + "&VER="+params.siteVersion;
		top.footerFrame.location.href = "common/copyright.asp?LANG=" + a_language + "&VER="+params.siteVersion;
		top.subHeaderFrame.location.href = "common/subHeader.asp?LANG=" + a_language + "&VER="+params.siteVersion;		
	}
	
	this.manageError = function (a_sFlag) {
		var url = 'common/error.asp?';
		url += 'ERR=' + a_sFlag;
		url += '&LANG=' + langManager.getLanguage();
		url += '&CERTIFICATE_URL=' + params.certificateSite;
		top.mainFrame.location.replace(url);
	}

	
	this.isCertificateValid = function (a_subject, s_atid, a_cid) {
		var result = ((s_atid.length == 8 && s_atid.search(/\w{8}/) != -1) &&
				  (a_subject.toUpperCase().indexOf("AMADEUS") != -1) &&
				  (a_subject.toUpperCase().search(/.+,.+,.+,.+,.+,.*PRINTER.*/, "i") == -1) &&
				  (a_subject.toUpperCase().indexOf("GATEWAY") == -1) &&
				  (a_subject.toUpperCase().indexOf("HWID") == -1) &&
				  (a_subject.toUpperCase().indexOf("VIRTUAL") == -1) )
		return result;
	}

	
	this.displayCertificateList = function() {
		var url = "common/certList.asp?PRODUCT=cruise&LANG="+langManager.getLanguage();
		var args = [params, certificates];
		var windowParams = "dialogHeight:230px;dialogWidth:450px;scrollbars=no;center:yes;help:no;border:thin;resizable:no;status:no";
		window.showModalDialog(url, args, windowParams);
	}

	
	this.validateCertificates = function() {
		params.atid = "";
		params.officeId = "";
		if (CertInfo==null) 
			throw "CERTLIST NOT INITIALIZED";
		certificates = [];
		var hCert = 0;
		var sSubject = '';
		var aSubject=null;
		var oItem = null;
		var hStore = CertInfo.OpenStore("MY");
		while ((hCert = CertInfo.EnumCertificates(hStore, hCert)) != 0) {
			sSubject = '' + CertInfo.GetCertificateString(hCert, "")
			aSubject = sSubject.split(', ')
			// check that subject has three items for weird non-AMA certificates !
			if (aSubject.length <3)
				continue;
			oItem = new Object()
			oItem.ATID     = aSubject[1].toUpperCase()
			oItem.OfficeId = aSubject[2].toUpperCase()
			oItem.cid      = aSubject[aSubject.length-2].toUpperCase();
			if (this.isCertificateValid(sSubject, oItem.ATID, oItem.cid)) {
				var sCID = oItem.cid;
				var prodPattern = "\\d{12}"; //production CID pattern
				var testPattern = "(AT|NG)[\\d{12}]"; //Test CID pattern		
				//Look for a production or Test CID
				if ((sCID.length != 12 && sCID.length != (14)) || 
					(sCID.search(prodPattern) == -1  && sCID.search(testPattern) == -1 )) {
						oItem.cid = oItem.ATID;
				}
				certificates.push(oItem);
			}
		}
		CertInfo.CloseStore(hStore);
		if (certificates.length == 0)
			throw "NO_CERTIFICATE";
		else if (certificates.length == 1) {
			params.atid=certificates[0].ATID;
			params.officeId=certificates[0].OfficeId;
			params.cid=certificates[0].cid;
		}
		else {
			this.displayCertificateList()
			if (params.atid=='' || params.officeId=='') 
				throw 'CANCEL';	
		}
	}
	

	this.execute = function (bCtrlShiftClick) {
		try {

			if (params.isMSVista() && !bCtrlShiftClick && params.isLessThan39p200())
			{
				showModalDialog("MSVista/WarningMessage.html",langManager.getLanguage(),"dialogWidth:500px;dialogHeight:180px;center:yes;edge:raised;help:no;resizable:no;scroll:no;status:no");
				return (-1)
			}
		
		
			if (! params.isValidVersion())
				throw ("VERSION_TOO_OLD");
			if (! params.isValidAUVersion())
				throw ("WRONG_AU_VERSION");
			if (! params.isSGCompatible())
				this.validateCertificates();
			this.installManager.updateWebConfStatistics();
			var sParams = params.getClientWinParams();
			var sPath = params.getCruisePath();
			if (params.useSameWindow()) {
				top.location.replace(sPath);
			}
			else if (params.useLauncher())
				this.launchInLauncher(sPath);
			else
				this.launchInIE(sPath, sParams);
			if (params.isAutoClose()) 
				setTimeout("window.close()",100);
		} 
		catch(e){
			if (e!="CANCEL")
				this.manageError(e);
		}
	}

	
	this.launchInIE = function(a_path, a_params) {
		if (cruiseWin && typeof(cruiseWin.close)=='function') {
			cruiseWin.close();
			cruiseWin = null;
		}
		cruiseWin = null;
		try {
			cruiseWin=window.open(a_path, 'DialogWin', a_params, false);
			cruiseWin.focus();
		}
		catch(e) {throw ("POPUP_BLOCKED");}
		if (! cruiseWin)
			throw ("POPUP_BLOCKED");
	}	


	this.launchInLauncher = function(a_path) {
		var launcher = new ActiveXObject("AutoUpdateSrv.Launcher");
	 	launcher.LaunchEx(a_path, 600, 800, "Cruise");
	}

	
}

