﻿
function ErrorAlert()
{
    switch (XMLHttpRequest.status)
    {
        case 500:
            FDMFrame.Alert("提示", "计算机已断开网络，请连接后重试");
            break;
        default:
            FDMFrame.Alert("提示", "您的操作可能引发异常请稍后重试");
            break;
    }
}
/*
window.alert=function(string)
{
	if(string&&typeof(string)!="object")
	    FDMFrame.Alert("警告",string.toString(),{name:"确定",script:""});
	else
	    FDMFrame.Alert("警告","[" + typeof(string) + "]",{name:"确定",script:""});
}
*/
if (window.isFocus == undefined)
{
    window.isFocus = true;
}
window.focus = new Function("window.isFocus=true");
window.blur = new Function("window.isFocus=false");
Array.prototype.p = function(key, val)
{
	if (val != null && key != null) this.push(key + "=" + val);
}

Array.prototype.toQueryString = function()
{
	return this.join("&");
}

String.format = function() 
{ 
	if(arguments.length == 0) return "";
	if(arguments.length == 1) return arguments[0];
	var reg = /{(\d+)?}/g;
	var args = arguments;
	var result = arguments[0].replace(reg, function($0, $1)
		{
			return args[parseInt($1)+1];
		})
	return result;
}
Array.prototype.getIndexByValue = function(value)
{
	return this.find(value);
}
Array.prototype.find = function(value)
{
	for(var i=0;i<this.length;i++)
	{
		if(this[i]==value)return i;
	}
	return -1;
}
String.prototype.isPhone = function()
{
	var p = /^0\d{10,11}$|^0\d{2}-\d{8}$|^0\d{3}-\d{7,8}$|^0\d{2}-\d{8}-\d{1,}$|^0\d{3}-\d{7,8}-\d{1,}$/;
	return p.test(this)
}
String.prototype.toZip = function() {
    var PhoneCodeString = this.trim();
    PhoneCodeString = PhoneCodeString.replace(/　/g, "");
    PhoneCodeString = PhoneCodeString.replace(/ /g, "");
    if (PhoneCodeString.length != 6) return null;
    PhoneCodeString = PhoneCodeString.replace(/０/g, "0");
    PhoneCodeString = PhoneCodeString.replace(/１/g, "1");
    PhoneCodeString = PhoneCodeString.replace(/２/g, "2");
    PhoneCodeString = PhoneCodeString.replace(/３/g, "3");
    PhoneCodeString = PhoneCodeString.replace(/４/g, "4");
    PhoneCodeString = PhoneCodeString.replace(/５/g, "5");
    PhoneCodeString = PhoneCodeString.replace(/６/g, "6");
    PhoneCodeString = PhoneCodeString.replace(/７/g, "7");
    PhoneCodeString = PhoneCodeString.replace(/８/g, "8");
    PhoneCodeString = PhoneCodeString.replace(/９/g, "9");
    if (!PhoneCodeString.isInt()) return null;
    return PhoneCodeString;
}
String.prototype.toPhone = function() {
    var PhoneCodeString = this.replace(/\\/g, " ");
    PhoneCodeString = PhoneCodeString.replace(/\//g, " ");
    PhoneCodeString = PhoneCodeString.replace("转", "-");

    PhoneCodeString = PhoneCodeString.replace(/　/g, " ");
    PhoneCodeString = PhoneCodeString.replace(/－/g, "-");
    PhoneCodeString = PhoneCodeString.replace(/＋/g, "+");
    PhoneCodeString = PhoneCodeString.replace(/０/g, "0");
    PhoneCodeString = PhoneCodeString.replace(/１/g, "1");
    PhoneCodeString = PhoneCodeString.replace(/２/g, "2");
    PhoneCodeString = PhoneCodeString.replace(/３/g, "3");
    PhoneCodeString = PhoneCodeString.replace(/４/g, "4");
    PhoneCodeString = PhoneCodeString.replace(/５/g, "5");
    PhoneCodeString = PhoneCodeString.replace(/６/g, "6");
    PhoneCodeString = PhoneCodeString.replace(/７/g, "7");
    PhoneCodeString = PhoneCodeString.replace(/８/g, "8");
    PhoneCodeString = PhoneCodeString.replace(/９/g, "9");
    PhoneCodeString = PhoneCodeString.replace(/ \+/g, " ");
    PhoneCodeString = PhoneCodeString.replace(/- /g, "-");
    var result = PhoneCodeString.match(/\-?\d+/g);
    if (result == null) return null;
    switch (result.length)
    {
        case 0: return null;
        case 1:
            return FormatedPhoneCode(null, null, result[0], null);
        case 2:
            return result[0].length < result[1].length ? FormatedPhoneCode(null, result[0], result[1], null) : FormatedPhoneCode(null, null, result[0], result[1].replace(/-/g, ""));
        case 3:
            return result[1].length < result[2].length ? FormatedPhoneCode(result[0], result[1], result[2], null) : FormatedPhoneCode(null, result[0], result[1], result[2].replace(/-/g, ""));
        default:
            return FormatedPhoneCode(result[0], result[1], result[2], result[3]);
    }
    return null;
}
function FormatedPhoneCode(countryCode, areaCode, phoneCode, extensionCode)
{
	countryCode = countryCode != null ? countryCode.replace("-", "") : "";
	areaCode = areaCode != null ? areaCode.replace("-", "") : "";
	phoneCode = phoneCode != null ? phoneCode.replace("-", "") : "";
	extensionCode = extensionCode != null ? extensionCode.replace("-", "") : "";
	var code = countryCode + "-" + (phoneCode != null && phoneCode.length > 10 ? "" : areaCode) + "-" + phoneCode + "-" + extensionCode;
	code = code.trim();
	code = code.replace(" -", " ");
	code = code.trim('-');
	return code;
}
String.prototype.isTelCode = function()
{   
    //有问题
	var p = /^0\d{2,3}$/;
	return p.test(this)
}
String.prototype.isZip = function()
{
	var p = /^\d{6}$/;
	return p.test(this)
}
String.prototype.isMobile = function()
{
    var p = /^1(3|5)\d{9}$/;
	return p.test(this)
}
String.prototype.isPassword = function()
{
    var p = /^(([^\s]| ){6,20})$/;
    return p.test(this);
}
String.prototype.ispassword = function()
{
    return this.isPassword();
}
String.prototype.isAccount = function()
{
    var p = /^(([a-zA-Z])(\w|-){5,20})$/;
    return p.test(this);
}
String.prototype.isaccount = function()
{
    return this.isAccount();
}
String.prototype.ispwd = function()
{
    return this.isPassword();
}
String.prototype.isPwd = function()
{
    return this.isPassword();
}
String.prototype.isDomainName = function()
{
	var p = /(\.{2,})|(\.$)|(^\.)|([^A-Za-z0-9\-_\.])/;
	return !p.test(this)
}
String.prototype.IsDomainName = function()
{
	return this.isDomainName();
}
String.prototype.trim = function() {
    if (arguments.length == 0)
        return this.replace(/(^[\s　]*)|([\s　]*$)/g, "");
    else
    {
        var s = arguments[0];
        var v = this;
        return eval("v.replace(/(^[\\s" + s + "]*)|([\\s" + s + "]*$)/g, '')");
    }
}
String.prototype.parseFloat = function()
{
	return parseFloat(this);
}
String.prototype.ParseFloat = function()
{
	return this.parseFloat();
}
String.prototype.Trim = function()
{
    return this.trim.apply(this, arguments);
}
String.prototype.toLower = function()
{
	return this.toLowerCase();
}
String.prototype.ToLower = function()
{
	return this.toLower();
}
String.prototype.toUpper = function()
{
	return this.toUpperCase();
}
String.prototype.ToUpper = function()
{
	return this.toUpper();
}
String.prototype.parseInt = function()
{
	return parseInt(this);
}
String.prototype.ParseInt = function()
{
	return this.parseInt();
}
String.prototype.parseBool = function()
{
	return this.toLower()=="true";
}
String.prototype.ParseBool = function()
{
	return this.parseBool();
}
String.prototype.parseDateTime = function() {
    var s = this.replace("年","-");
    s = s.replace("月","-");
    s = s.replace("日","");
    s = s.replace("点",":");
    s = s.replace("分",":");
    s = s.replace("秒","");
    s = s.replace(/-/g, "//");
    return new Date(s);
}
String.prototype.isMail = function()
{
    var re = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if(this.search(re) == 0)
	    return true;
    else
	    return false;
}
String.prototype.IsMail = function()
{
    return this.isMail();
}
String.prototype.IsEmail = function()
{
    return this.isMail();
}
String.prototype.isEmail = function()
{
    return this.isMail();
}
String.prototype.isEmpty = function()
{
    if(this.trim().length == 0)
	    return true;
    else
	    return false;
}
String.prototype.IsEmpty = function()
{
    return this.isEmpty();
}
String.prototype.isNull = function()
{
    return this == null;
}
String.prototype.IsNull = function()
{
    return this.isNull();
}
String.prototype.isInt = function()
{
	var re = /^-{0,1}\d{1,}$/;
	return re.test(this);
}
String.prototype.IsInt = function()
{
    return this.isInt();
}
String.prototype.isNumeric = function()
{
	var re = /^\d{1,}$|^\d{1,}.\d{1,}$/;
	 return re.test(this);
}
String.prototype.IsNumeric = function()
{
    return this.isNumeric();
}
String.prototype.isChinese = function()
{
	var re = /^[\u4e00-\u9fa5]{0,}$/;
	return re.test(this);
}
String.prototype.IsChinese = function()
{
	return this.isChinese(this);
}
String.prototype.withChinese = function()
{
	var re = /[\u4e00-\u9fa5]{1,}/;
	return this.search(re)>-1;
}
String.prototype.WithChinese = function()
{
	return this.withChinese();
}
String.prototype.len = function()
{
	return this.replace(/[^\x00-\xff]/g,"aa").length;
} 
String.prototype.Len = function()
{
	return this.replace(/[^\x00-\xff]/g,"aa").length;
}
String.prototype.format = function()
{
	var _Str_For_str = this;
	for(var i = 0; i < arguments.length; i++)
	{
		while(_Str_For_str.indexOf("{" + i + "}")>=0)
			_Str_For_str = _Str_For_str.replace("{" + i + "}",arguments[i]);
	}
	return _Str_For_str;
}
String.prototype.Format = function()
{
	return this.format();
}
String.prototype.HtmlDecode = function(){
    return this.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}
String.prototype.HtmlEncode =  function() {
    return this.replace(/&/g, '&amp').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
Date.prototype.isToday = function()
{
	var now = new Date();
	return this.getFullYear() == now.getFullYear() && this.getMonth() == now.getMonth() && this.getDate() == now.getDate() ? true : false;
}
Date.prototype.monthDaysCount = function()
{
    if(this.getMonth()==0||this.getMonth()==2||this.getMonth()==4||this.getMonth()==6||this.getMonth()==7||this.getMonth()==9||this.getMonth()==11)return 31;
    if(this.getMonth()==3||this.getMonth()==5||this.getMonth()==8||this.getMonth()==10)return 30;
    return this.isLeapYear()?29:28;
}
Date.prototype.isLeapYear =   function()
{
    var year = this.getYear()<1000?this.getYear()+1900:this.getYear();
    if(year %400==0) return true;
    if(year%100==0)return false;
    if(year%4==0)return true;
    return false;
}
String.isNullOrEmpty = function (val)
{
	return val == null || val == NaN || val == "";
}
function getOffset(Obj)
{
    Obj = ge(Obj);
	var x = Obj.offsetLeft;
	var y = Obj.offsetTop;
	if(Obj.offsetParent!=null)
	{
		var offset = getOffset(Obj.offsetParent);
		x += offset.x;
		y += offset.y;
	}
	var w = Obj.offsetWidth;
	var h = Obj.offsetHeight;
	return {x: x, y: y, w: w, h: h}
}
function addEvent(element, type, handler)
{
	if (window.addEventListener)
	{
		try
		{
			element.removeEventListener(type, handler, false); 
		}
		catch(e){}
		element.addEventListener(type, handler, false); 
	}
	else if (window.attachEvent)
	{
		try
		{
			element.detachEvent("on" + type, handler);
		}
		catch(e){}
		element.attachEvent("on" + type, handler);
	}
}
function removeEvent(element, type, handler)
{
	if (window.removeEventListener)
	{
		try
		{
			element.removeEventListener(type, handler, false); 
		}
		catch(e){}
	}
	else if (window.detachEvent)
	{
		try
		{
			element.detachEvent("on" + type, handler);
		}
		catch(e){}
	}
}
//禁止事件冒泡
function stopPropagation(evt)
{
	var e=(evt) ? evt : window.event;
	if (window.event)
	{
		e.cancelBubble=true;
	}
	else
	{
		e.stopPropagation();  
	}
}
function ce(tagName,parentObjId)
{
	if(parentObjId)
	{
		var _obj = ge(parentObjId);
		if(_obj==null)return null;
		var cobj = ce(tagName);
		_obj.appendChild(cobj);
		return cobj;
	}
	else
		return document.createElement(tagName);
}
function ae(childObj,parentObj)
{
	if(childObj!=null&&parentObj!=null)parentObj.appendChild(childObj);
}
function setOut(inerNode,outerNode)
{
	inerNode.parentNode.insertBefore(outerNode,inerNode);
	outerNode.appendChild(inerNode);
}
function getNodeIndex(Obj)
{
	var i=0;
	var oc = Obj.previousSibling;
	while(oc)
	{
		oc = oc.previousSibling;
		i++;
	}
	return i;
}
function ge(ID)
{
    if(typeof(ID)=="object")return ID;
    if(typeof(ID)=="string")
    	return document.getElementById(ID);
}
function re(ID)
{
	var _obj = typeof(ID)=="object"?ID:ge(ID);
	if(_obj==null)return;
	if(_obj.parentNode)_obj.parentNode.removeChild(_obj);
}
function getParamValue(URL,ParamName)
{
	var Opt	=	getParam(URL);
	for(i=0;i<Opt[0].length;i++)
	{
		if(Opt[0][i].toLowerCase()==ParamName.toLowerCase())return Opt[1][i];
	}
	return null;
}
function getParam(URL)
{
	URL	=	URL.substring(URL.indexOf("?")+1,URL.length);
	var opt	=	URL.split("&");
	var para	=	new Array();
	var value	=	new Array();
	for(i=0;i<opt.length;i++)
	{
		para[i]	=	opt[i].substring(0,opt[i].indexOf("="));
		value[i]	=	opt[i].substring(opt[i].indexOf("=")+1,opt[i].length);
	}
	var result	=	new Array(para,value);
	return result;
}
function QueryString(ParamName)
{
	return getParamValue(window.location.href,ParamName);
}

function StrRegExp(str,patStr)
{
	var pat = new RegExp(patStr);
	return(pat.test(str));
}
function GetScale(vle ,allNumber)
{
	var a=vle/allNumber;
	if(a.toString().indexOf('.')!=-1)
	{
		var b=a.toString().substring(a.toString().indexOf('.')+1,a.toString().length);
		if(b.length==1)
		{
			return b+"0";
		}
		else if(b.length==2)
		{
			return b;
		}
		else
		{
			return b.toString().substring(0,2);
		}
	}
	else if(a==0)
	{
		return "0";
	}
	else if(a==1)
	{
		return "100";
	}
	else
	{
		return "0";
	}
}

function PostToPage(formID, url, method, disableButton, target)
{
	var form = document.getElementById(formID);
	if (form != null)
	{
		RemoveViewState(formID);
		form.method = method;
		form.action = url;
		if (target != null) form.target = target;
		form.submit();
		if (disableButton != false ) DisableButton();	
	}
}
function RemoveViewState(formID)
{
	var form = document.getElementById(formID);
	if (form == null)
	{
		FDMFrame.Info('提示信息','指定的表单不存在!');
	}
	else
	{
		for(var i = 1; i < arguments.length; i++)
		{
			if (form.children[arguments[i]] != null)
			{
				RemoveNode(arguments[i]);
				//form.removeChild(form.children[arguments[i]]);
			}
		}
		RemoveNode("__VIEWSTATE");
		RemoveNode("__EVENTTARGET");
		RemoveNode("__EVENTARGUMENT");
	}
	return;
}
function RemoveNode(nodeID)
{
	var ntype = GetNType()
	var target = document.getElementById(nodeID);
	if (target == null || target == undefined) return;
	if (ntype == "ie")
	{
		target.removeNode(true);
	}
	else
	{
		target.parentNode.removeChild(target);
	}
}
function GetNType()
{
	return document.body.removeNode != undefined ? "ie" : "mf";
}
function DisableButton()
{
	var inputs = document.all.tags("input");
	for(var i = 0; i < inputs.length; i++)
	{
		if (inputs[i].type == "button" || inputs[i].type == "submit" || inputs[i].type == "reset")
		{
			inputs[i].disabled = true;
		}
	}
}

$.fn.check = function(mode) {
	mode = mode || 'on'; // if mode is undefined, use 'on' as default
	return this.each(function() {
		switch(mode) {
		case 'on':
			this.checked = true;
			break;
		case 'off':
			this.checked = false;
			break;
		case 'toggle':
			this.checked = !this.checked;
			break;
		}
	});
};

function jump(queryString, page)
{
	var qs = "?" + queryString.replace("{0}", page);
	location.href = qs;
}

//=================== Sandheart < ========================
var isIE = navigator.appName == "Microsoft Internet Explorer";

//根据下标移除Array中的值
Array.prototype.remove = function(dx)
{
    if(isNaN(dx) || dx > this.length){return false;}
    for(var i = 0,n = 0; i < this.length; i++)
    {
        if(i != dx)
        {
            this[n++] = this[i];
        }
    }
    this.length -= 1;
}


//----根据id或属性名称判断对象是否为空------
function objIsNull(id,isCheckContent)
{
	var tObj = document.getElementById(id);
	if(!tObj) return true;
	if(isCheckContent)
	{
	    try
	    {
	        if(!tObj.value && !tObj.innerText) return;
	    }
	    catch(e)
	    {}
	}
	return false;
}
//----根据id获取对象------
function getObj(id)
{
	return document.getElementById(id);
}

//----根据name获取对象------
function getObjs(n)
{
	return document.getElementsByName(n);
}
//----根据tagName获取对象------
function getOTags(n)
{
	return document.getElementsByTagName(n);
}
//----根据id或对象与属性名称获取对象的属性值------
function getOAV(idOrObj,attributeName)
{
    var tObj = (typeof(idOrObj) == 'object') ? idOrObj : getObj(idOrObj);
    if(!tObj) return null;
    try
    {
        return (tObj[attributeName]);
    }
    catch(e)
    {
        return null;
    }
}

//----判断字符串是否为空或null------
function isNullOrEmpty(obj)
{
    if(obj == null || obj.replace(/[\s　]/g ,'') == '')
        return true;
    else
        return false;
}

/*  获取XML对象中某个节点的值，支持下标
    例：GetNodeValue(xmlDoc, 'root/channel[1]/title[3]')；
        
    xmlObj：XML对象；
    path：要获取值的节点路径，如:'root/channel[1]/title[3]'，不加下标时自动选择第一个，找不到节点时返回空；
*/
function GetNodeValue(xmlObj, path)
{
    //debugger;
    var tempNodes = xmlObj;
    if (!tempNodes) return '';
    var tns = path.split('/');
    var reg = /.*(\[(\d+)\])/;
    var isGet = false; //判断是否获取到了值
    for (var i = 0; i < tns.length; i++)
    {
        //提出名字与下标值
        var tmp_name = tns[i];
        var tmp_sub = 0;
        var tmp_array = tmp_name.match(reg);
        if (tmp_array != null)
        {
            tmp_sub = tmp_array[2];
            tmp_name = tmp_name.replace(tmp_array[1], '');
        }
        isGet = false;
        try{
            if (tempNodes) tempNodes = tempNodes.getElementsByTagName(tmp_name)[tmp_sub];
        }
        catch (e)
        {
            return '';
        }
        if (tempNodes) isGet = true;
    }
    if (isGet)
    {
        if (isIE)
            return tempNodes.text;
        else
            return tempNodes.textContent
    }
    else
        return '';
}


//对字符串进行HTML编码
function HTMLEncode(str)
{
    var _div = document.createElement('div');
    _div.innerText = str;
    var reStr = _div.innerHTML;
    _div = null;
    return reStr
}
//对HTML进行字符串解码
function HTMLDecode(html)
{
    var _div = document.createElement('div');
    _div.innerHTML = html;
    var reStr = _div.innerText;
    _div = null;
    return reStr;
}
//返回一个对象在页面中的位置
function getOffset(Obj)
{
	var x = Obj.offsetLeft;
	var y = Obj.offsetTop;
	if(Obj.offsetParent!=null)
	{
		var offset = getOffset(Obj.offsetParent);
		x += offset.x;
		y += offset.y;
	}
	var w = Obj.offsetWidth;
	var h = Obj.offsetHeight;
	return {x: x, y: y, w: w, h: h}
}
//对象设置焦点，传入的参数可为id或对象
function setFocus(idOrObj)
{
    try
    {
        if(typeof(idOrObj) == 'object')
            idOrObj.focus();
        else
            getObj(idOrObj).focus();
    }
    catch(e)
    {
        //alert(e);
    }
}


//显示检测结果正确图片
function showOKImg(id,info)
{
    var img = getObj(id);
    if(img)
    {
        img.className = 'ok';
        if(!info) info = '';
        img.title = info;
        displayObj(id,true);
    }
}

//显示检测结果错误图片
function showErrorImg(id,info)
{
    var img = getObj(id);
    if(img)
    {
        img.className = 'error';
        if(!info) info = '';
        img.title = info;
        displayObj(id,true);
    }
}

//----设置对象是否显示------
function displayObj(idOrObj, isDisplay)
{
    var tObj = (typeof (idOrObj) == 'object') ? idOrObj : getObj(idOrObj);
    if (!tObj) return;
    if (isDisplay)
        tObj.style.display = '';
    else
        tObj.style.display = 'none';
}


//----设定Select表单的选定项------
function setSelectValue(idOrObj, v)
{
    var tObj = (typeof (idOrObj) == 'object') ? idOrObj : getObj(idOrObj);
    if (!tObj) return;
    for (var i = 0; i < tObj.length; i++)
    {
        if (tObj.options[i].value == v)
        {
            tObj.options[i].selected = true;
            break;
        }
    }
}

//----设定一组单选框(radio)选择某个值------
function setRadioValue(rName,v)
{
    var rs = document.getElementsByName(rName);
    if(!rs) return;
    for(var i = 0; i < rs.length; i++)
    {
        if(rs[i].value == v)

            rs[i].checked = true;
        else
            rs[i].checked = false;
        
    }
}

//----获取一组单选框(radio)所选的值------
function getRadioValue(rName)
{
    var objs = document.getElementsByName(rName);
    if(!objs)return undefined;    
    for(var i = 0; i < objs.length; i++)
    {
        if(objs[i].checked == true) return objs[i].value;
    }    
}

//----获取一组复选框(checkbox)所选的值的集合------
function getCheckboxValue(rName)
{
    var objs = document.getElementsByName(rName);
    if(!objs)return undefined;
    var vArray = new Array();
    for(var i = 0; i < objs.length; i++)
    {
        if(objs[i].checked == true) vArray[vArray.length] = objs[i].value;
    }
    return  vArray;
}

//数组对象remove方法，例：array.remove(1);
Array.prototype.remove=function(dx)
{
    if(isNaN(dx)|| typeof(dx) != 'number' || !this.length > 0 || dx > this.length){return false;}
    for(var i=0,n=0;i<this.length;i++)
    {
        if(i != dx)
        {
            this[n++]=this[i];
        }
    }
    this.length-=1;
}

//只允许输入数字(正)
function onlyInputNum(id)
{
    var obj = (typeof (id) == "object") ? id : getObj(id);
    if (!obj) return;
    var tv = obj.value;
    var pattren = /^\d*/;
    var rL = tv.match(pattren);
    obj.value = (rL) ? rL[0] : '';

//    var obj  = (typeof(id) == "object")?id:getObj(id);
//	if(!obj) return;
//	var tv = obj.value;
//	if(tv.isInt() || tv.isEmpty())return;
//	tv = tv.substring(0,tv.length-1);
//	while(tv && !tv.isInt() && tv.length > 0)
//	{
//		tv = tv.substring(0,tv.length-1);
//	}
//	obj.value = tv;
//	//alert('Only input number!');
}

//只允许输入整数(正,负)
function onlyInputInt(id)
{
    var obj  = (typeof(id) == "object")?id:getObj(id);
	if(!obj) return;
	var tv = obj.value;
    var pattren = /^-?\d*/;
    var rL = tv.match(pattren);
    obj.value = (rL) ? rL[0] : '';
    //alert('Only input number!');
}

//只允许输入数字与folat
function onlyInputFolat(id)
{
    var obj  = (typeof(id) == "object")?id:getObj(id);
	if(!obj) return;
	var tv = obj.value;
	var pattren = /^\d+([\.]?)(\d*)/;
	var rL = tv.match(pattren);
    obj.value = (rL) ? rL[0] : '';
}

//替换对象
/*
    newObj:新对象;
    oldObj:要替换的旧对象
*/
function replaceObj(newObj,oldObj)
{
    oldObj.parentNode.insertBefore(newObj,oldObj);
    oldObj.removeNode();
}

//利用name获取一组表单,为AJAX对象添加要传递的参数 (使用Rick's Ajax.js)
/*
    ajaxObj:要添加参数的AJAX对象;
    name:表单name;
    idKey:表单id与AJAX对象参数名称的差异字符(表单id.replace(idKey) == AJAX对象参数名称)
*/
function ajaxAddItems(ajaxObj, name, idKey)
{
    var boxs = getObjs(name);
    if(boxs)
    {
        for(var i=0; i<boxs.length; i++)
        {
            ajaxObj.AddItem(boxs[i].id.replace(idKey, ''), boxs[i].value);
        }     
    }
}

//把XML对象中的值填充到对应的一组表单中
/*
    xmlObj:XML对象
    name:要填充表单的name;
    idKey:表单id与AJAX对象参数名称的差异字符(表单id.replace(idKey) == AJAX对象参数名称)
    path:值在XML对象中的路径,如(Id的路径为：root/Data/Id，path就为：root/Data/);
*/
function setBoxsValue(xmlObj, name, idKey, path)
{
    var boxs = getObjs(name);
    if (!boxs) return;
    for (var i = 0; i < boxs.length; i++)
    {
        var temp_Id = boxs[i].id;
        var v = GetNodeValue(xmlObj, path + temp_Id.replace(idKey, ''));
        if (boxs[i].tagName == 'SELECT')
            setSelectValue(temp_Id, v);
        else
            boxs[i].value = v;
    }
}


//获取返回的XM信息
function getReXmlInfo(xmlObj)
{
    var rev;
    var info;
    if (typeof(xmlObj.childNodes) != 'undefined')
    {
        rev = GetNodeValue(xmlObj, 'Root/Value');
        info = GetNodeValue(xmlObj, 'Root/Info');
    }
    else
    {
        rev = xmlObj.Root.Value;
        info = xmlObj.Root.Info;
    }
    if (rev == -1)
        FDMFrame.Alert('警告', info);
    return { ReValue: rev, Info: info };
}

//获取自定义字段的示例
function GetFieidsExample(fType, width)
{
    var example = '';
    var posWidth = 0;
    var checkFunction = '';
    switch (fType)
    {
        case 'datetime':
            example = ' (yyyy-MM-dd hh:mm ss)';
            posWidth = 140;
            break;
        case 'int':
            checkFunction = 'onlyInputNum(this);';
            break;
        case 'float':
            example = '￥';
            posWidth = 20;
            checkFunction = 'onlyInputFolat(this);';
            break;
        default:
            break;
    }
    width = width > posWidth ? width - posWidth : width;
    return { 'Example': example, 'Width': width, "CheckFunction": checkFunction };
}

//序列化对象
function Searial(obj)
{
    var str = '';
    if (typeof (obj) == 'object')
    {
        for (node in obj)
        {
            str += escape(node) + ':' + escape(obj[node]) + ',';
        }
    }
    return str;
}

//反序列化对象
function UnSearial(str)
{
    var obj = {};
    if (str)
    {
        var temp = str.split(',');
        if (temp && temp.length > 0)
        {
            for (var i = 0; i < temp.length; i++)
            {
                var tmp = temp[i].split(':');
                if (tmp.length = 2)
                    obj[unescape(tmp[0])] = unescape(tmp[1]);
            }
        }
    }
    return obj;
}
//=================== > Sandheart ========================

//获得Cookie解码后的值

function GetCookieVal(offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

//获得Cookie解码后的值
function GetCookieV(sName) 
{
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++)
    {
        var aCrumb = aCookie[i].split("=");
        if (escape(sName) == aCrumb[0])
            return unescape(aCrumb[1]);
    }
    return null;
}
// 写 cookie
function setCookieT(sName, sValue, iTime) {
    if (ie)
    {
        setCookie(sName, sValue, iTime);
    }
    else
    {
        var date = new Date();
        if (iTime)
            date.setTime(date.getTime() + iTime * 1000);
        else
            date.setTime(date.getTime() + 3600 * 24 * 365 * 3 * 1000);
        //alert(date.getYear() + "," + date.getMonth() + "," + date.getDate());
        document.cookie = escape(sName) + "=" + escape(sValue) + "; Expires=" + date.toGMTString();
    }
}
// 读 cookie
function getCookieT(sName) {
    if (ie)
    {
        getCookie(sName);
    }
    else
    {
        var aCookie = document.cookie.split("; ");
        for (var i = 0; i < aCookie.length; i++)
        {
            var aCrumb = aCookie[i].split("=");
            if (escape(sName) == aCrumb[0])
                return unescape(aCrumb[1]);
        }
        return null;
    }
}
//设定Cookie值
function SetCookie(name, value) {
    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 * 1000));
    //alert(expdate.getYear() + "," + expdate.getMonth() + "," + expdate.getDate());
    if (ie)
    {
        UserData.setValue(name, value, arguments.length > 2 ? arguments[2] : null);
    }
    else
    {
        var str = name + "=" + escape(value) + ";" + ((expires == null) ? "" : (" Expires=" + expdate.toGMTString() + ";")) + ((path == null) ? "" : (" path=" + path + ";")) + ((domain == null) ? "" : ("domain=" + domain + ";")) + ((secure == true) ? "secure;" : "");
        document.cookie = str;
    }
}
var setCookie = SetCookie;

