
//********Global Configuration*************
var server = "oldportorange.digi-net.com";			//Groopz Server Addres
var siteid = "1381";											//Groopz Site ID
var away_img = "groopz-away.gif";					//Applet Button when Operators are "away"
var active_img = "groopz-active.gif";			//Applet Button when Operators are logged in
var paging_img = "groopz-paging.gif";			//Applet Button when after visitor has paged Operator
var button_width = "152";									//Width in pixels of the above three images
var button_height = "63";									//Height in pixels of the above three images
var persist = "true"; 										//Set to true to enable applet persistance
var tunneling = "true"; 									//Set to true to enable HTTP Tunneling
var group = "";														//Enter "Group" value here
//Email Stuff
var email = "disable";										// Set 'email' to 'builtin', 'url', or 'disable'
// If 'email' is set to 'builtin' define the following variables:
var emailTo = "email@yourserver.com";			//Email address that emails should be sent to
var email_img = "email.gif";							//Image used in email pop-up window
var emailBG = "217,217,217";							//Background color of email pop-up window
var emailFG = "0,0,0";										//Text color of email pop-up window
// If 'email' is set to 'url' define the following variables:
var emailURL = "http://www.yourserver.com/email";	//URL of Email page
var emailTarget = "_new";									//"_new" for new window, "_self" for same window
//********Global Configuration*************

isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IEwin = ((document.all)&&(navigator.appVersion.indexOf("MSIE")!=-1) && !isMac) ? true : false;
NS = (navigator.appName.indexOf("Netscape")!=-1) ? true : false;
Mozilla = (navigator.userAgent.indexOf("Mozilla")!=-1) ? true : false;

if(isMac==true) {
	var tunneling = "false";
}

NS6_7 = Mozilla && !IEwin

var useJS = isMac==false;
var useJS = NS6_7==false;

Imagenames = new Array(3);
Imagenames[0] = "http://" + server + "/groopz2/Resources/" + siteid +"/" + away_img;
Imagenames[1] = "http://" + server + "/groopz2/Resources/" + siteid +"/" + active_img;
Imagenames[2] = "http://" + server + "/groopz2/Resources/" + siteid +"/" + paging_img;
for(i=0; i<Imagenames.length; i++) {
	var pl = new Image();
	pl.src = Imagenames[i];
}

if (useJS==true) {
	document.write('<A HREF ="" onClick="_GroopzButton_click(); return false;" ');
	document.write('onMouseOver=\'status = \"Click Here for Live Assistance\"; return true\' onMouseOut=\'status = defaultStatus\' >');
	document.write('<IMG name = "_GroopzIm" border=0 SRC="' + Imagenames[0] +'">');
	document.write('</A>')
	setTimeout ("_GroopzCheck ()", 1000)
}

document.write("<APPLET NAME=\"groopz\" CODEBASE=http://" + server + "/groopz2/");
document.write(" CODE=com.diginet.groopz.suite.ec.applet.GroopzApplet.class ");
document.write(" WIDTH=");
document.write((useJS == false) ? button_width + " " :"0 ");
document.write(" HEIGHT=");
document.write((useJS == false) ? button_height + " " :"0 ");
document.write(" MAYSCRIPT ");
document.write(" ARCHIVE=GroopzApplet.jar>");

gid = getCookie("GroopzUID");
if(gid == null) {
	gid = Math.random();
	var dat = new Date();
	dat.setTime(dat.getTime() + 365*24*60*60*1000); 
	var expString = "; expires=" + dat.toGMTString();
	document.cookie = "GroopzUID" + "=" + escape(gid) + expString; 
}

//document.write(" <param name = UserName value = 'MyUser'>");
document.write(" <param name = GroopzUID value = "+gid+">");

// The name of the server to connect to.  This must be the same machine
// that the applet is served from.  For http tunneling, this should be
// the full URL to the HttpTunnelingServlet
document.write(" <param name = server value = " + server + ">");	

// The name of the site to connect to.  In the absence of this
// paramter, the default is 1000
document.write(" <param name = site value = " + siteid +">");

// The protocol to use by default (tcp, http, udp)
document.write(" <param name = network value = tcp>");
//http tunneling is off by default
document.write(" <param name = allowhttp value = " + tunneling + ">");

//document.write(" <param name = persist value = " + persist + ">");
document.write(" <param name = persist value = true>");

if(group.length != 0)
	document.write(" <param name = Groups value = " + group + ">");

// The title of the page shown in Groopz Operator.  This value is set to the 
// title of the web page it came from.
document.write(" <param name = title value = '"+document.title+"'>");

// The referrer 
document.write(" <param name = referrer value = '"+document.referrer+"'>");

//e-mail stuff

if(email=="builtin") {
	document.write(" <param name = emailTo value = " + emailTo + " >");
	document.write(" <param name = email_img value = " + email_img + "  >");
	document.write(" <param name = emailBG value = " + emailBG + " >");
	document.write(" <param name = emailFG value = " + emailFG + " >");
}

if(email=="url") {
	document.write(" <param name = emailURL value = " + emailURL + " >");
	document.write(" <param name = emailTarget value = " + emailTarget + "  >");
}

