
// Live Help Server Version: 3.26 Rev. 1

// stardevelop.com Live Help International Copyright 2003
// JavaScript Check Status Functions

var server = 'http://www.phdrinkingwater.com';
var request = '';
var domain = '.phdrinkingwater.com';

// FMP EDITS - add source, theme and offlinebutton toggle
var FMPRefresh = 60000;
var FMPsource = '';
var FMPtheme  = '';
var FMPoffbut = '';
var FMPdep	  = 'eric';
var FMPBackoffice = '';
var FMPOfflineURL = '';

function currentTime() {
	var date = new (Date)();
	return date.getTime();
}

var ns6 = (!document.all &&  _proxy_jslib_handle(document, 'getElementById', '', 0, 0)); 
var ie4 = (document.all);
var ns4 = (document.layers);

var initiateOpen = 0;
var initiateLoaded = 0;
var infoOpen = 0;
var infoImageLoaded = 0;
var countTracker = 0;
var idleTimeout = 90 * 60 * 1000;
var timeStart = currentTime();
var timeElapsed; var timerLiveHelpInfo; var timerClosingLiveHelpInfo;

var trackingInitalized = 0;
var topMargin = 10;
var leftMargin = 10;
var hAlign = "left";
var vAlign = "bottom";
var layerHeight = 238;
var layerWidth = 377;

var browserWidth = 0;
var browserHeight = 0;

var windowWidth = 625;
var windowHeight = 425;
var windowLeft = (screen.width - windowWidth) / 2;
var windowTop = (screen.height - windowHeight) / 2;
var size = 'height=' + windowHeight + ',width=' + windowWidth + ',top=' + windowTop + ',left=' + windowLeft;

var trackerStatus = new (Image);
var time = currentTime();
var title = document.title;
var localtime = new (Date)().toLocaleString(); // Only insert the timezone

var referrer;
if ( _proxy_jslib_handle(document, 'referrer', '', 0, 0).indexOf('') >= 0) {
	 referrer= _proxy_jslib_assign_rval('', 'referrer', '=', ( ''), referrer);
} else {
	 referrer= _proxy_jslib_assign_rval('', 'referrer', '=', (  _proxy_jslib_handle(document, 'referrer', '', 0, 0)), referrer);
}


// stardevelop.com Live Help International Copyright 2003
// JavaScript AJAX Tracking Functions

var TrackingTimer; var InitiateChatTimer; var LiveHelpXMLHTTP = null;
var currentStatus = '';
var statusImagesLiveHelp = new (Array)();

function urlencode(str) {
  var str =  _proxy_jslib_handle(escape(str), 'replace', '', 1, 0)(/[+]/g, '%2B');
  str =  _proxy_jslib_handle(str, 'replace', '', 1, 0)(/[\/]/g, '%2F');
  return str;
}

function checkXMLHTTP() {
	obj = null;
	if (window.XMLHttpRequest) {
		obj = new (XMLHttpRequest)();
	}
	else if (window.ActiveXObject) {
		obj = new (ActiveXObject)("Microsoft.XMLHTTP")
 if (!obj) {
			try {
				obj = new (ActiveXObject)("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					obj = new (ActiveXObject)("Microsoft.XMLHTTP");
				} catch(e) {
					obj = null;
				}
			}
		}
    }
	return obj;
}

LiveHelpXMLHTTP = checkXMLHTTP();