//删除Cookie
function delCookie(name){DelCookie(name);}
function removeCookie(name){DelCookie(name);}
function RemoveCookie(name){DelCookie(name);}
function DelCookie(name) {
    if (ie)
    {
        UserData.removeValue(name);
    }
    else
    {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = GetCookie(name);
        document.cookie = name + "=" + cval + "; Expires=" + exp.toGMTString();
    }
}
//获得Cookie的原始值
function getCookie(name){return GetCookie(name)}
function GetCookie(name) {
    if (ie)
    {
        return UserData.getValue(name);
    }
    else
    {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen)
        {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
            {
                return GetCookieVal(j);
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0)
            {
                break;
            }
        }
        return null;
    }
}
var msgf = null;
var taskf = null;
var clockf = null;
function flash(id)
{
    if(!ge(id))return;
    switch(ge(id).className)
    {
        case "task1":
            if(taskf)
            ge(id).className = "task2";
            break;
        case "task2":
            ge(id).className = "task1";
            break;
        case "clock1":
            ge(id).className = "clock2";
            break;
        case "clock2":
            ge(id).className = "clock1";
            break;
        case "msg1":
            ge(id).className = "msg2";
            break;
        case "msg2":
            ge(id).className = "msg1";
            break;
    }
}
function msgflash()
{
    return;
    if(msgf)
    {
        clearInterval(msgf);
        ge("msg").className = "msg2";
        msgf = null;
    }
    else
        msgf = setInterval("flash('msg')",500);
}
function clockflash()
{
    if(clockf)
    {
        clearInterval(clockf);
        ge("clock").className = "clock2";
        clockf = null;
    }
    else
        clockf = setInterval("flash('clock')",500);
}
function taskflash()
{
    if(taskf)
    {
        clearInterval(taskf);
        ge("task").className = "task2";
        taskf = null;
    }
    else
        taskf = setInterval("flash('task')",500);
}
$(document).ready(function() {
    UserData.init();
 if (typeof (pageonload) == "function") pageonload();
    if(typeof(pageOnLoad)=="function")pageOnLoad();
});
var UserData = {};
UserData.DataFile = "UDCookie";
UserData.Object = null;
UserData.init = function() {
    if (!UserData.Object)
    {
        try
        {
            UserData.Object = document.createElement('input');
            UserData.Object.type = "hidden";
            UserData.Object.addBehavior("#default#userData");
            document.body.appendChild(UserData.Object);
        }
        catch (e)
        {
            UserData.Object = null;
            return false;
        }
    }
    return true;
}
UserData.setValue = function(Name, Value, Time) {
    if (!UserData.Object)
    {
        if (!UserData.init()) return;
    }
    if (UserData.Object)
    {
        var o = UserData.Object;
        o.load(UserData.DataFile);
        if (UserData.DataFile) o.setAttribute(Name, escape(Value));
        var d = new Date();
        d.setTime(d.getTime() + ((Time ? Time : Time == -1?-1:365) * 1000))
        o.expires = d.toUTCString();
        o.save(UserData.DataFile);
    }
}
UserData.getValue = function(Name) {
    if (!UserData.Object)
    {
        if (!UserData.init()) return;
    }
    if (UserData.Object)
    {
        var o = UserData.Object;
        o.load(UserData.DataFile);
        return o.getAttribute(Name)?unescape(o.getAttribute(Name)):null;
    }
}
UserData.removeValue = function(Name) {
    UserData.setValue(Name,false, -1);
}
String.prototype.toXml  = function() {
    var xmlDoc = null;
    try 
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(this);
    }
    catch (e)
    {
        try   
        {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(this, "text/xml");
        }
        catch (e) { }
    }
    return xmlDoc;
} 
function QueryString(fieldName){ 
      var urlString = document.location.search;
      if(urlString != null)
      {
           var typeQu = fieldName+"=";
           var urlEnd = urlString.indexOf(typeQu);
           if(urlEnd != -1)
           {
                var paramsUrl = urlString.substring(urlEnd+typeQu.length);
                var isEnd = paramsUrl.indexOf('&');
                if(isEnd != -1)
                {
                     return paramsUrl.substring(0, isEnd);
                }
                else
                {
                    return paramsUrl;
                }
           }
           else 
           return null;
      }
     else
     return null;
}

 function   Date_istrue(asDate){   
  var   lsDate     =   asDate   +   "";   
  var   loDate     =   lsDate.split("-");   
  if   (loDate.length!=3)   return   false;     
  var   liYear     =   parseInt( loDate[0],10);   
  var   liMonth   =   parseInt( loDate[1],10);   
  var   liDay       =   parseInt( loDate[2],10);   
  if   ((loDate[0].length>4)||(loDate[1].length>2)||(loDate[2].length>2))   return   false;   
  if   (isNaN(liYear)||isNaN(liMonth)||isNaN(liDay))   return   false;   
  if   ((liYear<1900)||(liYear>3000))   return   false;   
  if   ((liMonth>12)||(liMonth<=0))       return   false;   
  if   (Date_getDay(liYear,liMonth)<liDay)   return   false;   
  return   !isNaN(Date.UTC(liYear,liMonth,liDay));   
  }  
  
  /*--   返回某年某月的天数--   */   
  function   Date_getDay(aiYear,aiMonth){   
  var   loDay   =   [0,31,28,31,30,31,30,31,31,30,31,30,31];   
  if   (aiYear%4==0)   loDay[2]   =   29;   
  return   loDay[aiMonth];   
  }   


