var $break = {};
var $continue = {};
String.prototype.stripTags        = fStripTags;       // 删除标签
String.prototype.escapeHTML       = fEscapeHTML;      // html编码
String.prototype.unescapeHTML     = fUnescapeHTML;    // html解码
String.prototype.encodeHTML		  = fEncodeHTML;    // html编码
String.prototype.decodeHTML		  = fDecodeHTML;    // html解码
String.prototype.toInt            = fToInt;           // 字符串转换城整型
String.prototype.usc_hdc          = fUsc_hdc;         // url＆html解码
String.prototype.trim             = fTrim;            // 删除字符串两边的空格
String.prototype.ltrim            = fLtrim;           // 删除左边的空格
String.prototype.rtrim            = fRtrim;           // 删除右边的空格
String.prototype.len              = fLen;             // 字符串的长度,可以检查中文
String.prototype.left             = fLeft;            // 截取左边数起第几个字符,截取后用...代替
String.prototype.isNumber         = fIsNumber;        // 字符串是否是整数
String.prototype.checkSpecialChar = fCheckSpecialChar;// 检查数否右特殊字符
String.prototype.posIndexOf		  = fPosIndexOf;	  // 第几个字符的位置
String.prototype.parseJson		  = fParseJson;		  // 转换json字符串到对象
String.prototype.matchAny		  = fStringMatchAny;
Date.prototype.dateAdd            = fDateAdd;         // 日期类型增加天数
Date.prototype.format             = fDateFormat;      // 格式化日期为yyyy-MM-dd hh:mm:ss
Field.clear             = fClear;           // 清除内容
Field.activate          = fActivate;        // 激活对象
El.toggle               = fToggle;          // 显示或者隐藏节点
El.hide                 = fHide;            // 隐藏节点
El.show                 = fShow;            // 显示节点
El.remove               = fRemove;          // 删除节点
El.insertElement        = fInsertElement;   // 插入节点
El.nextSibling          = fNextSibling;     // 下一个节点
El.preSibling           = fPreSibling;      // 前一个节点
El.createElement        = fCreateElement;   // 建立节点
El.setAttr              = fSetAttr;         // 设置属性
El.setStyle             = fSetStyle;        // 设置style属性
El.addClass             = fAddClass;        // 添加class
El.removeClass          = fRemoveClass;     // 删除class
El.setClass				= fSetClass;		// 设置class
El.delClass             = fDelClass;        // 删除一个或多个class
El.getX                 = fGetX;            // 获取节点的x坐标
El.getY                 = fGetY;            // 获取节点的y坐标
El.position				= fPosition;		// 节点的位置坐标
El.toggleText			= fToggleText;		// 轮换显示文字
El.setBit				= fSetBit;			// 将二进制的数组转换成十进制
El.toggleAttr			= fElementToggleAttr;
EV.getTarget		= fGetTarget;			// 获取target
EV.getEvent			= fGetEvent;			// 获取event
EV.stopEvent		= fStopEvent;			// 取消事件和事件冒泡
EV.stopPropagation	= fStopPropagation;		// 取消事件冒泡
EV.preventDefault	= fPreventDefault;		// 取消事件
EV.pointerX			= fPointerX;			// 鼠标x位置
EV.pointerY			= fPointerY;			// 鼠标y位置
EV.observers		= false;				// 监听事件的缓存对象
EV.observeAndCache  = fObserveAndCache;		
EV.unloadCache		= fUnloadCache;			// 取消所有事件监听
EV.stopObserving	= fStopObserving;		// 取消事件监听
EV.observe			= fObserve;				// 增加事件监听
Number.prototype.getBit = fNumberGetBit;	// 获得十进制数转换成二进制后某位的值
Number.prototype.setBit = fNumberSetBit;	// 设置十进制数转换成二进制后某位的值
Array.prototype.exchange = fArrayExchange;
Array.prototype.escapeNull = fArrayEscapeNull;
Array.prototype.clone = fArrayClone;
Array.prototype.subtract = fArraySubtract;
Array.prototype.filter = fArrayFilter;
Array.prototype.splice = fArraySplice;
Array.prototype.each = fArrayEach;
Array.prototype.has = fArrayHas;

// IE5兼容
if (!Array.prototype.push) {
  Array.prototype.ie5  = true;
  Array.prototype.push = function() {
	var startLength = this.length;
	for (var i = 0; i < arguments.length; i++)
	  this[startLength + i] = arguments[i];
	return this.length;
  }
}
if (!Array.prototype.shift) {
  Array.prototype.shift = function () {
	var returnValue = this[0];
	for (i = 1; i < this.length; i++) {
	  this[i - 1] = this[i];
	}
	this.length--;
	return returnValue;
  }
}
if (!Array.prototype.pop) {
  Array.prototype.pop = function () {
	  lastElement = this[this.length-1];
	  this.length = Math.max(this.length-1,0);
	  return lastElement;
  }
}

/**
 * 转换成字符串
 */
Array.prototype.toString = function(){
	return this.join("");
};
if(typeof Function.prototype.apply != "function"){
	Function.prototype.apply = fFunctionApply;
	Function.prototype.call = fFunctionCall;
}
Function.prototype.bind = fFunctionBind;

/**
 * Email数据结构类
 *
 * @class Email数据结构类
 */
Email.Value = fEmailValue;

/**
 * Email类的静态方法
 */
Email.match = fEmailMatch;			// 是否匹配一个email地址
Email.get = fEmailGet;				// 匹配和获取email地址
Email.getName = fEmailGetName;		// 获取名字部分
Email.getAddress = fEmailGetAddress;// 获取地址部分
Email.format = fEmailFormat;

/**
 * 浏览器类型
 * @param   void
 * @return  {void}
 */