function LoadXMLTracking(initiateResult) {

	LiveHelpXMLHTTP = checkXMLHTTP();
	
	// Run the XML query
	if (LiveHelpXMLHTTP.readyState != 0) {
		LiveHelpXMLHTTP.abort();
	}
	
	if (typeof initiateResult == 'undefined') { initiateResult = '' }
	
	var RequestData = 'JS=1&DEPARTMENT=eric&INITIATE=' + initiateResult;
	if (trackingInitalized == 0) {
		RequestData = 'JS=1&TITLE=' + escape(title) + '&URL=' + escape( _proxy_jslib_handle(document, 'location', '', 0, 0)) + '&REFERRER=' + escape( _proxy_jslib_handle(null, 'referrer', referrer, 0, 0)) + '&WIDTH=' + screen.width + '&HEIGHT=' + screen.height + '&COOKIE=&DEPARTMENT=eric&INITIATE=' + initiateResult;
		trackingInitalized = 1;
	}
	
	//FMP EDIT - add FMP variables to RequestData
	RequestData = RequestData + '&s=' + FMPsource + '&theme=' + FMPtheme + '&OFFLINEBUTTON=' + FMPoffbut;

	try {
		 _proxy_jslib_handle(LiveHelpXMLHTTP, 'open', '', 1, 0)('POST', 'http://www.phdrinkingwater.com/livehelp/include/status.php', true);
	} catch(e) {
		trackingInitalized = 0;
		LiveHelpXMLHTTP = null;
		OnlineTracker(); return;
	}

	LiveHelpXMLHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	LiveHelpXMLHTTP.setRequestHeader("Content-length", RequestData.length);
	LiveHelpXMLHTTP.setRequestHeader("Connection", "close");
		
	LiveHelpXMLHTTP.onreadystatechange = function() {
		if (LiveHelpXMLHTTP.readyState == 4) {
			// Process response as JavaScript
			if (LiveHelpXMLHTTP.status == 200) {
				eval(_proxy_jslib_proxify_js((LiveHelpXMLHTTP.responseText), 0, 0) );
			}
		}
	};

	LiveHelpXMLHTTP.send(RequestData);

	// If the Site Visitor has been Idle for under the given idleTimeout then run the tracker
	timeElapsed = time - timeStart;
	if (timeElapsed < idleTimeout) {
		window.clearTimeout(TrackingTimer);
		TrackingTimer =  _proxy_jslib_handle(window, 'setTimeout', '', 1, 0)('LoadXMLTracking();', FMPRefresh);
	}

}

function changeStatus(status) {

	var statusImage = new (Image);
	switch (status) {
		case 'Online':
			statusImageFile = '/images/livehelp_online2.gif';
			break;
		case 'BRB':
			statusImageFile = '/images/livehelp_brb2.gif';
			break;
		case 'Away':
			statusImageFile = '/images/livehelp_away2.gif';
			break;
		default:
			statusImageFile = '/images/livehelp_offline2.gif';
			break;
	}
	
	var time = currentTime();
	if (currentStatus != '' && currentStatus != status) {
	
		for (i = 0; i < statusImagesLiveHelp.length; i++) {
		
			// Determine if there is an alternate image path find IMAGES= variable within statusImagesLiveHelp[i].src
			var getImageLocation =  _proxy_jslib_handle( _proxy_jslib_handle(statusImagesLiveHelp, (i), 0, 0), 'src', '', 0, 0).indexOf('IMAGES=');
			var getDepartment =  _proxy_jslib_handle( _proxy_jslib_handle(statusImagesLiveHelp, (i), 0, 0), 'src', '', 0, 0).indexOf('DEPARTMENT=');
			
			 _proxy_jslib_assign('', statusImage, 'src', '=', ( statusImageFile));
			if (getImageLocation != -1) {
				// Load the IMAGES path into a variable
				var statusImageDirectory =  _proxy_jslib_handle( _proxy_jslib_handle(statusImagesLiveHelp, (i), 0, 0), 'src', '', 0, 0).substring(getImageLocation + 7);
				if (getDepartment == -1) {
					var filenamePos = statusImageFile.lastIndexOf('/');
					if (filenamePos != -1) {
						 _proxy_jslib_assign('', statusImage, 'src', '=', ( statusImageDirectory + statusImageFile.substring(filenamePos + 1) + '?IMAGES=' + statusImageDirectory));
					}
				}
			}
		
			if (getDepartment != -1) {
				// Load the DEPARTMENT path into a variable
				var department =  _proxy_jslib_handle( _proxy_jslib_handle(statusImagesLiveHelp, (i), 0, 0), 'src', '', 0, 0).substring(getDepartment + 11);
				var endRequestPos = department.lastIndexOf('&');
				if (endRequestPos != -1) {
					//FMP EDIT - Remove previous method, replace with our method
					//statusImage.src = 'http://www.phdrinkingwater.com/livehelp/include/status.php?DEPARTMENT=' + department.substring(0, endRequestPos) + '&IMAGES=' + statusImageDirectory;
					 _proxy_jslib_assign('', statusImage, 'src', '=', ( 'http://www.phdrinkingwater.com/livehelp/include/status.php?DEPARTMENT=' + FMPdep + '&IMAGES=' + statusImageDirectory));
				}
			}
		
			 _proxy_jslib_handle(statusImagesLiveHelp, (i), 0, 0).onload = null;
			swapImage( _proxy_jslib_handle(statusImagesLiveHelp, (i), 0, 0).name, '',  _proxy_jslib_handle(statusImage, 'src', '', 0, 0), 1);
		}
	}

	currentStatus = status;
	
	if (status == 'Offline' && trackingInitalized == 0) {
			// Do not continously request XML if Offline
			window.clearTimeout(TrackingTimer);
	}
}

