	/*
		The OverKnights Behavioral Design 
		Site Behavior Version 2.0
	*/	

	var chatBox = {
		ajaxCon:		false,
		container: 		false,
		pageAction:		false, 
		parameter: 		false,
		functionDone: 	false,
		isAccess:		false,
		
		send: function () {
			var objmsg = document.getElementById('strMessage');
			var objuser = document.getElementById('strUser');
			
			if ( objmsg.value != "" ) {
				chatBox.shout(objuser.value, objmsg.value);
				objmsg.value = "";
			}
		},
		
		shout: function(valUser, valMsg) {
			chatBox.ajaxCon = new ajaxKnights();
			if(!chatBox.ajaxCon) return;
			
			chatBox.pageAction = "action_chatbox.php";
			chatBox.parameter = "action=send"
			chatBox.parameter += "&user=" + valUser;
			chatBox.parameter += "&msg=" + valMsg;
					
			chatBox.functionDone = function(xmlObj) {
				var strResult = xmlObj.responseText;
				chatBox.isAccess =	false;
			
				if ( strResult == 'null' ) {
					alert("There is an error during data processing. Please refresh the page and try again...");
				} else {
					chatBox.refresh();	
				}
			}
			if (!chatBox.isAccess) chatBox.getContent();		
			else setTimeout('chatBox.shout(' + valUser + ', ' + valMsg + ');', 5000);
		},
		
		watcher: function() {
			chatBox.refresh();	
			setTimeout('chatBox.watcher();', 5000);
		},
		
		refresh: function() {
			chatBox.ajaxCon = new ajaxKnights();
			if(!chatBox.ajaxCon) return;
			
			chatBox.pageAction = "action_chatbox.php";
			chatBox.parameter = "action=message" 
			
			chatBox.functionDone = function(xmlObj) {
				var strResult = xmlObj.responseText;
				chatBox.isAccess =	false;
				if ( strResult != 'null' ) {
					chatBox.container = document.getElementById('contChatArea');
					chatBox.container.innerHTML = strResult.substring(strResult.indexOf("<msg>")+"<msg>".length, strResult.indexOf("</msg>"));
					chatBox.container = document.getElementById('uonline');
					chatBox.container.innerHTML = strResult.substring(strResult.indexOf("<uonline>")+"<uonline>".length, strResult.indexOf("</uonline>"));
					
				} else {
					alert("There is an error during data processing. Please refresh the page and try again...")
				}
			}
			
			chatBox.getContent();	
		},
		
		getContent: function() {
			var accessTime = new Date()
			chatBox.isAccess =	true;
			chatBox.parameter += "&t=" + accessTime.getTime();
			chatBox.ajaxCon.connect( chatBox.pageAction, 'Get', chatBox.parameter, chatBox.functionDone );
		}
	}
	