
function getUrlPrefix(){
  return "pg="+clsFwsPg+"&tg=AT-";
}

////////////////////////////////////////////////////
// ccAttendanceUtil.js
// Contains some extending codes for core datatype
// and HashMap type complete defination
// March 1, 2006 by Gil
////////////////////////////////////////////////////

function DocumentUtil(){

  this.agt = navigator.userAgent.toLowerCase(); //user agent
  this.apn = navigator.appName; // application
  this.apv = navigator.appVersion.toLowerCase();
  this.vn; //version
  this.isSA = this.agt.indexOf("safari") != -1;

  this.ie=window.ActiveXObject;
  this.Mozilla=document.implementation.createDocument;
  this.lclXmlDoc = null;

  //members
  //methods
  this.getStrToDocument = function(xmlString) {
    var myDocument;
    if (this.Mozilla){
      // Mozilla, create a new DOMParser
      var parser = new DOMParser();
      myDocument = parser.parseFromString(xmlString, "text/xml");
      var serializer = new XMLSerializer();
      var sss = serializer.serializeToString(myDocument);

    } else if (this.ie){
      // Internet Explorer, create a new XML document using ActiveX
      // and use loadXML as a DOM parser.
      myDocument = new ActiveXObject("Microsoft.XMLDOM");
      myDocument.async = "false";
      myDocument.loadXML(xmlString);

    } else {
      return null;
    }
    return myDocument;
  }

  this.getDomToStr = function(dxml){
    if (this.Mozilla){
      var serializer = new XMLSerializer();
      var sss = serializer.serializeToString(dxml);
      return sss;
    }else if (this.ie){
      return dxml.xml;
    }else{
      return null;
    }
  }
  this.selectNodes = function(dom,node,xpath) {
    if (this.Mozilla){

      return dom.evaluate(xpath, node, null, XPathResult.ANY_TYPE, null);
    }else if (this.ie){
      return node.selectNodes(xpath);
    }else{
      return null;
    }
  }
  this.selectSingleNode = function(dom,node,xpath) {
    if (this.Mozilla){

      var re = dom.evaluate(xpath, node, null, XPathResult.ANY_TYPE, null);
      if(re!=null){
        return  re.iterateNext();
      }
      return null;
    }else if (this.ie){
      return node.selectSingleNode(xpath);
    }else{
      return null;
    }
  }

  this.getNodeValue = function(node) {
    if (this.Mozilla){
      try{
        return node.textContent;
      }catch(XPathException){
        return null;
      }
    }else if (this.ie){
      return node.text;
    }else{

    return null;
    }
  }
  this.setNodeValue = function(node,value) {
    if (this.Mozilla){
      node.textContent = value ;
    }else if (this.ie){
      node.text = value ;
    }
  }
  this.next = function(nodes,i){
    if (this.Mozilla){
      var re  = nodes.iterateNext();
      return re;
    } else if (this.ie){
      if(i > nodes.length || i == nodes.length ) {
        return null;
      }
      return nodes.item(i);
    } else {
      return false;
    }
  }

  this.setNodeHTML = function(node,txt){
    if (this.Mozilla){
      node.innerHTML = txt;
    } else if (this.ie){
      node.innerHTML = txt;
    } else {}
  }

  this.setAttribute =function(node,name,value){
    try{
      if (this.Mozilla){
        var c= document.createAttribute(name);
        c.value = value;
        node.setAttributeNode(c);
      } else if (this.ie){
        node.setAttribute(name,value);
      } else if (this.isSA){
        eval(node + "." + name + " = " + value + ";");
      }else {
        var c= document.createAttribute(name);
        c.value = value;
        node.setAttributeNode(c);
      }
    }catch(egb){}
  }

  this.getAttribute =function(node,name){
    try{
      if (this.Mozilla){
        return node.attributes.getNamedItem(name).textContent;
      } else if (this.ie){
        if(this.lclXmlDoc!=null){
          //var nodecols = null;
          //nodecols = this.docutil.selectNodes(this.xmldoc,row,col.filed);
          return node.attributes(name).value;
        }
        return this.selectSingleNode(node, "@" + name);//node.attributes(name).value;
      } else {
        return node.getAttribute(name);
      }
    }catch(ega){}
    return "";
  }

}


/**
 * core prototype extending
 * Date March 1, 2006
 */


