<%@ page import="java.util.*" %>
<%@ taglib uri="/tld/im.tld" prefix="im" %>
<%@ taglib uri="/tld/jx.tld" prefix="jx" %>
<%@ taglib uri="/tld/desktop.tld" prefix="dt" %>
<%@ taglib uri="/tld/desktopProviderContext.tld" prefix="dtpc" %>
<%
	if (request.getAttribute("invite") != null ||
	request.getParameter("invite") != null) { %> <jsp:forward page="invite.jsp"/> <% }

	if (request.getAttribute("display") != null ||
		request.getParameter("display") != null) { %> <jsp:forward page="IMArchiveDisplay.jsp"/> <% }
	else {

 	String launchType = request.getParameter("launch");
 	if (launchType != null) { 
 		if (launchType.equals("jnlp")) { %> <jsp:forward page="jnlpLaunch.jsp"/> <% }
 		if (launchType.equals("plugin")) { %> <jsp:forward page="pluginLaunch.jsp"/> <% }
 	}
%>
<dt:obtainChannel channel="$JSPProvider">
<script>
// Needed for window error handler
function donothing()
{
	return true;
}

function launch_<dt:getName/>(user) {
	var launchURL = "<dt:scontent/>/IMLaunch?provider=<dt:getName/>&launch=<dtpc:getStringProperty key='clientRunMode'/>&msg=Welcome&last=false";
	if (user.length > 0) {
		launchURL = launchURL + "&username=" + user;
		launchURL = launchURL + "&autoinvite=" + user;
	}
	var myURL="<%= HttpUtils.getRequestURL(request) %>";
	var urlprefix = window.location.protocol + "//" + window.location.hostname;
	if (urlprefix != myURL.substr(0, urlprefix.length)) {
		launchURL = launchURL + "&secure=yes";
		var src = request.getParameter("src_url");
		if (src != null) {
			launchURL = launchURL + "&gateway_url=" + src;
		}
	}
	// Settings for IMLaunch.jsp on IM Server defined in codebase property
    launchURL = launchURL + "&codebase=<im:getCodebase/>";
    launchURL = launchURL + "&type=<dtpc:getStringProperty key='clientRunMode'/>";
    launchURL = launchURL + "&server=<im:getIMServer/>";
    launchURL = launchURL + "&uid=<im:getUsername/>";
    launchURL = launchURL + "&locale=<dtpc:getLocaleString/>";
    launchURL = launchURL + "&token=<im:getToken/>";
 
 	// Function to detect webstart installation when launching using jnlp
	if ('<dtpc:getStringProperty key='clientRunMode'/>' == 'jnlp') {
		var webstartInstalled = false;
		// Netscape 6+ / Mozilla does not tell you whether Java Web Start
		// is installed
		var ua = window.navigator.userAgent.toLowerCase();
		if (ua.indexOf('gecko') != -1) {
			webstartInstalled=true;
		} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
			// Check for Netscape 4.x
			x = navigator.mimeTypes['application/x-java-jnlp-file'];
			if (x) webstartInstalled=true;
		} else {
			// Assume everything else is IE
			saveErrorHandler = window.onerror;
			window.onerror = donothing;
			x = new ActiveXObject('JavaWebStart.IsInstalled');
			window.onerror = null;
			if (x) webstartInstalled=true;
		}

		if ( webstartInstalled ) {
			w = window.open(launchURL, '_blank', 'width=320,height=200,hotkeys=no,status=no,resizable=no,scrollbars=yes');
			// Automatically close jnlp launch window
			w.setTimeout('window.close()', '5000');
		} else {
			window.open("<im:getCodebase/>/javaws_not_installed.html");
		}
	} else {		
		window.open(launchURL, '_blank', 'width=320,height=200,hotkeys=no,status=no,resizable=no,scrollbars=yes');
	}
}

