//==========================================SYSTEM 
//IS IE
var _isie = null;
function IsIE(){ //ie
if (_isie == null){
    var navistr = window.navigator.userAgent.toLowerCase();
    if (navistr.indexOf("msie")>=1 ) 
    _isie = true; 
   else 
    _isie = false; 
}
return _isie;
} 

function EventSrc()
{
    if (IsIE()) {return window.event.srcElement;}
    
    var func=EventSrc.caller;
    while(func!=null)
    {   
        var arg0=func.arguments[0];
        if(arg0 && typeof(arg0.constructor) == 'object') {if(arg0.constructor==MouseEvent){  return arg0.target; }}
        func=func.caller;
    }
    var e = null;
    try{e = window.event.srcElement;}catch(ex){}
    return e;
}

function $(id) { return document.getElementById(id); }
function $DC(id) { return document.getElementById(id); }

//返回新建对象
var ThisObjTemp = null;
function $create(str)
{
    if (document.all) {return document.createElement(str);}
    str = str.Trim().replace(/^<|\/?\s*>$/g,"");
    var a = str.split(/\s+/);
    var o = document.createElement(a[0]);
    if (a.length>1)
    {
        str.replace(/(\w+)=([^\s\'\"]+)|(\w+)=\'([^\']+)\'|(\w+)=\"([^\"]+)\"/g,function(v,v1,v2,v3,v4,v5,v6)
        {
                o.setAttribute(v1||v3||v5,v2||v4||v6);
        });
    }
    return o;
}

var Mouse = new function(){
    this.x = 0;
    this.y = 0;
    this.capture = function(evt){
        if (document.all) {//  IE
            try{
            Mouse.x = window.event.x + document.body.scrollLeft;
            Mouse.y = window.event.y + document.body.scrollTop;
            }catch(e){}
        } else if (document.layers||document.getElementById) {    //  Netscape
            Mouse.x = evt.pageX;
            Mouse.y = evt.pageY;
        }
        //alert(Mouse.x + "/" + Mouse.y); //test
    };
    if (document.layers) { //netscape
        document.captureEvents(Event.MOUSEMOVE);
    }
    //此行代码影响鼠标事件
    //document.onmousemove = this.capture;
}


function GetScroll()
{
    var t, l, w, h;
    if (document.documentElement && document.documentElement.scrollTop) {
    t = document.documentElement.scrollTop;
    l = document.documentElement.scrollLeft;
    w = document.documentElement.scrollWidth;
    h = document.documentElement.scrollHeight;
    } else if (document.body) {
    t = document.body.scrollTop;
    l = document.body.scrollLeft;
    w = document.body.scrollWidth;
    h = document.body.scrollHeight;
    }
    return { t: t, l: l, w: w, h: h };
} 
//为FOXFIRE创建innerText的属性
if(!IsIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__("innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__("innerText",function(sText){this.textContent=sText; });
}
/**
 *   兼容firefox的 outerHTML  使用以下代码后，firefox可以使用element.outerHTML
 **/




if(window.HTMLElement) {
    HTMLElement.prototype.click = function()
{
       var evt = this.ownerDocument.createEvent('MouseEvents');
       evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
       this.dispatchEvent(evt);
};
    
    HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
        var r=this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df=r.createContextualFragment(sHTML);
        this.parentNode.replaceChild(df,this);
        return sHTML;
        });

    HTMLElement.prototype.__defineGetter__("outerHTML",function(){
     var attr;
        var attrs=this.attributes;
        var str="<"+this.tagName.toLowerCase();
        for(var i=0;i<attrs.length;i++){
            attr=attrs[i];
            if(attr.specified)
                str+=" "+attr.name+'="'+attr.value+'"';
            }
        if(!this.canHaveChildren)
            return str+">";
        return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
        });
        
 HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
  switch(this.tagName.toLowerCase()){
            case "area":
            case "base":
         case "basefont":
            case "col":
            case "frame":
            case "hr":
            case "img":
            case "br":
            case "input":
            case "isindex":
            case "link":
            case "meta":
            case "param":
            return false;
        }
        return true;

     });
}

