/**
 * <p>Logs a user action. This method returns the XML message sent
 * to the logging server or <tt>null</tt> if the web browser does
 * not support logging.</p>
 *
 * @param     action_id     action identifier
 * @param     info_type     optional, type of data in the <tt>info</tt> field
 * @param     info          optional, information to be logged
 * @return    the XML message send to the logging server, represented as a string
 */
function logUserAction(action_id, info_type, info) {
	var timezone = "UTC";
	var timestamp = _formatTimestamp(new Date());

	var xml = '<?xml version="1.0" encoding="UTF-8"?>\n<log_action ';
		xml += info;
		xml += '</log_action>';

	var escapedxml=escape(xml);
	
	var tracer=new Image();
	tracer.src="../java/tracer2.php?l="+escapedxml;

	return xml;
}


/**
 * <p>Logs a user action in full XML Mode. This method returns the XML message sent
 * to the logging server or <tt>null</tt> if the web browser does
 * not support logging.</p>
 *
 * @param     action_id     action identifier
 * @param     info_type     optional, type of data in the <tt>info</tt> field
 * @param     info          optional, information to be logged
 * @return    the XML message send to the logging server, represented as a string
 */
function logUserActionFullXML(user_id, session_id, action_id, info_type, info) {
	var timezone = "UTC";
	var timestamp = _formatTimestamp(new Date());

	var info_esc=escape(info);
	
	var xml = '<?xml version="1.0" encoding="UTF-8"?> \n ';
	xml+='<log_action auth_token="" session_id="'+session_id+'" user_guid="'+user_id+'" '
		+'date_time="'+timestamp+'" timezone="UTC" action_id="" source_id="JAVA_SCRIPT" '
		+'external_object_id="" info_type="tutor_message.dtd">'+info_esc+'</log_action>';

	
	var tracer=new Image();
	tracer.src="../java/tracer2.php?l="+xml;

	return xml;
}


/**
 * <p>Private method, used by <tt>logUserAction</tt> to generate a
 * timestamp in the proper format for logging. The resulting string
 * contains the specified date, converted to UTC.</p>
 *
 * @param     timestamp     date object, the timestamp to format as a string
 * @return    timestamp string
 */
function _formatTimestamp(timestamp) {
	var s = "";

	var year = timestamp.getUTCFullYear();
	s += year + "/";

	var month = timestamp.getUTCMonth()+1;
	s += ((month < 10) ? ("0" + month) : month) + "/";

	var date = timestamp.getUTCDate();
	s += ((date < 10) ? ("0" + date) : date) + " ";

	var hours = timestamp.getUTCHours();
	s += ((hours < 10) ? ("0" + hours) : hours) + ":";

	var mins = timestamp.getUTCMinutes();
	s += ((mins < 10) ? ("0" + mins) : mins) + ":";

	var secs = timestamp.getUTCSeconds();
	s += ((secs < 10) ? ("0" + secs) : secs);

	return s;
}

