// Initialize global var for new window object
// so it can be accessed by all functions on the page
var emailWindow
var printWindow
// set flag to help out with special handling for window closing
var isIE3 = (navigator.appVersion.indexOf("MSIE 3") != -1) ? true : false
// Mail This Page popup window
function mailPage() {
        var output = ""
        emailWindow = window.open("","mailPage","HEIGHT=400,WIDTH=600,resizable=no,scrollbars=no")
        // take care of Navigator 2
        if (emailWindow.opener == null) {
                emailWindow.opener = window
        }
        output += "<html><head><title>chemistry.org | Email A Friend</title><body bgcolor='#FFFFFF' TEXT='#000000'>"                                                                                                                                                                                                                   
        output += "<table border='0' cellpadding='0' cellspacing='0'>"                                                                                                                                                                                                              
        
	//output += "<tr valign='top' align='left'>"                                                                                                                                                                                                                                  
        //output += "<td colspan='4' width='100%' bgcolor='#EBF2F2'><img src='/portal/resources/ACS/System/images/c.gif' height='5' width='1' alt='spacer gif'></td>"                                                                                                                                           
        //output += "</tr>"                                                                                                                                                                                                                                                           
        //output += "<tr valign='top' align='left'>"                                                                                                                                                                                                                                  
        //output += "<td colspan='4' width='100%' bgcolor='#000000'><img src='/portal/resources/ACS/System/images/c.gif' height='1' width='1' alt='spacer gif'></td>"                                                                                                                                           
        //output += "</tr>"                                                                                                                                                                                                                                                           
        
	output += "<tr valign='top'>"
        output += "<td align='left'><img src='/portal/resources/ACS/System/images/c.gif' height='1' width='5' alt='spacer gif'></td>"
        output += "<td align='left'><img src='/portal/resources/ACS/System/images/logo.gif' height='57' width='550' alt='e-mail it!'></td>"
        output += "<td align='right'><img src='/portal/resources/ACS/System/images/c.gif' height='1' width='5' alt='spacer gif'></td>"
        output += "</tr>"
        output += "<tr valign='top'>"
        output += "<td align='left'><img src='/portal/resources/ACS/System/images/c.gif' height='1' width='5'></td>"
        output += "<td colspan='2'><br><font FACE='HELVETICA, HELV, ARIAL' SIZE='-1'>Share this chemistry.org content with others who you think will find it interesting, useful, or even amusing.</font></td>"
        output += "<td align='left'><img src='/portal/resources/ACS/System/images/c.gif' height='1' width='5'></td>"
        output += "</tr>"
        output += "<tr valign='top'>"
        output += "<td align='left'><img src='/portal/resources/ACS/System/images/c.gif' height='1' width='5'></td>"
        output += "<td colspan='2' bgcolor='#EBF2F2'>"
        output += "<form method='post' action='/portal/a/c/s/EmailAFriend'>"
        output += "<input type=hidden name=subject value=\"" + emailTitle + "\">"
        output += "<input type=hidden name=url value=\"" + document.location.href + "\">"
        output += "<input type=hidden name=body value=\"" + emailAbstract + "\">"
        output += "<table cellpadding=5 cellspacing=0 border=0 width=100%>"
        output += "<tr valign=top align=left>"
        output += "<td width=80><FONT FACE='HELVETICA, HELV, ARIAL' SIZE='-1'><b>Title:</b></FONT></td><td><FONT FACE='HELVETICA, HELV, ARIAL' SIZE='-1'><b>" + emailTitle + "</b><br>" + emailAbstract + "</FONT></td>"
        output += "</tr>"
        output += "<tr valign=top align=left>"
        output += "<td width=80><FONT FACE='HELVETICA, HELV, ARIAL' SIZE='-1'><b>Send to:</b></td><td><input type='text' size='30' name='email'></FONT></td>"
        output += "</tr>"
        output += "<tr valign=top align=left>"
        output += "<td width=80><FONT FACE='HELVETICA, HELV, ARIAL' SIZE='-1'><b>Your name:</b></td><td><input type='text' size='30' name='fromName'></FONT></td>"
        output += "</tr>"
        output += "<tr valign=top align=left>"
        output += "<td width=80><FONT FACE='HELVETICA, HELV, ARIAL' SIZE='-1'><b>Your e-mail address:</b></td><td><input type='text' size='30' name='fromEmail'></FONT></td>"
        output += "</tr>"
        output += "<tr valign=top align=left>"
        output += "<td width=80><FONT FACE='HELVETICA, HELV, ARIAL' SIZE='-1'><b>Comments:</b></td><td><textarea name='comments' rows='3' cols='50'></textarea></FONT></td>"
        output += "</tr>"
        output += "<tr valign=top align=left>"
        output += "<td width=80>&nbsp;</td><td><input type='image' border='0' name='Send' src='/portal/resources/ACS/System/images/btn-send.gif' border='0' height='19' width='47' alt='send'>"
        output += "<A HREF='javascript:void parent.close()'><img src='/portal/resources/ACS/System/images/btn-close.gif' border=0 height='19' width='103' alt='Close window'</a></td>"
        output += "</tr>"
        output += "</table>"
        output += "</td>"
        output += "<td align='left'><img src='/portal/resources/ACS/System/images/c.gif' height='1' width='5'></td>"
        output += "</tr>"
        output += "</table>"
        output += "</html>"                                                                                                                                                                   
        emailWindow.document.write(output)
        emailWindow.document.close()
}

