function Message() {
	this.width = 512;
	this.height = 150;
	this.background = null;
	this.message = null;
	this.isActiveX = false;
	this.solution = '';
	this.properties = null;
	this.applicationName = '';
	this.applicationType = '';
	this.currVersion = null;
	this.secureVersion = null;
	this.status = null;
	this.category = null;
	this.appAlias = null;
	this.definitionDateTime = null;
	this.result = null;
	this.solvingType = null;
	this.isRefusedToElevate = false;
}

Message.prototype = {
	setSize : function(width, height) {
		if(width)
			this.width = width;

		if(height)
			this.height = height;		
	}
	,
	
	setSolution: function(url) {
	 this.solution = url;
  }
  ,
  
  setProperties: function(properties) {
  	this.properties = properties;
  }
  ,
  
  setApplicationName: function(appName) {
  	this.applicationName = appName;
  }
  ,
  
  setApplicationType: function(appType) {
  	this.applicationType = appType;
  }
  ,
  
  setCurrVersion: function(cver) {
  	this.currVersion = cver;
  }
  ,
  
  setSecureVersion: function(lver) {
  	this.secureVersion = lver;
  }
  ,
  
  setStatus: function(stat) {
  	this.status = stat;
  }  
  ,
  
  setCategory: function(cat) {
  	this.category = cat;
  }
  ,
  
  setAppAlias: function(alias) {
  	this.appAlias = alias;
  }
  ,
  
  setDefinitionDateTime: function(dateTime) {
  	this.definitionDateTime = dateTime;
  }
  ,
  
  setResult: function(appResult) {
  	this.result = appResult;
  }
  ,

	close: function() {
		this.background.style.display = 'none';
		this.message.style.display = 'none';
		try {
  		document.body.removeChild(this.message);
  		document.body.removeChild(this.background);
  	}
  	catch(e) {}		
	}
	,
	
	display: function() {
		this._displayBackground();
		this._displayMessage();
		window.popup = this;
		window.attachEvent('onscroll', function(e){window.popup._reposition()});
		window.attachEvent('onresize', function(e){window.popup._reposition()});
		if (!this.isActiveX)
		  this._touchupShadow();
	}
	,
	
	displayActiveXBalloon : function() {
		this.isActiveX = true;
		this.display();
		this.isActiveX = false;
	}
	,
	
	_restartHC: function() {
		alert(this.properties.error_cannot_complete);
		top.window.location.reload(true);
	}
	,
	
	_displayBackground: function() {
		this.background = document.createElement('div');
		this.background.className='popupBackground';
		this.background.style.left = '0px';
	  this.background.style.top = '0px';
		this.background.style.zIndex = 94000;
		document.body.appendChild(this.background);
		this._repositionBackground();
	}
	,
	
	_displayMessage: function() {
		this.message = document.createElement('div');
		this.message.className = 'popupMessage';
		this.message.style.width = this.width + 'px';
		this.message.style.height = this.height + 'px';
		this.message.style.zIndex = 100000;
		document.body.appendChild(this.message);
		this._insertContent();
		this._repositionMessage();
	}
	,
	
	_reposition: function() {
		this._repositionBackground();
				
		if (this.ActiveX)
			this._repositionActiveInstallationBalloon();
	}
	,
	
	_repositionMessage: function() {
		var topOffset = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
  	var leftOffset = Math.max(document.body.scrollLeft, document.documentElement.scrollLeft + (top.progress != null ? top.progress.document.getElementById('shadowLeft').offsetLeft : document.getElementById('shadowLeft').offsetLeft));
		
		var browserSize = this._getBrowserSize();
		var bodyWidth = browserSize[0];
		var bodyHeight = browserSize[1];
		
  	if (this.isActiveX) {
	  	this.message.style.left = leftOffset + 'px';
	  	this.message.style.top = (topOffset + 30) + 'px';
  	}
  	else {
	  	this.message.style.left = Math.ceil((bodyWidth - this.message.offsetWidth) / 2) + 'px';
	  	this.message.style.top = (Math.ceil((bodyHeight - this.message.offsetHeight) / 2) +  topOffset) - 50 + 'px';
  	}
	}
	,
	
	_repositionActiveInstallationBalloon: function() {
		var topOffset = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
  	var leftOffset = Math.max(document.body.scrollLeft, document.documentElement.scrollLeft + document.getElementById('shadowLeft').offsetLeft);
  	this.message.style.left = leftOffset + 'px';;
	  this.message.style.top = (topOffset + 30) + 'px';
	}
	,
	
	_repositionBackground: function() {
  	this.background.style.top = Math.max(document.body.scrollTop, document.documentElement.scrollTop) + 'px';
  	this.background.style.left = Math.max(document.body.scrollLeft, document.documentElement.scrollLeft) + 'px';
		var browserSize = this._getBrowserSize();
		var bodyWidth = browserSize[0];
		var bodyHeight = browserSize[1];
  	this.background.style.width = bodyWidth + 'px';
  	this.background.style.height = bodyHeight + 'px';
	}
	,
	
	_touchupShadow: function() {
    var heightGapSize = document.getElementById('dialogShadowHeight').offsetHeight;
		document.getElementById('dialogShadowLeft').style.top = '32px';
		document.getElementById('dialogShadowLeft').style.height = heightGapSize + 'px'
		document.getElementById('dialogShadowRight').style.top = '32px';
		document.getElementById('dialogShadowRight').style.height = heightGapSize + 'px';
  }
  ,
	
	_getBrowserSize : function() {
		var bodyWidth = document.documentElement.clientWidth;
		var bodyHeight = document.documentElement.clientHeight;

		if (self.innerHeight){
		   bodyWidth = self.innerWidth; 
		   bodyHeight = self.innerHeight; 
		} 
		else if (document.documentElement && document.documentElement.clientHeight) {
		   bodyWidth = document.documentElement.clientWidth; 
		   bodyHeight = document.documentElement.clientHeight; 
		}
		else if (document.body) {
		   bodyWidth = document.body.clientWidth; 
		   bodyHeight = document.body.clientHeight; 
		}
		
		return [bodyWidth, bodyHeight];
	}
	,
	
	_insertContent: function() {
		if (this.isActiveX)
			this._buildActiveXInstallationBalloon();
		else 
			this._buildWindow();
	}
	,
	
  _buildActiveXInstallationBalloon: function() {
		var content = 
			"<div id='solution' style='height:100%'>" +
			"<div style='height:9px; width:" + this.width + "px; background: url(img/balloon_top_left.gif) no-repeat top left; font-size: 2px;'>" +
			"</div>" +
			"<div style='height:9px; width:" + this.width + "px; background: url(img/balloon_top_right.gif) no-repeat top right; font-size: 2px; margin-top:-9px; margin-left:1px'>" +
			"</div>" +
			"<div style='height:8px; width:" + (this.width - 17) + "px; background: #FFFDC1; font-size: 2px; margin-top:-9px; margin-left:9px; border-top:1px solid #AFAFAF'>" +
			"</div>" +
			"<div style='width:" + this.width + "px; height:" + (this.height + 4) + "px; border-left:1px solid #AFAFAF; border-right:1px solid #AFAFAF'>" +
			"<table border='0' width='100%' height='100%' cellspacing='0' cellpadding='0' style='background:#FFFDC1; padding-left:10px; padding-right:10px'>" +
	    "<tr valign='top'><td valign='top' align='right'><div style='background: url(img/balloon_arrow.gif) no-repeat; width:19px; height:32px; position:absolute; margin-top: -40px; margin-left:-300px'></div></td></tr>" +
			"<tr>" +
			"<td class='activeXText' valign='top' align='center'>" + this.properties.activex_download + "</td>" +
			"</tr>" +
			"</table>" +
			"</div>" +
			"<div style='height:9px; width:" + this.width + "px; background: url(img/balloon_bottom_left.gif) no-repeat bottom left; font-size: 2px; margin-top:0px'>" +
			"</div>" +
			"<div style='height:9px; width:" + this.width + "px; background: url(img/balloon_bottom_right.gif) no-repeat bottom right; font-size: 2px; margin-top:-9px; margin-left:1px'>" +
			"</div>" +
			"<div style='height:9px; width:" + (this.width - 17) + "px; background: #FFFDC1; font-size: 2px; margin-top:-9px; margin-left:9; border-bottom:1px solid #AFAFAF'>" +
			"</div>" +
			"</div>";
   	this.message.innerHTML = content;
  }
  ,
    
	_buildWindow : function() {
		var content =			
			"<div id='solution' style='min-height:100%;'>" +
			"<div style='height:32px; width:" + (parseInt(this.width) + 4) + "px; margin-left:0px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\"img/dialog_top_left.png\")'><div style='height:32px; margin-left:14px; padding-right:14px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src=\"img/dialog_top_mid.png\")'>" +
			"<div style='height:" + this.height + "px; width:14px; margin-left:" + (parseInt(this.width) - 10) + "px; position:absolute; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\"img/dialog_top_right.png\")'>" + 
      "</div>" +			
			"</div>" +
      "</div>" +
			"<div style='width:" + this.width + "px; height:" + this.height + "px; padding-left:9px;'>" +
			"<table border='0' width='100%' height='100%' cellspacing='0' cellpadding='0' style='background:#FFFFFF;'>" +
			"<tr style='height:100%'>" +
			"<td id='dialogShadowHeight' style='height:100%; width:24px;'><div id='dialogShadowLeft' style='height:100%; width:9px; position:absolute; margin-left:-9px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src=\"img/dialog_left.png\")'></div></td>" +
			"<td style='height:100%; padding-bottom:15px'>" +
      "<div>" + this._constructSolution() + "</div>" +
      "</td>" +
      "<td style='height:100%; width:24px'><div id='dialogShadowRight' style='height:100%; width:9px; position:absolute; margin-left:24px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src=\"img/dialog_right.png\")'></div></td>" +
			"</tr>" +
			"</table>" +
      "<div style='height:17px; width:" + (parseInt(this.width) + 1) + "px; margin-left:-9px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\"img/dialog_bottom_left.png\")'><div style='height:20px; margin-left:17px; margin-top:-3; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src=\"img/dialog_bottom_mid.png\")'>" +
      "<div style='height:17px; width:17px; margin-top: 3px; margin-left:" + (parseInt(this.width) - 16) + "px; position:absolute; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\"img/dialog_bottom_right.png\")'></div>" + 
      "</div></div>" +
      "</div>" +
			"</div>";
			
   	this.message.innerHTML = content;
	}    
	,
    
	_constructSolution: function() {
		var solution = "";
		if ("sp" == this.applicationType) {
			solution = this._constructMissingSPSolution();
		}
		else if ("microsoft" == this.applicationType) {
			solution = this._constructWindowsPatchesSolution();
		}
		else if ("secunia" == this.applicationType) {
			if ("endoflife" == this.status) {
				solution = 
				  "<div style='min-height:100%;'>" +
					"<table border='0' width='100%' height='100%' cellspacing='0' cellpadding='0' style='height:100%'>" +
					"<tr style='vertical-align:top;'>" +
          "<td colspan='5' class='title'>" + 
					this.properties.uninstall_this_program +
					"</td></tr>" +
					"<tr style='height:50%; vertical-align:top; padding-top:5px'>" + 
          "<td colspan='6' class='description'>" + 
					this.properties.uninstall_this_program_desc + "<p/>" +
					"</td></tr>" +
					"<tr style='vertical-align:bottom;'>" +
          "<td class='description' style='width:90%'></td>" +
					"<td align='right' style='width:90px'>" +
					"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
					"<tr style='cursor:pointer' onclick='removeUnsupportedProgram()' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" + 
					"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
					"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
					this.properties.remove +
					"</div></td>" + 
					"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
					"</tr>" + 
					"</table>" +
					"</td>" +
					"<td><div style='width:12px'></div></td>" +
					"<td align='right' style='width:90px'>" +
					this._getCancelCloseButton(this.properties.close_string) +
					"</td>" +					
					"</tr>" +
					"</table>" +
          "</div>";
			}
			else {
		  	solution = 
					"<table border='0' width='100%' height='100%' cellspacing='0' cellpadding='0'>" +
					"<tr style='vertical-align:top'><td colspan='4' class='title'>" + 
					this.properties.update_your_software.replace("$APP$", this.applicationName).replace("$CVER$", this.currVersion).replace("$LVER$", this.secureVersion) +
					"</td></tr>" +
					"<tr style='height:50%; vertical-align:top'><td colspan='4' class='description'>" + 
					this._getUpdateInstruction() + "<p/>" +
					"</td></tr>" +
					"<tr style='vertical-align:bottom'>" +
					"<td class='description' style='width:90%'><div></div></td>" + 
					"<td align='right' style='width:90px'>" +
					((this.solution == null || this.solution.length == 0) ? "" :
					"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
					"<tr style='cursor:pointer' onclick='gotoUpdateLink()' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" + 
					"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
					"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
					this.properties.update_now +
					"</div></td>" + 
					"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
					"</tr>" + 
					"</table>") +
					"</td>" +
					"<td><div style='width:12px'></div></td>" +
					"<td width='90px' align='right'>" +
					this._getCancelCloseButton(((this.solution == null || this.solution.length == 0) ? this.properties.close_string : this.properties.cancel)) +
					"</td>" +
					"</tr>" +						
					"</table>";
			}
		}
		else {
			solution = this._constructUpsellSolution();
		}
			
		return solution;
	}
	,
	
	_getUpdateInstruction: function() {
		if (this.solution == null || this.solution.length == 0) {
			return this.properties.unable_update.replace("$APP$", this.applicationName);
		}
		else if (this.solution.toLowerCase().match(".exe")) {
			return this.properties.update_instruction.replace("$APP$", this.applicationName)
		}
		else {
			return this.properties.update_instruction_page.replace("$APP$", this.applicationName)
		}
	}
	,
	
	_constructUpsellSolution: function() {
		var solution = "<table border='0' width='100%' cellspacing='0' cellpadding='0' style='height:100%'>";

		if ((this.status & Opswat_Info_ProductNotInstalled) || (this.status & Opswat_Info_IsExpired)) {
			return "<table border='0' width='100%' cellspacing='0' cellpadding='0' style='height:100%'>" + 
				"<tr style='vertical-align:top'><td colspan='6' class='title'>" + 
				this._getInstallProgram() +
				"</td></tr>" +
				"<tr style='height:50%; vertical-align:top'><td colspan='6' class='description'>" + 
				this._getUpsellRecommendation() + "<p/><a class='urlNoVisited' href='" + this.properties.upsell_learn_more_url+ "' target='_blank'>" + this.properties.upsell_learn_more + "</a>" + 
				"</td></tr>" +
				"<tr>" +
				"<td class='description' style='width:90%'><div></div></td>" + 
				"<td align='right'>" +
				(this.properties.upsell_try == null ? "" :
				"<div style='width:96px'>" +
				"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
				"<tr style='cursor:pointer' onclick='document.getElementById(\"statisticDiv\").innerHTML=top.progress.subFrame.aggregator.sendTry();window.open(\"" + this.properties.upsell_try_url +"\");closeMessage();' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" + 
				"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
				"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
				this.properties.upsell_try +
				"</div></td>" + 
				"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
				"</tr>" + 
				"</div>" +
				"</table>" +
				"</td>" +
				"<td><div style='width:12px'></div></td>") +
				"<td align='right'>" +
				(this.properties.upsell_buy == null ? "" :
				"<div style='width:96px'>"	+
				"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
				"<tr style='cursor:pointer' onclick='document.getElementById(\"statisticDiv\").innerHTML=top.progress.subFrame.aggregator.sendBuy();window.open(\"" + this.properties.upsell_buy_url +"\");closeMessage();' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" +
				"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
				"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
				this.properties.upsell_buy +
				"</div></td>" + 
				"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
				"</tr>" + 
				"</div>" +				
				"</table>" +
				"</td>" +				
				"<td><div style='width:12px'></div></td>") +
				"<td style='width:90px' align='right'>" +
				this._getCancelCloseButton(this.properties.cancel) +
				"</td>" +
				"</tr>" +
				"</table>";
	  }
	  
	  if (this.status & Opswat_Info_ProductOutdated ) {
	     return this._outOfDateAntivirusUpsellMessage();
    }
	  
	  if (this.status & Opswat_Info_IsEnabled) {
	  	//do nothing
	  }
	  else {
		  if (this.status & Opswat_Info_UnpdVerf_UpdateIsNotLatest) {
				solution += 
				  "<tr style='vertical-align:top;'><td colspan='4' class='title'>" + 
				  "<label id='solveMsgTitle'>" +
					this.properties.should_turn_on_update.replace("$APP$", this._getAppType()) +
					"</label>" +
					"</td></tr>" +
					"<tr style='height:50%; vertical-align:top'><td colspan='4' class='description'>" +
					"<label id='solveMsgDesc'>" +
					this.properties.should_turn_on_update_desc.replace("$APP$", this.applicationName) +
					"</label>" +
					"</td></tr>" +
					"<tr style='vertical-align:bottom'>" +
					"<td style='width:90%'><div></div></td>" +
					"<td>" +
					"<div><table border='0' cellspacing='0' cellpadding='0'>" +
					"<tr style='padding-bottom:15px:'>" +
					"<td class='description'></td>" + 
					"<td align='right'>" +
					"<div id='solveMsgProgress' style='visibility:hidden; display:none; width:200px'><div style='height:16px; width:16px; background:url(img/small_progress.gif) no-repeat;'><label style='margin-left:20px' class='stdButtonText'>" + this.properties.solve_string + "...  </label></div></div>"+					
					"<div id='solveMsgSolution'>" +
					"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
					"<tr style='cursor:pointer' onclick='solveIssue(\"" + this.solution + "\", \"3\");' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" + 
					"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
					"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:140px'>" +
					this.properties.turn_on_and_update +
					"</div></td>" + 
					"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
					"</tr>" + 
					"</table>" +
					"</div>" +
					"</td>" +
					"<td><div style='width:12px'></div></td>" +
					"<td width='90px' align='right'>" +
					this._getCancelCloseButton(this.properties.cancel) +
					"</tr>" +
					"</table>" +
					"</div>" +
					"</td>" +
					"</tr>";
					
					solution +=	"</table>";
					
					return solution;
		  }
		  
			solution +=	
				"<tr style='vertical-align:top'><td colspan='3' class='title'>" +
				"<label id='solveMsgTitle'>" +
				this.properties.should_turn_on.replace("$APP$", this._getAppType()) +
				"</label>" +
				"</td></tr>" +
				"<tr style='height:50%; vertical-align:top'><td colspan='4' class='description'>" +
				"<label id='solveMsgDesc'>" +
				this.properties.should_turn_on_desc.replace("$APP$", this.applicationName) +
				"</label>" +
				"</td></tr>" +
				"<tr style='vertical-align:bottom'>" +
				"<td style='width:90%'><div></div></td>" +
				"<td>" +
				"<div><table border='0' cellspacing='0' cellpadding='0'>" +
				"<tr style='padding-bottom:15px:'>" +
				"<td class='description'></td>" + 
				"<td align='right'>" +
				"<div id='solveMsgProgress' style='visibility:hidden; display:none; width:200px'><div style='height:16px; width:16px; background:url(img/small_progress.gif) no-repeat;'><label style='margin-left:20px' class='stdButtonText'>" + this.properties.solve_string + "...  </label></div></div>"+
				"<div id='solveMsgSolution'>" +
				"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
				"<tr style='cursor:pointer' onclick='solveIssue(\"" + this.solution + "\", \"1\");' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" + 
				"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
				"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
				this.properties.turn_on +
				"</div></td>" + 
				"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
				"</tr>" + 
				"</table>" +
				"</div>" +
				"</td>" +
				"<td><div style='width:12px'></div></td>" +
				"<td width='90px' align='right'>" +
				this._getCancelCloseButton(this.properties.cancel) +
				"</td>" +
				"</tr>" +
				"</table>" +
				"</div>" +
				"</td>" +
				"</tr>"; 
	  }
	  
	  if (this.status & Opswat_Info_UnpdVerf_UpdateIsNotLatest) {
			solution +=	
				"<tr style='vertical-align:top;'><td colspan='4' class='title'>" +
				"<label id='solveMsgTitle'>" +
				this.properties.should_update.replace("$APP$", this._getAppType()) +
				"</label>" +
				"</td></tr>" +
				"<tr style='height:50%; vertical-align:top'><td colspan='4' class='description'>" +
				"<label id='solveMsgDesc'>" +
				this.properties.should_update_desc.replace("$APP$", this.applicationName) + 
				"</label>" +
				"</td></tr>" +
				"<tr style='vertical-align:bottom'>" +
				"<td style='width:90%'><div></div></td>" +
				"<td>" +
				"<div><table border='0' cellspacing='0' cellpadding='0'>" +
				"<tr style='padding-bottom:15px:'>" +
				"<td class='description'></td>" + 
				"<td width='90px' align='right'>" +
				"<div id='solveMsgProgress' style='visibility:hidden; display:none; width:200px'><div style='height:16px; width:16px; background:url(img/small_progress.gif) no-repeat;'><label style='margin-left:20px' class='stdButtonText'>" + this.properties.solve_string + "...  </label></div></div>"+
				"<div id='solveMsgSolution'>" +				
				"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
				"<tr style='cursor:pointer' onclick='solveIssue(\"" + this.solution + "\", \"2\");' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" + 
				"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
				"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
				this.properties.get_update +
				"</div></td>" + 
				"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
				"</tr>" + 
				"</table>" +
				"</div>" +
				"</td>" +
				"<td><div style='width:12px'></div></td>" +
				"<td width='90px' align='right'>" +
				this._getCancelCloseButton(this.properties.cancel) +
				"</td>" +
				"</tr>" +
				"</table>" +
				"</div>" +
				"</td>" +
				"</tr>";
	  }
	  
	  solution +=	"</table>";
	  
	  return solution;
	}
	,
	
	_outOfDateAntivirusUpsellMessage : function() {
		return "<table border='0' width='100%' cellspacing='0' cellpadding='0' style='height:100%'>" + 
				"<tr style='vertical-align:top'><td colspan='6' class='title'>" + 
				this.properties.recommend_to_get_new_av +
				"</td></tr>" +
				"<tr style='height:90%; vertical-align:top; padding-top:5px'><td colspan='6' class='description'>" + 
				this.properties.recommend_to_get_new_av_desc + "<p/>" + this.properties.upsell_recommend_get_antivirus +
				"</td></tr>" +
				"<tr>" +
				"<td class='description' style='width:90%'><div></div></td>" + 
				"<td align='right'>" +
				(this.properties.upsell_try == null ? "" :
				"<div style='width:96px'>" +
				"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
				"<tr style='cursor:pointer' onclick='document.getElementById(\"statisticDiv\").innerHTML=top.progress.subFrame.aggregator.sendTry();window.open(\"" + this.properties.upsell_try_url +"\");closeMessage();' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" +
				"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
				"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
				this.properties.upsell_try +
				"</div></td>" + 
				"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
				"</tr>" + 
				"</div>" +
				"</table>" +
				"</td>" +
				"<td><div style='width:12px'></div></td>") +
				"<td align='right'>" +
				(this.properties.upsell_buy == null ? "" :
				"<div style='width:96px'>"	+
				"<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
				"<tr style='cursor:pointer' onclick='document.getElementById(\"statisticDiv\").innerHTML=top.progress.subFrame.aggregator.sendBuy();window.open(\"" + this.properties.upsell_buy_url +"\");closeMessage()' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" +
				"<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
				"<td class='stdButtonText' style='text-align:center'><div class='smallButtonMid' style='width:90px'>" +
				this.properties.upsell_buy +
				"</div></td>" + 
				"<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
				"</tr>" + 
				"</div>" +				
				"</table>" +
				"</td>" +				
				"<td><div style='width:12px'></div></td>") +
				"<td style='width:90px' align='right'>" +
				this._getCancelCloseButton(this.properties.cancel) +
				"</td>" +
				"</tr>" +
				"</table>";
  }
  ,
	
	_getCancelCloseButton: function(displayString) {
		return "<table border='0' width='100%' cellspacing='0' cellpadding='0'>" + 
					 "<tr style='cursor:pointer' onclick='closeMessage()' onMouseOver='onBtnMouseOver(this, 18);' onMouseOut='onBtnMouseOut(this);' onselectstart='return false;'>" + 
					 "<td><div class='smallButtonLeft'></div><div class='smallButtonLeftOver'></div></td>" +
					 "<td class='stdButtonText' style='text-align:center'><div id='closeBtn' class='smallButtonMid' style='width:84px'>" +
					 displayString +
					 "</div></td>" + 
					 "<td><div class='smallButtonRight'></div><div class='smallButtonRightOver'></div></td>" +
					 "</tr>" + 
					 "</table>";
	}
	,
	
	_getInstallProgram: function() {
		if (OPSWAT_AV == this.applicationType) {
			return this.properties.should_install_antivirus;
		}
		else if (OPSWAT_SW == this.applicationType) {
			return this.properties.should_install_antispyware;
		}
		else if (OPSWAT_FW == this.applicationType) {
			return this.properties.should_install_firewall;
		}
	}
	,	
	
	_getAppType: function() {
		if (OPSWAT_AV == this.applicationType) {
			return this.properties.antivirus;
		}
		else if (OPSWAT_SW == this.applicationType) {
			return this.properties.antispyware;
		}
		else if (OPSWAT_FW == this.applicationType) {
			return this.properties.firewall;
		}
	}
	,
	
	_getShouldInstallMessage: function() {
		if (OPSWAT_AV == this.applicationType) {
				return this.properties.should_install.replace('$APP$', this.properties.antivirus);
			}
			else if (OPSWAT_SW == this.applicationType) {
				return this.properties.should_install.replace('$APP$', this.properties.antispyware);
			}
			else if (OPSWAT_FW == this.applicationType) {
				return this.properties.should_install.replace('$APP$', this.properties.firewall);
			}
	}
	,

	_getUpsellRecommendation: function() {
			if (OPSWAT_AV == this.applicationType) {
				return this.properties.upsell_get_antivirus;
			}
			else if (OPSWAT_SW == this.applicationType) {
				return this.properties.upsell_get_antispyware;
			}
			else if (OPSWAT_FW == this.applicationType) {
				return this.properties.upsell_get_firewall;
			}
	}
	,
	
	_getRenewLicenseMessage: function() {
		if (OPSWAT_AV == this.applicationType) {
			return this.properties.need_to_renew.replace("$APP$", this.properties.antivirus);
		}
		else if (OPSWAT_SW == this.applicationType) {
			return this.properties.need_to_renew.replace("$APP$", this.properties.antispyware);
		}
		else if (OPSWAT_FW == this.applicationType) {
			return this.properties.need_to_renew.replace("$APP$", this.properties.firewall);
		}
	}
	,		
	
	_constructWindowsPatchesSolution: function() {
		var solution = "";
		
		solution += 
			"<table border='0' width='100%' height='100%' cellspacing='0' cellpadding='0' style='padding-left:5px; padding-right:5px;'>" + 
			"<tr style='vertical-align:top;'><td colspan='4' class='title'>" + 
			this.properties.update_windows_patch +
			"</td></tr>" +
			"<tr style='height:50%; vertical-align:top;'><td colspan='4' class='description'>" + 
			this.properties.update_windows_patch_desc;
			
		solution +=	
			"<p>" + 
			"</td></tr>" +
			"<tr style='vertical-align:bottom'>" +
			"<td class='description' style='width:90%'></td>" + 
			"<td style='width:90px' align='right'>" +
			this._getCancelCloseButton(this.properties.close_string) + 	
			"</td>" +
			"</tr>" +						
			"</table>";
			
			return solution;
	}
	,
	
	_constructMissingSPSolution: function() {
		var solution = "";
		
		solution += 
			"<table border='0' width='100%' height='100%' cellspacing='0' cellpadding='0' style='padding-left:5px; padding-right:5px;'>" + 
			"<tr style='vertical-align:top;'><td colspan='4' class='title'>" + 
			this.properties.update_sp +
			"</td></tr>" +
			"<tr style='height:50%; vertical-align:top'><td colspan='4' class='description'>" + 
			this.properties.update_sp_desc.replace("$URL$", this.solution) +
			"<p>" + 
			"</td></tr>" +
			"<tr style='vertical-align:bottom'>" +
			"<td class='description' style='width:90%'></td>" + 
			"<td style='width:90px' align='right'>" +
			this._getCancelCloseButton(this.properties.close_string) + 
			"</td>" +
			"</tr>" +
			"</table>";
			
			return solution;
	}
}

