﻿/*------------prototype extend begin ----------------*/
Object.extend(String.prototype,{
    factLength: function(){
    var len=0;
    for(var i=0;i<this.length;i++){
        var aa = this.charAt(i);
        if(escape(aa).length > 4){
            len += 2;
        }
        else{
            len++;
        }
    }
    return len;
  },
  isEmail:function(){
    return this.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/)!=null;
  },
  toBoolean:function(){
    var v=this.toString().toLowerCase();
    return v=="true"?true:false;
  },
  compareTime:function compare(s2){
      var par= /^(\d{1,4})(-|\/|.)(\d{1,2})\2(\d{1,2})/;
      var s1=this;
      var s1p=s1.match(par);
      var s2p=s2.match(par);
      if(s1p==null||s2p==null){
        return "err";
      }
      var y=s1p[1];
      var m=s1p[3].padLeft(2,"0");
      var d=s1p[4].padLeft(2,"0");
      var d1=parseInt(y+m+d,10);
      y=s2p[1];
      m=s2p[3].padLeft(2,"0");
      d=s2p[4].padLeft(2,"0");
      var d2=parseInt(y+m+d,10);
      if(d1>d2){
        return 1;
      }
      else if(d1==d2){
        var par2=/(\d{1,2}):(\d{1,2}):(\d{1,2})/;
        s1p=s1.match(par2);
        s2p=s2.match(par2);
        if(s1p==null){
            s1p=[];
            s1p[1]=s1p[2]=s1p[3]="0";
        }
        if(s2p==null){
            s2p=[];
            s2p[1]=s2p[2]=s2p[3]="0";
        }
        for(var i=1;i<s1p.length;i++){
            if(s1p[i]==""){
                s1p[i]="0";
            }
        }
        for(var i=1;i<s2p.length;i++){
            if(s2p[i]==""){
                s2p[i]="0";
            }
        }
        y=parseInt(s1p[1],10);
        m=parseInt(s1p[2],10);
        d=parseInt(s1p[3],10);
        d1=y*3600+m*60+d;
        y=parseInt(s2p[1],10);
        m=parseInt(s2p[2],10);
        d=parseInt(s2p[3],10); 
        d2=y*3600+m*60+d;
        if(d1>d2){return 1;}
        else if(d1==d2){return 0;}  
        else{return -1;}    
      }
      else{
        return -1;
      }
    },
    padLeft:function(length,fillText){
        var returnValue=this;
        if(this.length<length){
            for(var i=0;i<length-this.length;i++){
                returnValue="0"+returnValue;
            }
        }
        return returnValue;
    },
    padRight:function(length,fillText){
        var returnValue=this;
        if(this.length<length){
            for(var i=0;i<length-this.length;i++){
                returnValue=returnValue+"0";
            }
        }
        return returnValue;
    },
    isUrl:function(){
        if(this.match(/(^http:\/\/){1}/i)){
            return true;
        }
        else{   
            return false; 
        }
    },
    trim: function(){
		return this.replace(/\s/g, "");
	},
	lTrim:function(){
		return this.replace(/^\s*/,"");
	},
	rTrim:function(){
		return this.replace(/\s*$/,"");
	},
	isDate:function(){
        var match=/^(\d{1,4})(-|\/|.)(\d{1,2})\2(\d{1,2})$/;
        return this.match(match)!=null;
    },
    removePx:function(){
        return parseInt(this.replace(/px/ig,""),10);
    },
    stripTags:function(){
        return this.replace(/<\/?[^>]+>/gi, '');
    }
});
Object.extend(Number.prototype,{
        fix:function(digit){
            var value=this.valueOf();
            if(value.toString().indexOf(".")>0){
                var digits=Math.pow(10,digit)
                    ,tmp=Math.round(value*digits)/digits
                    ,arr=tmp.toString().split(".");
                if(!arr[1]){
                    arr[1]="0";
                }
                return arr[0]+"."+arr[1].padRight(digit);
            }else{
                return value.toString()+"."+"0".padLeft(digit);
            }
        }
    });
/*------------prototype extend end ----------------*/

/*------------ wsp public start--------------------*/
/*wsp namespace defined*/
if(!WSP){
    var WSP={
        Version:"10.1.0.0"
    };
}
WSP.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; ++i) {
        d=a[i].split(".");
        o=WSP;
        for (j=(d[0] == "WSP") ? 1 : 0; j<d.length; ++j) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }
    return o;
};
/**
 *Util 命名空间是一些通用方法的前缀.
 *Controls 命名空间是各js控件的前缀.
 *Modules 命名空间是各模块的前缀.
 */   