function fGetUserAgen(){
	var sUserAgent = window.navigator.userAgent;
	var sAppName = "";
	var sVersion = "";
	if(sUserAgent.indexOf("MSIE")>-1){
		sAppName   = "msie";	
		sVersion	= sUserAgent.replace(/.+MSIE/gi,"").replace(/;.+/gi,"") - 0;	
	}else if(sUserAgent.toUpperCase().indexOf("FIREFOX")>-1){
		sAppName = "firefox";
		sVersion = sUserAgent.replace(/.+Firefox\//gi,"").replace(/\(.*\)/g,"") - 0;
	}else if(sUserAgent.toUpperCase().indexOf("NETSCAPE")>-1){
		sAppName = "netscape";
		sVersion = sUserAgent.replace(/.+NETSCAPE\//gi,"").replace(/\(.*\)/g,"") - 0;
	}else if(/OPERA/ig.test(sUserAgent)){
		sAppName = "opera";
		sVersion = sUserAgent.replace(/OPERA\//gi,"").replace(/ .+/g,"") - 0;
	}else if(/SAFARI/ig.test(sUserAgent)){
		sAppName = "safari";
		sVersion = "0";
	}
	gAppName = sAppName; // 浏览器类型
	gVersion = sVersion; // 版本号	
	gIsIE = (sAppName == "msie");
}

/**
 * 实现apply方法
 * @param {Object}obj 可选项。将被用作当前对象的对象。
 * @param {Array}argu 可选项。将被传递给该函数的参数数组。
 * @return {Any} 返回调用的结果
 */
function fFunctionApply(obj, argu){
	 var s;
	 if(obj){
	  obj._caller = this ;
	  s  =   " obj._caller " ;
	 }
	 else  s  =   " this " ;
	 var  a = [];
	 for ( var  i = 0 ; i < argu.length; i ++ )
	  a[i]  =   " argu[ " +  i  + " ] " ;
	 return  eval(s  + " ( " +  a.join( " , " )  + " ); " );
}

/**
 * 实现call方法
 * @param {Object}obj 可选项。将被用作当前对象的对象。
 * @return {Any} 返回调用的结果
 */
function fFunctionCall(obj){
	 var  a = [];
     var nLenth = arguments.length;
	 for(var  i = 1 ; i < nLenth; i ++ )
	     a[i-1] = arguments[i];
	 return this.apply(obj, a);
}

/**
 * 绑定某个方法到某个对象
 */
function fFunctionBind(){
	var __method = this;
    var args = new Hashtable(arguments).toArray();
    var object = args.shift();
	return function(){
		return __method.apply(object, args.concat(new Hashtable(arguments).toArray()));
	}
}

/**
 * 文本输入框函数集合
 * 
 * @class 文本输入框对象
 */
function Field(){
  // TODO
}

/**
 * 元素函数集合
 * 
 * @class 元素对象
 */
function El(){
  // TODO
}

/**
 * event函数集合
 * 
 * @class event对象
 */
function EV(){}

/**
 * 检查字符串是否是合法的email地址格式 
 * 
 * @deprecated
 * @param  {string}str  Email地址
 * @return {String}     如果Email地址错误返回空字符串
 *
 * @see     #isEmailAddr
 TODO(deprated) 
function checkNoNamePart( str )
{
  str.toLowerCase();
  str.replace(/\s/gi, "");
  if (str.search("@") < 0)
  {
    return "";
  }
  return str;
}
 */

/**
 * 将完整的email地址转换成xxx@xxx.xxx
 * 
 * @deprecated
 * @param  {string}strstrEmail  Email地址
 * @return {String}             返回xxx@xxx.xxx格式的Email地址
 */
function fParseSingleEmail(sEmail){
  return Email.getAddress(sEmail);
}

/**
 * 检查字符串是否是合法的格式
 *
 * @param  {string}strEmail  Email地址
 * @return {Boolean}         如果Email地址错误返回空字符串
 */
function fIsEmailAddr(sEmail){
    return /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(sEmail);
}

/**
 * 检查字符串是否是合法的手机号码
 *
 * @param  {string}sPhone  手机号码
 * @return {Boolean}       返回是否合法的手机号码
 * TODO(deprated) 
 
function isPhoneNum(sPhone)
{
   return /^1[35][\d]{8}$/.test(sPhone);
}
*/

/**
 * 截取字符串到第n位字符
 *
 * @param  {string}str 源字符串 
 * @param  {number}n   截取位置 
 * @return {String}    0-n的字符串
 */
function fFixStr(sSource , n){
  var i,j;
  var sRet = "";
  var nLen = sSource.length;
  for(i=0,j=1 ; i<nLen; i++,j++){
    if(sSource.charCodeAt(i) > 255){
      j++;
    }
    if(j > n){
      break;
    }
    sRet += sSource.charAt(i);
  }
  return sRet;
}

/**
 * 删除字符串:&quot;
 *
 * @param  {string}sSrc 源字符串 
 * @return {String}    删除&quot后的字符串
 */
function fReplaceQuot(sSrc){ 
    var re = /&quot;/g;             // 创建正则表达式模式。
    return sSrc.replace(re, "");    // 用 "" 替换 "&quot;"。
}

/**
 * 检查字符串的日期格式是否正确
 *
 * @param  {date}sDate  要验证的日期 
 * @return {Boolean}    日期格式是否合法，合法的格式为yyyy-MM-dd 
 */
function fCheckDate(sDate){
  var aStr = sDate.split("-");
  var oDate = new Date(aStr[0],aStr[1]-1,aStr[2]);
  if(oDate.getFullYear() != aStr[0] || (oDate.getMonth()+1) != parseInt(aStr[1],10) || oDate.getDate() != parseInt(aStr[2],10)){
    return false;
  }
  return true;
}

/**
 * 去掉字符串两边的空格
 *
 * @param   void   
 * @return {String} 去掉两边空格后的字符串    
 */
function fTrim(){
  return this.replace(/(^\s*)|(\s*$)/g, "");
}

/**
 * 去掉字符串左边的空格 
 *
 * @param   void   
 * @return {String} 去掉左边空格后的字符串    
 */
function fLtrim(){
  return this.replace(/(^\s*)/g, "");
}

/**
 * 去掉字符串右边的空格
 *
 * @param   void   
 * @return {String} 去掉右边空格后的字符串    
 */
function fRtrim(){
  return this.replace(/(\s*$)/g, "");
}

/**
 * 去掉字符串的所有空格
 *
 * @param   void   
 * @return {String} 去掉所有空格后的字符串    
 */
function fCleanBlank(){
  return this.replace( /\s/g, "");
}

/**
 * 检查字符串是否含有"% \' \" \\ \/ "的字符
 *
 * @param  {boolean}flag  是否检测特殊字符  
 * @return {Boolean}      如果有特殊字符返回false,否则返回true
 */
function fCheckSpecialChar(nFlag){
    var sReg = /[,%\'\"\/\\;|\<\>]/;
    if(this.search(sReg) != -1){
        if(nFlag){
            fShowSysMsg({
                Content: "请不要输入 ＂, % \' \" \\ \/ ；|<>＂ 等特殊字符。"
            });
        }
        return false;
    }
    return true;
}

/**
 * indexOf any
 * @param{string}
 * @return{}
 */
function fStringMatchAny(arr) {
	var r = false;
	var str = this;
	arr.each(function(i, v){
		if(str.match(new RegExp(v))){
			r = true;
			throw $break;
		}
	});
	return r;
}

/**
 * 第几个字符的位置
 *
 * @param  {String}sSearch  需要匹配的目的字符串  
 * @return {Number}nIndex  第几个目的字符串  
 * example 查找 "abcdeabcde" 中第二个b的位置
 */
function fPosIndexOf(sSearch, nIndex){
	var aStr = this.split(sSearch);
	if(aStr.length - 1 < nIndex){
		return -1;
	}else{
		var len = 0;
		for(var i=0; i<nIndex; i++){
			len += aStr[i].length;
			len += sSearch.length;
		}
		return len - sSearch.length;
	}
}

/**
 * 转换json字符串到对象
 *
 * @patam void
 * @return (obj)转换后的对象，如果解析失败返回false
 */
function fParseJson() {
    try {
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( this.replace(/'(\\.|[^"\\])*'/g, ''))) && eval('(' + this + ')');
    } catch (e) {
        return false;
    }
};

/**
 * 取字符串长度,包括中文字的长度，一个中文字符长度为2
 *
 * @param   void  
 * @return {Number}  字符串的长度    
 */
function fLen(){
  var nCNLenth = 0;
  var nLenth = this.length;
  for (var i=0; i<nLenth; i++){
    if(this.charCodeAt(i)>255){
      nCNLenth += 2; 
    }else{
      nCNLenth++;
    }
  }
  return nCNLenth;
}

/**
 * 删除标签字符串
 *
 * @param   void
 * @return {String}   删除标签后的字符串 
 */
function fStripTags(){
    return this.replace(/<\/?[^>]+>/gi, '');
};

/**
 * html编码
 *
 * @param   void
 * @return {String}   编码后的html代码
 */
function fEscapeHTML(){
    var oDiv = document.createElement('div');
    var oText = document.createTextNode(this);
    oDiv.appendChild(oText);
    return oDiv.innerHTML;
};

/**
 * html解码
 *
 * @param   void
 * @return {String}  解码后的html代码  
 */
function fUnescapeHTML(){
    var oDiv = document.createElement('div');
    oDiv.innerHTML = this.stripTags();
    return oDiv.childNodes[0].nodeValue;
};

/**
 * html编码
 */
function fEncodeHTML(){
	var s = this;
	s = s.replace(/\&/gi,"&amp;");
	s = s.replace(/</gi,"&lt;");
	s = s.replace(/>/gi,"&gt;");
	s = s.replace(/\"/gi,"&quot;");
	return s;
}

/**
 * html解码
 */
function fDecodeHTML(){
	var s = this;
	s = s.replace(/&lt;/gi,"<");
	s = s.replace(/&gt;/gi,">");
	s = s.replace(/&quot;/gi,"\"");
	s = s.replace(/&amp;/gi,"&");
	s = s.replace(/&nbsp;/gi," ");
	return s;
}

/**
 * 字符串转整型
 *
 * @param   void  
 * @return {Number} 字符串对应的整数   
 */
function fToInt(){
  return parseInt(this,10);
}

/**
 * url＆html解码
 *
 * @param   void  
 * @return {String}  解码后的url＆html字符串  
 */
function fUsc_hdc(){
  return unescape(this.unescapeHTML());
}

/**
 * 截取字符串左边n位
 *
 * @param  {number}n  要截取的位数 
 * @return {String}   截取的字符串 
 */
function fLeft(nLen){
  var i = 0;
  var j = 0;
  if(this.len() <= nLen){
    return this;
  }
  while(j < nLen){
    if(this.charCodeAt(i)>255){
      j += 2;
    }else{
      j ++;
    }
    i ++;
  }
  return this.substring(0,i) + "..";
}

/**
 * 判断是否整数
 *
 * @param   void  
 * @return {Boolean}  返回是否整数   
 */
function fIsNumber(){
  return (this.search(/^\d+$/g) == 0);
}

/**
 * 日期变量增加n天
 *
 * @param  {number}n  要增加的天数,小于0表示减n天  
 * @return {Date}     增加了n天后的日期    
 */
function fDateAdd(n){
  return new Date(this.valueOf()+n*3600*24*1000);
};

/**
 * 格式化日期为 yyyy-MM-dd hh:mm:ss
 *
 * @param  {void}  
 * @return {String}
 *          返回字符串日期
 */
function fDateFormat(bOnlyDate){
    var nYear = this.getFullYear();
    var nMonth = this.getMonth() + 1;
    var nDate = this.getDate();
    var nHour = this.getHours();
    var nMinute = this.getMinutes();
    var nSecond = this.getSeconds();
    // 格式化时间
    var sTime = nYear + (nMonth<10 ? '-0' : '-') + nMonth + (nDate<10 ? '-0' : '-') + nDate + (nHour<10 ? ' 0' : ' ') + nHour + (nMinute<10 ? ':0' : ":") + nMinute + (nSecond<10 ? ':0' : ':') + nSecond;
	if(bOnlyDate){
		return sTime.split(" ")[0];
	}
    // 返回时间
    return sTime
}

/**
 * 清除输入框的内容
 *
 * @param  {void}  输入框对象, 参数没有数量限制
 * @return {void}
 */
function fClear() {
    var nLength = arguments.length;
    for (var i = 0; i < nLength; i++){
        $(arguments[i]).value = '';
    }
}

/**
 * 激活对象
 *
 * @param  {object}element 需要激活的对象
 * @return {void}
 */
function fActivate(oElement) {
  try{
    $(oElement).focus();
    $(oElement).select();
  }catch(exp){}
}

/**
 * 通过id获取对象
 *
 * @param  {string}args  id字符串，可以有多个参数，用逗号分开
 * @return {Object}      根据id返回相应的对象   
 */
function $() {
  var aElements = [];
  var nLength = arguments.length;
  for (var i = 0; i < nLength; i++) {
    var oElement = arguments[i];
    if(typeof oElement == 'string'){
		oElement = document.getElementById(oElement);
	}
	fExtendObj(El, oElement);	
    if(nLength == 1){
		return oElement;
	}
    aElements.push(oElement);
  }
  return aElements;
}

/**
 * 继承对象属性
 * @param {object}org 源对象
 * @param {object}tag 目标对象
 * @return {void}
 */
function fExtendObj(oOrg, oTag){
	for(var o in oOrg){
		try{
			if(!oTag[o]){
				oTag[o] = oOrg[o];
			}
		}catch(exp){}
	}
}

/**
 * 获取对象
 * @private
 * @param  {object}param 如果param不是对象则将其作为对象id处理
 * @return {Object}      返回相应对象
 */
function fGetObj(oParam){
  var oElement = null;
  if(typeof(oParam) == 'object'){
    oElement = oParam;
  }else{
    oElement = $(oParam);
  }
  return oElement;
}

/**
 * 显示或隐藏对象,对象显示时就隐藏,隐藏时就显示
 *
 * @param  {string}args  对象或者对象id,参数没有数量限制
 * @return {void}
 */
function fToggle() {
	if(arguments.length == 0){
		this.style.display = (this.style.display == 'none' ? '' : 'none');
	}else{
		for (var i = 0,m = arguments.length; i < m; i++) {
			var oElement = fGetObj(arguments[i]);
			if(oElement){
			  oElement.style.display = (oElement.style.display == 'none' ? '' : 'none');
			}
		}
	}
}

/**
 * 隐藏对象
 *
 * @param  {string}args  对象或者对象id,参数没有数量限制
 * @return {void}
 */
function fHide() {
	if(arguments.length == 0){
		this.style.display = 'none';
	}else{
		for (var i = 0,m = arguments.length; i < m; i++) {
		  var oElement = fGetObj(arguments[i]);
		  oElement.style.display = 'none';
		}
	}
}

/**
 * 显示对象
 *
 * @param  {string}args  对象或者对象id,参数没有数量限制
 * @return {void}
 */
function fShow() {
    var nLength = arguments.length;
	if(nLength == 0){
		this.style.display = '';
	}else{
		for (var i = 0; i < nLength; i++) {
		  var oElement = fGetObj(arguments[i]);
		  oElement.style.display = '';
		}
	}
}

/**
 * 删除对象
 *
 * @param  {string}args  对象或者对象id,参数没有数量限制
 * @return {void}
 */
function fRemove(){
    var nLength = arguments.length;
	if(nLength == 0){
		this.parentNode.removeChild(this);
	}else{
		for (var i = 0; i < nLength; i++) {
			oElement = fGetObj(arguments[i]);
			oElement.parentNode.removeChild(oElement);
		}
	}
}

/**
 * 插入对象
 *
 * @param  {object}element 基准对象，要插入的对象在该对象的前后
 * @param  {object}obj     要插入的对象
 * @param  {string}place   要插入的位置:beforeBegin,afterBegin,beforeEnd,afterEnd
 * @return {void}
 */
function fInsertElement(oElement,obj,sPlace){
  try{
	if(arguments.length == 2){
		var sPlace = obj;
		var obj = oElement;
		var oElement = this;
	}
	var oParent = oElement.parentNode;
    var nLen = oParent.childNodes.length;
    var nPos = -1;
    for(var i=0;i<nLen;i++){
      if(oParent.childNodes[i] == oElement){
        nPos = i;
      }
    }
    if(sPlace == "beforeEnd"){
      oElement.appendChild(obj);
    }else if(sPlace == "afterEnd"){
      if(nPos == nLen-1){
        oParent.appendChild(obj);
      }else{
        oParent.insertBefore(obj,oParent.childNodes[nPos+1]);
      }
    }else if(sPlace == "beforeBegin"){
		oElement.parentNode.insertBefore(obj, oElement);
    }else if(sPlace == "afterBegin"){
      if(oElement.childNodes.length == 0){
        oElement.appendChild(obj);
      }else{
        oElement.insertBefore(obj,oElement.childNodes[0]);
      }
    }
  }catch(exp){
    fDebug("fInsertElement",exp.description);
  } 
}

/**
 * 获取对象的下一个对象
 *
 * @param  {object}element 执行方法的对象
 * @return {Object}        element的下一个对象
 */
function fNextSibling(oElement){
  try{
	if(!oElement){
		oElement = this;
	}
    var oParent = oElement.parentNode;
    var aChilds = oParent.childNodes;
    for(var i=0,m=aChilds.length;i<m;i++){
      if(aChilds[i] == oElement){
        if(i == aChilds.length-1){
          return null;
        }else{
          return aChilds[i+1];
        }
      }
    }
  }catch(exp){
    fDebug("fNextSibling",exp.description);
  } 
}

/**
 * 获取对象的前一个对象
 *
 * @param  {object}element 执行方法的对象
 * @return {Object}        element的前一个对象
 */
function fPreSibling(oElement){
    try{
        if(!oElement){
            oElement = this;
        }
        var oParent = oElement.parentNode;
        var aChilds = oParent.childNodes;
        var nLength = aChilds.length;
        for(var i=0; i<nLength; i++){
            if(aChilds[i] == oElement){
                if(i == 0){
                    return null;
                }else{
                    return aChilds[i-1];
                }
            }
        }
    }catch(exp){
        fDebug("fPreSibling",exp.description);
    } 
}

/**
 * 在indexFrame里建立对象
 *
 * @param {string}tag  要建立的对象的标签
 * @param {string}sId  要建立的对象的id
 * @param {object}     返回根据标签建立的对象
 */
function fCreateElement(sTag, sId){
	if(sId){
		var o = $(sId);
		if(o){
			El.remove(o);
		}
	}
	var oElement = document.createElement(sTag);
	if(sId){
		oElement.id = sId;
	}
	fExtendObj(El, oElement);
	return oElement;
}

/**
 * 定义对象的属性
 *
 * @param {string}oElement 执行方法的对象
 * @param {object}oAttrObj 要设置属性的集合,格式:{'height':'100px','width':'200px'}
 * @param {void}
 */
function fSetAttr(oElement, oAttrObj){
	if(arguments.length == 1){
		var oAttrObj = oElement;
		var oElement = this;
	}
	for(var o in oAttrObj){
		oElement[o] = oAttrObj[o];
	}
}

/**
 * 定义style属性
 *
 * @param  {object}oElement  要操作的对象
 * @param  {string}oStyleObj 要设置style属性的集合,格式:{'height':'100px','width':'200px'}
 * @return {void}
 */
function fSetStyle(oElement, oStyleObj){
	if(arguments.length == 1){
		var oStyleObj = oElement;
		var oElement = this;
	}
	for(var o in oStyleObj){
		oElement.style[o] = oStyleObj[o];
	}
}

/**
 * 添加css的class
 *
 * @param  {object}element   执行方法的对象
 * @param  {string}sClassName 要添加的class名称
 * @return {void}
 */
function fAddClass(oElement, sClassName){
	if(arguments.length == 1){
		var sClassName = oElement;
		var oElement = this;
	}
	var aClass = oElement.className.split(" ");
	if(!aClass.has(sClassName)){
		aClass.push(sClassName);
	}
	aClass = aClass.escapeNull();
	oElement.className = aClass.join(" ");
}

/**
 * 删除对象的样式，包括一个或多个样式
 *
 * @param  {object}element     待删除样式的对象
 * @param  {string}className   需增加的样式
 * @return {void}         
 */
function fDelClass(oElement,sClassName){
	if(arguments.length == 1){
		var sClassName = oElement;
		var oElement = this;
	}
    oElement.className = oElement.className.replace(sClassName,"");
}

/**
 * 删除css的class
 *
 * @param  {object}element   执行方法的对象
 * @param  {string}sClassName 要删除的class名称
 * @return {void}
 */
function fRemoveClass(oElement, sClassName){
	if(arguments.length == 1){
		var sClassName = oElement;
		var oElement = this;
	}
	var aClass = oElement.className.split(" ");
	var arr = [];
	for(var i=0,m=aClass.length;i<m;i++){
		if(aClass[i] != sClassName){
		  arr[arr.length] = aClass[i];
		}
	}
	oElement.className = arr.join(" ");
}

/**
 * 设置class
 * @param  {Element}oElement  设置class的对象
 * @param  {string}sClassName  class值
 * @return {void}
 */
function fSetClass(oElement, sClassName){
	if(arguments.length == 1){
		var sClassName = oElement;
		var oElement = this;
	}
	oElement.className = sClassName;
}

/**
 * 取对象的x坐标
 *
 * @param  {object}element  执行方法的对象
 * @return {Number}         对象的x坐标
 */
function fGetX(oElement){
	if(!oElement){
		var oElement = this;
	}
	var l=oElement.offsetLeft;
	while(oElement=oElement.offsetParent){        
		l+=oElement.offsetLeft;
	}
	return l;
}

/**
 * 取对象的y坐标
 *
 * @param  {object}element  执行方法的对象
 * @return {Number}         对象的y坐标
 */
function fGetY(oElement){
	if(!oElement){
		var oElement = this;
	}
	var t=oElement.offsetTop;
	while(oElement=oElement.offsetParent){
		t+=oElement.offsetTop;
	}
	return t;
}


/**
 * 获取客户端宽度 extend function for coremail 3.0
 * @param void 
 * @return {Number}  客户端宽度
 * @return {Number} The width of the viewable area of the page.
 */
function fGetClientWidth(oDoc){
	return (
		 (oDoc || document).documentElement.offsetWidth
		 || (oDoc || document).body.offsetWidth
	  );
}

/**
 * 获取客户端高度
 * @param void 
 * @return {Number}  客户端高度
 * @return {Number} The height of the viewable area of the page.
 */
function fGetClientHeight(oDoc){
	return (
         self.innerHeight
         || (oDoc || document).documentElement.clientHeight
         || (oDoc || document).body.clientHeight
      );
}
function fGetTopClientHeight(oDoc){
	return (
         top.innerHeight
         || (oDoc || document).documentElement.clientHeight
         || (oDoc || document).body.clientHeight
      );
}
/**
 * 获取事件的触发元素
 * Returns the event's target element
 * @param {Event} ev Event对象
 * @param {boolean} resolveTextNode when set to true the target's
 *                  parent will be returned if the target is a 
 *                  text node
 * @return {HTMLElement} 返回事件的触发元素，如果是文本则返回父元素
 */
function fGetTarget(ev, resolveTextNode){
	if(!ev) ev = this.getEvent();
	var t = ev.target || ev.srcElement;

	if (resolveTextNode && t && "#text" == t.nodeName) {
		return t.parentNode;
	} else {
		return t;
	}
}
/**
 * 获取event对象
 * @param {Event} event对象
 * @return {Event} event对象
 */
function fGetEvent (e) {
	var ev = e || window.event || top.event;	
	if (!ev) {
		var aCaller = [];
		var c = this.getEvent.caller;
		while (c) {
			ev = c.arguments[0];
			if (ev && Event == ev.constructor) {
				break;
			}
			
			var b = false;
			for(var i=0;i<aCaller.length;i++){
				if(c == aCaller[i]){
					b = true;
					break;
				}
			}
			if(b){
				break;
			}else{
				aCaller.push(c);
			}
			c = c.caller;
		}
	}

	return ev;
}

/**
 * 阻止事件冒泡触发以及阻止默认事件触发
 * @param {Event} ev event对象
 * @return {void}
 */
function fStopEvent(ev) {
	if(!ev){
		ev = this.getEvent();
	}
	this.stopPropagation(ev);
	this.preventDefault(ev);
}

/**
 * 阻止事件冒泡触发
 * @param {Event} ev event对象
 * @return {void}
 */
function fStopPropagation(ev) {
	if(!ev){
		ev = this.getEvent();
	}
	if (ev.stopPropagation) {
		ev.stopPropagation();
	}else{
		ev.cancelBubble = true;
	}
}

/**
 * 阻止默认事件触发
 * @param {Event} ev event对象
 * @return {void}
 */
function fPreventDefault(ev) {
	if(!ev){
		ev = this.getEvent();
	}
	if (ev.preventDefault) {
		ev.preventDefault();
	} else {
		ev.returnValue = false;
	}
}

/**
 * 事件触发鼠标x坐标
 * @param {event}ev event对象
 * @return {number}返回x坐标
 */
function fPointerX(ev) {
	if(!ev){
		ev = this.getEvent();
	}
	var doc = document;
    return ev.pageX || (ev.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft));
}

/**
 * 事件触发鼠标x坐标
 * @param {event}ev event对象
 * @return {number}返回y坐标
 */
function fPointerY(ev) {
	if(!ev){
		ev = this.getEvent();
	}
	var doc = document;
    return ev.pageY || (ev.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop));
}

/**
 * 对象坐标
 * @param {element}oElement 坐标的对象
 * @return {array}返回坐标数组
 */
function fPosition(oElement) {
	if(!oElement){
		var oElement = this;
	}
    var nT = 0, nL = 0;
    do {
      nT += oElement.offsetTop  || 0;
      nL += oElement.offsetLeft || 0;
      oElement = oElement.offsetParent;
    } while (oElement);
    return [nL, nT];
}

/**
 * 轮换文字
 * @param {element}oElement 轮换文字的对象
 * @param {string}sText1 轮换文字1
 * @param {string}sText2 轮换文字2
 * @return {void}
 */
function fToggleText(oElement, sText1, sText2){
	if(!sText2){
		sText2 = sText1;
		sText1 = oElement;
		oElement = this;
	}
	oElement = $(oElement);
	if(oElement.innerHTML == sText1){
		oElement.innerHTML = sText2;
	}else{
		oElement.innerHTML = sText1;
	}
}
/**
 * 轮换属性
 * @param  {Array}arr  对象,属性以及值1和值2
 * @return {void}
 */
function fElementToggleAttr(arr){
	for(var i=0,m=arr.length;i<m;i++){
		if(arr[i].length == 3){
			var o = this;
			var a = arr[i][0];
			var v1 = arr[i][1];
			var v2 = arr[i][2];
		}else{
			var o = $(arr[i][0]);
			var a = arr[i][1];
			var v1 = arr[i][2];
			var v2 = arr[i][3];
		}
		if(o[a] == v1){
			o[a] = v2;
		}else{
			o[a] = v1
		}
	}
}

/**
 * 增加事件监视并cache下来
 * @param {element}oElement 事件的对象
 * @param {string}name 事件
 * @param {function}observer 绑定事件的函数
 * @param {bool}useCapture
 * @return {void}
 */
function fObserveAndCache(oElement, name, observer, useCapture) {
	if (!this.observers){
		this.observers = [];
	}
	if (oElement.addEventListener) {
		this.observers.push([oElement, name, observer, useCapture]);
		oElement.addEventListener(name, observer, useCapture);
	}else if(oElement.attachEvent) {
		this.observers.push([oElement, name, observer, useCapture]);
		oElement.attachEvent('on' + name, observer);
	}
}

/**
 * 移除所有监视和cache
 * @param {void}
 * @return {void}
 */
function fUnloadCache() {
    if (!this.observers){
		return;
	}
    for (var i = 0; i < this.observers.length; i++) {
      this.stopObserving(this.observers[i][0],this.observers[i][1],this.observers[i][2],this.observers[i][3]);
      this.observers[i][0] = null;
    }
    this.observers = false;
}

/**
 * 增加事件监视
 * @param {element}oElement 事件的对象
 * @param {string}name 事件
 * @param {function}observer 绑定事件的函数
 * @param {bool}useCapture
 * @return {void}
 */
function fObserve(oElement, name, observer, useCapture) {
    useCapture = useCapture || false;    
    if (name == 'keypress' &&
        (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
        || oElement.attachEvent)){
      name = 'keydown';
	}    
    this.observeAndCache(oElement, name, observer, useCapture);
}

/**
 * 移除事件监视
 * @param {element}oElement 事件的对象
 * @param {string}name 事件
 * @param {function}observer 绑定事件的函数
 * @param {bool}useCapture
 * @return {void}
 */
function fStopObserving(oElement, name, observer, useCapture) {
    useCapture = useCapture || false;    
    if (name == 'keypress' &&
        (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
        || oElement.detachEvent)){
      name = 'keydown';
    }
    if (oElement.removeEventListener) {
      oElement.removeEventListener(name, observer, useCapture);
    } else if (oElement.detachEvent) {
      oElement.detachEvent('on' + name, observer);
    }
}

/**
 * 哈希表类,初始化对象可以传数组，集合，或者不传参数
 *
 * @class 哈希表类
 */
function Hashtable(){
	this._hash = new Object();
	this._type = "object";
	this.isHash = true;
	/**  
	 * 添加对象
	 * @param {string}key 添加的属性或者数组的索引
	 * @param {string}value 添加的对象，可以是任何类型
	 * @return {bool} 成功返回true，失败返回false
	 */
	this.add = function(key,value){
		if(value && value.nodeType && value.nodeType == 1){		// 扩展节点属性
			value = $(value);
		}
		if(key && key.nodeType && key.nodeType == 1){		// 扩展节点属性
			key = $(key);
		}
		if(this._type == "object"){
			if(typeof(key)!="undefined"){
				if(this.contains(key)==false){
					this._hash[key]=typeof(value)=="undefined"?null:value;
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		}else{
			if(typeof(value) != "undefined" && typeof(key)!="undefined"){
				this._hash[key] = value;
				return true;
			}else if(typeof(key)!="undefined"){
				this._hash[this._hash.length] = key;
				return true;
			}else{
				return false;
			}
		}
	};
	/**
	 * 删除对象
	 * @param {string} 要删除的属性或者数组的索引
	 * @return {void}
	 */
	this.remove = function(key){
		delete this._hash[key];
	};
	/**
	 * 对象集合的个数
	 * @param {void}
	 * @return {int} 返回个数
	 */
	this.count = function(){
		if(this._type == "array"){
			return this._hash.length;
		}
		var i=0;
		for(var k in this._hash){
			i++;
		} 
		return i;
	};
	/**
	 * 获取对象
	 * @param {string}key 属性或者索引
	 * @return {string} 返回该对象
	 */
	this.items = function(key){
		return this._hash[key];
	};
	/**
	 * 是否有该key的对象
	 * @param {string}key 属性或者索引
	 * @return 有就返回true，否则返回false
	 */
	this.contains = function(key){
		return typeof(this._hash[key])!="undefined";
	};
	/**
	 * 查找是否有对应值
	 * @param {void}
	 * @return {void}
	 */
	this.has = function(s){
		for(var k in this._hash){
			if(this._hash[k] == s){
				return true;
			}
		}
		return false;
	};
	/**
	 * 清空集合
	 * @param {void}
	 * @return {void}
	 */
	this.clear = function(){
		for(var k in this._hash){
			delete this._hash[k];
		}
	};
	/**
	 * 将值连接
	 * @param {string}sJoin 连接符
	 * @return {void}
	 */
	this.join = function(sJoin){
		var arr = [];
		for(var k in this._hash){
			arr[arr.length] = (this._hash[k] + "");
		}
		return arr.join(sJoin);
	};
	/**
	 * 转换成数组
	 * @param {void}
	 * @return {void}
	 */
	this.toArray = function(){
		var arr = [];
		this.each(function(o, value){
			arr[arr.length] = value;
		});
		return arr;
	};
	/**
	 * 遍历集合
	 * @param {object}func function变量
	 * @return {void}
	 */
	this.each = function(func){
		try{
			if(this._type == "object"){
				for(var k in this._hash){
					try{
						func(k, this._hash[k]);
					}catch(e){
						if (e != $continue){
							throw e;
						}
					}
				}
			}else{
				for(var k=0,m=this._hash.length;k<m;k++){
					try{
						func(k, this._hash[k]);
					}catch(e){
						if (e != $continue){
							throw e;
						}
					}
				}
			}
		}catch(e){
			 if (e != $break) throw e;
		}
	};
	if(arguments.length>0){
		var arg = arguments[0];
		if(typeof arg == "object"){
			if(fIsValidCollection(arg) || arg.ie5){
				this._type = "array";
				this._hash = new Array();
				for(var i=0;i<arg.length;i++){
					this.add(i, arg[i]);
				}
			}else{
				for(var o in arg){
					this.add(o, arg[o]);
				}
			}
		}
	}
}

/**
 * We want to be able to use getElementsByTagName as a collection
 * to attach a group of events to.  Unfortunately, different 
 * browsers return different types of collections.  This function
 * tests to determine if the object is array-like.  It will also 
 * fail if the object is an array, but is empty.
 * @param o the object to test
 * @return {boolean} true if the object is array-like and populated
 */
function fIsValidCollection(o) {
	return ( o && (o.length || o.length == 0) && typeof o != "string" && !o.tagName && !o.alert );
}

/**
* 判断OBJ里面的checkbox是否选择
* @param {object}obj 需要查看的obj对象
* @param {boolean}isAll 是否判断全选
* @return {void}
*/
function fIsChecked(obj,bAll){
	var aList = obj.getElementsByTagName("INPUT");
	var bChecked = false;
	var bAllChecked = true;
	var bResult;
	for(var i=0,m=aList.length;i<m;i++){
		if(aList[i].type!="checkbox"){
			continue;
		}
		if(aList[i].checked){
			bChecked = true;
			if(!bAll){
				break;
			}
		}else{
			bAllChecked = false;
			if(bAll){
				break;
			}
		}
	}
	bResult = bAll ? bAllChecked:bChecked;
	return bResult;
}

/**
* 全选，全不选OBJ下面的CHECKBOX
* @param {object}obj 需要查看的obj对象
* @param {boolean}isChecked 是否选择
* @param {object} fCallback	回调函数
* @return {void}
*/
function fCheckAllCheckbox(obj,isChecked,fCallback){
	var aList = obj.getElementsByTagName("INPUT");
	for(var i=0,m=aList.length;i<m;i++){
		if(aList[i].type!="checkbox"){
			continue;
		}
		if(aList[i].checked == isChecked){
			continue;
		}
		aList[i].checked = isChecked;
		if(fCallback){
			fCallback(aList[i],isChecked);
		}
	}
}

/**
 * 交换数组元素的位置，
 * @param  {number}iIndex    需要交换元素的索引
 * @param  {number}iFlag     前后位置：-1--和前面的对象交换，1--和后面的对象交换
 * @return {void}
 */
function fArrayExchange(iIndex,iFlag){
     if (Math.max(0,iIndex,iIndex+iFlag)<0 || Math.min(this.length-1,iIndex,iIndex+iFlag)>this.length-1){
         return;
     }
     // 交换位置
     var oData = this[iIndex];
     this[iIndex] = this[iIndex+iFlag];
     this[iIndex+iFlag] = oData;
};

/**
 * 去除数组中的空元素
 * @return {Array}
 */
function fArrayEscapeNull(){
    var aRtn = [];
    for (var i=0,len=this.length;i<len;i++){
        if(this[i]){
           aRtn[aRtn.length] = this[i];
        }
    }
    return aRtn;
};

/**
 * 数组克隆
 * @return {Array}
 */
function fArrayClone(){
    var aRtn = [];
    for (var i=0;this[i] && (aRtn[i]=this[i]);i++);
    return aRtn;
};

/**
 * 去除匹配内容的数组元素
 * @param  {String}sCnt 
 *          匹配内容
 * @return {Array}
 */
function fArraySubtract(sCnt){
    var aRtn = [];
    for (var i=0;s=this[i];i++){
        if (s!=sCnt){aRtn[aRtn.length]=s;};
    }
    return aRtn;
};

/**
 * 过滤元素中的特殊字符
 * @param  {RegExp | String}reg
 *          要过滤的字符
 * @return {void}
 */
function fArrayFilter(reg){
    for(var i=0;s=this[i];i++){
       this[i] = s.replace(reg,"");
    }
};

/**
 * ie5增加push方法
 */

/**
 * 最后添加方法
 * @param  {Any}
 *          push的对象
 * @return {void}
 */
function fArrayPush(){
    var startLength = this.length;
    for (var i = 0; i < arguments.length; i++){
      this[startLength + i] = arguments[i];
    }
    return this.length;
}

/**
 * 删除方法
 * @param  {number} n
 *          要删除的索引
 * @return {void}
 */
function fArraySplice(n){
	var arr = new Array();
	for(var i=0;i<this.length;i++){
		if(i != n){
		  arr[arr.length] = this[i];
		}
	}
	return arr;
}

/**
 * ie5增加shift方法
 */
/**
 * 删除并返回第一个
 * @param  {void}
 * @return {void}
 */
function fArrayShift() {
	var returnValue = this[0];
	for (i = 1; i < this.length; i++) {
	  this[i - 1] = this[i];
	}
	this.length--;
	return returnValue;
}

/**
 * 删除并返回最后一个
 * @param  {void} 
 * @return {void}
 */
function fArrayPop() {
	lastElement = this[this.length-1];
	this.length = Math.max(this.length-1,0);
	return lastElement;
}

/**
 * 遍历数组
 * @param  {function} func 遍历需要调用的函数 
 * @return {void}
 */
function fArrayEach(func){
	for(var i=0,m=this.length;i<m;i++){
		try{
			func(i, this[i]);
		}catch(exp){
			if(exp == $break){
				break;
			}else if(exp == $continue){
				continue;
			}else{
				throw exp;
			}
		}
	}
}

/**
 * 遍历数组
 * @param  {object} value 判断数组中是否含有某个值 
 * @return {boolean} 
 */
function fArrayHas(value){
	var r = false;
	this.each(function(i, o){
		if(o == value){
			r = true;
			throw $break;
		}
	});
	return r;
};

/**
 * 转换成字符串
 */
function fArrayToString(sSplitter){
	if(!sSplitter){
		sSplitter = "";
	}
	return this.join(sSplitter);
}

/*
// IE's function encodeURIComponent will force UTF8 encode, so we overwrite it
var URI_E_CHARS = new Array();
for (var i = 0x00; i < 0x80; i++) {
    var c = String.fromCharCode(i);
    if (i < 0x10) {
        URI_E_CHARS[c] = "%0" + i.toString(16);
    } else if (c >= '0' && c <= '9') {
    } else if (c >= 'A' && c <= 'Z') {
    } else if (c >= 'a' && c <= 'z') {
    } else {
        URI_E_CHARS[c] = "%" + i.toString(16);
    }
}
URI_E_CHARS[" "]  = "+";
window.encodeURIComponent = function(s) {
    var s1 = "";
    for (var i = 0; i < s.length; i++) {
        var c0 = s.charAt(i);
        var c1 = URI_E_CHARS[c0];
        s1 += c1 ? c1 : c0;
    }
    return s1;
};
*/

/**
 * 转化HTML到文本，保留换行和空格
 */
function Html2Text(sHtml){
    var tag="";
    var result="";
    var sTmp="";
    var l = "<";
    var r = ">";
    var offset1=-1;
    var offset2=-1;    
    var temp="";    
    sTmp = sHtml;    
    do{
        offset1 = sTmp.indexOf(l);
        offset2 = sTmp.indexOf(r);    
        if (offset1 > 0 ){ 
            temp = sTmp.substring(0,offset1);
			result += temp; 
			sTmp = sTmp.substring(offset1,sTmp.length);
			continue;
		}
        if( offset1 == -1 ){
            result += sTmp;
            break;
        }    
        tag = sTmp.substring(offset1+1,offset2);
        sTmp = sTmp.substring(offset2+1,sTmp.length);
        if(tag == "br" || tag =="BR" ){ 
            result += "\r\n";  }
        else{
            tag = "";
        }
    }while(1);    
    while ( result.indexOf("&nbsp;") != "-1" ) result = result.replace("&nbsp;"," ");
    return result;
}

/**
 * 检查当前是否真是onmouseover状态
 * @private
 * @param  {object}o 绑定事件的对象
 * @param  {object}e 事件
 * @return {bool} 返回状态     
 */
function fCheckIsOnMouseOver(o, e){
	try{
		var e = e || EV.getEvent();
		var to = e.toElement || e.target;
		var from = e.fromElement || e.relatedTarget;
		if(El.descendantOf(to, o) && !El.descendantOf(from, o)){
			return true;
		}else{
			return false;
		}
	}catch(exp){
		return true;
	}
}

/**
 * 检查当前是否真是onmouseout状态
 * @private
 * @param  {object}o 绑定事件的对象
 * @param  {object}e 事件
 * @return {bool} 返回状态     
 */
function fCheckIsOnMouseOut(o, e){
	try{
		var e = e || EV.getEvent();
		var to = e.toElement || e.relatedTarget;
		var from = e.fromElement || e.target;
		// var div = El.createElement("div");div.innerHTML = to.outerHTML.encodeHTML();document.body.appendChild(div);
		if(!El.descendantOf(to, o) && El.descendantOf(from, o)){
			return true;
		}else{
			return false;
		}
	}catch(exp){
		return true;
	}
}

function Email(){
	this.add = fEmailAdd;			// 添加email地址
	this.remove = fEmailRemove;		// 删除email地址
	this.has = fEmailHas;			// 是否存在该email地址
	this.each = fEmailEach;			// 枚举所有email
	this.toString = fEmailToString;	// 转换成字符串
	this.toArray = fEmailToArray;		// 转换成数组
	this.initialize = fEmailInitialize;
	this.initialize();
};

function fEmailValue(n, a){
	/** 名字 */
	this.name = "";
	/** email地址 */
	this.address = "";
	this.toString = fEmailValueToString;
	this.initialize = fEmailValueInitialize;
	this.initialize(n, a);
}

function fEmailFormat(s){
	try{
		var t = s+"";
		var a = t.split(",");
		if(a.length > 0){
			a.each(function(i, v){
				a[i] = v.trim();
				if(i > 0) a[i] =  " " + a[i];
			});
			t = a.join(",");
		}
		return t.replace(/(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/g, '<a href="mailto:$1" class="fgy">$1</a>');
	}catch(exp){
		return s;
	}
}

/**
 * 是否匹配一个email地址
 * @param {String} t 一个email地址的字符串
 * @return {bool|Object} 匹配不成功,返回false,成功就返回Email.Value的对象
 */
function fEmailMatch(t){
	var name = "", address = "";
	iPos = t.lastIndexOf("@");
	var reg = /^@([\w-]+\.)+[\w-]{2,4}$/;
	if( iPos == -1 || t.length == iPos + 1){
		return false;
	}
	if( t.indexOf(">")==-1 && t.indexOf("<")==-1 ){
		if( t.indexOf("@") != iPos || t.indexOf("@") == 0){
			return false;
		}
	}
	if( t.charAt(t.length-1) == ">" ){
		sDomain = t.substring( iPos , t.length-1 );
	}else{
		sDomain = t.substr( iPos );
	}
	if( !reg.test(sDomain) ){
		return false;
	}
	if(t.indexOf(">") > -1 && t.indexOf("<") > -1){
		address = t.replace(/.*</, "").replace(/>/, "");
		name = t.replace(/<.+/, "").replace(/\"/g, "");
	}else{
		address = t;
	}
	if(name == ""){
		name = address.split("@")[0];
	}
	return new Email.Value(name, address);
}

/**
 * 匹配和获取email地址
 * @param {String} v 一个或者多个email地址的字符串
 * @return {Object} 返回一个对象,success为成功匹配的数据,Email对象,fail为不成功的数据,数组对象
 */
function fEmailGet(v){
	var s = new Email(), f = [];
	if(typeof v == "string" && v.trim() != ""){
		var sMail = v.replace(/[,;，；]+/g , ",");
		var arrMail = sMail.split(",");
		arrMail.each(function(i, value){
			var r = Email.match(value);
			if(r){
				s.add(r);
			}else{
				f.push(value);
			}
		});
	}else if(v instanceof Array){
		v.each(function(i, value){
			var r = Email.match(value);
			if(r){
				s.add(r);
			}else{
				f.push(value);
			}
		});
	}
	return {success : s, fail: f};
}

/**
 * Email.Value类初始化
 * @param {String} n 名字
 * @param {String} a 地址
 * @return {void}
 */
function fEmailValueInitialize(n, a){
	this.name = n;
	this.address = a;
}

/**
 * Email.Value对象转换成字符串
 */
function fEmailValueToString(isNoName){
	var s;
	if(isNoName){
		s = this.address;
	}else{
		s = '"'+this.name+'" <'+this.address+'>';
	}
	return s;
}

/**
 * 获取名字部分
 * @param {String} v 一个email地址的字符串
 * @return {bool|String} 匹配不成功,返回false,成功就返回名字部分
 */
function fEmailGetName(v){
	var r = Email.match(v);
	if(r){
		return r.name;
	}
	return r;
}

/**
 * 获取地址部分
 * @param {String} v 一个email地址的字符串
 * @return {bool|String} 匹配不成功,返回false,成功就返回地址部分
 */
function fEmailGetAddress(v){
	var r = Email.match(v);
	if(r){
		return r.address;
	}
	return r;
}

/**
 * 添加方法
 * @param {String|Object} v 一个email地址的字符串,或者一个Email对象
 * @return {Object} 成功就返回一个Email对象,否则返回null
 */
function fEmailAdd(v){
	if(typeof v == "string"){
		var r = Email.match(v);
		if(r){
			this.hash.add(r.address, r);	
		}
		return r;
	}else if(v instanceof Object){
		this.hash.add(v.address, v);
		return v
	}
	return null;
}

/**
 * 删除方法
 * @param {String} k hash的key,地址作为key
 * @return {void} 
 */
function fEmailRemove(k){
	this.hash.remove(k);
}

/**
 * Email对象是否存在输入的地址
 * @param {String} s 地址
 * @return {bool} 存在就返回true,否则返回false 
 */
function fEmailHas(s){
	var r = false;
	this.hash.each(function(k, v){
		if(v.address == s){
			r = true;
		}
	});
	return r;
}

/**
 * 遍历Email对象
 * @param {function} 遍历的处理函数, 传参数名称和地址
 * @return {void} 
 */
function fEmailEach(f){
	this.hash.each(function(k, v){
		f(v.name, v.address);
	})
}

/**
 * Email对象转换成字符串
 * @param {String} s 分隔符
 * @return {String} 返回字符串格式
 */
function fEmailToString(s, isNoName){
	var s = s || ",";
	var r = this.toArray(isNoName);
	return r.join(s);
}

/**
 * Email对象转换成数组
 * @param {void} 
 * @return {Array} 返回数组
 */
function fEmailToArray(isNoName){
	var r = [];
	this.each(function(name, address){
		if(isNoName){
			r.push(address);
		}else{
			r.push('"'+name+'" <'+address+'>');
		}
	});
	return r;
}

/**
 * Email构造函数
 * @param {void} 
 * @return {void}
 */
function fEmailInitialize(){
	this.hash = new Hashtable();
}

/**
 * 通过传入的数组值转换成十进制
 * 传入的数组中只存在0，1；对应二进制从右到左例如，传入[1,0,1,1]对应二进制为1101
 * @param {Array} aValue 
 * @return {Number} 返回十进制
 */
function fSetBit(aValue){
	num = 0;
	for(var i=0,n=aValue.length;i<n;i++){
		num += Math.pow(2,i)*aValue[i];
	}
	return num;
}

/**
 * Number方法，通过传入的位，获得十进制数对应的二进制对应位的值
 * 对应二进制从右到左，从0开始；例如，传入1对应二进制1101中的0
 * @param {Number} nPos 
 * @return {Number} 返回十进制
 */
function fNumberGetBit(nPos){
	num = this;
	if(typeof nPos != "number" || isNaN(nPos)){
		nPos = 0;
	}
	var nCompare = Math.pow(2,nPos);
	if((num & nCompare) > 0){
		return 1;
	}else{
		return 0;
	}
}

/**
 * Number方法，通过传入的位和值，设置十进制数对应的二进制对应位的值
 * 对应二进制从右到左，从0开始；例如，传入1对应二进制1101中的0
 * @param {Number} nPos
 * @param {Number} nValue
 * @return {Number} 返回十进制
 */
function fNumberSetBit(nPos,nValue){
	num = this;
	if(typeof nPos != "number" || isNaN(nPos)){
		nPos = 0;
	}
	if(typeof nValue != "number"  || isNaN(nValue)){
		return num;
	}
	if(num.getBit(nPos)!=nValue){
		var nCompare = Math.pow(2,nPos);
		if(nValue == 0){
			return num ^ nCompare;
		}else{
			return num | nCompare;
		}
	}
	return num;
}

function $A(o){
	var aTmp = [];
	if(fIsValidCollection(o)){
		for(var i=0,m=o.length;i<m;i++){
			aTmp[i] = o[i];
		}
	}
	return aTmp;
}

fGetUserAgen();

/**
 * 使对象可以拖动
 * @param {object}obj 触发拖动的对象
 * @param {object}oMoveObj 被拖动的对象
 */
function fSetDragable(obj, oMoveObj){
	var oDoc = document;
	var fSelectEvent = function(){return false};
	var fObjMoving = function(e){
		var ev = e || top.event;		// 获取event对象
		if(oDoc.all && ev.button != 1){
			obj.onmouseup();
			return;
		}
		var x = EV.pointerX(ev);	// 获取鼠标坐标
		var y = EV.pointerY(ev);	
		var x1 = x - oMoveObj.x;
		var y1 = y - oMoveObj.y;
		oMoveObj.style.left = parseInt(oMoveObj.style.left, 10) + x1 + "px";	// 设置位置
		oMoveObj.style.top = parseInt(oMoveObj.style.top, 10) + y1 + "px";
		oMoveObj.x = x;
		oMoveObj.y = y;
	};
	obj.onmousedown = function(e){
		var ev = e || top.event;	// 获取event对象
		var x = EV.pointerX(ev);	// 获取鼠标坐标
		var y = EV.pointerY(ev);
		oMoveObj.x = x;
		oMoveObj.y = y;
		EV.observe(oDoc, "mousemove", fObjMoving);		// 添加oDoc onmousemove事件
		EV.observe(oDoc, "selectstart", fSelectEvent);	// 添加oDoc selectstart事件
	};
	obj.onmouseup = function(){
		EV.stopObserving(oDoc, "mousemove", fObjMoving);
		EV.stopObserving(oDoc, "selectstart", fSelectEvent);
		var oMaskItem = $("maskItem");
		if(oMaskItem){
			oMaskItem.style.display = "none";
		}
	};
}

function $$(sId) {
	return document.getElementById(sId);
}

/**
 * 系统弹出对话框
 *
 * Tilte : 标题
 * Content : 内容
 * Type : 类型
 * IsModeless : 是否显示遮罩
 * Call : 执行
 * CancelCall : 取消执行
 * DefaultValue : 文本默认值
 */
function fShowSysMsg(oMsg) {
	var oDoc = document;
	var sHtml = '<div class="systip" id="dvSysMsg">' +
		        '   <div class="systip_title" id="dvSysTitle">' +
		        '		<div class="systip_bg systip_left"></div>' +
		        '		<div class="systip_bg systip_text">$title$</div>' +
		        '		<div class="systip_bg systip_right"><a href="javascript:void(0);" title="关闭" class="systip_bg" id="lnkSysClose"></a></div>' +
		        '	</div>' +
		        '	<div class="systip_content"> ' +
		        '		<div class="systip_message" id="spnMsgCon">$content$</div>' +
		        '	</div>' +
		        '	<div class="systip_footer" > ' +
		        '		<div class="systip_footer_in" id="dvSysBottom">' + '$cancel$' + '$ok$' + '</div>' +
		        '	</div>' +
		        '</div>';
	var sCancelHtml = '<input type="button" id="btnSysCancel" class="systip_btn button_off" value="  取 消  "  onMouseOver="this.className=\'systip_btn button_on\'" onMouseOut="this.className=\'systip_btn button_off\'" />';
	var sOkHtml = '<input type="button" id="btnSysOk" class="systip_btn button_off" value="  确 定  "   onMouseOver="this.className=\'systip_btn button_on\'" onMouseOut="this.className=\'systip_btn button_off\'" />';
	if(!oMsg.IsModeless){
		var sWidth = "100%";
	    var sHeight = "100%";	
	    var sAlpha = "-moz-opacity:0.07;";
	    sAlpha += "filter:alpha(opacity=7);";
	    if(navigator.userAgent.indexOf("opera") > -1 || navigator.userAgent.indexOf("safari") > -1) sAlpha = "opacity:0.07;";
		sMaskHtml = '<div style="position:absolute;z-index:998;top:0;left:0;width:'+ document.body.clientWidth +';height:'+ (fGetTopClientHeight(oDoc) + document.body.scrollTop) +';'+ sAlpha +'background-color:#000000"></div>';
		var oDivMask = oDoc.createElement("DIV");
		oDivMask.innerHTML = sMaskHtml;
		oDivMask.id = "dvSysMask";
		oDoc.body.appendChild(oDivMask);
	}
	switch(oMsg.Type){
	    case "iframe":
	        var oContent = oMsg.Content;
	        oMsg.Content = '<iframe id="'+ oContent.IframeName +'" src="../upload.aspx?ctrlid='+ oContent.CtrlId +'&type='+ oContent.Type +'" style="width:338px;height:68px" scrolling="no" frameborder="0"></iframe>';
	        break;
	    case "prompt":
    		oMsg.Content = '<table cellspacing="0" cellpadding="0" border="0">' +
	                       '   <tr>' +
	                       '       <td nowrap>'+ oMsg.Content +'：</td>' +
	                       '       <td><input type="'+ (oMsg.isPassword ? "password" : "text") +'" id="txtSysPrompt" value="" />&nbsp;<br /><span id="spnSysError"></span></td>' +
                           '   </tr>' +
                           '</table>';
	        break;
	}
	sHtml = sHtml.replace("$title$", oMsg.Title || "系统提示");
	sHtml = sHtml.replace("$content$", oMsg.Content || "");
	sHtml = sHtml.replace("$cancel$", !oMsg.isCancel ? sCancelHtml : "");
	sHtml = sHtml.replace("$ok$", !oMsg.isOk ? sOkHtml : "");
	var oDiv = oDoc.createElement("DIV");
	oDiv.innerHTML = sHtml;
	oDiv.className = "systip";
	oDiv.style.position = "absolute";
	oDiv.style.zIndex = 999;
	oDiv.id = "dvSysMsg";
	oDoc.body.appendChild(oDiv);
	function fRemove() {
		oDiv.parentNode.removeChild(oDiv);
		if(oDivMask) oDivMask.parentNode.removeChild(oDivMask);
		fShowItems();
	}
	$$("btnSysOk").onclick = function(){
		try{
			if(oMsg.Call){
				var r = oMsg.Call($$("txtSysPrompt") ? $$("txtSysPrompt").value : window.undefined);
				if(oMsg.Type=="prompt" && r){
					$$("spnSysError").innerHTML = r;
					return;
				}else if(r){
					return;
				}
			}
		}catch(exp){}
		fRemove();
	};
	if($$("btnSysCancel")){
		$$("btnSysCancel").onclick = function(){
			try{
				(oMsg.CancelCall || function(){})();
			}catch(exp){}
			fRemove();
		}
	}
	if($$("lnkSysClose")){
		$$("lnkSysClose").onclick = function(){
			try{
				(oMsg.CancelCall || function(){})();
			}catch(exp){}
			fRemove();
		}
	}
	var aHideItems = [];
	function fHideItems() {
		var arr = ((gIsIE && (gVersion == "5" || gVersion == "5.01"))?(["SELECT", "IFRAME"]):(((!gIsIE || (gIsIE && gVersion >= "7")) || gAppName == "opera")?[]:["SELECT"]));
		//var aIfrm = ["tope", "left", "main"];
		for(var i=0;i<arr.length;i++){
		//    for(var j=0;j<aIfrm.length;j++){
		//        $A(top.frames[aIfrm[j]].document.getElementsByTagName(arr[i])).each(function(i, o){
				$A(document.getElementsByTagName(arr[i])).each(function(i, o){
					if(o.id == "selNewGroup") throw $continue;
					o.style.visibility = "hidden";
					aHideItems[aHideItems.length] = o;
				});
				if(gIsIE && (gVersion == "5" || gVersion == "5.01")){
		//            $A(top.frames[aIfrm[j]].document.getElementsByTagName(arr[i])).each(function(i, o){
				    $A(document.getElementsByTagName(arr[i])).each(function(i, o){
						if(o.id == "selNewGroup") throw $continue;
						o.style.visibility = "hidden";
						aHideItems[aHideItems.length] = o;
					});
				}
		//    }
		}
	}
	function fShowItems() {
		try{
			for(var i=0;i<aHideItems.length;i++){
				if(aHideItems[i]){
					aHideItems[i].style.visibility = "visible";
				}
			}
		}catch(exp){}
	}
	fHideItems();
	top.fShowItems = fShowItems;
	top.aHideItems = aHideItems;
	var h = oDiv.offsetHeight;
	var w = oDiv.offsetWidth;
	var scrollTop = oDoc.body.scrollTop;
	var x = (fGetClientWidth(oDoc) - w)/2;
	var y = (fGetTopClientHeight(oDoc) - h)/2 + scrollTop;
	oDiv.style.left = x + "px";
	oDiv.style.top = y + "px";
	if(oMsg.Type=="prompt"){
		if(oMsg.DefaultValue){
			$$("txtSysPrompt").value = oMsg.DefaultValue;
		}
		$$("txtSysPrompt").select();
	}else{
		$$("btnSysOk").focus();
	}
	fSetDragable($$("dvSysTitle"), oDiv);
	return {ok : $$("btnSysOk"), cancel : $$("btnSysCancel"), "prompt" : $$("txtSysPrompt")};
}

function Uploadfile(id, type){
	fShowSysMsg({ Type : "iframe", Title : "上传文件", Content : { IframeName:"Uploadfile", CtrlId:id, Type:type } });
}