/*************************************************
 Popup DocViewer 
  - Opens MS Office documents, Adobe Acrobat and Shockwave Flash files 
 in a popup window with a smart "Loading..." status message
 (c) 2003 Glenn G. Vergara
 http://www21.brinkster.com/gver/
*************************************************/

function openDoc(filename,target){

    //var bar1= createBar(300,15,'white',1,'black','blue',85,7,3,"");

	//if not IE, open link normally
	if (!document.all){
		location.href = filename;
		return;
	}

	var strWinHandle = target + "_WinOpenDoc"; 
	//to ensure no global variable conflict with other script
	
	//just focus to the corresponding window if it is already open
	if (window[strWinHandle] && !window[strWinHandle].closed){
		window[strWinHandle].focus();
		return;
	}
	
	//open blank page
	window[strWinHandle] = window.open('',target,'menubar=1,location=0,toolbar=0,resizable=1,status=0'); //add other window features here

	//create frameset with only one frame	
	var strHTML = '<html>\n<head>\n<title>Loading...Please wait.</title>\n</head>\n';
	strHTML += '<frameset onload="window.focus()">\n<frame name="docFrame" src="about:blank">\n</frameset>\n';
	strHTML += '</html>';
	window[strWinHandle].document.write(strHTML);
	window[strWinHandle].document.close();

	//Flash the 'Loading...' message
	strHTML = '<html><body>';
	strHTML += '<table width="100%" height="100%">';
	strHTML += '<tr><td align="center" valign="middle">';
	strHTML += '<font face="Arial" color="red">Loading...Please wait.</font><br><br><img src="images/anmatcat.gif"><br><br>';
	//provide link to close window (for browsers with no appropriate plugin for the needed software)
	strHTML += '<font face="Arial" size="1" color="gray">If you do not have the needed software to launch the document, please <a href="javascript:top.close()">close</a> this window.</font>';
	strHTML += '</td></tr></table>';
	strHTML += '</body></html>';
	var winDocFrame = window[strWinHandle].top.frames['docFrame'];
	winDocFrame.document.write(strHTML);
	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){	
			window[strWinHandle].document.title = filename.substring(filename.lastIndexOf("/")+1); //extract just the filename
			winDocFrame.location.replace(filename); //finally, set frame's location to the document filename
		}
	}
	doc.src = filename; //onerror handler fires since image src is not actually an image
}