// As of changes made 10-7-03, this is the only version of printpage() that ought to be getting called.
function printPage(docID)
{
 printPage(docID, "");
}

// Print This Page popup window
function printPage(docID, url2) {
        var output = "";
        var hostname = "www.chemistry.org";
        var port = 80;
        var url = "";

        printWindow = window.open("", "printPage", "width=800,height=600,resizable=yes,scrollbars=yes");
        
	// take care of Navigator 2
        if (printWindow.opener == null) {
                printWindow.opener = window;
        }

        output = "<html><head><title>chemistry.org | Print This Page</title></head></html>";
	printWindow.document.write(output);

        hostname = window.location.hostname;
        port = window.location.port;
        if (port != 80 && port != "" && port != 443 ) { hostname += ":" + port; }
 
        if (url2 != null && url2 != "")
         {
           url = "http://" + hostname + "/portal/a/c/s/1/printit.html?id=" + docID + "&url=" + url2;
          } else
         {
           url = "http://" + hostname + "/portal/a/c/s/1/printit.html?id=" + docID;
          }

        printWindow.location = url;

        // <body bgcolor='#FFFFFF' TEXT='#000000'>

        // output += "<html><head><title>chemistry.org | Print This Page</title>"
        // output += "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"
        // output += "<meta http-equiv='refresh' content=\"0;URL='http://" + hostname  + "/portal/a/c/s/1/printit.html?id=" + docID + "'\">"
        // output += "</head></html>"
        // printWindow.document.write(output)
        // alert (printWindow.location.href)
        // printWindow.location.reload()
        printWindow.document.close();
}                  
// close subwindow, including ugly workaround for IE3
function closeWindow() {
        if (isIE3) {
                // if window is already open, nothing appears to happen
                // but if not, the subwindow flashes momentarily (yech!)
                emailWindow = window.open("","emailwindow","HEIGHT=400,WIDTH=600")    
        }          
        if (emailWindow && !emailWindow.closed) {
                emailWindow.close()
        }          
}
// close Print Friendly window, including ugly workaround for IE3
function closePrintWindow() {
        if (isIE3) {
                // if window is already open, nothing appears to happen
                // but if not, the subwindow flashes momentarily (yech!)
                printWindow = window.open("","printWindow","HEIGHT=800,WIDTH=600")    
        }          
        if (printWindow && !printWindow.closed) {
                printWindow.close()
        }          
}                 
