
var MORE = 'More ...';
var LESS = 'Less ...';
var SHOW = '(Show)';
var HIDE = '(Hide)';
var PLUS = "/image/plus.gif";
var MINUS = "/image/minus.gif";

function showMore(n)
{
  var row = document.getElementById('row' + n);
  var lbl = document.getElementById('lbl' + n);

  if (row.style.display == '')
  {
    row.style.display = 'none';
    lbl.innerHTML = MORE;
  }
  else
  {
    row.style.display = '';
    lbl.innerHTML = LESS;
  }
}



function uploadFile(str)
{
  window.open(str, "dialog", "left=200,top=200,width=430,height=200,menu=no,scrollbars=yes");
}

function doBrief(str)
{
  window.open(str, "dialog", "left=0,top=50,width=800,height=450,menu=no,scrollbars=yes");
}


function switchBox(obj, prefix, id)
{
  var row = document.getElementById(prefix + id);
  if (!row) return;
  if (row.style.display == '')
  {
    row.style.display = 'none';
    obj.src = PLUS
  }
  else
  {
    row.style.display = '';
    obj.src = MINUS
  }
}



function getOffSet(obj)
{
  var top = obj.offsetTop;
  var left = obj.offsetLeft;
  while (obj = obj.offsetParent)
  {
    top += obj.offsetTop;
    left += obj.offsetLeft;
  }
  var rec = new Array(1);
  rec[0] = top;
  rec[1] = left;
  return rec
}


function SetCookie(obj, name)
{
  if (obj.checked)
  {
    var expdate = new Date();
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if (expires != null) expdate.setTime(expdate.getTime() + ( expires * 100000 ));
    document.cookie = name + "=true" + ((expires == null) ? "" : ("; expires=" + expdate.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
  }
  else
  {
    DelCookie(name);
  }

}

function DelCookie(name)
{
  //删除Cookie
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  document.cookie = name + "=; expires=" + exp.toGMTString();
}

function getURLParam(url, key)
{
  var reg = new RegExp("(^|\\?|&)" + key + "=([^&]*)(\\s|&|$)", "i");
  if (reg.test(url)) return RegExp.$2;
  return "";
}

function findInPage(str)
{
  var txt, i, found,n = 0;
  if (str == "")  return false;
  txt = window.document.body.createTextRange();
  for (i = 0; i <= n && (found = txt.findText(str)) != false; i++)
  {
    txt.moveStart("character", 1);
    txt.moveEnd("textedit");
  }
  if (found)
  {
    txt.moveStart("character", -1);
    txt.findText(str);
    txt.select();
    txt.scrollIntoView();
    n++;
  }
}

function highLight()
{
  var str = getURLParam(window.location, 'highLight');
  findInPage(str);
}



function HashMap()
{
  this.map = new Array();

  function struct(key,value)
  {
	  this.key = key;
	  this.value = value;
  }

  this.get = function(key)
  {
	  for (var i = 0; i < this.map.length; i++)
	  {
	    if ( this.map[i].key === key )
	    {
	      return this.map[i].value;
	    }
	  }
	  return null;
  };


  this.put = function (key, value)
  {
	  for (var i = 0; i < this.map.length; i++)
	  {
	    if ( this.map[i].key === key )
	    {
	      this.map[i].value = value;
	      return;
	    }
	  }
	  this.map[this.map.length] = new struct(key, value);
  };


  this.remove = function (key)
  {
	  var v;
	  for (var i = 0; i < this.map.length; i++)
	  {
	    v = this.map.pop();
	    if ( v.key === key )
	      continue;
	    this.map.unshift(v);
	  }
  };


  this.count = function(){return this.map.length;};
  this.isEmpty = function (){return this.map.length <= 0;};
}



function copyText(obj) 
{
 ie = (document.all)? true:false
 if (ie)
 {
  var rng = document.body.createTextRange(); //列出所有文本对象内容
  rng.moveToElementText(obj);//移动文本范围以便范围的开始和结束位置能够完全包含给定元素的文本
  rng.scrollIntoView();//scrollIntoView 将对象滚动到可见范围内，将其排列到
  rng.select();//选择
  rng.execCommand("Copy");//复制
  rng.collapse(false);
 }
}

function sortSelectByText(objId)
{
  var select = document.getElementById(objId)
  var ln = select.options.length;
  var arr = new Array();
  for (var i = 0; i < ln; i++)
  {
    arr[i] = new Array(select.options[i].text,select.options[i].value,select.options[i].selected);
  }

  arr.sort();

  for (var i = ln-1; i >=0 ; i--)
  {
	  select.remove(i);
  }
  var selectedIndex = 0;
  for (i = 0; i < arr.length; i++)
  {
    var option=document.createElement('option');
    option.text=arr[i][0];
    option.value=arr[i][1];
	if (arr[i][2])
	{
		selectedIndex = i;		
	}

    try
    {
      select.add(option,null); // standards compliant
    }
    catch(ex)
    {
      select.add(option); // IE only
    }
  }
  select.selectedIndex = selectedIndex;
}


function getObjOffSet(obj)
{
  var top = obj.offsetTop;
  var left = obj.offsetLeft;
  while (obj = obj.offsetParent)
  {
  top += obj.offsetTop;
  left += obj.offsetLeft;
  }
  var rec = new Array(1);
  rec[0] = top;
  rec[1] = left;
  return rec
}