function solveIssue(appId, type) {
	var hasSolved = 0;
	messageObj.solvingType = type;

	displayProgress();
	
	if (top.scan)
		hasSolved = top.scan.SolveIssue(appId);
}

function displayProgress() {
	var solutionBtn = document.getElementById('solveMsgSolution');
	var progress = document.getElementById('solveMsgProgress');
	solutionBtn.style.visibility = 'hidden';
	solutionBtn.style.display = 'none';
	progress.style.visibility = 'visible';
	progress.style.display = 'block';
}

/**
 * @param status 0 is successful, 1 is for the case solving the same issue 
 * again. Other numbers are error code, which indicate failure.
 */
function onSolvedOutcome(status) {
	if (0 == parseInt(status)|| 1 == parseInt(status)) {
		closeMessage();
		removeSolvedItem(1);
		theEye.solve(1);
	}
	else {
		if (2 == parseInt(status))
			messageObj.isRefusedToElevate = true;
			
		updateSolvingMessageToReferVendorDoc(messageObj.solvingType);
	}
}

function updateSolvingMessageToReferVendorDoc(type) {
  var title = document.getElementById('solveMsgTitle');
	var desc = document.getElementById('solveMsgDesc');
	var progress = document.getElementById('solveMsgProgress');
	var closeBtn = document.getElementById('closeBtn');

	switch (parseInt(type)){
		case 1:
			title.innerHTML = this.properties.unable_turn_on.replace('$APP$', messageObj.applicationName);
			desc.innerHTML = this.properties.unable_turn_on_desc;
			closeBtn.innerHTML = this.properties.close_string;
			break;
		case 2:
			title.innerHTML = this.properties.unable_update.replace('$APP$', messageObj.applicationName);
			desc.innerHTML = this.properties.unable_update_desc;
			closeBtn.innerHTML = this.properties.close_string;
			break;		
		case 3:
			title.innerHTML = this.properties.unable_turn_on_update.replace('$APP$', messageObj.applicationName);
			desc.innerHTML = this.properties.unable_turn_on_update_desc;
			closeBtn.innerHTML = this.properties.close_string;
			break;		
		default:
			break;
	}

	progress.style.visibility = 'hidden';
	progress.style.display = 'none';
}