function findObj(n, d) {
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&& _proxy_jslib_handle( _proxy_jslib_handle(null, 'parent', parent, 0, 0), 'frames', '', 0, 0).length) {
		d= _proxy_jslib_handle( _proxy_jslib_handle( _proxy_jslib_handle(null, 'parent', parent, 0, 0), 'frames', '', 0, 0), (n.substring(p+1)), 0, 0).document; n=n.substring(0,p);}
		if(!(x= _proxy_jslib_handle(d, (n), 0, 0))&&d.all) x= _proxy_jslib_handle(d.all, (n), 0, 0); for (i=0;!x&&i<d.forms.length;i++) x= _proxy_jslib_handle(d.forms[(i)], (n), 0, 0);
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[(i)].document);
		if(!x &&  _proxy_jslib_handle(d, 'getElementById', '', 0, 0)) x= _proxy_jslib_handle(d, 'getElementById', '', 1, 0)(n); return x;
}

function swapImage() {
	var i,j=0,x,a=swapImage.arguments; document.sr=new (Array); for(i=0;i<(a.length-2);i+=3)
		if ((x=findObj( _proxy_jslib_handle(a, (i), 0, 0)))!=null){ _proxy_jslib_assign('', document.sr, (j++), '=', (x)); if(!x.oSrc) x.oSrc= _proxy_jslib_handle(x, 'src', '', 0, 0);  _proxy_jslib_assign('', x, 'src', '=', ( _proxy_jslib_handle(a, (i+2), 0, 0)));}
}

// stardevelop.com Live Help International Copyright 2003
// JavaScript Initiate Chat Layer Functions

function toggle(object) {
  if ( _proxy_jslib_handle(document, 'getElementById', '', 0, 0)) {
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(object).style.visibility == 'visible')
       _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(object).style.visibility = 'hidden';
    else
       _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(object).style.visibility = 'visible';
  }
  else if (document.layers && document.layers[(object)] != null) {
    if (document.layers[(object)].visibility == 'visible' || document.layers[(object)].visibility == 'show' )
      document.layers[(object)].visibility = 'hidden';
    else
      document.layers[(object)].visibility = 'visible';
  }
  else if (document.all) {
    if ( _proxy_jslib_handle(document.all, (object), 0, 0).style.visibility == 'visible')
       _proxy_jslib_handle(document.all, (object), 0, 0).style.visibility = 'hidden';
    else
       _proxy_jslib_handle(document.all, (object), 0, 0).style.visibility = 'visible';
  }
  return false;
}

function floatRefresh() {
	window.clearTimeout(InitiateChatTimer);
	window.clearTimeout(TrackingTimer);
	if (countTracker == FMPRefresh) {
		//if (LiveHelpXMLHTTP != null) {
			//LoadXMLTracking();
		//} else {
			OnlineTracker();
		//}
		countTracker = 0;
	}
	else {
		countTracker = countTracker + 10;
	}
	InitiateChatTimer =  _proxy_jslib_handle(window, 'setTimeout', '', 1, 0)('mainPositions(); floatRefresh();', 10);
}

function mainPositions() { 

	if ( _proxy_jslib_handle(document, 'getElementById', '', 0, 0)) {
		this.currentY = parseInt( _proxy_jslib_handle( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('floatLayer').style, 'top', '', 0, 0));
		this.currentX = parseInt( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('floatLayer').style.left); 
	} else if (document.all) {
		this.currentY = parseInt( _proxy_jslib_handle(document.all, ('floatLayer'), 0, 0).style.pixelTop);
		this.currentX = parseInt( _proxy_jslib_handle(document.all, ('floatLayer'), 0, 0).style.pixelLeft);
	} else if (document.layers && document.layers[(object)] != null) {
		this.currentY = parseInt( _proxy_jslib_handle(document.layers[('floatLayer')], 'top', '', 0, 0));
		this.currentX = parseInt(document.layers[('floatLayer')].left); 
	}

	if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
		this.scrollTop = document.documentElement.scrollTop;
		this.scrollLeft = document.documentElement.scrollLeft;
	} else {
		this.scrollTop =  _proxy_jslib_handle(document, 'body', '', 0, 0).scrollTop;
		this.scrollLeft =  _proxy_jslib_handle(document, 'body', '', 0, 0).scrollLeft;
	}
	
	var newTargetY = this.scrollTop + topMargin;
	var newTargetX = this.scrollLeft + leftMargin;
	if ( this.currentY != newTargetY || this.currentX != newTargetX) { 
		if (this.targetY != newTargetY || this.targetX != newTargetX) { 
			this.targetY = newTargetY; this.targetX = newTargetX;
			floatStart();
		}
		animate(); 
	}
} 