//onmouseenter和onmouseleave. 
var EleEvetBind = 
{ 
evtHash: [], 
ieGetUniqueID: function(_elem) 
{ 
if (_elem === window) { return 'theWindow'; } 
else if (_elem === document) { return 'theDocument'; } 
else { return _elem.uniqueID; } 
}, 
addEvent: function(_elem, _evtName, _fn, _useCapture) 
{ 
if (typeof _elem.addEventListener != 'undefined') 
{ 
if (_evtName == 'mouseenter') 
{ _elem.addEventListener('mouseover', EleEvetBind.mouseEnter(_fn), _useCapture); } 
else if (_evtName == 'mouseleave') 
{ _elem.addEventListener('mouseout', EleEvetBind.mouseEnter(_fn), _useCapture); } 
else 
{ _elem.addEventListener(_evtName, _fn, _useCapture); } 
} 
else if (typeof _elem.attachEvent != 'undefined') 
{ 
var key = '{FNKEY::obj_' + EleEvetBind.ieGetUniqueID(_elem) + '::evt_' + _evtName + '::fn_' + _fn + '}'; 
var f = EleEvetBind.evtHash[key]; 
if (typeof f != 'undefined') 
{ return; } 
f = function() 
{ 
_fn.call(_elem); 
}; 
EleEvetBind.evtHash[key] = f; 
_elem.attachEvent('on' + _evtName, f); 
// attach unload event to the window to clean up possibly IE memory leaks 
window.attachEvent('onunload', function() 
{ 
_elem.detachEvent('on' + _evtName, f); 
}); 
key = null; 
//f = null; /* DON'T null this out, or we won't be able to detach it */ 
} 
else 
{ _elem['on' + _evtName] = _fn; } 
}, 
removeEvent: function(_elem, _evtName, _fn, _useCapture) 
{ 
if (typeof _elem.removeEventListener != 'undefined') 
{ _elem.removeEventListener(_evtName, _fn, _useCapture); } 
else if (typeof _elem.detachEvent != 'undefined') 
{ 
var key = '{FNKEY::obj_' + EleEvetBind.ieGetUniqueID(_elem) + '::evt' + _evtName + '::fn_' + _fn + '}'; 
var f = EleEvetBind.evtHash[key]; 
if (typeof f != 'undefined') 
{ 
_elem.detachEvent('on' + _evtName, f); 
delete EleEvetBind.evtHash[key]; 
} 
key = null; 
//f = null; /* DON'T null this out, or we won't be able to detach it */ 
} 
}, 
mouseEnter: function(_pFn) 
{ 
return function(_evt) 
{ 
var relTarget = _evt.relatedTarget; 
if (this == relTarget || EleEvetBind.isAChildOf(this, relTarget)) 
{ return; } 
_pFn.call(this, _evt); 
} 
}, 
isAChildOf: function(_parent, _child) 
{ 
if (_parent == _child) { return false }; 
while (_child && _child != _parent) 
{ _child = _child.parentNode; } 
return _child == _parent; 
} 
};



//为Number对象
Number.prototype.toFixed=function(len)
{
    var add = 0;
    var s,temp;
    var s1 = this + "";
    var start = s1.indexOf(".");
    if(s1.substr(start+len+1,1)>=5)add=1;
    var temp = Math.pow(10,len);
    s = Math.floor(this * temp) + add;
    return s/temp;
}
//为string对象增加TRIM的功能
String.prototype.Trim = function(){return this.replace(/(^[ |　]*)|([ |　]*$)/g, "");}
String.prototype.Length = function()
{
    var i,sum;
    sum=0;
    var str = this;
    for(i=0;i<str.length;i++)
    {
        if ((str.charCodeAt(i)>=0) && (str.charCodeAt(i)<=255))
            sum=sum+1;
        else
            sum=sum+2;
    }
    return sum;
}

