	var strSecureAlgoritm= "";
	var strSecureKS		 = "";
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// Save To UserData
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function SaveUserData(strSecureAlgoritm , strSecureKS)
	{
		if(strSecureAlgoritm != null)
			oUserData.setAttribute("SecureAlgoritm", strSecureAlgoritm );

		if(strSecureKS != null)
			oUserData.setAttribute("SecureKS", strSecureKS);
			
		oUserData.save("oDataStore");
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// Load From UserData
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function LoadUserData()
	{
		oUserData.load("oDataStore");
		strSecureAlgoritm	= oUserData.getAttribute("SecureAlgoritm");
		strSecureKS			= oUserData.getAttribute("SecureKS");

	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// Set Cookie
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function fn_SetCookie(CookieName , CookieValue , Expired , ExpirationDate, Domain, IsSecure)
	{
		var Cookie = "";
		if (!Expired)
			Cookie = CookieName + "=" + CookieValue + ";expires=Mon, 31 Dec 2020 23:59:59 UTC;";
		else
			if (ExpirationDate=="")
				Cookie = CookieName + "=" + CookieValue
			else
				Cookie = CookieName + "=" + CookieValue + ";expires=" + ExpirationDate;
		if(Domain != null)
		{
			var Pos = Domain.indexOf(':');
			if(Pos == -1)
				Cookie += ";domain=" + Domain + ";";	
			else
				Cookie += ";domain=" + Domain.substr(0,Pos) + ";";	
		}
		if(IsSecure == true)	
			Cookie += "secure;";	
			
		Cookie += ";path=/";
		document.cookie	= Cookie;
		return;
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// GetCookie(CookieName)
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function fn_GetCookie(CookieName)
	{
		var Cookies , CookieNameInCookies , CookieValueInCookies
		Cookies = document.cookie;
		Cookies = Cookies.split(";")
		//alert(Cookies);
		for (var Counter=0 ; Counter<Cookies.length ; Counter++)
		{
			var strCookie = Cookies[Counter];
			var iEqualIndex = strCookie.search("=");
			if (iEqualIndex == -1)
			    continue;
				
			var CookieNameInCookies = strCookie.substring(0 , iEqualIndex);
			var CookieValueInCookies = strCookie.substring(iEqualIndex + 1 , strCookie.length);
			if (Trim(CookieNameInCookies)==Trim(CookieName))
				return CookieValueInCookies;
		}
		return -1;
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// LTrim(Str)
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function LTrim(Str)
	{
		var Char=Str.substring(0,1);
		while (Char==" ")
		{
			Str = Str.substring(1);
			Char=Str.substring(0,1);
		}
		return Str;
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// RTrim(Str)
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function RTrim(Str)
	{
		var Char=Str.substring(Str.length-1);
		while (Char==" ")
		{
			Str = Str.substring(0,Str.length-2);
			Char = Str.substring(Str.length-1);
		}
		return Str;
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// Trim(Str)
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function Trim(Str)
	{
		return RTrim(LTrim(Str));
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// UserAuthentication
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function UserAuthentication()
	{
		LoadUserData();
		execScript(strSecureAlgoritm.replace(/__/g,"\n").replace(/%3B/g,";"));
		var oDate = new Date();
		var strDate = oDate.getFullYear() + " " + parseInt(oDate.getMonth()+1)+ " " + oDate.getDate() + " " + oDate.getHours() + " " + oDate.getMinutes() + " " + parseInt(oDate.getSeconds()+1);
		fn_SetCookie("Date" ,strDate,true,"",null,false);
		var KS = strSecureKS;

		var iDifference = Math.abs(KS.length - strDate.length);	
		var strSpace = "";
		for(var i=0 ; i < iDifference ; i++)
			strSpace += " ";

		if(KS.length > strDate.length)	
			strDate += strSpace;
		else
			KS		+= strSpace;
		
		var EncryptedTimestamp = hex_hmac_sha1(KS, strDate);
		fn_SetCookie("EncryptedTimestamp" ,EncryptedTimestamp,true,"",null,false);
	}	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// SignatureDocument
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function SignatureDocument(Keyword)
	{
		LoadUserData();
		var KS = strSecureKS;

		execScript(strSecureAlgoritm.replace(/__/g,"\n").replace(/%3B/g,";"));
		var oDate = new Date();
		var strDate = oDate.getFullYear() + " " + parseInt(oDate.getMonth()+1)+ " " + oDate.getDate() + " " + oDate.getHours() + " " + oDate.getMinutes() + " " + parseInt(oDate.getSeconds()+1);
		fn_SetCookie("DateForInbox" ,strDate,true,"",null,false);

		strDate = Keyword + strDate;

		var iDifference = Math.abs(KS.length - strDate.length);	
		var strSpace = "";
		for(var i=0 ; i < iDifference ; i++)
			strSpace += " ";

		if(KS.length > strDate.length)	
			strDate += strSpace;
		else
			KS		+= strSpace;
		
		var EncryptedResponseForInbox = hex_hmac_sha1(KS, strDate);
		fn_SetCookie("EncryptedResponseForInbox" ,EncryptedResponseForInbox,true,"",null,false);
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	var CCookie = new Object();
	CCookie.SetCookie = fn_SetCookie;
	CCookie.GetCookie = fn_GetCookie;
