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_GetWindowWidth(iDefault)
{
    var iWidth = iDefault;

    if(window && window.innerWidth && window.innerWidth)
    {
        iWidth = window.innerWidth;
    }
    else if(document && document.body && document.body.clientWidth)
    {
        iWidth = document.body.clientWidth;
    }
    else if(document && document.documentElement && document.documentElement.clientWidth)
    {
        iWidth = document.documentElement.clientWidth;
    }

    return iWidth;
}

function LCLib_GetWindowHeight(iDefault)
{
    var iHeight = iDefault;

    if(window && window.innerHeight && window.innerHeight)
    {
        iHeight = window.innerHeight;
    }
    else if(document && document.body && document.body.clientHeight)
    {
        iHeight = document.body.clientHeight;
    }
    else if(document && document.documentElement && document.documentElement.clientHeight)
    {
        iHeight = document.documentElement.clientHeight;
    }

    return iHeight;
}

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)
{
		if(typeof(strText) == 'undefined')
		{
			return;
		}
	
    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);
    }
}