
//********Global Configuration*************
var server = "vegas.digi-net.com";			//Groopz Server Addres
var siteid = "4038";					//Groopz Site ID
var away_img = "1pixel.gif";				//Applet Button when Operators are "away"
var active_img = "1pixel.gif";				//Applet Button when Operators are logged in
var paging_img = "1pixel.gif";				//Applet Button when after visitor has paged Operator
var button_width = "0";				//Width in pixels of the above three images
var button_height = "0";				//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 = "builtin";					//Set 'email' to 'builtin', 'url', or 'disable'
// If 'email' is set to 'builtin' define the following variables:
var emailTo = "loll@prospector.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 = "";					//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";
}

var useJS = false;

document.write("<div style='display: none;'>");
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=GroopzApplet4.jar>");

gid = getCookie("GroopzUID");
if(gid == null) {
        //Affiliate Referrer Stuff
        var stringLoc = document.URL.indexOf('?');
        if (stringLoc != -1) {
                var affiliate = document.URL.substring(stringLoc+1, document.URL.length);
                document.cookie="affiliate="+escape(affiliate) + expString;
        }
                                                                                                                                                                                                     
        //Groopz UID stuff
        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;
                                                                                                                                                                                                     
        //Referral URL stuff
        document.cookie = "RefURL" + "=" + escape(document.referrer) + expString;
        document.cookie = "AffRefURL" + "=" + escape(document.location) + 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 + ">");

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 + "  >");
}

// 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 = everest_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 = 386,92>");

// 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 = 364,339>");

// 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 = 430,5>");

// 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 = 29,337,321,48>");

// 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 = 28,116,413,207>");


document.write(" <param name = avatar_pos value = 8000,5>");
document.write(" </APPLET>");
document.write(" <!-- End Applet Code -->");

document.write("</div>");


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]		
}

window.onfocus = broadcastOnsiteBrowsing
window.onblur = broadcastOffsiteBrowsing

var initialLoad = true;

function broadcastOnsiteBrowsing() {
	if(IEwin) {
		document.applets.groopz.broadcastOnsiteBrowsing();
	}
}

function broadcastOffsiteBrowsing() {
	if(IEwin) {
		if(initialLoad) {
			window.focus();
			initialLoad = false;
			return;
		}
		document.applets.groopz.broadcastOffsiteBrowsing();
	}
}