WSP.namespace("Util","Controls","Modules");
Object.extend(WSP.Util,{
    /**
     * 跳转到登录页面
     * @loginUrl 跳转页面
     * @showMsg 是否先提示信息
     */
    redirectLoginPage:function(loginUrl,showMsg){
        if(showMsg){
            WSP.MessageBox.alertMsg(Trans.UnLoginText,function(){WSP.Util.BAgent.redirect(loginUrl,false);});
        }else{
            WSP.Util.BAgent.redirect(loginUrl,false);
        }
    },
    /*区块编辑层显示*/
    showManageLayer:function(obj){
        var ps=Position;
        obj=$(obj);
        var wspManageLayer=$("wsp_manager_layer")
        if(!wspManageLayer){
            wspManageLayer=document.createElement("div");
            wspManageLayer.id="wsp_manager_layer";
            document.body.appendChild(wspManageLayer);
            wspManageLayer=$(wspManageLayer);
        }
        var selfSize=obj.getDimensions()
            ,lt=obj.positionedOffset(); 
        wspManageLayer.setStyle({
            display:"",
            position:"absolute",
            width:selfSize.width+"px",
            //height:"24px",            
            border:"solid 1px #5983D6",
            left:lt[0]+"px",
            top:lt[1]+"px",
            zIndex:0,
            //filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=100,style=3,finishOpacity=50)",
            //opacity:"0.6",
            // backgroundColor:"#fff",
            height:selfSize.height+"px"
        });
        var moduletools=obj.previous(".moduletools",0);
        wspManageLayer.innerHTML="<div class=\"g-sectionlayer-title\">"+moduletools.innerHTML+"</div>";
    },
    hiddenManageLayer:function(obj){
        var wspManageLayer=$("wsp_manager_layer");
        if(wspManageLayer){
            wspManageLayer.setStyle({display:"none"});
        }
    },
    initSectionEditEvents:function(){//alert(3);
       
        $$(".section").each(function(obj){
            var p=obj.previous(".moduletools",0);
            if(p){
                obj.onmouseover=function(){
                    WSP.Util.showManageLayer(this);
                };
                obj.onmousedown=function(){
                    WSP.Util.hiddenManageLayer(this);
                }
            }
        });
    },
    openOrCloseSectionEdit:function(a){
        if(a.innerHTML==WSP.trans.closeSectionEditText){
            $$("div.section").each(function(obj){
                obj.onmouseover=function(){};
                obj.onmousedown=function(){};
                var wspManageLayer=$("wsp_manager_layer");
                if(wspManageLayer){
                    wspManageLayer.setStyle({display:"none"});
                }
            });
            a.innerHTML=WSP.trans.openSectionEditText;
        }else{
            WSP.Util.initSectionEditEvents();
            a.innerHTML=WSP.trans.closeSectionEditText;
        }
    }
});
/**
 *浏览器判断.{WSP.Util.BAgent}
 */
(function(){
    function browserAgent() {
        var b = navigator.appName;
        var v = this.version = navigator.appVersion;
        var ua = navigator.userAgent.toLowerCase();
        this.v = parseInt(v);
        this.safari = ua.indexOf("safari")>-1;
        this.opera = ua.indexOf("opera")>-1;
        this.ns = !this.opera && !this.safari && (b=="Netscape");
        this.ie = !this.opera && (b=="Microsoft Internet Explorer");
        this.ff = ua.indexOf('gecko')>-1;
        if (this.ns) {
            this.ns4 = (this.v==4);
            this.ns6 = (this.v>=5);
            this.b = "Netscape";
        }else if (this.ie) {
            this.ie4=this.ie5=this.ie55=this.ie6=this.ie7=this.ie8=false;
            if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
            else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
            else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
            else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
            else if (v.indexOf('MSIE 7')>0) {this.ie7 = true; this.v = 7;}
            else if(v.indexOf('MSIE 8')>0) {this.ie8=true;this.v=8;}
            this.b = "MSIE";
        }else if (this.opera) {
            this.v=parseInt(ua.substr(ua.indexOf("opera")+6,1));
            this.opera6=(this.v>=6);
            this.opera7=(this.v>=7);
            this.b = "Opera";
        }else if (this.safari) {
            this.ns6 = (this.v>=5);
            this.b = "Safari";
        }
        this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false;
        this.def = (this.ie||this.dom);
        this.win32 = ua.indexOf("win")>-1;
        this.mac = ua.indexOf("mac")>-1;
        this.other = (!this.win32 && !this.mac);
        this.supported = (this.def||this.ns4||this.ns6||this.opera)? true:false;
        this.broadband=false;
        this._bws=new Date;
        this.redirect=function(url,isback){
            if(isback) {window.location.href=url;}
            else{window.location.replace(url);}
        }
    };
    WSP.Util.BAgent = new browserAgent();
})();
//兼容以前版本
var bAgent=WSP.Util.BAgent;
/**
 *custom document. {WSP.Util.Dom}
 */
