var $ = {};
var $ = function(id){var result = null; try{result = document.getElementById(id);}catch(e){}; return result;}
$.GetRadioValue = function(name)
{
var _radios = document.getElementsByName(name);
for (var i=0; i<_radios.length; i++)
{
if(_radios[i].checked)
{
return _radios[i].value;
}
}
}
$._init = [];
$.Templet = {};
$.Templet.option = function(data){
var _width = data.width;
var templet = "";
var _icon = "/Style/Images/space.gif";
if (!$.IsNull(data.icon) && data.type != "line") _icon = data.icon;
switch (data.type)
{
case "line":
templet = '
';
break;
case "text":
templet = '' + data.text + '
';
break;
case "link":
var _url = 'javascript:;';
if (!$.IsNull(data.url)) _url = data.url;
var _target = "_blank";
if (!$.IsNull(data.target)) _target = data.target;
templet = '';
break;
case "html":
templet = '' + data.html + '
';
break;
}
return templet;
};
/*------------------------------------ bof utils ----------------------------------------------------------------------------*/
String.prototype.Trim=function(){return this.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+$)/g, "")};
String.prototype.len=function(){return this.replace(/[^\x00-\xff]/g,"rr").length;};
String.prototype.HtmlEncode = function() { return this.replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>'); };
String.prototype.sub = function(n)
{
var r = /[^\x00-\xff]/g;
if(this.replace(r, "mm").length <= n) return this+"";
var m = Math.floor(n/2);
for(var i=m; i=n)
{
return this.substr(0, i);
}
}
return this+"";
};
/*------------------------------------ eof base ----------------------------------------------------------------------------*/
$.CopyClip = function(meintext){
if (window.clipboardData){ window.clipboardData.setData("Text", meintext);} else if (window.netscape){
try
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
}
catch (e)
{
$.alert("你使用的FF浏览器,复制功能被浏览器拒绝!\r\n请在浏览器地址栏输入'about:config'并回车\r\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
};
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
var copytext=meintext;
str.data=copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid=Components.interfaces.nsIClipboard;
if (!clip) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);}
return false;
};
$.GetPageWidth = function GetPageWidth(){ var result = 0; result = window.screen.width; result -= 16; if(Browser.isIE) { result -= 4; } return result;}
$.GetPageHeight = function GetPageHeight(){ var result = 0; result = window.screen.height; result -= 115; if(Browser.isIE) { result -= 4; } return result;}
$.GetScrollTop = function() { var scrollTop=0; if(document.documentElement&&document.documentElement.scrollTop) scrollTop = document.documentElement.scrollTop; else if(document.body) scrollTop=document.body.scrollTop; return scrollTop; };
$.SetScrollTop = function(_top) { if($.IsNull(_top)) _top = 0; if(document.documentElement&&document.documentElement.scrollTop) top.documentElement.scrollTop = _top+"px"; else if(document.body) top.body.scrollTop = _top+"px";};
$.Init = function(){if (arguments.callee.done) return; arguments.callee.done = true;
document.body.onmousedown = function(){$.OnBlur()};for (var i=0,len=$._init.length; i= 0; z--)
{
if (node.childNodes[z].nodeName==tagName) arr.push(node.childNodes[z].id);
}
return arr;
};
$.CancelBubble = function(evt){var e=(evt)?evt:window.event; try{e.cancelBubble = true;} catch (e) {}};
$.R = function(){ return Math.floor(Math.random() * 1000) };
$.getIframe = function(iframeid){var frm = $(iframeid); if($.IsNull(frm)) return; return document.frames ? document.frames[iframeid].document : frm.contentDocument};
$.dyniframesize = function(iframeid) {
var frm = $(iframeid);
if($.IsNull(frm)) return;
var subWeb = $.getIframe(iframeid);
if(frm != null && subWeb != null) {
frm.height = subWeb.body.scrollHeight;
};
};
$.setIframeHeight = function(iframeid, height){
var frm = $(iframeid);
if($.IsNull(frm)) return;
var subWeb = $.getIframe(iframeid);
if(frm != null && subWeb != null) {
frm.height = height;
};
}
$.Void = function(){return false;};
$.IsNull = function(input){var result = true; if(input!=undefined && input!="undefined"){input = input + "";input = input.Trim();if(input != "" && input != null){result = false; }}; return result;};
$.GetItemIndexof = function(items, value, type){var result = -1; if ($.IsNull(type)) { type = 0; }; for (i=0; iindexof) {items.splice(indexof,1);} } };
$.DeleteItemValue = function (items, value) {var indexof = $.GetItemIndexof(items, value); if(indexof<0) return; $.DeleteItem(items, indexof);};
$.AddItem = function (items, item, indexof){ if($.IsNull(indexof)) { indexof = items.length; }; items.splice(indexof, 0, item);};
$.AddClassName = function(obj, css){ if (!$.IsNull(obj)) { var result = obj.className.Trim(); obj.className = result + " " + css;}};
$.RemoveClassName = function(obj, css){ if (!$.IsNull(obj)){ var result = obj.className.Trim(); var classNames = []; if (!$.IsNull(result)){classNames = result.split(" "); $.DeleteItemValue(classNames, css); obj.className = classNames.join(" ");}}};
$.findPosX = function (obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) {curleft += obj.x;} else { curleft = obj.offsetLeft}; return curleft; };
$.findPosY = function (obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) {curtop += obj.y;} else { curtop = obj.offsetTop}; return curtop; };
$.Hover = function(obj){$.AddClassName(obj, "hover");}
$.Out = function(obj){$.RemoveClassName(obj, "hover")};
$.IsBlur = false;
$.FloatBoxId = null;
$.HoverBlur = function(){ $.IsBlur = true;};
$.OutBlur = function(obj) {$.IsBlur = false; if (obj.isShow()) { obj.focus();}};
$.OnBlur = function(isForced){if(!$.IsBlur || isForced == 1) { if (!$.IsNull($.FloatBoxId)) { $($.FloatBoxId).hide(); $.IsBlur = false; if($.FloatBoxId == "OptionBox") $.ClearOption(); $.FloatBoxId = null}}};
$.OpenFloatBox = function (obj, boxid) {$.OnBlur(1); var box = $(boxid); box.show(); var top = $.findPosY(obj) + obj.offsetHeight; if ((top + box.offsetHeight) > document.body.offsetHeight) top = $.findPosY(obj) - box.offsetHeight - 4; var left = $.findPosX(obj); if($.GetPageWidth() < (left + box.offsetWidth)) left = $.GetPageWidth() - box.offsetWidth - 5; box.style.top = (top+4)+"px"; box.style.left = (left+4)+"px"; box.focus();$.FloatBoxId = boxid; box.onmousedown = function(e){$.CancelBubble(e);};};
$.OpenOptionBox = function(obj){$.OpenFloatBox(obj, "OptionBox");};
$.AddOption = function(option, isFirst){
if(isFirst==0) $("Options").innerHTML = ""; var _optionHtml = $.Templet.option(option); $("Options").insertAdjacentHTML("beforeend", _optionHtml);
};
$.AdjustmentOptionsBox = function(optionsBoxId){
if($.IsNull(optionsBoxId)) optionsBoxId = "Options";
var _optionsBox = $(optionsBoxId);
var _options = $.GetChildrenByTagName(_optionsBox, "LI");
var _optionWidth = 0;
for (var i=0,len=_options.length; i _optionWidth) _optionWidth = _option.offsetWidth; else _option.style.width = _optionWidth + "px";
}
if (_optionWidth > 0) _optionsBox.style.width = (_optionWidth + 3) + "px";
};
$.AdjustmentFloatBox = function (obj) {var box = $("OptionBox"); if(!box.isShow()) return; var top = $.findPosY(obj) + obj.offsetHeight; if ((top + box.offsetHeight) > document.body.offsetHeight) top = $.findPosY(obj) - box.offsetHeight - 4; var left = $.findPosX(obj); if($.GetPageWidth() < (left + box.offsetWidth)) left = $.GetPageWidth() - box.offsetWidth - 5; box.style.top = (top+4)+"px"; box.style.left = (left+4)+"px";};
$.ClearOption = function(){$("Options").innerHTML = '
';};
$.CloseOption = function(){$.OnBlur(1);};
$.makeRandomNumber = function(length){ var result = ""; for (var i=0; i1 && type<5) { if(result!="") { result += spaceMark; }; var hh = now.getHours(); if (hh < 10) result += '0'; result += hh; result += spaceMark; var m = now.getMinutes(); if (m < 10) result += '0'; result += m; result += spaceMark; var ss = now.getTime() % 60000; ss = (ss - (ss % 1000)) / 1000; if (ss < 10) result += '0'; result += ss; if(randomNumberLength>0) { result += spaceMark; result += $.makeRandomNumber(randomNumberLength); } } return result;};
$.alert = function(message, url){$.Thick.open({"type":"alert", "message":message, "url":url});};
$.tip = function(message){$.Thick.open({"type":"tip", "message":message});};
$.confirm = function(message, callback){$.Thick.open({"type":"confirm", "message":message, "callback":callback});};
$.popupLayer = function(content, width, height, isEsc){var _isEsc = false; if(isEsc == 1) _isEsc = true; $.Thick.open({"type":"html", "content":content, "width":width, "height":height, "isEsc":_isEsc});};
/*------------------------------------ eof base ----------------------------------------------------------------------------*/
/*------------------------------------ bof cookie ----------------------------------------------------------------------------*/
function Cookie() {var _c_obj = {};_c_obj.cookies = []; _c_obj.get = function(name) {_c_obj._reset();return _c_obj.cookies[name];}; _c_obj.expires = -1; _c_obj.path = '/'; _c_obj.domain = ''; _c_obj.secure = false; _c_obj.set = function() { var args = this.set.arguments; var _num = args.length; if (_num < 2) return; var _cookie = args[0] + '=' + escape(args[1]); var now = new Date(); if(_c_obj.expires>0) { var _expires = new Date(now.getTime() + _c_obj.expires*24*60*60*1000); if (_num >= 3) { _expires = new Date(now.getTime() + args[2]*24*60*60*1000);}; _cookie += ';expires=' + _expires.toUTCString();} var _path = _c_obj.path; if (_num >= 4) { _path = args[3];}; _cookie += ';path=' + _path; var _domain = _c_obj.domain; if (_num >= 5) { _domain = args[4];}; if (!$.IsNull(_domain)) { _cookie += ';domain=' + _domain; } var _secure = _c_obj.secure; if (_num >= 6) {_secure = args[5];}; if (_secure) { _cookie += ';secure'; }; document.cookie = _cookie; };_c_obj.remove = function(name){if ($.IsNull(name)) return; _c_obj.set(name,'', -1);}; _c_obj._reset = function() { var cookie = document.cookie.split(';'); var _num = cookie.length; for (var i = 0; i < _num; i++) { var _arr = cookie[i].split('='); var _name = _arr[0].Trim(); var _value = ''; if (!$.IsNull(_arr[1])) { _value = unescape(_arr[1].Trim());} _c_obj.cookies[_name] = _value; } }; _c_obj.clear = function() { var temp=document.cookie.split(";"); for(var i=0, len=temp.length; i>" + err.message)
}
}
function getGhostPos(arr, ghost) {
var ln = arr.length;
for (var z=0; z _maxX || d>_maxX+b.clientWidth/2) h = _maxX;
if(g > _maxY || c>_maxY+b.offsetHeight/2) g = _maxY;
}
b.root.style.left=h+"px";
b.root.style.top=g+"px";
b.lastMouseX=d;
b.lastMouseY=c;
b.root.onDrag(h,g,a.clientX+$.GetScroll().left,a.clientY+$.GetScroll().top);
return false;
},
"end":function(){
document.onmousemove=null;
document.onmouseup=null;
Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top));
Drag.obj=null;
},
"fixE":function(a){
if(typeof a=="undefined")a=window.event;
if(typeof a.layerX=="undefined")a.layerX=a.offsetX;
if(typeof a.layerY=="undefined")a.layerY=a.offsetY;
return a;
}
};
/*------------------------------------ eof drag ----------------------------------------------------------------------------*/
/*---------------------------------------------------- bof ajax -----------------------------------------------------------------------------*/
var queue = {};
var queueIndexof = 0;
var randomQueue = {};
var randomQueueIndexof = 0;
var newsListQueue = {};
var newsListQueueIndexof = 0;
function AjaxClass()
{
var gIsIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
this.xmlHttp;
var c = this;
this.url;
this.method = "GET";
this.async=true;
this.user;
this.password;
this.sendParameter=null;
this.parameters = "";
this.userCallback = null;
this.dataType = "text";
this.queueSort = null;
this.queueIndexof = 0;
this.callback = function(request, parameters)
{
if(request.readyState==4)
{
if (request.status == 200)
{
var result = null;
switch(this.dataType)
{
case "text":
result = request.responseText;
break;
case "xml":
result = request.responseXML;
break;
case "json":
try
{
result = eval("("+request.responseText+")");
}
catch(err)
{
var erroType=$.GetQueryString("et");
var message = "Erro Data!";
if (!$.IsNull(erroType)&&erroType=="full")
{
message = request.responseText;
}
result = {"status":0, "message":message};
}
break;
}
$.AjaxCallback(result, this.dataType, this.userCallback, parameters);
}
else
{
return;
var result = null;
switch(this.dataType)
{
case "text":
result = "Error: status code is " + request.status;
break;
case "json":
result = {status:0, message:"Error: status code is " + request.status, error:request.status}
break;
}
if(result!=null)
{
$.AjaxCallback(result, this.dataType, this.userCallback, parameters);
}
else
{
$.alert("Error: status code is " + request.status);
}
}
}
}
if(window.XMLHttpRequest) this.xmlHttp=new XMLHttpRequest();
if(!this.xmlHttp&&window.ActiveXObject)
{
try
{
this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.5.0")
}
catch(e)
{
try
{
this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.4.0")
}
catch(e)
{
try
{
this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e)
{
try
{
this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}catch(e){}
}
}
}
}
this.open = function()
{
this.xmlHttp.open(this.method, this.url, this.async);
if (this.method=="POST")
{
var len = 0;
if (!$.IsNull(this.sendParameter))
{
len = this.sendParameter.length;
};
this.xmlHttp.setRequestHeader("Content-Length", len);
this.xmlHttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
}
if(this.async)
{
this.xmlHttp.onreadystatechange = function()
{
if(c.xmlHttp.readyState == 4)
{
try
{
c.callback(c.xmlHttp, c.parameters);
}
catch (err)
{
}
c.xmlHttp.abort();
c.xmlHttp = null;
var queueLength = 0;
switch (c.queueSort)
{
case 0:
DeleteQueue(randomQueue, c.PRI, c.queueIndexof);
queueLength = GetQueueLength(randomQueue);
break;
case 1:
DeleteQueue(queue, c.PRI, c.queueIndexof);
queueLength = GetQueueLength(queue);
break;
case 2:
DeleteQueue(newsListQueue, c.PRI, c.queueIndexof);
queueLength = GetQueueLength(newsListQueue);
if (queueLength<=0)
{
queueLength = GetQueueLength(randomQueue);
c.queueSort = 0;
}
break;
}
if (queueLength>0)
{
ExecuteQueue(c.queueSort);
}
}
}
}
this.sendParameter = this.sendParameter;
this.xmlHttp.send(this.sendParameter);
}
}
function AddQueue(sort, json)
{
var pri = json.PRI;
if ($.IsNull(pri))
{
pri = 1;
json.PRI = 1;
}
if ($.IsNull(randomQueue[pri]))
{
randomQueue[pri] = [];
}
switch (sort)
{
case 0:
if ($.IsNull(randomQueue[pri]))
{
randomQueue[pri] = [];
}
$.AddItem(randomQueue[pri], json);
break;
case 1:
if ($.IsNull(queue[pri]))
{
queue[pri] = [];
}
$.AddItem(queue[pri], json);
break;
case 2:
if ($.IsNull(newsListQueue[pri]))
{
newsListQueue[pri] = [];
}
$.AddItem(newsListQueue[pri], json);
break;
}
}
function GetQueueLength(queue)
{
var count = 0;
for (var pri in queue)
{
count += queue[pri].length;
}
return count;
}
function GetQueuePRI(queue)
{
var pris = [];
for (var pri in queue)
{
if (queue[pri].length>0)
{
$.AddItem(pris, pri);
}
}
pris = pris.sort(function(b, a){ return a-b; });
return pris;
}
function GetQueueIndexof(queue, json)
{
var pris = GetQueuePRI(queue);
var indexof = 0;
for (var i=0; iindexof)
{
json = jsons[indexof];
}
}
return json;
}
function GetQueue(sort)
{
var json = null;
switch (sort)
{
case 1:
if(GetQueueLength(queue)>0)
{
var pris = GetQueuePRI(queue);
json = GetQueueJson(queue, pris[0], 0);
json.indexof = 0;
json.sort = 1;
break;
}
case 0:
case 2:
if(GetQueueLength(newsListQueue)>0)
{
var pris = GetQueuePRI(newsListQueue);
json = GetQueueJson(newsListQueue, pris[0], 0);
json.indexof = 0;
json.sort = 2;
}
else
{
if (GetQueueLength(randomQueue)>0)
{
var pris = GetQueuePRI(randomQueue);
var pri = pris[0];
var jsons = randomQueue[pri]
var indexof = Math.floor(Math.random() * jsons.length);
json = jsons[indexof];
json.indexof = indexof;
json.sort = 0;
}
}
break;
}
return json;
}
$.Ajax = function(json, sort)
{
var length = 0;
AddQueue(sort, json);
switch (sort)
{
case 0:
length = GetQueueLength(newsListQueue) + GetQueueLength(randomQueue);
break;
case 1:
length = GetQueueLength(queue);
break;
case 2:
length = GetQueueLength(newsListQueue) + GetQueueLength(randomQueue);
break;
}
if ($.IsNull(sort))
{
alert(json.url);
}
else
{
if(length==1)
{
ExecuteQueue(sort);
}
}
}
$.AjaxCallback = function(data, dataType, userCallback, parameters)
{
if(userCallback!=null)
{
if(!$.IsNull(String(parameters)))
{
userCallback(data, parameters);
}
else
{
userCallback(data);
}
}
}
function ExecuteQueue(sort)
{
var json = GetQueue(sort);
if(json != null)
{
var url = "";
if(!$.IsNull(json.url)) url = json.url ;else return;
var async = false;
if(!$.IsNull(json.async)) async = json.async;
var dataType = "text";
if(!$.IsNull(json.dataType)) dataType = json.dataType;
var method = "GET";
if(!$.IsNull(json.method)) method = json.method;
var parameter = null;
if(!$.IsNull(json.data)) parameter = json.data; else method = "GET";
var userCallback = null;
if(!$.IsNull(json.userCallback)) userCallback = json.userCallback;
var parameters = "";
if(!$.IsNull(json.parameters)) parameters = json.parameters;
var pri = 1;
if(!$.IsNull(json.PRI)) pri = json.PRI;
var ajax = new AjaxClass();
ajax.queueSort = json.sort;
ajax.queueIndexof = json.indexof;
ajax.url = url;
ajax.sendParameter = parameter;
ajax.method = method;
ajax.asnc = async;
ajax.dataType = dataType;
ajax.parameters = parameters;
ajax.PRI = pri;
ajax.userCallback = userCallback;
ajax.open();
}
}
function ClearQueue(sort)
{
if(!$.IsNull(sort))
{
if(sort==2)
{
newsListQueue = {};
}
else
{
queue = {};
}
}
else
{
randomQueue = {};
}
}
function ClearAllQueue()
{
ClearQueue(2);
// ClearQueue(0);
// ClearQueue();
}
/*---------------------------------------------------- eof ajax -----------------------------------------------------------------------------*/
/*---------------------------------------------------- bof formValidator ------------------------------------------------------------------------*/
var regexEnum =
{
intege:"^-?[1-9]\\d*$",
intege1:"^[1-9]\\d*$",
intege2:"^-[1-9]\\d*$",
num:"^([+-]?)\\d*\\.?\\d+$",
num1:"^[1-9][0-9]{0,}$",
num2:"^-[1-9]\\d*|0$",
decmal:"^([+-]?)\\d*\\.\\d+$",
decmal1:"^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$",
decmal2:"^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$",
decmal3:"^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$",
decmal4:"^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$",
decmal5:"^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$",
email:"^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$",
color:"^[a-fA-F0-9]{6}$",
url:"^http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$",
chinese:"^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$",
ascii:"^[\\x00-\\xFF]+$",
zipcode:"^\\d{6}$",
mobile:"^(13|15)[0-9]{9}$",
ip4:"^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$",
notempty:"^\\S+$",
picture:"(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$",
rar:"(.*)\\.(rar|zip|7zip|tgz)$",
date:"^\\d{4}(\\-|\\/|\.)\\d{1,2}\\1\\d{1,2}$",
qq:"^[1-9]*[1-9][0-9]*$",
tel:"(\\d{3}-|\\d{4}-)?(\\d{8}|\\d{7})",
username:"^\\w+$",
letter:"^[A-Za-z]+$",
letter_u:"^[A-Z]+$",
letter_l:"^[a-z]+$",
idcard:"^[1-9]([0-9]{14}|[0-9]{17})$"
}
$.formValidator = function(formid){
var _f_v = {};
_f_v.formid = null;
_f_v.forms = {};
_f_v.validCount = 0;
_f_v.isValid = true;
_f_v.errorIds = [];
_f_v.verifing = 0;
_f_v.valid = function(){
_f_v.validCount = 0;
_f_v.isValid = true;
_f_v.errorIds = [];
_f_v.verifing = 0;
for (var key in _f_v.forms)
{
var _form = _f_v.forms[key];
if($.IsNull(_form.verifyStatus)) _form.verifyStatus = -2;
switch (_form.verifyStatus)
{
case -2:
_f_v.isValid = false;
_f_v.verifyForm(_form, true);
_f_v.verifing++;
break;
case -1:
_f_v.isValid = false;
_f_v.verifing++;
break;
case 0:
_f_v.isValid = false;
$.AddItem(_f_v.errorIds, _form.id);
break;
case 1:
break;
}
};
_f_v.sumbit();
};
_f_v.onSubmit = function(isSubmit){
var _isSumbit = false;
if(!$.IsNull(isSubmit)) _isSumbit = isSubmit;
if(!_isSumbit) return;
_f_v.valid();
};
_f_v.sumbit = function(){
if (_f_v.isValid)
{
if(!$.IsNull(_f_v.formid))
{
var _form = $(_f_v.formid);
if(!$.IsNull(_form)) _form.submit();
_f_v.isValid = false;
}
}
else
{
if(_f_v.verifing<=0 && _f_v.errorIds.length>0)
{
var _errorLables = [];
for (var i=0,len=_f_v.errorIds.length; i 0) top.$.alert(_errorLables.join(",") + '等' +_f_v.errorIds.length + '项输入未通过验证,请校证后重新提交'); else top.$.alert('您有' + _f_v.errorIds.length + '项输入未通过验证,请校证后重新提交');
}
}
};
_f_v.verifyForm = function(form, isSubmit){
if($.IsNull(form)) return true;
form.verifyStatus = -1;
var _f = $(form.id);
var _f_tip = $(form.id + "_tip");
var _correct = "";
var _ajaxValidator = null;
if(!$.IsNull(form.inputValidator))
{
for (var key in form.inputValidator)
{
var _validator = form.inputValidator[key];
switch (key)
{
case "Len":
var result = _f_v.verifyLen(form.id, _validator);
if(!result.status) {_f_v.showErrorTip(form.id, result.onerror); return;}
break;
case "Regex":
var result = _f_v.verifyRegex(form.id, _validator);
if(!result.status) {_f_v.showErrorTip(form.id, result.onerror); return;}
break;
case "Fun":
var result = _f_v.verifyFun(form.id, _validator);
if(!result.status) {_f_v.showErrorTip(form.id, result.onerror); return;}
break;
case "Compare":
var result = _f_v.verifyCompare(form.id, _validator);
if(!result.status) {_f_v.showErrorTip(form.id, result.onerror); return;}
break;
case "Ajax":
_ajaxValidator = _validator;
break;
};
};
};
if (!$.IsNull(_ajaxValidator))
{
_f_v.verifyAjax(form.id, _validator, isSubmit);
return;
};
_f_v.showCorrectTip(form.id);
_f_v.onSubmit(isSubmit);
};
_f_v.showCorrectTip = function(id){
var _form = _f_v.forms[id];
_form.verifyStatus = 1;
var _f = $(id);
var _f_tip = $(id + "_tip");
var _correct = "";
if(!$.IsNull(_form.oncorrect)) _correct = _form.oncorrect;
_f_tip.innerHTML = '
' + _correct;
_f_tip.className = 'tipCorrect';
}
_f_v.showErrorTip = function(id, tip)
{
var _form = _f_v.forms[id];
var _f = $(id);
var _f_tip = $(id + "_tip");
_form.verifyStatus = 0;
_f_tip.innerHTML = '
' + tip;
_f_tip.className = 'tipError';
};
_f_v.verifyAjax = function(id, validator, isSubmit)
{
var _result = {};
_result.status = true;
var _value = $(id).value.Trim();
var _url = validator.url;
if($.IsNull(_url) || $.IsNull(_value)) {
_f_v.showCorrectTip(id);
_f_v.onSubmit(isSubmit);
return;
};
var _f_tip = $(id + "_tip");
_f_tip.innerHTML = '
正在验证....';
_f_tip.className = 'tipLoading';
if($.IsNull(isSubmit)) isSubmit = false;
var _postData = validator.key + "=" + escape(_value);
$.Ajax({"url":_url, "method":"POST", dataType:"json", "async":true, "data":_postData, "userCallback":_f_v.verifyAjaxCallback, "parameters":{"isSubmit":isSubmit, "onerror":validator.onerror, "id":id}}, 1);
};
_f_v.verifyAjaxCallback = function(data, params){
if (data.status == 1)
{
_f_v.showCorrectTip(params.id);
_f_v.onSubmit(params.isSubmit);
}
else
{
_f_v.showErrorTip(params.id, params.onerror);
}
};
_f_v.verifyCompare = function(id, validator)
{
var _result = {};
_result.status = true;
var _value = $(id).value.Trim();
if($.IsNull(validator.desID)) return _result;
var _d_value = $(desID).value.Trim();
var _operateor = "=";
if(!$.IsNull(validator.operateor)) _operateor = "=";
switch (_operateor)
{
case "=":
_result.status = (_value == _d_value);
break;
case "!=":
_result.status = (_value != _d_value);
break;
case ">":
_result.status = (_value > _d_value);
break;
case ">=":
_result.status = (_value >= _d_value);
break;
case "<":
_result.status = (_value < _d_value);
break;
case "<=":
_result.status = (_value <= _d_value);
break;
case "oneok":
_result.status = (!$.IsNull(_value) || !$.IsNull(_d_value));
break;
}
if(!_result.status) _result.onerror = validator.onerror;
return _result;
};
_f_v.verifyFun = function(id, validator)
{
var _result = {};
_result.status = true;
_result.status = validator.callback();
if(!_result.status) _result.onerror = validator.onerror;
return _result;
}
_f_v.verifyRegex = function(id, validator)
{
var _result = {};
_result.status = true;
var _value = $(id).value.Trim();
var _regexp = validator.regexp;
if(!$.IsNull(regexEnum[_regexp])) _regexp = regexEnum[_regexp];
_result.status = $.IsMatch(_value, _regexp);
if(!_result.status) _result.onerror = validator.onerror;
return _result;
};
_f_v.verifyLen = function(id, validator){
var _result = {};
_result.status = true;
var _value = $(id).value.Trim();
var _len = _value.len();
if(!$.IsNull(validator.min)) if(_lenvalidator.max) _result.status = false;
if(!_result.status) _result.onerror = validator.onerror;
return _result;
}
_f_v.formInit = function(form){
if($.IsNull(form)) return true;
var _f = $(form.id);
var _f_tip = $(form.id + "_tip");
if(!$.IsNull(form.onshow)) {
_f_tip.innerHTML = '
' + form.onshow;
_f_tip.className = 'tipShow';
};
if(!$.IsNull(form.onfocus)) {
_f.onfocus = function(){
_f_tip.innerHTML = '
' + form.onfocus;
_f_tip.className = 'tipFocus';
};
};
_f.onblur = function(){_f_v.verifyForm(form)};
_f_v.forms[form.id] = form;
};
_f_v.init = function(formid){
_f_v.formid = formid;
$(formid).onsubmit = function(){
_f_v.valid();
return false;
};
};
_f_v.init(formid);
return _f_v;
}
/*----------------------------------------- eof formValidator -----------------------------------------------------------------------------*/
/*----------------------------------------- bof XML -----------------------------------------------------------------------------*/
if(document.implementation && document.implementation.createDocument)
{
XMLDocument.prototype.loadXML = function(xmlString)
{
var childNodes = this.childNodes;
for (var i = childNodes.length - 1; i >= 0; i--)
this.removeChild(childNodes[i]);
var dp = new DOMParser();
var newDOM = dp.parseFromString(xmlString, "text/xml");
var newElt = this.importNode(newDOM.documentElement, true);
this.appendChild(newElt);
};
// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; }
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshotLength; i++)
{
aResult[i] = aItems.snapshotItem(i);
}
return aResult;
}
// prototying the Element
Element.prototype.selectNodes = function(cXPathString)
{
if(this.ownerDocument.selectNodes)
{
return this.ownerDocument.selectNodes(cXPathString, this);
}
else{throw "For XML Elements Only";}
}
}
// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; }
var xItems = this.selectNodes(cXPathString, xNode);
if( xItems.length > 0 )
{
return xItems[0];
}
else
{
return null;
}
}
// prototying the Element
Element.prototype.selectSingleNode = function(cXPathString)
{
if(this.ownerDocument.selectSingleNode)
{
return this.ownerDocument.selectSingleNode(cXPathString, this);
}
else
{
throw "For XML Elements Only";
}
}
}
}
$.GetNodeValue = function(obj)
{
var str = "";
if(window.ActiveXObject) //IE
{
str = obj.text;
}
else //Mozilla
{
try
{
str = obj.childNodes[0].nodeValue;
}
catch(ex)
{
str = "";
}
}
return str;
}
$.GetValue = function(xmlDoc, xPath)
{
var result = "";
if(!xPath)
{
if (xmlDoc.nodeType==1)
{
if(xmlDoc.childNodes.length>0)
{
result = xmlDoc.childNodes[0].nodeValue;
}
}
}
else
{
result = $.GetNodeValue(xmlDoc.selectSingleNode(xPath));
}
return result;
}
$.GetAttribute = function (xmlDoc, xPath)
{
var result = "";
if(!xPath)
{
result = xmlDoc.value;
}
else
{
result = xmlDoc.selectSingleNode(xPath).value;
}
return result;
}
/*---------------------------------------------------- eof XML -----------------------------------------------------------------------------*/
$.RegisterInit = function(callback){if(!$.IsNull(callback)) $.AddItem($._init, callback);};
/* for Mozilla */
if (document.addEventListener) {document.addEventListener("DOMContentLoaded", $.Init, false);};
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("