function openDoc(filename,target,windowTitle){
	
	//to ensure no global variable conflict with other script
	var strWinHandle = target + "objDocWin"; 
	
	//just focus to the corresponding window if it is already open
	if (window[strWinHandle] && !window[strWinHandle].closed){
		window[strWinHandle].focus();
		return false;
	}
	
	//open blank page
	if (!window[strWinHandle] || window[strWinHandle].closed) {
		window[strWinHandle] = window.open('',target,'menubar=1,location=0,toolbar=0,resizable=1,status=0');
	}

		//change window name (target); later, target will be used as frame name
		window[strWinHandle].name = strWinHandle; 
	
	//create frameset with only 1 frame	
	var strHTML = '<html>\r\n<head>\r\n';
	//window title defaults to filename if not specified
	var winTitle = (windowTitle) ? windowTitle:filename.substring(filename.lastIndexOf("/")+1);
	strHTML += '<title>'+winTitle+'</title>\r\n';
	strHTML += '</head>\r\n';
	strHTML += '<frameset onload="window.focus()" rows="100%,*" border="0" frameborder="0" framespacing="0">\r\n';
	strHTML += '<frame name="'+target+'" src="about:blank">\r\n'; //set target as frame name
	strHTML += '</frameset>\r\n';
	strHTML += '</html>';
	window[strWinHandle].document.write(strHTML);
	window[strWinHandle].document.close();
	
	//put a little delay; Netscape6 causes a null document object when called directly
	setTimeout('loadDoc("'+strWinHandle+'","'+target+'","'+filename+'")',0);
	
	return false; //this cancels href of the calling link
}

function loadDoc(strWinHandle,target,filename){
	//Flash the 'Loading...' message
	var strHTML = '<html>\n<head>\n<title></title>\n';
	strHTML += '<style type="text/css">\nbody{margin:20px 0px 0px 0px;}\n#container{width:100%;text-align:center;font-family:Arial,Tahoma,Verdana}\n#status{font-weight:bold;font-size:14px;color:red;width:100%;}\n#alternative{font-size:11px;color:gray;width:100%;}\n</style>';
	strHTML += '</head>\n<body>';
	strHTML += '<div id="container">\n<div id="status">Loading...Please wait.</div>\n';
	//provide link to close window (for browsers with no appropriate plugin for the needed software)
	strHTML += '<div id="alternative">If you do not have the needed software/plugin to launch the document inside the browser, please <a href="#" onclick="top.close();return false;">close</a> this window.</div>\n</div>';
	strHTML += '</body>\n</html>';
	var winDocFrame = window[strWinHandle].frames[target];
	winDocFrame.document.write(strHTML); //winDocFrame.document is null in Netscape6 if called directly
	winDocFrame.document.close();
	
	//preload the document
	var doc = new Image();
	doc.onerror = function(){
		//check window if still open, the user might have closed it
		if (window[strWinHandle] && !window[strWinHandle].closed){
			winDocFrame.location.replace(this.src); //finally, set frameset's location to the document filename
		}
	}
	doc.src = filename; //onerror handler fires since image src is not actually an image
}
