function LiveChat() {
	this.mencomPath = '';
	this.branchCodes = new Array();
	this.xCode = '';
	
	this.SetMencomPath = SetMencomPath;
	this.SetCode = SetCode;
	this.AddBranch = AddBranch;
	this.CharPressed = CharPressed;
	this.CheckKeypress = CheckKeypress;
	this.StartChat = StartChat;
}

function SetMencomPath(mencomPath) {
	this.mencomPath = mencomPath;
}

function SetCode(code) {
	this.xCode = code;
}

function AddBranch(branchCode) {
	this.branchCodes.push(branchCode);
}

// the ASCII charachter number of the key pressed
function CharPressed(eventObj) {
	// check if browser is netscape
	if(eventObj && eventObj.which){
		// return the charachter pressed
		return eventObj.which;
	// else should be IE
	} else {
		eventObj = event;
		// return the charachter pressed
		return eventObj.keyCode;
	}
}

function CheckKeypress(eventObj) {
	// if the key pressed is Enter
	if (this.CharPressed(eventObj) == 13) {
		this.StartChat();
		return false;
	}
}

function StartChat() {
	var iframeSrc = this.mencomPath+'LiveChat.php';
	iframeSrc += "?n="+document.getElementById('chatName'+this.gadgetId).value;
	iframeSrc += "&c="+this.xCode;
	iframeSrc += "&b="+this.branchCodes.join('-');
	
	var chatIframe = document.getElementById('chatIframe'+this.gadgetId);
	chatIframe.src = iframeSrc;
	
	document.getElementById('chatStart'+this.gadgetId).style.visibility = 'hidden';
	var chatWindow = document.getElementById('chatWindow'+this.gadgetId);
	chatWindow.style.visibility = 'visible';
}