function gotoUpdateLink() {
	window.open(this.properties.validator_server + encodeURI(messageObj.solution));
    solveVulnerableItem();
}

function removeUnsupportedProgram() {
    top.scan.Scanner.AddRemoveProgramInvoke();
    solveVulnerableItem();
}

function solveVulnerableItem() {
    updateStatus();
    updateDescription();
    closeMessage();
    theEye.solve(2);
}

function updateStatus() {
	updateAppStatusIcon();
}

function updateAppStatusIcon() {
	var doc = top.progress != null ? top.progress.subFrame.card.document : document;
	var redIcon = doc.getElementById('smallStatusRed' + messageObj.appAlias);
	var orangeIcon = doc.getElementById('smallStatusOrange' + messageObj.appAlias);
	var grayIcon = doc.getElementById('smallStatusGray' + messageObj.appAlias);

	redIcon.style.visibility = 'hidden';
	orangeIcon.style.visibility = 'hidden';
	grayIcon.style.visibility = 'visible';
}

function updateDescription() {
	var doc = top.progress != null ? top.progress.subFrame.card.document : document;
	var title = doc.getElementById('appTitle' + messageObj.appAlias);
	var more = doc.getElementById('more' + messageObj.appAlias);
	var solve = doc.getElementById('solve' + messageObj.appAlias);
	
	title.innerText = this.properties.status_unknown.replace('$APP$', messageObj.applicationName);
}

