	//Initializes a new instance of the StringBuilder class
	//and appends the given value if supplied
	function StringBuilder(value) {
		this.strings = new Array("");
		this.append(value);
	}
	
	//Appends the given value to the end of this instance.
	StringBuilder.prototype.append = function (value) {
		if (value) {
		   this.strings.push(value);
		}
	}
	
	//Clears the string buffer
	StringBuilder.prototype.clear = function () {
		this.strings.length = 1;
	}
	
	//Converts this instance to a String.
	StringBuilder.prototype.toString = function () {
		return this.strings.join("");
	}

	
	function ChatObject()  {
		// master-on-off
		if ( typeof(enable_chat)=='undefined' ) enable_chat = true;
		if ( typeof(enable_cobrowse)=='undefined' ) enable_cobrowse = true;
		
		//*** Prod Environment ***
		var rbacc_protocol = null;
		var rbacc_server = null;
		var rbacc_path = null;
		var rbacc_appcode = null;
		var rbacc_param = null;
		var tal_rbacc_prfx_param = null;
		var tal_chatlogin_7Ascript = null;
		var tal_chatimg_7Ascript = null;
	
		//Meetme
		var meetme_7Ascript = null;
		var meetme_winoptions = null;
		var meetme_acceptButton = null;
		//var meetme_accept_img = '<img border="0" src="images/accept.gif" alt="Accept" width="68" height="21" />';
	
		//Talisma
		var tal_portid = null; //"1A07F23F-C8A0-44A5-8664-438588C8D60E";
		var tal_questid = null; //"&questid=68ABBB45-19FC-4BDB-969F-9E68060C396A";
	
		var tal_winoptions = null; //"resizable=no,width=515,height=575";
		var tal_openimg = null; //"&customopenimage=https://www.rbcroyalbank.com/eassist/images/booking_e.jpg";
		var tal_closeimg = null; //"&customcloseimage=https://www.rbcroyalbank.com/eassist/images/empty.gif";
		var tal_imgalttag = null; //"alt=\"Need Help? Chat Live\"";
		var tal_imgstyle = null;
		var tal_imglang = null;
		var tal_chatwithcobrowse = null;
		var tal_protocol = null;
		
		// Chat Object control variables
		var chatType = null;
		var lang = null;
		var cat_id = null;
		
		// initializes for the specific chat
		this.init = function(chatType, lang, cat_id) {
			this.chatType = chatType;
			this.lang = lang;
			this.cat_id = cat_id;
			
			// all have to be filled with "this."
			// NOTE: strange behaviour with those set with "this." and not,
			// should be the same!
			
			//*** Prod Environment ***
			this.rbacc_protocol = "https";
			this.rbacc_server = "www1.royalbank.com";
			this.rbacc_path = "/cgi-bin/rbaccess/rbunxcgi";
			this.rbacc_appcode = "XW";
			this.rbacc_param = "?F22=XW&F6=1&F7=SF&7APROTOCOL=HTTPS&7ASERVER=XWS0EASSIST1&7ASCRIPT=";
			this.tal_rbacc_prfx_param = "&rbaccess_prefix=https://www1.royalbank.com/cgi-bin/rbaccess/rbunxcgi?F22=XW%26F6=1%26F7=SF%267APROTOCOL=HTTPS%267ASERVER=XWS0EASSIST1%267ASCRIPT=";
			this.tal_chatlogin_7Ascript = "/netagent/rbc_cimlogin.aspx";
			this.tal_chatimg_7Ascript = "/netagent/client/invites/rbc_chatimage.aspx";
		
			//Meetme
			this.meetme_7Ascript = "/netagent/rbc/meetmecheck.aspx";
			this.meetme_winoptions = "resizable=yes,width=425,height=345";
			this.meetme_acceptButton = '<input id="WC_STARTCHAT" onclick="StartWC();" type="image" src="images/accept.gif" alt="Accept" title="Accept" width="68" height="21" />';
			//this.meetme_accept_img = '<img border="0" src="images/accept.gif" alt="Accept" width="68" height="21" />';
		
			//Talisma
			this.tal_portid = null; //"1A07F23F-C8A0-44A5-8664-438588C8D60E";
			this.tal_questid = null; //"&questid=68ABBB45-19FC-4BDB-969F-9E68060C396A";
		
			this.tal_winoptions = null; //"resizable=no,width=515,height=575";
			this.tal_openimg = null; //"&customopenimage=https://www.rbcroyalbank.com/eassist/images/booking_e.jpg";
			this.tal_closeimg = null; //"&customcloseimage=https://www.rbcroyalbank.com/eassist/images/empty.gif";
			this.tal_imgalttag = null; //"alt=\"Need Help? Chat Live\"";
			this.tal_imgstyle = "&style=style0";
			this.tal_imglang = "&imagelanguage=en-us";
			this.tal_chatwithcobrowse = false;
			this.tal_protocol = "HTTPS";
			
			// custom settings for
			// booken, bookfr, chaten1, chatfr1, chaten2, chatfr2
			if (chatType == "book") {
				this.tal_winoptions = "resizable=no,width=515,height=575";
				this.tal_openimg = "&customopenimage=https://www.rbcroyalbank.com/eassist/images/booking_e.jpg";
				this.tal_closeimg = "&customcloseimage=https://www.rbcroyalbank.com/eassist/images/empty.gif";
				this.tal_imgalttag = "alt=\"Book an Appointment at your local RBC branch today!\"";
				this.tal_questid = "&questid=68ABBB45-19FC-4BDB-969F-9E68060C396A";
				
				if (lang == "en") {
					this.tal_portid = "&portid=1A07F23F-C8A0-44A5-8664-438588C8D60E";
				} else if (lang == "fr") {
					this.tal_portid = "&portid=F500AC55-1BAB-4F71-A449-4DE3B97BD319";
					this.tal_questid = "&questid=986ABCD1-9EAB-4FE2-9ACF-6022ECFC2E30";
				}
			} else if (chatType == "chat") {
				this.tal_winoptions = "resizable=no,width=500,height=500";
				this.tal_openimg = "&customopenimage=https://www.rbcroyalbank.com/eassist/images/chat-leftnav-on-e.jpg";
				this.tal_closeimg = "&customcloseimage=https://www.rbcroyalbank.com/eassist/images/empty.gif";
				this.tal_imgalttag = "alt=\"Need Help? Chat Live\"";
				this.tal_questid = "&questid=C323534A-FED7-41F8-9D22-10A0D311C101";
				
				if (lang == "en" && cat_id == "1") {
					this.tal_portid = "&portid=DDC19F2E-8D78-4487-9586-779CBA402606";
				} else if (lang == "en" && cat_id == "2") {
					this.tal_portid = "&portid=FE376F77-1437-4739-BBCF-D918C87FE657";
				} else if (lang == "fr" && cat_id == "1") {
					this.tal_portid = "&portid=8ED408F6-4008-4D65-96E8-71002E5D4BA3";
				} else if (lang == "fr" && cat_id == "2") {
					this.tal_portid = "&portid=9F2520A4-2C34-427D-A79D-865FA2AE082A";
				}
				
			}
		};
		
		
		this.checkLive = function() {
			return chatStatus[this.chatType + this.lang + this.cat_id];
		}
		
		
		// write image, non-visible with onload event to trigger status update
		this.writeImage = function() {
			// use this to get the checklive url for php
			var sb = new StringBuilder();
			sb.append(this.rbacc_protocol);
			sb.append("://");
			sb.append(this.rbacc_server);
			sb.append(this.rbacc_path);
			sb.append(this.rbacc_param);
			sb.append(this.tal_chatimg_7Ascript);
			sb.append(this.tal_imgstyle);
			sb.append(this.tal_questid);
			sb.append(this.tal_portid);
			sb.append(this.tal_imglang);
			if (this.tal_openimg != "") {sb.append(this.tal_openimg);}
			if (this.tal_closeimg !="") {sb.append(this.tal_closeimg);}
			sb.append(this.tal_rbacc_prfx_param);
			document.write("<img onload=\"updateStatus('" + this.chatType + this.lang + this.cat_id + "');\" id=\"" + this.chatType + this.lang + this.cat_id +  "\" src=\"" + sb.toString() + "\" style=\"position: absolute; visibility:hidden;\" />");
		}
	
		
		this.loadWindow = function() {
			var sb = new StringBuilder();
			
			sb.append(this.rbacc_protocol);
			sb.append("://");
			sb.append(this.rbacc_server);
			sb.append(this.rbacc_path);
			sb.append(this.rbacc_param);
			sb.append(this.tal_chatlogin_7Ascript);
			sb.append(this.tal_questid);
			sb.append(this.tal_portid);
			sb.append(this.tal_rbacc_prfx_param);
//			sb.append("&nareferer='+escape(document.location.href)");
			sb.append("&nareferer=" + escape(document.location.href));
//			sb.append(", '_blank'");
//			sb.append(", '" + this.tal_winoptions + "'");
			//sb.append("&nareferer='+escape(document.location.href),'_blank','");
			//sb.append(this.tal_winoptions);
			
			window.open(sb.toString(), "", this.tal_winoptions);
		};
	
		this.createChatDiv = function()	{
			//Create standard Chat to launch in separate window
	
			var sb = new StringBuilder();
			var tmp_div = "";
	
			sb.append("<!-- START TALISMA CHAT BUTTON -->")
			sb.append("<a href = \"javascript:void(0)\" onclick=\"javascript:window.open('");
			sb.append(this.rbacc_protocol);
			sb.append("://");
			sb.append(this.rbacc_server);
			sb.append(this.rbacc_path);
			sb.append(this.rbacc_param);
			sb.append(this.tal_chatlogin_7Ascript);
			sb.append(this.tal_questid);
			sb.append(this.tal_portid);
			sb.append(this.tal_rbacc_prfx_param);
			sb.append("&nareferer='+escape(document.location.href),'_blank','");
			sb.append(this.tal_winoptions);
			sb.append("'); return false; \" ><img src=\"");
			sb.append(this.rbacc_protocol);
			sb.append("://");
			sb.append(this.rbacc_server);
			sb.append(this.rbacc_path);
			sb.append(this.rbacc_param);
			sb.append(this.tal_chatimg_7Ascript);
			sb.append(this.tal_imgstyle);
			sb.append(this.tal_questid);
			sb.append(this.tal_portid);
			sb.append(this.tal_imglang);
			if (this.tal_openimg != "") {sb.append(this.tal_openimg);}
			if (this.tal_closeimg !="") {sb.append(this.tal_closeimg);}
			sb.append(this.tal_rbacc_prfx_param);
			sb.append("\" border=\"0\" ");
			sb.append(this.tal_imgalttag);
			sb.append("></a>");
			sb.append("<!-- END TALISMA CHAT BUTTON -->")
	
			tmp_div = sb.toString();
			sb.clear()
			return tmp_div;
		};
		
		this.createChatWithCobrowseDiv = function(strText)	{
			//Create Chat with Cobrowse option to launch in separate window
	
			var sb = new StringBuilder();
			var tmp_div = "";
	
			sb.append("<!-- START TALISMA CHAT BUTTON WITH WEB COLLABORATION -->")
			sb.append("<script type=\"text/javascript\"> var TALCOB = null; function OnWCSessionStarted( id ){g_theWCObj.launchPortalLogin( id, \"");
			sb.append(this.rbacc_protocol);
			sb.append("://");
			sb.append(this.rbacc_server);
			sb.append(this.rbacc_path);
			sb.append(this.rbacc_param);
			sb.append(this.tal_chatlogin_7Ascript);
			sb.append(this.tal_questid);
			sb.append(this.tal_portid);
			sb.append(this.tal_rbacc_prfx_param);
			sb.append("\");return true;}function StartWC(){TALCOB = window.open(\"about:blank\",\"_blank\",\"");
			sb.append(this.tal_winoptions);
			sb.append("\"); g_theWCObj.startNewSession();}</scr");
			sb.append("ipt>");
			
			
			sb.append("<a id=\"WC_STARTCHAT\" href=\"javascript:StartWC();\">" + strText + "</a>");
	
			
			sb.append("<!-- END TALISMA CHAT BUTTON -->")
			tmp_div = sb.toString();
			sb.clear()
			return tmp_div;
		};
	
		this.createMeetMeDiv = function() {
			var sb = new StringBuilder();
			var tmp_div = "";
		   
			sb.append("<script type=\"text/javascript\"> var TALCOB = null; function OnWCSessionStarted( id ){ g_theWCObj.launchPortalLogin( id, \"");
			sb.append(this.rbacc_protocol);
			sb.append("://");
			sb.append(this.rbacc_server);
			sb.append(this.rbacc_path);
			sb.append(this.rbacc_param);
			sb.append(this.meetme_7Ascript);
			//sb.append(tal_questid);
			//sb.append(tal_portid);
			//sb.append("&rbc_mmac=\" + document.all.rbc_mmac.value );
			//sb.append("+\"&rbc_mmerrpg=\" + document.all.rbc_mmerrpg.value" );
			//sb.append("+\"&rbc_mmlang=\" + document.all.rbc_mmlang.value" );
	
			sb.append("&rbc_mmac=\" + document.getElementById('rbc_mmac').value + \""  );
			sb.append("&rbc_mmerrpg=\" + document.getElementById('rbc_mmerrpg').value + \"" );
			sb.append("&rbc_mmlang=\" + document.getElementById('rbc_mmlang').value + \"" );
	
		    sb.append(this.tal_rbacc_prfx_param);
			sb.append("\");return true;}");
			sb.append("function StartWC(){TALCOB = window.open(\"about:blank\",\"_blank\",\"");
	
			sb.append(this.meetme_winoptions);
			sb.append("\"); g_theWCObj.startNewSession(); }</scr")
			sb.append("ipt>");
			//sb.append("<a id=\"WC_STARTCHAT\" href=\"javascript:StartWC();\" >");
			//sb.append(meetme_accept_img);
			//sb.append("</a>");
		    sb.append( this.meetme_acceptButton );
	
			tmp_div = sb.toString();
			
			sb.clear()
			return tmp_div;
		};
	
		this.eAssist_getChatSnippet = function() {
		    if ( typeof(enable_chat)=='undefined' ) enable_chat = true;
		    if ( typeof(enable_cobrowse)=='undefined' ) enable_cobrowse = true;
	
		    tal_chat_div = "";
		 	if (enable_chat)
			{
				if (enable_cobrowse && tal_chatwithcobrowse)
					tal_chat_div = this.createChatWithCobrowseDiv();
				else
					tal_chat_div = this.createChatDiv();
			}
			document.write(tal_chat_div);	
		};
	
		this.eAssist_getMeetmeSnippet = function() {
		    if ( typeof(enable_cobrowse)=='undefined' ) enable_cobrowse = true;
		    
		    var meetme_html = "";
			if (enable_cobrowse)
				meetme_html = this.createMeetMeDiv();
	
		    //alert( meetme_html );
		    document.write(meetme_html);
		};	
	}