//获取控件绝对左坐标 象素单位
function   GetAbsLeft(e){var   l=e.offsetLeft;   while(e=e.offsetParent)   l   +=   e.offsetLeft;   return   l;}   
//获取控件绝对顶坐标 象素单位
function   GetAbsTop(e) {var   t=e.offsetTop;     while(e=e.offsetParent)   t   +=   e.offsetTop;     return   t;}


function WindowObject(name) 
{
    if (window.navigator.userAgent.toLowerCase().indexOf("msie")<1) 
    {
        return window[name];
    }
    else 
    {
        return document[name];
    }
}


WindowCharReload();

function WindowCharReload()
{
    if (typeof(WindowCharReloading) == 'undefined'){return;}
    var url = window.location.toString();
    if(/.*[\u4e00-\u9fa5]+.*$/.test(url)) 
    {
        url = encodeURI(url);
        //alert(url);
        window.location = url;
    }
}
//==========================================end系统兼容函数

function ChkTelephone(s)
{
    var pattern = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{5,9})(-(\d{2,4}))?(,\d{5,9}(-\d{2,4})?){0,3}$/;
	s = s.Trim();
	if (s.value == "" || !pattern.test(s)) { return false; }
	return true;

}

function PressIsTel(evt) {
    var key = eventCodeGet(evt);
    return ((key >= 48 && key <= 57) || key == 13 || key == 44 || key == 45);
}


function PressIsEmail(evt) {
    var key = eventCodeGet(evt);
    var b = false;
    //alert(key);
    if (key >= 48 && key <= 57) {
        b = true; //数字
    }
    else if (key >= 97 && key <= 122) {
        b = true; //小写字母
    }
    else if (key >= 65 && key <= 90) {
        b = true; //大写字母
    }
    else {
        switch (key) {
            case 13: //回车
            case 46: //.
            case 45: //-
            case 95: //_
            case 64: //@
                b = true;
                break;
        }
    }
    return b;
}

function ChkMobile(s)
{

    var partern = /^(1[358]\d{9})?(,1[358]\d{9}){0,2}$/;
	s = s.Trim();
	if (s.value == "" || !partern.test(s) ){return false;}
	return true;
}

function ChkEmail(s)
{
    var partern=/^(\s*([A-Za-z0-9_-]+(\.\w+)*@([\w-]+\.)+\w{2,3})\s*)?(,\s*([A-Za-z0-9_-]+(\.\w+)*@([\w-]+\.)+\w{2,3})\s*){0,2}$/;
	s = s.Trim();
	if (s.value == "" || !partern.test(s)) { return false; }

	var exts = '.com|.net|.cn .org|.biz|.cc|.name|.in|.mobi|.ac|.tw|.cm|.hk|.sh|.ac|.io|.travel|.ws|.us|.info|.tv|.ag|.vc|.la|.bz|.sc|.mn';
	s = s.toLowerCase();
	var ix = s.lastIndexOf('.');
	if (ix < 0) {
	    return false;
	}
	var emailExt = s.substring(ix);
	if (exts.indexOf(emailExt) < 0) {
	    return false;
	}
	
	return true;
}

function ChkInts(v)
{
    var partern=/^(\d+)?(,\d+)*$/;
	if (v == ""){return false;}
	if (!partern.test(v)){ return false;}
	return true;
}

function ChkInt(obj)
{
	var v = obj.value.replace(/１/g,"1").replace(/２/g,"2").replace(/３/g,"3").replace(/４/g,"4").replace(/５/g,"5").replace(/６/g,"6").replace(/７/g,"7").replace(/８/g,"8").replace(/９/g,"9").replace(/０/g,"0");
	var S = /^\d+$/;
	if(!S.test(v)){
		if(arguments[1]){obj.value = arguments[1];}
		else {obj.value = "";}
		return false;
	}
	obj.value = v;
	return true;
}

