function customerService() {

		// Determine if chat is applicable
		this.bNoChat = !this.chatApplicable();
		
		if(!this.startChat()) return;

		if(!this.bNoChat) {

			// Is chat available
			if(this.chatActive()) {

				// Initialize & Load Dialog Box
				var liveChat = jQuery('#before_you_go');
				
				liveChat.attr('title','Basic modal dialog');
				liveChat.dialog({
					bgiframe: false,
					width: 314,
					height: 152,
					modal: true,
					maxWidth: 314,
					maxHeight: 152,
					minWidth: 314,
					minHeight: 152,
					autoOpen: false,
					close: function(event, ui) {
						liveChat.remove();
					}
				});
				
				this.chatReference = liveChat;

				var self = this;
				
				jQuery('#closeForm').click(function(){
					liveChat.dialog('close');
				});
				
				jQuery('#openLiveChat').click(function(){
					window.open('http://www.sitewizard-support.co.uk/livechat/request.php?action=request&display_width=800&display_height=600&datetime=3%2F10%2F110+09%3A25%3A39+A.M&x=1&l=support&pagex=http:://www.sitewizard-support.co.uk&deptid=2&guest=true');
					return false;
				});
				
				window.onbeforeunload = function()
				{
					window.onbeforeunload = (function(){  jQuery('#before_you_go').remove(); });
					// Open Dialog Box
					liveChat.dialog('open');

					// Set the chat cookie
					//self.setChatCookie();

					// Return the confirmation window
					return "\n********* Hey Wait! Before You Go... *********\n\nA live agent has a special 15% discount for you.\n";

				};				
				
				// Find all links on the site
				jQuery('a').click(function(){  window.onbeforeunload = function(){};});
			}
		}
}

customerService.prototype.initiate			= function() { this.enableChatCookie(); }

customerService.prototype.chatReference     = null;
customerService.prototype.bNoChat			= false;
customerService.prototype.bFrameLoaded		= false;
customerService.prototype.bServerChatActive = false;
customerService.prototype.iCookieRestDays	= 30;
customerService.prototype.sChatVariable		= "NO_CHAT";
customerService.prototype.sChatSetVar		= "CHAT_SET";
customerService.prototype.chatData			= {};


customerService.prototype.chatActive		= function() {
	var repsonse = jQuery.ajax(
		{
			url:'chatServiceStatus.php',
			async:false
		}).responseText;

	repsonse = (repsonse == "true") ? true:false;
	this.bServerChatActive = repsonse;
	return this.bServerChatActive;
}

customerService.prototype.setChatCookie = function() {
	var date = new Date();
	date.setTime(date.getTime()+(this.iCookieRestDays*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = this.sChatVariable+"="+this.sChatVariable+expires+"; path=/";
}

customerService.prototype.enableChatCookie = function() {
	var date = new Date();
	date.setTime(date.getTime()+(this.iCookieRestDays*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = this.sChatSetVar+"="+this.sChatSetVar+expires+"; path=/";
}


customerService.prototype.chatApplicable	= function() {
	var nameEQ	= this.sChatVariable + "=";
	var ca		= document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return false;
	}
	return true;
} // This needs a better method name

customerService.prototype.startChat	= function() {
	var nameEQ	= this.sChatSetVar + "=";
	var ca		= document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return true;
	}
	return false;
} // This needs a better method name



customerService.prototype.getChatWindow		= function() {}

// Create cookie function
function createCookie(c,d,e){if(e){var b=new Date();b.setTime(b.getTime()+(e*24*60*60*1000));var a="; expires="+b.toGMTString()}else{var a=""}document.cookie=c+"="+d+a+"; path=/"};

function checkExternal(href) {
	return ((href.indexOf("://") > -1) || (href.indexOf("www.") > -1));
}
