
var hasHadFocus = false;
var listIsClear = true;

function doFocus()
{
	if(!hasHadFocus)
	{
		var el = elementById("searchfield");
		if(null != el)
		{
			el.value = "";
			hasHadFocus = true;
		}
	}
}

function doFilter()
{
    var oSearchEl = document.getElementById("searchfield");
    if(oSearchEl != null)
        showItems("searchtable", 1, oSearchEl.value,1, "checkoutrow-");
}


function showItems( oTableName, nColumnText, strSearch, nIgnoreRows, strRowStyle )
{
    strSearch = strSearch.toLowerCase();
    var oTable = document.getElementById(oTableName);
    if(oTable == null)
        return;
    var oRows = oTable.getElementsByTagName("tr");
    if(oRows == null)
        return;
    var nRowType = 1;
    
    for(var i = nIgnoreRows; i < oRows.length; i++)
    {
        var bShown = (strSearch == "") ? true : false;
        var oRow = oRows[i];
        if(null == oRows)
            continue;
        if( oRow.attributes["nohide"] != null )
            bShown = true;
        if(bShown)
        {
            SetRowStyle(strRowStyle, oRow, true, nRowType);
        }
        else
        {
            var oCols = oRow.getElementsByTagName("td");
            if(oCols != null && oCols.length >= nColumnText)
            {
                var oCol = oCols[nColumnText - 1];
                var strText = "";
                if(oCol != null)
                {
                    // IE uses innerText, firefox uses textContent
                    if(oCol.innerText != null)
                        strText = oCol.innerText;
                    else if(oCol.textContent)
                        strText = oCol.textContent;
                }
                if(strText != null)
                {
                    var strLowText = strText.toLowerCase();
                    if(strLowText.indexOf(strSearch) >= 0)
                        bShown = true;                    
                }
            }
            SetRowStyle(strRowStyle, oRow, bShown, nRowType);
        }
        if(bShown)
        {
            nRowType = (nRowType > 1) ? 1 : 2;
        }
    }
}


function SetRowStyle( strBaseStyle, oRow, bShown, nRowNumber )
{
    var strClassName = strBaseStyle;
    if(!bShown)
        strClassName += "off";
    else
        strClassName += nRowNumber;
    oRow.className = strClassName;
}


var oScrollerWindow = null;

function doSmoothScroll(oWindow,x,y,uTime) 
{
  var e = oWindow;
  if (!e.timeout) e.timeout = 25;
  var st = xScrollTop(e, 1);
  var sl = xScrollLeft(e, 1);
  e.xTarget = x; 
  e.yTarget = y; 
  e.slideTime = uTime; 
  e.stop = false;
  e.yA = e.yTarget - st;
  e.xA = e.xTarget - sl; // A = distance
  if (e.slideLinear) 
    e.B = 1/e.slideTime;
  else 
    e.B = Math.PI / (2 * e.slideTime); // B = period
  e.yD = st;
  e.xD = sl; // D = initial position
  var d = new Date(); e.C = d.getTime();
  if (!e.moving) 
  {
    oScrollerWindow = e;
    _doSmoothScroll();
  }
}
function _doSmoothScroll() 
{
  var e = oScrollerWindow || window;
  var now, s, t, newY, newX;
  now = new Date();
  t = now.getTime() - e.C;
  if (e.stop) { e.moving = false; }
  else if (t < e.slideTime) {
    setTimeout("_doSmoothScroll()", e.timeout);

    s = e.B * t;
    if (!e.slideLinear) s = Math.sin(s);
//    if (e.slideLinear) s = e.B * t;
//    else s = Math.sin(e.B * t);

    newX = Math.round(e.xA * s + e.xD);
    newY = Math.round(e.yA * s + e.yD);
    e.scrollTo(newX, newY);
    e.moving = true;
  }  
  else {
    e.scrollTo(e.xTarget, e.yTarget);
    oScrollerWindow = null;
    e.moving = false;
    if (e.onslideend) e.onslideend();
  }  
}

function getPageYPosition(e)
{
	if(!(e=elementById(e)))return 0;
	var y=0;
	while(e)
	{
		if(isDefined(e.offsetTop))
			y+=e.offsetTop;
		e=isDefined(e.offsetParent) ? e.offsetParent:null;
	}
	return y;
}


function isDefined()
{
	for(var i=0; i<arguments.length;++i)
	{
		if(typeof(arguments[i]) == 'undefined')
			return false;
	}
	return true;
}

function xScrollTop(e,bWin)
{
	var offset=0;
	if(!isDefined(e)||bWin||e==document||e.tagName.toLowerCase()=='html'||e.tagName.toLowerCase()=='body')
	{
		var w=window;
		if(bWin&&e)
			w=e;
		if(w.document.documentElement&&w.document.documentElement.scrollTop)
			offset=w.document.documentElement.scrollTop;
		else if(w.document.body&&isDefined(w.document.body.scrollTop))
			offset=w.document.body.scrollTop;
	}
	else
	{
		e=elementById(e);
		if(e && xNum(e.scrollTop))
			offset=e.scrollTop;
	}
	return offset;
}


function xScrollLeft(e,bWin)
{
	var offset=0;
	if(!isDefined(e)||bWin||e==document||e.tagName.toLowerCase()=='html'||e.tagName.toLowerCase()=='body')
	{
		var w=window;
		if(bWin&&e)
			w=e;
		if(w.document.documentElement&&w.document.documentElement.scrollLeft)
			offset=w.document.documentElement.scrollLeft;
		else if(w.document.body&&isDefined(w.document.body.scrollLeft))
			offset=w.document.body.scrollLeft;
	}
	else
	{
		e=elementById(e);
		if(e&&xNum(e.scrollLeft))
			offset=e.scrollLeft;
	}
	return offset;
}


function elementById(e)
{
	if(typeof(e)=='string')
	{
		if(document.getElementById)
			e=document.getElementById(e);
		else if(document.all)
			e=document.all[e];
		else e=null;
	}
	return e;
}


function smoothScroll(strTarget)
{
    doSmoothScroll(window, 0, getPageYPosition(strTarget), 300);
    return false;
}

function smoothScrollTop()
{
  doSmoothScroll(window, 0, 0, 500);
  return false;
}