function removeSolvedItem(count) {
	var doc = top.progress != null ? top.progress.subFrame.card.document : document;
	
	var div = doc.getElementById(messageObj.category);
	var resultTitleToBeRemoved = doc.getElementById(messageObj.appAlias + 'title');
	var resultDescToBeRemoved = doc.getElementById(messageObj.appAlias + 'desc');

	updateAppToSolved(doc);
	var solvedApp = resultTitleToBeRemoved;
	div.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].removeChild(resultTitleToBeRemoved);
	div.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].removeChild(resultDescToBeRemoved);
	
	if (!increaseSafeAppCount(doc, solvedApp)) {
		var safeAppBar = constructSafeAppsBar(doc);
		var safeAppGroup = constructSafeAppGroup(doc, solvedApp);
		div.childNodes[0].childNodes[0].appendChild(safeAppBar);
		div.childNodes[0].childNodes[0].appendChild(safeAppGroup);
	}

	decreaseVulnItemCount(doc, count);
}

function updateAppToSolved(doc) {
	var greenIcon = doc.getElementById('smallStatusGreen' + messageObj.appAlias);
	var more = doc.getElementById('more' + messageObj.appAlias);
	var solve = doc.getElementById('solve' + messageObj.appAlias);
	var appTitle = doc.getElementById('appTitle' + messageObj.appAlias);
	
	greenIcon.style.visibility = 'visible';
	more.style.visibility = 'hidden';
	solve.style.visibility = 'hidden';
	solve.style.display = 'none';
	
	appTitle.innerHTML = appTitle.innerText.substr(0, appTitle.innerText.indexOf(messageObj.applicationName) + messageObj.applicationName.length) + " " + properties.is_on;
}