function floatStart() { 
	var now = new (Date)();
	this.Y = this.targetY - this.currentY; this.X = this.targetX - this.currentX;
	
	this.C = Math.PI / 2400; 
	this.D = now.getTime();
	if (Math.abs(this.Y) > this.browserHeight) { 
		this.E = this.Y > 0 ? this.targetY - this.browserHeight : this.targetY + this.browserHeight;
		this.Y = this.Y > 0 ? this.browserHeight : -this.browserHeight;
	} else { 
		this.E = this.currentY;
	} 
	if (Math.abs(this.X) > this.browserWidth) { 
		this.F = this.X > 0 ? this.targetX - this.browserWidth : this.targetX + this.browserWidth;
		this.X = this.X > 0 ? this.browserWidth : -this.browserWidth;
	} else { 
		this.F = this.currentX;
	} 
} 

function animate() { 
	var now = new (Date)();
	var newY = this.Y * Math.sin( this.C * ( now.getTime() - this.D ) ) + this.E;
	var newX = this.X * Math.sin( this.C * ( now.getTime() - this.D ) ) + this.F;
	newY = Math.round(newY);
	newX = Math.round(newX);

	if ((this.Y > 0 && newY > this.currentY) || (this.Y < 0 && newY < this.currentY)) { 
		if ( _proxy_jslib_handle(document, 'getElementById', '', 0, 0)) {  _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('floatLayer').style, 'top', '=', ( newY + 'px')); }
		else if (document.all) {  _proxy_jslib_handle(document.all, ('floatLayer'), 0, 0).style.pixelTop = newY + 'px'; }
		else if (document.layers && document.layers[(object)] != null) {  _proxy_jslib_assign('', document.layers[('floatLayer')], 'top', '=', ( newY + 'px')); }
	}
	if ((this.X > 0 && newX > this.currentX) || (this.X < 0 && newX < this.currentX)) { 
		if ( _proxy_jslib_handle(document, 'getElementById', '', 0, 0)) {  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('floatLayer').style.left = newX + 'px'; }
		else if (document.all) {  _proxy_jslib_handle(document.all, ('floatLayer'), 0, 0).style.pixelLeft = newX + 'px'; }
		else if (document.layers && document.layers[(object)] != null) { document.layers[('floatLayer')].left = newX + 'px'; }
	}
}

function resetLayerLocation() {

	var width = 0; var height = 0;

	if(typeof(window.innerWidth) == 'number') {
		width = window.innerWidth;
		height = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	} else if( _proxy_jslib_handle(document, 'body', '', 0, 0) && ( _proxy_jslib_handle(document, 'body', '', 0, 0).clientWidth ||  _proxy_jslib_handle(document, 'body', '', 0, 0).clientHeight)) {
		width =  _proxy_jslib_handle(document, 'body', '', 0, 0).clientWidth;
		height =  _proxy_jslib_handle(document, 'body', '', 0, 0).clientHeight;
	}

	leftMargin = 10; topMargin = 10;
	browserWidth = width; browserHeight = height;
	
	if (hAlign == 'right') { leftMargin = width - leftMargin - layerWidth - 20; }
	else if (hAlign == 'center') { leftMargin = Math.round((width - 20) / 2) - Math.round(layerWidth / 2); }

	if (vAlign == 'bottom') { topMargin = height - topMargin - layerHeight; }
	else if (vAlign == 'center') { topMargin = Math.round((height - 20) / 2) - Math.round(layerHeight / 2); }

}

function stopLayer() {
	window.clearTimeout(InitiateChatTimer);	

	if (initiateOpen == 1) {
		toggle('floatLayer');
	}
	initiateLoaded = 0;
}

function acceptInitiateChat() {
	if (LiveHelpXMLHTTP != null) {
		LoadXMLTracking('Accepted');
	} else {
		OnlineTracker('Accepted');
	}
	stopLayer();
}

function declineInitiateChat() {
	if (LiveHelpXMLHTTP != null) {
		LoadXMLTracking('Declined');
	} else {
		OnlineTracker('Declined');
	}
	stopLayer();
}

function resizeEvent(e) {
	if (!e) e = window.event;
	resetLayerLocation();
	return true;	
}

window.onresize = resizeEvent;