//onkeypress(onkeydown)="return ChkDigit(this)"
//style="ime-mode:disabled"
function eventCodeGet(e) {
    if (!e) { var e = window.event; }var code;if (e.keyCode) { code = e.keyCode; } else if (e.which) { code = e.which; } else { code = window.event.keyCode;}
    return code;
}


function ChkDigit(e)
{
    var key = eventCodeGet(e);
	return ((key>=48 && key<=58) || key == 13);
}

function ChkDigits(e)
{
    var key = eventCodeGet(e);
	return ((key>=48 && key<=58) || key == 13 || key == 44);
}

function chkNumeric(e)
{
    var key = eventCodeGet(e);
	return ( (key>=48 && key<=58) || key == 46 || key == 13);
}

//onkeypress="return ChkStrNormal(event)" onblur="ChkStrNormalBlur(this)"
function ChkStrNormalBlur(e) { var v = e.value.Trim(); v = v.replace(/@/ig, ''); e.value = v; }
function ChkStrNormal(e) { var key = eventCodeGet(e); if (key == 64 || key == 229 || key == 39) { return false; } return true; }


function isNumeric(obj,isEmpty)
{
    var S = /^(-?\d+)(\.\d+)?$/;
	var V =  (obj.attributes["prevalue"]?obj.attributes["prevalue"].value:"");
	var v = obj.value;
	if (isEmpty && v == ""){  return;}
	if(!S.test(v))
	{
		if (arguments[2]) {alert("请输入正确的数据类型！");}
		obj.value = V;
		obj.select();
		return false;
	}
	return true;
}





function ChkDate(obj){
	var ret = true,arrDate;
	var V =  (obj.attributes["prevalue"]?obj.attributes["prevalue"].value:"");
    if(obj.value == "" && V == "")
	{//如果为空，则通过校验 
		ret = true; 
	}
	else
	{
		var pattern = /^((\\d{4})|(\\d{2}))-(\\d{1,2})-(\\d{1,2})$/g; 
		var str = obj.value.Trim().split(' ');
		if(!pattern.test(str[0])){ret = false; }
		arrDate = str[0].split("-"); 
		if(parseInt(arrDate[0],10)<100){arrDate[0] = 2000 + parseInt(arrDate[0],10) + ""; }
		var date =  new Date(arrDate[0],(parseInt(arrDate[1],10)-1)+"",arrDate[2]); 
		if(date.getFullYear()==arrDate[0] && date.getMonth()==(parseInt(arrDate[1],10) -1)+"" && date.getDate()==parseInt(arrDate[2],10)){
			ret = true; 
		}
		else {ret = false; }
		
		if(str[1] && str[1]!=''){
			pattern2 = /^(([1-2][0-4])|([0-1]?[0-9])):([0-5]?[0-9]):([0-5]?[0-9])$/g;
			ret = pattern2.test(str[1]);
		}
	}
	//alert(obj.value);
	//alert(ret);
	if (!ret){  obj.value = V;}
	return ret;
}

function SetDateNext(obj,name,day,k)
{
    if (obj.value == ""){return;}
    if (!ChkDate(obj)){ return true;}
    arrDate = obj.value.split("-"); 
    var ik = typeof(k)=="undefined"?1:k;
    var d ;
    switch(ik)
    {
    case "y":
    //d = new Date(parseInt(arrDate[0],10)+day,(parseInt(arrDate[1],10)-1)+"",parseInt(arrDate[2],10));
    document.getElementById(name).value = (parseInt(arrDate[0],10)+day) + "-" +arrDate[1] +"-"+arrDate[2];
    return;
    break;
    case "m":
    d = new Date(arrDate[0],(parseInt(arrDate[1],10)-1)+day,arrDate[2]);
    break;
    default:
    d = new Date(arrDate[0],arrDate[1],arrDate[2]);
    d = d.valueOf();
    d = d + (day* 24 * 60 * 60 * 1000);
    d = new Date(d);
    break;
    }
    document.getElementById(name).value = d.getFullYear() + "-" + (d.getMonth()) + "-" + d.getDay();
}

