	
	var MESSAGE_WINDOW_WIDTH = 450;
	
	if(typeof(IMAGE_FOLDER) == 'undefined')
		var IMAGE_FOLDER = "../../imgs";
	
	//------------------- lib ---------------------
	
	//Get the size of the page
	function getPageSize(){
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY){
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		}
		else if (document.body.scrollHeight > document.body.offsetHeight){
			// all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else{
		// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight){
			// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight){
			// Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else if (document.body){
			// other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		
		// for small pages with total height less then height of the viewport
		if (yScroll < windowHeight)
			pageHeight = windowHeight;
		else
			pageHeight = yScroll;
		
		// for small pages with total width less then width of the viewport
		if (xScroll < windowWidth)
			pageWidth = windowWidth;
		else
			pageWidth = xScroll;
		
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
		
		return arrayPageSize;
	}

//------------------------ Cover layer-----------------------------
	function writeCoverLayer(){
		document.writeln("<div id='coverDiv' style='width: " + 200 + "px;height: " + 400 + "px;position:absolute;z-index:999;top:0 px;left:0 px;background-color: #FFFFFF;display:none;filter:alpha(opacity=0);opacity: .0;-moz-opacity: 0.0;'>");
		document.writeln("	&nbsp;");
		document.writeln("</div>");
		document.writeln("<div id='coverContentContainer' style='display:none;position:absolute;z-index:1000;border-color: black;'>");
		document.writeln("<table style='font-size:12px' width='" + MESSAGE_WINDOW_WIDTH + "' border='0' cellpadding='0' cellspacing='0'>");
		document.writeln("	<tr>");
		document.writeln("		<td style='width:17px;height:27px' align='left'><img src='" + IMAGE_FOLDER + "/msg/left_top.gif'></td>");
		document.writeln("		<td style='background:url(" + IMAGE_FOLDER + "/msg/middle_top.gif)'><div id='coverMessageTitle'>System Info</div></td>");
		document.writeln("		<td style='width:24px;background:url(" + IMAGE_FOLDER + "/msg/right_top.gif)'><img id='coverCloseButton' src='" + IMAGE_FOLDER + "/msg/close.jpg' border='0' onclick='hideCoverLayer()' style='cursor:pointer'></td>");
		document.writeln("	</tr>");
		document.writeln("	<tr>");
		document.writeln("		<td style='background:url(" + IMAGE_FOLDER + "/msg/left_middle.gif)'>&nbsp;</td>");
		document.writeln("		<td style='background-color:white' align='center'>");
		document.writeln("			<div id='coverContentDiv'>");
		document.writeln("			</div>");
		document.writeln("		</td>");
		document.writeln("		<td style='background:url(" + IMAGE_FOLDER + "/msg/right_middle.gif)'>");
		document.writeln("			&nbsp;");
		document.writeln("		</td>");
		document.writeln("	</tr>");
		document.writeln("	<tr>");
		document.writeln("		<td><img src='" + IMAGE_FOLDER + "/msg/left_bottom.gif'></td>");
		document.writeln("		<td style='background:url(" + IMAGE_FOLDER + "/msg/middle_bottom.gif)'>&nbsp;</td>");
		document.writeln("		<td align='right'><img src='" + IMAGE_FOLDER + "/msg/right_bottom.gif' /></td>");
		document.writeln("	</tr>");
		document.writeln("</table>");
		document.writeln("</div>");
		
		adjustMessageDivPosition();
	}
	
	/**
	 * Adjust the message div position
	 */
	function adjustMessageDivPosition(){
		var coverDiv = document.getElementById("coverDiv");
		var coverContentContainer = document.getElementById("coverContentContainer");
		
		//resize cover div
		coverDiv.style.width = document.body.scrollWidth>=document.body.clientWidth?document.body.scrollWidth:document.body.clientWidth + "px";
		coverDiv.style.height = document.body.scrollHeight>=document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight + "px";
		
		var coverContentContainerLeft = document.body.scrollLeft + (document.body.clientWidth - coverContentContainer.offsetWidth)/2;
		var coverContentContainerTop = document.body.scrollTop + (document.body.clientHeight - coverContentContainer.offsetHeight)/2;
			
		if(coverContentContainerLeft < 2)
			coverContentContainerLeft = 2;
			
		if(coverContentContainerTop < 2)
			coverContentContainerTop = 2;
		else if(coverContentContainerTop > 200)
			coverContentContainerTop = coverContentContainerTop - 100;
			
		coverContentContainer.style.left = coverContentContainerLeft;
		coverContentContainer.style.top = coverContentContainerTop;
	}
	
	/**
	 * Show cover layer
	 */
	function showCoverLayer(){
		
		document.getElementById("coverDiv").style.display="";
		document.getElementById("coverContentContainer").style.display="";
		adjustMessageDivPosition();
		hideSelects("hidden");
	}
	
	function hideSelects(visibility){
		selects = document.getElementsByTagName('select');
		for(var n = 0; n < selects.length; n++) {
			selects[n].style.visibility = visibility;
		}
	}
	
	/**
	 * Hide the cover layer
	 */
	function hideCoverLayer(){
		document.getElementById("coverDiv").style.display="none";
		document.getElementById("coverContentContainer").style.display="none";
		hideSelects("visible");
	}
	
	/**
	 * Change the message title
	 */
	function changeMessageTitle(title){
		document.getElementById("coverMessageTitle").innerHTML = title;
	}
	
	/**
	 * Change the message content
	 */
	function changeMessageContent(content){
		document.getElementById("coverContentDiv").innerHTML = content;
	}
	
	function showMessage(title, content){
		changeMessageTitle(title);
		
		var innerContent = "";
		
		innerContent += "<div align='center' style='color:blue;padding:10'>" + "<img src='" + IMAGE_FOLDER + "/processing.gif'> <br>" + content + "</div>"
		
		changeMessageContent(innerContent);
		
		document.getElementById("coverCloseButton").style.visibility = "hidden";
		
		showCoverLayer();
	}
	//------------------------ Cover layer-----------------------------
	
	//------------------------ message type ---------------------------
	//????
	function loadingMessage(){
		showMessage("System Message","Loading...");
	}
	
	function processingMessage(){
		showMessage("System Message","Processing...");
	}
	
	//????
	function formatingMessage(){
		showMessage("System Message","Processing...");
	}
	//------------------------ message type ---------------------------
	
	//------------------------ ???? --------------------------------
	function showErrorReport(email){
		changeMessageTitle('<span style="font-size:13px;color:red">Error Report</span>');
		
		var innerContent = new Array();
		
		innerContent[innerContent.length] = '<div align="center" style="color:blue;padding:10px">';
		innerContent[innerContent.length] = '<table class="normalFont" style="width:420px" cellpadding="0" cellspacing="0">';
		innerContent[innerContent.length] = '	<tr>';
		innerContent[innerContent.length] = '		<td>';
		innerContent[innerContent.length] = '			Email';
		innerContent[innerContent.length] = '		</td>';
		innerContent[innerContent.length] = '		<td>';
		innerContent[innerContent.length] = '			<input id="feedbackEmail" class="thin_border_ele" type="text" style="width:300px" value="' + (email==null?'':email) + '">';
		innerContent[innerContent.length] = '		</td>';
		innerContent[innerContent.length] = '	</tr>';
		if(document.getElementById('sysExpStackTrack')){
			innerContent[innerContent.length] = '	<tr>';
			innerContent[innerContent.length] = '		<td nowrap="nowrap">';
			innerContent[innerContent.length] = '			Error Message';
			innerContent[innerContent.length] = '		</td>';
			innerContent[innerContent.length] = '		<td>';
			innerContent[innerContent.length] = '			<textarea readonly id="errorMessage" class="thin_border_ele" style="width:300px;height:60px;color:gray">' + document.getElementById('sysExpStackTrack').value + '</textarea>';
			innerContent[innerContent.length] = '		</td>';
			innerContent[innerContent.length] = '	</tr>';
		}
		innerContent[innerContent.length] = '	<tr>';
		innerContent[innerContent.length] = '		<td nowrap="nowrap">';
		innerContent[innerContent.length] = '			Error Description';
		innerContent[innerContent.length] = '		</td>';
		innerContent[innerContent.length] = '		<td>';
		innerContent[innerContent.length] = '			<textarea id="errorDesc" class="thin_border_ele" style="width:300px;height:100px"></textarea>';
		innerContent[innerContent.length] = '		</td>';
		innerContent[innerContent.length] = '	</tr>';
		innerContent[innerContent.length] = '	<tr>';
		innerContent[innerContent.length] = '		<td colspan="2">';
		innerContent[innerContent.length] = '			<font color="blue">Send your error description to us. Please fill in the Email address carefully.</font>';
		innerContent[innerContent.length] = '		</td>';
		innerContent[innerContent.length] = '	</tr>';
		innerContent[innerContent.length] = '	<tr>';
		innerContent[innerContent.length] = '		<td colspan="2" align="center">';
		innerContent[innerContent.length] = '			<input class="but_2_80" type="button" value="  Submit " onclick="submitErrorReport()">';
		innerContent[innerContent.length] = '		</td>';
		innerContent[innerContent.length] = '	</tr>';
		innerContent[innerContent.length] = '</table>';
		innerContent[innerContent.length] = '</div>';
		
		changeMessageContent(innerContent.join(''));
		
		document.getElementById("coverCloseButton").style.visibility = "visible";
		
		showCoverLayer();
		
		document.getElementById("errorDesc").focus();
	}
	
	function submitErrorReport(){
		window.top.frames["pageheader"].reportError(document.getElementById("feedbackEmail").value, 
			document.getElementById("errorMessage")?document.getElementById("errorMessage").value:"", 
			document.getElementById("errorDesc").value,
			window.location.href);
	}
	
	
	//Write cover layer
	writeCoverLayer();