document.write(" <param name = avatar_pos value = 5000,0>");

// The URL (relative to the Codebase above) of the image to use as the
// skin of the applet's Chat Dialog
document.write(" <param name = skin_img value = groopz-skin.gif>");

// The URL (relative to the Codebase above) of the image to use as the
// face of the applet when operators are available for calls
document.write(" <param name = active_img value = " + active_img + ">");

// The URL (relative to the Codebase above) of the image to use as the
// face of the applet when no operators are available.
document.write(" <param name = away_img value = " + away_img + ">");

// The URL (relative to the Codebase above) of the image to use as the
// face of the applet when the user clicks and requests help
document.write(" <param name = paging_img value = " + paging_img + ">");

// The URL (relative to the Codebase above) of the image to use as the
// send button in the "up" state (not pressed) (this button is on the Chat Dialog)
document.write(" <param name = sendup_img value = send-up.gif>");

// The URL (relative to the Codebase above) of the image to use as the
// send button in the "down" state (pressed) (this button is on the Chat Dialog)
document.write(" <param name = senddown_img value = send-down.gif>");

// The URL (relative to the Codebase above) of the image to use as the
// close button in the "up" state (not pressed) (this button is on the Chat Dialog)
document.write(" <param name = closeup_img value = close-up.gif>");

// The URL (relative to the Codebase above) of the image to use as the
// close button in the "down" state (pressed) (this button is on the Chat Dialog)
document.write(" <param name = closedown_img value = close-down.gif>");

// The location where the Operator's name should appear.
// This position is the top left corner of the name specified in pixels relative to the top left corner of the Chat Window
// The x and y coordinates are separated by a comma, so the point (100, 95) would be written as value = 100,95
document.write(" <param name = name_pos value = 143,36>");

// The location where the Send button should appear.
// This position is the top left corner specified in pixels relative to the top left corner of the Chat Window
// The x and y coordinates are separated by a comma, so the point (100, 95) would be written as value = 100,95
document.write(" <param name = send_pos value = 308,253>");

// The location where the Close button should appear.
// This position is the top left corner specified in pixels relative to the top left corner of the Chat Window
// The x and y coordinates are separated by a comma, so the point (100, 95) would be written as value = 100,95
document.write(" <param name = close_pos value = 308,285>");

// The location where the message input area should appear.
// This position is the top left corner specified in pixels relative to the top left corner of the Chat Window
// followed by the width and height of the input area.
// The values are separated by a comma, so to put the area at the point (10, 15) with a width and height of  200 X 100
// the value should be written as value = 10,15,200,100
document.write(" <param name = input_pos value = 8,253,293,61>");

// The location where the chat messages should appear.
// This position is the top left corner specified in pixels relative to the top left corner of the Chat Window
// followed by the width and height of the input area.
// The values are separated by a comma, so to put the area at the point (10, 15) with a width and height of  200 X 100
// the value should be written as value = 10,15,200,100
document.write(" <param name = chat_pos value = 8,60,381,185>");

document.write(" </APPLET>");
document.write(" <!-- End Applet Code -->");

function getCookie(name) {
	var result = null; 
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName); 
	var endOfCookie; 
	if (startOfCookie != -1) {
		startOfCookie += searchName.length; 
		endOfCookie = myCookie.indexOf(";", startOfCookie); 
		result = unescape(myCookie.substring(startOfCookie, endOfCookie)); 
	}
	return result; 
}

var checkCounter = 0;
var paging = false;
var loaded = false;
window.onerror = trapError;

function trapError(sMsg, sUrl, sLine) {
	if (sMsg=="Object doesn't support this property or method") {
		return true;
	}
	else return false;
}

function _GroopzCheck(status)
{
	if (loaded == false) {		
		checkCounter++
		if (checkCounter<10) 
			setTimeout ("_GroopzCheck ()", 1000)		
	}
	if (document.applets.groopz.isConnected()) {		
		if (paging == true) paging = document.applets.groopz.isPaging();
		if (document.applets.groopz.isOperatorAvailable()) {
			if (paging == true) _GroopzButton_swap(2)
			else _GroopzButton_swap(1)
		} else _GroopzButton_swap(0)
		if (loaded == true) setTimeout ("_GroopzCheck ()", 5000)
		loaded = true;
		
	}	
}	

function _GroopzButton_click()
{
	if (document.applets.groopz.isOperatorAvailable() && paging == false)
	{
		_GroopzButton_swap(2)
		paging = true;
		document.applets.groopz.helpRequest()
	} else if (document.applets.groopz.isOperatorAvailable() == false) {
		if (email=="builtin" && document.applets.groopz.isConnected()) {		
			document.applets.groopz.sendEmail()
		} 
		else if (email=="builtin" && !document.applets.groopz.isConnected()) {
			window.open("mailto:"+emailTo);
		}
		else if (email=="url") {
			window.open(emailURL, emailTarget);
		} 
	}
}

function _GroopzButton_swap(index)
{	
	if (document.layers)
		document["_GroopzIm"].src = Imagenames[index]
	else if (document.images)
		document.images["_GroopzIm"].src = Imagenames[index]		
}