function ChkIsChinese(str) {
    //如果值为空，通过校验 
    if (str == "") {
        return false;
    }
    var pattern = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;
    var t = pattern.test(str);
    if (t) { return true; }
    else { return false; }
}

function ReplaceChr(obj,v1,v2)
{
    obj.value = obj.value.replace(v1,v2);
}


var Cookies = {};
/**//**
 * 设置Cookies
 */
Cookies.Set = function(name, value){
     var argv = arguments;
     var argc = arguments.length;
     var expires = (argc > 2) ? argv[2] : null;
     var path = (argc > 3) ? argv[3] : '/';
     var domain = (argc > 4) ? argv[4] : null;
     var secure = (argc > 5) ? argv[5] : false;
     document.cookie = name + "=" + escape (value) +
       ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
       ((path == null) ? "" : ("; path=" + path)) +
       ((domain == null) ? "" : ("; domain=" + domain)) +
       ((secure == true) ? "; secure" : "");
};
/**//**
 * 读取Cookies
 */
Cookies.Get = function(name){
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    var j = 0;
    while(i < clen){
        j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return Cookies.GetCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if(i == 0)
            break;
    }
    return null;
};
/**//**
 * 清除Cookies
 */
Cookies.Clear = function(name) {
  if(Cookies.Get(name)){
    var expdate = new Date(); 
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
    Cookies.Set(name, "", expdate); 
  }
};

Cookies.GetCookieVal = function(offset){
   var endstr = document.cookie.indexOf(";", offset);
   if(endstr == -1){
       endstr = document.cookie.length;
   }
   return unescape(document.cookie.substring(offset, endstr));
};


//UHeaderError(e,sex)
//用户头像显示出错时显示默认头像
//调用方式<img  onerror="UHeaderError(this,1);" />
var iHeaderHas = 0;
function UHeaderError(e,sex)
{
    if (e.error){return;}
    e.error = "1";
    var s = sex;
//    if (typeof(sex) == "undefined" || sex == "" || sex == "1") { s = 'man';}
//    else { s = 'woman';}
//    var inx = iHeaderHas;
//    while (iHeaderHas == inx)
//    {
//        inx = parseInt(12*Math.random());
//    }    
//    if (inx <= 0 ){ inx = 1;}
//    if (inx > 12) { inx = 12;}
//    iHeaderHas = inx;
//    e.src='http://member.winfang.com/imgs/' +s + '/'+ inx + '.gif';
    
    if (s != "0" && s != "1") { s = "1";}
    e.src = 'http://img1.dichan.com/man/'+s+'_small.jpg';

}
//相片
function PhotoError(e) {
    UHeaderError(e,1);
}


//图片显示错误时显示默认阳随机图片 调用方式：onerror="PicError(this,'quanzi')"
//PicError(e,folder)
//e 图片对象
//folder 默认图片的目录 1-10.jpg
var PicRndNum = 0;
function PicError(e,folder)
{
    if (e.error){return;}
    e.error = "1";
    var fol = folder;
    if (typeof(fol) == "undefined" || fol == "") { fol = 'def';}
    PicRndNum ++;
    if (PicRndNum > 10){ PicRndNum  = 1;}
    var inx = PicRndNum;
//    while (PicRndNum == inx)
//    {
//        inx = parseInt(10*Math.random());
//    }    
//    if (inx <= 0 ){ inx = 1;}
//    if (inx > 10) { inx = 10;}
//    PicRndNum = inx;



    e.src = 'http://img1.dichan.com/imgs/' + fol + '/' + inx + '.gif';
    
}