function increaseSafeAppCount(doc, solvedApp) {
	var safeAppBar = doc.getElementById('safe' + messageObj.category);
	var safeAppCount = doc.getElementById('safeCount' + messageObj.category);
	var safeAppGroup = doc.getElementById('safeItems' + messageObj.category);
	
	if (safeAppBar) {
		if (parseInt(safeAppCount.innerText) == 1) {
			safeAppBar.innerHTML = properties.program_up_to_date.replace("$COUNT$", "<label id='safeCount" + messageObj.category + "'>" + (parseInt(safeAppCount.innerText) + 1) + "</label>");
		}
		else {
			safeAppCount.innerText = (parseInt(safeAppCount.innerText) + 1);
		}
		addSafeItem(safeAppGroup.childNodes[0], solvedApp);
		return 1;
	}
}

function constructSafeAppsBar(doc) {
	var tr1 = doc.createElement("tr");
	var td1 = doc.createElement('td');
	var div1 = doc.createElement('div');
	div1.style.height = '26px';
	div1.style.borderTop = '1px solid #DDDDDD';
	div1.style.lineHeight = '26px';
	var table1 = doc.createElement('table');
	table1.border = '0';
	table1.width = '100%';
	table1.cellSpacing = '0';
	table1.cellPadding = '0';
	var tbody1 = doc.createElement('tbody');
	var tr2 = doc.createElement('tr');
	tr2.className = 'smallLabel';
	var td2 = doc.createElement('td');
	var div2 = doc.createElement('div');
	div2.style.height = '26px';
	div2.style.width = '17px';
	var td3 = doc.createElement('td');
	var div3 = doc.createElement('div');
	div3.style.height = '17px';
	div3.style.width = '17px';
	div3.style.lineHeight = '17px';
	div3.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\"img/item_is_safe.png\")';
	var td4 = doc.createElement('td');
	var div4 = doc.createElement('div');
	div4.style.height = '26px';
	div4.style.width = '15px';
	var td5 = doc.createElement('td');
	td5.style.width = '300px';
	var label1 = doc.createElement('label');
	label1.id = 'safe' + messageObj.category;
	label1.innerHTML = this.properties.program_up_to_date_singular.replace("$COUNT$", "<label id='safeCount" + messageObj.category + "'>1</label>");
	var td6 = doc.createElement('td');
	td6.style.width = '200px';
	td6.align = 'right';
	var div5 = doc.createElement('div');
	div5.style.height = '26px';
	var a1 = doc.createElement('div');
	a1.className = 'smallLabel';
	a1.style.textDecoration = 'none';
	a1.style.cursor = 'pointer';
	a1.onclick = function() {expandDetails("9" + messageObj.category, 3)};
	var label2 = doc.createElement('label');
	label2.id = 'safeBarShowAll9' + messageObj.category;
	label2.innerHTML = this.properties.more_string + " ";
	var label3 = doc.createElement('label');
	label3.id = 'label9' + messageObj.category;
	label3.style.cursor = 'pointer';
	label3.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;';
	var div6 = doc.createElement('div');
	div6.id = 'safeBarShowAllIcon9' + messageObj.category;
	div6.style.cursor = 'pointer';
	div6.style.position = 'absolute';
	div6.style.height = '13px';
	div6.style.width = '13px';
	div6.style.marginLeft = '-10px';
	div6.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\"img/item_closed.png\")';	
	var td7 = doc.createElement('td');
	td7.style.width = '115px';
	var div7 = doc.createElement('div');
	div7.style.width = '115px';

	a1.appendChild(label2);
	a1.appendChild(label3);
	a1.appendChild(div6);
	div5.appendChild(a1);
	td2.appendChild(div2);
	td3.appendChild(div3);
	td4.appendChild(div4);
	td5.appendChild(label1);
	td6.appendChild(div5)
	td7.appendChild(div7);
	tr2.appendChild(td2);
	tr2.appendChild(td3);
	tr2.appendChild(td4);
	tr2.appendChild(td5);
	tr2.appendChild(td6);
	tr2.appendChild(td7);
	tbody1.appendChild(tr2);
	table1.appendChild(tbody1);
	div1.appendChild(table1);
	td1.appendChild(div1);
	tr1.appendChild(td1);
				
	return tr1;
}