WSP.Util.Dom=function(){
    var b=WSP.Util.BAgent;
    return {
        /**
         *是否是标准模式{Boolean}
         */
        isStandard:function(){
            return (document.compatMode == 'CSS1Compat');
        },
        /**
         *返回body对象{object}
         */
        getBody:function(){
            return (this.isStandard()) ? document.documentElement : document.body;
        },
        /**
         * 返回文档的实际高度{Int}(包括margin)
         */
        getDomHeight: function() {
            return Math.max(this.getBody().scrollHeight, this.getViewportHeight());
        },
        /**
         * 返回文档的实际宽度{Int}(包括margin)
         */
        getDomWidth: function() {
           return Math.max(this.getBody().scrollWidth, this.getViewportWidth());
        },
        /**
         * 返回文档的可视高度{Int}(包括scrollbar)
         */
        getViewportHeight: function() {
            var height = self.innerHeight; // Safari, Opera
            var mode = document.compatMode;
            if ( (mode || b.ie) && !b.safari ) { // IE, Gecko
                height = this.getBody().clientHeight;
            }
            return height;
        },
        /**
         * 返回文档的可视宽度{Int}(包括scrollbar)
         */
        getViewportWidth: function() {
            var width = self.innerWidth;  // Safari
            var mode = document.compatMode;
            if (mode || b.ie) { // IE, Gecko, Opera
                width = this.getBody().clientWidth;
            }
            return width;
        },
        /**
         * 返回对象的正中left{px}
         */
        getCenterLeft:function(pm){
            var vw=this.getViewportWidth()
                ,sLeft=this.getBody().scrollLeft
                ,selfWidth=0;
            if(typeof pm=="number"){
                selfWidth=pm;
            }else if(typeof pm=="object"){
                selfWidth=$(pm).getDimensions().width;
            }else{
                alert("paramters is not null!");
                return;
            }
            if(vw>selfWidth){
                return (vw-selfWidth)/2+sLeft+"px";
            }else{
                return sLeft+"px";
            }
        },
        /**
         * 返回对象的正中top{px}
         */
        getCenterTop:function(pm){
            var vh=this.getViewportHeight()
                ,sTop=this.getBody().scrollTop
                ,selfHeight=0;
            if(typeof pm=="number"){
                selfHeight=pm;
            }else if(typeof pm=="object"){
                selfHeight=$(pm).getDimensions().height;
            }else{
                alert("paramters is not null!");
                return;
            }    
            if(vh>selfHeight){
                return (vh-selfHeight)/2+sTop+"px";
            }else{
                return sTop+"px";
            }
        },
        /**
         * 得到对象的innerText
         */
        getInnerText:function(obj){
            return (obj.innerText!=undefined)?obj.innerText:obj.textContent;
        },
        /**
         * 得到对象的outerHTML
         */
        getOuterHTML:function(obj){
            //ff
            if(window.HTMLElement){
                var attr
                ,attrs=obj.attributes
                ,str="<"+obj.tagName.toLowerCase();
                function _canHaveChildren(obj){
                    switch(obj.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;
                };
                for(var i=0;i<attrs.length;i++){
                    attr=attrs[i];
                    if(attr.specified){
                        str+=" "+attr.name+'="'+attr.value+'"';
                    }
                }
                if(!_canHaveChildren(obj)){
                    return str+">";
                }else{
                    return str+">"+obj.innerHTML+"</"+obj.tagName.toLowerCase()+">";
                }
            }else{
                return obj.outerHTML;
            }
        },
        /**
         * 得到对象的ChildNodes
         */
        getChildNodes:function(obj){
            if(b.ie){
                return obj.childNodes;
            }else{
                var cs=obj.childNodes
                    ,nodes=[]
                    ,c=null;
                for(var i=0;i<cs.length;i++){
                    c=cs[i];
                    if(c.nodeType==3){
                        if(c.nodeValue.replace(/\s/ig,"")==""){
                            continue;
                        }
                    }
                    nodes.push(c);
                }
                return nodes;
            }
        },
        /**
         * 得到对象的绝对位置坐标
         */
        getAbsPosition:function(obj) {
	        var pos = new Object;
	        pos.x = 0;
	        pos.y = 0;
	        if (obj) {
		        pos.x = obj.offsetLeft;
		        pos.y = obj.offsetTop;
		        if(obj.offsetParent) {
			        var parentpos = getAbsPosition(obj.offsetParent);
			        pos.x += parentpos.x;
			        pos.y += parentpos.y;
		        }
	        }
	        return pos;
        },
        /**
         * 得到对象的currentStyle属性
         */
        getCurrentStyle:function(obj){
            if(obj.currentStyle){
                return obj.currentStyle;
            }else{
                return document.defaultView.getComputedStyle(obj,null);
            }
        }
    }
}();
/**
 * custom event. {WSP.Util.Event}
 */
WSP.Util.Event=function(){
    return {
        getEvent:function(e){
            return e || window.event;
        },
        getTarget:function(e){
            return e.target || e.srcElement;
        }
    }
}();
WSP.Util.String=function(){
    return {
        getFactLength:function(str){
            var len=0,strLen=0;
            if(str){
                strLen=str.length;
                for(var i=0;i<strLen;i++){
                    var aa = str.charAt(i);
                    if(escape(aa).length > 4){
                        len += 2;
                    }else{
                        len++;
                    }
                }
            }
            return len;
        },
        isNumber:function(str){
            if(str==""){
                return false;
            }else{
                return !isNaN(str);
            }
        },
        trim: function(str){
		    return str.replace(/\s/g, "");
	    },
	    lTrim:function(str){
		    return str.replace(/^\s*/,"");
	    },
	    rTrim:function(str){
		    return str.replace(/\s*$/,"");
	    },
	    isNullOrEmpty:function(str){
	        return str==null||str=="";
	    },
	    toInt:function(str){
	        return parseInt(str,10);
	    },
	    format:function(format){
	        var args=arguments;
            for(var i=1;i<args.length;i++){
                format=format.replace("{"+(i-1)+"}",args[i])
            }
            return format;
	    }
    }
}();
/*end*/
WSP.Util.Object=function(){
    return {
        isNull:function(obj){
            return obj==undefined||obj==null;
        }
    }
}();
WSP.Controls.Util=function(){
    var string=WSP.Util.String;
    return {
        addErrorBoxCss:function(obj){
            obj.className=" errortxtbox "+obj.className ;
        },
        removeErrorBoxCss:function (obj){
            obj.className=obj.className.replace(/errortxtbox/,'');
        },
        overMaxLength:function(obj,length){
            var limitLen=0;
            if(length){
                limitLen=length;
            }else{
                limitLen=obj.getAttribute("maxlength");
            }
            if(string.isNumber(limitLen)){
                return limitLen<string.getFactLength(obj.value);
            }else{
                return false;
            }
        },
        getSelText:function(selObj){
            return selObj.options[selObj.selectedIndex].text;
        },
        getSelItemByValue:function(selObj,value){
            var items=selObj.options;
            for(var i=0;i<items.length;i++){
                if(items[i].value==value){
                    return items[i];
                }
            }
            return null;
        }
    }
}();
/*弹出窗口*/
WSP.Controls.OpenWindow=Class.create({
    initialize:function(container,options){
        this.options={
            className:"g-hdlayer",/*容器样式*/
            title:"title",/*标题*/
            titleClass:"g-hdlayertitle"/*标题样式*/
        }
        Object.extend(this.options, options||{});
        this.container=container;
        if(this.container.className.length==0){
            this.container.className=this.options.className;
        }
        //标题
        this.title=document.createElement("div");
        this.title.className=this.options.titleClass;
        this.title.innerHTML=this.options.title;
        this.container.appendChild(this.title);
        //iframe
        this.ifr=document.createElement("iframe");
        this.ifr.marginHeight=0;
        this.ifr.marginWidth=0;
        this.ifr.frameBorder=0;
        this.ifr.src="about:blank";
        this.container.appendChild(this.ifr);
        //button
        var divBtn=document.createElement("div");
        this.closeBtn=document.createElement("input");
        this.closeBtn.type="button";
        this.closeBtn.value="关闭";
        this.closeBtn.className="g-button";
        //close event
        this.closeBtn.onclick=(function(self){
            return function(){
                self.close();
            }
        })(this);
        divBtn.appendChild(this.closeBtn);
        this.container.appendChild(divBtn);
        //move event 
        new WSP.Controls.DivDragMove(this.title,this.container);
    },
    show:function(url){
        with(this.container.style){
            display="block";
            left=WSP.Util.Dom.getCenterLeft(this.container);
            top=WSP.Util.Dom.getCenterTop(this.container);
        }
        //创建全屏遮盖
        WSP.Controls.ScreenShadow.create();
        var d=new Date();
        this.ifr.src=url+"&t="+escape(d.toUTCString());
    },
    close:function(){
        with(this.container.style){
            display="none";
        }
        this.ifr.src="about:blank";
        WSP.Controls.ScreenShadow.close();
    }
});
function xPageY(e) {
  if (xDef(e.pageY)) { return e.pageY;}
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y+=e.offsetTop;
    e = xParent(e);
  }
  return y;
}
function xParent(e,bNode){
  var p=null;
  if (!bNode && xDef(e.offsetParent)) p=e.offsetParent;
  else if (xDef(e.parentNode)) p=e.parentNode;
  else if (xDef(e.parentElement)) p=e.parentElement;
  else if (xDef(e.parentLayer)){if (e.parentLayer!=window) p=e.parentLayer;}
  return p;
}
function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function getAbsPosition(obj) {
	var pos = new Object;
	pos.x = 0;
	pos.y = 0;

	if (obj) {
		pos.x = obj.offsetLeft;
		pos.y = obj.offsetTop;

		if(obj.offsetParent) {
			var parentpos = getAbsPosition(obj.offsetParent);
			pos.x += parentpos.x;
			pos.y += parentpos.y;
		}
	}

	return pos;
}
/*from main*/
//show the length of input texts and set max length     begin
function showNumber(obj, maxlength)
{
    var objid = obj.id;
    var show_num = $(obj.id+"show_write_sum");
    obj.title = " <= " + maxlength;
    if(!show_num)
    {
        var span = document.createElement("span");
        span.innerText = LimitNum + ":" + maxlength;
        span.id = obj.id+"show_write_sum";
        span.style.color = "black";
        obj.parentNode.appendChild(span);
    }
    else
    {
        if(obj.value.length > maxlength)
        {
            obj.value = obj.value.substring(0, maxlength);
        }
        else
        {
            show_num.innerHTML = "<font color=black>" + LimitNum + ":<b>" + parseInt(maxlength - obj.value.length) + "</b></font>";
        }
    }
}
//end
// check is Int
function checkIsInt(value, notvalue)
{
    var newvalue = value;
    if(newvalue.match(/^[0-9]+$/) == newvalue)
    { 
	if(notvalue != null)
	{
	   if(newvalue == notvalue)
	   {
		return false;
           }
	}
	return true; 
    }
    else 
	return false;
}
//end
//don't display msg
function checkMsgShow(id)
{
    try
    {
        document.getElementById(id).style.display = "none";
        clearInterval(__msgIntervalTime_hexj);
    }catch(e){}
}
//end
//check the contains of section input element beg   hexj 2007/12/11
//the [id] is button's id. because every section while contain a div with classname=section
//the [gotoid] is end parent obj
//need modify - -.
function checkAllInputValues(id,gotoid){
    var fromObj=document.getElementById(id);
	var parentObj=fromObj.parentNode;
	if(gotoid!=null&&gotoid!=""){
		while(parentObj!=null){
			if(parentObj.id!=""&&parentObj.id==gotoid){
				break;
			}
			else{
			    parentObj=parentObj.parentNode;
			}
		}
	}
	else{
		while(parentObj!=null){
			if((parentObj.tagName=="DIV"||parentObj.tagName=="div") && parentObj.className=="section"){
				break;
			}
			else{
			    parentObj=parentObj.parentNode;
			}
		}
	}
    if(parentObj==null)return false;
    var inputtexts=parentObj.getElementsByTagName("input");
    var s=true;
    for(var i=0;i<inputtexts.length;i++){
        var c=inputtexts[i];
        if(c.type=="text"||c.type=="textarea"||c.type=="password"){
            removeErrorBoxCss(c);
            if(c.getAttribute("isnotnull")==""){   
                if(c.value.replace(/\s/g,"")==""){
                    addErrorBoxCss(c);
                    c.focus();
                    s=false;
                }
                else{
                    c.className=c.className.replace(/errortxtbox/,'');
                    if(c.getAttribute("checktype")=="email"){
                        if(c.value.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/)==null){
                            addErrorBoxCss(c);
                            c.focus();
                            s=false;
                        }
                    }
                }
            }
            if(c.getAttribute("isnumber")==""){
                if(isNaN(c.value)){
                    addErrorBoxCss(c);c.focus();s=false;
                }
            }
            if(c.getAttribute("isint")==""){
                if(c.value.match(/^[0-9]+$/) != c.value){
					addErrorBoxCss(c);c.focus();s=false;
            	}
            }
       }
    }
    var selects=parentObj.getElementsByTagName("select");
	for(var j=0;j<selects.length;j++){ 
		var c = selects[j];
		removeErrorBoxCss(c.parentNode);
	   	if(c.getAttribute("isnotnull")==""){
	        if(c.value.replace(/\s/g,"")==""){
		        addErrorBoxCss(c.parentNode);
		        s=false;
	        }
   	    }
	}
    return s;
}

