

//function openDoc(filename, target, windowTitle){
function openDoc(filename){
	
	target = "_pdf";
	windowTitle = ".: Enrico Bernardo Wine Consulting :: PRESS :."
	//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
	window[strWinHandle] = window.open('',target,'menubar=0,location=0,toolbar=0,resizable=1,status=no');
		
		//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="">\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+'")',1);
	
	return false; //this cancels href of the calling link
}

function loadDoc(strWinHandle,target,filename){
	//Flash the 'Loading...' message
	var strHTML = '<html><style type="text/css">.tbl {margin: 0px; height: auto; width: auto; border: thin solid #72121F;}</style><body>';
	strHTML += '<div align="center" valign="center">';
	strHTML += '<table align="center" valign="middle" width="667" height="438" class="tbl" cellpadding="0" cellspacing="0">';
	strHTML += '<tr><td align="center" valign="middle" colspan="100">';
	strHTML += '<font face="Tahoma" color="red">Loading... Please wait.</font><br><br>';
	strHTML += '<font face="Tahoma" size="1" color="gray">If you do not have the needed software/plugin to launch the document inside the browser, please <a href="javascript:window.close();">close</a> this window.</font>';
	strHTML += '</td>';
	strHTML += '<td height="*"><img src="img/waiting.jpg" width="167" height="438"></td>';
	strHTML += '</tr></table>';
	strHTML += '</div>';
	strHTML += '</body></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(filename); //finally, set frameset's location to the document filename
		}
	}
	doc.src = filename; //onerror handler fires since image src is not actually an image
}