function LCLib_NumberFormat(iNumber, iLength, strFill)
{
    iOldLength = String(iNumber).length;
    strRet = String(iNumber);
    while(iOldLength < iLength)
    {
        strRet = String(strFill) + strRet;
        iOldLength++;
    }

    return strRet;
}

function LCLib_FindFrameByName(strName, objCurrent)
{
    var ret = null;

    for(var i = 0; i < objCurrent.frames.length; i++)
    {
        if(objCurrent.frames[i].name == strName)
        {
            return objCurrent.frames[i];
        }

        ret = LCLib_FindFrameByName(strName, objCurrent.frames[i]);
    }

    return ret;
}

function LCLib_ParseUrlParams(strSearch)
{
    var arNameValuePairs = new Array();

    var iBegin = strSearch.indexOf('?');
    while(iBegin > -1)
    {
        var strPair = '';
        var iEnd = strSearch.indexOf('&', iBegin + 1);
        if(iEnd > -1)
        {
            strPair = strSearch.substring(iBegin + 1, iEnd);
            iBegin = iEnd;
        }
        else
        {
            strPair = strSearch.substring(iBegin + 1);
            iBegin = -1;
        }

        var iDelim = strPair.indexOf('=');
        if(iDelim > -1 && (iEnd < 0 || iEnd > iDelim))
        {
            arNameValuePairs[arNameValuePairs.length] = strPair.substring(0, iDelim);
            arNameValuePairs[arNameValuePairs.length] = strPair.substring(iDelim + 1);
        }
        else
        {
            arNameValuePairs[arNameValuePairs.length] = strPair;
            arNameValuePairs[arNameValuePairs.length] = '';
        }
    }

    return arNameValuePairs;
}

function LCLib_BuildUrlParams(arNameValuePairs)
{
    var strParams = '';
    if(arNameValuePairs.length > 0)
    {
        strParams = '?';
    }

    for(var i = 0; i < arNameValuePairs.length; i += 2)
    {
        if(strParams.length > 1)
        {
            strParams += '&';
        }

        strParams += arNameValuePairs[i] + '=' + arNameValuePairs[i + 1];
    }

    return strParams;
}

function LCLib_GetLocationDir(strLocation)
{
    if(strLocation.indexOf('?') > -1)
    {
        strLocation = strLocation.substring(0, strLocation.indexOf('?'));
    }

    if(strLocation.lastIndexOf('/') > -1)
    {
        strLocation = strLocation.substring(0, strLocation.lastIndexOf('/'));
    }

    return strLocation;
}

function LCLib_OnLoadOnUnloadSortComparer(objX, objY)
{
    return objX.iPriority - objY.iPriority;
}

var LCLib_arOnLoadActions = new Array();
var LCLib_arOnUnloadActions = new Array();

function LCLib_addOnLoadAction(strAction, iPriority)
{
    var objOnLoad = new Object();
    objOnLoad.strAction = strAction;
    objOnLoad.iPriority = iPriority;
    LCLib_arOnLoadActions[LCLib_arOnLoadActions.length] = objOnLoad;
}

function LCLib_addOnUnloadAction(strAction, iPriority)
{
    var objOnUnload = new Object();
    objOnUnload.strAction = strAction;
    objOnUnload.iPriority = iPriority;
    LCLib_arOnUnloadActions[LCLib_arOnUnloadActions.length] = objOnUnload;
}

function LCLib_OnLoad()
{
    LCLib_arOnLoadActions.sort();
    for(var i = 0; i < LCLib_arOnLoadActions.length; i++)
    {
        eval(LCLib_arOnLoadActions[i].strAction);
    }
}

function LCLib_OnUnload()
{
    LCLib_arOnUnloadActions.sort();
    for(var i = 0; i < LCLib_arOnUnloadActions.length; i++)
    {
        eval(LCLib_arOnUnloadActions[i].strAction);
    }
}

function LCLib_GetWindowWidth2(iDefault, objWnd)
{
    var iWidth = iDefault;

    if(objWnd && objWnd.innerWidth && objWnd.innerWidth)
    {
        iWidth = objWnd.innerWidth;
    }
    else if(objWnd.document && objWnd.document.body && objWnd.document.body.clientWidth)
    {
        iWidth = objWnd.document.body.clientWidth;
    }
    else if(objWnd.document && objWnd.document.documentElement && objWnd.document.documentElement.clientWidth)
    {
        iWidth = objWnd.document.documentElement.clientWidth;
    }

    return iWidth;
}

function LCLib_GetWindowWidth(iDefault)
{
	return LCLib_GetWindowWidth2(iDefault, window);	
}