function GetSiblingText(obj)
{
   var arrNotText=[":","：","|",""];
   var previousobj=obj.previousSibling;
   while(previousobj!=null&&typeof(previousobj.tagName)!="undefined"&&previousobj.tagName.toString().toLowerCase()=="br"){
    previousobj=previousobj.previousSibling;
   }
   if(previousobj!=null){ //debugger;
	   if(typeof(previousobj.tagName)=="undefined"){
	      if(previousobj.nodeValue.replace(/\s*/g, "").replace(/[:：|]*/,'')==""){
	        var a=previousobj.previousSibling;
	        while(a!=null){
	            var txt=getInnerText(a).trim();
	            if(arrNotText.indexOf(txt)==-1)
	            {return "【"+txt+"】";}
	            else{
	                a=a.previousSibling;
	            }
	        }
	        if(a==null){
	            return getParentElementText(obj);
	        }
	      }
	      else{
	            return "【"+previousobj.nodeValue+"】";
	        }
	   }
	   else{
		   return getParentElementText(obj);
	   }
   }
   else{
		return getParentElementText(obj);
   }
}
function getParentElementText(obj){	
	var parentobj=obj.parentNode;
	while(parentobj!=null){
		var parentobjPreviousSli=parentobj.previousSibling;
		while(parentobjPreviousSli!=null){
			var innertext=getInnerText(parentobjPreviousSli).Trim();
			if(innertext!=""){
				return "【"+innertext+"】";
			}
			else{
			    parentobjPreviousSli=parentobjPreviousSli.previousSibling;
			}
		}
		parentobj=parentobj.parentNode;
	}
	return "";
}
function addErrorBoxCss(obj){
    WSP.Controls.Util.addErrorBoxCss(obj);
}
function removeErrorBoxCss(obj){
    WSP.Controls.Util.removeErrorBoxCss(obj);
}
//end
/*get innertext of element .*/
function getInnerText(obj)
{
	return window.ActiveXObject?obj.innerText:obj.textContent;    
}
//check grid is empty
function checkGridIsEmpty(gridId,tipMsg)
{
	var obj=document.getElementById(gridId);
	if(obj!=null && obj.rows.length<=1)
	{ 
		if(typeof tipMsg!='undefined') return alertMsg(tipMsg);
		else return alertMsg(gridEmptyText);
	}
	else {return true;}
}
/*products title ellisText .if more than length , use "...".
note:now, only use in product.
*/
function ellisText(id, length)
{
	try
	{
		var obj = document.getElementById(id);
		if(obj==null) return;
		for(var i=0; i < obj.rows.length * 2; i++)
		{
			var ccid = id + '_ctl';
			if(i < 10)
			{
				ccid += '0';
			}
			var cc= document.getElementById(ccid + i + '_lnkShowProductDetail');
			var content=cc.innerHTML.replace(/^\s*|\s*$/g, "");
			if(content.length > length)
			{
				cc.title=content;
				cc.innerHTML = content.substring(0,length) + "...";
			}
		}
	}catch(e){}
}
/*fix event*/
function fixE(e)
{
	if(typeof e=='undefined') {e=window.event;}
	return e;
}
/*article click count*/
function clickCount(articleId)
{
    var parameters="articleId="+articleId;
    var myoption={method:"get",parameters:parameters};
    new Ajax.Request("/wsp/WdServiceForSelf.asmx/UpdateArticleClickCount", myoption);
}
/*can send SBC case number*/
function getNumber(num,blallowzero)
{
	var newnum="";
	if(num.trim().length==0){return '';}
	if(blallowzero)
	{
		var re = new RegExp("(0|０)\.?(０|0)*").exec(num);   
		if(re!=null&&re.toString().split(',')[0]==num)
		{return 0;}
	}
	for(var i=0;i<num.length; i++)
	{
		var charitem=num.charCodeAt(i);
		if(charitem>=65296&&charitem<=65305)
		{
			if(!(i==0&&charitem==65296))
			newnum=newnum+String.fromCharCode(charitem-65248);
		}
		else if(charitem>=48&&charitem<=57)
		{
			if(!(i==0&&charitem==48))
			newnum=newnum+String.fromCharCode(num.charCodeAt(i));
		}
	}
	return newnum;
}
function checkInputLength(obj)
{
	//debugger;
	//alert(obj.id);
	var newvalue="";
	var len=0;
	var arrvalue=obj.value.toArray();
	var length=arrvalue.length;
	//debugger;
	for(var i=0;i<length;i++){
		if(escape(arrvalue[i].charAt(0)).length>4){
			len=len+2;
		}
		else{
			len++;
		}
		if(len<=obj.maxLength){
			newvalue=newvalue+arrvalue[i];
		}
	}
	obj.value=newvalue;
}
function initTextBoxkeyUpAndDownEvent(obj){
	switch(obj.tagName.toLowerCase()){
		case "input":{
			if(obj.maxLength!=2147483647){
				obj.onblur=function(){
				    checkInputLength(this);
				}
				obj.onfocus=function(){
				    this.select();
				}
			}
			break;
		}
		case "textarea":{
			if(obj.getAttribute("maxsize")!=null){
				obj.maxLength=obj.getAttribute("maxsize");
				obj.onblur=function(){;
				    checkInputLength(this);
				}
				obj.onfocus=function(){
				    this.select();
			    }
			}
			break;
		}
	}
}
function initTextBoxEvent(obj){
	var inputElements=obj.getElementsByTagName("input");
	var len=inputElements.length;
	for(var i=0;i<len;i++){
		initTextBoxkeyUpAndDownEvent(inputElements[i]);
	}
	var textareas=obj.getElementsByTagName("textarea");
	var lengs=textareas.length;
	for(var j=0;j<lengs;j++){
		initTextBoxkeyUpAndDownEvent(textareas[j]);
	}
}
/*from defaultbutton.js*/
function fnTrapKD(btnID, event, nextCtrWhenPressTab){
	var button = document.getElementById(btnID); // only recent browsers
	if (document.all){
		if (event.keyCode == 13){
			event.returnValue = false;
			event.cancel = true;
			button.click();
		}
		else if(event.keyCode==9&&typeof nextCtrWhenPressTab!="undefined"){
		    event.returnValue=false;
		    event.cancel=true;
		    document.getElementById(nextCtrWhenPressTab).focus();
		}
	}
	else if (document.getElementById){
		if (event.which == 13) {
			event.returnValue = false;
			event.cancel = true;
			button.focus();
			button.click();
		}
		else if(event.which==9){
			event.returnValue=false;
		    event.cancel=true;
		    document.getElementById(nextCtrWhenPressTab).focus();	
			return false;
		}
	}
}