function checkInitiate(e) {
	// Check if site visitor has an Initiate Chat Request Pending for display...
	if (!e) var e = window.event;
	var imageWidth = this.width; var imageHeight = this.height;
	
	if (imageWidth == 2 && imageHeight == 2) {
		displayInitiateChat();
	}
	return true;
}

function displayInitiateChat() {

	if (initiateOpen == 0 || initiateLoaded == 1) {
	
		resetLayerLocation();
		
		if ( _proxy_jslib_handle(document, 'getElementById', '', 0, 0)) {
			 _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('floatLayer').style, 'top', '=', ( topMargin + 'px'));  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('floatLayer').style.left = leftMargin + 'px';
		} else if (document.all) {
			 _proxy_jslib_handle(document.all, ('floatLayer'), 0, 0).style.pixelTop = topMargin + 'px';  _proxy_jslib_handle(document.all, ('floatLayer'), 0, 0).style.pixelLeft = leftMargin + 'px';
		} else if (document.layers) {
			 _proxy_jslib_assign('', document.layers[('floatLayer')], 'top', '=', ( topMargin + 'px'));  _proxy_jslib_handle(layers, ('floatLayer'), 0, 0).left = leftMargin + 'px';
		}
		
		var openingTrackerStatus = new (Image);
		
		 _proxy_jslib_assign('', openingTrackerStatus, 'src', '=', ( 'http://www.phdrinkingwater.com/livehelp/include/tracker.php?INITIATE=Opened'));
	
		if ( _proxy_jslib_handle(document, 'getElementById', '', 0, 0)) {  _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('floatLayer'), 'location', '=', ( 'http://www.phdrinkingwater.com/livehelp/include/tracker.php?INITIATE=Opened')); }
		else if (document.layers) {  _proxy_jslib_assign('', document.layers[('floatLayer')], 'location', '=', ( 'http://www.phdrinkingwater.com/livehelp/include/tracker.php?INITIATE=Opened')); }
		else if (document.all) {  _proxy_jslib_assign('',  _proxy_jslib_handle(document.all, ('floatLayer'), 0, 0), 'location', '=', ( 'http://www.phdrinkingwater.com/livehelp/include/tracker.php?INITIATE=Opened')); }
	
		floatRefresh();

		toggle('floatLayer');
		initiateOpen = 1;
	}
}

var LiveHelpWindow = '';
var OfflineEmail = 0;
var HiddenStatus = 0;

function openLiveHelp(department) {

	HiddenStatus = 1;
	if ((OfflineEmail == 0 && currentStatus != 'Online') || (OfflineEmail == 0 && currentStatus == '' && HiddenStatus == 1)) {
		return;
	} else {
		if (!LiveHelpWindow.closed &&  _proxy_jslib_handle(LiveHelpWindow, 'location', '', 0, 0)) {
			if (LiveHelpWindow.focus) {
				LiveHelpWindow.focus();
			}
			return;
		} else {
			if (FMPOfflineURL != '' && currentStatus != 'Online')
				LiveHelpWindow =  _proxy_jslib_assign('',  _proxy_jslib_handle(window, 'location', '', 0, 0), 'href', '=', ( 'http://www.phdrinkingwater.com' + FMPOfflineURL));
			else
				LiveHelpWindow =  _proxy_jslib_handle(window, 'open', '', 1, 0)('http://www.phdrinkingwater.com/livehelp/index.php?URL=' + escape( _proxy_jslib_handle(document, 'location', '', 0, 0)) + '&DEPARTMENT=eric' + '&TITLE=' + urlencode(title) + '&SERVER=http://www.phdrinkingwater.com&COOKIE=&LANGUAGE=en', 'SUPPORTER', size);
		}
	}
	if (LiveHelpWindow) {  _proxy_jslib_assign('', LiveHelpWindow, 'opener', '=', ( self)); }
}

function OnlineTracker(initiateResult) {
	var time = currentTime();
	 _proxy_jslib_assign('', trackerStatus, 'src', '=', ( 'http://www.phdrinkingwater.com/livehelp/include/tracker.php?TITLE=' + urlencode(title) + '&URL=' + urlencode( _proxy_jslib_handle(document, 'location', '', 0, 0)) + '&REFERRER=' + urlencode( _proxy_jslib_handle(null, 'referrer', referrer, 0, 0)) + '&WIDTH=' + screen.width + '&HEIGHT=' + screen.height + '&COOKIE=&DEPARTMENT=eric'));
}

if (LiveHelpXMLHTTP != null) {
	LoadXMLTracking();
}
else {
	OnlineTracker();
}

// ;
_proxy_jslib_flush_write_buffers() ;