function LCLib_GetWindowHeight2(iDefault, objWnd)
{
    var iHeight = iDefault;

    if(objWnd && objWnd.innerHeight && objWnd.innerHeight)
    {
        iHeight = objWnd.innerHeight;
    }
    else if(objWnd.document && objWnd.document.body && objWnd.document.body.clientHeight)
    {
        iHeight = objWnd.document.body.clientHeight;
    }
    else if(objWnd.document && objWnd.document.documentElement && objWnd.document.documentElement.clientHeight)
    {
        iHeight = objWnd.document.documentElement.clientHeight;
    }

    return iHeight;
}

function LCLib_GetWindowHeight(iDefault)
{
	return LCLib_GetWindowHeight2(iDefault, window);
}

function LCLib_ltrim()
{
    return(this.replace(/^\s+/,''));
}

function LCLib_rtrim()
{
    return(this.replace(/\s+$/,''));
}

function LCLib_trim()
{
    return(this.replace(/^\s+/,'').replace(/\s+$/,''));
}

String.prototype.ltrim = LCLib_ltrim;
String.prototype.rtrim = LCLib_rtrim;
String.prototype.trim  = LCLib_trim;

function LCLib_GetItemNumberFromUrl(strUrl)
{
    var strSelf = strUrl;
    var iPos = strSelf.indexOf('/_lccms_/_');
    if(iPos > -1)
    {
        strSelf = strSelf.substr(iPos + 10);
        iPos = strSelf.indexOf('/');
        if(iPos > -1)
        {
            strSelf = strSelf.substr(0, iPos);
            return strSelf;
        }
    }

    return '';
}

function LCLib_GetStringBetweenTags(strText, strStartTag, strEndTag)
{
	var iPos = strText.indexOf(strStartTag);
	if(iPos > -1)
	{
		strText = strText.substr(iPos + strStartTag.length);
		iPos = strText.indexOf(strEndTag);
		if(iPos > -1)
		{
			strText = strText.substr(0, iPos);
			return strText;
		}
	}
	
	return '';
}

function LCLib_SetCookie(strName, strValue, strExpires, strPath, strDomain, strSecure)
{
  document.cookie = strName + "=" + escape(strValue) +
    ( (strExpires) ? ";expires=" + strExpires.toGMTString() : "") +
    ( (strPath)    ? ";path="    + strPath                  : "") +
    ( (strDomain)  ? ";domain="  + strDomain                : "") +
    ( (strSecure)  ? ";secure"                              : "");
}

function LCLib_GetCookie(strName)
{
  var iStart = document.cookie.indexOf(strName + "=");
  var iLen   = iStart + strName.length + 1;
  if ((!iStart) && (strName != document.cookie.substring(0, strName.length))) { return null; }
  if (iStart == -1) { return null; }
  var iEnd = document.cookie.indexOf(";", iLen);
  if (iEnd == -1) { iEnd = document.cookie.length; }
  return(unescape(document.cookie.substring(iLen, iEnd)));
}

function LCLib_SetDebugMode(bDebug)
{
	LCLib_SetCookie('lclib_debugmode', Number(bDebug), 0);
}

function LCLib_GetDebugMode()
{
	var strDebugMode = LCLib_GetCookie('lclib_debugmode');
	
	if(typeof(strDebugMode) != 'undefined')
	{
		return Number(strDebugMode);
	}
	else
	{
		return false;
	}
}

function LCLib_DoDebugOutput(strMessage)
{
	if(LCLib_GetDebugMode())
	{
		alert(strMessage);
	}
}

function LCLib_GetItemPathUrlFromItemUrl(strUrl)
{
	var strSelf = strUrl;
	var iPos = strSelf.indexOf('/_lccms_/_');
	if(iPos > -1)
	{
		iPos = strSelf.indexOf('/', iPos + 10);
		if(iPos > -1)
		{
			strSelf = strSelf.substr(0, iPos + 1);
			
			if(strSelf.indexOf('http://') != strSelf.lastIndexOf('http://'))
			{
				strSelf = strSelf.substr(strSelf.lastIndexOf('http://'));
			}
			
			return strSelf;
		}
	}
	
	return '';
}

function LCLib_QuickHash(strInput)
{
	var strHash = strInput.length;
	var iTotal = 0;
	
	for(var i = 0; i < strInput.length; i++)
	{
		iTotal += Math.sqrt(Math.pow(strInput.charCodeAt(i), i));
	}
	
	strHash += String(iTotal);
	strHash = strHash.replace('.', '');
	strHash = strHash.replace('e', '');
	strHash = strHash.replace('+', '');
	
	return strHash;
}