//注册 studyez命名空间
var studyez=studyez ? studyez:{};
//注册工具类命名空间
studyez.tool=studyez.tool ? studyez.tool:{};
//常用的工具类
//注:本接口适合用提供工具类
studyez.tool.helper=studyez.tool.helper ? studyez.tool.helper: {
//注意:属性或是方法名之前不要加 this
version: "1.0.0",
$:function(id){
return document.getElementById(id);
},
addEvent:function(id,eventName,funName){
var o=$(id);
if(o){
o.attachEvent ? o.attachEvent("on"+eventName,funName):o.addEventListener(eventName,funName,false );
}
},
removeEvent:function(id,eventName,funName){
var o=$(id);
if(o){
o.detachEvent ? o.detachEvent("on"+eventName,funName ): o.removeEventListener(eventName ,funName ,false );
}
},
trimEnd:function(t){
//除掉尾部空格
return t.replace(//s*$/g, "");
},
trimStart:function(t){
//除掉首部空格
return t.replace(/^/s*/g, "");
},
trimEndStart:function(t){
//除掉首尾空格
return t.replace(/(^/s*)|(/s*$)/g, "");
},
trim:function(t){
//除掉所有的空格
return t.replace(//s*/g, "");
// return t.replace(/(^ *)|( *$)/g, "");
},
isInterger:function(t){
//最多12位正整数
return /^[1-9]/d{0,11}$/i.test(t);
},
isZero:function(t){
//判断是否为零
return /^0$/.test(t);
},
createXmlHttp:function(){
//创建XmlHttpRequest组件
//失败返回 null
var http=false ;
if(window.XMLHttpRequest){
http = new XMLHttpRequest();
}else if(window.ActiveXObject){
var arrXmlHttpTypes = ['MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'];
for(var i=0;i<arrXmlHttpTypes.length;i++){
try{
http = new ActiveXObject(arrXmlHttpTypes[i]);
}catch(ex){}//不支持MSXML.XMLHttp对象的IE
}
}
if(http)
return http;
else
return null;
} ,
setStyleClass:function(id,styleClass){
//设置元素的 class属性值。
var o=$(id);
if(o){
o.setAttribute(window.attachEvent ? "className":"class",styleClass);
}
}
}
//哈希表的实现
studyez.tool.hashTable=function(){
this._hash = new Object;
this.add = function(key,value){
if(typeof(key) == "undefined")
return ;
if(this.contains(key))
return ;
this._hash[key] = typeof(value) == "undefined" ? null:value;
}
this.remove = function(key){
delete this._hash[key];
}
this.count = function(){
var i=0;
for(var k in this._hash){
i++;
}
return i;
}
this.items = function(key){
return this._hash[key];
}
this.contains = function(key){
return typeof(this._hash[key]) != "undefined";
}
this.clear = function(){
for(var k in this._hash){
delete this._hash[k];
}
}
}
//通用树结点定义
studyez.tool.treeNode=function(key,text,parentId,pri){
this.key=key ;
this.text=text;
this.parentId = parentId;
this.pri=pri;
this.parent=null;
var subs=new Array();
var dscCallback=function(node1,node2){
return node1.pri -node2.pri;
}
var ascCallback=function(node1,node2){
return node2.pri-node1.pri;
}
this.addSub=function(node){
if(!(node instanceof studyez.tool.treeNode))
return ;
if(node.parentId!=this.key)
return ;
node.parent=this;
subs.push(node);
}
this.sort=function(desc){
if(desc){
subs.sort(dscCallback);
} else {
subs.sort(ascCallback);
}
}
this.show=function(){
var len=subs.length;
var es="";
for(var i=0;i<len ;i ++){
es +=subs[i].key+",";
}
return es ;
}
this.subNode=function(){
return subs;
}
}
//括展原先的数据结构
studyez.tool.examTreeNode=function(key,text,parentId,pri,type){
studyez.tool.treeNode.call(this,key,text,parentId,pri);
this.type=type;
this.getType=function(){
return 10+this.type;
}
}
function createSubRadios(divId,cnt){
var dv=document.getElementById(divId);
for(var i=0;i<cnt ;i++){
var rdo;
if(window.attachEvent){
rdo = document.createElement("<input type=/'radio/' name=/'rdo/' value=/'" + i + "/' id=/'rdo" + i + "/'>");
} else {
alert("here");
rdo=document.createElement("input");
rdo.setAttribute("name","xx");
rdo.type="radio";
rdo.value=i;
}
dv.appendChild(rdo);
dv.appendChild(document.createTextNode(i));
}
}
function createSubCheckboxs(divId,cnt){
var dv=document.getElementById(divId);
for(var i=0;i<cnt ;i++){
var rdo;
rdo=document.createElement("input");
rdo.type="checkbox";
rdo.id=divId+"_sub_"+i;
rdo.value=i;
dv.appendChild(rdo);
dv.appendChild(document.createTextNode(i));
}
}
function ShowMsg(strMsg){
alert(strMsg);
}
function clear(){
var ts=document.getElementById("st1");
for(var i=0;i<ts.length;i ++){
ts[i].checked=false;
}
}