function resizeimg(ImgD, iwidth, iheight) {
	var image = new Image();
	image.src = ImgD.src;
	if (image.width > 0 && image.height > 0) {
		if (image.width / image.height >= iwidth / iheight) {
			if (image.width > iwidth) {
				ImgD.width = iwidth;
				ImgD.height = (image.height * iwidth) / image.width;
			} else {
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
			ImgD.alt = image.width + "\xd7" + image.height;
		} else {
			if (image.height > iheight) {
				ImgD.height = iheight;
				ImgD.width = (image.width * iheight) / image.height;
			} else {
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
			ImgD.alt = image.width + "\xd7" + image.height;
		}
		// 改变鼠标指针
		ImgD.style.cursor = "pointer";
		ImgD.align="middle";
		// 判断浏览器，如果是IE
		if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) {
			ImgD.title = "\u70b9\u51fb\u56fe\u7247\u53ef\u5728\u65b0\u7a97\u53e3\u6253\u5f00";
		} else { //如果不是IE
			ImgD.title = "\u70b9\u51fb\u56fe\u7247\u53ef\u5728\u65b0\u7a97\u53e3\u6253\u5f00";
		}
	}
}
function getSectionParentElement(section){
    var pReturnElement=new Object();
    pReturnElement.width="0";
    pReturnElement.height="0";
    if(section!=null){
        var p=section;
        while(p!=null&&!(p.tagName.toString().toLowerCase()=="div"&&p.className=="section")){
            p=p.parentNode;
        }
        if(p!=null){
            p=p.parentNode;
            if(p!=null){
                pReturnElement.width=p.offsetWidth;
                pReturnElement.height=p.offsetHeight;
            }
        }
    }
    return pReturnElement;
}
//section open or close
function openOrClose(obj){
    var section=obj.nextSibling;
    while(section!=null&&section.className!="section"){
        section=section.nextSibling;
    }
    if(section!=null){
        if(section.style.display==""){
            section.style.display="none";
        } 
        else{
            section.style.display="";
        }
    }
}
function OpenOrCloseNavBox(img)
{
    var pobj = img.parentNode;
    var divrelat = pobj.nextSibling;
    if(divrelat.style.display == "none")
    {
        var src = img.src;
        img.src = src.replace("navbox_impexp","navbox_impcls");
        //img.src = "images/navbox/navbox_impcls.gif";
        img.alt = "收缩";
        divrelat.style.display = "block";
    }
    else
    {
        var src = img.src;
        img.src = src.replace("navbox_impcls","navbox_impexp");
        //img.src = "images/navbox/navbox_impexp.gif";
        img.alt = "展开";
        divrelat.style.display = "none";
    }
}

/*==================user section begin=================*/
function openOrgSelPage(ids){			
    var txtUsername = $(ids.txtUsername);
    var lblLoginError = $(ids.lblLoginError);
    var txtOrgInfo = $(ids.txtOrgInfo);
    var hdOrgValue = $(ids.txtOrgValue);
    var hdOrgName = $(ids.txtOrgName);
    if(txtUsername.value.length==0){
        lblLoginError.innerText=Trans.userNameMissingText;
        txtUsername.focus();
        return;
    }
	var oReturn=new Object();
    oReturn.textStr="";
    oReturn.valueStr="";
    var ocode = '';
    var pageguid='';
    var d=new Date();
    oReturn = OpenWithResponse("/wsp/Modules/User/SelOrg.aspx?guid="+pageguid+"&usercode="+txtUsername.value+"&ocode="+ocode+"&r="+d.toUTCString(),oReturn,430,200);
    if(oReturn==null){
        oReturn=new Object();
        oReturn.textStr="";
        oReturn.valueStr="";
    }
    if(hdOrgValue&&txtOrgInfo){
        if(oReturn.valueStr&&oReturn.valueStr.length>0){	
            hdOrgValue.value = oReturn.valueStr;                
            txtOrgInfo.value = "["+oReturn.valueStr+"]"+oReturn.textStr;
            txtOrgInfo.title = hdOrgName.value = oReturn.textStr;
            txtOrgInfo.style.color='blue';
        }
        else {
            hdOrgValue.value = "";                
            txtOrgInfo.value = Trans.noOrgText;
            txtOrgInfo.title = hdOrgName = "";
            txtOrgInfo.style.color='';
        }
    }
}
function showButton(obj,ids){
    var trOrg = ids.trOrg;
    var hplResetpwd = ids.hplResetPassword;
    var src = event.srcElement;
    if(src.tagName == "INPUT"){
        var resetObj = $(hplResetpwd);
        if(event.srcElement.value == "0"){
            if(resetObj != null) resetObj.style.visibility = "hidden";
            $(trOrg).style.display = "";
        }
        else{
            $(trOrg).style.display = "none";
            if(resetObj != null) resetObj.style.visibility = "visible";
        }
    } 
}
function visibleTip(obj,lblLoginError){
    if(obj.value != null && obj.value.replace(/\s/g, "").length != 0){
        $(lblLoginError).innerText = "";
    }
}

function tryGetUSBSecCode(){
	var usb=$("USBVal");
	if(usb!=null){
		var code="";
		try{
			code=usb.getcode();
		}
		catch(e){
			code="";
		}
		$("txtUSBVal_SecCode").value=code;
	}
}
/*============end user section======================*/
var uicGuid="";
function goToDeliverRemind(id){
    createAllDiv("打开页面中。。。");
    var now=new Date();
    var requestUrl=WSPCore.siteUrl+"/Modules/UICNode/ValidateUIC.ashx?guid="+uicGuid+"&v="+escape(now.toUTCString());
    var myoption={method:"get",onComplete:function(request,b){
        var returnValue = request.responseText.stripTags();
        var f=new Function("return "+returnValue);
        var json=f();
        //debugger;
        if(typeof json.error!="undefined"){
            var errorMsg="";
            switch(json.error){
                case 0:errorMsg="页面已经过期,请重新登陆.";break;
                case 1:errorMsg="您无权限查看此页面.";break;
                case 2:errorMsg="参数出错!";break;
                default:errorMsg=json.error;break;
            }
            alert(errorMsg);
        }
        else{
            uicGuid=json.guid;
            var uicUrl=json.uicurl;
            var url="about:blank";
            if(id=="more"){
                url=uicUrl+"/NavigatorForWSP.aspx?GID="+uicGuid+"&PageUrl=UIC/PSU.Presentation.Stock/FSU_DeliverRemind.aspx";
            }
            else{
                url=uicUrl+"/NavigatorForWSP.aspx?GID="+uicGuid+"&PageUrl=UIC/PSU.Presentation.Stock/FSU_PurOrder_NewEdit.aspx&type=dev&id="+id;
            }
            window.open(url);
        }
        cancelevent();
     }
    };
    new Ajax.Request(requestUrl, myoption);
}
function getBodySize(){
    var size=new Object();
    var body=getBodyObj();
    var scrollW=body.scrollWidth,scrollH=body.scrollHeight,clientW=body.clientWidth;clientH=body.clientHeight,bodyW=scrollW,bodyH=scrollH;
    bodyW=(scrollW>clientW?scrollW:clientW);
    bodyH=(scrollH>clientH?scrollH:clientH);
    size.width=bodyW;
    size.height=bodyH;
    return size;
}
function getBodyObj(){
    return (document.compatMode.toLowerCase()=="css1compat")?document.documentElement:document.body;
}
/*返回文件的扩展名.不包括'.'*/
function getFileExt(uploadPath){
    var lastIndex=uploadPath.lastIndexOf(".");
    if(lastIndex<0){
        return null;
    }
    return uploadPath.substring(lastIndex+1);
}
function getFileName(uploadPath){
    var lastIndex=uploadPath.lastIndexOf('\\');
    if(lastIndex<0){
        return null;
    }
    return uploadPath.substring(lastIndex+1);
}
function showChilds(obj,parm){
    var pm="id="+parm;
    var divContent=$(obj.id+"_child");
    createAllDiv();
    if(divContent!=undefined){
        divContent.className="";
    }
    else{
        var action={
            onComplete:function(request,b){
                var xml=request.responseXML;
                var pms={
                    pObj:null,
                    uniqueId:obj.id,
                    position:'absolute',
                    headerText:[Trans.qtyText,Trans.nameText],
                    headerWidth:['10%','60%'],
                    createDivAll:false
                }
                createHtmlTableFromXML(xml,pms);
            },parameters:pm
        };
        new Ajax.Request(WSPCore.siteUrl+"/WDServiceForSelf.asmx/GetChilds", action);
    }
}
/*psu bar*/
function openOrCloseBarPsu(obj,search){
    if(obj.className.indexOf('openbar')>0){
        obj.className=obj.className.replace(/psu-openbar/,"psu-closebar");
        obj.title="隐藏查询";
        search.style.display="";
    }
    else{
        obj.className=obj.className.replace(/psu-closebar/,"psu-openbar");
        obj.title="显示查询";
        search.style.display="none";
    }
}
/*------------ wsp public end--------------------*/
/* the operation for cookie */
WSP.Modules.Cookie=function(){
    return{
        setCookie:function(name,value,expire) {    
                    document.cookie = name + "="+ escape (value) + ";path=/";    
                },
        getCookie:function(name) {    
                    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));    
                    if(arr != null) return unescape(arr[2]); return null;    
                },
        delCookie:function(name) {    
                    var exp = new Date();    
                    exp.setTime(exp.getTime() - 1);    
                    var cval=WSP.Modules.Cookie.getCookie(name);    
                    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString()+";path=/";    
                }     
    }
}();
/*
function setCookie(name,value,expire) {    
    document.cookie = name + "="+ escape (value) + ";path=/";    
}    
   
function getCookie(name) {    
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));    
    if(arr != null) return unescape(arr[2]); return null;    
}    
   
function delCookie(name){    
    var exp = new Date();    
    exp.setTime(exp.getTime() - 1);    
    var cval=getCookie(name);    
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString()+";path=/";    
}
*/