//Object
Object.prototype.getClass=function(){
  //just work for system class
  var s=this.constructor.toString();
  try{
    return s.match(/function (\w+)\(.+/)[1];
  }catch(egb){
    s=Object.prototype.toString.apply(this);
    return s.match(/\[object (\w+)\]/)[1];
  }
}
Object.prototype.hashCode=function(){
  var h=0;
  var s=this.toString();
  for (var i = 0; i < s.length; i++) {
    h = 31*h + s.charCodeAt(i);
  }
  return h;
}
//protected used in subclass
Object.prototype.typeMatches=function(obj){
  return this.getClass()===obj.getClass();
}
//

Object.prototype.equals=function(obj){
  if(!this.typeMatches(obj)) return false;
  return this.toString()===obj.toString();
}

//String

String.prototype.equalsIgnoreCase=function(str){
  if(str.getClass()!="String") return false;
  return this.toUpperCase()===str.toUpperCase();
}
String.prototype.compareTo=function(str){
  if(!this.typeMatches(str)) throw "Type Mismacth!";
  var s1=this.toString();
  var s2=str.toString();
  if(s1===s2) return 0;
  else if(s1>s2) return 1;
  else return -1;
}
String.prototype.compareToIgnoreCase=function(str){
  if(!this.typeMatches(str)) throw "Type Mismacth!";
  var s1=this.toUpperCase();
  var s2=str.toUpperCase();
  if(s1===s2) return 0;
  else if(s1>s2) return 1;
  else return -1;
}


String.prototype.startsWith=function(prefix){
  return this.substring(0,prefix.length)==prefix;
}
String.prototype.endsWith=function(suffix){
  return this.substring(this.length-suffix.length)==suffix;
}

String.prototype.concat=function(str){
  return new String(this.toString()+str);
}

String.prototype.toCharArray=function(){
  var charArr=new Array();
  for(var i=0;i<this.length;i++) charArr[i]=this.charAt(i);
  return charArr;
}
String.prototype.trim=function(){
  return this.replace(/(^\s*)|(\s*$)/g,"");
}

//Number

Number.prototype.hashCode=function(){
  //just for int,not for double
  return (this);
}
Number.prototype.equals=function(obj){
  if(!this.typeMatches(obj)) return false;
  return this.toString()==obj.toString();
}

Number.prototype.compareTo=function(obj){
  if(!this.typeMatches(obj)) return false;
  return this-obj;
}
Number.toHexString=function(i){
  return i.toString(16);
}
Number.toBinaryString=function(i){
  return i.toString(2);
}

//Date

Date.prototype.hashCode=function(){
  var l=this.getTime();
  var s=Number.toHexString(l);

  var high=0;
  if(s.length>8) high=parseInt(s.substring(0,s.length-8),16);

  var low=l & 0xffffffff;
  return low^high;
}
Date.prototype.equals=function(obj){
  if(!this.typeMatches(obj)) return false;
  return this.getTime()==obj.getTime();
}

Date.prototype.compareTo=function(obj){
  if(!this.typeMatches(obj)) return false;
  return (this.getTime()-obj.getTime())& 0xffffffff;
}

//Array extending
Array.prototype.findValue = function(val, step){
  var rtn = -1;
  //var
  var currDCLen = this.length;
  if (currDCLen != 0){
    if(step == null || step == 0){
      step = 1;
    }
    for(var i = 0; i<currDCLen; i+=step){
      if(this[i]==val){
        rtn=i;
        break;
      }
    }
  }
  return rtn;
}

Array.prototype.containsValue = function(val) {
  var currDCLen = this.length;
  var rtn = false;
  if (currDCLen != 0){
    for(var i = 0; i<currDCLen; i++){
      if(this[i]==val){
        rtn=true;
        break;
      }
    }
  }
  return rtn;
}


/**
 * hashmap defining
 * Date: March 1, 2006
 */

//HashMap
function HashMap()
{
  //private:
  this.len=8;
  this.table=new Array();
  this.length=0;
  this.hash= function(x){
    var h = x.hashCode();
    h += ~(h << 9);
    h ^=  (h >>> 14);
    h +=  (h << 4);
    h ^=  (h >>> 10);
    return h;
  }

  this.rehash=rehash;
  function rehash() {

    var oldTable = this.table;

    this.table=new Array();

    //transfer
    for (var i = 0; i< oldTable.length; i++) {
      var e = oldTable[i];
      if (e != null) {
        oldTable[i] = null;
        do {
          var next = e.next;
          var j = this.indexFor(e.hash);
          e.next = this.table[j];
          this.table[j] = e;
          e = next;
        } while (e != null);
      }
    }

  }



  this.indexFor=indexFor;
  function indexFor(h) {

    var index= h & (this.len-1);
    return index;
  }

  function Entry(h,k,v,n){

    this.value = v;
    this.next = n;
    this.key = k;
    this.hash = h;

    this.getKey=getKey;
    function getKey() {
      return this.key;
    }

    this.getValue=getValue;
    function getValue() {
      return this.value;
    }
    this.setValue=setValue;
    function setValue(newValue) {
      var oldValue = this.value;
      this.value = newValue;
      return oldValue;
    }

    this.equals=equals;
    function equals(o) {
      var e = o;
      var k1 = this.getKey();
      var k2 = e.getKey();
      var v1 = this.getValue();
      var v2 = e.getValue();
      return (k1.equals(k2) && v1.equals(v2));
    }

    this.hashCode=hashCode;
    function hashCode() {
      return this.key.hashCode() ^ this.value.hashCode();
    }

    this.toString=toString;
    function toString() {
      return this.getKey() + "=" + this.getValue();
    }
  }


  function HashIterator(table,index,ne){
    this.table=table;
    this.ne=ne;
    this.index=index;
    this.current=null;

    this.hasNext=hasNext;
    function hasNext() {
     return this.ne != null;
    }

    this.next=next;
    function next() {

      var e = this.ne;
      if (e == null)
        throw "No such Element";

      var n = e.next;
      var t = this.table;
      var i = this.index;
      while (n == null && i > 0)
          n = t[--i];
      this.index = i;
      this.ne = n;
      this.current=e;

      return this.current;
    }
  }


  //public:
  this.size=size;
  function size() {
    return this.length;
  }


  this.isEmpty=isEmpty;
  function isEmpty() {
      return this.length == 0;
  }

  this.get=get;
  function get(key) {
    var hash =this.hash(key);
    var i = this.indexFor(hash);

    var e = this.table[i];

    while (true) {
      if (e ==null)
        return null;
      if (e.hash == hash && key.equals(e.key))
        return e.value;
      e = e.next;
    }

  }

  this.containsKey=containsKey;
  function containsKey(key) {
    var hash = this.hash(key);
    var i = this.indexFor(hash);
    var e = this.table[i];

    while (e != null) {
      if (e.hash == hash && key.equals(e.key))
        return true;
      e = e.next;
    }
    return false;
  }


  this.put=put;
  function put(key,value) {
    var hash = this.hash(key);
    var i = this.indexFor(hash);

    for (var e = this.table[i]; e != null; e = e.next) {
      if (e.hash == hash && key.equals(e.key)) {
        var oldValue = e.value;
        e.value = value;
        return oldValue;
      }
    }

    this.addEntry(hash, key, value, i);

    var r=Math.ceil(this.length * 1.5);

    if(r > this.len){
      this.len= this.len << 1;
      this.rehash();
    }
    return null;
  }

  this.putAll=putAll;
  function putAll(map){
    var mod=false;
    for(var it=map.iterator();it.hasNext();){
      var e=it.next();
      if(this.put(e.getKey(),e.getValue())) mod=true;
    }
  }


  this.remove=remove;
  function remove(key) {
    var e = this.removeEntryForKey(key);

    return (e ==null ? null : e.value);
  }

  this.removeEntryForKey=removeEntryForKey;
  function removeEntryForKey(key) {
    var hash = this.hash(key);
    var i = this.indexFor(hash);

    var prev = this.table[i];
    var e = prev;

    while (e != null) {
      var next = e.next;
      if (e.hash == hash && key.equals(e.key)) {
        this.length--;
        if (prev.equals(e))
          this.table[i] = next;
        else
          prev.next = next;
        return e;
      }
      prev = e;
      e = next;
    }
    return e;
  }

  this.clear=clear;
  function clear() {
    for (var i = 0; i < this.table.length; i++)
      this.table[i] = null;
    this.length = 0;
  }

  this.containsValue=containsValue;
  function containsValue(value) {
    if (value == null) return false;

    var tab = this.table;
    for (var i = 0; i < tab.length ; i++)
      for (var e = tab[i] ; e != null ; e = e.next)
        if (value.equals(e.value))
          return true;
    return false;
  }

  this.addEntry=addEntry;
  function addEntry(hash, key, value, bucketIndex) {
    this.table[bucketIndex] = new Entry(hash, key, value, this.table[bucketIndex]);
    this.length++;
  }


  this.iterator=iterator;
  function iterator(){
    var i=this.table.length;

    var next=null;
    while(i>0 && next==null){
      next=this.table[--i];
    }

    return new HashIterator(this.table,i,next);
  }

  this.hashCode=hashCode;
  function hashCode(){
    var h=0;
    for(var it=this.iterator();it.hasNext();){
      h+=it.next().hashCode();
    }
    return h;
  }
  this.equals=equals;
  function equals(map){
    if(map.size()!=this.size()) return false;

    for(var it=this.iterator();it.hasNext();){

     var e=it.next();
     var key=e.getKey();
     var value=e.getValue();

     if(!value.equals(map.get(key))) return false

    }
    return true;
  }
}

//Fix special string for XML doc
function fixXml(str){
  try{
    return str.replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  }catch(e){return null;}
}

