var messageUrl = Common.getRoot() + "message/getmessage";
var pathInfoUrl = Common.getRoot() + "message/getPathInfo";

var validateMessage = Class.create();
validateMessage.prototype = {
	m_Messages : null,
	m_Buffer : null,

	initialize : function (pValue)
	{
		if (pValue ==null) pValue = "error";

		this.loadData(pValue);

		this.m_Messages = eval('(' + m_Buffer.result + ')');
	},

	loadData : function(pValue)
	{
		//requestHeaders: [ "Connection", 'close' ],
		new Ajax.Request(messageUrl, {
			asynchronous: false,
			parameters: $H({'message': pValue}),
			method: "post",
			onSuccess: function(xmlHttp)
			{
				try
				{
					this.m_Buffer = eval('(' + xmlHttp.responseText + ')');
					return true;
				}
				catch(E)
				{
					alert("Message Load Fail : " + xmlHttp.responseText);

					return false;
				}
			},
			onFailure : function (request)
			{
				alert("Message Request Fail");
				return false;
			}
		});
	},

	getMessage : function(pValue)
	{
		if (this.m_Messages == null) return "Message Data is null.";
		else {
			if(this.m_Messages[pValue] != undefined) {
				return this.m_Messages[pValue].replace(/&#039;/g, "'").replace(/\/n/g, "\n");
			} else {
				return '['+pValue+']Message Data is null.';
			}
		}
	}
};

var pathInfo = Class.create();
pathInfo.prototype = {
	m_Messages : null,
	m_Buffer : null,

	initialize : function ()
	{
		if( this.readCookie( "URLTYPE" ) == null || this.readCookie( "LANGUAGE" ) == null)
		{
			this.loadData();
		}
	},

	loadData : function() {
		getAjaxData( pathInfoUrl, '', this.loadDataCallback.bind(this) );
	},

	loadDataCallback : function(pValue) {
		this.m_Buffer = pValue;
		this.m_Messages = eval('(' + this.m_Buffer.result + ')');
		//this.createCookie( 'IMAGEROOT', this.m_Messages['IMAGEROOT'] , 1 );
		//this.createCookie( 'IMAGEPATH', this.m_Messages['IMAGEPATH'] , 1 );
		this.createCookie( 'LANGUAGE', this.m_Messages['LANGUAGE'] , 1 );
		this.createCookie( 'URLTYPE', this.m_Messages['URLTYPE'] , 1 );
		this.createCookie( 'DOMAIN', this.m_Messages['DOMAIN'] , 1 );
		this.createCookie( 'GROUPID', this.m_Messages['GROUPID'] , 1 );
		this.createCookie( 'ROOT', this.m_Messages['ROOT'] , 1 );
	},

	createCookie : function (name,value,days)
	{
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},

	readCookie : function(name) {
		var nameEQ = name + "=";
		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 decodeURIComponent(c.substring(nameEQ.length,c.length));
		}
		return null;
	},

	getInfo : function(pValue)
	{
		var returnData = this.readCookie(pValue);
		if(returnData) {
			return returnData;
		} else {
			return this.m_Messages ? this.m_Messages[pValue] : null;
		}
	}
};
var pathHelper = new pathInfo();