function constructSafeAppGroup(doc, solvedApp) {
	var tr1 = doc.createElement('tr');
	var td1 = doc.createElement('td');
	var div1 = doc.createElement('div');
	div1.id = '9' + messageObj.category;
	div1.style.visibility = 'hidden';
	div1.style.display = 'none';
	var table1 = doc.createElement('table');
	table1.id = 'safeItems' + messageObj.category;
	table1.border = '0';
	table1.width = '100%';
	table1.cellSpacing = '0';
	table1.cellPadding = '0';
	var tbody1 = doc.createElement('tbody');
	addSafeItem(tbody1, solvedApp);
	table1.appendChild(tbody1);	
	div1.appendChild(table1);
	td1.appendChild(div1);
	tr1.appendChild(td1);
	
	return tr1;
}

function addSafeItem(tbody, solvedApp) {
	tbody.appendChild(solvedApp);
}

function decreaseVulnItemCount(doc, count) {
	var vulnAppCount = doc.getElementById('unsafeCount' + messageObj.category);
	var cardTitle = doc.getElementById('cardTitle' + messageObj.category);

	if (parseInt(vulnAppCount.innerText) - 1 == 0) {
		if (messageObj.category == 1 || messageObj.category == 2) {
			cardTitle.innerText = this.properties.up_to_date;
		}
		else {
			cardTitle.innerText = this.properties.all_programs_up_to_date;
		}
		
		var redIcon = doc.getElementById('cardIconRed' + messageObj.category);
		var orangeIcon = doc.getElementById('cardIconOrange' + messageObj.category);
		var greenIcon = doc.getElementById('cardIconGreen' + messageObj.category);

		redIcon.style.visibility = 'hidden';
		orangeIcon.style.visibility = 'hidden';
		greenIcon.style.visibility = 'visible';
	}
	else {
		if (messageObj.category == 2) {
			//decrease the problem count first no matter what
			vulnAppCount.innerText = parseInt(vulnAppCount.innerText) - parseInt(count);
			//decrease the problem firewall count
			if (OPSWAT_FW == messageObj.applicationType) {
				messageObj.result.problemFirewallCount = parseInt(messageObj.result.problemFirewallCount) - 1;
				messageObj.result.isAllFirewallOff = false;
			}
			
			//no more problem apps, make it green!
			if (parseInt(vulnAppCount.innerText) == 0) {
					makeCardIconGreen(doc, cardTitle, properties.up_to_date);
			}
			//if the count is same, meaning only firewall problem
			else if (parseInt(vulnAppCount.innerText) == parseInt(messageObj.result.problemFirewallCount)) {
				//now we have turned on at least 1 firewall, make it green too!
				if(!messageObj.result.isAllFirewallOff) {
					makeCardIconGreen(doc, cardTitle, properties.safe_but_has_other_problem.replace("$COUNT$", "<label id='unsafeCount" + messageObj.category + "'>" + messageObj.result.problemFirewallCount + "</label>").replace("$APP$", properties.firewall));
				}
			}
			else if (parseInt(vulnAppCount.innerText) == 1) {
				cardTitle.innerHTML = properties.item_need_attention_singular.replace("$COUNT$", "<label id='unsafeCount" + messageObj.category + "'>1</label>");
			}
		}
	}
}

function makeCardIconGreen(doc, card, text) {
	var redIcon = doc.getElementById('cardIconRed' + messageObj.category);
	var orangeIcon = doc.getElementById('cardIconOrange' + messageObj.category);
	var greenIcon = doc.getElementById('cardIconGreen' + messageObj.category);

	redIcon.style.visibility = 'hidden';
	orangeIcon.style.visibility = 'hidden';
	greenIcon.style.visibility = 'visible';
	
	card.innerHTML = text;
}