var OBJECT = "object", STRING = "string", NUMBER = "number", BOOLEAN = "boolean", FUNCTION = "function", NULL = "undefined";
var BODY = "BODY", DIV = "DIV", TABLE = "TABLE", TR = "TR", TD = "TD", INPUT = "INPUT", SELECT = "SELECT", TEXTAREA = "TEXTAREA";
var ENTER = 13;
var UNKNOWN = 0, NEW = 5, EDIT = 6, DELETE = 8;

function isObj(o) { return typeof o == OBJECT; }
function isString(v) { return typeof v == STRING; }
function isNumber(v) { return typeof v == NUMBER; }
function isBoolean(v) { return typeof v == BOOLEAN; }
function isFunction(v) { return typeof v == FUNCTION; }
function isNull(v) { return v == null || typeof v == NULL }
function isEmpty(v) { return isNull(v) || String(v) == ""; }

function val(v, d) { return v == null ? d : v; }
function str(v, d) { return v == null ? (d == null ? "" : d) : String(v); }

function obj(o) { return isObj(o) ? o : document.getElementById(o); }
function objs(o) { return isObj(o) ? o : document.getElementsByName(o); }
function tag(o) { return isObj(o) ? o.tagName : null; }

function parentObj(o) { return obj(o).parentNode; }
function nextObj(o) { return obj(o).nextSibling; }
function previousObj(o) { return obj(o).previousSibling; }
function childObj(o) { return obj(o).firstChild; }

function click(o) { try { obj(o).click(); } catch (e) { pe(e); } }
function focus(o) { try { obj(o).focus(); } catch (e) { pe(e); } }
function select(o) { try { obj(o).select(); } catch (e) { pe(e); } focus(o); }

function show(o) { try { obj(o).style.display = ""; } catch (e) { pe(e); } }
function hide(o) { try { obj(o).style.display = "none"; } catch (e) { pe(e); } }
function enable(o) { try { obj(o).disabled = false; } catch (e) { pe(e); } }
function disable(o) { try { obj(o).disabled = true; } catch (e) { pe(e); } }

function style(o, n) { try { var o = obj(o); if (n != null) o.className = n; return o.style; } catch (e) { pe(e); return null; } }
function html(o, s) { try { var o = obj(o); if (s != null) o.innerHTML = s; return o.innerHTML; } catch (e) { pe(e); return null; } }

function value(o, d) { try { return obj(o).value; } catch (e) { return d; } }
function values(o) { var vs = new Array(); var os = objs(o); for (var i = 0; i < os.length; i++) { try { vs.push(os[i].value); } catch (e) { pe(e); } } return vs; }

function clear(o) { try { obj(o).value = ""; } catch (e) { pe(e); } }
function length(o) { try { return obj(o).value.length; } catch (e) { pe(e); } }

function encode(s) { return encodeURIComponent(s); }
function param(o, n) { var v = value(o); try { return isEmpty(v) ? "" : "&" + (n == null ? o : n) + "=" + encode(v); } catch (e) { pe(e); return ""; } }
function params(o, n) { var s = ""; var os = objs(o); for (var i = 0; i < os.length; i++) { try { var v = os[i].value; s += isEmpty(v) ? "" : "&" + (n == null ? o : n) + "=" + encode(v); } catch (e) {} } return s; }

function locate(u, t) { (t == null ? window : t).location.href = str(u); }
function submit(u, t, f) { var f = obj(f) || document.forms[0]; f.action = str(u); f.target = str(t); f.method = "post"; f.submit(); }
function reset(f) { f = obj(f) || document.forms[0]; f.reset(); }
function openwin(u, t, p) { return window.open(str(u), str(t, "_blank"), str(p)); }
function closewin() { window.close(); }
function focuswin() { document.focus(); }

function isBody(o) { try { return tag(o) == BODY; } catch (e) { return false; } }
function isDiv(o) { try { return tag(o) == DIV; } catch (e) { return false; } }
function isTable(o) { try { return tag(o) == TABLE; } catch (e) { return false; } }
function isTr(o) { try { return tag(o) == TR; } catch (e) { return false; } }
function isTd(o) { try { return tag(o) == TD; } catch (e) { return false; } }
function isInput(o) { try { return tag(o) == INPUT; } catch (e) { return false; } }
function isSelect(o) { try { return tag(o) == SELECT; } catch (e) { return false; } }
function isTextArea(o) { try { return tag(o) == TEXTAREA; } catch (e) { return false; } }
function isFormObj(o) { return (isInput(o) || isSelect(o) || isTextArea(o)) && !isEmpty(o.name); }

