//Data Container JavaScript Library
//Copyright(C) 1999 NXT Wave Ltd
//http://www.nxt-wave.com
//Developed by Greg Montgomery
//email: greg@nxt-wave.com
//Release: Beta 0.9

var isNav4,isIE4
if(navigator.appVersion.charAt(0) == "4") {
  if (navigator.appName=="Netscape") {
    isNav4 = true
  } else {
    isIE4 = true
  }
}

function DataContainer(name){
  this.name = name
  this.colDefn = new Array()
  this.lastFilter = null
  this.curFilter = null
  this.curRow = 0
  this.rows = new Array()
  this.useFilter = false
  this.sortOrder = null
  return this
}

function DCColDefn(name,type,title,size,valid,comp) {
  this.name = name
  this.type = type
  this.title = title
  this.size = size
  this.valid = valid
  this.comp = comp
  return this
}

function DCRow(status, cols) {
  this.status = status
  this.infilter = false
  for(i=0; i<cols.length; i++){
    col = new DCCol(cols[i])
    cols[i] = col
  }
  this.cols = cols
  return this
}

function DCCol(val){
  this.val = val
  return this
}

function DCFilter(rowInd, filterArgs){
  this.rowInd=rowInd
  this.filterArgs = filterArgs
  return this
}

function DCFilterCol(name,op,value){
  this.name = name
  this.op = op
  this.value = value
  return this
}

function DCAddRow(DC,row){
  size = DC.rows.length
  DC.rows[size] = row
  return size
}

function DCAddColDefn(DC,colDefn){
  size = DC.colDefn.length
  DC.colDefn[size] = colDefn
  return size
}

function DCGetColVal(DC,rowInd,colInd) {
  colDefn = DC.colDefn[colInd]
  if (colDefn.comp==null || colDefn.comp.length==0)
  {
    return DC.rows[rowInd].cols[colInd].val
  } else {
    row = DC.rows[rowInd]
    col = DC.rows[rowInd].cols[colInd]
    val = col.val
    return eval(colDefn.comp)
  }
}

function DCSortBy(DC,col,asc) {
  logMessage("D","column is"+col)
  tp = DC.colDefn[col].type
  if (asc==0){
    for (var ind =0; ind< DC.rows.length; ind++) {
      var min = ind;
      for (var j=ind; j < DC.rows.length; j++) {
        if (tp=="N") {
          if (Number(DC.rows[j].cols[col].val) < Number(DC.rows[min].cols[col].val)){
     	    min = j
          }
        } else {
          if (DC.rows[j].cols[col].val < DC.rows[min].cols[col].val){
     	    min = j
          }
        }
      }
      var old = DC.rows[ind]
      DC.rows[ind] = DC.rows[min]
      DC.rows[min] = old
    }
  } else {
    for (var ind =0; ind< DC.rows.length; ind++) {
      var min = ind;
      for (var j=ind; j < DC.rows.length; j++) {
        if (tp!="C") {
          if (Number(DC.rows[j].cols[col].val) > Number(DC.rows[min].cols[col].val)){
     	    min = j
          }
        } else {
          if (DC.rows[j].cols[col].val > DC.rows[min].cols[col].val){
     	    min = j
          }
        }
      }
      var old = DC.rows[ind]
      DC.rows[ind] = DC.rows[min]
      DC.rows[min] = old
    } 
  }          
}

function logMessage(ertype,msg) {
  //window.status = msg
}

var cookie_buf = ""
function setCookieState(cookie_str,setting) {
        document.cookie = cookie_str+"=" + escape(setting)
        //currState = setting
        cookie_buf = document.cookie
}
// retrieve cookie data
function getCookieState(cookie_str) {
        var label = cookie_str+"="
        var labelLen = label.length
    if (cookie_buf.length==0)
    {
        cookie_buf = document.cookie
    }
        var cLen = cookie_buf.length
        var i = 0
        while (i < cLen) {
                var j = i + labelLen
                if (cookie_buf.substring(i,j) == label) {
                        var cEnd = cookie_buf.indexOf(";",j)
                        if (cEnd ==     -1) {
                                cEnd = cookie_buf.length
                        }
                        return unescape(cookie_buf.substring(j,cEnd))
                }
                i++
        }
        return ""
}
function setCookieStateAct(doc,cookie_str,setting) {
        doc.cookie = cookie_str+"=" + escape(setting)
        //currState = setting
}
function getCookieStateAct(doc,cookie_str) {
        var label = cookie_str+"="
        var labelLen = label.length
    cookie_buf = doc.cookie
    if (cookie_buf.length==0)
    {
        cookie_buf = document.cookie
    }
        var cLen = cookie_buf.length
        var i = 0
        while (i < cLen) {
                var j = i + labelLen
                if (cookie_buf.substring(i,j) == label) {
                        var cEnd = cookie_buf.indexOf(";",j)
                        if (cEnd ==     -1) {
                                cEnd = cookie_buf.length
                        }
                        return unescape(cookie_buf.substring(j,cEnd))
                }
                i++
        }
        return ""
}