//图片最大不超过
//e 图片对象
//w1 最大宽度
//h1 最大高度,不传值时，仅限制宽度
function PhotoMax(e,w1,h1)
{
    var w = 100;
    var h = 100;
    var b = false;
    var isW= false;
    var isH= false;
    if (typeof(w1) != "undefined") { w = w1;}
    if (typeof(h1) != "undefined") { h = h1; b = true;}
    
    var img = document.createElement("IMG");
    img.src = e.src;
    var currentW = img.width;
    if (currentW < e.width) { currentW = e.width ;}
    
    var currentH = img.height;
    if (currentH < e.height) { currentH = e.height ;}
    
    if (b)
    {
        if (currentH > currentW && currentH > h)
        {
            e.style.height = h+"px"; isH = true;
        }

    }
    if (!isH && currentW > w)
    {
        e.style.width = w+"px"; isW = true;
    }
    //如果有设高度，并且缩小后高度仍超限定
    if (b && e.height > h) {
        e.style.height = h + "px"; isW = true;
        e.style.width = ""; isW = false;
    }
    if ((isW && isH) || (!isW && !isH))
    {}
    else
    {
        if (isW && e.height != "" )//清空HEIGHT属性
        {
            e.removeAttribute("height") ;
        }
        if (isH && e.width != "" )//清空WIDTH属性
        {
            e.removeAttribute("width") ;
        }
    }
    //if (isW || isH){ e.title+= '(点击查看大图)'; e.onmousedown = function(){ window.open(e.src);};}
    img = null;

}

//UrlCopy(url)
//复制当前地址
//调用方式<a onclick="return UrlCopy()"></a>或<a onclick="return UrlCopy('http://www.xxx.com/#1')"></a>
function UrlCopy(url)
{
    var u = url;
    if (typeof(url) == "undefined" ){ u = window.location.toString();}
    window.clipboardData.setData("Text",u);
    alert("地址复制成功。");
    return false;
}





//隐藏DIV面板
function DivHidden(name)
{
    var obj = document.getElementById(name);
    if (obj){obj.style.display = "none";}
    return false;
}

//返回在线编辑器内的文本
function GetFckContent(name)
{ 
    var s = "FCKeditor1___Frame"; if (typeof(name) != "undefined") { s = name;} var frame0 = window.frames[s]; if (frame0 && frame0.frames[0]){ return frame0.frames[0].document.body.innerText; }
    return "";
}

function SetBackUrl(obj,istourl)
{
	if (obj.innerText == "退出"){  istourl = true;}
	var url = window.location.toString();
	
    var href = obj.href;
    if ( href.indexOf('tourl=') > 0 ) {return;}
    if ( href.indexOf('?') > 0 ) {  href += "&tourl="+escape(url); } else { href += "?tourl="+escape(url); }
    obj.href = href;
}




function Chk_All(name) {
    var objs = document.getElementsByName(name);
    for (var i = 0; i < objs.length; i++) { objs[i].checked = !objs[i].checked; }
}

function Chk_Clear(name) {
    var objs = document.getElementsByName(name);
    for (var i = 0; i < objs.length; i++) { objs[i].checked = false; }
}

function Chk_GetIds(name) {
    var objs = document.getElementsByName(name);
    var ids = '';
    var j = 0;
    for (var i = 0; i < objs.length; i++) {
        if (objs[i].checked) { ids += ',' + objs[i].value; j++; }
    }
    if (ids.length > 0) { ids = ids.substring(1); }
    return ids;
}

function SelectOptionSelected(id, v) {
    var obj = document.getElementById(id);
    if (!obj) {return false;}
    for (var i = 0; i < obj.options.length; i++) {
        //alert(obj.options[i].value + " == " + v);
        if (obj.options[i].value == v) {
            obj.options[i].selected = true; return;
        }
    }
}