</script>
	<jx:declare id="fontFace" type="java.lang.String"/>
	<dtpc:getStringProperty id="fontFace" key="fontFace1"/>
	<font face="<%=fontFace%>">
	<font size=-1><i>Last updated: <im:getDateTime format="{0,date,long} {0,time,short}"/></i></font>
	<p>
	<jx:set var="nogroups" value="true"/>
	<dtpc:getStringProperty id="groups" key="contactGroup"/>
	<jx:if test="$groups == ''">
		<im:getContactGroups id="groups"/>
		<% if (pageContext.getAttribute("groups") == null) { %>
			<p>
			<font color="red">Error</font>: Unable to get contact information from Instant Messaging server.
			<jx:set var="nogroups" value="false"/>
			<jx:set var="groups" value=""/>
		<% } %>
	</jx:if>
	<jx:forEach var="cg" items="$groups">
		<jx:set var="nogroups" value="false"/>
		<im:getContactGroup id="contacts" group="$cg"/>
		<% if (pageContext.getAttribute("contacts") == null) { %>
			<p>
			<font color="red">Error</font>: Unable to get contact information from Instant Messaging server.
		<% } else { %>
		<img src="<dt:scontent/>/im/images/folder_col.gif" border=0 align=absmiddle>
		<b><jx:expr value="$cg"/></b><br>
		<jx:set var="noneonline" value="true"/>
		<jx:forEach var="contact" items="$contacts">
			<im:obtainContact contact="$contact">
			<im:getContactPresence id="p"/>
			<jx:declare id="p" type="java.lang.String"/>
			<jx:set var="anchortag">
				<a href="javascript:launch_<dt:getName/>('<im:getContactUsername/>')" 
onMouseOver="window.status='Click to chat with <im:getContactName/>'; return true;"
onMouseOut="window.status=''; return true;">
			</jx:set>
			<jx:choose>
				<jx:when test="$p=='OPEN'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Online_13Padded.gif" alt="Open - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
					<jx:set var="noneonline" value="false"/>
				</jx:when>
				<jx:when test="$p=='ONLINE'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Online_13Padded.gif" alt="Online - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
					<jx:set var="noneonline" value="false"/>
				</jx:when>
				<jx:when test="$p=='IDLE'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Idle_13Padded.gif" alt="Idle - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
					<jx:set var="noneonline" value="false"/>
				</jx:when>
				<jx:when test="$p=='BUSY'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Online_13Padded.gif" alt="Busy - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
					<jx:set var="noneonline" value="false"/>
				</jx:when>

<%-- Offline States - Uncomment this if you want users to see offline contacts --
				<jx:when test="$p=='CLOSED'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Offline_13Padded.gif" alt="Offline - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
				</jx:when>
				<jx:when test="$p=='AWAY'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Away_13Padded.gif" alt="Away - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
				</jx:when>
				<jx:when test="$p=='FORWARDED'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Forwarded_13Padded.gif" alt="Offline - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
				</jx:when>
				<jx:when test="$p=='OTHER'">
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Offline_13Padded.gif" alt="Other - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
				</jx:when>
				<jx:otherwise>
					<jx:expr value="$anchortag"/>
					<img src="<dt:scontent/>/im/images/Offline_13Padded.gif" alt="<%=p%> - Click to chat" border=0 align=absmiddle></a>
					<im:getContactName/></br>
				</jx:otherwise>
--	End of offline states --%>

			</jx:choose>
		</im:obtainContact>
	</jx:forEach>
	<jx:if test="$noneonline == 'true'">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>No on-line contacts.</i><br>
	</jx:if>
	<% } %>
</jx:forEach>
<jx:if test="$nogroups == 'true'">
<p>
No contact groups defined.
</jx:if>
<p>
Start the <a href="javascript:launch_<dt:getName/>('')" 
onMouseOver="window.status='Click to start Instant Messenger'; return true;"
onMouseOut="window.status=''; return true;">
Instant Messenger</a> or click an icon to chat with a person.
</dt:obtainChannel>
<% } %>