function parentDiv(o) { while (!isDiv(o) && !isBody(o)) o = parentObj(o); return o; }
function parentTable(o) { while (!isTable(o) && !isBody(o)) o = parentObj(o); return o; }
function parentTr(o) { while (!isTr(o) && !isBody(o)) o = parentObj(o); return o; }
function parentTd(o) { while (!isTd(o) && !isBody(o)) o = parentObj(o); return o; }
function enableTr(o) { try { var os = parentTr(o).all; for (var i = 0; i < os.length; i++) { if (isFormObj(os[i])) enable(os[i]) } } catch (e) { pe(e) } }
function disableTr(o) { try { var os = parentTr(o).all; for (var i = 0; i < os.length; i++) { if (parentObj(os[i]) == parentObj(o)) continue; if (isFormObj(os[i])) disable(os[i]) } } catch (e) { pe(e) } }
function checkTr(o) { try { o.checked ? enableTr(o) : disableTr(o); } catch (e) { pe(e) } }
function checkHidden(o) { try { o.nextSibling.value = o.checked ? 1 : 0 } catch (e) { pe(e) } }

function enter() { if (event.keyCode == ENTER) { event.returnValue = false; return true; } return false; }

function preload() { var d = document; if (d.images) { if(!d.p) d.p = new Array(); var i, j = d.p.length, a = preload.arguments; for (i = 0; i > a.length; i++) if (a[i].indexOf("#") != 0) { d.p[j] = new Image; d.p[j++].src = a[i]; } }
}

var _timer;
function wait(code, time, timer) { try { clearTimeout(timer == null ? _timer : timer); return _timer = setTimeout(code, time * 1000); } catch (e) { pe(e); } }
function repeat(code, time, timer) { try { stop(timer); return _timer = setInterval(code, time * 1000); } catch (e) { pe(e); } }
function stop(timer) { try { clearInterval(timer == null ? _timer : timer); } catch (e) { pe(e); } }

var _request, _response, _function;
function send(u, f, params) { if (window.XMLHttpRequest) _request = new XMLHttpRequest(); else if (window.ActiveXObject) _request = new ActiveXObject("Microsoft.XMLHTTP"); if (_request) { _function = f == null ? "doResponse" : f; _request.onreadystatechange = process; _request.open("post", u, true); _request.setRequestHeader("content-type","application/x-www-form-urlencoded"); _request.send(params); } }
function process() { var rs = _request.readyState; if (rs == 4) { _response = _request.responseText; eval(_function + "(_response)"); } }


function pe(e) {
	//alert(e.description);
}



function rw(str) {document.write(str);}

//Flash
function getFlashStr(id, url, width, height, bgcolor) {
	var s = '';
	s += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" align="middle">';
	s += '<param name="allowScriptAccess" value="sameDomain" />';
	s += '<param name="movie" value="'+url+'" />';
	s += '<param name="quality" value="high" />';
	s += '<param name="wmode" value="transparent" />';
	if (bgcolor) {
		s += '<param name="bgcolor" value="'+bgcolor+'" />';
	}
	s += '<embed src="'+url+'" quality="high" ';
	if (bgcolor) {
		s += 'bgcolor="'+bgcolor+'"';
	}
	s += 'width="'+width+'" height="'+height+'" swliveconnect="true" name="'+id+'" allowScriptAccess="sameDomain" quality="high" wmode="transparent" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	s += '</object>';
	return s;
}

function writeFlash(id, url, width, height, bgcolor) {
	rw(getFlashStr(id, url, width, height, bgcolor));
}

function getFlashObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function hasStr(txt, str) {return (txt.indexOf(str) != -1);}

function openWin(url, target, width, height,scrollbars) {
	var r = window.open(url, target == null ? "_blank" : target, "width=" + (width == null ? 564 : width) + ", height=" + (height == null ? 528 : height)+ ", scrollbars=" + (scrollbars == null ? "yes" : scrollbars) + ", toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=no");
	r.focus();
}

//input reg check
function regInput(obj, reg, inputStr) {
  var docSel = document.selection.createRange();
  if (docSel.parentElement().tagName != "INPUT") return false;
  oSel = docSel.duplicate();
  oSel.text = "";
  var srcRange = obj.createTextRange();
  oSel.setEndPoint("StartToStart", srcRange);
  var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
  return reg.test(str);
}
//check Number
//var ___regStr = /^\d*\.?\d{0,2}$/; //2位小数浮点数
var ___regStr = /^\d*$/; //整数
function doOnKeyPress(obj) {
	return regInput(obj, ___regStr,  String.fromCharCode(event.keyCode));
}

function doOnPaste(obj) {
	return regInput(obj, ___regStr,  window.clipboardData.getData('Text'));
}

function doOnDrop(obj) {
	return regInput(obj, ___regStr,  event.dataTransfer.getData('Text'));
}