
Ext.ns("ssh.util");  




/**
 * @singletone
 */
ssh.util = function(){ 
    return {
        // 事件常用处理
	    EventHelper: {
	        cancelBubble: function(e){
	            if (e.stopPropagation) 
	                e.stopPropagation();
	            else 
	                e.cancelBubble = true;
	        },
	        cancelDefualt: function(e){
	            if (e.preventDefault) 
	                e.preventDefault();
	            else 
	                e.returnValue = false;
	        }
	    }
    }
}();

ssh.util.goBack = function(){
    window.history.go(-1);
}

/**
 * 解决下拉框拦住DIV问题
 * @param {} objDiv
 * @author 张建
 */

ssh.util.iframe =  function (handle){
	var w =  handle.getWidth();
	var h = handle.getHeight();
	
	var ifrm = handle.createChild({tag:'iframe', src:'about:blank'});
	ifrm.dom.frameBorder = 0;
	ifrm.dom.style.cssText = 'position:absolute; visibility:inherit; top:0px; left:0px; width:' + w + 'px; height:' + h + 'px; z-index: -1; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
	return ifrm;
}

/**
 * 插入HTML文本信息并执脚本内容
 * @param {} html (文本信息可含JAVASCRIPT脚本)
 * @param {} el (Ext Element)
 * @author 张建
 */
ssh.util.update = function(html, el){    
	ssh.util.exec(html);
    el.update(html);                    
};	

/**
 * 插入HTML文本信息并执脚本内容
 * @param {} html (文本信息可含JAVASCRIPT脚本)
 * @param {} el (Ext Element)
 * @author 张建
 */
ssh.util.exec = function(html){    
      var hd = document.getElementsByTagName("head")[0];  
      var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;  
      var srcRe = /\ssrc=([\'\"])(.*?)\1/i;  
      var typeRe = /\stype=([\'\"])(.*?)\1/i;  
      var match;  
      while(match = re.exec(html)){  
           var attrs = match[1];  
           var srcMatch = attrs ? attrs.match(srcRe) : false;  
           if(srcMatch && srcMatch[2]){  
                var s = document.createElement("script");  
                s.src = srcMatch[2];  
                var typeMatch = attrs.match(typeRe);  
                if(typeMatch && typeMatch[2]){  
                     s.type = typeMatch[2];  
                }  
                hd.appendChild(s);  
            }else if(match[2] && match[2].length > 0){  
                if(window.execScript) {  
                        window.execScript(match[2]);  
                } else {  
                        window.eval(match[2]);  
                }  
           }  
      }                       
};


/**
 * 修正IE6 PNG图片
 * @author 张建
 */
Ext.apply(Ext.ns("ssh.util"), {

    DD_belatedPNG : {
        ns: 'DD_belatedPNG',
        imgSize: {},
        delay: 10,
        nodesFixed: 0,
        createVmlNameSpace: function () { /* enable VML */
            if (document.namespaces && !document.namespaces[this.ns]) {
                document.namespaces.add(this.ns, 'urn:schemas-microsoft-com:vml');
            }
        },
        createVmlStyleSheet: function () { /* style VML, enable behaviors */
            /*
                Just in case lots of other developers have added
                lots of other stylesheets using document.createStyleSheet
                and hit the 31-limit mark, let's not use that method!
                further reading: http://msdn.microsoft.com/en-us/library/ms531194(VS.85).aspx
            */
            var screenStyleSheet, printStyleSheet;
            screenStyleSheet = document.createElement('style');
            screenStyleSheet.setAttribute('media', 'screen');
            document.documentElement.firstChild.insertBefore(screenStyleSheet, document.documentElement.firstChild.firstChild);
            if (screenStyleSheet.styleSheet) {
                screenStyleSheet = screenStyleSheet.styleSheet;
                screenStyleSheet.addRule(this.ns + '\\:*', '{behavior:url(#default#VML)}');
                screenStyleSheet.addRule(this.ns + '\\:shape', 'position:absolute;');
                screenStyleSheet.addRule('img.' + this.ns + '_sizeFinder', 'behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;'); /* large negative top value for avoiding vertical scrollbars for large images, suggested by James O'Brien, http://www.thanatopsic.org/hendrik/ */
                this.screenStyleSheet = screenStyleSheet;
                
                /* Add a print-media stylesheet, for preventing VML artifacts from showing up in print (including preview). */
                /* Thanks to R閙i Pr関ost for automating this! */
                printStyleSheet = document.createElement('style');
                printStyleSheet.setAttribute('media', 'print');
                document.documentElement.firstChild.insertBefore(printStyleSheet, document.documentElement.firstChild.firstChild);
                printStyleSheet = printStyleSheet.styleSheet;
                printStyleSheet.addRule(this.ns + '\\:*', '{display: none !important;}');
                printStyleSheet.addRule('img.' + this.ns + '_sizeFinder', '{display: none !important;}');
            }
        },
        readPropertyChange: function () {
            var el, display, v;
            el = event.srcElement;
            if (!el.vmlInitiated) {
                return;
            }
            if (event.propertyName.search('background') != -1 || event.propertyName.search('border') != -1) {
                ssh.util.DD_belatedPNG.applyVML(el);
            }
            if (event.propertyName == 'style.display') {
                display = (el.currentStyle.display == 'none') ? 'none' : 'block';
                for (v in el.vml) {
                    if (el.vml.hasOwnProperty(v)) {
                        el.vml[v].shape.style.display = display;
                    }
                }
            }
            if (event.propertyName.search('filter') != -1) {
                ssh.util.DD_belatedPNG.vmlOpacity(el);
            }
        },
        vmlOpacity: function (el) {
            if (el.currentStyle.filter.search('lpha') != -1) {
                var trans = el.currentStyle.filter;
                trans = parseInt(trans.substring(trans.lastIndexOf('=')+1, trans.lastIndexOf(')')), 10)/100;
                el.vml.color.shape.style.filter = el.currentStyle.filter; /* complete guesswork */
                el.vml.image.fill.opacity = trans; /* complete guesswork */
            }
        },
        handlePseudoHover: function (el) {
            setTimeout(function () { /* wouldn't work as intended without setTimeout */
                ssh.util.DD_belatedPNG.applyVML(el);
            }, 1);
        },
        /**
        * This is the method to use in a document.
        * @param {String} selector - REQUIRED - a CSS selector, such as '#doc .container'
        **/
        fix: function (selector) {
            try {
                document.execCommand("BackgroundImageCache", false, true); /* TredoSoft Multiple IE doesn't like this, so try{} it */
            } catch(r) {}
            ssh.util.DD_belatedPNG.createVmlNameSpace();
            ssh.util.DD_belatedPNG.createVmlStyleSheet();               
            if (this.screenStyleSheet) {
                var selectors, i;
                selectors = selector.split(','); /* multiple selectors supported, no need for multiple calls to this anymore */
                for (i=0; i<selectors.length; i++) {
                    this.screenStyleSheet.addRule(selectors[i], 'behavior:expression(ssh.util.DD_belatedPNG.fixPng(this))'); /* seems to execute the function without adding it to the stylesheet - interesting... */
                }
            }
        },
        fixOnce: function () {
			if (!ssh.util.DD_belatedPNG.gFixFlag) {
			    ssh.util.DD_belatedPNG.gFixFlag = true; 		
				if (Ext.isIE6) { 
					ssh.util.DD_belatedPNG.fix('*');
				}
			}
        },
        applyVML: function (el) {
            el.runtimeStyle.cssText = '';
            this.vmlFill(el);
            this.vmlOffsets(el);
            this.vmlOpacity(el);
            if (el.isImg) {
                this.copyImageBorders(el);
            }
        },
        attachHandlers: function (el) {
            var self, handlers, handler, moreForAs, a, h;
            self = this;
            handlers = {resize: 'vmlOffsets', move: 'vmlOffsets'};
            if (el.nodeName == 'A') {
                moreForAs = {mouseleave: 'handlePseudoHover', mouseenter: 'handlePseudoHover', focus: 'handlePseudoHover', blur: 'handlePseudoHover'};
                for (a in moreForAs) {          
                    if (moreForAs.hasOwnProperty(a)) {
                        handlers[a] = moreForAs[a];
                    }
                }
            }
            for (h in handlers) {
                if (handlers.hasOwnProperty(h)) {
                    handler = function () {
                        self[handlers[h]](el);
                    };
                    el.attachEvent('on' + h, handler);
                }
            }
            el.attachEvent('onpropertychange', this.readPropertyChange);
        },
        giveLayout: function (el) {
            el.style.zoom = 1;
            if (el.currentStyle.position == 'static') {
                el.style.position = 'relative';
            }
        },
        copyImageBorders: function (el) {
            var styles, s;
            styles = {'borderStyle':true, 'borderWidth':true, 'borderColor':true};
            for (s in styles) {
                if (styles.hasOwnProperty(s)) {
                    el.vml.color.shape.style[s] = el.currentStyle[s];
                }
            }
        },
        vmlFill: function (el) {
            if (!el.currentStyle) {
                return;
            } else {
                var elStyle, noImg, lib, v, img, imgLoaded;
                elStyle = el.currentStyle;
            }
            for (v in el.vml) {
                if (el.vml.hasOwnProperty(v)) {
                    el.vml[v].shape.style.zIndex = elStyle.zIndex;
                }
            }
            el.runtimeStyle.backgroundColor = '';
            el.runtimeStyle.backgroundImage = '';
            noImg = true;
            if (elStyle.backgroundImage != 'none' || el.isImg) {
                if (!el.isImg) {
                    el.vmlBg = elStyle.backgroundImage;
                    el.vmlBg = el.vmlBg.substr(5, el.vmlBg.lastIndexOf('")')-5);
                }
                else {
                    el.vmlBg = el.src;
                }
                lib = this;
                if (!lib.imgSize[el.vmlBg]) { /* determine size of loaded image */
                    img = document.createElement('img');
                    lib.imgSize[el.vmlBg] = img;
                    img.className = lib.ns + '_sizeFinder';
                    img.runtimeStyle.cssText = 'behavior:none; position:absolute; left:-10000px; top:-10000px; border:none; margin:0; padding:0;'; /* make sure to set behavior to none to prevent accidental matching of the helper elements! */
                    imgLoaded = function () {
                        this.width = this.offsetWidth; /* weird cache-busting requirement! */
                        this.height = this.offsetHeight;
                        lib.vmlOffsets(el);
                    };
                    img.attachEvent('onload', imgLoaded);
                    img.src = el.vmlBg;
                    img.removeAttribute('width');
                    img.removeAttribute('height');
                    document.body.insertBefore(img, document.body.firstChild);
                }
                el.vml.image.fill.src = el.vmlBg;
                noImg = false;
            }
            el.vml.image.fill.on = !noImg;
            el.vml.image.fill.color = 'none';
            el.vml.color.shape.style.backgroundColor = elStyle.backgroundColor;
            el.runtimeStyle.backgroundImage = 'none';
            el.runtimeStyle.backgroundColor = 'transparent';
        },
        /* IE can't figure out what do when the offsetLeft and the clientLeft add up to 1, and the VML ends up getting fuzzy... so we have to push/enlarge things by 1 pixel and then clip off the excess */
        vmlOffsets: function (el) {
            var thisStyle, size, fudge, makeVisible, bg, bgR, dC, altC, b, c, v;
            thisStyle = el.currentStyle;
            size = {'W':el.clientWidth+1, 'H':el.clientHeight+1, 'w':this.imgSize[el.vmlBg].width, 'h':this.imgSize[el.vmlBg].height, 'L':el.offsetLeft, 'T':el.offsetTop, 'bLW':el.clientLeft, 'bTW':el.clientTop};
            fudge = (size.L + size.bLW == 1) ? 1 : 0;
            /* vml shape, left, top, width, height, origin */
            makeVisible = function (vml, l, t, w, h, o) {
                vml.coordsize = w+','+h;
                vml.coordorigin = o+','+o;
                vml.path = 'm0,0l'+w+',0l'+w+','+h+'l0,'+h+' xe';
                vml.style.width = w + 'px';
                vml.style.height = h + 'px';
                vml.style.left = l + 'px';
                vml.style.top = t + 'px';
            };
            makeVisible(el.vml.color.shape, (size.L + (el.isImg ? 0 : size.bLW)), (size.T + (el.isImg ? 0 : size.bTW)), (size.W-1), (size.H-1), 0);
            makeVisible(el.vml.image.shape, (size.L + size.bLW), (size.T + size.bTW), (size.W), (size.H), 1 );
            bg = {'X':0, 'Y':0};
            if (el.isImg) {
                bg.X = parseInt(thisStyle.paddingLeft, 10) + 1;
                bg.Y = parseInt(thisStyle.paddingTop, 10) + 1;
            }
            else {
                for (b in bg) {
                    if (bg.hasOwnProperty(b)) {
                        this.figurePercentage(bg, size, b, thisStyle['backgroundPosition'+b]);
                    }
                }
            }
            el.vml.image.fill.position = (bg.X/size.W) + ',' + (bg.Y/size.H);
            bgR = thisStyle.backgroundRepeat;
            dC = {'T':1, 'R':size.W+fudge, 'B':size.H, 'L':1+fudge}; /* these are defaults for repeat of any kind */
            altC = { 'X': {'b1': 'L', 'b2': 'R', 'd': 'W'}, 'Y': {'b1': 'T', 'b2': 'B', 'd': 'H'} };
            if (bgR != 'repeat' || el.isImg) {
                c = {'T':(bg.Y), 'R':(bg.X+size.w), 'B':(bg.Y+size.h), 'L':(bg.X)}; /* these are defaults for no-repeat - clips down to the image location */
                if (bgR.search('repeat-') != -1) { /* now let's revert to dC for repeat-x or repeat-y */
                    v = bgR.split('repeat-')[1].toUpperCase();
                    c[altC[v].b1] = 1;
                    c[altC[v].b2] = size[altC[v].d];
                }
                if (c.B > size.H) {
                    c.B = size.H;
                }
                el.vml.image.shape.style.clip = 'rect('+c.T+'px '+(c.R+fudge)+'px '+c.B+'px '+(c.L+fudge)+'px)';
            }
            else {
                el.vml.image.shape.style.clip = 'rect('+dC.T+'px '+dC.R+'px '+dC.B+'px '+dC.L+'px)';
            }
        },
        figurePercentage: function (bg, size, axis, position) {
            var horizontal, fraction;
            fraction = true;
            horizontal = (axis == 'X');
            switch(position) {
                case 'left':
                case 'top':
                    bg[axis] = 0;
                    break;
                case 'center':
                    bg[axis] = 0.5;
                    break;
                case 'right':
                case 'bottom':
                    bg[axis] = 1;
                    break;
                default:
                    if (position.search('%') != -1) {
                        bg[axis] = parseInt(position, 10) / 100;
                    }
                    else {
                        fraction = false;
                    }
            }
            bg[axis] = Math.ceil(  fraction ? ( (size[horizontal?'W': 'H'] * bg[axis]) - (size[horizontal?'w': 'h'] * bg[axis]) ) : parseInt(position, 10)  );
            if (bg[axis] % 2 === 0) {
                bg[axis]++;
            }
            return bg[axis];
        },
        fixPng: function (el) {
            el.style.behavior = 'none';
            var lib, els, nodeStr, v, e;
            if (el.nodeName == 'BODY' || el.nodeName == 'TD' || el.nodeName == 'TR') { /* elements not supported yet */
                return;
            }
            el.isImg = false;
            if (el.nodeName == 'IMG') {
                if(el.src.toLowerCase().search(/\.png$/) != -1) {
                    el.isImg = true;
                    el.style.visibility = 'hidden';
                }
                else {
                    return;
                }
            }
            else if (el.currentStyle.backgroundImage.toLowerCase().search('.png') == -1) {
                return;
            }
            lib = ssh.util.DD_belatedPNG;
            el.vml = {color: {}, image: {}};
            els = {shape: {}, fill: {}};
            for (v in el.vml) {
                if (el.vml.hasOwnProperty(v)) {
                    for (e in els) {
                        if (els.hasOwnProperty(e)) {
                            nodeStr = lib.ns + ':' + e;
                            el.vml[v][e] = document.createElement(nodeStr);
                        }
                    }
                    el.vml[v].shape.stroked = false;
                    el.vml[v].shape.appendChild(el.vml[v].fill);
                    el.parentNode.insertBefore(el.vml[v].shape, el);
                }
            }
            el.vml.image.shape.fillcolor = 'none'; /* Don't show blank white shapeangle when waiting for image to load. */
            el.vml.image.fill.type = 'tile'; /* Makes image show up. */
            el.vml.color.fill.on = false; /* Actually going to apply vml element's style.backgroundColor, so hide the whiteness. */
            lib.attachHandlers(el);
            lib.giveLayout(el);
            lib.giveLayout(el.offsetParent);
            el.vmlInitiated = true;
            lib.applyVML(el); /* Render! */
        }
    }
    
});

ssh.util.DD_belatedPNG.gFixFlag = false;

$cancelDefualt = ssh.util.EventHelper.cancelDefualt;
$cancelBubble = ssh.util.EventHelper.cancelBubble;

/**   
 * 对Date的扩展，将 Date 转化为指定格式的String   
 * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符   
 * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)   
 * eg:   
 * (new Date()).pattern("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423   
 * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04   
 * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04   
 * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04   
 * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18   
 */    
Date.prototype.format = function(fmt) {     
    var o = {     
    "M+" : this.getMonth()+1, //月份     
    "d+" : this.getDate(), //日     
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时     
    "H+" : this.getHours(), //小时     
    "m+" : this.getMinutes(), //分     
    "s+" : this.getSeconds(), //秒     
    "q+" : Math.floor((this.getMonth()+3)/3), //季度     
    "S" : this.getMilliseconds() //毫秒     
    };     
    var week = {     
    "0" : "\u65e5",     
    "1" : "\u4e00",     
    "2" : "\u4e8c",     
    "3" : "\u4e09",     
    "4" : "\u56db",     
    "5" : "\u4e94",     
    "6" : "\u516d"    
    };     
    if(/(y+)/.test(fmt)){     
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));     
    }     
    if(/(E+)/.test(fmt)){     
        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);     
    }     
    for(var k in o){     
        if(new RegExp("("+ k +")").test(fmt)){     
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));     
        }     
    }     
    return fmt;     
};

ssh.util.Format = function(){
    return {
        date : function(v, format){
            if(!v){
                return "";
            }
            
            if(Ext.isNumber(v)){
                v = new Date(v);
            }
            
            if (v.length >= 10) {
                var y = v.substr(0, 4) - 0;
                var m = v.substr(5, 2) - 0;
                var d = v.substr(8, 2) - 0;
                
                if (v.length >= 18) {
                    v = new Date(y, m, d,
                      v.substr(11, 2) - 0,
                      v.substr(14, 2) - 0,
                      v.substr(17, 2) - 0
                    );
                } else {
                    v = new Date(y, m, d);
                }
            }
            
            return v.format(format || "yyyy-MM-dd hh:mm:ss");
        },

        /**
         * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
         * @param {String} format Any valid date format string
         * @return {Function} The date formatting function
         */
        dateRenderer : function(format){
            return function(v){
                return ssh.util.Format.date(v, format);
            };
        }
    };
}();


/**
**ajax提交处理
**@author yangchuan
**/
Ext.apply(Ext.ns("ssh.Ajax"), {
	/**
	* ajax提交函数处理函数
	*@path :控制器路径
	*@formId： 表单id
	*@succ：成功函数 
	*@fail： 失败函数 
	*@type： 返回值类型 json表示返回object。 text：表示字符串，其他表示返回response对象
	*@author yangchuan
	*/
	request: function (config, type) {
		config.infoPanelObj = Ext.get(config.infoPanel || "ssh_info_panel");
		
		var formElement = Ext.get(config.form);
		
		ssh.Ajax._clearState(formElement, config.infoPanelObj);
		var successHandler = config.success;
		var failureHandler = config.failure;
		
		if (Ext.isEmpty(config.url) && formElement) {
			config.url = formElement.dom.action;
		}
		
		config.success = function (response, opts) {
			var resultData = response;
			var isJsonResponse = (type || "json") == "json";
			
			var success = (response.status || 200 == 200);
			
			if (success) {
				if (isJsonResponse) {
					try {
						resultData = Ext.decode(response.responseText);
					} catch (e) {
						resultData = response.responseText;
						success = false;
					}
				} else { //type == "text") 
					resultData = response.responseText;
				}
			}
			
			if (success) {
				if (isJsonResponse) {
					if (Ext.isObject(resultData.fieldErrors)) {
						success = false;
						var errors = resultData.fieldErrors;
						
						// 显示字段相关错误信息						
						for (var id in errors) {
							var objInfo = Ext.get(id + "_ssh_tip");
							
							if (objInfo) {
								objInfo.dom.innerHTML = errors[id];
								objInfo.setStyle("display", "");
							} else {
								var obj = Ext.get(id);
								if(obj){
									obj.parent().createChild({
										id: id + "_ssh_tip",
										tag: "span", 
										cls: "ssh_tip field_error",
										html: errors[id]
									});
								} else {
									alert("没有找到id为'" + id + "'的节点");
								}
							}
						}
					} 
					
					if (Ext.isObject(resultData.globalErrors)) {
						var errors = resultData.globalErrors;
						if (errors.error) {
							success = false;
						}
	
						// 显示全局信息
						var obj = config.infoPanelObj;
						
						if (Ext.isObject(obj)) {
							var ul = obj.createChild({
									tag: "ul", 
									cls: "ssh_tip"
								});
										
							// 增加全局提示条目	
							for (var key in errors) {
								ul.createChild({
									tag: "li", 
									cls: key
								}).createChild({
									tag: "div" 
								}).createChild({
									tag: "p", 
									html: errors[key]
								});
							}
						} else {
							alert("没有找到id为'" + (config.infoPanel || "ssh_info_panel") + "'的节点");
						}
					}
				}
			}
			
			if (success) {
				if (Ext.isFunction(successHandler)) {
					successHandler(resultData, opts);
				}
			} else {
				if (Ext.isFunction(failureHandler)) {
					failureHandler(resultData, opts);
				}
			}
			
			if (resultData.redirect) {
			    window.location = resultData.redirect; 
			}
		};
		
		config.failure = function (response, opts) {
			// 根据错误状态提示全局错误 （超时 -1，请求地址无效 0）
			var obj = config.infoPanelObj;
			
			if (obj) {						
				var ul = obj.createChild({
						tag: "ul", 
						cls: "ssh_tip"
				});
							
				// 增加全局提示条目	
			
				ul.createChild({
					tag: "li", 
					cls: "error"
				}).createChild({
					tag: "div" 
				}).createChild({
					tag: "p", 
					html: "请求出错（状态码：" + response.status + "）"
				});
			}
			
			if (Ext.isFunction(failureHandler)) {
				failureHandler(response, opts);
			}
		};
		
		Ext.Ajax.request(config);
	},
	

	/**
	*清理所有错误信息
	*@frmId:表单id
	*@author yangchuan
	*/
	_clearState: function (formElement, obj) {
		if (Ext.isObject(obj)) {						
			// 删除全局提示条目	
			var infos = obj.select("ul");
			if (infos) {
				infos.remove();
			}
			
			var ul = obj.createChild({
					tag: "ul", 
					cls: "ssh_tip"
			});
		}	

		var form = formElement;
		if (form) {
			var infos = form.select("span.ssh_tip");
			if (infos) {
				infos.setStyle("display", "none");
			}
		}
	}
});

/**
* DD_roundies, this adds rounded-corner CSS in standard browsers and VML sublayers in IE that accomplish a similar appearance when comparing said browsers.
* Author: Drew Diller
* Email: drew.diller@gmail.com
* URL: http://www.dillerdesign.com/experiment/DD_roundies/
* Version: 0.0.2a
* Licensed under the MIT License: http://dillerdesign.com/experiment/DD_roundies/#license
*
* Usage:
* DD_roundies.addRule('#doc .container', '10px 5px'); // selector and multiple radii
* DD_roundies.addRule('.box', 5, true); // selector, radius, and optional addition of border-radius code for standard browsers.
* 
* Just want the PNG fixing effect for IE6, and don't want to also use the DD_belatedPNG library?  Don't give any additional arguments after the CSS selector.
* DD_roundies.addRule('.your .example img');
**/

var DD_roundies = {

	ns: 'DD_roundies',
	
	IE6: false,
	IE7: false,
	IE8: false,
	IEversion: function() {
		if (document.documentMode != 8 && document.namespaces && !document.namespaces[this.ns]) {
			this.IE6 = true;
			this.IE7 = true;
		}
		else if (document.documentMode == 8) {
			this.IE8 = true;
		}
	},
	querySelector: document.querySelectorAll,
	selectorsToProcess: [],
	imgSize: {},
	
	createVmlNameSpace: function() { /* enable VML */
		if (this.IE6 || this.IE7) {
			document.namespaces.add(this.ns, 'urn:schemas-microsoft-com:vml');
		}
		if (this.IE8) {
			document.writeln('<?import namespace="' + this.ns + '" implementation="#default#VML" ?>');
		}
	},
	
	createVmlStyleSheet: function() { /* style VML, enable behaviors */
		/*
			Just in case lots of other developers have added
			lots of other stylesheets using document.createStyleSheet
			and hit the 31-limit mark, let's not use that method!
			further reading: http://msdn.microsoft.com/en-us/library/ms531194(VS.85).aspx
		*/
		var style = document.createElement('style');
		document.documentElement.firstChild.insertBefore(style, document.documentElement.firstChild.firstChild);
		if (style.styleSheet) { /* IE */
			try {
				var styleSheet = style.styleSheet;
				styleSheet.addRule(this.ns + '\\:*', '{behavior:url(#default#VML)}');
				this.styleSheet = styleSheet;
			} catch(err) {}
		}
		else {
			this.styleSheet = style;
		}
	},
	
	/**
	* Method to use from afar - refer to it whenever.
	* Example for IE only: DD_roundies.addRule('div.boxy_box', '10px 5px');
	* Example for IE, Firefox, and WebKit: DD_roundies.addRule('div.boxy_box', '10px 5px', true);
	* @param {String} selector - REQUIRED - a CSS selector, such as '#doc .container'
	* @param {Integer} radius - REQUIRED - the desired radius for the box corners
	* @param {Boolean} standards - OPTIONAL - true if you also wish to output -moz-border-radius/-webkit-border-radius/border-radius declarations
	**/
	addRule: function(selector, rad, standards) {
		if (typeof rad == 'undefined' || rad === null) {
			rad = 0;
		}
		if (rad.constructor.toString().search('Array') == -1) {
			rad = rad.toString().replace(/[^0-9 ]/g, '').split(' ');
		}
		for (var i=0; i<4; i++) {
			rad[i] = (!rad[i] && rad[i] !== 0) ? rad[Math.max((i-2), 0)] : rad[i];
		}
		if (this.styleSheet) {
			if (this.styleSheet.addRule) { /* IE */
				var selectors = selector.split(','); /* multiple selectors supported, no need for multiple calls to this anymore */
				for (var i=0; i<selectors.length; i++) {
					this.styleSheet.addRule(selectors[i], 'behavior:expression(DD_roundies.roundify.call(this, [' + rad.join(',') + ']))'); /* seems to execute the function without adding it to the stylesheet - interesting... */
				}
			}
			else if (standards) {
				var moz_implementation = rad.join('px ') + 'px';
				this.styleSheet.appendChild(document.createTextNode(selector + ' {border-radius:' + moz_implementation + '; -moz-border-radius:' + moz_implementation + ';}'));
				this.styleSheet.appendChild(document.createTextNode(selector + ' {-webkit-border-top-left-radius:' + rad[0] + 'px ' + rad[0] + 'px; -webkit-border-top-right-radius:' + rad[1] + 'px ' + rad[1] + 'px; -webkit-border-bottom-right-radius:' + rad[2] + 'px ' + rad[2] + 'px; -webkit-border-bottom-left-radius:' + rad[3] + 'px ' + rad[3] + 'px;}'));
			}
		}
		else if (this.IE8) {
			this.selectorsToProcess.push({'selector':selector, 'radii':rad});
		}
	},
	
	readPropertyChanges: function(el) {
		switch (event.propertyName) {
			case 'style.border':
			case 'style.borderWidth':
			case 'style.padding':
				this.applyVML(el);
				break;
			case 'style.borderColor':
				this.vmlStrokeColor(el);
				break;
			case 'style.backgroundColor':
			case 'style.backgroundPosition':
			case 'style.backgroundRepeat':
				this.applyVML(el);
				break;
			case 'style.display':
				el.vmlBox.style.display = (el.style.display == 'none') ? 'none' : 'block';
				break;
			case 'style.filter':
				this.vmlOpacity(el);
				break;
			case 'style.zIndex':
				el.vmlBox.style.zIndex = el.style.zIndex;
				break;
		}
	},
	
	applyVML: function(el) {
		el.runtimeStyle.cssText = '';
		this.vmlFill(el);
		this.vmlStrokeColor(el);
		this.vmlStrokeWeight(el);
		this.vmlOffsets(el);
		this.vmlPath(el);
		this.nixBorder(el);
		this.vmlOpacity(el);
	},
	
	vmlOpacity: function(el) {
		if (el.currentStyle.filter.search('lpha') != -1) {
			var trans = el.currentStyle.filter;
			trans = parseInt(trans.substring(trans.lastIndexOf('=')+1, trans.lastIndexOf(')')), 10)/100;
			for (var v in el.vml) {
				el.vml[v].filler.opacity = trans;
			}
		}
	},
	
	vmlFill: function(el) {
		if (!el.currentStyle) {
			return;
		} else {
			var elStyle = el.currentStyle;
		}
		el.runtimeStyle.backgroundColor = '';
		el.runtimeStyle.backgroundImage = '';
		var noColor = (elStyle.backgroundColor == 'transparent');
		var noImg = true;
		if (elStyle.backgroundImage != 'none' || el.isImg) {
			if (!el.isImg) {
				el.vmlBg = elStyle.backgroundImage;
				el.vmlBg = el.vmlBg.substr(5, el.vmlBg.lastIndexOf('")')-5);
			}
			else {
				el.vmlBg = el.src;
			}
			var lib = this;
			if (!lib.imgSize[el.vmlBg]) { /* determine size of loaded image */
				var img = document.createElement('img');
				img.attachEvent('onload', function() {
					this.width = this.offsetWidth; /* weird cache-busting requirement! */
					this.height = this.offsetHeight;
					lib.vmlOffsets(el);
				});
				img.className = lib.ns + '_sizeFinder';
				img.runtimeStyle.cssText = 'behavior:none; position:absolute; top:-10000px; left:-10000px; border:none;'; /* make sure to set behavior to none to prevent accidental matching of the helper elements! */
				img.src = el.vmlBg;
				img.removeAttribute('width');
				img.removeAttribute('height');
				document.body.insertBefore(img, document.body.firstChild);
				lib.imgSize[el.vmlBg] = img;
			}
			el.vml.image.filler.src = el.vmlBg;
			noImg = false;
		}
		el.vml.image.filled = !noImg;
		el.vml.image.fillcolor = 'none';
		el.vml.color.filled = !noColor;
		el.vml.color.fillcolor = elStyle.backgroundColor;
		el.runtimeStyle.backgroundImage = 'none';
		el.runtimeStyle.backgroundColor = 'transparent';
	},
	
	vmlStrokeColor: function(el) {
		el.vml.stroke.fillcolor = el.currentStyle.borderColor;
	},
	
	vmlStrokeWeight: function(el) {
		var borders = ['Top', 'Right', 'Bottom', 'Left'];
		el.bW = {};
		for (var b=0; b<4; b++) {
			el.bW[borders[b]] = parseInt(el.currentStyle['border' + borders[b] + 'Width'], 10) || 0;
		}
	},
	
	vmlOffsets: function(el) {
		var dims = ['Left', 'Top', 'Width', 'Height'];
		for (var d=0; d<4; d++) {
			el.dim[dims[d]] = el['offset'+dims[d]];
		}
		var assign = function(obj, topLeft) {
			obj.style.left = (topLeft ? 0 : el.dim.Left) + 'px';
			obj.style.top = (topLeft ? 0 : el.dim.Top) + 'px';
			obj.style.width = el.dim.Width + 'px';
			obj.style.height = el.dim.Height + 'px';
		};
		for (var v in el.vml) {
			var mult = (v == 'image') ? 1 : 2;
			el.vml[v].coordsize = (el.dim.Width*mult) + ', ' + (el.dim.Height*mult);
			assign(el.vml[v], true);
		}
		assign(el.vmlBox, false);
		
		if (DD_roundies.IE8) {
			el.vml.stroke.style.margin = '-1px';
			if (typeof el.bW == 'undefined') {
				this.vmlStrokeWeight(el);
			}
			el.vml.color.style.margin = (el.bW.Top-1) + 'px ' + (el.bW.Left-1) + 'px';
		}
	},
	
	vmlPath: function(el) {
		var coords = function(direction, w, h, r, aL, aT, mult) {
			var cmd = direction ? ['m', 'qy', 'l', 'qx', 'l', 'qy', 'l', 'qx', 'l'] : ['qx', 'l', 'qy', 'l', 'qx', 'l', 'qy', 'l', 'm']; /* whoa */
			aL *= mult;
			aT *= mult;
			w *= mult;
			h *= mult;
			var R = r.slice(); /* do not affect original array */
			for (var i=0; i<4; i++) {
				R[i] *= mult;
				R[i] = Math.min(w/2, h/2, R[i]); /* make sure you do not get funky shapes - pick the smallest: half of the width, half of the height, or current value */
			}
			var coords = [
				cmd[0] + Math.floor(0+aL) +','+ Math.floor(R[0]+aT),
				cmd[1] + Math.floor(R[0]+aL) +','+ Math.floor(0+aT),
				cmd[2] + Math.ceil(w-R[1]+aL) +','+ Math.floor(0+aT),
				cmd[3] + Math.ceil(w+aL) +','+ Math.floor(R[1]+aT),
				cmd[4] + Math.ceil(w+aL) +','+ Math.ceil(h-R[2]+aT),
				cmd[5] + Math.ceil(w-R[2]+aL) +','+ Math.ceil(h+aT),
				cmd[6] + Math.floor(R[3]+aL) +','+ Math.ceil(h+aT),
				cmd[7] + Math.floor(0+aL) +','+ Math.ceil(h-R[3]+aT),
				cmd[8] + Math.floor(0+aL) +','+ Math.floor(R[0]+aT)
			];
			if (!direction) {
				coords.reverse();
			}
			var path = coords.join('');
			return path;
		};
	
		if (typeof el.bW == 'undefined') {
			this.vmlStrokeWeight(el);
		}
		var bW = el.bW;
		var rad = el.DD_radii.slice();
		
		/* determine outer curves */
		var outer = coords(true, el.dim.Width, el.dim.Height, rad, 0, 0, 2);
		
		/* determine inner curves */
		rad[0] -= Math.max(bW.Left, bW.Top);
		rad[1] -= Math.max(bW.Top, bW.Right);
		rad[2] -= Math.max(bW.Right, bW.Bottom);
		rad[3] -= Math.max(bW.Bottom, bW.Left);
		for (var i=0; i<4; i++) {
			rad[i] = Math.max(rad[i], 0);
		}
		var inner = coords(false, el.dim.Width-bW.Left-bW.Right, el.dim.Height-bW.Top-bW.Bottom, rad, bW.Left, bW.Top, 2);
		var image = coords(true, el.dim.Width-bW.Left-bW.Right+1, el.dim.Height-bW.Top-bW.Bottom+1, rad, bW.Left, bW.Top, 1);
		
		/* apply huge path string */
		el.vml.color.path = inner;
		el.vml.image.path = image;
		el.vml.stroke.path = outer + inner;
		
		this.clipImage(el);
	},
	
	nixBorder: function(el) {
		var s = el.currentStyle;
		var sides = ['Top', 'Left', 'Right', 'Bottom'];
		for (var i=0; i<4; i++) {
			el.runtimeStyle['padding' + sides[i]] = (parseInt(s['padding' + sides[i]], 10) || 0) + (parseInt(s['border' + sides[i] + 'Width'], 10) || 0) + 'px';
		}
		el.runtimeStyle.border = 'none';
	},
	
	clipImage: function(el) {
		var lib = DD_roundies;
		if (!el.vmlBg || !lib.imgSize[el.vmlBg]) {
			return;
		}
		var thisStyle = el.currentStyle;
		var bg = {'X':0, 'Y':0};
		var figurePercentage = function(axis, position) {
			var fraction = true;
			switch(position) {
				case 'left':
				case 'top':
					bg[axis] = 0;
					break;
				case 'center':
					bg[axis] = 0.5;
					break;
				case 'right':
				case 'bottom':
					bg[axis] = 1;
					break;
				default:
					if (position.search('%') != -1) {
						bg[axis] = parseInt(position, 10) * 0.01;
					}
					else {
						fraction = false;
					}
			}
			var horz = (axis == 'X');
			bg[axis] = Math.ceil(fraction ? (( el.dim[horz ? 'Width' : 'Height'] - (el.bW[horz ? 'Left' : 'Top'] + el.bW[horz ? 'Right' : 'Bottom']) ) * bg[axis]) - (lib.imgSize[el.vmlBg][horz ? 'width' : 'height'] * bg[axis]) : parseInt(position, 10));
			bg[axis] += 1;
		};
		for (var b in bg) {
			figurePercentage(b, thisStyle['backgroundPosition'+b]);
		}
		el.vml.image.filler.position = (bg.X/(el.dim.Width-el.bW.Left-el.bW.Right+1)) + ',' + (bg.Y/(el.dim.Height-el.bW.Top-el.bW.Bottom+1));
		var bgR = thisStyle.backgroundRepeat;
		var c = {'T':1, 'R':el.dim.Width+1, 'B':el.dim.Height+1, 'L':1}; /* these are defaults for repeat of any kind */
		var altC = { 'X': {'b1': 'L', 'b2': 'R', 'd': 'Width'}, 'Y': {'b1': 'T', 'b2': 'B', 'd': 'Height'} };
		if (bgR != 'repeat') {
			c = {'T':(bg.Y), 'R':(bg.X+lib.imgSize[el.vmlBg].width), 'B':(bg.Y+lib.imgSize[el.vmlBg].height), 'L':(bg.X)}; /* these are defaults for no-repeat - clips down to the image location */
			if (bgR.search('repeat-') != -1) { /* now let's revert to dC for repeat-x or repeat-y */
				var v = bgR.split('repeat-')[1].toUpperCase();
				c[altC[v].b1] = 1;
				c[altC[v].b2] = el.dim[altC[v].d]+1;
			}
			if (c.B > el.dim.Height) {
				c.B = el.dim.Height+1;
			}
		}
		el.vml.image.style.clip = 'rect('+c.T+'px '+c.R+'px '+c.B+'px '+c.L+'px)';
	},
	
	pseudoClass: function(el) {
		var self = this;
		setTimeout(function() { /* would not work as intended without setTimeout */
			self.applyVML(el);
		}, 1);
	},
	
	reposition: function(el) {
		this.vmlOffsets(el);
		this.vmlPath(el);
	},
	
	roundify: function(rad) {
		this.style.behavior = 'none';
		if (!this.currentStyle) {
			return;
		}
		else {
			var thisStyle = this.currentStyle;
		}
		var allowed = {BODY: false, TABLE: false, TR: false, TD: false, SELECT: false, OPTION: false, TEXTAREA: false};
		if (allowed[this.nodeName] === false) { /* elements not supported yet */
			return;
		}
		var self = this; /* who knows when you might need a setTimeout */
		var lib = DD_roundies;
		this.DD_radii = rad;
		this.dim = {};

		/* attach handlers */
		var handlers = {resize: 'reposition', move: 'reposition'};
		if (this.nodeName == 'A') {
			var moreForAs = {mouseleave: 'pseudoClass', mouseenter: 'pseudoClass', focus: 'pseudoClass', blur: 'pseudoClass'};
			for (var a in moreForAs) {
				handlers[a] = moreForAs[a];
			}
		}
		for (var h in handlers) {
			this.attachEvent('on' + h, function() {
				lib[handlers[h]](self);
			});
		}
		this.attachEvent('onpropertychange', function() {
			lib.readPropertyChanges(self);
		});
		
		/* ensure that this elent and its parent is given hasLayout (needed for accurate positioning) */
		var giveLayout = function(el) {
			el.style.zoom = 1;
			if (el.currentStyle.position == 'static') {
				el.style.position = 'relative';
			}
		};
		giveLayout(this.offsetParent);
		giveLayout(this);
		
		/* create vml elements */
		this.vmlBox = document.createElement('ignore'); /* IE8 really wants to be encased in a wrapper element for the VML to work, and I don't want to disturb getElementsByTagName('div') - open to suggestion on how to do this differently */
		this.vmlBox.runtimeStyle.cssText = 'behavior:none; position:absolute; margin:0; padding:0; border:0; background:none;'; /* super important - if something accidentally matches this (you yourseld did this once, Drew), you'll get infinitely-created elements and a frozen browser! */
		this.vmlBox.style.zIndex = thisStyle.zIndex;
		this.vml = {'color':true, 'image':true, 'stroke':true};
		for (var v in this.vml) {
			this.vml[v] = document.createElement(lib.ns + ':shape');
			this.vml[v].filler = document.createElement(lib.ns + ':fill');
			this.vml[v].appendChild(this.vml[v].filler);
			this.vml[v].stroked = false;
			this.vml[v].style.position = 'absolute';
			this.vml[v].style.zIndex = thisStyle.zIndex;
			this.vml[v].coordorigin = '1,1';
			this.vmlBox.appendChild(this.vml[v]);
		}
		this.vml.image.fillcolor = 'none';
		this.vml.image.filler.type = 'tile';
		this.parentNode.insertBefore(this.vmlBox, this);
		
		this.isImg = false;
		if (this.nodeName == 'IMG') {
			this.isImg = true;
			this.style.visibility = 'hidden';
		}
		
		setTimeout(function() {
			lib.applyVML(self);
		}, 1);
	}
	
};

try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}
DD_roundies.IEversion();
DD_roundies.createVmlNameSpace();
DD_roundies.createVmlStyleSheet();

if (DD_roundies.IE8 && document.attachEvent && DD_roundies.querySelector) {
	document.attachEvent('onreadystatechange', function() {
		if (document.readyState == 'complete') {
			var selectors = DD_roundies.selectorsToProcess;
			var length = selectors.length;
			var delayedCall = function(node, radii, index) {
				setTimeout(function() {
					DD_roundies.roundify.call(node, radii);
				}, index*100);
			};
			for (var i=0; i<length; i++) {
				var results = document.querySelectorAll(selectors[i].selector);
				var rLength = results.length;
				for (var r=0; r<rLength; r++) {
					if (results[r].nodeName != 'INPUT') { /* IE8 doesn't like to do this to inputs yet */
						delayedCall(results[r], selectors[i].radii, r);
					}
				}
			}
		}
	});
}
 /****************************************************************
  *                                                              *
  *  CurvyCorners                                                *
  *  ------------                                                *
  *                                                              *
  *  This script generates rounded corners for your boxes.       *
  *                                                              *
  *  Version 2.1                                             *
  *  Copyright (c) 2010 Cameron Cooke                            *
  *  Contributors: Tim Hutchison, CPK Smithies, Terry Riegel,    *
  *                Simó Albert.                                  *
  *                                                              *
  *  Website: http://www.curvycorners.net                        *
  *  SVN:     http://curvycorners.googlecode.com/                *
  *  Email:   cameron@curvycorners.net                           *
  *  Discuss: http://groups.google.com/group/curvycorners        *
  *                                                              *
  *  Please consult the SVN for a list of changes since the last *
  *  revision.                                                   *
  *                                                              *
  *  This library is free software; you can redistribute         *
  *  it and/or modify it under the terms of the GNU              *
  *  Lesser General Public License as published by the           *
  *  Free Software Foundation; either version 2.1 of the         *
  *  License, or (at your option) any later version.             *
  *                                                              *
  *  This library is distributed in the hope that it will        *
  *  be useful, but WITHOUT ANY WARRANTY; without even the       *
  *  implied warranty of MERCHANTABILITY or FITNESS FOR A        *
  *  PARTICULAR PURPOSE. See the GNU Lesser General Public       *
  *  License for more details.                                   *
  *                                                              *
  *  You should have received a copy of the GNU Lesser           *
  *  General Public License along with this library;             *
  *  Inc., 59 Temple Place, Suite 330, Boston,                   *
  *  MA 02111-1307 USA                                           *
  *                                                              *
  ****************************************************************/

/*
Version 2.x now autoMagically applies borders via CSS rules.

Opera and Chrome support rounded corners via

border-radius

Safari and Mozilla support rounded borders via

-webkit-border-radius, -moz-border-radius

We let these browsers render their borders natively.
Firefox for Windows renders non-antialiased
borders so they look a bit ugly. Google's Chrome will render its "ugly"
borders as well. So if we let FireFox, Safari, Opera and Chrome render
their borders natively, then we only have to support IE
for rounded borders. Fortunately IE reads CSS properties
that it doesn't understand (Opera, Firefox and Safari discard them);
so for IE we find and apply -moz-border-radius and friends.

So to make curvycorners work with any major browser simply add the
following CSS declarations and it should be good to go...

.round {
  border-radius: 3ex;
  -webkit-border-radius: 3ex;
  -moz-border-radius: 3ex;
}
*/

function browserdetect() {
  var agent = navigator.userAgent.toLowerCase();
  this.isIE = agent.indexOf("msie") > -1;
  if (this.isIE) {
    this.ieVer = /msie\s(\d\.\d)/.exec(agent)[1];
    this.quirksMode = !document.compatMode || document.compatMode.indexOf("BackCompat") > -1;
    this.get_style = function(obj, prop) {
      if (!(prop in obj.currentStyle)) return "";
      var matches = /^([\d.]+)(\w*)/.exec(obj.currentStyle[prop]);
      if (!matches) return obj.currentStyle[prop];
      if (matches[1] == 0) return '0';
      // now convert to pixels if necessary
      if (matches[2] && matches[2] !== 'px') {
        var style = obj.style.left;
        var rtStyle = obj.runtimeStyle.left;
        obj.runtimeStyle.left = obj.currentStyle.left;
        obj.style.left = matches[1] + matches[2];
        matches[0] = obj.style.pixelLeft;
        obj.style.left = style;
        obj.runtimeStyle.left = rtStyle;
      }
      return matches[0];
    };
    this.supportsCorners = false;
  }
  else {
    this.ieVer = this.quirksMode = 0;
    this.get_style = function(obj, prop) {
      prop = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
      return document.defaultView.getComputedStyle(obj, '').getPropertyValue(prop);
    };
    this.isSafari  = agent.indexOf('safari') != -1;
    this.isWebKit  = agent.indexOf('webkit') != -1;
    this.isOp      = 'opera' in window;
    if (this.isOp)
      this.supportsCorners =  (this.isOp = window.opera.version()) >= 10.5;
    else {
      if (!this.isWebkit) { // firefox check
        if (!(this.isMoz = agent.indexOf('firefox') !== -1)) {
          for (var i = document.childNodes.length; --i >= 0; ) if ('style' in document.childNodes[i]) {
            this.isMoz = 'MozBorderRadius' in document.childNodes[i].style;
            break;
          }
        }
      }
      this.supportsCorners = this.isWebKit || this.isMoz;
    }
  }
}
var curvyBrowser = new browserdetect;

/* Force caching of bg images in IE6 */
if (curvyBrowser.isIE) {
  try {
    document.execCommand("BackgroundImageCache", false, true);
  }
  catch(e) {}
}

// object that parses border-radius properties for a box

function curvyCnrSpec(selText) {
  this.selectorText = selText;
  this.tlR = this.trR = this.blR = this.brR = 0;
  this.tlu = this.tru = this.blu = this.bru = "";
  this.antiAlias = true; // default true
}
curvyCnrSpec.prototype.setcorner = function(tb, lr, radius, unit) {
  if (!tb) { // no corner specified
    this.tlR = this.trR = this.blR = this.brR = parseInt(radius);
    this.tlu = this.tru = this.blu = this.bru = unit;
  }
  else { // corner specified
    var propname = tb.charAt(0) + lr.charAt(0);
    this[propname + 'R'] = parseInt(radius);
    this[propname + 'u'] = unit;
  }
};
/*
  get(propstring)
  where propstring is:
  - 'tR' or 'bR' : returns top or bottom radius.
  - 'tlR', 'trR', 'blR' or 'brR' : returns top/bottom left/right radius.
  - 'tlu', 'tru', 'blr' or 'bru' : returns t/b l/r unit (px, em...)
  - 'tRu' or 'bRu' : returns top/bottom radius+unit
  - 'tlRu', 'trRu', 'blRu', 'brRu' : returns t/b l/r radius+unit
*/
curvyCnrSpec.prototype.get = function(prop) {
  if (/^(t|b)(l|r)(R|u)$/.test(prop)) return this[prop];
  if (/^(t|b)(l|r)Ru$/.test(prop)) {
    var pname = prop.charAt(0) + prop.charAt(1);
    return this[pname + 'R'] + this[pname + 'u'];
  }
  if (/^(t|b)Ru?$/.test(prop)) {
    var tb = prop.charAt(0);
    tb += this[tb + 'lR'] > this[tb + 'rR'] ? 'l' : 'r';
    var retval = this[tb + 'R'];
    if (prop.length === 3 && prop.charAt(2) === 'u')
      retval += this[tb = 'u'];
    return retval;
  }
  throw new Error('Don\'t recognize property ' + prop);
};
curvyCnrSpec.prototype.radiusdiff = function(tb) {
  if (tb !== 't' && tb !== 'b') throw new Error("Param must be 't' or 'b'");
  return Math.abs(this[tb + 'lR'] - this[tb + 'rR']);
};
curvyCnrSpec.prototype.setfrom = function(obj) {
  this.tlu = this.tru = this.blu = this.bru = 'px'; // default to px
  if ('tl' in obj) this.tlR = obj.tl.radius;
  if ('tr' in obj) this.trR = obj.tr.radius;
  if ('bl' in obj) this.blR = obj.bl.radius;
  if ('br' in obj) this.brR = obj.br.radius;
  if ('antiAlias' in obj) this.antiAlias = obj.antiAlias;
};
curvyCnrSpec.prototype.cloneOn = function(box) { // not needed by IE
  var props = ['tl', 'tr', 'bl', 'br'];
  var converted = 0;
  var i, propu;

  for (i in props) if (!isNaN(i)) {
    propu = this[props[i] + 'u'];
    if (propu !== '' && propu !== 'px') {
      converted = new curvyCnrSpec;
      break;
    }
  }
  if (!converted)
    converted = this; // no need to clone
  else {
    var propi, propR, save = curvyBrowser.get_style(box, 'left');
    for (i in props) if (!isNaN(i)) {
      propi = props[i];
      propu = this[propi + 'u'];
      propR = this[propi + 'R'];
      if (propu !== 'px') {
        var save2 = box.style.left;
        box.style.left = propR + propu;
        propR = box.style.pixelLeft;
        box.style.left = save2;
      }
      converted[propi + 'R'] = propR;
      converted[propi + 'u'] = 'px';
    }
    box.style.left = save;
  }
  return converted;
};
curvyCnrSpec.prototype.radiusSum = function(tb) {
  if (tb !== 't' && tb !== 'b') throw new Error("Param must be 't' or 'b'");
  return this[tb + 'lR'] + this[tb + 'rR'];
};
curvyCnrSpec.prototype.radiusCount = function(tb) {
  var count = 0;
  if (this[tb + 'lR']) ++count;
  if (this[tb + 'rR']) ++count;
  return count;
};
curvyCnrSpec.prototype.cornerNames = function() {
  var ret = [];
  if (this.tlR) ret.push('tl');
  if (this.trR) ret.push('tr');
  if (this.blR) ret.push('bl');
  if (this.brR) ret.push('br');
  return ret;
};

/*
  Object that parses Opera CSS
*/
function operasheet(sheetnumber) {
  var txt = document.styleSheets.item(sheetnumber).ownerNode.text;
  txt = txt.replace(/\/\*(\n|\r|.)*?\*\//g, ''); // strip comments
  // this pattern extracts all border-radius-containing rulesets
  // matches will be:
  // [0] = the whole lot
  // [1] = the selector text
  // [2] = all the rule text between braces
  // [3] = top/bottom and left/right parts if present (only if webkit/CSS3)
  // [4] = top|bottom
  // [5] = left|right
  // .. but 3..5 are useless as they're only the first match.
  var pat = new RegExp("^\\s*([\\w.#][-\\w.#, ]+)[\\n\\s]*\\{([^}]+border-((top|bottom)-(left|right)-)?radius[^}]*)\\}", "mg");
  var matches;
  this.rules = [];
  while ((matches = pat.exec(txt)) !== null) {
    var pat2 = new RegExp("(..)border-((top|bottom)-(left|right)-)?radius:\\s*([\\d.]+)(in|em|px|ex|pt)", "g");
    var submatches, cornerspec = new curvyCnrSpec(matches[1]);
    while ((submatches = pat2.exec(matches[2])) !== null)
      if (submatches[1] !== "z-")
        cornerspec.setcorner(submatches[3], submatches[4], submatches[5], submatches[6]);
    this.rules.push(cornerspec);
  }
}
// static class function to determine if the sheet is worth parsing
operasheet.contains_border_radius = function(sheetnumber) {
  return /border-((top|bottom)-(left|right)-)?radius/.test(document.styleSheets.item(sheetnumber).ownerNode.text);
};

/*
Usage:

  curvyCorners(settingsObj, "selectorStr");
  curvyCorners(settingsObj, domObj1[, domObj2[, domObj3[, . . . [, domObjN]]]]);
  selectorStr::= "<complexSelector>[, <complexSelector>]..."
  complexSelector::= <selector>[ <selector]
  selector::= "[<elementname>].classname" | "#id"
*/

function curvyCorners() {
  var i, j, boxCol, settings, startIndex;
  // Check parameters
  if (typeof arguments[0] !== "object") throw curvyCorners.newError("First parameter of curvyCorners() must be an object.");
  if (arguments[0] instanceof curvyCnrSpec) {
    settings = arguments[0];
    if (!settings.selectorText && typeof arguments[1] === 'string')
      settings.selectorText = arguments[1];
  }
  else {
    if (typeof arguments[1] !== "object" && typeof arguments[1] !== "string") throw curvyCorners.newError("Second parameter of curvyCorners() must be an object or a class name.");
    j = arguments[1];
    if (typeof j !== 'string') j = '';
    if (j !== '' && j.charAt(0) !== '.' && 'autoPad' in arguments[0]) j = '.' + j; // for compatibility, prefix with dot
    settings = new curvyCnrSpec(j);
    settings.setfrom(arguments[0]);
  }

  // Get object(s)
  if (settings.selectorText) {
    startIndex = 0;
    var args = settings.selectorText.replace(/\s+$/,'').split(/,\s*/); // handle comma-separated selector list
    boxCol = new Array;

    for (i = 0; i < args.length; ++i) {
      if ((j = args[i].lastIndexOf('#')) !== -1)
        args[i] = args[i].substr(j); // ignore everything on LHS of ID
      boxCol = boxCol.concat(curvyCorners.getElementsBySelector(args[i].split(/\s+/)));
    }
  }
  else {
    startIndex = 1;
    boxCol = arguments;
  }

  // Loop through each object
  for (i = startIndex, j = boxCol.length; i < j; ++i) {
    var theBox = boxCol[i];
    var skipCorners = false;
    if (!theBox.className)
      theBox.className = 'curvyIgnore'; // don't do it twice
    else {
      skipCorners = theBox.className.indexOf('curvyIgnore') !== -1;
      if (!skipCorners) theBox.className += ' curvyIgnore'; // prevent repeats
    }
    if (!skipCorners) {
      if (theBox.className.indexOf('curvyRedraw') !== -1) {
        if (typeof curvyCorners.redrawList === 'undefined') curvyCorners.redrawList = new Array;
        curvyCorners.redrawList.push({
          node : theBox,
          spec : settings,
          copy : theBox.cloneNode(false)
        });
      }
      var obj = new curvyObject(settings, theBox);
      obj.applyCorners();
    }
  }
}
curvyCorners.prototype.applyCornersToAll = function () { // now redundant
  throw curvyCorners.newError('This function is now redundant. Just call curvyCorners(). See documentation.');
};

curvyCorners.redraw = function() {
  if (curvyBrowser.supportsCorners) return;
  if (!curvyCorners.redrawList) throw curvyCorners.newError('curvyCorners.redraw() has nothing to redraw.');
  var old_block_value = curvyCorners.block_redraw;
  curvyCorners.block_redraw = true;
  for (var i in curvyCorners.redrawList) {
    if (isNaN(i)) continue; // in case of added prototype methods
    var o = curvyCorners.redrawList[i];
    if (!o.node.clientWidth) continue; // don't resize hidden boxes
    var newchild = o.copy.cloneNode(false);
    for (var contents = o.node.firstChild; contents !== null; contents = contents.nextSibling)
      if (contents.className.indexOf('autoPadDiv') !== -1) break;
    if (!contents) {
      curvyCorners.alert('Couldn\'t find autoPad DIV');
      break;
    }
    o.node.parentNode.replaceChild(newchild, o.node);
    // remove script elements, if any
    var scripts = contents.getElementsByTagName('script');
    for (var j = scripts.length - 1; j >= 0; --j)
      scripts[j].parentNode.removeChild(scripts[j]);
    while (contents.firstChild) newchild.appendChild(contents.removeChild(contents.firstChild));
    o = new curvyObject(o.spec, o.node = newchild);
    o.applyCorners();
  }
  curvyCorners.block_redraw = old_block_value;
};
curvyCorners.adjust = function(obj, prop, newval) {
  if (!curvyBrowser.supportsCorners) {
    if (!curvyCorners.redrawList) throw curvyCorners.newError('curvyCorners.adjust() has nothing to adjust.');
    var i, j = curvyCorners.redrawList.length;
    for (i = 0; i < j; ++i) if (curvyCorners.redrawList[i].node === obj) break;
    if (i === j) throw curvyCorners.newError('Object not redrawable');
    obj = curvyCorners.redrawList[i].copy;
  }
  if (prop.indexOf('.') === -1)
    obj[prop] = newval;
  else eval('obj.' + prop + "='" + newval + "'");
};
curvyCorners.handleWinResize = function() {
  if (!curvyCorners.block_redraw) curvyCorners.redraw();
};
curvyCorners.setWinResize = function(onoff) {
  curvyCorners.block_redraw = !onoff;
};
curvyCorners.newError = function(errorMessage) {
  return new Error("curvyCorners Error:\n" + errorMessage);
};
curvyCorners.alert = function(errorMessage) {
  if (typeof curvyCornersVerbose === 'undefined' || curvyCornersVerbose) alert(errorMessage);
};

// curvyCorners object (can be called directly)

function curvyObject() {
  var boxDisp;
  this.box              = arguments[1];
  this.settings         = arguments[0];
  this.topContainer = this.bottomContainer = this.shell = boxDisp = null;
  var boxWidth = this.box.clientWidth; // browser-independent IE-emulation (NB includes padding)

  if (('canHaveChildren' in this.box && !this.box.canHaveChildren) || this.box.tagName === 'TABLE')
    throw new Error(this.errmsg("You cannot apply corners to " + this.box.tagName + " elements.", "Error"));
  if (!boxWidth && curvyBrowser.isIE) {
    this.box.style.zoom = 1; // can force IE to calculate width
    boxWidth = this.box.clientWidth;
  }

  // try to handle attempts to style inline elements

  if (!boxWidth && curvyBrowser.get_style(this.box, 'display') === 'inline') {
    this.box.style.display = 'inline-block';
    curvyCorners.alert(this.errmsg("Converting inline element to inline-block", "warning"));
    boxWidth = this.box.clientWidth;
  }

  // if still no clientWidth, maybe the box or a parent has 'display:none'.

  if (!boxWidth) {
    if (!this.box.parentNode) throw this.newError("box has no parent!"); // unlikely...
    for (boxDisp = this.box; ; boxDisp = boxDisp.parentNode) {
      if (!boxDisp || boxDisp.tagName === 'BODY') { // we've hit the buffers
        this.applyCorners = function() {}; // make the error benign
        curvyCorners.alert(this.errmsg("zero-width box with no accountable parent", "warning"));
        return;
      }
      if (curvyBrowser.get_style(boxDisp, 'display') === 'none') break;
    }
    // here, we've found the box whose display is set to 'none'.
    var boxDispSave = boxDisp.style.display;
    boxDisp.style.display = 'block'; // display in order to get browser to calculate clientWidth
    boxWidth = this.box.clientWidth;
  }

  // all attempts have failed

  if (!boxWidth) {
    curvyCorners.alert(this.errmsg("zero-width box, cannot display", "error"));
    this.applyCorners = function() {}; // make the error harmless
    return;
  }
  if (arguments[0] instanceof curvyCnrSpec)
    this.spec = arguments[0].cloneOn(this.box); // convert non-pixel units
  else {
    this.spec = new curvyCnrSpec('');
    this.spec.setfrom(this.settings); // no need for unit conversion, use settings param. directly
  }

  // Get box formatting details
  var borderWidth     = curvyBrowser.get_style(this.box, "borderTopWidth");
  var borderWidthB    = curvyBrowser.get_style(this.box, "borderBottomWidth");
  var borderWidthL    = curvyBrowser.get_style(this.box, "borderLeftWidth");
  var borderWidthR    = curvyBrowser.get_style(this.box, "borderRightWidth");
  var borderColour    = curvyBrowser.get_style(this.box, "borderTopColor");
  var borderColourB   = curvyBrowser.get_style(this.box, "borderBottomColor");
  var borderColourL   = curvyBrowser.get_style(this.box, "borderLeftColor");
  var borderColourR   = curvyBrowser.get_style(this.box, "borderRightColor");
  var borderStyle     = curvyBrowser.get_style(this.box, "borderTopStyle");
  var borderStyleB    = curvyBrowser.get_style(this.box, "borderBottomStyle");
  var borderStyleL    = curvyBrowser.get_style(this.box, "borderLeftStyle");
  var borderStyleR    = curvyBrowser.get_style(this.box, "borderRightStyle");

  var boxColour       = curvyBrowser.get_style(this.box, "backgroundColor");
  var backgroundImage = curvyBrowser.get_style(this.box, "backgroundImage");
  var backgroundRepeat= curvyBrowser.get_style(this.box, "backgroundRepeat");
  var backgroundPosX, backgroundPosY;
  if (this.box.currentStyle && this.box.currentStyle.backgroundPositionX) {
    backgroundPosX  = curvyBrowser.get_style(this.box, "backgroundPositionX");
    backgroundPosY  = curvyBrowser.get_style(this.box, "backgroundPositionY");
  }
  else {
    backgroundPosX = curvyBrowser.get_style(this.box, 'backgroundPosition');
    backgroundPosX = backgroundPosX.split(' ');
    backgroundPosY = backgroundPosX.length === 2 ? backgroundPosX[1] : 0;
    backgroundPosX = backgroundPosX[0];
  }
  var boxPosition     = curvyBrowser.get_style(this.box, "position");
  var topPadding      = curvyBrowser.get_style(this.box, "paddingTop");
  var bottomPadding   = curvyBrowser.get_style(this.box, "paddingBottom");
  var leftPadding     = curvyBrowser.get_style(this.box, "paddingLeft");
  var rightPadding    = curvyBrowser.get_style(this.box, "paddingRight");
  var filter = curvyBrowser.ieVer > 7 ? curvyBrowser.get_style(this.box, 'filter') : null; // IE8 bug fix

  var topMaxRadius    = this.spec.get('tR');
  var botMaxRadius    = this.spec.get('bR');
  var styleToNPx = function(val) {
    if (typeof val === 'number') return val;
    if (typeof val !== 'string') throw new Error('unexpected styleToNPx type ' + typeof val);
    var matches = /^[-\d.]([a-z]+)$/.exec(val);
    if (matches && matches[1] != 'px') throw new Error('Unexpected unit ' + matches[1]);
    if (isNaN(val = parseInt(val))) val = 0;
    return val;
  };
  var min0Px = function(val) {
    return val <= 0 ? "0" : val + "px";
  };

  // Set formatting properties
  try {
    this.borderWidth     = styleToNPx(borderWidth);
    this.borderWidthB    = styleToNPx(borderWidthB);
    this.borderWidthL    = styleToNPx(borderWidthL);
    this.borderWidthR    = styleToNPx(borderWidthR);
    this.boxColour       = curvyObject.format_colour(boxColour);
    this.topPadding      = styleToNPx(topPadding);
    this.bottomPadding   = styleToNPx(bottomPadding);
    this.leftPadding     = styleToNPx(leftPadding);
    this.rightPadding    = styleToNPx(rightPadding);
    this.boxWidth        = boxWidth;
    this.boxHeight       = this.box.clientHeight;
    this.borderColour    = curvyObject.format_colour(borderColour);
    this.borderColourB   = curvyObject.format_colour(borderColourB);
    this.borderColourL   = curvyObject.format_colour(borderColourL);
    this.borderColourR   = curvyObject.format_colour(borderColourR);
    this.borderString    = this.borderWidth + "px" + " " + borderStyle + " " + this.borderColour;
    this.borderStringB   = this.borderWidthB + "px" + " " + borderStyleB + " " + this.borderColourB;
    this.borderStringL   = this.borderWidthL + "px" + " " + borderStyleL + " " + this.borderColourL;
    this.borderStringR   = this.borderWidthR + "px" + " " + borderStyleR + " " + this.borderColourR;
    this.backgroundImage = ((backgroundImage != "none")? backgroundImage : "");
    this.backgroundRepeat= backgroundRepeat;
  }
  catch(e) {
    throw this.newError(e.message);
  }
  var clientHeight = this.boxHeight;
  var clientWidth = boxWidth; // save it as it gets trampled on later
  if (curvyBrowser.isOp) {
    var t;
    backgroundPosX = styleToNPx(backgroundPosX);
    backgroundPosY = styleToNPx(backgroundPosY);
    if (backgroundPosX) {
      t = clientWidth + this.borderWidthL + this.borderWidthR;
      if (backgroundPosX > t) backgroundPosX = t;
      backgroundPosX = (t / backgroundPosX * 100) + '%'; // convert to percentage
    }
    if (backgroundPosY) {
      t = clientHeight + this.borderWidth + this.borderWidthB;
      if (backgroundPosY > t) backgroundPosY = t;
      backgroundPosY = (t / backgroundPosY * 100) + '%'; // convert to percentage
    }
  }
  if (curvyBrowser.quirksMode) {
  }
  else {
    this.boxWidth -= this.leftPadding + this.rightPadding;
    this.boxHeight -= this.topPadding + this.bottomPadding;
  }

  // Create content container
  this.contentContainer = document.createElement("div");
  if (filter) this.contentContainer.style.filter = filter; // IE8 bug fix
  while (this.box.firstChild) this.contentContainer.appendChild(this.box.removeChild(this.box.firstChild));

  if (boxPosition != "absolute") this.box.style.position = "relative";
  this.box.style.padding = '0';
  this.box.style.border = this.box.style.backgroundImage = 'none';
  this.box.style.backgroundColor = 'transparent';

  this.box.style.width   = (clientWidth + this.borderWidthL + this.borderWidthR) + 'px';
  this.box.style.height  = (clientHeight + this.borderWidth + this.borderWidthB) + 'px';

  // Ok we add an inner div to actually put things into this will allow us to keep the height

  var newMainContainer = document.createElement("div");
  newMainContainer.style.position = "absolute";
  if (filter) newMainContainer.style.filter = filter; // IE8 bug fix
  if (curvyBrowser.quirksMode) {
    newMainContainer.style.width  = (clientWidth + this.borderWidthL + this.borderWidthR) + 'px';
  } else {
    newMainContainer.style.width  = clientWidth + 'px';
  }
  newMainContainer.style.height = min0Px(clientHeight + this.borderWidth + this.borderWidthB - topMaxRadius - botMaxRadius);
  newMainContainer.style.padding  = "0";
  newMainContainer.style.top    = topMaxRadius + "px";
  newMainContainer.style.left   = "0";
  if (this.borderWidthL)
    newMainContainer.style.borderLeft = this.borderStringL;
  if (this.borderWidth && !topMaxRadius)
    newMainContainer.style.borderTop = this.borderString;
  if (this.borderWidthR)
    newMainContainer.style.borderRight = this.borderStringR;
  if (this.borderWidthB && !botMaxRadius)
    newMainContainer.style.borderBottom = this.borderStringB;
  newMainContainer.style.backgroundColor    = boxColour;
  newMainContainer.style.backgroundImage    = this.backgroundImage;
  newMainContainer.style.backgroundRepeat   = this.backgroundRepeat;
  newMainContainer.style.direction = 'ltr';
  this.shell = this.box.appendChild(newMainContainer);

  boxWidth = curvyBrowser.get_style(this.shell, "width");
  if (boxWidth === "" || boxWidth === "auto" || boxWidth.indexOf("%") !== -1) throw this.newError('Shell width is ' + boxWidth);
  this.boxWidth = (boxWidth !== "" && boxWidth != "auto" && boxWidth.indexOf("%") == -1) ? parseInt(boxWidth) : this.shell.clientWidth;

  /*
    This method creates the corners and
    applies them to the div element.
  */
  this.applyCorners = function() {
    /*
      Set up background offsets. This may need to be delayed until
      the background image is loaded.
    */
    this.backgroundPosX = this.backgroundPosY = 0;
    if (this.backgroundObject) {
      var bgOffset = function(style, imglen, boxlen) {
        if (style === 0) return 0;
        if (style === 'right' || style === 'bottom') return boxlen - imglen;
        if (style === 'center') return (boxlen - imglen) / 2;
        if (style.indexOf('%') > 0) return (boxlen - imglen) * 100 / parseInt(style);
        return styleToNPx(style);
      };
      this.backgroundPosX  = bgOffset(backgroundPosX, this.backgroundObject.width, clientWidth);
      this.backgroundPosY  = bgOffset(backgroundPosY, this.backgroundObject.height, clientHeight);
    }
    else if (this.backgroundImage) {
      this.backgroundPosX = styleToNPx(backgroundPosX);
      this.backgroundPosY = styleToNPx(backgroundPosY);
    }
    /*
      Create top and bottom containers.
      These will be used as a parent for the corners and bars.
    */
    // Build top bar only if a top corner is to be drawn
    if (topMaxRadius) {
      newMainContainer = document.createElement("div");
      newMainContainer.style.width = this.boxWidth + "px";
      newMainContainer.style.fontSize = "1px";
      newMainContainer.style.overflow = "hidden";
      newMainContainer.style.position = "absolute";
      newMainContainer.style.paddingLeft  = this.borderWidth + "px";
      newMainContainer.style.paddingRight = this.borderWidth + "px";
      newMainContainer.style.height = topMaxRadius + "px";
      newMainContainer.style.top    = -topMaxRadius + "px";
      newMainContainer.style.left   = -this.borderWidthL + "px";
      this.topContainer = this.shell.appendChild(newMainContainer);
    }
    // Build bottom bar only if a bottom corner is to be drawn
    if (botMaxRadius) {
      newMainContainer = document.createElement("div");
      newMainContainer.style.width = this.boxWidth + "px";
      newMainContainer.style.fontSize = "1px";
      newMainContainer.style.overflow = "hidden";
      newMainContainer.style.position = "absolute";
      newMainContainer.style.paddingLeft  = this.borderWidthB + "px";
      newMainContainer.style.paddingRight = this.borderWidthB + "px";
      newMainContainer.style.height   =  botMaxRadius + "px";
      newMainContainer.style.bottom   = -botMaxRadius + "px";
      newMainContainer.style.left     = -this.borderWidthL + "px";
      this.bottomContainer = this.shell.appendChild(newMainContainer);
    }

    var corners = this.spec.cornerNames();  // array of available corners

    /*
    Loop for each corner
    */
    for (var i in corners) if (!isNaN(i)) {
      // Get current corner type from array
      var cc = corners[i];
      var specRadius = this.spec[cc + 'R'];
      // Has the user requested the currentCorner be round?
      // Code to apply correct color to top or bottom
      var bwidth, bcolor, borderRadius, borderWidthTB;
      if (cc == "tr" || cc == "tl") {
        bwidth = this.borderWidth;
        bcolor = this.borderColour;
        borderWidthTB = this.borderWidth;
      } else {
        bwidth = this.borderWidthB;
        bcolor = this.borderColourB;
        borderWidthTB = this.borderWidthB;
      }
      borderRadius = specRadius - borderWidthTB;
      var newCorner = document.createElement("div");
      newCorner.style.height = this.spec.get(cc + 'Ru');
      newCorner.style.width  = this.spec.get(cc + 'Ru');
      newCorner.style.position = "absolute";
      newCorner.style.fontSize = "1px";
      newCorner.style.overflow = "hidden";
      // THE FOLLOWING BLOCK OF CODE CREATES A ROUNDED CORNER
      // ---------------------------------------------------- TOP
      var intx, inty, outsideColour;
      var trans = filter ? parseInt(/alpha\(opacity.(\d+)\)/.exec(filter)[1]) : 100; // IE8 bug fix
      // Cycle the x-axis
      for (intx = 0; intx < specRadius; ++intx) {
        // Calculate the value of y1 which identifies the pixels inside the border
        var y1 = (intx + 1 >= borderRadius) ? -1 : Math.floor(Math.sqrt(Math.pow(borderRadius, 2) - Math.pow(intx + 1, 2))) - 1;
        // Calculate y2 and y3 only if there is a border defined
        if (borderRadius != specRadius) {
          var y2 = (intx >= borderRadius) ? -1 : Math.ceil(Math.sqrt(Math.pow(borderRadius, 2) - Math.pow(intx, 2)));
          var y3 = (intx + 1 >= specRadius) ? -1 : Math.floor(Math.sqrt(Math.pow(specRadius, 2) - Math.pow((intx+1), 2))) - 1;
        }
        // Calculate y4
        var y4 = (intx >= specRadius) ? -1 : Math.ceil(Math.sqrt(Math.pow(specRadius, 2) - Math.pow(intx, 2)));
        // Draw bar on inside of the border with foreground colour
        if (y1 > -1) this.drawPixel(intx, 0, this.boxColour, trans, (y1 + 1), newCorner, true, specRadius);
        // Draw border/foreground antialiased pixels and border only if there is a border defined
        if (borderRadius != specRadius) {
          // Cycle the y-axis
          if (this.spec.antiAlias) {
            for (inty = y1 + 1; inty < y2; ++inty) {
              // For each of the pixels that need anti aliasing between the foreground and border colour draw single pixel divs
              if (this.backgroundImage !== "") {
                var borderFract = curvyObject.pixelFraction(intx, inty, borderRadius) * 100;
                this.drawPixel(intx, inty, bcolor, trans, 1, newCorner, borderFract >= 30, specRadius);
              }
              else if (this.boxColour !== 'transparent') {
                var pixelcolour = curvyObject.BlendColour(this.boxColour, bcolor, curvyObject.pixelFraction(intx, inty, borderRadius));
                this.drawPixel(intx, inty, pixelcolour, trans, 1, newCorner, false, specRadius);
              }
              else this.drawPixel(intx, inty, bcolor, trans >> 1, 1, newCorner, false, specRadius);
            }
            // Draw bar for the border
            if (y3 >= y2) {
              if (y2 == -1) y2 = 0;
              this.drawPixel(intx, y2, bcolor, trans, (y3 - y2 + 1), newCorner, false, 0);
            }
            outsideColour = bcolor;  // Set the colour for the outside AA curve
            inty = y3;               // start_pos - 1 for y-axis AA pixels
          }
          else { // no antiAlias
            if (y3 > y1) { // NB condition was >=, changed to avoid zero-height divs
              this.drawPixel(intx, (y1 + 1), bcolor, trans, (y3 - y1), newCorner, false, 0);
            }
          }
        }
        else {
          outsideColour = this.boxColour;  // Set the colour for the outside curve
          inty = y1;               // start_pos - 1 for y-axis AA pixels
        }
        // Draw aa pixels?
        if (this.spec.antiAlias && this.boxColour !== 'transparent') {
          // Cycle the y-axis and draw the anti aliased pixels on the outside of the curve
          while (++inty < y4) {
            // For each of the pixels that need anti aliasing between the foreground/border colour & background draw single pixel divs
            this.drawPixel(intx, inty, outsideColour, (curvyObject.pixelFraction(intx, inty , specRadius) * trans), 1, newCorner, borderWidthTB <= 0, specRadius);
          }
        }
      }
      // END OF CORNER CREATION
      // ---------------------------------------------------- END

      /*
      Now we have a new corner we need to reposition all the pixels unless
      the current corner is the bottom right.
      */
      // Loop through all children (pixel bars)
      var k;
      for (t = 0, k = newCorner.childNodes.length; t < k; ++t) {
        // Get current pixel bar
        var pixelBar = newCorner.childNodes[t];
        // Get current top and left properties
        var pixelBarTop    = parseInt(pixelBar.style.top);
        var pixelBarLeft   = parseInt(pixelBar.style.left);
        var pixelBarHeight = parseInt(pixelBar.style.height);
        // Reposition pixels
        if (cc == "tl" || cc == "bl") {
          pixelBar.style.left = (specRadius - pixelBarLeft - 1) + "px"; // Left
        }
        if (cc == "tr" || cc == "tl"){
          pixelBar.style.top =  (specRadius - pixelBarHeight - pixelBarTop) + "px"; // Top
        }
        pixelBar.style.backgroundRepeat = this.backgroundRepeat;

        if (this.backgroundImage) switch(cc) {
          case "tr":
            pixelBar.style.backgroundPosition = (this.backgroundPosX - this.borderWidthL + specRadius - clientWidth - pixelBarLeft) + "px " + (this.backgroundPosY + pixelBarHeight + pixelBarTop + this.borderWidth - specRadius) + "px";
          break;
          case "tl":
            pixelBar.style.backgroundPosition = (this.backgroundPosX - specRadius + pixelBarLeft + 1 + this.borderWidthL) + "px " + (this.backgroundPosY - specRadius + pixelBarHeight + pixelBarTop + this.borderWidth) + "px";
          break;
          case "bl":
            pixelBar.style.backgroundPosition = (this.backgroundPosX - specRadius + pixelBarLeft + 1 + this.borderWidthL) + "px " + (this.backgroundPosY - clientHeight - this.borderWidth + (curvyBrowser.quirksMode ? pixelBarTop : -pixelBarTop) + specRadius) + "px";
          break;
          case "br":
            if (curvyBrowser.quirksMode) {
              pixelBar.style.backgroundPosition = (this.backgroundPosX - this.borderWidthL - clientWidth + specRadius - pixelBarLeft) + "px " + (this.backgroundPosY - clientHeight - this.borderWidth + pixelBarTop + specRadius) + "px";
            } else {
              pixelBar.style.backgroundPosition = (this.backgroundPosX - this.borderWidthL - clientWidth + specRadius - pixelBarLeft) + "px " + (this.backgroundPosY - clientHeight - this.borderWidth + specRadius - pixelBarTop) + "px";
            }
          //break;
        }
      }

      // Position the container
      switch (cc) {
        case "tl":
          newCorner.style.top = newCorner.style.left = "0";
          this.topContainer.appendChild(newCorner);
        break;
        case "tr":
          newCorner.style.top = newCorner.style.right = "0";
          this.topContainer.appendChild(newCorner);
        break;
        case "bl":
          newCorner.style.bottom = newCorner.style.left = "0";
          this.bottomContainer.appendChild(newCorner);
        break;
        case "br":
          newCorner.style.bottom = newCorner.style.right = "0";
          this.bottomContainer.appendChild(newCorner);
        //break;
      }
    }

    /*
      The last thing to do is draw the rest of the filler DIVs.
    */

    // Find out which corner has the bigger radius and get the difference amount
    var radiusDiff = {
      t : this.spec.radiusdiff('t'),
      b : this.spec.radiusdiff('b')
    };

    for (var z in radiusDiff) {
      if (typeof z === 'function') continue; // for prototype, mootools frameworks
      if (!this.spec.get(z + 'R')) continue; // no need if no corners
      if (radiusDiff[z]) {
        // Get the type of corner that is the smaller one
        var smallerCornerType = (this.spec[z + "lR"] < this.spec[z + "rR"]) ? z + "l" : z + "r";

        // First we need to create a DIV for the space under the smaller corner
        var newFiller = document.createElement("div");
        newFiller.style.height = radiusDiff[z] + "px";
        newFiller.style.width  =  this.spec.get(smallerCornerType + 'Ru');
        newFiller.style.position = "absolute";
        newFiller.style.fontSize = "1px";
        newFiller.style.overflow = "hidden";
        newFiller.style.backgroundColor = this.boxColour;
        if (filter) newFiller.style.filter = filter; // IE8 bug fix
        // Set background image with original features
        newFiller.style.backgroundImage = this.backgroundImage;
        newFiller.style.backgroundRepeat = this.backgroundRepeat;

        // Position filler
        switch (smallerCornerType) {
          case "tl":
            newFiller.style.bottom =
            newFiller.style.left   = "0";
            newFiller.style.borderLeft = this.borderStringL;
            // Set background image in original position
            newFiller.style.backgroundPosition = this.backgroundPosX + "px " + (this.borderWidth + this.backgroundPosY - this.spec.tlR) + "px";
            this.topContainer.appendChild(newFiller);
          break;
          case "tr":
            newFiller.style.bottom =
            newFiller.style.right  = "0";
            newFiller.style.borderRight = this.borderStringR;
            // Set background image in original position
            newFiller.style.backgroundPosition = (this.backgroundPosX - this.boxWidth + this.spec.trR) + "px " + (this.borderWidth + this.backgroundPosY - this.spec.trR) + "px";
            this.topContainer.appendChild(newFiller);
          break;
          case "bl":
            newFiller.style.top    =
            newFiller.style.left   = "0";
            newFiller.style.borderLeft = this.borderStringL;
            // Set background image in original position
            newFiller.style.backgroundPosition = this.backgroundPosX + "px " + (this.backgroundPosY - this.borderWidth - this.boxHeight + radiusDiff[z] + this.spec.blR) + "px";
            this.bottomContainer.appendChild(newFiller);
          break;
          case "br":
            newFiller.style.top    =
            newFiller.style.right  = "0";
            newFiller.style.borderRight = this.borderStringR;
            // Set background image in original position.
            newFiller.style.backgroundPosition = (this.borderWidthL + this.backgroundPosX - this.boxWidth + this.spec.brR) + "px " + (this.backgroundPosY - this.borderWidth - this.boxHeight + radiusDiff[z] + this.spec.brR) + "px";
            this.bottomContainer.appendChild(newFiller);
          //break;
        }
      }

      // Create the bar to fill the gap between each corner horizontally
      var newFillerBar = document.createElement("div");
      if (filter) newFillerBar.style.filter = filter; // IE8 bug fix
      newFillerBar.style.position = "relative";
      newFillerBar.style.fontSize = "1px";
      newFillerBar.style.overflow = "hidden";
      newFillerBar.style.width = this.fillerWidth(z);
      newFillerBar.style.backgroundColor = this.boxColour;
      newFillerBar.style.backgroundImage = this.backgroundImage;
      newFillerBar.style.backgroundRepeat= this.backgroundRepeat;

      switch (z) {
        case "t":
          // Top Bar
          if (this.topContainer) {
            if (curvyBrowser.quirksMode) {
              newFillerBar.style.height = 100 + topMaxRadius + "px";
            } else {
              newFillerBar.style.height = 100 + topMaxRadius - this.borderWidth + "px";
            }
            newFillerBar.style.marginLeft  = this.spec.tlR ? (this.spec.tlR - this.borderWidthL) + "px" : "0";
            newFillerBar.style.borderTop   = this.borderString;
            if (this.backgroundImage) {
              var x_offset = this.spec.tlR ?
                (this.borderWidthL + this.backgroundPosX - this.spec.tlR) + "px " : this.backgroundPosX + "px ";
              newFillerBar.style.backgroundPosition  = x_offset + this.backgroundPosY + "px";
              // Reposition the box's background image
              this.shell.style.backgroundPosition = this.backgroundPosX + "px " + (this.backgroundPosY - topMaxRadius + this.borderWidthL) + "px";
            }
            this.topContainer.appendChild(newFillerBar);
          }
        break;
        case "b":
          if (this.bottomContainer) {
            // Bottom Bar
            if (curvyBrowser.quirksMode) {
              newFillerBar.style.height     = botMaxRadius + "px";
            } else {
              newFillerBar.style.height     = botMaxRadius - this.borderWidthB + "px";
            }
            newFillerBar.style.marginLeft   = this.spec.blR ? (this.spec.blR - this.borderWidthL) + "px" : "0";
            newFillerBar.style.borderBottom = this.borderStringB;
            if (this.backgroundImage) {
              var x_offset = this.spec.blR ?
                (this.backgroundPosX + this.borderWidthL - this.spec.blR) + "px " : this.backgroundPosX + "px ";
              newFillerBar.style.backgroundPosition = x_offset + (this.backgroundPosY - clientHeight - this.borderWidth + botMaxRadius) + "px";
            }
            this.bottomContainer.appendChild(newFillerBar);
          }
        //break;
      }
    }

    // style content container
    this.contentContainer.style.position = "absolute";
    // contentContainer.style.border = "1px dotted #000"; // DEBUG, comment for production
    this.contentContainer.className    = "autoPadDiv";
    this.contentContainer.style.left   = this.borderWidthL + "px";
    // Get padding amounts
    // Apply top padding
    this.contentContainer.style.paddingTop = this.topPadding + "px";
    this.contentContainer.style.top = this.borderWidth + "px";
    // skip bottom padding - it doesn't show!
    // Apply left and right padding
    this.contentContainer.style.paddingLeft = this.leftPadding + "px";
    this.contentContainer.style.paddingRight = this.rightPadding + "px";
    z = clientWidth;
    if (!curvyBrowser.quirksMode) z -= this.leftPadding + this.rightPadding;
    this.contentContainer.style.width = z + "px";
    this.contentContainer.style.textAlign = curvyBrowser.get_style(this.box, 'textAlign');
    this.box.style.textAlign = 'left'; // important otherwise layout goes wild

    this.box.appendChild(this.contentContainer);
    if (boxDisp) boxDisp.style.display = boxDispSave;
  };
  if (this.backgroundImage) {
    backgroundPosX = this.backgroundCheck(backgroundPosX);
    backgroundPosY = this.backgroundCheck(backgroundPosY);
    if (this.backgroundObject) {
      this.backgroundObject.holdingElement = this;
      this.dispatch = this.applyCorners;
      this.applyCorners = function() {
        if (this.backgroundObject.complete)
          this.dispatch();
        else this.backgroundObject.onload = new Function('curvyObject.dispatch(this.holdingElement);');
      };
    }
  }
}

curvyObject.prototype.backgroundCheck = function(style) {
  if (style === 'top' || style === 'left' || parseInt(style) === 0) return 0;
  if (!(/^[-\d.]+px$/.test(style))  && !this.backgroundObject) {
    this.backgroundObject = new Image;
    var imgName = function(str) {
      var matches = /url\("?([^'"]+)"?\)/.exec(str);
      return (matches ? matches[1] : str);
    };
    this.backgroundObject.src = imgName(this.backgroundImage);
  }
  return style;
};

curvyObject.dispatch = function(obj) {
  if ('dispatch' in obj)
    obj.dispatch();
  else throw obj.newError('No dispatch function');
};

// append a pixel DIV to newCorner

curvyObject.prototype.drawPixel = function(intx, inty, colour, transAmount, height, newCorner, image, cornerRadius) {
  var pixel = document.createElement("div");
  pixel.style.height   = height + "px";
  pixel.style.width    = "1px";
  pixel.style.position = "absolute";
  pixel.style.fontSize = "1px";
  pixel.style.overflow = "hidden";
  var topMaxRadius = this.spec.get('tR');
  pixel.style.backgroundColor = colour;
  // Don't apply background image to border pixels
  if (image && this.backgroundImage !== "") {
    pixel.style.backgroundImage = this.backgroundImage;
    pixel.style.backgroundPosition  = "-" + (this.boxWidth - (cornerRadius - intx) + this.borderWidth) + "px -" + ((this.boxHeight + topMaxRadius + inty) - this.borderWidth) + "px";
  }
  // Set opacity if the transparency is anything other than 100
  if (transAmount != 100) curvyObject.setOpacity(pixel, transAmount);
  // Set position
  pixel.style.top = inty + "px";
  pixel.style.left = intx + "px";
  newCorner.appendChild(pixel);
};

curvyObject.prototype.fillerWidth = function(tb) {
  var b_width, f_width;
  b_width = curvyBrowser.quirksMode ? 0 : this.spec.radiusCount(tb) * this.borderWidthL;
  if ((f_width = this.boxWidth - this.spec.radiusSum(tb) + b_width) < 0)
    throw this.newError("Radius exceeds box width");
  return f_width + 'px';
};

curvyObject.prototype.errmsg = function(msg, gravity) {
  var extradata = "\ntag: " + this.box.tagName;
  if (this.box.id) extradata += "\nid: " + this.box.id;
  if (this.box.className) extradata += "\nclass: " + this.box.className;
  var parent;
  if ((parent = this.box.parentNode) === null)
    extradata += "\n(box has no parent)";
  else {
    extradata += "\nParent tag: " + parent.tagName;
    if (parent.id) extradata += "\nParent ID: " + parent.id;
    if (parent.className) extradata += "\nParent class: " + parent.className;
  }
  if (gravity === undefined) gravity = 'warning';
  return 'curvyObject ' + gravity + ":\n" + msg + extradata;
};

curvyObject.prototype.newError = function(msg) {
  return new Error(this.errmsg(msg, 'exception'));
};

// ------------- UTILITY FUNCTIONS

//  Convert a number 0..255 to hex


curvyObject.IntToHex = function(strNum) {
  var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ];

  return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15];
};

/*
  Blends the two colours by the fraction
  returns the resulting colour as a string in the format "#FFFFFF"
*/

curvyObject.BlendColour = function(Col1, Col2, Col1Fraction) {
  if (Col1 === 'transparent' || Col2 === 'transparent') throw this.newError('Cannot blend with transparent');
  if (Col1.charAt(0) !== '#') {
    //curvyCorners.alert('Found colour1 ' + Col1 + ': please let us know you saw this report.');
    Col1 = curvyObject.format_colour(Col1);
  }
  if (Col2.charAt(0) !== '#') {
    //curvyCorners.alert('Found colour2 ' + Col2 + ': please let us know you saw this report.');
    Col2 = curvyObject.format_colour(Col2);
  }
  var red1 = parseInt(Col1.substr(1, 2), 16);
  var green1 = parseInt(Col1.substr(3, 2), 16);
  var blue1 = parseInt(Col1.substr(5, 2), 16);
  var red2 = parseInt(Col2.substr(1, 2), 16);
  var green2 = parseInt(Col2.substr(3, 2), 16);
  var blue2 = parseInt(Col2.substr(5, 2), 16);

  if (Col1Fraction > 1 || Col1Fraction < 0) Col1Fraction = 1;

  var endRed = Math.round((red1 * Col1Fraction) + (red2 * (1 - Col1Fraction)));
  if (endRed > 255) endRed = 255;
  if (endRed < 0) endRed = 0;

  var endGreen = Math.round((green1 * Col1Fraction) + (green2 * (1 - Col1Fraction)));
  if (endGreen > 255) endGreen = 255;
  if (endGreen < 0) endGreen = 0;

  var endBlue = Math.round((blue1 * Col1Fraction) + (blue2 * (1 - Col1Fraction)));
  if (endBlue > 255) endBlue = 255;
  if (endBlue < 0) endBlue = 0;

  return "#" + curvyObject.IntToHex(endRed) + curvyObject.IntToHex(endGreen)+ curvyObject.IntToHex(endBlue);
};

/*
  For a pixel cut by the line determines the fraction of the pixel on the 'inside' of the
  line.  Returns a number between 0 and 1
*/

curvyObject.pixelFraction = function(x, y, r) {
  var fraction;
  var rsquared = r * r;

  /*
    determine the co-ordinates of the two points on the perimeter of the pixel that the
    circle crosses
  */
  var xvalues = new Array(2);
  var yvalues = new Array(2);
  var point = 0;
  var whatsides = "";

  // x + 0 = Left
  var intersect = Math.sqrt(rsquared - Math.pow(x, 2));

  if (intersect >= y && intersect < (y + 1)) {
    whatsides = "Left";
    xvalues[point] = 0;
    yvalues[point] = intersect - y;
    ++point;
  }
  // y + 1 = Top
  intersect = Math.sqrt(rsquared - Math.pow(y + 1, 2));

  if (intersect >= x && intersect < (x + 1)) {
    whatsides += "Top";
    xvalues[point] = intersect - x;
    yvalues[point] = 1;
    ++point;
  }
  // x + 1 = Right
  intersect = Math.sqrt(rsquared - Math.pow(x + 1, 2));

  if (intersect >= y && intersect < (y + 1)) {
    whatsides += "Right";
    xvalues[point] = 1;
    yvalues[point] = intersect - y;
    ++point;
  }
  // y + 0 = Bottom
  intersect = Math.sqrt(rsquared - Math.pow(y, 2));

  if (intersect >= x && intersect < (x + 1)) {
    whatsides += "Bottom";
    xvalues[point] = intersect - x;
    yvalues[point] = 0;
  }

  /*
    depending on which sides of the perimeter of the pixel the circle crosses calculate the
    fraction of the pixel inside the circle
  */
  switch (whatsides) {
    case "LeftRight":
      fraction = Math.min(yvalues[0], yvalues[1]) + ((Math.max(yvalues[0], yvalues[1]) - Math.min(yvalues[0], yvalues[1])) / 2);
    break;

    case "TopRight":
      fraction = 1 - (((1 - xvalues[0]) * (1 - yvalues[1])) / 2);
    break;

    case "TopBottom":
      fraction = Math.min(xvalues[0], xvalues[1]) + ((Math.max(xvalues[0], xvalues[1]) - Math.min(xvalues[0], xvalues[1])) / 2);
    break;

    case "LeftBottom":
      fraction = yvalues[0] * xvalues[1] / 2;
    break;

    default:
      fraction = 1;
  }

  return fraction;
};

// Returns an array of rgb values

curvyObject.rgb2Array = function(rgbColour) {
  // Remove rgb()
  var rgbValues = rgbColour.substring(4, rgbColour.indexOf(")"));

  // Split RGB into array
  return rgbValues.split(/,\s*/);
};

// This function converts CSS rgb(x, x, x) to hexadecimal

curvyObject.rgb2Hex = function(rgbColour) {
  try {
    // Get array of RGB values
    var rgbArray = curvyObject.rgb2Array(rgbColour);

    // Get RGB values
    var red   = parseInt(rgbArray[0]);
    var green = parseInt(rgbArray[1]);
    var blue  = parseInt(rgbArray[2]);

    // Build hex colour code
    var hexColour = "#" + curvyObject.IntToHex(red) + curvyObject.IntToHex(green) + curvyObject.IntToHex(blue);
  }
  catch (e) {
    var msg = 'getMessage' in e ? e.getMessage() : e.message;
    throw new Error("Error (" + msg + ") converting RGB value to Hex in rgb2Hex");
  }

  return hexColour;
};

/*
  Function by Simon Willison from sitepoint.com
  Modified by Cameron Cooke adding Safari's rgba support
*/

curvyObject.setOpacity = function(obj, opacity) {
  opacity = (opacity == 100) ? 99.999 : opacity;

  if (curvyBrowser.isSafari && obj.tagName != "IFRAME") {
    // Get array of RGB values
    var rgbArray = curvyObject.rgb2Array(obj.style.backgroundColor);

    // Get RGB values
    var red   = parseInt(rgbArray[0]);
    var green = parseInt(rgbArray[1]);
    var blue  = parseInt(rgbArray[2]);

    // Safari using RGBA support
    obj.style.backgroundColor = "rgba(" + red + ", " + green + ", " + blue + ", " + opacity/100 + ")";
  }
  else if (typeof obj.style.opacity !== "undefined") { // W3C
    obj.style.opacity = opacity / 100;
  }
  else if (typeof obj.style.MozOpacity !== "undefined") { // Older Mozilla
    obj.style.MozOpacity = opacity / 100;
  }
  else if (typeof obj.style.filter !== "undefined") { // IE
    obj.style.filter = "alpha(opacity=" + opacity + ")";
  }
  else if (typeof obj.style.KHTMLOpacity !== "undefined") { // Older KHTML-based browsers
    obj.style.KHTMLOpacity = opacity / 100;
  }
};


// Cross browser add event wrapper

curvyCorners.addEvent = function(elm, evType, fn, useCapture) {
  if (elm.addEventListener) {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  }
  if (elm.attachEvent) return elm.attachEvent('on' + evType, fn);
  elm['on' + evType] = fn;
  return false;
};
if (typeof addEvent === 'undefined') addEvent = curvyCorners.addEvent; // only if necessary

// Gets the computed colour.
curvyObject.getComputedColour = function(colour) {
  var d = document.createElement('DIV');
  d.style.backgroundColor = colour;
  document.body.appendChild(d);

  if (window.getComputedStyle) { // Mozilla, Opera, Chrome, Safari
    var rtn = document.defaultView.getComputedStyle(d, null).getPropertyValue('background-color');
    d.parentNode.removeChild(d);
    if (rtn.substr(0, 3) === "rgb") rtn = curvyObject.rgb2Hex(rtn);
    return rtn;
  }
  else { // IE
    var rng = document.body.createTextRange();
    rng.moveToElementText(d);
    rng.execCommand('ForeColor', false, colour);
    var iClr = rng.queryCommandValue('ForeColor');
    var rgb = "rgb("+(iClr & 0xFF)+", "+((iClr & 0xFF00)>>8)+", "+((iClr & 0xFF0000)>>16)+")";
    d.parentNode.removeChild(d);
    rng = null;
    return curvyObject.rgb2Hex(rgb);
  }
};

// convert colour name, rgb() and #RGB to #RRGGBB
curvyObject.format_colour = function(colour) {
  // Make sure colour is set and not transparent
  if (colour !== "" && colour !== "transparent") {
    // RGB Value?
    if (colour.substr(0, 3) === "rgb") {
      // Get HEX aquiv.
      colour = curvyObject.rgb2Hex(colour);
    }
    else if (colour.charAt(0) !== '#') {
      // Convert colour name to hex value
      colour = curvyObject.getComputedColour(colour);
    }
    else if (colour.length === 4) {
      // 3 chr colour code add remainder
      colour = "#" + colour.charAt(1) + colour.charAt(1) + colour.charAt(2) + colour.charAt(2) + colour.charAt(3) + colour.charAt(3);
    }
  }
  return colour;
};

// Get elements by class by Dustin Diaz / CPKS
// NB if searchClass is a class name, it MUST be preceded by '.'

curvyCorners.getElementsByClass = function(searchClass, node) {
  var classElements = new Array;
  if (node === undefined) node = document;
  searchClass = searchClass.split('.'); // see if there's a tag in there
  var tag = '*'; // prepare for no tag
  if (searchClass.length === 1) {
    tag = searchClass[0];
    searchClass = false;
  }
  else {
    if (searchClass[0]) tag = searchClass[0];
    searchClass = searchClass[1];
  }
  var i, els, elsLen;
  if (tag.charAt(0) === '#') {
    els = document.getElementById(tag.substr(1));
    if (els) classElements.push(els);
  }
  else {
    els = node.getElementsByTagName(tag);
    elsLen = els.length;
    if (searchClass) {
      var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
      for (i = 0; i < elsLen; ++i) {
        if (pattern.test(els[i].className)) classElements.push(els[i]);
      }
    }
    else for (i = 0; i < elsLen; ++i) classElements.push(els[i]);
  }
  return classElements;
};

curvyCorners.getElementsBySelector = function(selectors, parent) {
  var ret;
  var sel = selectors[0];
  if (parent === undefined) parent = document;
  if (sel.indexOf('#') === -1)
    ret = curvyCorners.getElementsByClass(sel, parent);
  else {
    var t = parent.getElementById(sel.substr(1));
    if (!t) return [];
    ret = [t];
  }
  if (selectors.length > 1) {
    var subret = [];
    for (var i = ret.length; --i >= 0; )
      subret = subret.concat(curvyCorners.getElementsBySelector(selectors.slice(1), ret[i]));
    ret = subret;
  }
  return ret;
};

if (curvyBrowser.supportsCorners) {
  var curvyCornersNoAutoScan = true; // it won't do anything anyway.
  curvyCorners.init = function() {}; // make it harmless
}
else {

  // autoscan code

  curvyCorners.scanStyles = function() {
    function units(num) {
      if (!parseInt(num)) return 'px'; // '0' becomes '0px' for simplicity's sake
      var matches = /^[\d.]+(\w+)$/.exec(num);
      return matches[1];
    }
    var t, i, j;

    if (curvyBrowser.isIE) {
      function procIEStyles(rule) {
        var style = rule.style, allR, tR, tL, bR, bL;

        if (curvyBrowser.ieVer > 6.0) {
          allR = style['-moz-border-radius'] || 0;
          tR   = style['-moz-border-radius-topright'] || 0;
          tL   = style['-moz-border-radius-topleft'] || 0;
          bR   = style['-moz-border-radius-bottomright'] || 0;
          bL   = style['-moz-border-radius-bottomleft'] || 0;
        }
        else {
          allR = style['moz-border-radius'] || 0;
          tR   = style['moz-border-radius-topright'] || 0;
          tL   = style['moz-border-radius-topleft'] || 0;
          bR   = style['moz-border-radius-bottomright'] || 0;
          bL   = style['moz-border-radius-bottomleft'] || 0;
        }
        if (allR) {
          var t = allR.split('/'); // ignore elliptical spec.
          t = t[0].split(/\s+/);
          if (t[t.length - 1] === '') t.pop();
          switch (t.length) {
            case 3:
              tL = t[0];
              tR = bL = t[1];
              bR = t[2];
              allR = false;
            break;
            case 2:
              tL = bR = t[0];
              tR = bL = t[1];
              allR = false;
            case 1:
            break;
            case 4:
              tL = t[0];
              tR = t[1];
              bR = t[2];
              bL = t[3];
              allR = false;
            break;
            default:
              curvyCorners.alert('Illegal corners specification: ' + allR);
            //break;
          }
        }
        if (allR || tL || tR || bR || bL) {
          var settings = new curvyCnrSpec(rule.selectorText);
          if (allR)
            settings.setcorner(null, null, parseInt(allR), units(allR));
          else {
            if (tR) settings.setcorner('t', 'r', parseInt(tR), units(tR));
            if (tL) settings.setcorner('t', 'l', parseInt(tL), units(tL));
            if (bL) settings.setcorner('b', 'l', parseInt(bL), units(bL));
            if (bR) settings.setcorner('b', 'r', parseInt(bR), units(bR));
          }
          curvyCorners(settings);
        }
      }
      for (t = 0; t < document.styleSheets.length; ++t) {
        try {
          if (document.styleSheets[t].imports) {
            for (i = 0; i < document.styleSheets[t].imports.length; ++i)
              for (j = 0; j < document.styleSheets[t].imports[i].rules.length; ++j)
                procIEStyles(document.styleSheets[t].imports[i].rules[j]);
          }
          for (i = 0; i < document.styleSheets[t].rules.length; ++i)
            procIEStyles(document.styleSheets[t].rules[i]);
        }
        catch (e) {
          if (typeof curvyCornersVerbose !== 'undefined' && curvyCornersVerbose)
            alert(e.message + " - ignored");
        } // catch but ignore any permission error
      }
    }
    else if (curvyBrowser.isOp) {
      for (t = 0; t < document.styleSheets.length; ++t) {
        if (operasheet.contains_border_radius(t)) {
          j = new operasheet(t);
          for (i in j.rules) if (!isNaN(i))
            curvyCorners(j.rules[i]);
        }
      }
    }
    else curvyCorners.alert('Scanstyles does nothing in Webkit/Firefox/Opera');
  };

  // Dean Edwards/Matthias Miller/John Resig

  curvyCorners.init = function() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (curvyBrowser.isWebKit && curvyCorners.init.timer) {
      clearInterval(curvyCorners.init.timer);
      curvyCorners.init.timer = null;
    }

    // do stuff
    curvyCorners.scanStyles();
  };
}

if (typeof curvyCornersNoAutoScan === 'undefined' || curvyCornersNoAutoScan === false) {
  if (curvyBrowser.isOp)
    document.addEventListener("DOMContentLoaded", curvyCorners.init, false);
  else curvyCorners.addEvent(window, 'load', curvyCorners.init, false);
}

/**
 * 窗口显示类
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */
Ext.apply(Ext.ns("ssh"), {
    Window: Ext.extend(function(config){
    	/* config:数据格式 {id:"", title:"", html:"",isCache:是否缓存, renderTo:呈现对象, format:"", url:"", params:{}, bind:function(){}}
    	 * id：窗口编号（可选项） title:窗口标题 html：窗口内容（与url不可同时使用只能传其一） format:数据格式(text,json)  url:链接地址 params：参数信息 bind:绑定方法 
    	*/
        this.config = config || {}; 
        // 初始化窗口
        this.init();
    }, {
    	init: function(){ 		
        	var me = this;    		
        	this.config['handle'] = this;      
        	this.config['isCache'] = Ext.isEmpty(this.config['isCache']) ? false : this.config['isCache']; 
        	this.config['isMask'] = Ext.isEmpty(this.config['isMask']) ? true : this.config['isMask'];
        	this.config['isFixed'] = Ext.isEmpty(this.config['isFixed']) ? false : this.config['isFixed'];        	
        	this.config['bind'] = this.config['bind'] || function(){};
        	this.config['cls'] = this.config['cls'] || 'window-gray'; 
        	this.config['style'] = this.config['style'] || 'flat';

        	var html = Ext.isEmpty(this.config['html']) ? '' :  this.config['html'];
    		var windowTpl = new Ext.Template(this.getTemplate());
    		this.handle = windowTpl.append(Ext.getBody(), { 
    						cls:this.config['cls'],
	            			title:this.config.title, 
	            			html:html}, 
            			true); 
            			
        	this.content = this.handle.child(".window-content");   
            this.handle.id = Ext.isEmpty(this.config['id']) ? this.handle.id : this.config['id'];
            this.inner = this.handle.child('.window-inner');  
            this.btnHeader = this.handle.child('.window-header');            
            this.btnClose = this.handle.child('.window-close');

            this.footer  = this.handle.child('.window-footer');
            
            this.buttons = this.config.buttons || [];
            
            if(this.buttons.length == 0)
            {
            	this.footer.setStyle('display', 'none');            
            }else
            {            
	            for(var i=0; i<this.buttons.length; i++)
	            {            	
	            	var id = this.buttons[i].id || Ext.id();
	            	var type = this.buttons[i].type;
	            	var text = this.buttons[i].text;
	            	var button = this.footer.createChild({tag:'a',cls:'window-button', id:id, href:'javascript:;',html:text});
					if(!Ext.isEmpty(this.buttons[i].callback))
					{
						this.buttons[i].callback(button, this);						
					}
					
					
					if(type == 'close')
	            	{
	            		button.on('click', function(e) {
	            			e.preventDefault(); 
	            			me.cancel();
						});            	
	            	}               	
	            	
	            	
	            }
            }           
            
            // 退出键
            if(this.config['isMask'] )
            {            	
            	   if(Ext.isIE)
            	   {            	   
	            	  Ext.get(window).on('keyup', function(e, t) {
							if(e. getCharCode() == 27 && !Ext.isEmpty(me.handle))
							{								
								me.cancel();
							}						
						});     
            	   }else
            	   {
	            	  Ext.fly(window).on('keyup', function(e, t) {
							if(e. getCharCode() == 27 && !Ext.isEmpty(me.handle))
							{
								me.cancel();
							}						
						});              	   
            	   }
       	
            }
            
            // 窗口风格
		  	this.style();
			// 绑定窗口
            this.bind();
			if(!Ext.isEmpty(this.config['renderTo']))
			{
				this.content.appendChild(Ext.get(this.config['renderTo'])); 			
			}else if(!Ext.isEmpty(this.config.url))
            {                 
	            this.content.addClass('loading');		            
				this.inner.slideIn('t',{duration: .2, useDisplay: true, callback:function(){			
	                Ext.Ajax.request({
		                url: me.config.url,
		                async: true,
		                params: me.config.params,
		                form: me.config.form,
		                success: function(response, opts){
		                	try
		                	{
		                		if(Ext.isEmpty(me.handle)){return;}
			                	me.content.removeClass('loading');		
			                	me.inner.setStyle('visibility', '');
			                	
			                	var result = response.responseText;;
			                	if(me.config.format == 'json')
			                	{
			                		result = Ext.decode(result).html;
			                	}
			                	me.fill(result);	  
		                        // 绑定内容
	            				me.config.bind();
	            				// 窗口居中
					        	if(Ext.isEmpty(me.config['left']) &&  Ext.isEmpty(me.config['top']))
					        	{	            				
						            me.center();
					        	}
		                	}catch(e)
		                	{
		                		
		                	
		                	}
		                },
		                failure: function(response, opts){
		                	me.content.removeClass('loading');
		                	alert('服务端失效的状态代码：' + response.status);
		                }
		            });					
					
					
				}}); 	            
            }else
            {
                // 绑定内容
				this.config.bind();
            }
            
            this.mask(); 
    	},
    	style: function() {
		   
            if(this.config['style'] == '3d' && Ext.isIE6)
            {   //修正ie6 PNG问题
            	this.fixIE6Png();
            }else if(this.config['style'] == 'nonTitleBar')
            {
            	this.btnHeader.setStyle('display', 'none');
            }      		
    	},
        bind: function(){
        	var me=this;
			if(Ext.isBorderBox || Ext.isIE7 || Ext.isIE6) {        	
				ssh.util.iframe(this.handle);        	
			}
			
        	if(!Ext.isEmpty(this.config['left']) &&  !Ext.isEmpty(this.config['top']))
        	{
        		this.moveTo(this.config['left'], this.config['top']);
        	}else
        	{
        		this.center();
        	}
        	
        	if(!Ext.isEmpty(this.config['width']))
        	{
        		this.setWidth(this.config['width']);
        	}   
        	
        	if(!Ext.isEmpty(this.config['height']))
        	{
        		this.setHeight(this.config['height']);
        	}          	
        	
        	
            this.btnClose.on('mousedown', function(e){ 
                $cancelBubble(e);        
                $cancelDefualt(e);
            });          
			
            this.btnClose.on('mouseup', function(e){
            	if(me.config['isCache'])
            	{
            		me.hide();
            	}else
            	{            	
            		me.close();
            	}
            });              


            this.btnHeader.on('selectstart', function(e){ 
            	$cancelBubble(e);        
                $cancelDefualt(e); 
                return false;     
            });             
            
            // 窗口拖放
            (function(o, m, s, x, y, d){
                s = m.style;
                d = document;
                o.onselectstart = function(){
                    return false;
                }; // 阻止选择
                o.onmousedown = function(e){
					o.focus();
                    e = e || event;
                    x = e.clientX - m.offsetLeft;
                    y = e.clientY - m.offsetTop;
                    d.onmousemove = function(e){
                        e = e || event;
                        s.left = e.clientX - x + "px";
                        s.top = e.clientY - y + "px";
                        
                        me.topOffset = me.handle.getTop() - (document.documentElement.scrollTop || document.body.scrollTop);
                    }
                    d.onmouseup = function(){
                        d.onmouseup = d.onmousemove = "";
                    }
                }
            })(this.btnHeader.dom, this.handle.dom);		
       
            if(this.config['isFixed'])
            {
				if(Ext.isIE6)
				{			
					me.handle.setStyle('position', 'absolute');						
					me.topOffset = me.handle.getTop() - (document.documentElement.scrollTop || document.body.scrollTop);
	            	Ext.fly(window).on('scroll',function(e){
	            		var scrollTop = (document.documentElement.scrollTop || document.body.scrollTop);
	            		var top = scrollTop + me.topOffset;
	            		if(me.handle)
	            		{
		            		me.handle.setTop(top);
	            		}
					}); 
				}
				else
				{
					me.handle.setStyle('position', 'fixed');		
				}            	
            }
            
        },
		/**
		 * 修正IE6 png图片
		 */
		fixIE6Png: function()
		{
			try
			{
	            try {
	                document.execCommand("BackgroundImageCache", false, true); /* TredoSoft Multiple IE doesn't like this, so try{} it */
	            } catch(r) {}
	            ssh.util.DD_belatedPNG.createVmlNameSpace();
	            ssh.util.DD_belatedPNG.createVmlStyleSheet();  	
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-mdl_t_l').dom); 
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-mdl_t_r').dom);				
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-mdl_b_l').dom);				
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-mdl_b_r').dom);			
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-mdl_t_c').dom);
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-mdl_b_c').dom);
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-mdl_c').dom);
				ssh.util.DD_belatedPNG.fixPng(this.handle.child('.window-close').dom);
			}catch(e)
			{
				alert(e);
			}
		},		        
        getTemplate: function() {        	
        	if(this.config['style'] == 'flat' || this.config['style'] == 'nonTitleBar')
        	{
	            return [
						'<div class="{cls}">', 
							'<div class="window-border">',
								'<div class="window-header">',
									'<em>{title}</em>',
					    			'<a class="window-close" href="javascript:;"></a>',
								'</div>',
								'<div class="window-inner">',
									'<div class="window-content">',
										'{html}',
									'</div>',
									'<div class="window-footer">',
									'</div>',									
								'</div>',
							'</div>',
						'</div>'
	            ];          		
        	}else
        	{
	            return [
						'<div class="{cls}">', 
							'<div class="window-mdl_t">',
								'<div class="window-mdl_t_l">',
									'<div class="window-mdl_t_r">',
										'<div class="window-mdl_t_c"></div>',								
									'</div>',
								'</div>',
					        '</div>',
							'<div class="window-mdl_c">',
								'<div class="window-header">',
									'<em>{title}</em>',
					    			'<a class="window-close" href="javascript:;"></a>',
								'</div>',
								'<div class="window-inner">',
									'<div class="window-content">',
										'{html}',
									'</div>',
									'<div class="window-footer">',
									'</div>',									
								'</div>',												
							'</div>',					
						    '<div class="window-mdl_b">',
								'<div class="window-mdl_b_l">',
									'<div class="window-mdl_b_r">',
										'<div class="window-mdl_b_c"></div>',	
									'</div>',							
								'</div>',
						    '</div>', 
						'</div>'
	            ];        	
        	
        	}
        },        
        bindAll: function(){
            // 绑定窗口
            this.bind();
            // 绑定内容
            this.config.bind();
        },
        fill: function(info)
        {
            this.content.update(info);
        },
        center: function()
        {        	
        	var scrollTop = Ext.getBody().getScroll().top;
        	var scrollLeft = Ext.getBody().getScroll().left;
        	
        	var areaWidth =  document.documentElement.clientWidth || Ext.getBody().dom.clientWidth;
        	var areaHeight = document.documentElement.clientHeight || Ext.getBody().dom.clientHeight;
        	
        	var displayWidth = this.handle.dom.clientWidth;
        	var displayHeight = this.handle.dom.clientHeight;

        	
            var top = (areaHeight > displayHeight 
            		  ? (areaHeight - displayHeight) / 2 
            		  :0) + scrollTop;   

        	var left = (areaWidth > displayWidth
            		  ? (areaWidth - displayWidth) / 2 
            		  :0) + scrollLeft;

            this.handle.moveTo(left, top);   
        },
        setWidth: function(width)
        {
        	this.handle.setWidth(width);
        	
        },
        setHeight: function(height)
        {
        	this.handle.setHeight(height);
        },
        
        /**
         * 设定窗口
         */
        setSize: function(width, height) {        
        	this.setWidth(width);
        	this.setHeight(height);
        },
        /**
         * 移动窗口
         * @param {} left
         * @param {} top
         */
        moveTo: function(left, top) {
			this.handle.moveTo(left, top);   
        },
        /**
         * 显示窗口
         */
        show: function(){
			this.mask();         	
            this.handle.show();
        },
        /**
         * 关闭窗口
         */
        close: function(){        
        	this.unmask();
			this.handle.remove();
			this.handle = null;		
			if(!Ext.isEmpty(this.config['callbackClose']))
			{
				this.config['callbackClose']();
			}			
        },
        /**
         * 隐藏窗口
         */
        hide: function(){
			this.unmask();        	
        	this.handle.hide();
        },
        cancel: function() {
        	if(this.config['isCache'])
        	{
        		this.hide();
        	}else
        	{            	
        		this.close();
        	}        
        },
        mask: function() {
        	if(!Ext.isEmpty(this.maskEl))
        	{
        		return;
        	}        	
			if(this.config['isMask'] == true)
			{

				if(Ext.isBorderBox || Ext.isIE7 || Ext.isIE6) {    
					this.iframe = ssh.util.iframe(Ext.getBody());   
					this.iframe.setStyle('z-index', 19998);
				}


	        	this.maskEl = Ext.getBody().createChild({
	        		tag:'div',
	        		cls:'window-mask'        	
	        	})   
	        	this.maskEl.setOpacity(0.2);
	            this.maskEl.on('selectstart', function(e){ 
	            	$cancelBubble(e);        
	                $cancelDefualt(e); 
	                return false;     
	            });     	        	
	        	var me = this;
	            window.onresize = function(){
	            	me.setMaskSize();
	            	
	            };			
	            me.setMaskSize();
	        }

        },
        unmask: function() {      	
        	if(!Ext.isEmpty(this.maskEl))
        	{
        		this.maskEl.remove();
        		this.maskEl = null;
        	}
        	
        	if(!Ext.isEmpty(this.iframe))
        	{
        		this.iframe.remove();
        		this.iframe = null;
        	}    
        	window.onresize = null;
        },
        setMaskSize: function()
        {
           var dsh=document.documentElement.scrollHeight || document.body.scrollHeight;
           var dch=document.documentElement.clientHeight || document.body.clientHeight;
           var dsw=document.documentElement.scrollWidth || document.body.scrollWidth;
           var dcw=document.documentElement.clientWidth || document.body.clientWidth;        	
     	   var bdh=(dsh>dch)?dsh:dch;
           var bdw=(dsw>dcw)?dsw:dcw;

           this.maskEl.setWidth(bdw);
           this.maskEl.setHeight(bdh);  
        }
    })
});
/**
 *表格控件
 */
Ext.ns('ssh.grid');



ssh.grid.GridPanel = Ext.extend(Ext.util.Observable, {
    // 列数
    columnCount: 0,
    // 表格显示最大行数
    rows: 10,
    // 是否显示列头
    hideHeaders: false,
    // 是否自动加载数据
    autoLoad: true,
    // 表格列数组(tr)
    rowElements: undefined,
    // 表格单元二维数组(td)
    cells: undefined,
    // 同步处理函数
    nextDo: undefined,
    // 选取样式
    selectedCls: undefined,
    // 全局信息区id
    infoPanel: undefined,
    // 是否返回html
    responseType: 'json',
    //ajax请求使用的参数。
    params:{},
    page: undefined,
    table: undefined,
    // 翻页中间按钮个数
    maxIndex: 11,
    //是否显示首尾按钮
    showFLBtn:false,
    //是否显示上下页按钮
    showUDBtn:true,
    //是否显示页码号
    showNumBtn:true,
    //是否显示跳转按钮
    showGoto:false,
    //按钮主题
    btnTheme:'bigBtn',
    //空字符串
    emptyString:"",
    //页码停靠位置
    numparent:null,
    numparentid:null,
    //是否在页面=1的时候，隐藏翻页按钮
    isHiddenBtn:true,
    // 是否显示读取页面
    isLoading:false,
    /**
     * 构造函数，初始表格环境 参数dgConfig为一个对象直接量
     * @param {String} url 翻页控制器
     * @param {String} form 查询表单的id
     * @param {String} parent 依赖的父节点id
     * @param {int} row 行数
     * @param {Object} dsConfig 数据集对象{captions:[],filedNames[]}
     */
    constructor: function(config){
        Ext.apply(this, config);
        
        if(!this.maxIndex) {
            this.maxIndex = 11;
        } else {
            if (this.maxIndex % 2 ==0) {
                this.maxIndex++;
            }
        }
        
        // 得到父面板
        this.panel = Ext.get(this.renderTo);
        if(this.columns){
        	this.columnCount = this.columns.length;
        }
        if (this.responseType == 'json') {
        	this.createTable();
        } else {
        	if (Ext.isEmpty(this.table)) {
		        this.table = this.panel.createChild({
		           tag: "div"
		        });
	        }
        }
        //old代码
        //this.createIndexPanel();
        
        if (this.autoLoad) {
            this.load();
        }
    },
    
    /**
     * 创建表格行
     * @param {Object} parent
     * @param {Object} cls
     */
    createRow: function(parent, cls, number){
        var row = parent.dom.insertRow(number);
        var extRow = Ext.get(row);
        extRow.addClass(cls);
        return extRow;
    },
    /**
     * 创建表头单元格标记 th
     * @param {Object} parent
     * @param {Object} name
     * @param {Object} cls
     */
    createTH: function(parent, name, cls, width){
        var th = document.createElement("th");
        th.innerHTML = name;
        var extTH = Ext.get(th);
        parent.appendChild(extTH);
        
        if (!Ext.isEmpty(cls)){
            extTH.addClass(cls);
        }
        
        if (!Ext.isEmpty(width)){
            extTH.setWidth(width);
        }
        
        return extTH;
    },
    
    /**
     * 创建表格
     * @param {Object} parent
     * @param {Object} filedName
     * @param {Object} cls
     */
    createCel: function(parent,fieldName,cls,number){
        var cel = parent.dom.insertCell(number);
        var extCel = Ext.get(cel);
        if (cls != "") {
            extCel.addClass(cls);
        }
        extCel.fieldName = fieldName;
        return extCel;
    },
    
    /**
     * 初始化表格
     */
    createTable: function(){
        this.table = this.panel.createChild({ tag: "table" });
        
        // 创建thead节点
        if (!this.hideHeaders) {
	        var head = Ext.get(this.table.dom.createTHead());
	        if(!this.headCls){
	            this.headCls = "";
	        }
	        var row = this.createRow(head,this.headCls,0);
	        for(var i=0; i< this.columnCount; i++){
	            var column = this.columns[i];
                this.createTH(row, column.header, column.headCls, column.width);
	        }
        }
        
        // 创建tbody的节点
        var tBody = this.table.createChild({ tag:"tbody" });
        this.rowElements = new Array(this.rows);
        this.cells = new Array(this.rows);
        
        var rowCls = "";
        for(var i = 0; i < this.rows; i++){
            if((i + 1) % 2 == 0) {
                rowCls = "drak";
            } else {
                rowCls = "light";
            }           
            
            var row = this.createRow(tBody, rowCls, i);
              if(this.selectedCls){
        		var obj = this;
           		row.on("mouseover",function(e,t){
           			if(obj.selectedRow){
           				obj.selectedRow.removeClass(obj.selectedCls);
           			}
           			obj.selectedRow = this;
           			obj.selectedRow.addClass(obj.selectedCls);
              		//obj.selectedRow.dom.className =  obj.selectedCls+" " +obj.selectedRow.dom.className;
           		});
           		row.on("mouseout",function(e,t){
           			if(obj.selectedRow){
           				obj.selectedRow.removeClass(obj.selectedCls);
           			}
           		});
        	}
            
            var cellsContext = new Array(this.columnCount);
            
            for(var j = 0; j < this.columnCount; j++){
                var celCls = "";
                if(this.columns[j].cls){
                    celCls = this.columns[j].cls;
                }
                cellsContext[j] = this.createCel(row, this.columns[j].dataIndex, celCls, j);
            }
            
            this.rowElements[i] = row;
            this.cells[i] = cellsContext;
        }
    },

    /**
     * 创建翻页工具条panel
     */
    createIndexPanel: function(){
        var obj = this;
		if(Ext.isEmpty(this.numparentid)){
		  this.numparent = this.panel;
		}else{
		   this.numparent = Ext.get(this.numparentid);
		}
        var tdObj = this.numparent.createChild({
           tag: "div",
           cls: "toolbar"
        });
        
        this.indexPanel = tdObj.createChild({
           tag: "ul"
        });
        
        function createBtn(label, cls, eventHandel){
            var btn = obj.indexPanel.createChild({
                tag: 'li',
                cls: cls
            });
            
//            btn.setStyle("display", "none");
            btn.on("click", eventHandel);
            btn.unable = function(val){
                if(!val){
                    val = label;
                }
                btn.dom.innerHTML = "<span>"+val+"</span>"
            }
            btn.enable = function(val){
                if(!val){
                    val = label;
                }
                btn.dom.innerHTML = "<a href='javascript:;'><span>" + val + "</span></a>"
            }
            return btn;
        }   
        
        this.firstBtn = createBtn(this.btnCaption[this.btnTheme].firstBtn, "pager_text", function(e,t){
            if(obj.page.currentPage/1 > 1){
                obj.page.currentPage=1;
                obj.load();
            }
        });
      
        this.upBtn = createBtn(this.btnCaption[this.btnTheme].upBtn, "pager_text", function(e,t){
                if(obj.page.currentPage/1 > 1){
                    obj.page.currentPage--;
                    obj.load();
                }
        });
  
        this.pageIndex = new Array(); 
        if(this.showNumBtn){
	        for(var i = 1; i < this.maxIndex + 1; i++){
	            var label = i;
	            var index = createBtn(i, "pager_text", function(e,t){
	                if(obj.page.currentPage / 1 != this.value / 1){
	                    obj.page.currentPage = this.value;
	                    obj.load();
	                }
	            });
	            index.value = i;
	            index.enable();
	            obj.pageIndex[i-1] = index;
	        }
  		}
  		
        this.nextBtn =createBtn(this.btnCaption[this.btnTheme].nextBtn, "pager_text", function(e,t){
            if(obj.page.currentPage/1 < obj.page.totalPages/1){
                obj.page.currentPage++;
                obj.load();
            }
        });
    
        this.lastBtn = createBtn(this.btnCaption[this.btnTheme].lastBtn, "pager_text", function(e,t){
            if(obj.page.currentPage/1 < obj.page.totalPages/1){
                obj.page.currentPage=obj.page.totalPages;
                obj.load();
            }
        });
        

        //html:"到第<input type='text' value='1' class='pager_input'>页"
        var btn1 = obj.indexPanel.createChild({
             tag: 'li',
             html: '<span>转到</span>',
             cls: 'page_goto'
        });
       
        this.pageNum = btn1.createChild({
            tag:'input',
            cls:'pager_input',
            type:'text',
            size:'2',
            value:'1'
        });
        
        var regEx = /^\d+$/;
        
        this.pageNum.on("blur",function(){
            if(!regEx.test(this.getValue())){
                alert("只能输入数字");
                this.dom.value="";
                this.focus();
            }
        })
        
        btn1.createChild({
                    tag:'span',
                    html:'页'
        });
        
         
        	
        
            var btn2 = obj.indexPanel.createChild({
                    tag:'li',
                    cls:'pager_text pager_sure',
                    html:"<a href='javascript:;'><span>"+this.btnCaption[this.btnTheme].sureBtn+"</span></a>"
            });
            btn2.on("click",function(){
            var num = obj.pageNum.getValue();
            if(regEx.test(num)){
                num = num / 1;
                if(num >obj.page.totalPages){
                    obj.page.currentPage=obj.page.totalPages
                }else if(num<1){
                    obj.page.currentPage =1;
                }else{
                    obj.page.currentPage = num;
                }
                obj.pageNum.dom.value = obj.page.currentPage;
                obj.load();
            }
        });
      if(!obj.showGoto){ 
          btn1.setStyle("display","none");
      	  btn2.setStyle("display","none");
       }
    },

    /**
    * 提交请求，获取数据
    */
    load: function(config){
        var obj = this;
        if(!obj.page) {
          obj.page = {
            currentPage: 1,
            pageResults: obj.rows
          }
        }
        
        if (!Ext.isEmpty(config)) {
	    	obj.params.op = null; // 清除操作标记，避免重复执行
	        Ext.apply(obj.params, config);
        }
        if(this.isLoading == true){
        	var center = Ext.fly(this.renderTo).createChild({
	     		tag: 'center',
	     		cls: 'grid'
	     	});
	        var ts = center.createChild({
	        	tag: 'div',
	        	name: '123',
	        	cls: 'load'
	        });
        }
        var me = this;
        
        // 异步请求数据
        ssh.Ajax.request({
            url: obj.url,
            infoPanel: obj.infoPanel,
            form: obj.form,
            params: function(){
            	return Ext.applyIf({
               		currentPage: obj.page.currentPage,
               		pageResults: obj.rows
            	}, 
            	obj.params
            )},
            success: function(response, opts){
            	if(me.isLoading == true){
            		center.setStyle('display', 'none');
            	}
		    	obj.params.op = null; // 清除操作标记，避免重复执行
            	if (obj.responseType == 'json') {
	                obj.fillData(response.data);
            	} else {
            		obj.table.dom.innerHTML ="";
	    			obj.indexPanelFlag = Ext.get(obj.numparentid)||false;
            		obj.table.dom.innerHTML = response;
//            		obj.page.currentPage = Ext.fly(obj.renderTo + '_currentPage').getValue(true);
//            		obj.page.totalResults = Ext.fly(obj.renderTo + '_totalResults').getValue(true);
            		obj.page.totalPages = Ext.fly(obj.renderTo + '_totalPages').getValue(true);
            		if (obj.page.currentPage > 1 && obj.page.currentPage > obj.page.totalPages) {
            			obj.page.currentPage = obj.page.totalPages - 1;
            		}
            		obj.fillData(obj.page);
                }
                if(obj.nextDo){
                	if(obj.nextDo.params){
                		obj.nextDo.handel.apply(obj,obj.nextDo.params);
                	}else{
                		obj.nextDo.handel.apply(obj);
                	}
                }
            },
            failure: function(response, opts){
		    	obj.params.op = null; // 清除操作标记，避免重复执行
    	
//                alert("请求发生异常");
            }
        }, obj.responseType);
    },
    /**
    *刷新数据
    */
    fillData: function(page) {
     	var obj = this;
        obj.page = page;
        
        if(Ext.isEmpty(this.indexPanel) ||  (!Ext.isEmpty(obj.numparentid) && !this.indexPanelFlag)){
        	this.createIndexPanel();
        }
        if(obj.page.totalPages<=0){
         	obj.indexPanel.setStyle("display","none");
		    if(!Ext.isEmpty(this.emptyString) || this.emptyString != ''){
		    	obj.table.dom.innerHTML = this.emptyString;
		    }
        }
        
	    var result = page.results;
        if (result) {
		    var resultLen = 0;
	        if (Ext.isArray(result)) {
	         	resultLen = result.length;
	        }
	        
			for(var i = 0; i < obj.cells.length; i++){
	           var row = obj.rowElements[i];
		       if(resultLen > i){
		          for(var j = 0; j< obj.columnCount; j++){
		             var cel = obj.cells[i][j];
		             var value = result[i][cel.fieldName];
		                    
		             var render = obj.columns[j].render;
		             if (Ext.isEmpty(render)) {
		                if (Ext.isEmpty(value)) {
		                   cel.dom.innerHTML = "";
		                } else {
		                   cel.dom.innerHTML = value;
		                }
		            } else {
		                cel.dom.innerHTML = render(value, i+1, result[i]);
		            }
		     	}
	            row.setStyle("display","");
		      } else {
		          for(var j = 0; j < obj.columnCount; j++){
		           	var cel = obj.cells[i][j];
		          	cel.dom.innerHTML = "";
		          }
	              row.setStyle("display","none");
		      }
		    }
	    }
	    obj.pageNum.dom.value = obj.page.currentPage;
	   if(obj.isHiddenBtn && obj.page.totalPages<=1){
	   		obj.indexPanel.setStyle("display","none")
	   }else{ 
	   		obj.indexPanel.setStyle("display","")
	   		if(obj.showNumBtn){
	        	obj._showNum();
	        }else{
	        	obj._hideNum();
	        }
	        obj._showControlBtn();
	   	}
	},
    
    /**
    *显示页码编号
    */
    _showNum: function(){
        var obj = this;
        var step = (this.maxIndex-1)/2
        var first = obj.page.currentPage/1 - step;
        var last = obj.page.currentPage/1 +step;
        
        if(first/1<1) {
            last = last/1 - first/1;
            first = 1;
            if(last/1 > obj.page.totalPages/1){
                last = obj.page.totalPages;
            }
        }
        if(last/1 > obj.page.totalPages/1){
            first =obj.page.currentPage/1 -(this.maxIndex-1)+(obj.page.totalPages/1-obj.page.currentPage/1);
            last = obj.page.totalPages;
            if(first/1<1) {
                first =1;
            }
        }
        for(var i=0; i < this.maxIndex ;i++){
            var index = first/1+i/1;
            if(index > last/1){
                obj.pageIndex[i].setStyle("display","none");
            }else{
                obj.pageIndex[i].enable(index);
                obj.pageIndex[i].value= index;
                obj.pageIndex[i].setStyle("display","");
                if(index/1 == obj.page.currentPage/1){
                    obj.pageIndex[i].addClass("pager_foc");
                    obj.pageIndex[i].unable(index);
                }else{
                    obj.pageIndex[i].removeClass("pager_foc");
                }
            }
        }
    },
    /**
    *隐藏页码编号
    */
    _hideNum:function(){
    	if(this.pageIndex.length>0){
	    	for(var i=0; i < this.maxIndex ;i++){
	    		 this.pageIndex[i].setStyle("display","none");
	    	}
	    }
    
    },
    _showFLBtn:function(){
    	this.firstBtn.setStyle("display","");
        this.lastBtn.setStyle("display","");
    },
    _hideFLBtn:function(){
    	this.firstBtn.setStyle("display","none");
        this.lastBtn.setStyle("display","none");
    },
    _showUDBtn:function(){
    	this.upBtn.setStyle("display","");
        this.nextBtn.setStyle("display","");
    },
    _hideUDBtn:function(){
    	this.upBtn.setStyle("display","none");
        this.nextBtn.setStyle("display","none");
    },
    /**
     * 显示上下页按钮
    */
    _showControlBtn:function(){
        var obj = this; 
        if(!obj.showFLBtn){
        	obj._hideFLBtn();
        }else{
        	obj._showFLBtn();
        }
        if(!obj.showUDBtn){
        	obj._hideUDBtn()
        }else{
        	obj._showUDBtn()
        }
        if(!obj.showFLBtn && !obj.showUDBtn){
          return;
        }
        obj.firstBtn.removeClass("pager_nolink");
        obj.firstBtn.removeClass("pager_back-no");
        obj.firstBtn.addClass("pager_back");
        obj.firstBtn.enable();
        
        obj.upBtn.removeClass("pager_nolink");
        obj.upBtn.removeClass("pager_back-no");
        obj.upBtn.addClass("pager_back");
        obj.upBtn.enable();
        
        obj.nextBtn.removeClass("pager_nolink");
        obj.nextBtn.removeClass("pager_next-no");
        obj.nextBtn.addClass("pager_next");
        obj.nextBtn.enable();
        
        obj.lastBtn.removeClass("pager_nolink");
        obj.lastBtn.removeClass("pager_next-no");
        obj.lastBtn.addClass("pager_next");
        obj.lastBtn.enable();
        
        if (obj.page.currentPage >= obj.page.totalPages){
            obj.nextBtn.addClass("pager_nolink");
            obj.nextBtn.addClass("pager_next-no");
            obj.nextBtn.removeClass("pager_next");
            obj.nextBtn.unable();
            
            obj.lastBtn.addClass("pager_nolink");
            obj.lastBtn.addClass("pager_next-no");
            obj.lastBtn.removeClass("pager_next");
            obj.lastBtn.unable();
        } 
         if(obj.page.currentPage <= 1) {
            obj.firstBtn.addClass("pager_nolink");
            obj.firstBtn.addClass("pager_back-no");
            obj.firstBtn.removeClass("pager_back");
            obj.firstBtn.unable();
            
            obj.upBtn.addClass("pager_nolink");
            obj.upBtn.addClass("pager_back-no");
            obj.upBtn.removeClass("pager_back");
            obj.upBtn.unable();
        } 
        
    }
});


/**
*按钮标题
*/
Ext.apply(ssh.grid.GridPanel.prototype,{
	btnCaption:{
		bigBtn:{
			firstBtn:"首页",
			upBtn:"上一页",
			nextBtn:"下一页",
			lastBtn:"尾页",
			sureBtn:"确定"
		},
		smallBtn:{
			firstBtn:"<<",
			upBtn:"<",
			nextBtn:">",
			lastBtn:">>",
			sureBtn:"go"
		}
	}
});

 /**
     * tab框架,用于创建tab布局。是tabItem对象的容器，可被拖拽到其它布局中。
     * @param {Object} target
     */
ssh.TabPanel = Ext.extend(Ext.util.Observable, {
    constructor: function(config){
    	this.renderTo = config.renderTo;
        this.targetNode = Ext.get(this.renderTo);
        this.init();
        this.initEvents();
    }, 
	init: function(){
        this.rootNode = this.targetNode.createChild({
           tag: "div",
           cls: "ssh-tabs-container cl"
        });
		this.tabs = this.rootNode.createChild({
			tag: "div",
			cls:"cl"
		});
        this.tabPanel = this.tabs.createChild({
			id:this.rootNode.id+"_tabPanel",
            tag: "ul",
			cls:"ssh-tabs-strip"
        });
		this.contentPanel = this.rootNode.createChild({
			id:this.tabPanel.id+"_cards",
			tag:"div",
			cls:"ssh-tabs-cards"
		});
	},
	initEvents: function(){
		Ext.select('.ssh-tabs-strip').on('click', function(e, t){
			Ext.fly(t).radioClass('ssh-tabs-tab-active');
			Ext.get('content_' + t.id).radioClass('ssh-tabs-card-active');
		}, null, {
			delegate: 'li'
		});
	},
	addTab: function(label){
		return	new ssh.TabItem(this.tabPanel,label,this.contentPanel);
	}
});
	/**
	 * TabItem:用于创建tab布局的tab页，TabItem的内容可被其它布局方式分割布局
	 * @param {Object} tabPanel
	 * @param {Object} label
	 * @param {Object} contentPanel
	 * @param {Object} layer
	 */
ssh.TabItem = Ext.extend(Ext.util.Observable, {
    constructor:function(tabPanel,label,contentPanel,layer){
		this.rootNode = tabPanel.parent().parent();
		this.tabPanel = tabPanel;
		this.contentPanel = contentPanel;
		this._addContent(label);
		if(layer){
			this.contentItem.appendChild(layer);
		}
	},
	_addItem: function(label){
            return this.tabPanel.createChild({
                tag: "li",
                html: "<span>" + label + "</span>"
            });
     },
        
	_addContent: function(label){
		var tabItem = this._addItem(label);
		this.contentItem = this.contentPanel.createChild({
			id: "content_" + tabItem.id,
			tag: "div",
			cls: "ssh-tabs-card"
		});
	    tabItem.radioClass('ssh-tabs-tab-active');
    	this.contentItem.radioClass('ssh-tabs-card-active');
    }
});
/**
 * 调色板类
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */


Ext.ns('ssh.util');

ssh.util.Palette = Ext.extend(Ext.util.Observable, {
	/**
	 * 
	 * @param {} parameter (left: X坐标, top:Y坐标, color:颜色值, callback: 回调函数, adhere: 粘附对象)
	 * @param Function callback 回调函数
	 */
    constructor: function(parameter) {
		//设置默认坐标
    	var me = this;
    	me.isEnter = false;
    	if(!Ext.isEmpty(parameter.adhere))
    	{
    		var adhere = parameter.adhere;
			me.left = adhere.getX();
			me.top = adhere.getY() + adhere.getHeight();  	    	
    	}else
    	{    	
			me.left = Ext.isEmpty(parameter.left) ? 0 : parameter.left;
			me.top = Ext.isEmpty(parameter.top) ? 0 : parameter.top;    	
    	}
		var tpl = new Ext.Template(this.getTemplate());
		
		me.handle = tpl.append(Ext.getBody().dom, {left: me.left, top: me.top}, true);
		me.handle.child('.palette-image').on('mousedown', function(e){
			var color = me.getColor(e); //获取颜色
			me.setColor(color); //设置颜色
			if(parameter.callback != null)
			{
				parameter.callback(color);
			}
		});
		
        me.hideTask = new Ext.util.DelayedTask(function() {
        	if(me.isEnter == false)
        	{
				me.handle.remove();
        	}
        });			
		
		me.setCapture(me.handle);	        
		me.handle.on('selectstart', function(e, t){
			e.stopEvent();
		});		        

		me.handle.on('mousedown', function(e, t){
			me.isEnter = true;
		});		
		
		me.handle.on('mousemove', function(e, t){
			window.status = e.getXY()[0] + ';' + e.getXY()[1];
		});			
				
		me.handle.on('mouseup', function(e, t){
			me.isEnter = false;			
			me.input.focus();
		});			
		
		me.input = this.handle.child('.palette-colorhex');
		me.input.focus();
		me.input.on('focus', function(e, t){
			me.hideTask.cancel();					
		});		
		me.input.on('blur', function(e, t){
			 me.hideTask.delay(300);						
		});				
		
		me.input.on('keyup', function(e, t){
			if(e.keyCode == 13){
				var color = me.input.dom.value;
				me.setColor(color); //设置颜色
				if(parameter.callback != null)
				{
					parameter.callback(color);
				}
			}
		});
		
		me.handle.child('.palette-close').on('click', function(){
			me.handle.remove();
		});
		//设置默认颜色		
		if(!Ext.isEmpty(parameter.color)){
			this.setColor(parameter.color); 
		}
				
		if(Ext.isBorderBox || Ext.isIE7 || Ext.isIE6) {        	
			ssh.util.iframe(this.handle);        	
		}

    },
    
    setCapture: function(el)
    {
		if (el.dom.setCapture) 
		{
			el.dom.setCapture();
		}
		if (window.captureEvents) {
			window.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		}
    },
    
	releaseCapture: function(el)
	{
		el.on('mouseup', function(e) {
			if (el.dom.releaseCapture) {
				el.dom.releaseCapture();
			};
		});		
	},
    
    moveTo : function(x, y) {
    	this.handle.moveTo(x, y);
    },
    show : function() {
    	this.handle.show();
    },
    hide : function() {
    	this.handle.hide();
    },
    /**
     * 设置颜色
     * @param {} color
     */
    setColor : function(color) { 
    	this.handle.child('.palette-box').setStyle('background-color', color);
		this.handle.child('.palette-colorhex').dom.value = color;
    },
    /**
     * 获取颜色
     * @param {} e
     */
	getColor : function(e) {
		var hex = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'];
		var x = e.getXY()[0] - this.handle.getLeft();
		var y = e.getXY()[1] - this.handle.getTop();

		if(x > 164 || y > 164) {
			return;
		}
		var hsv = new Object();
		var h = 164;
		hsv.h = 360 * x / 164;
		if (y > h/2) {
			hsv.s = 1.0;
			hsv.v = 2 * (h - y) / h;
		}
		else {
			hsv.v = 1.0;
			hsv.s = y / (h/2);
		}
		var rgb = this.hsvToRgb(hsv);
		var red   = Math.round(255 * rgb.r);
		var green = Math.round(255 * rgb.g);
		var blue  = Math.round(255 * rgb.b);
		hexstr = '#' + hex[(red - (red % 16)) / 16].toString() + hex[red % 16].toString()
			 + hex[(green - (green % 16)) / 16].toString() + hex[green % 16].toString()
			 + hex[(blue - (blue % 16)) / 16].toString() + hex[blue % 16].toString()

		return hexstr;
	},
	hsvToRgb:function(hsv) {
		var rgb = new Object();
		var i, f, p, q, t;
	
		if(hsv.s == 0) {
			// achromatic (grey)
			rgb.r = rgb.g = rgb.b = hsv.v;
			return rgb;
		}
		hsv.h /= 60;
		i = Math.floor( hsv.h );
		f = hsv.h - i;
		p = hsv.v * ( 1 - hsv.s );
		q = hsv.v * ( 1 - hsv.s * f );
		t = hsv.v * ( 1 - hsv.s * ( 1 - f ) );
		switch( i ) {
			case 0:
				rgb.r = hsv.v;
				rgb.g = t;
				rgb.b = p;
				break;
			case 1:
				rgb.r = q;
				rgb.g = hsv.v;
				rgb.b = p;
				break;
			case 2:
				rgb.r = p;
				rgb.g = hsv.v;
				rgb.b = t;
				break;
			case 3:
				rgb.r = p;
				rgb.g = q;
				rgb.b = hsv.v;
				break;
			case 4:
				rgb.r = t;
				rgb.g = p;
				rgb.b = hsv.v;
				break;
			default:
				rgb.r = hsv.v;
				rgb.g = p;
				rgb.b = q;
				break;
		}
		return rgb;
	},				
	/**
	 * 板模数据
	 * @return {}
	 */
    getTemplate: function() {
        return [
			'<div class="palette" style="top:{top}px; left:{left}px">',
				'<table style="border:1px solid #333;" cellspacing="0" cellpadding="0">',
					'<tr><td colspan="3"><div class="palette-image"></div></td></tr>',
					'<tr height="20"><td width="10" class="palette-box"></td>',
						'<td width="60px">',
							'<input class="palette-colorhex">',
						'</td><td><div class="palette-close" >关闭</div></td></tr>',
				'</table>',
			'</div>'
        ];
    }    
});
// 提示框控件

ssh.TipBox = Ext.extend(Ext.util.Observable, {
    autoWidth: true,
	renderTo: undefined,
	tipTo: undefined,
    delay: 0.2,
    // 菜单反转效果的class
    hoverClass: undefined,
    // 位置
    top: undefined,
    left: undefined,
	
    constructor: function(config) {
        config = config || {};
        Ext.apply(this, config);
        
        this.el = Ext.get(config.renderTo);
        this.etip = Ext.get(config.tipTo);

        this.initEvents();
	},
	
	initEvents: function() {
        this.hideTask = new Ext.util.DelayedTask(function() {
        	if (ssh_current_tipBox == this) {
        		ssh_current_tipBox = null;
        	}
        	this.hide();
        }, this);

        this.el.hover(function() {
        	if (Ext.isObject(ssh_current_tipBox) && ssh_current_tipBox != this) {
        		ssh_current_tipBox.hideAll();
        	}

       		ssh_current_tipBox = this;
            this.hideTask.cancel();
            this.show();
        }, function() {
            this.hideTask.delay(this.delay * 1000);
        }, this);
        
        this.etip.hover(function() {
            this.hideTask.cancel();
        }, function() {
            this.hideTask.delay(this.delay * 1000);
        }, this);
	},
	
    show: function() {
  		if (!Ext.isEmpty(this.hoverClass)) {
  			this.el.addClass(this.hoverClass);
  		}
        this.etip.setStyle("display", "");
    },
    
    hide: function() {
  		if (!Ext.isEmpty(this.hoverClass)) {
  			this.el.removeClass(this.hoverClass);
  		}
        this.etip.setStyle("display", "none");
    },
    
    hideAll: function() {
        this.hideTask.cancel();
        this.hide();
    }
});

// 当前活动和显示的 tipBox
ssh_current_tipBox = null;
/**
 * 提示信息框
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh');

ssh.ToolTip = Ext.extend(Ext.util.Observable, {
	delay: 0.2,
	isFixed: false,
	offset: 8,
	minWidth: '100px',
	/**
	 * 
	 * @param {} config (left: X坐标(px), top:Y坐标(px), align:位置, width:宽度(px), height:高度(px), delay:延时时间 , html: 显示内容, url:网页地址, params:地址参数  callback:回调函数, isFixed:是否固定,renderTo: 粘附对象)
	 * @param Function callback 回调函数
	 */	
    constructor: function(config) {
        Ext.apply(this, config);   
        ssh.garbage = ssh.garbage || {};
        if (!Ext.isEmpty(this.renderTo)) {
        	this.adhere = Ext.get(this.renderTo);
        }   
        this.align = Ext.isEmpty(this.align) ? 'right' : this.align;
		this.width = Ext.isEmpty(this.width) ? this.minWidth : this.width;		
		this.height = Ext.isEmpty(this.height) ? 'auto' : this.height;		
		var tpl = new Ext.Template(this.getTemplate());		
		this.handle = tpl.append(Ext.getBody().dom, {width: this.width, height:this.height, html:this.html}, true);	
		this.toolClose = this.handle.child('.x-tool-close');
		this.tipAnchor = this.handle.child('.x-tip-anchor');
		

		if(! this.isFixed) {
			this.toolClose.setStyle('display', 'none');
		}
		
        if(!Ext.isEmpty(this.url)) {            
            Ext.Ajax.request({
                url: this.url,
                async: true,
                params: this.params,
                win: this,
                success: function(response, opts){
                	var result = response.responseText;;
                	if(opts.win.format == 'json')
                	{
                		result = Ext.decode(result).html;
                	}					
                	opts.win.fill(result);	                	
                    opts.win.bindAll();
                },
                failure: function(response, opts){
                	alert('服务端失效的状态代码：' + response.status);
                }
            });
        } else {
             this.bindAll();
        }		
		
		
        this.initEvents();
	},
	
    bindAll: function() {
		switch(this.align)
		{
			case 'right':
				this.left = Ext.isEmpty(this.left) ? this.adhere.getRight() + this.offset + 'px' : this.left;		
				this.top = Ext.isEmpty(this.top) ? this.adhere.getTop() + 'px' : this.top;
				this.handle.setStyle({left:this.left, top:this.top});				
				this.tipAnchor.addClass('x-tip-anchor-left');
				break;
			case 'left':
				this.left = Ext.isEmpty(this.left) ? this.adhere.getLeft() - this.handle.getWidth() -  this.offset + 'px' : this.left;		
				this.top = Ext.isEmpty(this.top) ? this.adhere.getTop() + 'px' : this.top;
				this.handle.setStyle({left:this.left, top:this.top});				
				this.tipAnchor.addClass('x-tip-anchor-right');
				break;
			case 'top':
				this.left = Ext.isEmpty(this.left) ? this.adhere.getLeft() + 'px' : this.left;		
				this.top = Ext.isEmpty(this.top) ? this.adhere.getTop() - this.handle.getHeight() -  this.offset + 'px' : this.top;
				this.handle.setStyle({left:this.left, top:this.top});				
				this.tipAnchor.addClass('x-tip-anchor-bottom');			
				break;
			case 'bottom':
				this.left = Ext.isEmpty(this.left) ? this.adhere.getLeft()  + 'px' : this.left;		
				this.top = Ext.isEmpty(this.top) ? this.adhere.getBottom () + this.offset + 'px' : this.top;   
				this.handle.setStyle({left:this.left, top:this.top});				
				this.tipAnchor.addClass('x-tip-anchor-top');							
				break;			
		}
        // 绑定内容
		if(!Ext.isEmpty(this.callback)) {this.callback(); }
    },	
	
	initEvents: function() {
		var me = this;
		this.toolClose.on('click', function(){
			me.hide();
		});
		
        this.hideTask = new Ext.util.DelayedTask(function() {
        	me.hide();
        });		
		
		Ext.getBody().on('mousemove', function(e, t){
			var x = e.getXY()[0];
			var y = e.getXY()[1];
			if(x >= me.handle.getLeft() 
			   && x <= (me.handle.getLeft() + me.handle.getWidth())
			   && y >= (me.handle.getTop() - 30) 
			   && y <= me.handle.getBottom())
			{
				me.hideTask.cancel();			
			}else
			{
				if(!me.isFixed){
					me.hideTask.delay(me.delay * 1000);				
				}			
			}
		});		        
        
		/*
		this.handle.hover(function(){
			me.hideTask.cancel();

		},function(){
			if(!me.isFixed){
				me.hide();				
			}
		});		
		*/		
		

		this.adhere.hover(function(){
			me.show();
		},function(){
			if(!me.isFixed){
				me.hideTask.delay(me.delay * 1000);				
			}
		});		
	},
	
    fill: function(info) {
    	var content = this.handle.child(".content-tip");
        content.update(info);
    },
	
    moveTo : function(x, y) {
    	this.handle.moveTo(x, y);
    },
    
    show : function() {
    	//隐藏已显示提示内容
    	if(ssh.garbage.currentToolTip)
    	{
    		ssh.garbage.currentToolTip.hide();
    		ssh.garbage.currentToolTip = null;
    	}
    	
		if(! this.isFixed) {
			ssh.garbage.currentToolTip = this;
		}    	
    	
    	this.handle.show();
    },
    
    hide : function() {
    	this.handle.hide();
    },

    getTemplate: function() {
        return [
				'<div style="position: absolute;  z-index: 11000; visibility: hidden; width: {width}; height: {height}; " class="x-tip">',
				  '<div class="x-tip-tl">',
				    '<div class="x-tip-tr">',
				      '<div class="x-tip-tc">',
				        '<div style="-moz-user-select: none;" class="x-tip-header x-unselectable">',
				          '<div class="x-tool x-tool-close">&nbsp;</div>',
				          '<span class="x-tip-header-text"><a href="#"></a></span></div>',
				      '</div>',
				    '</div>',
				  '</div>',
				  '<div class="x-tip-bwrap">',
				    '<div class="x-tip-ml">',
				      '<div class="x-tip-mr">',
				        '<div class="x-tip-mc">',
				          '<div style="height: auto;" class="x-tip-body">',
				            '<div class="content-tip">',
								'{html}',
				              '<div class="clear"></div>',
				            '</div>',
				          '</div>',
				        '</div>',
				      '</div>',
				    '</div>',
				    '<div class="x-tip-bl x-panel-nofooter">',
				      '<div class="x-tip-br">',
				        '<div class="x-tip-bc"></div>',
				      '</div>',
				    '</div>',
				  '</div>',
				  '<div style="z-index: 11001;" class="x-tip-anchor"></div>',
				'</div>'		
        ];
    }        		
});


/**
 * 容器
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh');

ssh.Container = Ext.extend(Ext.util.Observable, {
    constructor: function(renderTo) {	
		this.renderTo = Ext.isEmpty(renderTo) ?	Ext.getBody() : Ext.get(renderTo);
		this.handle = this.renderTo.createChild({tag:'div'});			
	},	
	
	setWidth : function(width) {
    	this.handle.setWidth(width);
    },
	
	setHeight : function(height) {
    	this.handle.setHeight(height);
    },	
	
    moveTo : function(x, y) {
    	this.handle.moveTo(x, y);
    },
    
    show : function() {
    	this.handle.show();
    },
    
    hide : function() {		
    	this.handle.hide();
    },   	
	
    remove : function() {
    	this.handle.remove();
    },
	
	addItem : function(object) {
		this.handle.appendChild(object.handle);
	}    	
});

/**
 * 面板
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh');

ssh.Panel = Ext.extend(ssh.Container, {
    constructor: function(config) {
		Ext.apply(this, config);		
		this.initUI();		
        this.initEvents();		
	},	
	initUI: function() { 	
		var me = this;	 
		ssh.Panel.superclass.constructor.call(me, me.renderTo);						
		this.handle.addClass('panel');						
		
		var tpl = new Ext.Template(me.getTemplate());
		me.html = Ext.isEmpty(me.html) ? '' : me.html;
		tpl.append(me.handle,{title:me.title, html:me.html});			
		
		me.header = me.handle.child('.panel-header');
		me.body = me.handle.child('.panel-bwrap');   			
		me.content = me.handle.child('.content-panel');
		me.floor =  me.handle.child('.panel-bl');
		
		me.panelTool = me.handle.child('.panel-tool');		
		me.isLoad = Ext.isEmpty(me.isLoad) ? false : me.isLoad;
        if(!Ext.isEmpty(this.url) && me.isLoad) {            
			me.load();
        } 	
	},
	/**
	 * 加载
	 */
	load: function()
	{
		var me = this;	 					
		me.body.addClass('panel-loading');		
		me.body.slideIn('t',{duration: .2, useDisplay: true, callback:function(){			
	       Ext.Ajax.request({
	            url: me.url,
	            async: true,
	            params: me.params,
	            success: function(response, opts){
					me.body.removeClass('panel-loading');            	
	            	var result = response.responseText;;
	            	me.fill(result);	         
					me.isLoad = true;			
	            },
	            failure: function(response, opts){
	            	me.body.removeClass('panel-loading');
	            	alert('服务端失效的状态代码：' + response.status);
	            }
	        });				
		}}); 		
	},
	
	/**
	 * 填充
	 * @param {Object} info 内容信息
	 */ 
    fill: function(info) {
        this.content.update(info);
    },	

	/**
	 * 收缩
	 */
	shrink: function() {
		this.panelTool.removeClass('panel-close');
		this.panelTool.addClass('panel-open');
		this.body.slideOut('t',{duration: .2, useDisplay: true});
    },	
	
	/**
	 * 展开
	 */
	decoil: function() {
		this.panelTool.removeClass('panel-open');
		this.panelTool.addClass('panel-close');		
        if(!Ext.isEmpty(this.url) && this.isLoad == false) {            
			this.load();
        }else
        {
			this.body.slideIn('t',{duration: .2, useDisplay: true});        
        }
    },	

	
	initEvents: function() {
		var me = this;
		this.handle.child('.panel-header').on('click', function(){			
			if(me.panelTool.hasClass('panel-open'))
			{
				me.decoil();				
			}else
			{
				me.shrink();
			}
		});		
		
	},	
    getTemplate: function() {
        return [
				  '<div class="panel-tl">',
				    '<div class="panel-tr">',
				      '<div class="panel-tc">',
				        '<div class="panel-header">',
				          '<div class="panel-tool panel-close">&nbsp;</div>',
				          '<span class="panel-header-text">{title}</span></div>',
				      '</div>',
				    '</div>',
				  '</div>',
				  '<div class="panel-bwrap">',
				    '<div class="panel-ml">',
				      '<div class="panel-mr">',
				        '<div class="panel-mc">',
				          '<div style="height: auto;" class="panel-body">',
				            '<div class="content-panel">',
								'{html}',
				            '</div>',
				          '</div>',
				        '</div>',
				      '</div>',
				    '</div>',
				    '<div class="panel-bl">',
				      '<div class="panel-br">',
				        '<div class="panel-bc"></div>',
				      '</div>',
				    '</div>',
				  '</div>'
				  
        ];	
    }  	
	
});
/**
 * outlook风格工具箱
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh');

ssh.Kit = Ext.extend(ssh.Container, {
	/**
	 * 
	 * @param {} config ()
	 * @param Function callback 回调函数
	 */	
    constructor: function(config) {
		ssh.Kit.superclass.constructor.call(this, Ext.get(this.renderTo));		
        Ext.apply(this, config);   
		this.initUI();		
        this.initEvents();
	},	
	initUI: function() { 
		this.cls = Ext.isEmpty(this.cls) ? 'kit-gray' : this.cls;
		this.handle.addClass(this.cls);
		
		this.hide.call(this);				
		Ext.get(this.renderTo).appendChild(this.handle);
		if(Ext.isArray(this.items))
		{
			for(var i = 0; i < this.items.length; i ++)
			{
				if (Ext.isObject(this.items[i])) {
				 	this.items[i]['renderTo'] = this.handle;
				 	var panel = new ssh.Panel(this.items[i]);
				 	this.items[i]['panel'] = panel; 
				}
			}	
		}		
		if(Ext.isEmpty(this.index))
		{
			this.allShrink();	
			
		}else
		{
			if(this.index == -1)
			{
				this.allDecoil();				
			}else
			{
				
				this.showIndexItem(this.index);
			}			
		}
		 
				
		this.show();		
	},
	/**
	 * 显示索引项
	 */
	showIndexItem: function(index)
	{
		for(var i = 0; i < this.items.length; i++)
		{
			if(Ext.isObject(this.items[i])&&Ext.isObject(this.items[i]['panel'])){
				if(index == i)
				{
					this.items[i]['panel'].decoil();	
				}else
				{
					this.items[i]['panel'].shrink();	
				}	
			
			}
		}
	},
	
	/**
	 * 填充内容
	 */
	fillItem: function(index, info)
	{
		this.items[index]['panel'].fill(info);	
	},	
	
	/**
	 * 加载内容
	 */
	loadItem: function(index)
	{
		this.items[index]['panel'].load();	
	},		
	
	/**
	 * 所有收缩
	 */
	allShrink: function() {
		for(var i = 0; i < this.items.length; i++)
		{
			this.items[i]['panel'].shrink();
		}
	},
	/**
	 * 所有展开
	 */
	allDecoil: function() {
		for(var i = 0; i < this.items.length; i++)
		{
			this.items[i]['panel'].decoil();
		}
	},	
	initEvents: function() {
		var me = this;
	}
});
/**
 * 相片
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh');

ssh.Photo = Ext.extend(ssh.Container, {
	width: 'auto',
	height: 'auto',	
    constructor: function(config) {
		Ext.apply(this, config);						
		this.initUI();		
        this.initEvents();		
	},	
	initUI: function() { 	
		var me = this;	 
		ssh.Photo.superclass.constructor.call(me, me.renderTo);	
		this.handle.addClass('photo');		
					
		me.alt = Ext.isEmpty(me.alt) ? '' : me.alt;
		me.src = Ext.isEmpty(me.src) ? '' : me.src;
		me.href = Ext.isEmpty(me.href) ? '#' : me.href;
		var tpl = new Ext.Template(me.getTemplate());		
		tpl.append(me.handle,{width:me.width, height:me.height, alt: me.alt, src: me.src, href:me.href});			
								
	},
		
	initEvents: function() {
		var me = this;		
	},
	
    getTemplate: function() {
        return [
				  '<a href="{href}">',
				    '<img style="width:{width}; height:{height}" src="{src}">',
				  '</a>'
        ];	
    } 	
});
/**
 * 
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh');

ssh.Photograph = Ext.extend(ssh.Container, {
	delay: 5,	
	index: 0,
	last: 0,
	nowWidth: 0,
	nowIndex: 0,
	style: 'rightAngle',
	isShowText: true,
	isRuning: true,
	isPause: false,
	readCount:0, //读取数
	/**
	 * 
	 * @param {} config ()
	 * @param Function callback 回调函数
	 */	
    constructor: function(config) {
		ssh.Photograph.superclass.constructor.call(this, Ext.get(this.renderTo));		
        Ext.apply(this, config);
        this.initUI();	
       	this.initEvents();
    },	
	
	/**
	* 初始化界面
	*/ 
	initUI: function() { 
		// 宽度
		this.width = Ext.isEmpty(this.width) ? Ext.fly(this.renderTo).dom.offsetWidth+'px' : this.width;
		// 高度
		this.height = Ext.isEmpty(this.height) ? Ext.fly(this.renderTo).dom.offsetHeight+'px' : this.height;
		// CSS样式
		this.cls = Ext.isEmpty(this.cls) ? 'photograph-fade-2' : this.cls;
		this.cls = this.cls=='photograph-gray' ? 'photograph-fade-2' : this.cls;
		this.cls = this.cls=='photograph-orange' ? 'photograph-fade-2' : this.cls;
		// 样式
		this.effect = Ext.isEmpty(this.effect) ? this.cls.split('-')[1] : this.effect;	
		// 控件最外层框架
		this.div = Ext.fly(this.renderTo).createChild({tag: 'div'});
		this.div.addClass(this.cls);
		this.div.appendChild(this.handle);
		this.div.setWidth(this.width);
		this.div.setHeight(this.height);
		
		this.items = this.items || {};
		//this.hide.call(this);
		this.handle.setHeight(this.height);
		// 下方透明显示层
		this.navigationPanel = this.div.createChild({
			tag:'div', 
			style:'display:' + (this.isShowText ? 'block' : 'none'),
			cls:'photographShowText'
		});
				
		// 圆角和直角的判定
		if(this.style == 'circular'){
			var offsetWidth = -4;
			this.navigationPanel.setLeft(2);
			this.navigationPanel.setWidth((parseInt(this.width) + offsetWidth));			
		}else if(this.style == 'rightAngle') {this.navigationPanel.setLeft(0);}	
		// 边角处理	
		this.background_1 = this.div.createChild({tag:'div', cls:'photographBackgroundLeftDown', 
							style:'display:' + (this.style == 'circular' ? 'block' : 'none')});
		this.background_2 = this.div.createChild({tag:'div', cls:'photographBackgroundRightDown',
							style:'display:' + (this.style == 'circular' ? 'block' : 'none')});
		this.background_3 = this.div.createChild({tag:'div', cls:'photographBackgroundLeftUp',
							style:'display:' + (this.style == 'circular' ? 'block' : 'none')});
	  	this.background_4 = this.div.createChild({tag:'div', cls:'photographBackgroundRightUp',
	  						style:'display:' + (this.style == 'circular' ? 'block' : 'none')});
		// 左下部分文字显示层
		this.textPanel = this.navigationPanel.createChild({
			tag:'div', 
			cls:'lable',
			html: this.items[0].alt
		});
	  	
		if(this.effect == 'fade'){
			this.handle.setWidth(this.width);
		}else if(this.effect == 'scroll'){
			this.handWidth = parseInt(this.width)*this.items.length;
			this.handle.setWidth(this.handWidth);
			// 左右箭头的处理
			this.prev = this.div.createChild({tag:'div', cls:'photographPrev'});
			this.next = this.div.createChild({tag:'div', cls:'photographNext'});
			if(this.cls == 'photograph-scroll-2'){
				this.prev.setTop(parseInt(this.height)/2-15);
				this.next.setTop(parseInt(this.height)/2-15);
			}else if(this.cls == 'photograph-scroll-1'){
				this.prev.setTop(parseInt(this.height)/2-40);
				this.next.setTop(parseInt(this.height)/2-40);
			}
			
			// 下排按钮的处理
			var buttonBackGround = this.div.createChild({tag:'div', cls:'firstLevel'});
			this.leftArc = buttonBackGround.createChild({tag:'span', cls:'photographLc'});
			this.center = buttonBackGround.createChild({tag:'span', cls:'photographMc'});
			this.rightArc = buttonBackGround.createChild({tag:'span', cls:'photographRc'});
			if(this.cls == 'photograph-scroll-1'){
				buttonBackGround.select('span:nth-child(2)').setWidth(this.items.length*24);
			}else if(this.cls == 'photograph-scroll-2'){
				buttonBackGround.select('span:nth-child(2)').setWidth(this.items.length*28);
			}
			var s = (this.items.length*24);
			
			// 下方按钮偏转设置（显示左下角文字时）
			if(this.isShowText){
				if(this.cls == 'photograph-scroll-1'){
					buttonBackGround.setLeft(parseInt(this.width)-(s+36));
				}else if(this.cls == 'photograph-scroll-2'){
					buttonBackGround.setLeft(parseInt(this.width)-(s+28));
				}
			}else{
				buttonBackGround.setLeft(parseInt(this.width)/2-s/2);
			}
		}		

		// 动态创建按钮
		for(var i = 0; i < this.items.length; i++)
		{
			 this.items[i]['renderTo'] = this.handle;
			 this.items[i]['width'] = this.width;
			 this.items[i]['height'] = this.height;
			 var photo = new ssh.Photo(this.items[i]);

			 photo.handle.child('img').on('load', function(){
			 	me.readCount+=1;
			 	if(me.readCount == me.items.length)
			 	{
			 		me.div.setStyle('background-image', 'none');
			 	}
			 });
			 
			 this.items[i]['photo'] = photo;
			 var button = null;
			 // 按钮属性设置
			 if(this.effect == 'fade'){
			 	button = this.handle.createChild({
				 	tag: 'span',
					cls: 'nav-button',
				 	html: i+1
			 	});
			 	button.setLeft(parseInt(this.width)-(26*this.items.length));
			 	button.setTop(parseInt(this.height)-28);
			 }else if(this.effect == 'scroll'){
			 	if(this.cls == 'photograph-scroll-2'){
				 	button = this.center.createChild({
					 	tag: 'span',
					 	cls: 'photographSPAN',
					 	html: i+1
					});
					
					var child = button.createChild({
						tag:'span',
						cls:'photographRed',
						html: i+1
					});
				}else if(this.cls == 'photograph-scroll-1'){
			 		button = this.center.createChild({
					 	tag: 'span',
					 	cls: 'photographSPAN'
					});
					
					var child = button.createChild({
						tag:'span',
						cls:'photographRed'
					});
				}
			 	
			}
			 
			var me = this;		
			// 按钮事件 
			if(this.effect == 'fade'){
				// 获得焦点
				button.hover(function(e, t){
					e.stopEvent();
					me.showIndexItem(me.getIndex(t));
					me.textShow(t.id);
				}, function(e, t){			 	
					});
			}else if(this.effect == 'scroll'){  
				// 点击   
				button.on('click', function(e, t){
					var index = 1;
					var prev = this.prev();
					while(!Ext.isEmpty(prev))
					{
						prev = prev.prev();
						index += 1;		
					}					
					me.jump(index);
				});
			}
			this.items[i]['button'] = button;			 			 
		}
		
		this.tip = Ext.getBody().createChild({tag:'div', html:'', style:'position:absolute; color:#404040; font-size:12px; padding:2px; z-index:100; display:none; border:solid 1px #40B3FF; background-color:#E5F5FF;'});

		// 处理IE兼容问题
		if(Ext.isIE)
		{
			if(this.cls == 'photograph-scroll-1' || this.cls == 'photograph-scroll-2')	
			{
				var radius = 0;
				switch(this.cls)
				{
					case 'photograph-scroll-1':
						radius = 4;
						break;				
					case 'photograph-scroll-2':
						radius = 10;
						break;
				}
				var setting = {
					tl: { radius: radius },
					tr: { radius: radius },
					bl: { radius: radius },
					br: { radius: radius },
					antiAlias: true
				}
				curvyCorners(setting, ".photographSPAN");					
				curvyCorners(setting, ".photographRed");	
			}
			// IE6下PNG图片处理
			if(Ext.isIE6)
			{	var me = this;
				me.isPause = true;
				me.fixIE6Png();
				me.isPause = false;
				/*
				if (document.readyState == "complete")
				{
					me.isPause = true;
					me.fixIE6Png();
					me.isPause = false;
				}
				else
				{
			       document.onreadystatechange = function()
			       {
						if (document.readyState == "complete")
						{	                	
		                  	me.fixIE6Png();		                        
		                }
			       };
				}
				*/
			}
		}		
	
		this.show();
	},
	/**
	 * 修正IE6 png图片
	 */
	fixIE6Png: function()
	{
		try
		{
            try {
                document.execCommand("BackgroundImageCache", false, true); /* TredoSoft Multiple IE doesn't like this, so try{} it */
            } catch(r) {}
            ssh.util.DD_belatedPNG.createVmlNameSpace();
            ssh.util.DD_belatedPNG.createVmlStyleSheet();  	
			ssh.util.DD_belatedPNG.fixPng(this.navigationPanel.dom); 
			ssh.util.DD_belatedPNG.fixPng(this.background_1.dom);				
			ssh.util.DD_belatedPNG.fixPng(this.background_2.dom);				
			ssh.util.DD_belatedPNG.fixPng(this.background_3.dom);
			ssh.util.DD_belatedPNG.fixPng(this.background_4.dom);			
            if(this.effect == 'scroll')
            {
				ssh.util.DD_belatedPNG.fixPng(this.prev.dom);				
				ssh.util.DD_belatedPNG.fixPng(this.next.dom);            	            	
				if(this.cls == 'photograph-scroll-1')
				{				
					ssh.util.DD_belatedPNG.fixPng(this.leftArc.dom);
					ssh.util.DD_belatedPNG.fixPng(this.center.dom);
					ssh.util.DD_belatedPNG.fixPng(this.rightArc.dom);
				}
            }
		}catch(e)
		{
			alert(e);
		}
	},		
	/**
	 * 文本显示
	 */
	textShow: function(id){
		var me = this;
		if(this.effect == 'fade'){
				for(var i=0;i<this.items.length;i++){
					if(this.items[i].button.id == id){
						this.textPanel.dom.innerHTML = this.items[i].alt
					}	
				};
			}else if(this.effect == 'scroll'){
				this.textPanel.dom.innerHTML = this.items[id-1].alt
		}
	},
	
	/**
	 * 显示索引项
	 */
	showIndexItem: function(index)
	{		
		this.last = index == 0 ? this.items.length - 1: index - 1;		
		for(var i = 0; i < this.items.length; i +=1)
		{
			if(i != index && i != this.last )
			{
				this.hideItem(i);
			}			
		}		
		this.showItem(index);		
	},
	getIndex: function (t)
	{		
		for(var i = 0; i < this.items.length; i +=1)
		{
			if(this.items[i]['button'].id == t.id)
			{
				return i;									
			}			
		}	
	},
	
	/**
	 * 显示图片
	 */
	showItem: function(index)
	{
		var me = this;				
		this.items[index]['button'].radioClass('activate');	
		if(index != this.last)
		{		
			this.items[this.last]['photo'].handle.setStyle('z-index', 0);
			this.items[index]['photo'].handle.setStyle('z-index', 1);	
			this.items[index]['photo'].handle.fadeIn({duration: me.delay / 4,callback:function(){
				if(me.index != me.items.length - 1)
				{
					me.index += 1;				
				}else
				{				
					me.index = 0;
				}	
			}});
		}else
		{
			this.items[index]['photo'].show();	
		}				
		this.textPanel.dom.innerHTML = this.items[index]['photo'].alt;
		this.tip.update(this.items[index]['photo'].alt);
	},
	// 隐藏
	hideItem: function(index)
	{
		this.items[index]['photo'].handle.setStyle('display', 'none');		
	},

	// 初始化事件
	initEvents: function() {
		var me = this;
		// 样式选择
		if(this.effect=='fade'){
			// 图片获得焦点
			this.handle.hover(function(e, t){	
				if(!Ext.isEmpty(me.tip.dom.innerHTML))
				{
					me.tip.setStyle('display', 'block');
				}
			}, function(){
				me.tip.setStyle('display', 'none');
			});
			
			this.handle.on('mousemove', function(e, t){			 
				me.tip.setLeft(e.getPageX());					
				me.tip.setTop(e.getPageY() + 22);
			});
			
		//使用TaskMgr		
		this.toggleTask = {
		run: function(){			
			try
			{
				if(me.isPause == false && me.readCount == me.items.length){
					me.showIndexItem(me.index);
				}
			}catch(e)
			{
				me.runner.stop(me.toggleTask);
			}
		},
		interval: me.delay * 1000
		};
				
		this.runner = new Ext.util.TaskRunner();
		this.div.hover(function(){
			me.runner.stop(me.toggleTask);
		}, function(){	
			window.setTimeout(function(){
					me.runner.start(me.toggleTask);
			} , 3000);
		});	
		this.runner.start(this.toggleTask);	
		}else if(this.effect=='scroll'){
			this.nowIndex = 1;
			this.nowWidth = this.handle.dom.offsetLeft;	
			this.jump(1);
			// 左右箭头按钮事件
			this.prev.on('click',function(){
				if(me.isRuning == true){
				me.isRuning = false;
				me.rollNext(me.nowIndex);
				}
			});
			this.next.on('click',function(){
				if(me.isRuning == true){
				me.isRuning = false;
				me.rollBack(me.nowIndex);
				}
			});
			
			this.toggleTask = {
					run: function(){			
						try
						{
							if(me.isPause == false && me.readCount == me.items.length){
								me.rollBack(me.nowIndex);							
							}
						}catch(e)
						{
							me.runner.stop(me.toggleTask);
						}
					},
					interval: me.delay * 1000
					};
					this.runner = new Ext.util.TaskRunner();
					this.div.hover(function(){
						if(me.effect == 'scroll'){
							me.runner.stop(me.toggleTask);
						}
					}, function(){
						window.setTimeout(function(){
							if(me.effect == 'scroll'){
								me.runner.start(me.toggleTask);
							}		
						} , 200);	
					});	
			this.time = window.setTimeout(function(){
				if(me.effect == 'scroll'){
					me.runner.start(me.toggleTask);	
				}		
			} , 3000);	
			for(var i=0;i<this.items.length;i++){
				var s = this.items[i].photo.handle.id
			}
		}
	},
	
	/**
	 * 向后翻滚
	 */
	rollBack:function(i){
		var x = 0;
		if(i>this.items.length){
			i=this.items.length;
		}
		var s = this.items[0].photo.handle.dom.offsetWidth;
		var me = this;
		var runner = new Ext.util.TaskRunner();
		if(i<this.items.length){
			// 非边缘的情况
			var back = {
	    		run: function(){
			        if(x<11){
						Ext.fly(me.handle.dom.id).setLeft(me.nowWidth);
						me.nowWidth = me.nowWidth -s/10;
						x++;
					}else{
						runner.stop(back);
						me.nowIndex = me.nowIndex + 1;
						me.button(me.nowIndex-1);
						me.nowWidth = me.handle.dom.offsetLeft;
						me.textShow(i+1);
						me.isRuning = true;
						
					}
	        	},interval: 20 
			};
			runner.start(back);
		}else{ 
			// 边缘的情况（快速回翻）
			var back = {
				run: function(){
			        if(me.handle.dom.offsetLeft<0){
						Ext.fly(me.handle.dom.id).setLeft(me.nowWidth);
						me.nowWidth = me.nowWidth + s/5;
					}else{
						Ext.fly(me.handle.dom.id).setLeft(0);
						runner.stop(back);
						me.nowIndex = 1;
						me.button(me.nowIndex-1);
						me.nowWidth = me.handle.dom.offsetLeft;
						me.textShow(1);
						me.isRuning = true;
					}
	        	},interval: 10 
			};
			runner.start(back);
		}
	},
	
	/**
	 * 向前翻滚
	 */
	rollNext:function(i){
		var x = 0;
		if(i<0){
			i=1;
		}
		var s = this.items[0].photo.handle.dom.offsetWidth;
		var me = this;
		var runner = new Ext.util.TaskRunner();
		if(i!=1){
			// 非边缘的情况
			var next = {
	    		run: function(){
			        if(x<11){
						Ext.fly(me.handle.dom.id).setLeft(me.nowWidth);
						me.nowWidth = me.nowWidth +s/10;
						x++;
					}else{
						runner.stop(next);
						me.nowIndex = me.nowIndex -1;
						me.button(me.nowIndex-1);
						me.nowWidth = me.handle.dom.offsetLeft;
						me.textShow(i-1);
						me.isRuning = true;
					}
	        	},interval: 20 
			};
			runner.start(next);
		}else{ 
			// 边缘的情况（快速回翻）
			var next = {
				run: function(){
					if(me.handle.dom.offsetLeft>=-(me.items.length-1)*s){
						Ext.fly(me.handle.dom.id).setLeft(parseFloat(me.nowWidth));
						me.nowWidth = me.nowWidth - s/5;;
					}else{
						Ext.fly(me.handle.dom.id).setLeft(-(me.items.length-1)*parseFloat(me.width));
						runner.stop(next);
						me.nowIndex = me.items.length;
						me.button(me.nowIndex-1);
						me.nowWidth = me.handle.dom.offsetLeft;
						me.textShow(me.items.length);
						me.isRuning = true;
					}
	        	},interval: 10 
			};
			runner.start(next);
		}
	},
	
	/**
	 * 下排按钮点击跳转
	 */
	jump:function(i){
		var s = (i-1)*(this.items[0].photo.handle.dom.offsetWidth);
		this.button(i-1);
		Ext.fly(this.handle.dom.id).setX(-s);
		Ext.fly(this.handle.dom.id).setLeft(-s);
		Ext.fly(this.items[i-1].photo.handle.dom.id).fadeIn();
		this.textShow(i);
		this.nowIndex = i;
		this.nowWidth = this.handle.dom.offsetLeft;
	},
	
	/**
	 * 下排按钮颜色变化
	 */ 
	button:function(i){
		var me = this;
		for(var j=0;j<this.items.length;j++){
			// 样式选择
			if(this.effect == 'scroll'){
				if(j!=i){
					if(this.items[j].button.dom.children.length!=0){
						this.items[j].button.select('span:last-child').setStyle('display', 'none');
					}
				}else{
					this.items[j].button.select('span:last-child').setStyle('display', 'block');
				}
			}
		}
	},
	
	/**
	 * 样式切换
	 */ 
	change:function(cls){
		var me = this;
		this.cls = cls;
		this.effect = null;
		
		if(this.time){  
          clearTimeout(this.time);  
          delete this.time;  
      	}	   
		// 初始化全部元素
		this.nowWidth = 0;	
		if(this.runner){
			// 停止自动跳转事件
			this.runner.stop(this.toggleTask);
//			this.toggleTask = null;
//			this.runner = null;
			delete this.toggleTask;
			delete this.runner;
		}
		// 删除元素
		this.tip.remove();
		delete this.handle;
		this.div.remove();
		
		// 图片删除
		for(var i=0;i<this.items.length;i++){
			delete this.items[i].button;
			delete this.items[i].renderTo;
			delete this.items[i].width;
			delete this.items[i].height;
			delete this.items[i].photo;
		}
		
		// 重新初始化
		ssh.Photograph.superclass.constructor.call(me, Ext.get(me.renderTo));		
      	me.initUI();	
       	me.initEvents();	
		
	}
});
/**
 * 菜单信息框
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh');

ssh.Menu = Ext.extend(ssh.Container, {
	delay: 0.5,
	offsetLeft: 0,
	offsetTop: 0,	
	cls: 'menu-gray',
	mode: 'hover', 
	borderWidth: 0,
	effect:'none',
	/** 
	 * @param {} config (left: X坐标(px), top:Y坐标(px), delay:延时时间, adhereTo: 吸附对象)
	 */	
    constructor: function(config) {
        Ext.apply(this, config);
		ssh.Menu.superclass.constructor.call(this, Ext.get(this.renderTo));		   
		this.initUI();	
        this.initEvents();
	},
	/**
	 * 调整菜单位置
	 */
	adjust: function() {
		var left = Ext.isEmpty(this.left) ? this.adhereTo.getLeft() + this.offsetLeft : this.left;
		var top =  Ext.isEmpty(this.top) ? this.adhereTo.getBottom() + this.offsetTop : this.adhereTo.getBottom();
		left = Ext.isIE6 ? left - this.borderWidth * 2: left;
		top = Ext.isIE6 ? top - this.borderWidth * 2: top;
		this.handle.setLeft(left);
		this.handle.setTop(top);
	},
	initUI: function() { 	
		this.items = this.items || {};	
		this.handle.hide();	
	    this.adhereTo = Ext.get(this.adhereTo);
		this.handle.addClass(this.cls);		
		this.handle.setStyle('z-index',9998);
		this.adjust();
		// 根菜单
		this.rootMenu = this.addMenu(this.handle);
		this.createMenuItem(this.rootMenu, this.items);		
		this.doAutoWidth();
		
        //ie6 and ie7/ie8 quirksmode need iframes behind the submenus        
        if(Ext.isBorderBox || Ext.isIE7 || Ext.isIE6) {
            this.handle.select('ul').each(function(sub) {
                sub.parent().createChild({tag: 'iframe', cls: 'ux-menu-ie-iframe'})
                    .setWidth(sub.getWidth())
                    .setHeight(sub.getHeight());
            });
        }		
	},
	addMenu: function(item)
	{
		result =  item.createChild({
			 		tag: 'ul',
					cls: 'hidden'
			 	})	 	
		return result;
	},
	addItem: function(menu, item)
	{
		var result;		
		var itemTag = {
			 			tag: 'li',
						html: String.format('<a id="{3}" href="{0}" target="{1}">{2}</a>', Ext.isEmpty(item.href) ? 'javascript:;' : item.href, Ext.isEmpty(item.target) ? '_self' : item.target, item.text, Ext.isEmpty(item.id) ? Ext.id() : item.id)
			 			};
		if(Ext.isEmpty(menu))
		{
			result = this.rootMenu.createChild(itemTag);
		}else
		{
			result = menu.createChild(itemTag);		
		}
		
		if(!Ext.isEmpty(item.click))
		{
			var me = this;
			result.on('mouseup', function(e, t){
				item.click(me.getIndex(result))				
			});
		}
		
		return result;
	},
	getIndex: function(current){
		var index = 0;
		var item = current.prev();
		while(item)
		{
			item = item.prev();
			index ++;
		}
		return index;	
	},
	createMenuItem: function(parent, items)
	{		
		var me = this;	
		for(var i = 0; i < items.length; i ++)
		{
			var item = items[i];
			var child = this.addItem(parent, item);

			 if (!Ext.isEmpty(item.items)) {
				var subItem = child.createChild({
			 		tag: 'ul',
					cls: 'hidden'
			 	})	 	
				this.createMenuItem(subItem, item.items);
			 }		
		}					
	},
	initEvents: function() {
		var me = this;		
		Ext.getBody().on('mouseup', function(e, t){
			me.hide();			
			me.hideAll();			
		});
		
 		this.handle.select('ul').each(function(sub){
			sub.on('mouseover', function(e, t){
			   me.cancelBubble(e)			
			   //取消隐藏
			   me.hideTask.cancel();		   				
			   me.mainMenu = Ext.get(t);				
			});
			
			sub.on('mouseout', function(e, t){
			    if(me.mode == 'hover')
	        	{
				   me.cancelBubble(e)
				   me.hideTask.delay(me.delay * 1000);				
	        	}
			});			
			
             var items = sub.select('>li');		
			 items.each(function(item){		
			 	item.on('mouseup', function(e, t){
		        	me.hide();			
					me.hideAll();			 		
			 	});
			 	
				item.on('mouseover', function(e, t){					
					var item = Ext.get(t).parent();
					var subMenu = item.down('ul');
					
					if(!Ext.isEmpty(me.subMenu) && me.subMenu.id != item.parent().id && me.subMenu.parent().id != item.id)
					{
						me.subMenu.addClass('hidden');	
					}
																	
					if (!Ext.isEmpty(subMenu))
					{
						// 显示子菜单				
						me.removeClass(subMenu, 'sub');
						me.subMenu = subMenu; //保存子菜单项	
					}					
				});
			 });
		});		
		
	
        this.hideTask = new Ext.util.DelayedTask(function() {
    		me.hide();			
			me.hideAll();					        	
        });		
		
        if(this.mode == 'hover')
        {        
			this.adhereTo.hover(function(){
				me.adjust();				
				me.show();				
				me.removeClass(me.rootMenu, 'main');
			},function(){	
				me.hideTask.delay(me.delay * 1000);				
			});
        }else if(this.mode == 'click')
        {
			this.adhereTo.on('mouseup', function(e, t){
				me.cancelBubble(e);				
				me.adjust();				
				me.show();				
				me.removeClass(me.rootMenu, 'main');
			});        	
			
			this.adhereTo.on('blur', function(e, t){
			   me.cancelBubble(e)
			   me.hideTask.delay(me.delay * 1000);					 		
			});
			  			
        }
	},	
	removeClass:function(item, type)
	{	
		if(item.hasClass('hidden'))
		{
			item.removeClass('hidden');			
			var callback = function(){	
				item.setStyle('visibility', '');
			};
			switch(this.effect)
			{
				case 'fadeIn':
					item.fadeIn({callback:callback});
					break
				case 'slideIn':
					var direction = type == "main" ? 't' : 'l';
					item.slideIn(direction, {duration: .2, callback:callback});
					break;
				default:
					item.setStyle('visibility', 'visible');
					item.setStyle('visibility', '');					
					break;
			}
			
		}
	},
	
	cancelBubble: function(e)
	{
        if (e.stopPropagation) 
            e.stopPropagation();
        else 
            e.cancelBubble = true;				
	},
	
	/**
	 * 隐藏所有菜单
	 */
    hideAll: function() {
        this.handle.select('ul').each(function(sub){			
			sub.addClass('hidden');			
		});
    },	
	
	/**
	 * 自动调整宽度
	 */
    doAutoWidth: function() {        
    	var me = this;
        var fixWidth = function(sub) {
            var widest = 0;
            var items = sub.select('>li');

            sub.setStyle({width: 3000 + 'px'});
            items.each(function(item) {
                widest = Math.max(widest, item.getWidth()); 
            });

            widest = me.adhereTo.getWidth() < 200 && me.adhereTo.getWidth() > widest ? me.adhereTo.getWidth() : widest;             
            widest = Ext.isIE6 && widest == me.adhereTo.getWidth()  ? widest - me.borderWidth * 2 : widest; 
            
            items.setWidth(widest + 'px');
            sub.setWidth(widest + 'px');
			
            items.each(function(item) {
                var subItem = item.down('ul');
				if(!Ext.isEmpty(subItem))
				{
					var left = item.getWidth();
					subItem.setTop(0);					
					subItem.setLeft(left + 2);							
				}				
            });
			
        }
		
        this.handle.select('ul').each(fixWidth);
    }	
	
});


/**
 * 正则表达式验证
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh.form');

ssh.form.regexValidator = {
	/**
	 * email 正则表达式
	 */
	email:'/^[A-Za-z0-9_]+([A-Za-z0-9_\\.][A-Za-z0-9_]+)*@[A-Za-z0-9_]+(\\.[A-Za-z0-9_]+)*\\.[A-Za-z0-9_]+([-.][A-Za-z0-9_]+)*$/',
	phone:'/(^(\\d{2,4}[-_－—]?)?\\d{3,8}([-_－—]?\\d{3,8})?([-_－—]?\\d{1,7})?$)|(^0?1\\d{10}$)/',
	mulPhone: '^((\\d{3,4}){0,1}\\-{0,1}\\d{7,8})(\\,(\\d{3,4}){0,1}\\-{0,1}\\d{7,8})*$/',
	mobile:'/^((\\(\\d{3}\\))|(\\d{3}\\-))?1\\d{10}$/',
	Url: "/^http:\\/\\/[A-Za-z0-9]+\\.[A-Za-z0-9]+[\\/=\\?%\\-&_~`@[\\]\\':+!]*([^<>\"\"])*$/",
	IdCard: '/^\\d{15}(\\d{2}[A-Za-z0-9])?$/',
	Currency: '/^\\d+(\\.\\d+)?$/',
	_number: '/^\\d+$/',
	Zip: '/^[1-9]\\d{5}$/',
	QQ: '/^[1-9]\\d{4,8}$/',
	_integer: '/^[-\\+]?\\d+$/',
	positiveInteger: '/^[1-9]\\d*|0$/',
	_double: '/^[-\\+]?\\d+(\\.\\d+)?$/',
	english: '/^[A-Za-z]+$/',
	AccountId: '/^[A-Za-z|0-9|_|\u0391-\uFFE5]+$/',
	chinese: '/^[\u4E00-\u9FA5]+$/',
	isMatch:function(regex, value)
	{
		return new Boolean(eval(regex).exec(value)) ;
	}
	    			
};

/**
 * 表单验证
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh.form');

ssh.form.FormValidator = Ext.extend(Ext.util.Observable, {
    constructor: function(config) {	
		this.bind(config);
    },	
    /**
     * 绑定表单项
     * @param {} config
     */
	bind : function(config) {
		var me = this;
		this.form = Ext.get(config.form);
        this.isAjaxSubmit = config.isAjaxSubmit; // 是否使用AJAX进行提交	
		this.mode = Ext.isEmpty(config.mode) ? 'rich' : config.mode;
		this.isFloat = Ext.isEmpty(config.isFloat) ? false : config.isFloat;
		this.adhereIndex = Ext.isEmpty(config.adhereIndex) ? 0 : config.adhereIndex;		
		this.offsetLeft = Ext.isEmpty(config.offsetLeft) ? 0 : config.offsetLeft;
		this.offsetTop = Ext.isEmpty(config.offsetTop) ? 0 : config.offsetTop;
		
        this.callback = config.callback;
        this.custom = config.custom;
		this.items = [];		
		this.url = Ext.isEmpty(config.url) && this.form ? this.form.dom.action : config.url;	
		// 表单提示信息
		if(this.mode == 'thin' && this.isFloat)
		{	
			var field = this.findElement(config.fields[this.adhereIndex].name);			
			var width = Ext.isEmpty(config.tipWidth) ? field.getWidth() : config.tipWidth;
			var left =  field.getLeft() + this.offsetLeft;			
			var top =  field.getBottom() + this.offsetTop;
			left = Ext.isIE6 ? 
				   left - 2 : left;
			top = Ext.isIE6 ? 
				   top - 2 : top;			
			this.tipTo = Ext.getBody().createChild({tag:'div', 
													style:
													String.format('position:absolute;z-index:1000; left:{0}px; top:{1}px; width:{2}px', left, top, width)});													
		}
		// 绑定提交按钮
		if(config.submit)
		{
            Ext.fly(config.submit).on('mousedown', function(e){
                e.stopEvent();
            });		
            Ext.fly(config.submit).on('click', function(e){
                e.stopEvent();
            });   			
			Ext.fly(config.submit).on('mouseup', function(e){
				if(me.custom)
				{
					me.custom(e, me);
				}else
				{
					me.validator(e);
				}
			});
		}
		
		// 绑定Form表单
		this.form.on('submit', function(e){	
				if(me.custom)
				{
					me.custom(e, me);
				}else
				{
					me.validator(e);
				}		
		});		

		
		for(var i = 0; i < config.fields.length; i ++)
		{
			this.add(config.fields[i]);
		}
    },
    /**
     * 错误提示内容
     */
    errors: function(config) {
    	if(!Ext.isEmpty(config))
    	{
    		for(var i = 0; i<config.length; i++)
    		{
    			var item = this.findItem('name', config[i].name);
    			if(!Ext.isEmpty(item))
    			{
    				item.updateTip(config[i].tipType, config[i].tipText);
    			}    			
    		}
    	}
    },
    /**
     * 获取字段
     * @param {} name
     * @return {}
     */
    getFields: function(name)
    {
		for (var i = 0; i < this.form.elements.length; i ++)
		{
			if(this.form.elements[i].name = name){
				return Ext.get(this.form.elements[i]); 
			}   
		}    	
		return null;
    },
    /**
     * 查找元素
     * @param {} name
     * @return {}
     */
    findElement: function(name)
    {
		for (var j = 0; j < this.form.dom.elements.length; j ++)
		{
			var element = this.form.dom.elements[j];	
			if(element.name == name)
			{
				return Ext.get(element);
			}
		}        	
		return null;    	
    },
    /**
     * 查找字段
     * @param {} id
     */    
    findItem: function(name, value)
    {
    	for(var i=0; i<this.items.length; i++)
    	{
    		if(this.items[i][name] == value){
	    		return this.items[i];
    		}
    	}
    	return null;    	
    },    
    /**
     * 验证规则
     */
    validator: function(e) {    	
    	if(this.checkout())
    	{
    		this.submit(e);
    	} else
    	{
    		e.preventDefault(); 
    	}
    },
    /**
     * 验证检查
     * @param {} e
     */
    checkout: function()
    {
    	var isPass = true;
    	for(var i = 0; i < this.items.length; i++)
    	{
			if(this.mode == 'thin' && isPass == false)
    		{
    			this.items[i].updateTip('none', '');	
    		}else
    		{    		
	    		if(this.items[i].hasError()){
		    		isPass = false;
	    		}
    		}
    	}
    	return isPass;    	
    },
    /**
     * 添加验证
     */
    add: function(field) {
		switch(field.type)
		{
			case 'text':
				this.items.push(new ssh.form.TextFieldValidator(this, field));
				break;
		}
    },    
    /**
     * 移除验证
     */
    remove: function(field) {
    	field.destroy();
    	this.items.remove(field);
    },
    /**
     * 获取验证
     */
    getItem: function(index) {
    	return this.items[index];
    },    
    /**
     * 获取验证
     */
    getItemByName: function(name) {
    	for(var i = 0; i < this.items.length; i++)
    	{
    		var field = this.items[i];
    		if(field.name == name)
    		{
    			return field;
    		}
    	}    	
    	return null;
    },     
    /**
     * 提交数据
     */
    submit : function(e) {
    	if(this.isAjaxSubmit)
    	{
			var me = this;    		   
            Ext.Ajax.request({
                url: me.url,
                form: me.form,
                success: function(response, opts){
                	var result = response.responseText;;
					try {
						var tipInfo = null;	
						try
						{
							tipInfo = Ext.decode(result);						
						} catch(e)
						{
							//显示系统异常信息
							alert(result);		
							return;
						}
						//字段错误提示信息
						if (Ext.isObject(tipInfo.fieldErrors)) {
							var errors = tipInfo.fieldErrors;
							// 显示字段相关错误信息					
							tipErrors = [];
							for (var fieldName in errors) {
								tipErrors.push({name:fieldName, tipType:'error', tipText: errors[fieldName]});								
							}
							me.errors(tipErrors);
						}
						// 执行回调函数
						if(me.callback)
						{
							me.callback(tipInfo.globalErrors);
						}							
						
					} catch (e) {
						//显示系统异常信息
						alert(e);
					} 
                },
                failure: function(response, opts){
                	alert('服务端失效的状态代码：' + response.status);
                }
            });    		
         
    		e.preventDefault();             
    	}else
    	{
    		this.form.dom.submit();
    	}
    }
});

/**
 * 字段验证
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh.form');

ssh.form.FieldValidator = Ext.extend(Ext.util.Observable, {
	offsetTop:0,
	offsetLeft:0,
	isInsideTip:false,
    constructor: function(form, config) {    	    	
        Ext.apply(this, config);    	
        this.form = form;
        this.handle = this.form.findElement(this.name); //控件句柄
        this.tipTo = form.mode == 'thin' && form.isFloat ? form.tipTo : Ext.get(this.tipTo); //提示点
        this.tipPanel = this.createTipPanel(); //提示信息面板
        this.state = 'none';
        this.message = '';
        this.rule = this.rule || []; 
        this.passTip = this.passTip || '';
        this.focusTip = this.focusTip || '';   
		this.onChange();
		this.onFocus();
		this.onBlur();
        this.init();		
    },	
	createTipPanel: function() {
		var tipPanelTpl = new Ext.Template(this.getTemplate('tipPanelX'));
		var tipPanel = tipPanelTpl.append(this.tipTo, { 
            			tipType:"field_none", 
            			tipText:''}, 
        			true);
        			
        var height = this.tipTo.getHeight();
        if(height > tipPanel.getHeight())
        {
			tipPanel.setStyle('min-height', height + 'px');        
			tipPanel.setStyle('_height', height + 'px');		
        }
		return tipPanel;
	},
    getTemplate: function(name) {
		switch(name)    	
		{
			case 'tipPanel':
	        return ['<ul class="ssh_tip">',
						'<li class="{tipType}">',
							'<div>',
								'<p>{tipText}</p>',
							'</div>',
						'</li>',
					'</ul>'];
			case 'tipPanelX':
	        return ['<div class="ssh_tip {tipType}">',
						'{tipText}',
					'</div>'];						
		}
    },  	
	
	onChange : function() {
    	var me = this;		
		this.handle.on('change', function(){
			me.filter();
		});
    },
    onFocus : function() {
    	var me = this;
    	this.handle.on('focus', function(){
			// 更新界面    		
    		me.handle.removeClass('field_hint');
    		me.handle.removeClass('field_error');
    		me.handle.removeClass('field_warning');			
			me.handle.addClass('field_focus');   
			if(me.hightLight){Ext.fly(me.hightLight).addClass('hover');  }
    		// 去除默认
    		if(me.isInsideTip && me.currentValue() == me.defaultValue)
    		{
    			me.handle.dom.value = '';
    		    me.setValue(me.currentValue());
    		}
    		// 焦点提示
			if(me.isInsideTip == false && me.form.mode == 'rich' && (me.currentValue() == me.defaultValue || Ext.isEmpty(me.currentValue())))
			{
				me.updateTip('prompt', me.focusTip);
			}    					
    	});
    },
    onBlur : function() {
    	var me = this;
    	this.handle.on('blur', function(){ 
    		// 更新界面
    		me.handle.removeClass('field_focus');      		
    		if(me.hightLight){Ext.fly(me.hightLight).removeClass('hover');  }
    		// 还原默认
    		if(me.isInsideTip && Ext.isEmpty(me.currentValue()) && !Ext.isEmpty(me.defaultValue))
    		{
    			me.handle.dom.value = me.defaultValue;
    		    me.setValue(me.currentValue());
    		    me.handle.addClass('field_hint');
    		}    		
    		
    		// 值已改变    		
    		if(me.form.mode == 'rich')
    		{
	    		if(!Ext.isEmpty(me.currentValue()) && me.currentValue() != me.getValue())
	    		{
	    				me.hasError();    			
	    		}else
	    		{
					switch(me.state)    	
					{
						case 'prompt':
							me.updateTip('none', '');
							break;					
						case 'error':
							me.handle.addClass('field_error');
							break;
						case 'warning':
							me.handle.addClass('field_warning');
							break;
					}    		
	    		}  
    		}
    	});
    },
    /**
     * 基础验证
     * @return {Boolean}
     */
    baseValidator: function() {
     	var result = true; // 验证结果
    	if(this.require && Ext.isEmpty(this.value))
    	{
    		this.updateTip('error', this.requireTip);
			result = false;
    	}
    	return result;    		    	    	
    },
    /**
     * 规则验证
     * @return {Boolean}
     */
    ruleValidator: function() {
     	var result = true; // 验证结果
    	for(var i = 0; i < this.rule.length; i ++)
    	{
    		var ruleInfo = this.rule[i];
    		if(ruleInfo.regex)
    		{    			
    			result = ssh.form.regexValidator.isMatch(ruleInfo.isTemplate ? ssh.form.regexValidator[ruleInfo.regex] : ruleInfo.regex, this.value);
    		}else if(ruleInfo.handler)
    		{
    			result = ruleInfo.handler(this.value);	    		
    		}else if(ruleInfo.url)
    		{
				var conn = this.createXhrObject();
				var url = Ext.isFunction(ruleInfo.url) ? ruleInfo.url() : ruleInfo.url;
				var parameter = 'value=' + this.value;
				conn.open('post', url, false);
				conn.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 				
				conn.send(parameter);
				if (conn.status == "200") {
					try
					{
	                	var responseText =  conn.responseText;	                	
	                	var resultInfo = Ext.decode(responseText);
	                	if(resultInfo.tipType != 'ok')
	                	{
	                		result = false;
	                	}
	                	ruleInfo.tipType = resultInfo.tipType;
	                	ruleInfo.tipText = resultInfo.tipText;
					}catch(e)
					{
	                	ruleInfo.tipType = 'error';
	                	ruleInfo.tipText = '系统异常';
					}
				}else
				{
 	                result = false;								
				    ruleInfo.tipType = 'error';
                	ruleInfo.tipText = '服务端失效的状态代码：' + conn.status;				
				}
    		}

    		if(result == false)
			{
				this.updateTip(ruleInfo.tipType, ruleInfo.tipText);	 
				break;
			}	    		
    	}
    	return result;      	
    },        
    hasError : function() {    
    	// 已通过验证且值未改变
    	if(this.state == 'ok' && this.currentValue() == this.getValue())
    	{
    		return false;
    	}else
    	{
    		if(this.isInsideTip && this.currentValue() == this.defaultValue)
    		{
    			this.handle.dom.value = '';
    		    this.setValue(this.currentValue());

    		}else
    		{
    	    	this.setValue(this.currentValue());
    		}
    		
	    	if(this.baseValidator())
	    	{	    		
	    		 if(!this.require && Ext.isEmpty(this.value))
		    	{
		    		return false;
		    	}else
		    	{	
		    		if(this.ruleValidator() == true)
		    		{		    		
			    		if(this.form.mode == 'rich')
			    		{
			    			this.updateTip('ok', this.passTip);
			    		}else
			    		{
			    			this.updateTip('none', '');
			    		}
			    	    return false;
		    		}else
		    		{
		    			return true;
		    		}
		    		
		    	}    	
	    	}else
	    	{
	    	    return true;    	
	    	}	    				
    	}
    },   
    setValue:function(value) {
    	this.value = value;
    },
    currentValue:function() {
    	return this.handle.dom.value;
    },
    getValue:function() {
		return this.value;    	
    },
    createXhrObject:function() {
        var http;            
	    var activeX = ['MSXML2.XMLHTTP.3.0',
	                   'MSXML2.XMLHTTP',
	                   'Microsoft.XMLHTTP'];        
        try {
            http = new XMLHttpRequest();   
        } catch(e) {
            for (var i = 0; i < activeX.length; ++i) {              
                try {
                    http = new ActiveXObject(activeX[i]);                        
                    break;
                } catch(e) {}
            }
        } finally {
            return http;
        }
    },    
    /**
     * 更新提示
     * @param {} state
     * @param {} message
     */
    updateTip: function(state, message) {
    	var className = 'none';
    	switch(state)
    	{
    		case 'none':
    			className = 'field_none';
    			break;    		
    		case 'prompt':
    			className = 'field_info';
    			break;
    		case 'warning':
    			className = 'field_warning';
    			break;      			
    		case 'error':
    			className = 'field_error';
    			break;    	
    		case 'ok':
				className = 'field_ok';    		
    			break;     			
    	}    	    	
    	// 更新提示
    	this.tipPanel.dom.className = 'ssh_tip ' + className;
    	this.tipPanel.update(message);
    	this.state = state;
		this.message = message;   			
		// 更新字段
		this.updateField();  		
    },    
    /**
     * 更新字段
     */
    updateField: function()
    {
		this.handle.removeClass('field_error');
		this.handle.removeClass('field_warning');			    	
		switch(this.state)    	
		{
			case 'error':
				this.handle.addClass('field_error');
				break;
			case 'warning':
				this.handle.addClass('field_warning');
				break;
		}  		    
    },
    /**
     * 销毁
     */
    destroy: function()
    {
		this.handle.removeAllListeners();    	
		// 更新界面
		this.handle.removeClass('field_focus');      		
		if(this.hightLight){Ext.fly(this.hightLight).removeClass('hover');  }	
		this.updateTip('none', '');		
    }    
});

/**
 * 文本字段验证
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */

Ext.ns('ssh.form');

ssh.form.TextFieldValidator = Ext.extend(ssh.form.FieldValidator, {
    init: function() {
    	var me = this;
    	var isSubmit = Ext.isEmpty(this.isSubmit) ? false : this.isSubmit; 
		// 输入长度
    	if(this.length){this.handle.dom.setAttribute(Ext.isIE ? 'maxlength' : 'maxLength', this.length);}
    	// 默认值
    	if(Ext.isEmpty(this.handle.dom.value)) {
    		this.handle.dom.value = this.defaultValue ? this.defaultValue : '';	
    	}
    	// 提示样式
    	if(this.isInsideTip){this.handle.addClass('field_hint');}     		    	
    	// 焦点获取
		if(this.isFocus) {this.handle.focus();}    
		// 回车提交
		this.handle.on('keydown', function(e){
			if(e.keyCode == 13){
				if(isSubmit)
				{ 
					if(me.form.custom)
					{
						me.form.custom(e, me.form);
					}else
					{
						me.form.validator(e);
					}					
				}							
   			}
		});		
		
		this.handle.on('keypress', function(e){
			if(e.keyCode == 13){
				if(isSubmit)
				{
					e.preventDefault(); 
				}	
   			}
		});		
    },
    filter: function() {
    	
    }    
});
(function() {
	function xf(format) {
		var args = Array.prototype.slice.call(arguments, 1);
		return format.replace(/\{(\d+)\}/g, function(m, i) {
					return args[i]
				})
	}
	Date.formatCodeToRegex = function(character, currentGroup) {
		var p = Date.parseCodes[character];
		if (p) {
			p = Ext.type(p) == "function" ? p() : p;
			Date.parseCodes[character] = p
		}
		return p ? Ext.applyIf({
					c : p.c ? xf(p.c, currentGroup || "{0}") : p.c
				}, p) : {
			g : 0,
			c : null,
			s : Ext.escapeRe(character)
		}
	};
	var $f = Date.formatCodeToRegex;
	Ext.apply(Date, {
		parseFunctions : {
			count : 0
		},
		parseRegexes : [],
		formatFunctions : {
			count : 0
		},
		daysInMonth : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
		y2kYear : 50,
		MILLI : "ms",
		SECOND : "s",
		MINUTE : "mi",
		HOUR : "h",
		DAY : "d",
		MONTH : "mo",
		YEAR : "y",
		dayNames : ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
				"Friday", "Saturday"],
		monthNames : ["January", "February", "March", "April", "May", "June",
				"July", "August", "September", "October", "November",
				"December"],
		monthNumbers : {
			Jan : 0,
			Feb : 1,
			Mar : 2,
			Apr : 3,
			May : 4,
			Jun : 5,
			Jul : 6,
			Aug : 7,
			Sep : 8,
			Oct : 9,
			Nov : 10,
			Dec : 11
		},
		getShortMonthName : function(month) {
			return Date.monthNames[month].substring(0, 3)
		},
		getShortDayName : function(day) {
			return Date.dayNames[day].substring(0,1)
		},
		getMonthNumber : function(name) {
			return Date.monthNumbers[name.substring(0, 1).toUpperCase()
					+ name.substring(1, 3).toLowerCase()]
		},
		formatCodes : {
			d : "String.leftPad(this.getDate(), 2, '0')",
			D : "Date.getShortDayName(this.getDay())",
			j : "this.getDate()",
			l : "Date.dayNames[this.getDay()]",
			N : "(this.getDay() ? this.getDay() : 7)",
			S : "this.getSuffix()",
			w : "this.getDay()",
			z : "this.getDayOfYear()",
			W : "String.leftPad(this.getWeekOfYear(), 2, '0')",
			F : "Date.monthNames[this.getMonth()]",
			m : "String.leftPad(this.getMonth() + 1, 2, '0')",
			M : "Date.getShortMonthName(this.getMonth())",
			n : "(this.getMonth() + 1)",
			t : "this.getDaysInMonth()",
			L : "(this.isLeapYear() ? 1 : 0)",
			o : "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0)))",
			Y : "this.getFullYear()",
			y : "('' + this.getFullYear()).substring(2, 4)",
			a : "(this.getHours() < 12 ? 'am' : 'pm')",
			A : "(this.getHours() < 12 ? 'AM' : 'PM')",
			g : "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
			G : "this.getHours()",
			h : "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
			H : "String.leftPad(this.getHours(), 2, '0')",
			i : "String.leftPad(this.getMinutes(), 2, '0')",
			s : "String.leftPad(this.getSeconds(), 2, '0')",
			u : "String.leftPad(this.getMilliseconds(), 3, '0')",
			O : "this.getGMTOffset()",
			P : "this.getGMTOffset(true)",
			T : "this.getTimezone()",
			Z : "(this.getTimezoneOffset() * -60)",
			c : function() {
				for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
					var e = c.charAt(i);
					code.push(e == "T" ? "'T'" : Date.getFormatCode(e))
				}
				return code.join(" + ")
			},
			U : "Math.round(this.getTime() / 1000)"
		},
		parseDate : function(input, format) {
			var p = Date.parseFunctions;
			if (p[format] == null) {
				Date.createParser(format)
			}
			var func = p[format];
			return Date[func](input)
		},
		getFormatCode : function(character) {
			var f = Date.formatCodes[character];
			if (f) {
//				f = Ext.type(f) == "function" ? f() : f;
				Date.formatCodes[character] = f
			}
//			return f || ("'" + String.escape(character) + "'")
		},
		createNewFormat : function(format) {
			var funcName = "format" + Date.formatFunctions.count++, code = "Date.prototype."
					+ funcName + " = function(){return ", special = false, ch = "";
			Date.formatFunctions[format] = funcName;
			for (var i = 0; i < format.length; ++i) {
				ch = format.charAt(i);
				if (!special && ch == "\\") {
					special = true
				} else {
					if (special) {
						special = false;
						code += "'" + String.escape(ch) + "' + "
					} else {
						code += Date.getFormatCode(ch) + " + "
					}
				}
			}
			eval(code.substring(0, code.length - 3) + ";}")
		},
		createParser : function() {
			var code = [
					"Date.{0} = function(input){",
					"var y, m, d, h = 0, i = 0, s = 0, ms = 0, o, z, u, v;",
					"input = String(input);",
					"d = new Date();",
					"y = d.getFullYear();",
					"m = d.getMonth();",
					"d = d.getDate();",
					"var results = input.match(Date.parseRegexes[{1}]);",
					"if(results && results.length > 0){",
					"{2}",
					"if(u){",
					"v = new Date(u * 1000);",
					"}else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0 && ms >= 0){",
					"v = new Date(y, m, d, h, i, s, ms);",
					"}else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0){",
					"v = new Date(y, m, d, h, i, s);",
					"}else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0){",
					"v = new Date(y, m, d, h, i);",
					"}else if (y >= 0 && m >= 0 && d > 0 && h >= 0){",
					"v = new Date(y, m, d, h);",
					"}else if (y >= 0 && m >= 0 && d > 0){",
					"v = new Date(y, m, d);",
					"}else if (y >= 0 && m >= 0){",
					"v = new Date(y, m);",
					"}else if (y >= 0){",
					"v = new Date(y);",
					"}",
					"}",
					"return (v && (z != null || o != null))? (Ext.type(z) == 'number' ? v.add(Date.SECOND, -v.getTimezoneOffset() * 60 - z) : v.add(Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn))) : v;",
					"}"].join("\n");
			return function(format) {
				var funcName = "parse" + Date.parseFunctions.count++, regexNum = Date.parseRegexes.length, currentGroup = 1, calc = "", regex = "", special = false, ch = "";
				Date.parseFunctions[format] = funcName;
				for (var i = 0; i < format.length; ++i) {
					ch = format.charAt(i);
					if (!special && ch == "\\") {
						special = true
					} else {
						if (special) {
							special = false;
							regex += String.escape(ch)
						} else {
							var obj = $f(ch, currentGroup);
							currentGroup += obj.g;
							regex += obj.s;
							if (obj.g && obj.c) {
								calc += obj.c
							}
						}
					}
				}
				Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$", "i");
				eval(xf(code, funcName, regexNum, calc))
			}
		}(),
		parseCodes : {
			d : {
				g : 1,
				c : "d = parseInt(results[{0}], 10);\n",
				s : "(\\d{2})"
			},
			j : {
				g : 1,
				c : "d = parseInt(results[{0}], 10);\n",
				s : "(\\d{1,2})"
			},
			D : function() {
				for (var a = [], i = 0; i < 7; a.push(Date.getShortDayName(i)), ++i) {
				}
				return {
					g : 0,
					c : null,
					s : "(?:" + a.join("|") + ")"
				}
			},
			l : function() {
				return {
					g : 0,
					c : null,
					s : "(?:" + Date.dayNames.join("|") + ")"
				}
			},
			N : {
				g : 0,
				c : null,
				s : "[1-7]"
			},
			S : {
				g : 0,
				c : null,
				s : "(?:st|nd|rd|th)"
			},
			w : {
				g : 0,
				c : null,
				s : "[0-6]"
			},
			z : {
				g : 0,
				c : null,
				s : "(?:\\d{1,3})"
			},
			W : {
				g : 0,
				c : null,
				s : "(?:\\d{2})"
			},
			F : function() {
				return {
					g : 1,
					c : "m = parseInt(Date.getMonthNumber(results[{0}]), 10);\n",
					s : "(" + Date.monthNames.join("|") + ")"
				}
			},
			M : function() {
				for (var a = [], i = 0; i < 12; a.push(Date
						.getShortMonthName(i)), ++i) {
				}
				return Ext.applyIf({
							s : "(" + a.join("|") + ")"
						}, $f("F"))
			},
			m : {
				g : 1,
				c : "m = parseInt(results[{0}], 10) - 1;\n",
				s : "(\\d{2})"
			},
			n : {
				g : 1,
				c : "m = parseInt(results[{0}], 10) - 1;\n",
				s : "(\\d{1,2})"
			},
			t : {
				g : 0,
				c : null,
				s : "(?:\\d{2})"
			},
			L : {
				g : 0,
				c : null,
				s : "(?:1|0)"
			},
			o : function() {
				return $f("Y")
			},
			Y : {
				g : 1,
				c : "y = parseInt(results[{0}], 10);\n",
				s : "(\\d{4})"
			},
			y : {
				g : 1,
				c : "var ty = parseInt(results[{0}], 10);\ny = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
				s : "(\\d{1,2})"
			},
			a : {
				g : 1,
				c : "if (results[{0}] == 'am') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",
				s : "(am|pm)"
			},
			A : {
				g : 1,
				c : "if (results[{0}] == 'AM') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",
				s : "(AM|PM)"
			},
			g : function() {
				return $f("G")
			},
			G : {
				g : 1,
				c : "h = parseInt(results[{0}], 10);\n",
				s : "(\\d{1,2})"
			},
			h : function() {
				return $f("H")
			},
			H : {
				g : 1,
				c : "h = parseInt(results[{0}], 10);\n",
				s : "(\\d{2})"
			},
			i : {
				g : 1,
				c : "i = parseInt(results[{0}], 10);\n",
				s : "(\\d{2})"
			},
			s : {
				g : 1,
				c : "s = parseInt(results[{0}], 10);\n",
				s : "(\\d{2})"
			},
			u : {
				g : 1,
				c : "ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
				s : "(\\d+)"
			},
			O : {
				g : 1,
				c : [
						"o = results[{0}];",
						"var sn = o.substring(0,1);",
						"var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);",
						"var mn = o.substring(3,5) % 60;",
						"o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n"]
						.join("\n"),
				s : "([+-]\\d{4})"
			},
			P : {
				g : 1,
				c : [
						"o = results[{0}];",
						"var sn = o.substring(0,1);",
						"var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);",
						"var mn = o.substring(4,6) % 60;",
						"o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n"]
						.join("\n"),
				s : "([+-]\\d{2}:\\d{2})"
			},
			T : {
				g : 0,
				c : null,
				s : "[A-Z]{1,4}"
			},
			Z : {
				g : 1,
				c : "z = results[{0}] * 1;\nz = (-43200 <= z && z <= 50400)? z : null;\n",
				s : "([+-]?\\d{1,5})"
			},
			c : function() {
				var calc = [], arr = [$f("Y", 1), $f("m", 2), $f("d", 3),
						$f("h", 4), $f("i", 5), $f("s", 6), {
							c : "ms = (results[7] || '.0').substring(1); ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"
						}, {
							c : ["if(results[9] == 'Z'){", "z = 0;", "}else{",
									$f("P", 9).c, "}"].join("\n")
						}];
				for (var i = 0, l = arr.length; i < l; ++i) {
					calc.push(arr[i].c)
				}
				return {
					g : 1,
					c : calc.join(""),
					s : arr[0].s + "-" + arr[1].s + "-" + arr[2].s + "T"
							+ arr[3].s + ":" + arr[4].s + ":" + arr[5].s
							+ "((.|,)\\d+)?(Z|([+-]\\d{2}:\\d{2}))"
				}
			},
			U : {
				g : 1,
				c : "u = parseInt(results[{0}], 10);\n",
				s : "(-?\\d+)"
			}
		}
	})
}());

Ext.apply(Date.prototype, {
			dateFormat : function(b) {
				if (Date.formatFunctions[b] == null) {
					Date.createNewFormat(b)
				}
				var a = Date.formatFunctions[b];
				return this[a]()
			},
			getTimezone : function() {
				return this
						.toString()
						.replace(
								/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/,
								"$1$2").replace(/[^A-Z]/g, "")
			},
			getGMTOffset : function(a) {
				return (this.getTimezoneOffset() > 0 ? "-" : "+")
						+ String.leftPad(Math.floor(Math.abs(this
										.getTimezoneOffset())
										/ 60), 2, "0")
						+ (a ? ":" : "")
						+ String.leftPad(Math
										.abs(this.getTimezoneOffset() % 60), 2,
								"0")
			},
			getDayOfYear : function() {
				var a = 0;
				Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
				for (var b = 0; b < this.getMonth(); ++b) {
					a += Date.daysInMonth[b]
				}
				return a + this.getDate() - 1
			},
			getWeekOfYear : function() {
				var a = 86400000, b = 7 * a;
				return function() {
					var d = Date.UTC(this.getFullYear(), this.getMonth(), this
									.getDate()
									+ 3)
							/ a, c = Math.floor(d / 7), e = new Date(c * b)
							.getUTCFullYear();
					return c - Math.floor(Date.UTC(e, 0, 7) / b) + 1
				}
			}(),
			isLeapYear : function() {
				var a = this.getFullYear();
				return !!((a & 3) == 0 && (a % 100 || (a % 400 == 0 && a)))
			},
			getFirstDayOfMonth : function() {
				var a = (this.getDay() - (this.getDate() - 1)) % 7;
				return (a < 0) ? (a + 7) : a
			},
			getLastDayOfMonth : function() {
				var a = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this
						.getDate()))
						% 7;
				return (a < 0) ? (a + 7) : a
			},
			getFirstDateOfMonth : function() {
				return new Date(this.getFullYear(), this.getMonth(), 1)
			},
			getLastDateOfMonth : function() {
				return new Date(this.getFullYear(), this.getMonth(), this
								.getDaysInMonth())
			},
			getDaysInMonth : function() {
				Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
				return Date.daysInMonth[this.getMonth()]
			},
			getSuffix : function() {
				switch (this.getDate()) {
					case 1 :
					case 21 :
					case 31 :
						return "st";
					case 2 :
					case 22 :
						return "nd";
					case 3 :
					case 23 :
						return "rd";
					default :
						return "th"
				}
			},
			clone : function() {
				return new Date(this.getTime())
			},
			clearTime : function(a) {
				if (a) {
					return this.clone().clearTime()
				}
				this.setHours(0);
				this.setMinutes(0);
				this.setSeconds(0);
				this.setMilliseconds(0);
				return this
			},
			add : function(b, c) {
				var e = this.clone();
				if (!b || c === 0) {
					return e
				}
				switch (b.toLowerCase()) {
					case Date.MILLI :
						e.setMilliseconds(this.getMilliseconds() + c);
						break;
					case Date.SECOND :
						e.setSeconds(this.getSeconds() + c);
						break;
					case Date.MINUTE :
						e.setMinutes(this.getMinutes() + c);
						break;
					case Date.HOUR :
						e.setHours(this.getHours() + c);
						break;
					case Date.DAY :
						e.setDate(this.getDate() + c);
						break;
					case Date.MONTH :
						var a = this.getDate();
						if (a > 28) {
							a = Math.min(a, this.getFirstDateOfMonth().add(
											"mo", c).getLastDateOfMonth()
											.getDate())
						}
						e.setDate(a);
						e.setMonth(this.getMonth() + c);
						break;
					case Date.YEAR :
						e.setFullYear(this.getFullYear() + c);
						break
				}
				return e
			},
			between : function(c, a) {
				var b = this.getTime();
				return c.getTime() <= b && b <= a.getTime()
			}
		});
Date.prototype.format = Date.prototype.dateFormat;
if (Ext.isSafari) {
	Date.brokenSetMonth = Date.prototype.setMonth;
	Date.prototype.setMonth = function(a) {
		if (a <= -1) {
			var d = Math.ceil(-a);
			var c = Math.ceil(d / 12);
			var b = (d % 12) ? 12 - d % 12 : 0;
			this.setFullYear(this.getFullYear() - c);
			return Date.brokenSetMonth.call(this, b)
		} else {
			return Date.brokenSetMonth.apply(this, arguments)
		}
	}
};
/**
 * 
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Combo = Ext.extend(Ext.util.Observable,{
	// 显示层是否展开(true: 展开, false：隐藏)
	isShow: false,
	// 键盘上下键的选中项
	isSelect: 1,
	// 是否有文字被选中
	isSelecting: false,
	// 下拉选项的个数
	count: 0,
	// 保存的
	showText: null,
	// 默认数组
	items:[],
	// 默认
	texts: null,
	// 创建构造方法
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
        this.initUI();
        this.initEvents();
    },
	
     
     /**
     * 初始化界面
     */
     initUI:function(){
     	// 尺寸
		this.width = Ext.isEmpty(this.width) ? Ext.fly(this.renderTo).dom.offsetWidth+'px' : this.width;
		this.height = Ext.isEmpty(this.height) ? Ext.fly(this.renderTo).dom.offsetHeight+'px' : this.height;
		this.isClear = Ext.isEmpty(this.isClear) ? false : this.isClear;
		// CSS样式
		this.cls = Ext.isEmpty(this.cls) ? 'combo-one' : this.cls;
		this.lineCount = Ext.isEmpty(this.lineCount) ? 30 : this.lineCount;
		// 控件最外层框架
		this.div = Ext.fly(this.renderTo).createChild({tag: 'div'});
		this.div.addClass(this.cls);
		
		// 判断图片大小
     	switch(this.size){
     		case 'big': this.size = 32;
     		break;
     		case 'middle': this.size = 18;
     		break;
     		case 'small': this.size = 8;
     		break;
     	}
     	// 创建元素
     	this.text = this.div.createChild({
     		tag: 'textarea',
     		name: 'comboText',
     		cls: 'text',
     		readonly: 'readonly',
     		html: this.defaultValue
     	});
     	if(Ext.isIE){
     		this.text.setStyle('overflow', 'hidden');
     	}
   		this.text.setWidth(this.width);
		this.text.setHeight('24px');
    	this.show = this.div.createChild({
    		tag: 'div',
    		cls: 'show'
    	});
    	this.idShow = this.div.createChild({
    		tag: 'input',
    		type: 'text',
    		style: 'position:relative;left:10px;top:0px;width:100px;height:100px;',
    		name: this.idShowName
    	});
    	var me = this;
    	this.text.on('click', function(e ,t){
    		me.isClick == true;
    		me.setSelect(me.text.dom,0,0);
    	});
    	this.ajax(null);
	 	this.idShow.setStyle('display', 'none');
    	// 隐藏显示层
    	this.show.setStyle('display', 'none');
    	// 设置参数
    	this.text.setWidth(this.width);
    //	this.show.setWidth(this.width);
    	// 最大高度
    	if(parseInt(this.show.dom.offsetHeight) > parseInt(this.height)){
    		this.show.setHeight(this.height);
    	}
    //	if(this.canInput == false){
   	//		this.text.dom.disabled = 'disabled';
    //	}
    },
     
     /**
     * 初始化事件
     */
	initEvents:function(){
		var me = this;
		// 空白部分点击
   		this.text.on('blur',function(e, t){
   			window.setTimeout(function(){
   				me.show.setStyle('dispaly', 'none');
		    	me.isShow = false;
		   		me.isClick = true;
//		   		me.textValue('');
		   } , 200);
		});
			this.text.on('keydown', function(e, t){
				var zhj = 0;
				if(e.keyCode == 8 || e.keyCode == 46){
					me.deleteKey(e);
					me.changeHeight();
				}
			//	e.stopEvent();
				// 上下按钮控制
			/*	if(e.keyCode == 38){
					me.isSelect = me.isSelect - 1;
					me.keyBoard(me.isSelect);
					return;
				}else if(e.keyCode == 40){
					me.isSelect = me.isSelect + 1;
					me.keyBoard(me.isSelect);
					return;
				}
				if(e.keyCode == 37 || e.keyCode == 39){
					me.isClick == true;
					me.setSelect(me.text.dom,0,0);
					me.canChange = false;
					return;
					}*/
				});
	/*	if(this.canIndex == true){	
			this.text.on('keyup', function(e, t){
				alert('1');
		    	if(e.keyCode != 38 && e.keyCode != 40){
		   			me.keyPress(e.keyCode);
		   		}
	    		// 回车键控制
				if(e.keyCode == 13){
				   	if(me.isShow == true){
				   		me.Enter();
				   	}
				}
	    	});
		}	*/
		
	},
     
     /**
     * 键盘点击事件
     */
     keyPress:function(str){
     	var cursortPosition = this.getCursortPosition(this.text.dom,false);
     	this.isShow = true;
     	var showText = this.text.dom.value.split(';');
     	var temporary = '';
     	this.removeShow();
     	// 根据输入的值搜索
     	var textShow = this.text.dom.value.split('');
     	if(textShow.length==0){return;}
     	if(str == 'delete'){
     		textShow[textShow.length-1] = null;
     		textShow.length = textShow.length-1;
     		var count = 0;
     		var text = '';
	     	for(var i=textShow.length;i>-1;i--){
	     		if(textShow[i-1]==';'){count = i;break;}
	     	}
	     	for(var i=count;i<textShow.length;i++){
	     		text = text + textShow[i];
	     	}
	     	showText[showText.length-1] = text;
     	}
     	for(var i=0;i<this.items.length;i++){
    		temporary = this.items[i].value.substring(0,showText[showText.length-1].length);
    		if(temporary==''){
    			temporary = this.items[i].value.substring(0,1);
    			if(temporary == textShow[cursortPosition-1]){
	    			this.divShowText(i);
	    		//	this.show.setStyle('display', 'block');
    				this.isShow = true;
	    		}
    		}
    		if(temporary == showText[showText.length-1]){
    			this.ajax('value='+showText[showText.length-1]);
    			this.divShowText(i);
    		//	this.show.setStyle('display', 'block');
    			this.isShow = true;
    		}
    		
    		temporary = '';
	    }
     },
     
     /**
     * 改变文本框的值
     */
     textValue:function(e){
     	var showText = '';
     	var idShow = '';
     	
     //	if((this.text.dom.value == null || this.text.dom.value == '') && e == ''){return;}
     	if(this.showText == null){this.showText = this.text.dom.value.split(';');}
     //	if(e == ''){return;}
     //	var c = this.text.dom.value.split(';');
     //	c[c.length-1] = e;
     	
    /* 	if(this.isSelecting == true){
     		for(var i=0;i<c.length;i++){
     			if(c[i] != this.showText[i]){
     				c[i] = this.showText[i+1];
     				break;
     			}
     		}
     	}*/
     	
    /* 	if(this.showText != null){
	     	for(var i=0; i<c.length; i++){
	     		for(var j=i; j<this.showText.length; j++){
	     			if(this.showText[j] != c[i]){
	     				var s = c[i].split('');
	     				var x = '';
	     				for(var m=1;m<s.length;m++){x = x + s[m];}
	     				if(this.showText[j] == x){c[i] = this.showText[j];}
	     			}
	     		}
	     	}
     	}*/
     /*	for(var i=0; i<c.length; i++){
     		if(i == c.length-1 && c[c.length-1] == ''){
     			showText = showText + '';
     		}else{
     			if(c[i] == null){break;}
     			showText = showText + c[i] + ';';
     			for(var j=0;j<this.items.length;j++){
     				if(this.items[j].value == c[i]){
     					idShow = idShow + this.items[j].id +';';
     					break;
     				}
     			}
     		}
     	}*/
     	//this.showText = c;
     	var c = null;
     	var d = null;
     	var count = 0;
     	var id = '';
     	if(this.text.dom.value != ''){
     		c = this.texts.split('');
     	}
     	if(this.texts.split(';').length == 2){
     		this.idShow.dom.value = '';
	     	this.texts = this.text.dom.value = '';
     	}else{
	     	for(var i=this.end-2; i>0; i--){
		     		if(c[i] == ';'){
		     			count = count + 1;
		     		}
		     	}
		     	d = this.idShow.dom.value.split(';');
		     	for(var i=0; i<d.length-1; i++){
		     		if(i != count){
		     			id = id + d[i] + ';';
		     		}
		     	}
		     	this.idShow.dom.value = id;
	     		this.texts = this.text.dom.value;
     	}
     	
     	},
     
     /**
     * 获取显示值
     */
     divShowText: function(i){
     	var me = this;
     	if(this.items[i].value == null){
     		this.items[i].value = '';
     	}
     	// 创建下拉框显示内容
     	var span = this.show.createChild({
	     	tag: 'span',
	     	cls: 'span',
	   		style: 'top:'+this.count*this.size*1.5+'px'
	    });
	   	if(this.isShowImg == true){
	   		span.createChild({
		   		tag: 'img',
		   		style: 'position:relative;left:'+this.size*0.25+'px;top:'+this.size*0.25+'px;',
		   		src: this.items[i].src
	     	});
	   	}
	   if(this.items[i].remarks == null){this.items[i].remarks = this.remarks}	
	   span.createChild({
     		tag: 'b',
     		style: 'position:relative;left:'+this.size*0.5+'px;',
     		html: this.items[i].value +'--<font color="gray" disabled="disabled">'+this.items[i].remarks+'</font>'
     	});
     	
	    span.setHeight(this.size*1.5+'px');
     	span.select('b:first-child').setStyle('line-height',this.size+'px');
     	if(this.size == 8){
     		span.setStyle('font-size',this.size*1.5+'px');
     	}else{
    		span.setStyle('font-size',this.size*0.75+'px');
     	}
     	
     	span.on('click',function(e,t){
     		if(Ext.isIE){
     			if(t.tagName == 'FONT'){
     				var a = t.offsetParent.innerText.split('--');
     			}else if(t.tagName == 'IMG'){
     				var a = t.parentNode.childNodes[1].innerText.split('--');
     			}else{
     				var a = t.innerText.split('--');
     			}
     		}else{
     			if(t.tagName == 'FONT'){
     				var a = t.offsetParent.textContent.split('--');
     			}else if(t.tagName == 'IMG'){
     				var a = t.parentNode.childNodes[1].textContent.split('--');
     			}else{
     				var a = t.textContent.split('--');
     			}
     		}
     		me.show.hide();
     		me.isShow = false;
     		if(a[1] == 'undefined'){
     			me.textValue('');
     		}else{
     			me.textValue(a[0]);
     		}
     	});
     	span.hover(function(e, t){
    		me.show.select('span:nth-child(n)').removeClass('span-over');
     		span.addClass('span-over');
		}, function(e, t){
			span.removeClass('span-over');
		});
     	this.count = this.count + 1;
     	if(Ext.isIE7){
     		this.show.setHeight(this.size*this.show.dom.childNodes.length*1.5+20+'px');
     	}else{
     		this.show.setHeight(this.size*this.show.dom.childNodes.length*1.5+'px');
     		//this.show.setHeight('100px');
     	}
     	this.show.select('span:first-child').addClass('span-over');
    	
     },
     
     /**
     * 重置显示层的内容
     */
     removeShow: function(){
     	this.show.select('span:nth-child(n)').remove();
     	this.count = 0;
     },
     
     /**
     * 键盘控制选择
     */
     keyBoard: function(i){
     	var me = this;
     	if(i<1){
     		i = this.show.dom.childNodes.length;
     		this.isSelect = this.show.dom.childNodes.length;
     	}else if(i>this.show.dom.childNodes.length){
     		i = 1;
     		this.isSelect = 1;
     	}
     	this.show.select('span:nth-child(n)').removeClass('span-over');
     	var select = this.show.select('span:nth-child('+i+')');
     	select.addClass('span-over');
     	this.text.focus();
     },
     
     /**
     * 按下回车键
     */
     Enter: function(){
     	var span = this.show.select('span:nth-child('+this.isSelect+')');
     	if(span.elements.length == 0){
     		this.show.setStyle('display', 'none');
     		this.isShow = false;
     		return;
     	}
     	var idShow = '';
     	if(Ext.isIE){
     		var a = span.elements[0].innerText.split('--');
     	}else{
     		var a = span.elements[0].textContent.split('--');
     	}
     	if(a[1] == 'undefined'){
     		this.textValue('');
     	}else{
   			this.textValue(a[0]);
     	}
     	this.isSelect = 1;
     	this.keyPress();
		this.isShow = false;
		this.show.setStyle('display', 'none');
     },
     
     /**
     * 获取光标位置
     */
     getCursortPosition: function(ctrl, bo) {//获取光标位置函数
        var CaretPos = 0;    // IE Support
        if (document.selection) {
        	var Sel = document.selection.createRange();
            if(bo == true){
            	this.text.focus ();
            	CaretPos = Sel.text.length;
        	}else if(bo == false){
        		Sel.moveStart('character', -ctrl.value.length);
        		if(this.type == 'Xxb'){
        			var a = Sel.text.split('对象： ');
	        		if(a[0]!='' && a[1] != null ){
	        			CaretPos = a[1].length;
	        		}else if(a[1] == null){
	        			CaretPos = Sel.text.length;
	        		}else{
	        			CaretPos = Sel.text.length;
	        		}
        		}else{
        			CaretPos = Sel.text.length;
        		}
        		
        	}
    }
        // Firefox support
        else if (ctrl.selectionStart || ctrl.selectionStart == '0'){
        	if(bo == true){
        		CaretPos = ctrl.selectionEnd;
        	}else if(bo == false){
        		CaretPos = ctrl.selectionStart;
        	}
        }
        return (CaretPos);
	},
	
	/**
	* 设置选中
	*/
	setSelect : function(textarea, st, en)
	{
		// 获取当前光标位置
		var CaretPos = this.getCursortPosition(textarea,false);
	/*	if(CaretPos == this.text.dom.value.length){
			return;
		}*/
		var textShow = this.text.dom.value.split('');
		if(CaretPos != 0){
			var start = CaretPos;
			var end = CaretPos;
			for(var i=CaretPos-1;i<textShow.length;i++){
					if(textShow[i] == ';'){
						end = i + 1;
						break;
					}
				}
			}
			for(var i=CaretPos-2;i<textShow.length;i--){
				if(i<=0){
					start = 0;
					break;
				}
				if(textShow[i] == ';'){
					start = i + 1;
					break;
				}
			}
		this.start = start;
		this.end = end;	
		if(st==0&&en==0){
			st = start;
			en = end;
		}	
		if ( typeof textarea.createTextRange != 'undefined' )// IE
		{
			var range = textarea.createTextRange();
			// 先把相对起点移动到0处
			range.moveStart("character", 0);
			range.moveEnd("character", 0);
			range.collapse(true); // 移动插入光标到start处
			range.moveStart("character", st);
			range.moveEnd("character", end-st);
			range.select();
		} // if
		else if ( typeof textarea.setSelectionRange != 'undefined' )
		{     
			textarea.setSelectionRange(st, en);
			textarea.focus();
		} // else 
		this.isSelecting = true;
	},
	
	/**
	* 按下删除键
	*/
	deleteKey: function(e){
		var CursortPosition = this.end;
		var showText = this.text.dom.value.split('');
		var lin = '';
		if(this.text.dom.value == ''){
			this.show.setStyle('display', 'none');
			this.isShow = false;
		}
		if(this.isSelecting == true){
			if(Ext.isIE){
				var CaretPos = this.start;
				var CaretPosEnd = this.end;
			}else{
				var CaretPos = this.getCursortPosition(this.text.dom,false);
				var CaretPosEnd = this.getCursortPosition(this.text.dom,true);
			}
			for(var i=0;i<CaretPosEnd-CaretPos;i++){
				delete showText[i+CaretPos];
			}
			for(var i=0;i<showText.length;i++){
				if(i<CaretPos || i>CaretPosEnd-1 ){lin = lin + showText[i];}
			}
			this.text.dom.value = lin;
			this.isSelecting = false;
			this.show.setStyle('display', 'none');
			this.isShow = false;
			this.textValue('');
			e.stopEvent();
		}else{
			if(showText[CursortPosition-1] != ';'){
				this.keyPress('delete');
				return;
			}else{
				showText[showText.length-1] = null;
	     		showText.length = showText.length-1;
	     		for(var i=0;i<showText.length;i++){
	     			lin = lin + showText[i];
	     		}
	     		this.text.dom.value = lin;
				this.show.setStyle('display', 'none');
				this.isShow = false;
				this.isClick = true;
				this.textValue('');
				e.stopEvent();
			}
		}
	},
	
	/**
	* Ajax连接数据库	 
	*/ 
	ajax: function(find){
		if(this.isAjaxBack == true){
			var me = this;
			Ext.Ajax.request({
				url: me.url + '?' + find,
	   			success: function(response, opts) {
	     			me.items = Ext.util.JSON.decode(response.responseText); 
	     		},
	   			failure: function(response, opts) {
	      			console.log('服务端失效的状态代码： ' + response.status);
	   			}
			});
		}
	},
	
	/**
	* 从通讯录获取数据
	*/
	contacts: function(items){
		var value = '';
		var id = '';
		if(items == null){
			return;
		}
		if(this.isClear == true){
			this.text.dom.value = '';
			this.idShow.dom.value = '';
		}
		var text = '';
		var id = '';
		if(this.idShow.dom.value != ''){
			text = this.text.dom.value;
			id = this.idShow.dom.value;
		}
		
		
		for(var i = 0; i < items.length; i++){
			text = text + items[i].value + ';';
			id = id + items[i].id + ';';
		//	this.items.push({value:items[i].value, id:items[i].id});
		//	this.textValue(items[i].value);
		}
		this.texts = text;
		this.text.dom.value = text;
		this.idShow.dom.value = id;
		this.changeHeight();
    },
	
	/**
	* 修改文本框高度
	*/
	changeHeight: function(){
		if(this.text.dom.value.length > this.lineCount){
			for(var i = 1; i < 100; i++){
     			if(this.text.dom.value.length/this.lineCount < i){
     				if(i == 2){
     					i = i + 1;
     				}
     				this.text.setHeight(24 * i);
     				break;
		     	}
		    }	
     	}else{
     		this.text.setHeight(24);
     	}
	}
/*	contacts: function(items){
		var textCount = 0;
		if(this.showText == null){
			this.showText = '';
			textCount = this.showText.length;
		}
		var textShow = '';
		var idShow = '';
		var id = this.idShow.dom.value.split(';');
		
		for(var i=0;i<items.length;i++){
			for(var j=0;j<id.length;j++){
				if(items[i].id == id[j]){
					items[i].id = '';
					items[i].value = '';
				}
			}
			if(items[i].id != ''){
				this.showText[textCount] = items[i].value;
				idShow = idShow + items[i].id + ';';
				textCount = textCount + 1;
			}
		}
		
		for(var i=0;i<this.showText.length;i++){
			textShow += this.showText[i] + ';';
		}
		this.text.dom.value = textShow;
		this.textValue('');
	}*/
});   
Ext.ns('ssh');
// 定义方法，继承基类    
ssh.Calendar = Ext.extend(Ext.util.Observable, {
	closed: true,
	
	constructor: function(config) {
		Ext.apply(this, config);
		this.initUI();
	},
	
	/**
	* 初始化界面
	*/
	initUI: function(){
		var me = this;
		this.style = Ext.isEmpty(this.style) ? 'calendar-gray' : this.style;
		this.type = Ext.isEmpty(this.type) ? 'zh_w' : this.type;
		this.sysDate = Ext.isEmpty(this.sysDate) ? 'no' : this.sysDate;
		this.module = Ext.isEmpty(this.module) ? '' : this.module;
		if (Ext.isIE) {
			Ext.DomHelper.useDom = true;
		}
		
		this.textShow = Ext.fly(Ext.fly(this.showId).dom.parentNode).createChild({
			tag: 'input',
			type: 'text',
			name: this.showName,
			style: 'display:none;'
		});
		if(this.module == "xueXB"){
			this.textShow.dom.defaultValue = Ext.fly(this.calendarShow).dom.value;
		}
		
		// 获取confing中传回的值
		ssh.Calendar.superclass.constructor.call(this);
		
		this.addEvents('select');
		this.calendarContainer = Ext.DomHelper.append(document.body, {
					tag : 'div',
					cls : this.style,
					style : 'display:none'
				});
		Ext.fly(this.calendarContainer).on('click', function(){
			me.closed = false;
			Ext.fly(me.showId).focus();
		});		
   		var navibar = Ext.DomHelper.append(this.calendarContainer, {
					tag : 'div',
					cls : 'navibar clearfix'
				});
		var prevNavi = Ext.DomHelper.append(navibar, {
					tag : 'a',
					cls : 'leftBtn',
					title:'上一月',
					hideFocus : 'on'
				}, true);
		// 导航上一月
		prevNavi.on('click', function() {
					var value = (Ext.isIE) ? this.btnMonthYear.dom.innerText.split('') : this.btnMonthYear.dom.textContent.split('');
					var nowMonth = '';
					if(value[6] != '月'){
						nowMonth = value[5] + value[6];
					}else{
						nowMonth = value[5];
					}
					this.naviDate.setMonth(parseInt(nowMonth) - 2);
					this.loadData(this.naviDate, this.type);
					me.closed = false;
					Ext.fly(me.showId).focus();
				}, this);
	
		var monthAndyear = Ext.DomHelper.append(navibar, {
					tag : 'em',
					cls : 'monthYear'
				}, true);
	
		this.btnMonthYear = Ext.DomHelper.append(monthAndyear, {
					tag : 'button',
					cls : 'btn-arrow'
				}, true);
		this.btnMonthYear.on('click', function() {
				this.showYMSelect(this.type);
				}, this);
		// 导航下一月
		var nextNavi = Ext.DomHelper.append(navibar, {
					tag : 'a',
					cls : 'rightBtn',
					title:'下一月',
					hideFocus : 'on'
				}, true);
		nextNavi.on('click', function() {
					var value = (Ext.isIE) ? this.btnMonthYear.dom.innerText.split('') : this.btnMonthYear.dom.textContent.split('');
					var nowMonth = '';
					if(value[6] != '月'){
						nowMonth = value[5] + value[6];
					}else{
						nowMonth = value[5];
					}
					this.naviDate.setMonth(nowMonth);
					this.loadData(this.naviDate, this.type);
					me.closed = false;
					Ext.fly(me.showId).focus();
				}, this);
		var calendarData = Ext.DomHelper.append(this.calendarContainer, {
					tag : 'table',
					cls : 'calendarData',
					cellSpacing : '0'
				});
		this.body = Ext.DomHelper.append(calendarData, {
					tag : 'tbody'
				},true);
		Ext.fly(this.body).on('click', function(){
			me.closed = false;
			Ext.fly(me.showId).focus();
		});
				
		this.body.on('click', this.dateSelect, this);
		var tfoot = Ext.DomHelper.append(calendarData, {tag : 'tbody'});
		var tfoottr = Ext.DomHelper.append(tfoot, {tag : 'tr'});
		var tfoottd = Ext.DomHelper.append(tfoottr, {tag : 'td','colSpan' : '7'});
		var btnToday = Ext.DomHelper.append(tfoottd, {
		        id:'btntoday',
				tag : 'button',
				html : '今天',
				title:new Date().getFullYear()+'/'+(new Date().getMonth()+1)+'/'+new Date().getDate(),
				cls : 'date-btn'
		}, true);
		// 今天按钮,返回到当前月
		var me = this;
		btnToday.on('click', function(e, t) {
				if(this.module == 'xueXB'){
					me.loadData(me.today, 'zh_w');
					me.todayButton();
				}else{
					this.loadData(this.today, this.type);
					me.todayButton();
				}
		}, this);
		
		var close = Ext.DomHelper.append(tfoottd, {
		        id:'btntoday',
				tag : 'button',
				html : '关闭',
				title: '关闭',
				cls : 'date-btn'
		}, true);
		close.on('click', function(){
			Ext.fly(me.calendarContainer).hide();
		});
		// 当前日期
		try{
			this.today = this.date();
		}catch(e){
			this.today = new Date();
		}
		if(this.module == "xueXB"){
			if(Ext.fly(this.calendarShow).dom.value == '' && this.defaultTime == true){
				this.dateShow(this.today);
			}
		}
		
		// 导航月
		this.naviDate = this.today.clone();
		this.loadData(this.today, this.type);
		this.yearMonthSelector = Ext.DomHelper.append(document.body, {
					tag : 'div',
					cls : 'calendar-gray',
					style : 'display:none'
				});
		var selectYandMTable = Ext.DomHelper.append(this.yearMonthSelector, {
					tag : 'table',
					cellSpacing : "0",
					border : "0",
					cls : 'yearMonth'
				});
		var trs = [];
		var tr = [];
		tr.push({
					tag : 'td',
					cls : 'date-mp-month',
					html : '<a hideFocus="on" href="#" onclick="return false;">1</a>'
					});
		tr.push({
					tag : 'td',
					cls : 'date-mp-month date-mp-sep',
					html : '<a hideFocus="on" href="#" onclick="return false;">2</a>'
					});
		tr.push({
					tag : 'td',
					cls : 'date-mp-ybtn',
					html : '<a class="date-mp-prev" id="' + this.id + '_mpPrev'
							+ '" hideFocus="on" href="#" onclick="return false;"></a>'
				});
		tr.push({
					tag : 'td',
					cls : 'date-mp-ybtn',
					html : '<a class="date-mp-next" id="'+ this.id +'_mpNext'
							+ '" hideFocus="on" href="#" onclick="return false;"></a>'
				});
		trs.push({
					tag : 'tr',
					cn : tr
				});
	
		// 保存当前的年月，用于年月选择导航
	
		// 导航年月
		this.yearMonthNavi = this.naviDate.clone();
		var startMonth = 3;
		var startYear = this.yearMonthNavi.getFullYear() - 5;
	
		// 已选择的年月保存
		this.selectedYear = this.yearMonthNavi.getFullYear();
		this.selectedMonth = this.yearMonthNavi.getMonth() + 1;
	
		for (var i = 0; i < 5; i++) {
			tr = [];
			tr.push({
						tag : 'td',
						cls : 'date-mp-month',
						html : '<a hideFocus="on" href="#" onclick="return false;"> ' + (startMonth++)
								+ ' </a>'
	
					});
	
			tr.push({
						tag : 'td',
						cls : 'date-mp-month date-mp-sep',
						html : '<a hideFocus="on" href="#" onclick="return false;"> ' + (startMonth++)
								+ ' </a>'
	
					});
	
			tr.push({
						tag : 'td',
						cls : 'date-mp-year',
						html : '<a hideFocus="on" href="#" onclick="return false;"> ' + (startYear++)
								+ '</a>'
	
					});
	
			tr.push({
						tag : 'td',
						cls : 'date-mp-year',
						html : '<a hideFocus="on" href="#" onclick="return false;"> ' + (startYear++)
								+ '</a>'
					});
			trs.push({
						tag : 'tr',
						cn : tr
					});
	
		}
		this.yearMonthSelectorBody = Ext.DomHelper.append(selectYandMTable, {
					tag : 'tbody',
					cn : trs
				}, true);
	
		var yearMonSelTft = Ext.DomHelper.append(selectYandMTable, {
					tag : 'tbody'
				});
	
		var yearMonSelftr = Ext.DomHelper.append(yearMonSelTft, {
					tag : 'tr'
				});
	
		var ymFoottd = Ext.DomHelper.append(yearMonSelftr, {
					tag : 'td',
					colSpan : '4'
				});
	
		var btnOkYM = Ext.DomHelper.append(ymFoottd,
				{
					tag : 'button',
					html : '确定',
					cls : 'date-btn'
				}, true);
	
		// 年月确定选择
		btnOkYM.on('click', function() {
					// 更新导航年月，并重新渲染导航日历
					me.closed == false;
					this.naviDate.setFullYear(this.selectedYear);
					this.naviDate.setMonth(this.selectedMonth - 1);
					this.loadData(this.naviDate, this.type);
					this.hideYMSelect();
					me.closed = false;
					Ext.fly(me.showId).focus();
					Ext.fly(me.calendarContainer).show();
				}, this);
		var btnCancelYM = Ext.DomHelper.append(ymFoottd, {
					tag : 'button',
					html : '取消',
					cls : 'date-btn'
				}, true);
	
		btnCancelYM.on('click', function() {
					this.hideYMSelect();
					me.closed = false;
					Ext.fly(me.showId).focus();
					Ext.fly(me.calendarContainer).show();
				}, this);
	
		this.loadYearMonthData(this.yearMonthNavi);
		// 导航年月
		Ext.get(this.id + '_mpPrev').on('click', function(evt) {
					this.yearMonthNavi = this.yearMonthNavi.add(Date.YEAR, -10);
					this.loadYearMonthData(this.yearMonthNavi);
					evt.stopEvent();
				}, this);
		Ext.get(this.id + '_mpNext').on('click', function(evt) {
					this.yearMonthNavi = this.yearMonthNavi.add(Date.YEAR, 10);
					this.loadYearMonthData(this.yearMonthNavi);
					evt.stopEvent();
				}, this);
		// 年月选择
		this.yearMonthSelectorBody.on('click', this.selectYearAndMonth, this);
		this.loadData(me.today, 'zh_w');
		this.todayButton();
		var me = this;
		Ext.fly(me.showId).on('blur',function(e, t){
   			window.setTimeout(function(){
   				if(me.closed == true){
   					Ext.fly(me.calendarContainer).hide();
   				}
   				me.closed = true;
   			}, 200);
		});
		Ext.get(this.showId).on('click',function(){
			    //日历显示在 x y 坐标;
			    var x=Ext.get(me.showId).getX();
			    var y=Ext.get(me.showId).getY();
		        me.show(x,y+20);
		        ssh.util.iframe(Ext.fly(me.calendarContainer));
		        Ext.fly(me.calendarContainer).show();
		        var z = Ext.fly(me.calendarContainer);
		    });
		    if(this.module == "XueXB"){
		    	Ext.get(this.calendarShow).on('click',function(){
		    		//日历显示在 x y 坐标;
				    var x=Ext.get(me.showId).getX();
				    var y=Ext.get(me.showId).getY();
			        this.show(x,y+20);
			        ssh.util.iframe(Ext.fly(me.calendarContainer));
		        	Ext.fly(me.calendarContainer).show();
			        var z = Ext.fly(me.calendarContainer);
			        Ext.fly(me.showId).focus();
				});
	        }
	        this.update();
	        //选择某日期,传给文本框
	        this.on('select',function(selectedDate){
	        	me.dateShow(selectedDate);
	        	me.hide();
	        });	
		},
	
			/**
			 * 年月导航 
			 * @param {}evt
			 */
			selectYearAndMonth : function(evt) {
				var target = evt.getTarget('td');
				if (target) {
					target = Ext.fly(target);
					if (target.hasClass('date-mp-year')) {
						this.yearMonthSelectorBody.select('.date-mp-year')
								.removeClass('date-mp-sel');
						this.selectedYear = target.first().dom.innerHTML
								.replace('', '');
						target.addClass('date-mp-sel');
					} else if (target.hasClass('date-mp-month')) {
						this.yearMonthSelectorBody.select('.date-mp-month')
								.removeClass('date-mp-sel');
						this.selectedMonth = target.first().dom.innerHTML
								.replace('', '');
						target.addClass('date-mp-sel');
					}
				}
				evt.stopEvent();
			},
			/**
			 * 选择了日历的某个日期
			 * @param {} evt
			 */
			dateSelect : function(evt) {
				this.body.select('td').removeClass('date-selected');
				var b = this.calendarContainer;
				// **********
				// **********
				if(evt.target.offsetParent.className == 'prevday'){
					return;
				}else if(evt.target.offsetParent.className == 'nextday'){
					return;
				}else{
				// **********
				// **********
					var td = Ext.fly(evt.getTarget('td'));
					if (td) {
						td.addClass('date-selected');
						var noThisMonth = false;
						if (td.hasClass('prevday')) {
							this.naviDate = this.naviDate.add(Date.MONTH, -1);
							noThisMonth = true;
							return;
						}
						if (td.hasClass('nextday')) {
							this.naviDate = this.naviDate.add(Date.MONTH, 1);
							noThisMonth = true;
							return;
						}
						// **********
						// **********
						if(this.module == 'xueXB'){
							var nowMonth = '';
							if(Ext.isIE){
								var buttonShow = this.btnMonthYear.dom.innerText.split('');
							}else{
								var buttonShow = this.btnMonthYear.dom.childNodes[0].textContent.split('');
							}
							if(buttonShow[6] != '月'){
								nowMonth = buttonShow[5] + buttonShow[6];
							}else{
								nowMonth = buttonShow[5];
							}
							if(nowMonth != this.today.getMonth() + 1){
								this.naviDate = this.naviDate.add(Date.MONTH, 1);
								noThisMonth = false;
							}
							if(Ext.isIE){
								if(this.today.getDate() > evt.target.innerText){
									this.naviDate.setMonth(this.today.getMonth()+1);
								}
							}else{
								if(this.today.getDate() > evt.target.textContent){
									this.naviDate.setMonth(this.today.getMonth()+1);
								}
							}	
						}
						// **********
						// **********
						this.naviDate.setDate(td.first().dom.innerHTML);
						// 不是当前月就载入那个月数据
						if (noThisMonth) {
							this.loadData(this.naviDate, this.type);
						}
						if(this.type=='zh_w'){
						this.fireEvent('select', this.naviDate.clone());
						}else if(this.type=='UK'){
							this.fireEvent('select',this.naviDate.format('Y/m/d'));
						}
					}
					evt.stopEvent();
				}	
			},
			/**
			 * 显示 导航年月选择器
			 */
			showYMSelect : function(type) {
				this.yearMonthNavi = this.naviDate.clone();
				var startMonth = 3;
				var startYear = this.yearMonthNavi.getFullYear() - 5;
				this.selectedYear = this.yearMonthNavi.getFullYear();
				if (type == 'zh_w') {
					this.selectedMonth = this.yearMonthNavi.getMonth() + 1;
				} else if (type == 'UK') {
					this.selectedMonth = this.yearMonthNavi.getMonth() + 1;
				}
				this.loadYearMonthData(this.yearMonthNavi);
				this.yearMonthSelector.style.display = '';
				Ext.get(this.yearMonthSelector).setXY(Ext
						.get(this.calendarContainer).getXY());
				Ext.get(this.yearMonthSelector).slideIn('t', {
							duration : .2
						});
			},
			/**
			 * 隐藏年月导航
			 */
			hideYMSelect : function() {
				Ext.get(this.yearMonthSelector).slideOut('t', {
							duration : .2
						});
			},
			/**
			 * 前后五年
			 * @param {}navi
			 */
			loadYearMonthData : function(navi) {
				var startYear = navi.getFullYear() - 5;
				var naviYear = this.selectedYear;
				var naviMonth = this.selectedMonth;
				this.yearMonthSelectorBody.select('.date-mp-year a').each(
						function(el) {
							el.update((startYear++));
							if (el.dom.innerHTML == naviYear)
								el.parent().addClass('date-mp-sel');
							else
								el.parent().removeClass('date-mp-sel');
						});
				this.yearMonthSelectorBody.select('.date-mp-month a').each(
						function(el) {
							if (el.dom.innerHTML == naviMonth)
								el.parent().addClass('date-mp-sel');
							else
								el.parent().removeClass('date-mp-sel');
						});
			},
			/**
			 * 选择当前月的某一天
			 * @param {}date
			 */
			selectDate : function(date) {
				this.body.select('td').removeClass('date-selected');
				this.body.select('td').each(function(el) {
							if (el.hasClass('prevday')
									|| el.hasClass('nextday'))
								return;
						});
			},
			/**
			 * 载入当前月日历 
			 * days总天数 
			 * firstOfMonth第一天 
			 * firstWeek第一周 
			 * beforeMonth上一个月
			 * @param {}currentMonthDate
			 */
			loadData : function(currentMonthDate, type) {
				var weekName = '';
				if (type == 'zh_w') {
					this.btnMonthYear.update(currentMonthDate.format('Y年m月'));
					weekName = ['日', '一', '二', '三', '四', '五', '六'];
				} else if (type == 'UK') {
					this.btnMonthYear.update(currentMonthDate.format('F Y'));
					weekName = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
				}
				var days = currentMonthDate.getDaysInMonth();
				var firstOfMonth = currentMonthDate.getFirstDateOfMonth();
				if(type == 'zh_w'){
					this.btnMonthYear.update(currentMonthDate.getFullYear()+'年'+(currentMonthDate.getMonth()+1)+'月');
				}
				var firstWeek = firstOfMonth.getDay();
				// 第一天就是周日，多显示上月一周
				if (firstWeek == 0) {
					firstWeek = 7;
				}
				var beforeMonth = currentMonthDate.add(Date.MONTH, -1);
				// 和当前月第一天同一星期的上个月日期,或多显示一周过度
				var beforeMonthDate = beforeMonth.getDaysInMonth() - firstWeek;

				// 日历当前表格的所有行数据
				var trs = [];
				var tr = {
					tag : 'tr',
					cn : []
				};
				var j = 0;
				while (j <= 7) {
					for (var j = 0; j < 7; j++) {
						tr.cn.push({
									tag : 'th',
									cn : [{
												tag : 'span',
												html : weekName[j]
											}]
								});
					}
					if (j = 7) {
						trs.push(tr);
						tr = {
							tag : 'tr',
							cn : []
						};
					}
					++j;
				}
				var i = 0;
				// 和当前月第一天同一星期的上个月日期 放入当前行
				for (; i < firstWeek; i++) {
					tr.cn.push({
						tag : 'td',
						cls : 'prevday',
						cn : [{
							tag : 'a',
							hideFocus : 'on',
							href : '#',
							onclick : 'return false',
							html : ++beforeMonthDate
							}]
					});
				}
				// 当前月的日期
				var current = 1;	
//				var inThisMonth = (currentMonthDate.format('Y-m') == this.today
//						.format('Y-m'));
				var inThisMonth = (currentMonthDate.getMonth() == this.today.getMonth());
				// 当前月的处理，每周新开一行
				while (current <= days) {
					// 新的一周开始了
					if (i % 7 == 0) {
						trs.push(tr);
						tr = {
							tag : 'tr',
							cn : []
						};
					}
					var todayCls = '';
					// 是否今天
					if (inThisMonth && current == this.today.getDate())
						todayCls = 'date-today';
					// 放入当前周
					tr.cn.push({
								tag : 'td',
								cls : todayCls,
								cn : [{
											tag : 'a',
											hideFocus : 'on',
											href : '#',
											onclick : 'return false',
											html : current++
										}]
							});
					++i;
				}
				// 恰好上月结束完整一周
				if (i % 7 == 0) {
					trs.push(tr);
					tr = {
						tag : 'tr',
						cn : []
					};
				}
				// 下月多显示一下或者和本月最后一天同一周的下月日期显示
				var nextMonth = 7 - i % 7;
				for (var i = 1; i <= nextMonth; i++) {
					tr.cn.push({
								tag : 'td',
								cls : 'nextday',
								cn : [{
											tag : 'a',
											hideFocus : 'on',
											href : '#',
											onclick : 'return false',
											html : i
										}]
							});
				}
				trs.push(tr);
				if (Ext.isIE) {
					while (this.body.dom.firstChild) {
						Ext.fly(this.body.dom.firstChild).remove();
					}
					Ext.DomHelper.append(this.body, trs);

				} else {
					var xx = this.naviDate.getDate();;
					Ext.DomHelper.overwrite(this.body, trs);
				}
				this.selectDate(2);
				// **********
				// **********
				if(this.module == 'xueXB'){
					var newYear = currentMonthDate.getFullYear();
					var newMouth = currentMonthDate.getMonth()+1;
					var newDay = currentMonthDate.getDate();
					var nowYear = this.today.getFullYear();
					var nowMouth = this.today.getMonth()+1;
					var nowDay = this.today.getDate();
					if(newYear != nowYear){
						this.selectOtherMouth(0);
					}else if(newMouth != nowMouth){
						if(days - nowDay < 15 && newMouth == nowMouth + 1){
							this.selectOtherMouth(nowDay);
						}else{
							this.selectOtherMouth(0);
						}
					}else{
						this.canSelectDate(days);
					}
				}
				this.holidaysChangeColor();
				// **********
				// **********
			},
			/**
			 * 日历显示的x,y位置
			 * 
			 * @param {}x
			 * @param {}y
			 */
			show : function(x, y) {
				this.calendarContainer.style.display = '';
				Ext.get(this.calendarContainer).setLocation(x, y);
			},
			/**
			 * 隐藏
			 */
			hide : function() {
				this.calendarContainer.style.display = 'none';
			},
			/**
			* 取系统时间
			*/
			date : function(){
				var xmlHttp = false;
				if(Ext.isIE6){
					try {
						xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
					} catch (e) {
					try {
   						 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e2) {
						 xmlHttp = false;
					}
					}
				}else{
					if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
						var activeX = ['MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'];       
						try {
				        	    xmlHttp = new XMLHttpRequest();   
				        	} catch(e) {
				        	    for (var i = 0; i < activeX.length; i++) {              
				        	        try {
				       	             xmlHttp = new ActiveXObject(activeX[i]);                        
				       	             break;
				      	          } catch(e) {}
				      	      }
				        } 
					}
				}
				xmlHttp.open('GET', '', false);
				xmlHttp.setRequestHeader("Range", "bytes=-1");
				xmlHttp.send(null);
				var today = new Date(xmlHttp.getResponseHeader('Date'));
				return today;
			},
			
			/**
			* 修改
			*/
			update: function(){
			/*	this.hideDiv = Ext.fly(this.formId).createChild({
					tag: 'div',
					name: 'name'
				});*/
			},
			
			/**
			* 设定可以选择的时间
			*/
			canSelectDate: function(days){
				var year = this.today.getFullYear();
				var mouth = this.today.getMonth()+1;
				var date = this.today.getDate();
				var max = 0;
				
				var value = '';
				var text = '';
				
				max = days;
				var count = -100;
				for(var i=1;i<this.body.dom.childNodes.length;i++){
					for(var j=0;j<7;j++){
						value = this.body.dom.children[i];
						text = value.children[j];
						if(Ext.isIE){
							if(text.innerText == date && text.className != 'prevday' && count < -50){
								count = 0;
							}
						}else{
							if(text.textContent == date && text.className != 'prevday' && count < -50){
								count = 0;
							}
						}
						
						if(count > 14 || count < 0){
							text.title = this.tipsText;
							text.className = 'nextday';
						}else{
							if(text.className == 'nextday'){
								text.className = '';
							}
						}
						count += 1;
					}
				}
			},
			
			/**
			* 设定其他月份的情况
			*/
			selectOtherMouth: function(count){
				var cou = -100;
				for(var i = 1; i < this.body.dom.childNodes.length; i++){
					for(var j = 0; j < 7; j++){
						value = this.body.dom.children[i];
						text = value.children[j];
						if(Ext.isIE){
							if(count !=0 && text.innerText >= count && cou<-50){
								cou = text.innerText - count;
							}
						}else{
							if(count !=0 && text.textContent >= count && cou<-50){
								cou = text.textContent - count;
							}
						}
						
						text.className = '';
						if(cou > 14 || cou < -1){
							text.title = this.tipsText;
							text.className = 'nextday';
						}else{
							if(text.className == 'nextday'){
								text.className = '';
							}
						}
						cou += 1;
					}
				}		
			},
			
			
			/**
			* 周末颜色修改
			*/
			holidaysChangeColor: function(){
				for(var i=1;i<this.body.dom.childNodes.length;i++){
					for(var j=0;j<7;j++){
						var value = this.body.dom.children[i];
						var text = value.children[j];
						if(text.className != 'prevday' && text.className != 'nextday'){
							if(j==0 || j==6){
								text.className = 'holidays';
							}
						}
					}
				}
			},
			
			/**
			* 今天按钮
			*/
			todayButton: function(){
				for(var i=1;i<this.body.dom.childNodes.length;i++){
					for(var j=0;j<7;j++){
						var value = this.body.dom.children[i];
						var text = value.children[j];
						if(text.className != 'prevday' && text.className != 'nextday'){
							if(Ext.isIE){
								if(text.innerText == this.today.getDate()){
									text.className = text.className + ' date-selected';
								}
							}else{
								if(text.textContent == this.today.getDate()){
									text.className = text.className + ' date-selected';
								}
							}
						}
					}
				}
				this.naviDate.setFullYear(this.today.getFullYear());
				this.naviDate.setMonth(this.today.getMonth());
				this.naviDate.setDate(this.today.getDate());
				var ax = this.naviDate.toLocaleString();
				var zhj = 0;	
			},
			
			/**
			* 时间显示
			*/
			dateShow: function(d){
				if(this.module == 'xueXB'){
					if(d.getDate() < this.today.getDate()){
						d.setMonth(this.today.getMonth() + 1);
					}else if(d.getDate() == this.today.getDate()){
						d.setMonth(this.today.getMonth());
					}
				}
				var dateForm = this.dateForm.split(',');
				var ret=d.getFullYear()+dateForm[0];
				ret+=("00"+(d.getMonth()+1)).slice(-2)+dateForm[1]
				ret+=("00"+d.getDate()).slice(-2)+dateForm[2]
				if(this.isShowTime == true){
					ret+= ' ' + ("00"+d.getHours()).slice(-2)+dateForm[3]
					ret+=("00"+d.getMinutes()).slice(-2)+dateForm[4]
					ret+=("00"+d.getSeconds()).slice(-2)+dateForm[5]
				}
				Ext.fly(this.calendarShow).dom.value = ret;
				this.textShow.dom.defaultValue = ret;
				this.textShow.dom.value = ret;
			}
				
		/*	dateShow: function(selectedDate){
				var date = '';
				var time = '';
				var dateSymbol = [];
				var timeSymbol = [];
				var count = 0;
				Ext.fly(this.calendarShow).dom.value = '';
				// 日期格式
				if(this.dateForm == null || this.dateForm == ''){
					if(this.isShowTime == true){
						Ext.fly(this.calendarShow).dom.value = selectedDate.toLocaleString();
					}else{
						Ext.fly(this.calendarShow).dom.value = selectedDate.toLocaleDateString();
					}
					
					return;
				}
				if(this.dateForm.split(' ')[0] != null){
					date = this.dateForm.split(' ')[0].split('');
					for(var i = 0; i < date.length; i++){
						if(date[i] != 'y' && date[i] != 'M' && date[i] != 'd'){
							dateSymbol = date[i];
						}
					}
					date = this.dateForm.split(' ')[0].split(dateSymbol);
					for(var i = 0; i < date.length; i++){
						if(date[i] == 'yyyy'){
							date[i] = selectedDate.getFullYear();
						}else if(date[i] == 'yy'){
							var a = selectedDate.getFullYear() + '';
							date[i] = a.split('')[2] + a.split('')[3];
						}else if(date[i] == 'MM'){
							date[i] = selectedDate.getMonth() + 1;
						}else if(date[i] == 'dd'){
							var ss = selectedDate.getDate();
							date[i] = selectedDate.getDate();
						}
					}
					date = date[0] + dateSymbol + date[1] + dateSymbol + date[2];
				}
					
				if(this.dateForm.split(' ')[1] != null){
					time = this.dateForm.split(' ')[1].split('');
					for(var i = 0; i < time.length; i++){
						if(time[i] != 'h' && time[i] != 'm' && time[i] != 's'){
							timeSymbol = time[i];
						}
					}
					var zs = this.dateForm.split(' ')[1];
					time = this.dateForm.split(' ')[1].split(timeSymbol);
					for(var i = 0; i < time.length; i++){
						if(time[i] == 'hh'){
							time[i] = selectedDate.getHours();
						}else if(time[i] == 'mm'){
							time[i] = selectedDate.getMinutes();
						}else if(time[i] == 'ss'){
							time[i] = selectedDate.getSeconds();
						}
					}
					time = time[0] + timeSymbol + time[1] + timeSymbol + time[2];
				}
				if(this.isShowTime == true){
						Ext.fly(this.calendarShow).dom.value = date + ' ' + time;
					}else{
						Ext.fly(this.calendarShow).dom.value = date;
					}
				
			}	*/
});
/**
 * 
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 张建
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Anchor = Ext.extend(Ext.util.Observable,{
	scrollTask:null, //滚动任务
	runner:null, //执行者
	page:null, //页面
	section:null, //目标
	offsetY:20, //偏移
	
	// 创建构造方法
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
        this.initUI();
        this.initEvents();
    },

    /**
     * 初始化界面
     */
    initUI:function(){
    	var me = this;
		this.page = Ext.get(Ext.isChrome ? document.body : document.documentElement);    	
		for(var i=0; i < this.items.length; i++)
		{
			var shortcut = this.items[i].shortcut;	
			var section =  this.items[i].section;
			if(shortcut.indexOf('.') != -1)
			{				
				Ext.select(shortcut).each(function(item)
				{
					me.bindItem(item, section);				
				});
			}else
			{
				me.bindItem(Ext.fly(shortcut), section);								
			}
		}    	    	
    },
     
     /**
     * 初始化事件
     */
	initEvents:function(){
		var me = this;		
        this.scrollTask = {
			run: function(){
				try
				{
					var sectionTop =  me.section.getTop();
					var scrollTop = me.page.getScroll().top;																		
					if(sectionTop > scrollTop)
					{
						var top = scrollTop + me.offsetY;
						if(sectionTop < top)
						{
							me.scrollTo(sectionTop);
						}else
						{
							me.scrollTo(top);
						}									
					}else if(sectionTop < scrollTop)
					{
						var top = scrollTop - me.offsetY;
						if(sectionTop > top)
						{
							me.scrollTo(sectionTop);
						}else
						{
							me.scrollTo(top);
						}						
					}					
					else
					{
						me.runner.stop(me.scrollTask);
					}
				}catch(e)
				{
					
				}
			},
			interval: 0.1
			};
				
		this.runner = new Ext.util.TaskRunner();		
	},

	/**
	 * 绑定项
	 * @param {} item
	 */	
	bindItem:function(item, section) {
		var me = this;
		item.dom.setAttribute('tag', section);		
		item.on('click', function(e){
			e.preventDefault();		 
			tag =  this.getAttribute('tag');
			me.section = tag.indexOf('.') != -1 ? Ext.getBody().child(tag) : Ext.get(tag);
			me.runner.start(me.scrollTask);			
		})		
	},
	/**
	 * 滚动到
	 * @param {} value
	 */
	scrollTo: function(value)
	{
		var oldTop, newTop;
		oldTop = this.page.getScroll().top;
		this.page.scrollTo('top', value);
		newTop = this.page.getScroll().top;
		if(oldTop == newTop)
		{
			this.runner.stop(this.scrollTask);
		}
	}		
});   
/**
 * 树形控件
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns("ssh");
ssh.Tree = Ext.extend(Ext.util.Observable, {
	ajaxEnd: true,
	childItems: '',
	
	constructor : function(config) {
		Ext.apply(this, config);
		this.initUI();
		this.initEvents();
	},
	
	/**
	* 初始化界面
	*/ 
	initUI : function() {
		this.mode = Ext.isEmpty(this.mode) ? '' : this.mode;
		var Up = Ext.fly("tree-div");
		Up.addClass(this.cls);
		
	},
	
	/**
	* 初始化事件
	*/
	initEvents : function() {
		var me = this;
		this.createParentNode(this.items[0]);
		Ext.fly('btnGet').on('click', function(){
			var zse = '';
			var s = Ext.select('input[name = ' + me.name + ']');
			for(var i = 0; i < s.elements.length; i++){
				if(s.elements[i].checked == true){
					zse += s.elements[i].value + ';';
				}
			}
			alert('sub:  ' + zse);
			var xxx = 0;
		});
	},
	
	/**
	* Ajax
	*/
	ajax: function(value, t){
		var items = '';
		var ur = '?value=' + value;
		if(this.isAjaxBack == true){
			var me = this;
			var zh = t.src;
			var className = t.className;
			t.className = 'loadingImg';
			Ext.Ajax.request({
				url: me.url + ur,
				success: function(response, opts) {
					t.className = className;
					if(response.responseText == ''){
						me.changeImg(t);
						return;
					}
					me.childItems = '';
					me.childItems = Ext.util.JSON.decode(response.responseText);
					me.addNode(value);
					me.changeImg(t);
	     		},
	   			failure: function(response, opts) {
	   				console.log('服务端失效的状态代码： ' + response.status);
	   			}
			});
		}	
	},
	
	/**
	* 添加节点
	*/
	addNode: function(value){
		var childNodes = '';
		var me = this;
		if(this.childItems != null){
			var div = Ext.fly(Ext.select('div[name = ' + value + ']').elements[0].parentNode.parentNode);
			var count = 0;
			var img = '<div class="white"></div>';
			for(var i = 1; i < 100; i++){
				if(div.dom.parentNode.id == 'tree-div'){
					count = i;
					break;	
				}else{
					div = Ext.fly(div.dom.parentNode);
				}
			}
			var div1 = Ext.select('div[name = ' + value + ']').elements[0];
			var div2 = Ext.fly(div1.parentNode.parentNode);
			var src  = '';
			if(Ext.isIE && this.mode == ''){
				if(count != 1){
					src = div2.dom.childNodes[0].childNodes[div2.dom.childNodes[0].childNodes.length - 3].className;
				}else{
					src = div2.dom.childNodes[0].childNodes[div2.dom.childNodes[0].childNodes.length - 2].className;
				}
			}else{
				if(count != 1){
					src = div2.dom.childNodes[0].childNodes[div2.dom.childNodes[0].childNodes.length - 4].className;
				}else{
					src = div2.dom.childNodes[0].childNodes[div2.dom.childNodes[0].childNodes.length - 3].className;
				}
			}
			for(var i = 1; i < count; i = i + 2){
				if(src == 'lastParentClose' || src == 'folderClose'){
					img += '<div class="white"></div>';
				}else{
					img += '<div class="straightLine"></div>';
				}
			}
			var child = Ext.fly(div2).createChild({
				tag: 'ul',
				cls: 'childDiv'
			});
			if(Ext.isIE && this.isAjaxBack == false){this.childItems.length = this.childItems.length - 1}
			for(var i = 0; i < this.childItems.length; i++){
				var im = img;
				if(this.childItems[i].isChild == 'false' && i != this.childItems.length - 1){
					img = img + '<div class="parentClose" name="'+this.childItems[i].value
					+'"></div><div class="folderClose"></div>';
				}else if(this.childItems[i].isChild == 'false' && i == this.childItems.length - 1){
					img = img + '<div class="lastParentClose" name="'+this.childItems[i].value
					+'"></div><div class="folderClose"></div>';
				} 
				if(this.childItems[i].isChild == 'true' && i != this.childItems.length - 1){
					img = img + '<div class="child" name="'+this.childItems[i].value
					+'"></div><div class="file"></div>';
				}else if(this.childItems[i].isChild == 'true' && i == this.childItems.length - 1){
					img = img + '<div class="lastChild" name="'+this.childItems[i].value
					+'"></div><div class="file"></div>';
				}
				var div = child.createChild({
					tag: 'div'
				});
				if(this.mode != '' && this.mode != null) {
					var htm = '<input type="'+this.mode+'" value="' + this.childItems[i].value + '" name="'+ this.name +'"/>';
				} else if ([(this.mode == '') || (this.mode == null)] && this.childItems[i].isChild != false) {
					var htm = ' ';
				}
				if(this.childItems[i].isChild == 'true'){
					var a = div.createChild({
						tag: 'li',
						html: img + htm
					});
					a.createChild({
						tag: 'a',
						href: Ext.isEmpty(this.childItems[i].href) ? '#' : this.childItems[i].href,
						onclick: Ext.isEmpty(this.childItems[i].onclick) && Ext.isEmpty(this.childItems[i].href) ? 'return false;' : this.childItems[i].onclick,
						html:  this.childItems[i].title
					});
				}else{
					var a = div.createChild({
						tag: 'li',
						html: img + htm
					});
						
					a.createChild({
						tag: 'a',
						href: Ext.isEmpty(this.childItems[i].href) ? '#' : this.childItems[i].href,
						onclick: Ext.isEmpty(this.childItems[i].onclick) && Ext.isEmpty(this.childItems[i].href) ? 'return false;' : this.childItems[i].onclick,
						html:  this.childItems[i].title
					});
				}
				
				if(Ext.isIE && this.mode == ''){
					count = a.dom.childNodes.length - 3;
				}else{
					count = a.dom.childNodes.length - 4;
				}
				Ext.fly(a.dom.childNodes[count]).on('click', function(e, t){
					var value = Ext.fly(t.parentNode.childNodes[count]).getAttribute('name');
					var div = Ext.fly(t.parentNode.parentNode);
					var img = t.className;
					if(div.dom.childNodes[1] == null && img != 'child' && img != 'lastChild'){
						me.ajax(value, t);
					}else{
						me.changeImg(t);
					}
				});
				Ext.fly(div2.dom.parentNode.childNodes[div2.dom.parentNode.childNodes.length - 2]).on('click', function(e, t){
					if(me.mode != 'checkbox'){
						return;
					}
					if(t.checked == true){
						var zh = Ext.fly(t.parentNode.parentNode).select('input:nth-child(n)');
						for(var i = 0; i < zh.elements.length; i++){
							zh.elements[i].checked = true;
						}
					}else{
						var zh = Ext.fly(t.parentNode.parentNode).select('input:nth-child(n)');
						for(var i = 0; i < zh.elements.length; i++){
							zh.elements[i].checked = false;
						}
					}
				});
				img = im;
				html = '';
			}
			
		}	
	},
	
	/**
	* 图片状态修改
	*/
	changeImg: function(t){
		var src = t.className;
		if(t.parentNode.parentNode.childNodes[1] == null){
			return;
		}
		var fileSrc = '';
		if(t.parentNode.childNodes.length == 3){
			fileSrc = t.parentNode.childNodes[t.parentNode.childNodes.length - 2].className;
		}else{
			fileSrc = t.parentNode.childNodes[t.parentNode.childNodes.length - 3].className;
		}
		if(fileSrc == 'folderClose'){
			if(t.parentNode.childNodes.length == 3){
				t.parentNode.childNodes[t.parentNode.childNodes.length - 2].className = 'folderOpen';
			}else{
				t.parentNode.childNodes[t.parentNode.childNodes.length - 3].className = 'folderOpen';
			}
		}else if(fileSrc == 'folderOpen'){
			if(t.parentNode.childNodes.length == 3){
				t.parentNode.childNodes[t.parentNode.childNodes.length - 2].className = 'folderClose';
			}else{
				t.parentNode.childNodes[t.parentNode.childNodes.length - 3].className = 'folderClose';
			}
		}
		// 处于中间的父节点
		if(src == 'parentClose'){
			t.className = 'parentOpen';
			Ext.fly(t.parentNode.parentNode.childNodes[t.parentNode.parentNode.childNodes.length - 1]).setStyle('display','block');
		}else if(src == 'parentOpen'){
			t.className = 'parentClose';
			if(this.isDeletChild == true){
				Ext.fly(t.parentNode.nextElementSibling).remove();
			}else{
				Ext.fly(t.parentNode.parentNode.childNodes[1]).setStyle('display','none');
			}
		}
		// 处于末尾的父节点
		if(src == 'lastParentClose'){
			t.className = 'lastParentOpen';
			Ext.fly(t.parentNode.parentNode.childNodes[1]).setStyle('display','block');
		}else if(src == 'lastParentOpen'){
			t.className = 'lastParentClose';
			if(this.isDeletChild == true){
				Ext.fly(t.parentNode.nextElementSibling).remove();
			}else{
				Ext.fly(t.parentNode.parentNode.childNodes[1]).setStyle('display','none');
			}
		}
	},
	
	/**
	* 创建最上层节点
	*/
	createParentNode: function(item){
		var me = this;
		var it = '';
		var mode = '';
		
		var ul = Ext.fly(this.renderTo).createChild({
			tag: 'ul'
		});
		
		var li = ul.createChild({
			tag: 'li'
		});
		
		var operationDiv = li.createChild({
			tag: 'div',
			cls: 'lastParentClose',
			name: item.value
		});
		
		var showDiv = li.createChild({
			tag: 'div',
			cls: 'folderClose'
		});
		
		if(this.mode != '' && this.mode != null){
			mode = li.createChild({
				tag: 'input',
				type: me.mode,
				name: 'nodes',
				value: 'one'
			});
		}
		
		var a = li.createChild({
			tag: 'a',
			html: item.title
		});
		
		this.addChildNode(item);
		Ext.select('ul[class = childDiv]').setStyle('display', 'none');
		operationDiv.on('click', function(e, t){
			var value = Ext.fly(t.parentNode.childNodes[0]).getAttribute('name');;
			var div = Ext.fly(t.parentNode.parentNode);
			var img = t.className;
			if(div.dom.childNodes[1] == null && img != 'new.png' && me.isAjaxBack == true){
				me.ajax(value, t);
			}else{
				me.changeImg(t);
			}
		});
		if(mode != ''){
			mode.on('click', function(e, t){
				if(me.mode != 'checkbox'){
					return;
				}
				if(t.checked == true){
					var zh = Ext.fly(t.parentNode.parentNode).select('input:nth-child(n)');
					for(var i = 0; i < zh.elements.length; i++){
						zh.elements[i].checked = true;
					}
				}else{
					var zh = Ext.fly(t.parentNode.parentNode).select('input:nth-child(n)');
					for(var i = 0; i < zh.elements.length; i++){
						zh.elements[i].checked = false;
					}
				}
			});
		}
	},
	
	/**
	* 创建子节点
	*/
	addChildNode: function(item){
		this.childItems = item.items;
		this.addNode(item.value);
		if(this.isAjaxBack == false){
			for(var i = 0; i < item.items.length; i++){
				var it = item.items[i];
				if(item.items[i].items != null){
					this.addChildNode(item.items[i]);
				}
			}
		}
	}
});
/**
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Player = Ext.extend(Ext.util.Observable,{
	isShow: false,
	play: true,
	loop: true,
	mimeType: 'application/x-shockwave-flash',
	/**
	* 构造方法
	*/
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
       	this.initUI();
    },
    
    /**
    * 初始化界面
    */
    initUI: function(){
    	// 默认值设置
    	this.width = Ext.isEmpty(this.width) ? Ext.fly(this.renderTo).dom.offsetWidth : this.width;
    	this.height = Ext.isEmpty(this.height) ? Ext.fly(this.renderTo).dom.offsetHeight : this.height;
    	if(this.height < 40){
    		this.height = this.width * 3/4;
    	}
    	this.cls = Ext.isEmpty(this.cls) ? 'flash-default' : this.cls;
    	this.type = Ext.isEmpty(this.type) ? this.playerAddress.split('.')[this.playerAddress.split('.').length - 1] : this.type;
    	this.playerType = Ext.isEmpty(this.type) ? '' : this.playerType;
    	this.womde = 'opaque';
    	
    /*	var playe = this.playerType.split(',');
    	for(var i=0; i<playe.length; i++){
    		if(playe[i] == 'automatic'){this.play = true;}
    		if(playe[i] == 'cycles'){this.loop = true;}
    		if(playe[i] == 'transparent'){this.womde = 'transparent';}
    	}
    */	
    	// 元素创建
    	// div: 控件最外层框架 
    	this.div = Ext.fly(this.renderTo).createChild({
    		tag: 'div',
    		cls: this.cls
    	});
     	// showDiv: flash播放层
    	this.showDiv = this.div.createChild({
    		tag: 'div',
    		cls: 'showDiv'
    	});
    //	this.showDiv.setWidth(this.width);
    //	this.showDiv.setHeight(this.height);
    	if(this.type == 'swf'){
    		this.flash = this.showDiv.createChild({
	    		tag: 'embed',
	    		id: this.flashId,
	    		width: this.width,
	    		height: this.height,
	    		quality: 'high',
	    		name: this.flashId,
	    		src: this.playerAddress,
	    		womde: this.womde,
	    		play: this.play,
	    		loop: this.loop,
	    		type: 'flv-application/octet-stream'
	    	});
    	}else if(this.type == 'flv'){
    		var html = '<param name="movie" value="' + this.player + '?file=' + this.playerAddress 
    		+ '" /><param name="allowfullscreen" value="true" />';
    		if(this.loop == false){
    			html += '<param name="loop" value="false" />';
    		}
    		this.obj = this.showDiv.createChild({
    			tag: 'object',
    			type: 'application/x-shockwave-flash',
    			width: this.width,
    			height: this.height,
    			wmode: this.womde,
    			data: this.player + '?file=' + this.playerAddress,
    			html: html
    		});
    	}else if(this.type == 'gif' || this.type == 'jpg'){
    		// 图片显示
	    	this.img = this.showDiv.createChild({
				tag: 'img',
				src: this.playerAddress,
				alt: this.imgTitle,
				width: this.width,
				height: this.height
			});
		}
    	//video/x-msvideo				   .avi 
    	//application/x-shockwave-flash    .swf
    	//flv-application/octet-stream     .flv
	 }
})    
/**
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Code = Ext.extend(Ext.util.Observable,{
	
	/**
	* 构造方法
	*/
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
       	this.initUI();
       	this.initEvents();
    },
    
    /**
    * 初始化界面
    */
    initUI: function(){
    	// 默认值设置
    	this.width = Ext.isEmpty(this.width) ? Ext.fly(this.renderTo).dom.offsetWidth : this.width;
    	this.height = Ext.isEmpty(this.height) ? Ext.fly(this.renderTo).dom.offsetHeight : this.height;
    	this.cls = Ext.isEmpty(this.cls) ? 'code-default' : this.cls;
    	
    	// 创建元素
    	// 控件外框架
   		this.div = Ext.fly(this.renderTo).createChild({
    		tag: 'div',
    		cls: this.cls
    	});
    	// 文本输入框
 /*    	this.text = this.div.createChild({
    		tag: 'textarea',
    		id: 'textarea',
    		cls: 'text'
    	});*/
    	this.iframe = this.div.createChild({
	    		tag: 'div',
	    		width: this.width,
	    		height: this.height,
	    		cls: 'text'
	    });
/*	    this.button = this.div.createChild({
    		tag: 'button',
    		html: 'aaa'
    	});
    	this.res = this.div.createChild({
    		tag: 'button',
    		html: 'bbb'
    	});
*/    	
//    	this.res.setStyle('display', 'none');
//    	this.iframe.setStyle('display', 'none');
//    	this.text.setWidth(this.width);
//    	this.text.setHeight(this.height);
    	this.iframe.setWidth(this.width);
    	this.iframe.setHeight(this.height);
    },
   	
   	/**
   	* 初始化事件
   	*/
   	initEvents: function(){
   		var me = this;
 /*    	this.button.on('click', function(){
   			me.text.setStyle('display', 'none');
    		me.button.setStyle('display', 'none');
    		me.iframe.setStyle('display', 'block');
    		me.res.setStyle('display', 'block');*/
    		// 获取输入的值
    		ssh.util.update(this.textValue, me.iframe);
//   	});
/*   	this.res.on('click', function(){
   			me.text.setStyle('display', 'block');
    		me.button.setStyle('display', 'block');
    		me.iframe.setStyle('display', 'none');
    		me.res.setStyle('display', 'none');
   		});*/
   	}
})    
/**
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Picture = Ext.extend(Ext.util.Observable,{
	
	/**
	* 构造方法
	*/
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
       	this.initUI();
       	this.initEvents();
    },
    
    /**
    * 初始化界面
    */
    initUI: function(){
    	// 默认值设置
    	this.width = Ext.isEmpty(this.width) ? Ext.fly(this.renderTo).dom.parentNode.offsetWidth : this.width;
    	this.height = Ext.isEmpty(this.height) ? Ext.fly(this.renderTo).dom.parentNode.offsetHeight : this.height;
    	this.cls = Ext.isEmpty(this.cls) ? 'flash-default' : this.cls;
    	if(this.height == 0){this.height = Ext.fly(this.renderTo).dom.offsetParent.offsetHeight - 31 };
    	if(this.height == 42 || this.height == -16){this.height = 40; };
   		if(this.height != 40){this.height = this.height - 31;}
    	var link = '';
    	if(this.linkMode == 'new'){
    		link = '_blank';
    	}
    	// 创建元素
    	// 控件外框架
    	this.div = Ext.fly(this.renderTo).createChild({
    		tag: 'div',
    		cls: this.cls
    	});
    	// 图片的超链接
    	this.a = this.div.createChild({
    		tag: 'a',
    		href: this.urlAddress,
    		target: link
    	});
    	// 图片显示
    	this.img = this.a.createChild({
			tag: 'img',
			src: this.imgUrl,
			alt: this.imgTitle
		}); 
		this.img.setStyle('position', 'relative');
		this.img.setStyle('left', '2000px');
		var me = this;
		this.img.on('load', function(e, t){
			var oldWidth = e.target.offsetWidth;
			var oldHeight = e.target.offsetHeight;
			var bi = oldHeight / oldWidth;
			if(oldWidth < me.width){
				me.width = oldWidth;
			}
			if(me.height / me.width > bi || me.height == 40 || me.height == -16){
				me.height = me.width * bi;
				me.width = me.width - 15;
			}else if(me.height / me.width < bi){
				me.width = me.height / bi;
			}
			if(Ext.isIE6){
				me.img.setStyle('width', me.width - 10 + 'px');
				me.img.setStyle('height', me.height - 10 + 'px');
			}else{
				me.img.setStyle('width', me.width + 'px');
				me.img.setStyle('height', me.height + 'px');
			}
			me.img.setStyle('left', 'auto');
		})
		// 显示图片标题
		this.tip = Ext.getBody().createChild({tag:'div', html:'', style:'position:absolute; color:#404040; font-size:12px; padding:2px; z-index:100; display:none; border:solid 1px black; background-color:white'});
	},
   	
   	/**
   	* 初始化事件
   	*/
   	initEvents: function(){
   		var me = this;
   		// 鼠标移动显示事件
   		if(Ext.isIE8 || !Ext.isIE){
	   		this.img.on('mousemove', function(e, t){
	   			me.tip.update(this.dom.alt);
	   			me.tip.setLeft(e.getPageX());
				me.tip.setTop(e.getPageY() + 22);
				me.tip.setStyle('display', 'block');
			});
	   		this.img.on('mouseout', function(e, t){
	   			me.tip.setStyle('display', 'none');
	   		});
   		}
   		this.img.on('blur', function(){
   			me.tip.setStyle('display', 'none');
   		})
   	}
})    
/**
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.millionCalendar = Ext.extend(Ext.util.Observable,{

	/**
	* 构造方法
	*/
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);
		this.initUI();
	},
    
    /**
    * 初始化界面
    */
    initUI: function(){
   // 	<div id="cal"><div id="top">公元&nbsp;<select></select>&nbsp;年&nbsp;<select></select>&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;农历<span></span>年&nbsp;[&nbsp;<span></span>年&nbsp;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="回到今天" title="点击后跳转回今天" style="padding:0px"></div><ul id="wk"><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li><b>六</b></li><li><b>日</b></li></ul><div id="cm"></div><div id="bm"><a target="_blank" onMouseDown="return c({'fm':'alop','title':this.innerHTML,'url':this.href,'p1':al_c(this),'p2':1})" href="javascript:void(0)">历史上的今天</a></div></div>
		var me = this;
		var xhtml = '<tr><td><div id="cal"><div id="top">公元&nbsp;&nbsp;<select>&nbsp;</select>&nbsp;年&nbsp;&nbsp;<select>&nbsp;</select>&nbsp;月&nbsp;'
		+'&nbsp;&nbsp;&nbsp;农历<span></span>年&nbsp;[&nbsp;<span></span>年&nbsp;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button"'
		+' value="回到今天" title="点击后跳转回今天" style="padding:0px"></div><ul id="wk"><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li>'
		+'<li><b>六</b></li><li><b>日</b></li></ul><div id="cm"></div><div id="bm"><a target="_blank" onMouseDown="return'
		+'" href="javascript:void(0)"></a></div></div>'
		+'<script id="script"></script></td></tr></table>';
		this.div = Ext.fly(this.renderTo).createChild({
			tag: 'div',
			cls: this.cls
		});
		var table = this.div.createChild({
			tag: 'table',
			html: xhtml, 
			cellspacing: 0, 
			cellpadding: 0 
		}) 
		Ext.fly('script').dom.value = this.initEvents();
/*		alert('1');  
		var tr = table.createChild({tag: 'tr'});
		alert('2');
		var td = tr.createChild({tag: 'td'});
		var div = td.createChild({tag: 'div', id: 'cal'});
		var topDiv = div.createChild({
			tag: 'div', 
			id: 'top',
			html: '公元&nbsp;<select></select>&nbsp;年&nbsp;<select></select>&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;农历<span></span>'
				+'年&nbsp;[&nbsp;<span></span>年&nbsp;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" style="padding:0px" title="点击后跳转回今天" value="回到今天">'
		});
		var ul = div.createChild({
			tag: 'ul', 
			id: 'wk',
			html: '<li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li><b>六</b></li><li><b>日</b></li>'
		});
		div.createChild({tag: 'div', id: 'cm'});
		var bmDiv = div.createChild({
			tag: 'div', 
			id: 'bm',
			html: '<a target="_blank" onMouseDown="return c({"fm":"alop","title":this.innerHTML,"url":this.href,"p1"'
			+':al_c(this),"p2":1})" href="javascript:void(0)"></a>'
		});
		td.createChild({tag: 'script', html: this.initEvents()});*/
	},
    
    /**
    * 初始化事件
    */
    initEvents: function(){
    	(function () {
			var T = navigator.userAgent.indexOf("MSIE") != -1 && !window.opera;
			function N(C) {
				return document.getElementById(C);
			}
			function S(C) {
				return document.createElement(C);
			}
			var Q = [19416, 19168, 42352, 21717, 53856, 55632, 91476, 22176, 39632, 21970, 19168, 42422, 42192, 53840, 119381, 46400, 54944, 44450, 38320, 84343, 18800, 42160, 46261, 27216, 27968, 109396, 11104, 38256, 21234, 18800, 25958, 54432, 59984, 28309, 23248, 11104, 100067, 37600, 116951, 51536, 54432, 120998, 46416, 22176, 107956, 9680, 37584, 53938, 43344, 46423, 27808, 46416, 86869, 19872, 42416, 83315, 21168, 43432, 59728, 27296, 44710, 43856, 19296, 43748, 42352, 21088, 62051, 55632, 23383, 22176, 38608, 19925, 19152, 42192, 54484, 53840, 54616, 46400, 46752, 103846, 38320, 18864, 43380, 42160, 45690, 27216, 27968, 44870, 43872, 38256, 19189, 18800, 25776, 29859, 59984, 27480, 21952, 43872, 38613, 37600, 51552, 55636, 54432, 55888, 30034, 22176, 43959, 9680, 37584, 51893, 43344, 46240, 47780, 44368, 21977, 19360, 42416, 86390, 21168, 43312, 31060, 27296, 44368, 23378, 19296, 42726, 42208, 53856, 60005, 54576, 23200, 30371, 38608, 19415, 19152, 42192, 118966, 53840, 54560, 56645, 46496, 22224, 21938, 18864, 42359, 42160, 43600, 111189, 27936, 44448, 84835];
			var K = "\u7532\u4e59\u4e19\u4e01\u620a\u5df1\u5e9a\u8f9b\u58ec\u7678";
			var J = "\u5b50\u4e11\u5bc5\u536f\u8fb0\u5df3\u5348\u672a\u7533\u9149\u620c\u4ea5";
			var P = "\u9f20\u725b\u864e\u5154\u9f99\u86c7\u9a6c\u7f8a\u7334\u9e21\u72d7\u732a";
			var L = ["\u5c0f\u5bd2", "\u5927\u5bd2", "\u7acb\u6625", "\u96e8\u6c34", "\u60ca\u86f0", "\u6625\u5206", "\u6e05\u660e", "\u8c37\u96e8", "\u7acb\u590f", "\u5c0f\u6ee1", "\u8292\u79cd", "\u590f\u81f3", "\u5c0f\u6691", "\u5927\u6691", "\u7acb\u79cb", "\u5904\u6691", "\u767d\u9732", "\u79cb\u5206", "\u5bd2\u9732", "\u971c\u964d", "\u7acb\u51ac", "\u5c0f\u96ea", "\u5927\u96ea", "\u51ac\u81f3"];
			var B = [0, 21208, 43467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758];
			var A = "\u65e5\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341";
			var F = ["\u6b63", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341", "\u5341\u4e00", "\u814a"];
			var D = "\u521d\u5341\u5eff\u5345";
			var W = {"0101":"*1\u5143\u65e6\u8282", "0214":"\u60c5\u4eba\u8282", "0305":"\u5b66\u96f7\u950b\u7eaa\u5ff5\u65e5", "0308":"\u5987\u5973\u8282", "0312":"\u690d\u6811\u8282", "0315":"\u6d88\u8d39\u8005\u6743\u76ca\u65e5", "0401":"\u611a\u4eba\u8282", "0501":"*1\u52b3\u52a8\u8282", "0504":"\u9752\u5e74\u8282", "0601":"\u56fd\u9645\u513f\u7ae5\u8282", "0701":"\u4e2d\u56fd\u5171\u4ea7\u515a\u8bde\u8fb0", "0801":"\u5efa\u519b\u8282", "0910":"\u4e2d\u56fd\u6559\u5e08\u8282", "1001":"*3\u56fd\u5e86\u8282", "1224":"\u5e73\u5b89\u591c", "1225":"\u5723\u8bde\u8282"};
			var U = {"0101":"*2\u6625\u8282", "0115":"\u5143\u5bb5\u8282", "0505":"*1\u7aef\u5348\u8282", "0815":"*1\u4e2d\u79cb\u8282", "0909":"\u91cd\u9633\u8282", "1208":"\u814a\u516b\u8282", "0100":"\u9664\u5915"};
			function V(Z) {
				function d(k, j) {
					var i = new Date((31556925974.7 * (k - 1900) + B[j] * 60000) + Date.UTC(1900, 0, 6, 2, 5));
					return (i.getUTCDate());
				}
				function e(l) {
					var j, k = 348;
					for (j = 32768; j > 8; j >>= 1) {
						k += (Q[l - 1900] & j) ? 1 : 0;
					}
					return (k + c(l));
				}
				function b(i) {
					return (K.charAt(i % 10) + J.charAt(i % 12));
				}
				function c(i) {
					if (h(i)) {
						return ((Q[i - 1900] & 65536) ? 30 : 29);
					} else {
						return (0);
					}
				}
				function h(i) {
					return (Q[i - 1900] & 15);
				}
				function f(j, i) {
					return ((Q[j - 1900] & (65536 >> i)) ? 30 : 29);
				}
				function C(n) {
					var l, k = 0, j = 0;
					var m = new Date(1900, 0, 31);
					var o = (n - m) / 86400000;
					this.dayCyl = o + 40;
					this.monCyl = 14;
					for (l = 1900; l < 2050 && o > 0; l++) {
						j = e(l);
						o -= j;
						this.monCyl += 12;
					}
					if (o < 0) {
						o += j;
						l--;
						this.monCyl -= 12;
					}
					this.year = l;
					this.yearCyl = l - 1864;
					k = h(l);
					this.isLeap = false;
					for (l = 1; l < 13 && o > 0; l++) {
						if (k > 0 && l == (k + 1) && this.isLeap == false) {
							--l;
							this.isLeap = true;
							j = c(this.year);
						} else {
							j = f(this.year, l);
						}
						if (this.isLeap == true && l == (k + 1)) {
							this.isLeap = false;
						}
						o -= j;
						if (this.isLeap == false) {
							this.monCyl++;
						}
					}
					if (o == 0 && k > 0 && l == k + 1) {
						if (this.isLeap) {
							this.isLeap = false;
						} else {
							this.isLeap = true;
							--l;
							--this.monCyl;
						}
					}
					if (o < 0) {
						o += j;
						--l;
						--this.monCyl;
					}
					this.month = l;
					this.day = o + 1;
				}
				function G(i) {
					return i < 10 ? "0" + i : i;
				}
				function g(j, k) {
					var i = j;
					return k.replace(/dd?d?d?|MM?M?M?|yy?y?y?/g, function (l) {
						switch (l) {
						  case "yyyy":
							var m = "000" + i.getFullYear();
							return m.substring(m.length - 4);
						  case "dd":
							return G(i.getDate());
						  case "d":
							return i.getDate().toString();
						  case "MM":
							return G((i.getMonth() + 1));
						  case "M":
							return i.getMonth() + 1;
						}
					});
				}
				function a(j, i) {
					var k;
					switch (j, i) {
					  case 10:
						k = "\u521d\u5341";
						break;
					  case 20:
						k = "\u4e8c\u5341";
						break;
					  case 30:
						k = "\u4e09\u5341";
						break;
					  default:
						k = D.charAt(Math.floor(i / 10));
						k += A.charAt(i % 10);
					}
					return (k);
				}
				this.date = Z;
				this.isToday = false;
				this.isRestDay = false;
				this.solarYear = g(Z, "yyyy");
				this.solarMonth = g(Z, "M");
				this.solarDate = g(Z, "d");
				this.solarWeekDay = Z.getDay();
				this.solarWeekDayInChinese = "\u661f\u671f" + A.charAt(this.solarWeekDay);
				var Y = new C(Z);
				this.lunarYear = Y.year;
				this.shengxiao = P.charAt((this.lunarYear - 4) % 12);
				this.lunarMonth = Y.month;
				this.lunarIsLeapMonth = Y.isLeap;
				this.lunarMonthInChinese = this.lunarIsLeapMonth ? "\u95f0" + F[Y.month - 1] : F[Y.month - 1];
				this.lunarDate = Y.day;
				this.showInLunar = this.lunarDateInChinese = a(this.lunarMonth, this.lunarDate);
				if (this.lunarDate == 1) {
					this.showInLunar = this.lunarMonthInChinese + "\u6708";
				}
				this.ganzhiYear = b(Y.yearCyl);
				this.ganzhiMonth = b(Y.monCyl);
				this.ganzhiDate = b(Y.dayCyl++);
				this.jieqi = "";
				this.restDays = 0;
				if (d(this.solarYear, (this.solarMonth - 1) * 2) == g(Z, "d")) {
					this.showInLunar = this.jieqi = L[(this.solarMonth - 1) * 2];
				}
				if (d(this.solarYear, (this.solarMonth - 1) * 2 + 1) == g(Z, "d")) {
					this.showInLunar = this.jieqi = L[(this.solarMonth - 1) * 2 + 1];
				}
				if (this.showInLunar == "\u6e05\u660e") {
					this.showInLunar = "\u6e05\u660e\u8282";
					this.restDays = 1;
				}
				this.solarFestival = W[g(Z, "MM") + g(Z, "dd")];
				if (typeof this.solarFestival == "undefined") {
					this.solarFestival = "";
				} else {
					if (/\*(\d)/.test(this.solarFestival)) {
						this.restDays = parseInt(RegExp.$1);
						this.solarFestival = this.solarFestival.replace(/\*\d/, "");
					}
				}
				this.showInLunar = (this.solarFestival == "") ? this.showInLunar : this.solarFestival;
				this.lunarFestival = U[this.lunarIsLeapMonth ? "00" : G(this.lunarMonth) + G(this.lunarDate)];
				if (typeof this.lunarFestival == "undefined") {
					this.lunarFestival = "";
				} else {
					if (/\*(\d)/.test(this.lunarFestival)) {
						this.restDays = (this.restDays > parseInt(RegExp.$1)) ? this.restDays : parseInt(RegExp.$1);
						this.lunarFestival = this.lunarFestival.replace(/\*\d/, "");
					}
				}
				if (this.lunarMonth == 12 && this.lunarDate == f(this.lunarYear, 12)) {
					this.lunarFestival = U["0100"];
					this.restDays = 1;
				}
				this.showInLunar = (this.lunarFestival == "") ? this.showInLunar : this.lunarFestival;
				this.showInLunar = (this.showInLunar.length > 4) ? this.showInLunar.substr(0, 2) + "..." : this.showInLunar;
			}
			var R = (function () {
				var Y = {};
				Y.lines = 0;
				Y.dateArray = new Array(42);
				function Z(b) {
					return (((b % 4 === 0) && (b % 100 !== 0)) || (b % 400 === 0));
				}
				function G(b, c) {
					return [31, (Z(b) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][c];
				}
				function C(b, c) {
					b.setDate(b.getDate() + c);
					return b;
				}
				function a(b) {
					var g = 0;
					var d = new V(new Date(b.solarYear, b.solarMonth - 1, 1));
					var e = (d.solarWeekDay - 1 == -1) ? 6 : d.solarWeekDay - 1;
					Y.lines = Math.ceil((e + G(b.solarYear, b.solarMonth - 1)) / 7);
					for (var f = 0; f < Y.dateArray.length; f++) {
						if (d.restDays != 0) {
							g = d.restDays;
						}
						if (g > 0) {
							d.isRest = true;
						}
						if (e-- > 0 || d.solarMonth != b.solarMonth) {
							Y.dateArray[f] = null;
							continue;
						}
						var c = new V(new Date());
						if (d.solarYear == c.solarYear && d.solarMonth == c.solarMonth && d.solarDate == c.solarDate) {
							d.isToday = true;
						}
						Y.dateArray[f] = d;
						d = new V(C(d.date, 1));
						g--;
					}
				}
				return {init:function (b) {
					a(b);
				}, getJson:function () {
					return Y;
				}};
			})();
			var X = (function () {
				var C = N("top").getElementsByTagName("SELECT")[0];
				var Y = N("top").getElementsByTagName("SELECT")[1];
				var G = N("top").getElementsByTagName("SPAN")[0];
				var d = N("top").getElementsByTagName("SPAN")[1];
				var Z = N("top").getElementsByTagName("INPUT")[0];
				function b(h) {
					G.innerHTML = h.ganzhiYear;
					d.innerHTML = h.shengxiao;
				}
				function c(h) {
					C[h.solarYear - 1901].selected = true;
					Y[h.solarMonth - 1].selected = true;
				}
				function g() {
					var k = C.value;
					var h = Y.value;
					var j = new V(new Date(k, h - 1, 1));
					R.init(j);
					O.draw();
					if (this == C) {
						j = new V(new Date(k, 3, 1));
						G.innerHTML = j.ganzhiYear;
						d.innerHTML = j.shengxiao;
					}
					var i = new V(new Date());
					Z.style.visibility = (k == i.solarYear && h == i.solarMonth) ? "hidden" : "visible";
				}
				function a() {
					var h = new V(new Date());
					b(h);
					c(h);
					R.init(h);
					O.draw();
					Z.style.visibility = "hidden";
				}
				function e(l, h) {
					for (var k = 1901; k < 2050; k++) {
						var j = S("OPTION");
						j.value = k;
						j.innerHTML = k;
						if (k == l) {
							j.selected = "selected";
						}
						C.appendChild(j);
					}
					for (var k = 1; k < 13; k++) {
						var j = S("OPTION");
						j.value = k;
						j.innerHTML = k;
						if (k == h) {
							j.selected = "selected";
						}
						Y.appendChild(j);
					}
					C.onchange = g;
					Y.onchange = g;
				}
				function f(h) {
					e(h.solarYear, h.solarMonth);
					G.innerHTML = h.ganzhiYear;
					d.innerHTML = h.shengxiao;
					Z.onclick = a;
					var i = new V(new Date());
					Z.style.visibility = (h.solarYear === i.solarYear && h.solarMonth === i.solarMonth && h.solarDate === i.solarDate) ? "hidden" : "visible";
				}
				return {init:function (h) {
					f(h);
				}, reset:function (h) {
					c(h);
				}};
			})();
			var O = (function () {
				function C(e) {
					var a = R.getJson();
					var d = a.dateArray;
					N("cm").style.height = a.lines * 38 + 2 + "px";
					N("cm").innerHTML = "";
					for (var b = 0; b < d.length; b++) {
						if (d[b] == null) {
							continue;
						}
						var Y = S("DIV");
						if (e) {
							if (e.solarDate === d[b].solarDate) {
								Y.style.cssText = "border:1px solid #a5b9da;background:#c1d9ff";
							}
						} else {
							if (d[b].isToday) {
								Y.style.cssText = "border:1px solid #a5b9da;background:#c1d9ff";
							}
						}
						Y.className = "cell";
						Y.style.left = (b % 7) * 60 + "px";
						Y.style.top = Math.floor(b / 7) * 38 + 2 + "px";
						var c = S("DIV");
						c.className = "so";
						c.style.color = ((b % 7) > 4 || d[b].isRest) ? "#c60b02" : "#313131";
						c.innerHTML = d[b].solarDate;
						Y.appendChild(c);
						var Z = S("DIV");
						Z.style.color = "#666";
						Z.innerHTML = d[b].showInLunar;
						Y.appendChild(Z);
						Y.onmouseover = (function (f) {
							return function (g) {
								E.show({dateIndex:f, cell:this});
							};
						})(b);
						Y.onmouseout = function () {
							E.hide();
						};
						N("cm").appendChild(Y);
					}
					var G = S("DIV");
					G.id = "fd";
					N("cm").appendChild(G);
					E.init(G);
				}
				return {draw:function (G) {
					C(G);
				}};
			})();
			var E = (function () {
				var C;
				function Z(f, d) {
					if (arguments.length > 1) {
						var c = /([.*+?^=!:${}()|[\]\/\\])/g, a = "{".replace(c, "\\$1"), e = "}".replace(c, "\\$1");
						var b = new RegExp("#" + a + "([^" + a + e + "]+)" + e, "g");
						if (typeof (d) == "object") {
							return f.replace(b, function (g, i) {
								var h = d[i];
								return typeof (h) == "undefined" ? "" : h;
							});
						}
					}
					return f;
				}
				function G(c) {
					var b = R.getJson().dateArray[c.dateIndex];
					var a = c.cell;
					var d = "#{solarYear}&nbsp;\u5e74&nbsp;#{solarMonth}&nbsp;\u6708&nbsp;#{solarDate}&nbsp;\u65e5&nbsp;#{solarWeekDayInChinese}";
					d += "<br><b>\u519c\u5386&nbsp;#{lunarMonthInChinese}\u6708#{lunarDateInChinese}</b>";
					d += "<br>#{ganzhiYear}\u5e74&nbsp;#{ganzhiMonth}\u6708&nbsp;#{ganzhiDate}\u65e5";
					if (b.solarFestival != "" || b.lunarFestival != "" || b.jieqi != "") {
						d += "<br><b>#{lunarFestival} #{solarFestival} #{jieqi}</b>";
					}
					C.innerHTML = Z(d, b);
					C.style.top = a.offsetTop + a.offsetHeight - 5 + "px";
					C.style.left = a.offsetLeft + a.offsetWidth - 5 + "px";
					C.style.display = "block";
				}
				function Y() {
					C.style.display = "none";
				}
				return {show:function (a) {
					G(a);
				}, hide:function () {
					Y();
				}, init:function (a) {
					C = a;
				}};
			})();
			var H = (function () {
				var G = N("bm").getElementsByTagName("A")[0];
				function C(Y) {
					G.href = "http://baike.baidu.com/list-php/dispose/searchword.php?word=" + Y.solarMonth + "%D4%C2" + Y.solarDate + "%C8%D5&pic=1";
				}
				return {setLink:function (Y) {
					C(Y);
				}};
			})();
			var M = new V(new Date());
			var I = (function () {
				if (window.op_calendar && window.op_calendar.year && window.op_calendar.month && window.op_calendar.day) {
					var C = new Date([window.op_calendar.year, window.op_calendar.month, window.op_calendar.day].join("/"));
					if ((C.toString().toLowerCase() !== "invalid date") && (Object.prototype.toString.apply(C).toLowerCase() === "[object date]")) {
						return new V(C);
					} else {
						return M;
					}
				} else {
					return M;
				}
			})();
			X.init(I);
			if (T && window.attachEvent) {
				window.attachEvent("onload", function () {
					X.reset(I);
				});
			}
			R.init(I);
			O.draw(I);
			H.setLink(M);
		})();
    }
})

/**
 * 
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Inputbox = Ext.extend(Ext.util.Observable,{
	// 显示框的默认值
	textValue: '',
	// 选中项的ID
	selectId: '',
	// 显示层是否展示
	isShow: false,
	// 是否有删除操作
	isDelete: false,
	// 光标位置
	address: 0,
	// 选择项位置
	selectCount: 0,
	// 回调函数
	callback: function(){},
	// 是否选择
	clec: false,
	
	/**
	* 构造方法
	*/
	constructor: function(config) {
		
		// 合并config中的内容
		Ext.apply(this, config);
		this.initUI();
		this.initEvents();
	},
	
     /**
     * 初始化界面
     */
     initUI: function(){
     	// 初始化参数
     	this.width = Ext.isEmpty(this.width) ? Ext.fly(this.renderTo).dom.offsetWidth : this.width;
		this.height = Ext.isEmpty(this.height) ? Ext.fly(this.renderTo).dom.offsetHeight : this.height;
		this.lineHeight = Ext.isEmpty(this.lineHeight) ? '20' : this.lineHeight;
		this.onlyOne = Ext.isEmpty(this.onlyOne) ? false : this.onlyOne;
		this.isAjax = Ext.isEmpty(this.isAjax) ? false : this.isAjax;
		this.ajaxUrl = Ext.isEmpty(this.ajaxUrl) ? '' : this.ajaxUrl;
		
		// 创建元素
		// 外层框架 
/*		this.div = Ext.fly(this.renderTo).createChild({
			tag: 'div', 
			cls: 'inputbox-default'
		});
		// 显示文本框
		this.text = this.div.createChild({
			tag: 'input',
			type: 'text',
			cls: 'text'
		});
		// 显示选择内容的DIV
		this.showDiv = this.div.createChild({
			tag: 'div',
			cls: 'show',
			name: 'showDivName'
		});
		// 隐藏的保存域
		this.hide = this.div.createChild({
			tag: 'div',
			name: this.hideName
		});*/
		this.text = Ext.get(this.textId);
		this.text.dom.autocomplete == "off";
		this.showDivWidth = Ext.isEmpty(this.showDivWidth) ? this.text.dom.offsetWidth : this.showDivWidth;
		
		this.text.addClass('inputbox-default-text');
		this.showDiv = Ext.get(this.showDivId);
		this.showDiv.addClass('inputbox-default-show');
		this.hide = Ext.get(this.hideId);
		// 属性设定
		this.hide.setStyle('display', 'none');
		this.text.setStyle('width', this.width+'px');
		this.text.setStyle('height', this.height+'px');
		this.text.setStyle('line-height', this.lineHeight+'px');
		this.showDiv.setStyle('display', 'none');
		this.isShow = false;
		this.showDiv.setStyle('width', this.showDivWidth +'px');
		this.showDiv.setStyle('top', parseInt(this.height)+10+'px');
		this.showDiv.setStyle('left', '8px');
	},
     
     /**
     * 初始化事件
     */
	initEvents: function(){
		var me = this;
		if(this.isAjax == true){
			this.ajax();	
		}
		// 输入框获取按键抬起事件
		this.text.on('keyup', function(e, t){
			// 最后一位删除事件处理
			if(e.keyCode == 8 || e.keyCode == 46){
				var isLast = false;
				// 全部删除的情况
				if(me.text.dom.value == ''){
					me.showDiv.setStyle('display', 'none');
					me.isShow = false;
				}
				// 一段内的删除
				if(me.textValue.length < me.text.dom.value.length + 1&& me.selectCount == 0){
					me.showDivText();
					return;
				}
				// 连续删除时光标移位
				if(me.address > me.text.dom.value.length + 1 && me.selectCount != 0){
					me.address = me.text.dom.value.length + 1
				}
				if(me.address != 0 && me.address == me.text.dom.value.length + 1){
					me.lastDelete();
					isLast = true;
				}
				me.isDelete = true;
				me.textValue = me.text.dom.value;
				if(Ext.isIE){
					var ids = me.hide.dom.innerHTML.split(';');
				}else{
					var ids = me.hide.dom.textContent.split(';');
				}
				if(me.selectCount == 0 || me.selectCount == ids.length){
					me.selectCount = ids.length - 1;
				}
				var id = '';
				me.selectId = '';
				for(var i=0; i<ids.length - 1; i++){
					if(i != me.selectCount - 1){
						id = id + ids[i] + ';';
					}
				}
				if(Ext.isIE){
					me.hide.dom.innerHTML = id;
				}else{
					me.hide.dom.textContent = id;
				}
				
				if(isLast == true){
					me.text.focus();
				}else{
					me.text.blur();
				}
				me.showDiv.setStyle('display', 'none');
				me.isShow = false;
			}
			
			// 选择框弹出事件
			if(me.text.dom.value != me.textValue){
				var chars = me.text.dom.value.split(';');
				if(chars[chars.length-1] == ''){
					return;
				}
				// 选择之后的对比处理
				if(me.selectCount != 0){
					if(me.textValue.split(';')[me.selectCount] == null){return;}
					var len = me.textValue.split(';')[me.selectCount].length;
					var text = '';
					var ch = chars[me.selectCount - 1].split('');
					for(var i=0; i<chars[me.selectCount - 1].length - len; i++){
						text = text + ch[i];
					}
					chars[chars.length-1] = text;
				}
				var length = chars[chars.length-1].length;
				var value = '';
				var len = 0;
				len = me.items.length;
				if(me.items[me.items.length-1] == null){
					len = len - 1;
				}
				me.selectId = '';
				for(var i=0; i<len; i++){
					for(var j=0; j<length; j++){
						if(me.items[i].value.split('').length<length){
							me.showDiv.setStyle('display', 'none');
							me.isShow = false;
							return;
						}
						value = value + me.items[i].value.split('')[j];
					}
					if(chars[chars.length-1] == value){
						me.selectId = me.selectId + me.items[i].id + ';';
					}
					value = '';
				}
				me.addSpan();
			}else if(me.text.dom.value == ''){
				// 显示框为空的时候隐藏选择框
				me.showDiv.select('span:nth-child(n)').remove();
			}
		});
		
		// 输入框点击事件
		this.text.on('click', function(e, t){
			var address = me.getCursortPosition(me.text.dom, false);
			me.textClikc(address);
		});
		
		Ext.fly(document.body).on('click', function(e, t){
			var text = Ext.fly(e.target);
			if(text.dom.id != me.textId){
				window.setTimeout(function(){
				me.showDiv.setStyle('display', 'none'); 
				me.isShow = false;
				me.text.dom.value = me.textValue;
				if(me.showDiv.dom.childNodes.length != 0){
					var id = me.selectId.split(';')[0];
					var length = 0;
					if(Ext.isIE){
						length = me.items.length - 1;
					}else{
						length = me.items.length;
					}
					if(me.clec == false){
						for(var i=0; i<length - 1; i++){
							if(me.items[i].id == id){
								if(me.onlyOne == true){
									me.text.dom.value = me.items[i].value + ';';
									me.hide.dom.innerHTML = me.items[i].id + ';';
								}else{
									me.text.dom.value = me.text.dom.value + me.items[i].value + ';';
									me.hide.dom.innerHTML = me.hide.dom.innerHTML + me.items[i].id + ';';
								}
								break;
							}
						}
					}
					me.clec = false;
				}
				me.textValue = me.text.dom.value;
				me.selectId = '';
   			}, 300);
			}
		})
	},
	
	/**
	* 将符合条件的项加入选择DIV
	*/
	addSpan: function(){
		this.showDiv.select('span:nth-child(n)').remove();
		this.showDiv.select('iframe:nth-child(n)').remove();
		this.showDiv.setStyle('overflow-x', 'hidden');
		if(this.selectId == ''){
			return;
		}
		this.showDiv.setStyle('display', 'block');
		this.isShow = true;
		var ids = this.selectId.split(';');
		var me = this;
		var height = 0;
		var len = 0;
		len = this.items.length;
		if(this.items[this.items.length-1] == null){
			len = len - 1;
		}
		for(var i=0; i<len; i++){
			for(var j=0; j<ids.length; j++){
				if(ids[j] == this.items[i].id){
					var span = this.showDiv.createChild({
						tag: 'span',
						cls: 'inputbox-default-span',
						html: '&nbsp;' + this.items[i].value + '&nbsp;&nbsp;' + this.items[i].remarks
					});
					span.setStyle('top', height*this.lineHeight+'px');
					span.setStyle('height', this.lineHeight+'px');
					height = height + 1;
					span.on('click', function(e, t){me.spanClick(e, t)});
					span.hover(function(e, t){
			    		me.showDiv.select('span:nth-child(n)').removeClass('inputbox-default-span-over');
			     		Ext.fly(t).addClass('inputbox-default-span-over');
					}, function(e, t){
						span.removeClass('inputbox-default-span-over');
					});
				}
			}
		}
		if((ids.length-1)* parseInt(this.lineHeight) > 200){
			this.showDiv.setStyle('height', '200px');
		}else{
			this.showDiv.setStyle('height', (ids.length-1)* parseInt(this.lineHeight)+'px');
		}
	//	this.selectId = '';
	//	var zzz = ssh.util.iframe(this.showDiv);
		//var xxx = this.showDiv.select('iframe:nth-child(n)');
		//zzz.setStyle('width', '180px');
	},
	
	/**
	* 选项点击事件
	*/
	spanClick: function(e, t){
		this.text.dom.value = this.textValue;
		var text = t.innerHTML.split('&nbsp;');
		var me = this;
		var id = '';
		for(var i=0; i<this.items.length; i++){
			if(this.items[i].value == text[1] && this.items[i].remarks == text[3]){
				id = this.items[i].id
				break;
			}
		}
		// this.onlyOne: 是否只显示一个
		if(this.onlyOne == true){
			this.textValue = text[1] + ';';
			this.text.dom.value = this.textValue;
			this.hide.dom.textContent = id + ';';
			this.hide.dom.innerHTML = id + ';';
			this.clec = true;
		}else{
			if(this.selectCount != 0){
				var values = this.textValue.split(';');
				var ids = this.hide.dom.textContent.split(';');
				var value = '';
				var idc = '';
				for(var i=0; i<values.length - 1; i++){
					if(i != this.selectCount - 1){
						value = value + values[i] + ';';
						idc = idc + ids[i] + ';';
					}else{
						value = value + text[1] + ';';
						idc = idc + id + ';';
					}
				}
				this.textValue = value;
				this.text.dom.value = this.textValue;
				if(Ext.isIE){
					this.hide.dom.innerHTML = idc;
				}else{
					this.hide.dom.textContent = idc;
				}
			}else{
				this.text.dom.value = this.text.dom.value + text[1] + ';';
				this.textValue = this.textValue + text[1] + ';';
				if(Ext.isIE){
					this.hide.dom.innerHTML = this.hide.dom.innerHTML + id + ';';
				}else{
					this.hide.dom.textContent = this.hide.dom.textContent + id + ';';
				}
			}
			this.clec = true;
			
		}
		
		// 赋值
		this.showDiv.setStyle('display', 'none');
		this.isShow = false;
		this.callback(id);
	},
	
	/**
	* 文本框点击事件
	*/
	textClikc: function(address){
		this.selectCount = 0;
		var maxLength = this.text.dom.value.length;
		if(address == maxLength){
			this.address = address;
			return;
		}
		var start = 0;
		var end = 0;
		var value = this.text.dom.value.split('');
		if(value[address] != ';'){
			for(var i=address; i<maxLength; i++){
				if(value[i] == ';'){
					end = i;
					break;
				}
			}
		}else{end = address;}
		for(var i=address-1; i>0; i--){
			if(value[i] == ';'){
				start = i;
				break;
			}
		}
		if(start == 0){start = -1}
		this.setSelect(this.text.dom, start+1, end+1);
		for(var i=end; i>0; i--){
			if(value[i] == ';'){
				this.selectCount = this.selectCount + 1;
			}
		}
		this.address = 0;
	},
	
	/**
	* 最后一位的删除事件
	*/
	lastDelete: function(){
		var text = this.text.dom.value.split(';');
		var value = '';
		for(var i=0; i<text.length-1; i++){
			value = value + text[i] + ';';
		}
		this.text.dom.value = value;
		this.textValue = value;
	},
	
	/**
	* 是否打开显示框的验证
	*/
	showDivText: function(){
		this.showDiv.select('span:nth-child(n)').remove();
		// 从输入框取到的值
		var text = this.text.dom.value.split(';');
		// 从输入框分出的数组长度
		var length = 0;
		// items中取出的名称
		var value = '';
		// 验证是否有新输入的值
		if(text[text.length-1] != null){
			length = text[text.length-1].length;
		}
		var len = 0;
		if(Ext.isIE){
			len = this.items.length - 1;
		}else{
			len = this.items.length;
		};
		if(length != 0){
			this.selectId = '';
			for(var i=0; i<len; i++){
				for(var j=0; j<length; j++){
					value = value + this.items[i].value.split('')[j];
				}
				if(text[text.length-1] == value){
					this.selectId = this.selectId + this.items[i].id + ';';
				}
				value = '';
			}
			this.addSpan();
		}else if(this.text.dom.value == ''){
			// 显示框为空的时候隐藏选择框
			this.showDiv.select('span:nth-child(n)').remove();
		}else{
			this.showDiv.setStyle('display', 'none');
		}
	},
	
	/**
	* 改变值
	*/
	changeValue: function(item){
		this.items.push({value:item.value, id:item.id});
		if(this.onlyOne == true){
			this.text.dom.value = item.value + ';';
			this.hide.dom.innerHTML = item.id + ';';
		}else{
			this.text.dom.value = this.text.dom.value + item.value + ';';
			this.hide.dom.innerHTML = this.hide.dom.innerHTML + item.id + ';';
		}
		this.textValue = this.text.dom.value;
	},
	
	/**
     * 获取光标位置
     */
     getCursortPosition: function(ctrl, bo) {//获取光标位置函数
        var CaretPos = 0;    // IE Support
        if (document.selection) {
        	var Sel = document.selection.createRange();
            if(bo == true){
            	this.text.focus ();
            	CaretPos = Sel.text.length;
        	}else if(bo == false){
        		Sel.moveStart('character', -ctrl.value.length);
        		CaretPos = Sel.text.length;
        	}
    }
        // Firefox support
        else if (ctrl.selectionStart || ctrl.selectionStart == '0'){
        	if(bo == true){
        		CaretPos = ctrl.selectionEnd;
        	}else if(bo == false){
        		CaretPos = ctrl.selectionStart;
        	}
        }
        return (CaretPos);
	},
	
	/**
	* 设置选中
	*/
	setSelect : function(textarea, start, end)
	{
		if ( typeof textarea.createTextRange != 'undefined' )// IE
		{
			var range = textarea.createTextRange();
			// 先把相对起点移动到0处
			range.moveStart("character", 0);
			range.moveEnd("character", 0);
			range.collapse(true); // 移动插入光标到start处
			range.moveStart("character", start);
			range.moveEnd("character", end-start);
			range.select();
		} // if
		else if ( typeof textarea.setSelectionRange != 'undefined' )
		{     
			textarea.setSelectionRange(start, end);
			textarea.focus();
		} // else 
		this.isSelecting = true;
	},
	
	/**
	* Ajax连接数据库	 
	*/ 
	ajax: function(){
		var me = this;
		Ext.Ajax.request({
			url: me.ajaxUrl,
	   		success: function(response, opts) {
	     		me.items = Ext.util.JSON.decode(response.responseText); 
	     	},
	   		failure: function(response, opts) {
	      		console.log('服务端失效的状态代码： ' + response.status);
	   		}
		});
	}
});   
Ext.ns('ssh');
/**
*	自定义方法（继承基类）
*/                                                              
ssh.progressBar = Ext.extend(Ext.util.Observable,{

	/**
	*	创建构造方法
	*/ 
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
        this.initUI();
	},
	
	/**
	*	初始化界面
	*/ 
	initUI:function(){
		// 参数配置
		this.cls = Ext.isEmpty(this.cls) ? 'progress-img' : this.cls;
		this.proSkin = Ext.isEmpty(this.proSkin) ? '1' : this.proSkin;
		this.width = Ext.isEmpty(this.width) ? '300px' : this.width;
		this.skinCount = Ext.isEmpty(this.skinCount) ? 5 : this.skinCount;
		this.progressCount = Ext.isEmpty(this.progressCount) ? 1 : this.progressCount;
		this.max = Ext.isEmpty(this.max) ? 100 : this.max;
		this.min = Ext.isEmpty(this.min) ? 0 : this.min;
		this.now = Ext.isEmpty(this.now) ? 50 : this.now;
		var me = this;
		var x = 1;
		this.items = new Array();
		// 自动生成进度条数组
		for(var i=0;i<this.progressCount;i++){
			this.items[i]={name:i};
		}
		if(this.cls == 'progress-img'){
			this.color = '';
		}
		// 确定容器
		this.div = Ext.get(this.renderTo);
		// 创建页面元素
		for(var i=0;i<this.items.length;i++){
			// 创建显示总容器
			this.items[i]['showDiv'] = this.div.createChild({
				tag: 'div',
				cls: 'showDiv'
			});
			// 创建进度显示容器
			this.items[i]['show'] = this.items[i].showDiv.createChild({
				tag: 'div',
				cls: 'show',
				html: '<center><b class="show"></b></center>'
			});
			// 创建背景显示容器
			var background = this.items[i].showDiv.createChild({
				tag: 'div',
				cls: 'background'
			});
			// 创建进度条外框
			this.items[i]['proDiv'] = this.items[i].showDiv.createChild({
				tag: 'div',
				cls: 'proDiv-'+this.proSkin
			});
			// 创建进度条内容
			this.items[i]['progress'] = this.items[i].proDiv.createChild({
				tag: 'div',
				cls: 'progress-'+this.proSkin
			});
			// 设置总容器样式
			this.div.addClass(this.cls);
			// 设置进度条容器样式
			this.items[i].proDiv.setWidth(this.width);
			this.items[i].proDiv.setStyle('background-color',this.color);
			// 设置显示容器样式
			this.items[i].showDiv.setTop(i*40+80);
			this.items[i].showDiv.setWidth(this.width);
			this.items[i].showDiv.setStyle('color',this.showColor);
			// 设置进度条背景样式
			background.setWidth(this.width);
			background.setStyle('background-color',this.backgroundColor);
			// 设置进度条默认值
			this.items[i].proDiv.setWidth((this.now/this.max)*parseFloat(this.width));
			if(this.textShow == 'true'){
				this.items[i].show.select('b:first-child').update((this.now/this.max*100).toFixed(1)+'%');
			}
		}
	},
	
	/**
	* 进度条设置
	× count--改变后的目标（数字）
	* s--该进度条在数组中的位置(只有一个进度条时可为空)
	*/
	run:function(count,s){
		if(this.progressCount==1){
			s = 0;
		}
		var runner = new Ext.util.TaskRunner();
		var me = this;
		var x = 0;
		var move = {
	    	run: function(){
				if(x<11){
					me.items[s].proDiv.setWidth(x*(count/1000)*parseFloat(me.width));
					if(me.textShow == 'true'){
						me.items[s].show.select('b:first-child').update((x*(count/10)).toFixed(1)+'%');
					}
					x++;
				}else{
					runner.stop(move);
				}
			},interval: 300 
		};
		runner.start(move);
	},
	
	/**
	*	皮肤选择下拉框(需要在初始化时调用)
	*/
	downBox:function(){
		var me = this;
		var x = 1;
		for(var i=0;i<this.items.length;i++){
			// 创建下拉框
			this.items[i]['select'] = this.div.createChild({
				tag: 'select',
				cls: 'select'
			});
			
			// 设置下拉框（皮肤选择）样式
			this.items[i].select.setTop(i*40+80);
			this.items[i].select.setLeft(parseFloat(this.width)+40);
			
			// 下拉框生成选项
			for(var j=0;j<this.skinCount;j+=1){
				var op = document.createElement("option");
				if(j == parseInt(this.proSkin)-1){
					op.selected = true;
				}
				op.value = j+1;
				op.text = '样式-'+(j+1);
				me.items[i].select.appendChild(op);
			    var s = me.items[i].select.select('option:nth-child(n)');
			    s.elements[j].text = '样式-'+(j+1);
			}
		}
		
		// 进度条皮肤改变
		for(var i=0;i<me.progressCount;i++){
			me.items[i].select.on('click' ,function(e, t){
				if(me.items[e.target.id]==null){
					me.items[e.target.offsetParent.id].proDiv.removeClass('proDiv-'+x);
					me.items[e.target.offsetParent.id].progress.removeClass('progress-'+x);
					me.items[e.target.offsetParent.id].proDiv.addClass('proDiv-'+e.target.value);
					me.items[e.target.offsetParent.id].progress.addClass('progress-'+e.target.value);
					x = e.target.value;
				}else{
				    me.items[e.target.id].proDiv.removeClass('proDiv-'+x);
					me.items[e.target.id].progress.removeClass('progress-'+x);
					me.items[e.target.id].proDiv.addClass('proDiv-'+e.target.value);
					me.items[e.target.id].progress.addClass('progress-'+e.target.value);
					x = e.target.value;
				}
			});
		}
	}
});

/**
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Album = Ext.extend(Ext.util.Observable,{
	// 当前显示的小图片编号
	nowShowNo: [1, 2, 3, 4, 5, 6, 7, 8, 9],
	// 滚动长度
	srollCount: 268,
	// items的长度
	length: 0,
	// 当前显示的大图片
	nowBigImg: 0,
	// 图片比例
	Proportion: 0,
	// 图片原始宽度
	defImgWidth: 0,
	// 图片原始高度
	defImgHeight: 0,
	// 当前翻转角度
	turnDegree: 0,
	// 是否使用剪切图
	isOriginal: true,
	
	nowPage: 1,
	
	/**
	* 构造方法
	*/
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);	
		this.initUI();
	},
    
    /**
    * 初始化界面
    */
    initUI: function(){
    	// 默认值设置
    	this.mode = Ext.isEmpty(this.mode) ? 'NO.1' : this.mode;
    	this.comment = Ext.isEmpty(this.comment) ? '' : this.comment;
    	var me = this;
		
			if(this.mode == 'NO.1'){
				this.oneInitUI();
				me.oneInitEvent();
			}else if(this.mode == 'NO.2'){
			//	this.nowPage = this.nowPage - 1;
   			//	this.twoInitUI();
			//	this.twoInitEvent();
			}
			
    },
   	
   	/**
   	* 图片滚动事件
   	*/
   	imgScroll: function(count, left){
   		var runner = new Ext.util.TaskRunner();
   		var le = left;
   		var me = this;
   		var cou = count/10;
   		var s = 0;
   		var i = 0;
   		var runn = {
   			run: function(){
				if(i < 11){
					me.showSmallHide.setLeft(left);
					left = left + cou;
					i = i + 1; 
					if(i == 10){
						me.showSmallHide.setLeft(le + count);
					}
				}
			},interval: 20
		};
		runner.start(runn); 
	},
   	
   	// 左侧跳转判断方法
   	leftJudge: function(count){
   		var left = this.showSmallHide.dom.offsetLeft;
   		if(left != 0){
	   		for(var i=0; i<this.nowShowNo.length; i++){
	   			if(this.nowShowNo[i] != 0){
	   				this.nowShowNo[i] = this.nowShowNo[i] - 4;
	   			}else{
	   				this.nowShowNo[i] = this.nowShowNo[i-1] + 1;	
	   			}
	   		}
	   		this.imgScroll(count, left);
   		}
   	},
   	
   	// 右侧跳转判断方法
   	rightJudge: function(count){
   		var left = this.showSmallHide.dom.offsetLeft;
   		// 判断当前显示的小图片的编号
   		if(this.nowShowNo[4] == 0){
   			return;
   		}
   		for(var i=0; i<this.nowShowNo.length; i++){
   			if(this.nowShowNo[i] != 0){
   				this.nowShowNo[i] = this.nowShowNo[i] + 4;
   			}
   			if(this.nowShowNo[i] > this.length){
   				this.nowShowNo[i] = 0;
   			}
   		}
   		this.imgScroll(count, left);
   	},
   	
   	
   	
   	/**
   	* 大图片改变事件
   	*/
   	changeImg: function(t){
   		var count = 0;
   		var me = this;
   		var addCount = 0;
   		this.showSmallHide.select('div:nth-child(n)').removeClass('imgDiv-select');
		Ext.fly(t.parentNode).addClass('imgDiv-select');
		for(var i=0; i<this.showSmallHide.dom.childNodes.length; i++){
			if(this.showSmallHide.dom.childNodes[i].className != 'imgDiv' && this.showSmallHide.dom.childNodes[i].className != 'imgDiv '){
				addCount = i + 1;
			}
		}
		var sr = t.getAttribute('src').split('/');;
	//	var sr = t.src.split('/');
		var src = sr[sr.length - 1].split('.thumb')[0];;
		var title = t.title;
		var img = '';
		for(var i=0; i<this.length; i++){
			if(this.items[i].smallImg.split('/')[this.items[i].smallImg.split('/').length - 1] == src && this.items[i].title == title){
				img = this.items[i].bigImg;
				count = i + 1;
				break;
			}
		}
		
		if(this.mode == 'NO.1'){
			this.albumPages.dom.innerHTML = '第'+count+'张 共'+this.length+'张';
			this.albumShare.dom.innerHTML = '分享('+this.items[count-1].share+')';
			this.albumCom.dom.innerHTML = '评论('+this.items[count-1].comment+')';
			this.albumAvi.dom.innerHTML = '阅览('+this.items[count-1].avi+')';
			if(this.albumTitle != null){
				this.albumTitle.dom.children[0].innerHTML = this.items[count-1].title;
			}
			this.albumCommon.dom.innerHTML = this.items[count-1].pl;
			this.albumId.dom.innerHTML = this.items[count-1].id;
			this.pid.dom.value = this.items[this.nowPage-1].id;
			this.albumDate.dom.innerHTML = this.items[count-1].date;
			this.updateTitleAndCom(count-1);
		}
		
		// 判断是否使用原图显示
		if(this.isOriginal){
			this.imgBig.dom.src = img;
		}else{
			var endNames = img.split('.');
			var endName = endNames[endNames.length-1];
			this.imgBig.dom.src = img + '.album.' + endName;
		}
		
		
		if(count == this.nowShowNo[0] && this.nowShowNo[0] != 1){
			this.leftJudge(this.srollCount);
		}else if(count == this.nowShowNo[8] && this.nowShowNo[8] != this.length){
			this.rightJudge(-this.srollCount);
		}
		this.callBack(this.items[count-1].id);
		this.bigImgChange();
	},
   	
   	/**
   	* 大图片点击事件
   	*/
   	imgClick: function(e, t){
   		if(t.tagName == 'DIV'){
   			t = t.childNodes[0];
   		}
   		var me = this;	
   		// 保存当前图片在集合中的位置
   		var count = 0;
   		var removeCount = 0;
   		var addCount = 0;
   		var sr = t.getAttribute('src').split('/');;
	//	var sr = t.src.split('/');
		// 判断是否使用原图
		if(me.isOriginal){
			var src = sr[sr.length - 1];
		}else{
			var src = sr[sr.length - 1].split('.album.')[0];
		}
		var title = t.name;
		// 确定当前小图片滚动条的位置
   		var left = this.showSmallHide.dom.offsetLeft;
   		for(var i=0; i<this.length; i++){
   			if(this.items[i].bigImg.split('/')[this.items[i].bigImg.split('/').length - 1] == src && this.items[i].title == title){
   				count = i;
   				break;
   			}
   		}
   		var sss = this.showBig.getX() + (this.showBig.dom.offsetWidth / 2);
		if(e.xy[0] > sss){
   			// 判断是否最后一位
   			if(count == this.length - 1){
   				count = -1;
   			}
   			removeCount = count + 1;
   			addCount = count + 2;
   			count = count + 1;
   		}else if(count == 0){
   			return;
   		}else{
   			removeCount = count + 1;
   			addCount = count;
   			count = count - 1;
   		}
   		var count1 = count + 1;
   		if(this.mode == 'NO.1'){
   			this.albumPages.dom.innerHTML = '第'+count1+'张 共'+this.length+'张';
			this.albumShare.dom.innerHTML = '分享('+this.items[count].share+')';
			this.albumCom.dom.innerHTML = '评论('+this.items[count].comment+')';
			this.albumAvi.dom.innerHTML = '阅览('+this.items[count].avi+')';
			if(this.albumTitle != null){
				this.albumTitle.dom.children[0].innerHTML = this.items[count].title;
			}
			this.albumCommon.dom.innerHTML = this.items[count].pl;
			this.albumId.dom.innerHTML = this.items[count].id;
			this.pid.dom.value = this.items[this.nowPage-1].id;
			this.albumDate.dom.innerHTML = this.items[count].date;
			this.updateTitleAndCom(count);
		}
		
		// 判断是否使用原图显示
		if(this.isOriginal){
			this.imgBig.dom.src = this.items[count].bigImg;
		}else{
			var endNames = this.items[count].bigImg.split('.');
			var endName = endNames[endNames.length-1];
			this.imgBig.dom.src = this.items[count].bigImg + '.album.' + endName;
		}
		
		this.imgBig.dom.name = this.items[count].title;
   		this.showSmallHide.select('div:nth-child('+removeCount+')').removeClass('imgDiv-select');
   		this.showSmallHide.select('div:nth-child('+addCount+')').addClass('imgDiv-select');
   		if(addCount == 1 && removeCount == 0){
   			this.showSmallHide.setLeft(0);
   			this.nowShowNo = [1, 2, 3, 4, 5, 6, 7, 8, 9];
   		}else if(addCount == this.length && removeCount == 1 && addCount != 9){
   			var sy = (this.length - 9) % 4;
   			var sd = parseInt((this.length - 9) / 4) + 1;
   			this.showSmallHide.setLeft(-this.srollCount * sd);
   			this.nowShowNo[this.nowShowNo.length - sy - 1] = this.length;
   			var s = 1;
   			for(var i=this.nowShowNo.length - sy - 2; i>-1; i--){
   				this.nowShowNo[i] = this.length - s;
   				s = s + 1;
   			}
   			for(var i=this.nowShowNo.length - sy; i<this.nowShowNo.length; i++){
   				this.nowShowNo[i] = 0;
   			}
   		}
   		
   		if(this.nowShowNo[8] == addCount && this.nowShowNo[8] != this.length){
   			// 向后翻页
   			this.rightJudge(-this.srollCount);
   		}else if(this.nowShowNo[0] == addCount && this.nowShowNo[0] != 1){
   			// 向前翻页
   			this.leftJudge(this.srollCount);
	   	}
	   	this.callBack(this.items[count].id);
	    this.bigImgChange();
	 },
   	
   	/**
   	* 旋转后调整位置
   	*/
   	degree: function(){
 		var me = this;
		var text = me.closed.dom.style.cssText.split(';');
		var top = 0;
		var left = 0;
/*		var tt = '';
		if(Ext.isIE6){
			left = text[1].split(':')[1].split('p')[0];
			top = text[4].split(':')[1].split('p')[0];
		}else if(Ext.isIE8){
			left = text[2].split(':')[1].split('p')[0];
			top = text[1].split(':')[1].split('p')[0];
		}else{
			left = text[0].split(':')[1].split('p')[0];
			top = text[1].split(':')[1].split('p')[0];
		}*/
		if(Ext.isIE){
			
	   }else{
			
	   	}
   		
		if(this.turnDegree == 360 || this.turnDegree == -360){
   			this.turnDegree = 0;	
   		}
   	},
   	
   	/**
   	* 大图片位置调整
   	*/
   	bigImgChange: function(){
   		var me = this;
   		me.imgBig.setStyle('display', 'none');
   		me.showBig.setStyle('background', 'url("images/loadingX.gif") no-repeat center center');
   		this.imgBig.on('load', function(){
   			me.imgBig.setStyle('display', 'block');
   			me.showBig.setStyle('background', 'none');
	   		me.imgBig.setStyle('width', 'auto');
   			me.imgBig.setStyle('height', 'auto');
   			var width = me.imgBig.dom.clientWidth;
	   		var height = me.imgBig.dom.clientHeight;
	   		var he = 0;
		   	if(width > 600){
		   		he = (height / width) * 600;
		   		me.imgBig.setStyle('width', '600px');
		   		me.imgBig.setStyle('height', he + 'px');
		   		width = 600;
		   		height = he;
		   	}
		   	if(height < 300){
				me.imgBig.setStyle('margin-top', (300 - height) / 2 + 'px');
				me.showBig.setStyle('height', '300px');
			}else{
				me.imgBig.setStyle('margin-top', '10px');
				me.showBig.setStyle('height', (height + 20) + 'px');
			}
		});
	},
   	
   	
   	/**
   	* 修改图片标题和描述
   	*/
   	updateTitleAndCom: function(i){
   		var me = this;
   		var userid = Ext.fly('userid').dom.value.split(';');
   		if(userid[0] == userid[1]){
	   		if(!Ext.isIE){
				this.albumCommon.dom.innerHTML = this.items[i].pl + '&nbsp;<a href="#" onclick="return false;"><img src="css/blog/myBlog/images/ico-8.gif" alt="编辑"></a>&nbsp;'+
				'&nbsp;<a href="#" onclick="return false;" style="display:none">点击此添加照片描述<img src="css/blog/myBlog/images/ico-8.gif" alt="编辑"></a><textarea style="display:none"></textarea><div style="display:none"><button>提交</button><button>返回</button></div>';
			}else{
				this.albumCommon.dom.innerHTML = this.items[i].pl + '&nbsp;<a href="#" onclick="return false;"><img src="css/blog/myBlog/images/ico-8.gif" alt="编辑"></a>&nbsp;'+
				'&nbsp;<a href="#" onclick="return false;" style="display:none">点击此添加照片描述<img src="css/blog/myBlog/images/ico-8.gif" alt="编辑"></a><textarea style="display:none"></textarea><span style="display:none"><button>提交</button><button>返回</button></span>';
			}
			if(this.items[i].pl == ''){
				Ext.fly(this.albumCommon.dom.children[1]).setStyle('display', 'block');
				Ext.fly(this.albumCommon.dom.children[0]).setStyle('display', 'none');
			}
			// 描述新增
	   		Ext.fly(this.albumCommon.dom.children[1]).on('click', function(e, t){
	   			me.albumCommon.dom.children[2].value = '';
	   			Ext.fly(me.albumCommon.dom.children[2]).setStyle('display', 'block');
	   			Ext.fly(me.albumCommon.dom.children[3]).setStyle('display', 'block');
	   		});
	   		// 描述修改
	   		Ext.fly(this.albumCommon.dom.children[0].children[0]).on('click', function(e, t){
	   			Ext.fly(me.albumCommon.dom.children[2]).setStyle('display', 'block');
	   			Ext.fly(me.albumCommon.dom.children[3]).setStyle('display', 'block');
	   		});
	   		// 提交按钮（描述）
	   		Ext.fly(this.albumCommon.dom.children[3].children[0]).on('click', function(e, t){
	   			Ext.Ajax.request({
					url: me.ajaxUrl + 'updatePhotoPdescription.do?pid='+me.albumTitle.dom.children[5].innerHTML+'&pdescription='+me.albumCommon.dom.children[2].value,
			   		success: function(response, opts) {
			   			alert('修改完成！！');
			   			Ext.fly(me.albumCommon.dom.children[2]).setStyle('display', 'none');
	   					Ext.fly(me.albumCommon.dom.children[3]).setStyle('display', 'none');
			     	},
			   		failure: function(response, opts) {
			      		console.log('服务端失效的状态代码： ' + response.status);
			   		}
				});
	   		});
	   		// 返回按钮（描述）
	   		Ext.fly(this.albumCommon.dom.children[3].children[1]).on('click', function(e, t){
	   			Ext.fly(me.albumCommon.dom.children[2]).setStyle('display', 'none');
	   			Ext.fly(me.albumCommon.dom.children[3]).setStyle('display', 'none');
	   		});
	   	}	
   	},
   	
   	// 图片调用方法（外调）
   	findPhoto: function(i, items){
   		this.items = items;
   		var me = this;
   		if(this.items[this.items.length-1] == null){
   			this.length = this.items.length - 1;
   		}
   		this.twoInitUI();
		this.twoInitEvent();
   /* 	this.div.setStyle('display', 'none');
		this.imgBig.on('load', function(){
			me.div.setStyle('display', 'block');
   			me.twoInitEvent();
			var text = me.showDiv.dom.style.cssText.split(';');
			var tt = '';
			if(Ext.isIE6){
				tt = text[2].split(':');
				var top = -(me.closeH - tt[1].split('p')[0]) - 15;
				me.closed.setStyle('top', top  + 'px');
			}else if(Ext.isIE8){
				tt = text[0].split(':');
				var top = -(me.closeH - tt[1].split('p')[0]) - 15;
				me.closed.setStyle('top', top  + 'px');
			}else{
				tt = text[1].split(':');
				var top = -(me.closeH - tt[1].split('p')[0]) - 15;
				me.closed.setStyle('top', top + 'px');
			}
			var left = me.imgBig.dom.width + 50;
			me.closed.setStyle('left', left + 'px');
			me.closed.setStyle('display', 'block')
   		});*/
   		
	},
   	
   	/**
   	* ajax处理
   	*/
   	ajax: function(){
   		var me = this;
   		Ext.Ajax.request({
			url: me.ajaxUrl,
	   		success: function(response, opts) {
	     		var ite = Ext.util.JSON.decode(response.responseText);
	     		var zhj = 0;
	     	},
	   		failure: function(response, opts) {
	      		console.log('服务端失效的状态代码： ' + response.status);
	   		}
		});
   	},
   	
   	/**
	 * 修正IE6 png图片
	 */
	fixIE6Png: function()
	{
		try
		{
            try {
                document.execCommand("BackgroundImageCache", false, true); /* TredoSoft Multiple IE doesn't like this, so try{} it */
            } catch(r) {}
            ssh.util.DD_belatedPNG.createVmlNameSpace();
            ssh.util.DD_belatedPNG.createVmlStyleSheet();  
            
        //    ssh.util.DD_belatedPNG.fixPng(this.closed.dom); 
      		ssh.util.DD_belatedPNG.fixPng(this.toolbarDiv.dom);
			ssh.util.DD_belatedPNG.fixPng(this.leftSpan.dom);
			ssh.util.DD_belatedPNG.fixPng(this.rightSpan.dom);
			ssh.util.DD_belatedPNG.fixPng(this.toolbar.dom);   
			ssh.util.DD_belatedPNG.fixPng(this.shareSpan.dom);
			ssh.util.DD_belatedPNG.fixPng(this.spaceSpan.dom);
			ssh.util.DD_belatedPNG.fixPng(this.leftRotation.dom);
			ssh.util.DD_belatedPNG.fixPng(this.rightRotation.dom);
			ssh.util.DD_belatedPNG.fixPng(this.imgProportion.dom);		
			ssh.util.DD_belatedPNG.fixPng(this.leftPage.dom);
			ssh.util.DD_belatedPNG.fixPng(this.rightPage.dom);
			ssh.util.DD_belatedPNG.fixPng(this.closeSpan.dom);	
			ssh.util.DD_belatedPNG.fixPng(this.shareSpan2.dom);
			ssh.util.DD_belatedPNG.fixPng(this.spaceSpan2.dom);
			ssh.util.DD_belatedPNG.fixPng(this.leftRotation2.dom);
			ssh.util.DD_belatedPNG.fixPng(this.rightRotation2.dom);
			ssh.util.DD_belatedPNG.fixPng(this.imgProportion2.dom);
			ssh.util.DD_belatedPNG.fixPng(this.leftPage2.dom);
			ssh.util.DD_belatedPNG.fixPng(this.rightPage2.dom);
			ssh.util.DD_belatedPNG.fixPng(this.closeSpan2.dom);	
		}catch(e)
		{
			alert(e);
		}
	},	
   	
   	/**
   	* 第一种方式初始化
   	*/
   	oneInitUI: function(){
   		var me = this;
   		this.length = this.items.length;
		if(this.items[this.items.length - 1] == null){
			this.length = this.items.length - 1;
		}
		
   		// 创建元素
		// 控件最外层DIV
		this.div = Ext.fly(this.renderTo).createChild({tag: 'div', cls: 'album-one-default'});
		// 居中显示
		var center = this.div.createChild({tag: 'center'});
		// 小图片显示层(整体框架)
		this.showSmallDiv = center.createChild({tag: 'div', cls: 'showSmallDiv'});
		// 小图片显示层左边按钮
		this.leftS = this.showSmallDiv.createChild({tag: 'div', cls: 'leftS'});
		// 小图片显示层
		this.showSmall = this.showSmallDiv.createChild({tag: 'div', cls: 'showSmall'});
		// 小图片显示层右边按钮
		this.rightS = this.showSmallDiv.createChild({tag: 'div', cls: 'rightS'});
		// 小图片显示层(隐藏)
		this.showSmallHide = this.showSmall.createChild({tag: 'div', cls: 'showSmallHide'});
		// 大图片显示层
		this.imgBigDiv = Ext.fly(this.imgDIV).createChild({tag: 'div', cls: 'album-one-default'});
		// 居中
		var center2 = this.imgBigDiv.createChild({tag: 'center'});
		// 大图片显示层
		this.showBig = center2.createChild({tag: 'div', cls: 'showBig'});
		// 大图显示
		if(this.isOriginal){
			this.imgBig = this.showBig.createChild({tag: 'img', src: this.items[this.nowPage - 1].bigImg, name: this.items[this.nowPage - 1].title});
		}else{
			var endNames = this.items[this.nowPage - 1].bigImg.split('.');
			var endName = endNames[endNames.length-1];
			this.imgBig = this.showBig.createChild({tag: 'img', src: this.items[this.nowPage - 1].bigImg+'.album.'+endName, name: this.items[this.nowPage - 1].title});
		}
		
		// 引用页面已有元素
		// 页数显示
		this.albumPages = Ext.get('albumPages');
		if(this.albumPages == null){this.albumPages = Ext.get('album');}
		this.albumPages.dom.innerHTML = '第'+this.nowPage+'张 共'+this.length+'张';
		// 分享数
		this.albumShare = Ext.get('albumShare');
		if(this.albumShare == null){this.albumShare = Ext.get('album');}
		this.albumShare.dom.innerHTML = '分享('+this.items[this.nowPage-1].share+')';
		// 评论数
		this.albumCom = Ext.get('albumCom');
		if(this.albumCom == null){this.albumCom = Ext.get('album');}
		this.albumCom.dom.innerHTML = '评论('+this.items[this.nowPage-1].comment+')';
		// 阅读数
		this.albumAvi = Ext.get('albumAvi');
		if(this.albumAvi == null){this.albumAvi = Ext.get('album');}
		this.albumAvi.dom.innerHTML = '阅览('+this.items[this.nowPage-1].avi+')';
		// 照片标题
		this.albumTitle = Ext.get('albumTitle');
		if(this.albumTitle != null){
			this.albumTitle.dom.children[0].innerHTML = this.items[this.nowPage-1].title;
		}
		// 照片ID
		this.albumId = Ext.get('albumId');
		if(this.albumId == null){this.albumId = Ext.get('album');}
		this.pid = Ext.get(this.pid);
		this.albumId.dom.innerHTML = this.items[this.nowPage-1].id;
		this.pid.dom.value = this.items[this.nowPage-1].id; 
		// 照片上传时间
		this.albumDate = Ext.get('albumDate');
		if(this.albumDate == null){this.albumDate = Ext.get('album');}
		this.albumDate.dom.innerHTML = this.items[this.nowPage-1].date;
		// 照片描述
		this.albumCommon = Ext.get('albumCommon');
		if(this.albumCommon == null){this.albumCommon = Ext.get('album');}
		this.albumCommon.dom.innerHTML = this.items[this.nowPage-1].pl;
		this.updateTitleAndCom(this.nowPage-1);
	},
	
	/**
	* 初始化事件
	*/
	oneInitEvent: function(){
		var me = this;
		for(var i=0; i<this.nowShowNo.length; i++){
   			if(this.nowShowNo[i] != 0){
   				this.nowShowNo[i] = this.nowShowNo[i] + 4;
   			}
   			if(this.nowShowNo[i] > this.length){
   				this.nowShowNo[i] = 0;
   			}
   		}
		// 创建小图片
		this.bigImgChange();
		for(var i=0; i<this.length; i++){
			var imgDiv = this.showSmallHide.createChild({
				tag: 'div',
				cls: 'imgDiv'
			});
			var imgSmall = imgDiv.createChild({
				tag: 'img',
				cls: 'imgSmall',
				title: this.items[i].title,
				src: this.items[i].smallImg
			});
			if(imgSmall.dom.offsetWidth > 60){
				//imgSmall.setStyle('margin-left', -(imgSmall.dom.offsetWidth - 60) / 2 + 'px');
				imgSmall.setStyle('width', '60px');
				imgSmall.setStyle('height', '60px');
			}
			imgSmall.on('click', function(e, t){
				me.changeImg(t);
			});
			if(i == this.nowPage - 1){
				me.changeImg(imgSmall.dom);
			}
		}
		
		// 初始化事件
		// 鼠标移动到大图片变化形状
		this.showBig.on('mousemove', function(e, t){
			var sss = this.getX() + (this.dom.offsetWidth / 2);
			var base = Ext.select('base');
   			var ba = '';
   			if(base.elements[0].innerHTML != ''){
   				ba = base.elements[0].href + 'js/ssh/images/';
   			}else{
   				ba = 'css/images/';
   			}
			if(e.xy[0] > sss){
				me.showBig.setStyle('cursor', 'url(fts_res/js/ssh/images/album-right.cur), auto');
			}else{
   				me.showBig.setStyle('cursor', 'url(fts_res/js/ssh/images/album-left.cur), auto');
   			}
   		});
   		this.showBig.on('mouseover', function(e, t){
   			var base = Ext.select('base');
   			var ba = '';
   			if(base.elements[0].innerHTML != ''){
   				ba = base.elements[0].href + 'js/ssh/images/';
   			}else{
   				ba = 'css/images/';
   			}
   			var sss = this.getX() + (this.dom.offsetWidth / 2);
   			if(e.xy[0] > sss){
				me.showBig.setStyle('cursor', 'url(fts_res/js/ssh/images/album-right.cur), auto');
			}else{
   				me.showBig.setStyle('cursor', 'url(fts_res/js/ssh/images/album-left.cur), auto');
   			}
   		});
   		this.showBig.on('mouseout', function(e, t){
   			me.showBig.removeClass('showBig-left');
   			me.showBig.removeClass('showBig-right');
   		});
   		
   		// 小图片左侧按钮点击事件
   		this.leftS.on('click', function(e, t){
   			if(me.nowShowNo[0] != 1){
   				me.leftJudge(me.srollCount);
   			}else{
   				// 从第一位翻到最后一位
   				var sy = (me.length - 9) % 4;
   				var sd = parseInt((me.length - 9) / 4) + 1;
   				me.showSmallHide.setLeft(-me.srollCount * sd);
   				me.nowShowNo[me.nowShowNo.length - sy - 1] = me.length;
   				var s = 1;
   				for(var i=me.nowShowNo.length - sy - 2; i>-1; i--){
   					me.nowShowNo[i] = me.length - s;
   					s = s + 1;
   				}
   				for(var i=me.nowShowNo.length - sy; i<me.nowShowNo.length; i++){
   					me.nowShowNo[i] = 0;
   				}
   			}
   		});
   		
   		// 小图片右侧按钮点击事件
   		this.rightS.on('click', function(e, t){
   			if(me.nowShowNo[8] != 0 && me.nowShowNo[8] != me.length ){
   				me.rightJudge(-me.srollCount);
   			}else{
   				me.showSmallHide.setLeft(0);
   				if(me.nowShowNo[0] != 0){
   					me.nowShowNo = [1, 2, 3, 4, 5, 6, 7, 8, 9];
   				}
   			}
   		});
   		
   		// 大图片点击事件
   		this.showBig.on('click', function(e, t){
   			me.imgClick(e, t);
   		});
   		
   		// 标题修改
   		var userid = Ext.fly('userid').dom.value.split(';');
   		if(userid[0] == userid[1]){
	   		Ext.fly(this.albumTitle.dom.children[1].children[0]).on('click', function(e, t){
	   			me.albumTitle.dom.children[3].value = '';
	   			Ext.fly(me.albumTitle.dom.children[3]).setStyle('display', 'block');
	   			Ext.fly(me.albumTitle.dom.children[4]).setStyle('display', 'block');
	   		});
	   		// 提交按钮（标题）
	   		Ext.fly(this.albumTitle.dom.children[4].children[0]).on('click', function(e, t){
	   			Ext.Ajax.request({
					url: me.ajaxUrl + 'updatePhotoTitle.do?pid='+me.albumTitle.dom.children[5].innerHTML+'&ptitle='+me.albumTitle.dom.children[3].value,
			   		success: function(response, opts) {
			   			alert('修改完成！！');
			   			Ext.fly(me.albumTitle.dom.children[3]).setStyle('display', 'none');
	   					Ext.fly(me.albumTitle.dom.children[4]).setStyle('display', 'none');
			     	},
			   		failure: function(response, opts) {
			      		console.log('服务端失效的状态代码： ' + response.status);
			   		}
				});
	   		});
	   		// 返回按钮（标题）
	   		Ext.fly(this.albumTitle.dom.children[4].children[1]).on('click', function(e, t){
	   			Ext.fly(me.albumTitle.dom.children[3]).setStyle('display', 'none');
	   			Ext.fly(me.albumTitle.dom.children[4]).setStyle('display', 'none');
	   		});
   		}else{
   			if(this.albumTitle != null){
				Ext.fly(this.albumTitle.dom.children[1].children[0]).setStyle('display', 'none');
			}
   		}
   		
   		
   		
   	},

   	/**
   	* 第二种方式初始化
   	*/
   	twoInitUI: function(){
   		var me = this;
   		var dsh = document.documentElement.scrollHeight || document.body.scrollHeight;
		var dch = document.documentElement.clientHeight || document.body.clientHeight;
		var dsw = document.documentElement.scrollWidth || document.body.scrollWidth;
		var dcw = document.documentElement.clientWidth || document.body.clientWidth;        	
		this.bdh = (dsh>dch) ? dsh : dch;
		this.bdw = (dsw>dcw) ? dsw : dcw;
   		
   		// 创建元素
		// 控件最外层DIV
   		this.div = Ext.fly(this.renderTo).createChild({tag: 'div', cls: 'album-two-default'});
   		// 遮罩层
   		this.block = this.div.createChild({tag: 'div', cls: 'block'});
   		// 显示层
   		this.showDiv = this.div.createChild({tag: 'div', cls: 'showDiv'});
   		// 图片显示层
   		this.imgDiv = this.showDiv.createChild({tag: 'div', cls: 'imgDiv'});
   		// 关闭按钮
   		this.closed = this.imgDiv.createChild({tag: 'div', cls: 'closed'});
   		// 图片显示
   		this.imgBig = this.imgDiv.createChild({tag: 'img', cls: 'imgBig', src: this.items[this.nowPage-1].bigImg});
   		// 页数显示
   		this.pages = this.imgDiv.createChild({tag: 'span', cls: 'pages', html: this.items[this.nowPage-1].title + '&nbsp;&nbsp;' + this.nowPage +'/' + this.length });
   		// 工具条显示层
   		this.toolbarDiv = this.div.createChild({tag: 'div', cls: 'toolbarDiv'});
   		// 左面边框
   		this.leftSpan = this.toolbarDiv.createChild({tag: 'span', cls: 'leftSpan'});
   		// 工具条
   		this.toolbar = this.toolbarDiv.createChild({tag: 'ul', cls: 'toolbar'});
   		// 右面边框
   		this.rightSpan = this.toolbarDiv.createChild({tag: 'span', cls: 'rightSpan'});
   		// 工具项
   		var share = this.toolbar.createChild({tag: 'li', cls: 'share'});
   		// 分享
   		this.shareSpan = share.createChild({tag: 'span', cls: 'shareSpan', title: '分享'});
   		this.shareSpan2 = share.createChild({tag: 'span', cls: 'shareSpan-move', title: '分享'});
   		// 转到空间
   		this.spaceSpan = share.createChild({tag: 'span', cls: 'spaceSpan', title: '转到空间'});
   		this.spaceSpan2 = share.createChild({tag: 'span', cls: 'spaceSpan-move', title: '转到空间'});
   		// 左旋转
   		this.leftRotation = share.createChild({tag: 'span', cls: 'leftRotation', title: '左旋转'});
   		this.leftRotation2 = share.createChild({tag: 'span', cls: 'leftRotation-move', title: '左旋转'});
   		// 右旋转
   		this.rightRotation = share.createChild({tag: 'span', cls: 'rightRotation', title: '右旋转'});
   		this.rightRotation2 = share.createChild({tag: 'span', cls: 'rightRotation-move', title: '右旋转'});
   		// 图片比例
   		this.imgProportion = share.createChild({tag: 'span', cls: 'imgProportion', title: '图片比例'});
   		this.imgProportion2 = share.createChild({tag: 'span', cls: 'imgProportion-move', title: '图片比例'});
   		// 左翻页
   		this.leftPage = share.createChild({tag: 'span', cls: 'leftPage', title: '左翻页'});
   		this.leftPage2 = share.createChild({tag: 'span', cls: 'leftPage-move', title: '左翻页'});
   		// 右翻页
   		this.rightPage = share.createChild({tag: 'span', cls: 'rightPage', title: '右翻页'});
   		this.rightPage2 = share.createChild({tag: 'span', cls: 'rightPage-move', title: '右翻页'});
   		// 关闭
   		this.closeSpan = share.createChild({tag: 'span', cls: 'closeSpan', title: '关闭'});
   		this.closeSpan2 = share.createChild({tag: 'span', cls: 'closeSpan-move', title: '关闭'});
   		
   		if(Ext.isIE6){
	   		this.fixIE6Png();
	   	}
   		
   		// 保存图片的默认宽度和高度
   		this.defImgWidth = this.width;
   		this.defImgHeight = this.height;
   		this.Proportion = this.defImgHeight / this.defImgWidth;
   	},	
   	
   	/**
	* 初始化事件
	*/
	twoInitEvent: function(){	
		var me = this;
		// 遮罩层
		this.block.setStyle('width', this.bdw + 'px');
		this.block.setStyle('height', this.bdh + 'px');
		this.block.setOpacity(0.5);
		// 图片
		// 设定图片大小
		this.imgBig.on('load', function(e, t){
			if(me.imgBig.dom.offsetWidth > me.defImgWidth ){
				me.imgBig.setStyle('width', me.defImgWidth + 'px');
				me.imgBig.setStyle('height', me.Proportion * me.defImgWidth + 'px');
			}else if(me.imgBig.dom.offsetHeight > me.defImgHeight){
				me.imgBig.setStyle('height', me.defImgHeight + 'px');
				me.imgBig.setStyle('width', me.defImgHeight / me.Proportion + 'px');
			}
		
			// 图片显示层
			me.imgDiv.setStyle('width', me.imgBig.dom.offsetWidth + 10 + 'px');
			if(Ext.isIE6){
				me.imgDiv.setStyle('height', me.imgBig.dom.offsetHeight + 10 + 'px');
			}else{
				me.imgDiv.setStyle('height', me.imgBig.dom.offsetHeight + 25 + 'px');
			}
			// 显示层
			var left = (me.bdw - me.showDiv.dom.offsetWidth) / 2;
			var top = (me.bdh - me.showDiv.dom.offsetHeight - 70) / 2;
			me.showDiv.setStyle('left', left + 'px');
			me.showDiv.setStyle('top', document.documentElement.scrollTop + 150 + 'px'); 
			// 页数显示
			me.pages.setStyle('bottom', '10px');
			me.pages.setStyle('right',  '15px');
			// 关闭按钮
			if(Ext.isIE){
				me.closed.setStyle('left', me.imgBig.dom.offsetWidth-20 + 'px');
				me.closed.setStyle('margin-top', '-6px');
			}else{
				me.closed.setStyle('left', me.imgBig.dom.offsetWidth-8 + 'px');
				me.closed.setStyle('margin-top', '-15px');
			}
			
			
			// 工具条显示层
			if(!Ext.isIE6){
				me.toolbarDiv.setStyle('left', (me.bdw - 406) / 2 + 'px');
			}
			me.toolbarDiv.setStyle('top', document.documentElement.scrollTop + me.showDiv.dom.offsetHeight + 160 + 'px');
			// 工具项集合（分享、转存、左旋转、右旋转、图片比例、左翻页、右翻页、关闭）
			me.shareSpan.addClass('imgPng');
			me.shareSpan2.addClass('imgPng');
			me.shareSpan2.setStyle('display', 'none');
			me.spaceSpan.addClass('imgPng');
			me.spaceSpan2.addClass('imgPng');
			me.spaceSpan2.setStyle('display', 'none');
			me.leftRotation.addClass('imgPng');
			me.leftRotation2.addClass('imgPng');
			me.leftRotation2.setStyle('display', 'none');
			me.rightRotation.addClass('imgPng');
			me.rightRotation2.addClass('imgPng');
			me.rightRotation2.setStyle('display', 'none');
			me.imgProportion.addClass('imgPng');
			me.imgProportion2.addClass('imgPng');
			me.imgProportion2.setStyle('display', 'none');
			me.imgProportion.setStyle('display', 'none');
			me.imgProportion2.addClass('imgPng');
			me.imgProportion2.setStyle('display', 'none');
			me.leftPage.addClass('imgPng');
			me.leftPage2.addClass('imgPng');
			me.leftPage2.setStyle('display', 'none');
			me.rightPage.addClass('imgPng');
			me.rightPage2.addClass('imgPng');
			me.rightPage2.setStyle('display', 'none');
			me.closeSpan.addClass('imgPng');
			me.closeSpan2.addClass('imgPng');
			me.closeSpan2.setStyle('display', 'none');
		});
		
		
  		// 事件
   		// 鼠标移动到关闭按钮事件
   		this.closed.on('mouseover', function(e, t){
   			this.setStyle('-moz-transform', 'scale(1.2) rotate(360deg)');
   		});
   		this.closed.on('mouseout', function(e, t){
   			this.setStyle('-moz-transform', 'none');
   		});

   		// 关闭按钮
   		this.closed.on('click', function(){
   			me.div.setStyle('display', 'none');
   		});
   		
   		// 大图片点击事件
   		this.imgBig.on('click', function(e, t){
   			if(e.xy[0]>me.bdw/2){
   				if(me.nowBigImg != me.length-1){
   					me.nowBigImg = me.nowBigImg + 1; 
   				}else{
   					me.nowBigImg = 0;
   				}
   			}else{
   				if(me.nowBigImg != 0){
   					me.nowBigImg = me.nowBigImg - 1; 
   				}else{
   					me.nowBigImg = me.length - 1;
   				}
   			}
   			me.imgBig.dom.src = me.items[me.nowBigImg].bigImg;
   			me.pages.dom.innerHTML = me.items[me.nowBigImg].title + '&nbsp;&nbsp;' + (me.nowBigImg + 1) + '/' + me.length;
   		
   		});
   		
   		// 鼠标移动到大图片变化形状
		this.imgDiv.on('mousemove', function(e, t){
			var sss = this.getX() + (this.dom.offsetWidth / 2);
			var base = Ext.select('base');
			if(e.xy[0] > sss){
				me.imgDiv.setStyle('cursor', 'url(fts_res/js/ssh/images/album-right.cur), auto');
			}else{
   				me.imgDiv.setStyle('cursor', 'url(fts_res/js/ssh/images/album-left.cur), auto');
   			}
   		});
   		this.imgDiv.on('mouseover', function(e, t){
   			var sss = this.getX() + (this.dom.offsetWidth / 2);
   			var base = Ext.select('base');
			if(e.xy[0] > sss){
				me.imgDiv.setStyle('cursor', 'url(fts_res/js/ssh/images/album-right.cur), auto');
			}else{
   				me.imgDiv.setStyle('cursor', 'url(fts_res/js/ssh/images/album-left.cur), auto');
   			}
   		});
   		this.imgDiv.on('mouseout', function(e, t){
   			me.imgDiv.removeClass('showBig-left');
   			me.imgDiv.removeClass('showBig-right');
   		});
   		
   		// 工具条事件
   		// 分享(鼠标停靠、鼠标移出、点击)
   		this.shareSpan.on('mouseover', function(e, t){
   			me.shareSpan.addClass('shareSpan-move');
   			if(Ext.isIE6){
   				me.shareSpan.setStyle('display', 'none');
   				me.shareSpan2.setStyle('display', 'block');
   			}
   		});
   		this.shareSpan.on('mouseout', function(e, t){
   			me.shareSpan.removeClass('shareSpan-move');
   			if(Ext.isIE6){
   				me.shareSpan2.setStyle('display', 'none');
   				me.shareSpan.setStyle('display', 'block');
   			}
   		});
   		this.shareSpan.on('mouseup', function(e, t){
   		});
   		
   		// 转存(鼠标停靠、鼠标移出、点击)
   		this.spaceSpan.on('mouseover', function(e, t){
   			me.spaceSpan.addClass('spaceSpan-move');
   			if(Ext.isIE6){
   				me.spaceSpan.setStyle('display', 'none');
   				me.spaceSpan2.setStyle('display', 'block');
   			}
   		});
   		this.spaceSpan.on('mouseout', function(e, t){
   			me.spaceSpan.removeClass('spaceSpan-move');
   			if(Ext.isIE6){
   				me.spaceSpan2.setStyle('display', 'none');
   				me.spaceSpan.setStyle('display', 'block');
   			}
   		});
   		this.spaceSpan.on('mouseup', function(e, t){
   		});
   		
   		// 左旋转(鼠标停靠、鼠标移出、点击)
   		this.leftRotation.on('mouseover', function(e, t){
   			me.leftRotation.addClass('leftRotation-move');
   			if(Ext.isIE6){
   				me.leftRotation.setStyle('display', 'none');
   				me.leftRotation2.setStyle('display', 'block');
   			}
   		});
   		this.leftRotation.on('mouseout', function(e, t){
   			me.leftRotation.removeClass('leftRotation-move');
   			if(Ext.isIE6){
   				me.leftRotation2.setStyle('display', 'none');
   				me.leftRotation.setStyle('display', 'block');
   			}
   		});
   		this.leftRotation.on('mouseup', function(e, t){
   			me.turnDegree = me.turnDegree - 90;
   			var nos = me.turnDegree / 90;
   			if(nos < 0){ nos = nos * -1}
   			if(Ext.isIE){
   			//	me.closed.setStyle('left', me.imgBig.dom.offsetWidth-20 + 'px');
			//	me.closed.setStyle('margin-top', '-8px');
   				me.showDiv.setStyle('filter', 'progid:DXImageTransform.Microsoft.BasicImage( rotation= '+ nos +')');
   			}else{
   				me.showDiv.setStyle('-moz-transform', 'rotate('+ me.turnDegree +'deg)');
   			}
   			me.degree();
   		});
   		
   		// 右旋转(鼠标停靠、鼠标移出、点击)
   		this.rightRotation.on('mouseover', function(e, t){
   			me.rightRotation.addClass('rightRotation-move');
   			if(Ext.isIE6){
   				me.rightRotation.setStyle('display', 'none');
   				me.rightRotation2.setStyle('display', 'block');
   			}
   		});
   		this.rightRotation.on('mouseout', function(e, t){
   			me.rightRotation.removeClass('rightRotation-move');
   			if(Ext.isIE6){
   				me.rightRotation2.setStyle('display', 'none');
   				me.rightRotation.setStyle('display', 'block');
   			}
   		});
   		this.rightRotation.on('mouseup', function(e, t){
   			me.turnDegree = me.turnDegree + 90;
   			var nos = me.turnDegree / 90;
   			if(nos < 0){ nos = nos * -1}
   			if(Ext.isIE){
   			//	me.closed.setStyle('left', me.imgBig.dom.offsetWidth-20 + 'px');
			//	me.closed.setStyle('margin-top', '-8px');
   				me.showDiv.setStyle('filter', 'progid:DXImageTransform.Microsoft.BasicImage( rotation= '+ nos +')');
   			}else{
   				me.showDiv.setStyle('-moz-transform', 'rotate('+ me.turnDegree +'deg)');
   			}
   			me.degree();
   		});
   		
   		// 图片比例(鼠标停靠、鼠标移出、点击)
   		this.imgProportion.on('mouseover', function(e, t){
   			me.imgProportion.addClass('imgProportion-move');
   			if(Ext.isIE6){
   				me.imgProportion.setStyle('display', 'none');
   				me.imgProportion2.setStyle('display', 'block');
   			}
   		});
   		this.imgProportion.on('mouseout', function(e, t){
   			me.imgProportion.removeClass('imgProportion-move');
   			if(Ext.isIE6){
   				me.imgProportion2.setStyle('display', 'none');
   				me.imgProportion.setStyle('display', 'block');
   			}
   		});
   		this.imgProportion.on('mouseup', function(e, t){
   		});
   		
   		// 左翻页(鼠标停靠、鼠标移出、点击)
   		this.leftPage.on('mouseover', function(e, t){
   			me.leftPage.addClass('leftPage-move');
   			if(Ext.isIE6){
   				me.leftPage.setStyle('display', 'none');
   				me.leftPage2.setStyle('display', 'block');
   			}
   		});
   		this.leftPage.on('mouseout', function(e, t){
   			me.leftPage.removeClass('leftPage-move');
   			if(Ext.isIE6){
   				me.leftPage2.setStyle('display', 'none');
   				me.leftPage.setStyle('display', 'block');
   			}
   		});
   		this.leftPage.on('click', function(e, t){
   			if(me.nowBigImg != 0){
   				me.nowBigImg = me.nowBigImg - 1; 
   			}else{
   				me.nowBigImg = me.length - 1;
   			}
   			me.imgBig.dom.src = me.items[me.nowBigImg].bigImg;
   			me.pages.dom.innerHTML = me.items[me.nowBigImg].title + '&nbsp;&nbsp;' + (me.nowBigImg + 1) +'/' + me.length;
   		});
   		
   		// 右翻页(鼠标停靠、鼠标移出、点击)
   		this.rightPage.on('mouseover', function(e, t){
   			me.rightPage.addClass('rightPage-move');
   			if(Ext.isIE6){
   				me.rightPage.setStyle('display', 'none');
   				me.rightPage2.setStyle('display', 'block');
   			}
   		});
   		this.rightPage.on('mouseout', function(e, t){
   			me.rightPage.removeClass('rightPage-move');
   			if(Ext.isIE6){
   				me.rightPage2.setStyle('display', 'none');
   				me.rightPage.setStyle('display', 'block');
   			}
   		});
   		this.rightPage.on('mouseup', function(e, t){
   			if(me.nowBigImg != me.length + 1){
   				me.nowBigImg = me.nowBigImg + 1; 
   			}else{
   				me.nowBigImg = 0;
   			}
   			me.imgBig.dom.src = me.items[me.nowBigImg].bigImg;
   			me.pages.dom.innerHTML = me.items[me.nowBigImg].title + '&nbsp;&nbsp;' + (me.nowBigImg + 1) +'/' + me.length;
   		});
   		
   		// 关闭(鼠标停靠、鼠标移出、点击)
   		this.closeSpan.on('mouseover', function(e, t){
   			me.closeSpan.addClass('closeSpan-move');
   			if(Ext.isIE6){
   				me.closeSpan.setStyle('display', 'none');
   				me.closeSpan2.setStyle('display', 'block');
   			}
   		});
   		this.closeSpan.on('mouseout', function(e, t){
   			me.closeSpan.removeClass('closeSpan-move');
   			if(Ext.isIE6){
   				me.closeSpan2.setStyle('display', 'none');
   				me.closeSpan.setStyle('display', 'block');
   			}
   		});
   		this.closeSpan.on('mouseup', function(e, t){
   			me.div.setStyle('display', 'none');
   		});
   		
   		// 浏览器大小改变事件
  /* 		Ext.fly(window).on('resize', function(e, t){
   			var divWidth = document.documentElement.clientWidth;
			var divHeight = document.documentElement.clientHeight;
			var imgWidth = me.imgBig.dom.width;
			var imgHeight = me.imgBig.dom.height;
			
			var left = 0;
			var top = 0;
			
			me.imgBig.setStyle('top', '5px');
			me.imgBig.setStyle('left', '5px');
				
			top = (divHeight - me.showDiv.dom.offsetHeight - 65) / 2;
			if(top < 15 || imgHeight < me.imgBig.dom.height ){	
				imgHeight = (divHeight - 100 > me.defImgHeight) ? me.defImgHeight : divHeight - 100;
				imgWidth = imgHeight / me.Proportion;
				me.imgBig.setStyle('width', imgWidth + 'px');
				me.imgBig.setStyle('height', imgHeight + 'px');
				me.imgDiv.setStyle('width', imgWidth + 10 + 'px');
				me.imgDiv.setStyle('height', imgHeight + 10 + 'px');
				if(me.turnDegree % 180 != 0){
	   				me.imgDiv.setStyle('width', imgHeight + 10 + 'px');
					me.imgDiv.setStyle('height', imgWidth + 10 + 'px');
					if(Ext.isIE){
						me.imgBig.setStyle('left', '5px');
						me.imgBig.setStyle('top', '5px');
					}else{
						me.imgBig.setStyle('left', -(imgWidth - imgHeight) / 2 + 5 + 'px');
						me.imgBig.setStyle('top', (imgWidth - imgHeight) / 2 + 5 + 'px');
					}
				}
				top = 15;
			}
			left = (divWidth - me.showDiv.dom.offsetWidth) / 2;
			if(top != -1){
				me.showDiv.setStyle('top', top + 'px'); 
				me.closed.setStyle('top', top - 25 + 'px');
				if(Ext.isIE){
					me.closed.setStyle('top', top - 32 + 'px');
				}
			}
				
			me.toolbarDiv.setStyle('left', (divWidth - 406) / 2 + 'px')
			me.block.setStyle('width', divWidth + 'px');
			me.block.setStyle('height', divHeight + 'px');
			me.showDiv.setStyle('left', left + 'px');
			me.closed.setStyle('left', left + me.showDiv.dom.offsetWidth - 25 + 'px');
			if(Ext.isIE6 || Ext.isIE7){
				me.closed.setStyle('top', top - 30  + 'px'); 
			}
	   	}); */
 	}
})    
/**
 * 下拉框控件
 * @author 聂庆童
 * @version 1.0
 * @2011-9-15	
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.DownBox = Ext.extend(Ext.util.Observable,{
	isShowImg: false,		// 是否显示图片
	isOnReading: false,		// 文本框是否可以输入
	isShow: false,		// 下拉框是否打开 
	pd: false,		// 判断是否失去焦点
	length: 0,		// 数据量
	ajaxUrl: null,		// Ajax访问路径
	deValue: '',		// 当前选择的ID
	
	// 创建构造方法
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
        this.initUI();
        this.initEvents();
    },
    
    /**
    * 初始化界面
    */
    initUI: function(){
    	// 外层框架
    	this.div = Ext.fly(this.renderTo).createChild({tag: 'div', cls: this.cls});
    	// 文本框(输入和显示)
    	this.text = this.div.createChild({tag: 'input', type: 'text', cls: 'text'});
    	// 下拉按钮
    	this.img = this.div.createChild({tag: 'div', cls: 'img'});
    	// 选项显示层
    	this.showDiv = this.div.createChild({tag: 'div', cls: 'showDiv'});
    	// 隐藏域
    	this.hide = this.div.createChild({tag: 'input', type: 'text', name: 'downHide', id: 'downHide', style: 'display: none;'});
    	
    	// 初始化设置
    	this.text.setStyle('width', this.width + 'px');
    	// 设置文本框是否可以输入
    	if(this.isOnReading == false){this.text.dom.readOnly = true;}
    	this.img.setStyle('left', this.width + 2 + this.text.getX() + 'px');
    	this.img.setStyle('top', this.text.getY() + 'px');
    	this.showDiv.setStyle('width', this.width + 17 + 'px');
    	this.showDiv.setStyle('height', '200px');
    	this.showDiv.setStyle('display', 'none');
    	if(Ext.isIE6 || Ext.isIE7){
    		this.showDiv.setStyle('left', this.text.getX());
    		this.showDiv.setStyle('top', this.text.getY() + 24);
    		this.showDiv.setStyle('width', this.width + 17);
    	}
    	
    	// 通过ajax获取数据
    	if(this.ajaxUrl != '' && this.ajaxUrl != null){
    		this.ajax();
    	}
    	// IE下this.items.length的值比实际多1
    	if(Ext.isIE){
    		this.length = this.items.length - 1;
    	}else{
    		this.length = this.items.length;
    	}
    	// 载入全部选项
    	this.addSpan();
    },
    
    /**
    * 初始化事件
    */
    initEvents: function(){
    	var me = this;
    	// 下拉按钮--鼠标移上
    	this.img.on('mouseover', function(e, t){
    		me.img.setStyle('background-position', '-17px 0');
    	});
    	// 下拉按钮--鼠标移开
    	this.img.on('mouseout', function(e, t){
    		me.img.setStyle('background-position', '0 0');
    	});
    	// 下拉按钮--鼠标按下
    	this.img.on('mousedown', function(e, t){
    		me.img.setStyle('background-position', '-34px 0');
    		me.pd = true;
    	});
    	// 下拉按钮--鼠标按下
    	this.img.on('mouseup', function(e, t){
    		me.img.setStyle('background-position', '0 0');
    	});
    	// 下拉按钮--点击
    	this.img.on('click', function(e, t){
    		if(me.isShow == false){
    			me.showDiv.setStyle('display', 'block');
    			me.isShow = true;
    		}else{
    			me.showDiv.setStyle('display', 'none');
    			me.isShow = false;
    		}
    		me.pd = false;
    		me.text.focus();
    	});
    	// 显示层--按下抬起
    	this.showDiv.on('mousedown', function(e, t){
    		me.pd = true;
    	});
    	this.showDiv.on('mouseup', function(e, t){
    		me.pd = false;
    		me.text.focus();
    	});
    	// 文本框--点击
    	this.text.on('click', function(e, t){
    		if(me.isShow == false){
    			me.showDiv.setStyle('display', 'block');
    			me.isShow = true;
    		}else{
    			me.showDiv.setStyle('display', 'none');
    			me.isShow = false;
    		}
    	});
    	// 文本框--键盘升起
    	this.text.on('keyup', function(e, t){
    		var value = me.text.dom.value;
    		me.findSpan(value);
    		
    	});
    	// 文本框--失去焦点
    	this.text.on('blur', function(e, t){
    		if(me.pd == true){
	    		me.pd = false;
	    		return;
		    }
		    me.showDiv.setStyle('display', 'none');
		    me.isShow = false;
		    if(me.text.dom.value == '' || me.text.dom.value == null){
		    	me.hide.dom.value = '';
		    }else{
		    	me.text.dom.value = me.deValue;
		    }
		    
    	});
    },
    
    /**
    * 加载选项
    */
    addSpan: function(key){
    	var me = this;
    	// 默认加载全部选项
    	for(var i=0; i<this.length; i++){
    		// 判断是否显示图片
   			if(this.isShowImg == true){
    			var html = '<img src="'+this.items[i].imgUrl+'" class="images" /><font class="font">' + this.items[i].value+'</font>';
    		}else{
    			var html =  '<font class="font">'+this.items[i].value+'</font>';
    		}
    		// 选项
    		var span = this.showDiv.createChild({tag: 'span', cls: 'span', name: this.items[i].id, html: html});
    		me.spanFun(span, i);
    	}
    	if(length < 10){
    		this.showDiv.setStyle('height', this.length * 20 + 'px');
    	}else{
    		this.showDiv.setStyle('height', '200px');
    	}
    },
    
    /**
    * 选项选择
    */
    selectSpan: function(id){
    	for(var i=0; i<this.length; i++){
    		if(id == this.items[i].id){
    			this.text.dom.value = this.items[i].value;
    			this.hide.dom.value = this.items[i].id;
    			this.deValue = this.items[i].value;
    		}
    	}
    },
    
    /**
    * ajax获取数据
    */
    ajax: function(){
		var me = this;
		Ext.Ajax.request({
			url: me.ajaxUrl,
	   		success: function(response, opts) {
	     		me.items = Ext.util.JSON.decode(response.responseText); 
	     	},
	   		failure: function(response, opts) {
	      		console.log('服务端失效的状态代码： ' + response.status);
	   		}
		});
	},
	
	/**
	* 根据输入内容查询选项
	*/
	findSpan: function(value){
		var spans = this.showDiv.dom.children;
		this.showDiv.select('span:nth-child(n)').remove();
		var s = 0;
		var len = value.length;
		for(var i=0; i<this.length; i++){
			var val = this.items[i].value.substring(0, len);
			if(val == value){
				if(this.isShowImg == true){
	    			var html = '<img src="'+this.items[i].imgUrl+'" class="images" /><font class="font">' + this.items[i].value+'</font>';
	    		}else{
	    			var html =  '<font class="font">'+this.items[i].value+'</font>';
	    		}
	    		// 选项
	    		var span = this.showDiv.createChild({tag: 'span', cls: 'span', name: this.items[i].id, html: html});
	    		this.spanFun(span, s);
	    		s++;
				
			}
			
		}
		if(length < 10){
    		this.showDiv.setStyle('height', s * 20 + 'px');
    	}else{
    		this.showDiv.setStyle('height', '200px');
    	}
		this.showDiv.setStyle('display', 'block');
		this.isShow = true;
	},
	
	/**
	* 选项方法集合
	*/
	spanFun: function(span, i){
		var me = this;
		span.setStyle('width', '100%');
    	span.setStyle('margin-top', 20*i + 'px');
    	// 选项移动事件
    	span.on('mouseover', function(e, t){
    		if(t.className == 'images' || t.className == 'font'){t = t.parentNode}
    		Ext.fly(t).addClass('spanMove');
    	});
    	span.on('mouseout', function(e, t){
    		if(t.className == 'images' || t.className == 'font'){t = t.parentNode}
    		Ext.fly(t).removeClass('spanMove');
    	});
    	// 选项点击事件
    	span.on('click', function(e, t){
    		if(t.className == 'images' || t.className == 'font'){t = t.parentNode}
    		me.selectSpan(Ext.get(t).getAttribute('name'));
    		me.showDiv.setStyle('display', 'none');
    		me.isShow = false;
    	});
    	
    	
	}
});    
/**
 * 地图控件
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Map = Ext.extend(Ext.util.Observable,{
	
	width: 720,		// 默认宽度
	height: 500,		// 默认高度
	jsonArr: [],		// JSON数据
	jsonIcon: {w:21,h:25,l:22,t:21,x:6,lb:5},
	iw: [],
	def: [106.55824, 29.571601], 
	isOpenNav: false,
	isOpenSca: false,
	isOpenOve: false,
	isAdmin: false,
	isAjax: false,
	isWindow: false,
	mapSize: 17,
	callback: function(){},
	resNull: true,
	bind: function(){},
	callbackchange: function(){},
	callbackClose: function(){},
	beforeClose: function(){},
	
	/**
	* 构造方法
	*/
	constructor: function(config) {
		// 合并config中的内容
		Ext.apply(this, config);		
       	
    },
    
    /**
    * 初始化界面
    */
    initUI: function(){
    	// 默认值设置
    	this.cls = Ext.isEmpty(this.cls) ? 'map-default' : this.cls;
    	
    	// 创建元素
    	// 控件外框架
    	Ext.fly(this.renderTo).addClass(this.cls);
    	
  //  	if(this.isWindow == false){
    		Ext.fly(this.renderTo).createChild({
	    		tag: 'div',
	    		id: this.renderTo + 'sss',
	    		cls: this.cls
	    	});
   // 	}
   		this.div = Ext.get(this.renderTo + 'sss');
       	
    	
  //  	var zsd = Ext.fly(this.renderTo).dom.parentNode;
    	this.chaDiv = Ext.fly(this.renderTo).createChild({
    		tag: 'div',
    		title: '进入全屏状态',
    		cls: 'inFull'
    	});
    	this.chaDiv.setStyle('margin-top', '-'+ (parseInt(this.height)-5) +'px');
    	if(this.isWindow == true){this.chaDiv.setStyle('display', 'none');}
    	
    	
    	if(this.width == 'auto' ){
    		this.width = this.div.dom.offsetWidth - 5;
    		this.height = this.width * 3/4;
    	}
    	this.hide = Ext.get(this.hideId);
    	
    	//创建和初始化地图函数：
	    this.createMap();//创建地图
	    this.addMapControl();//向地图添加控件
	    this.addMarker();//向地图中添加marker
	 },
	 
	 /**
	 * 初始化事件
	 */
	 initEvent: function(){
	 	var me = this;
	 	var render = Ext.fly(me.renderTo).createChild({tag: 'div', id: 'mapDiv' + me.renderTo, style: 'display:none;'});
	 	var hideId = Ext.fly(me.renderTo).createChild({tag: 'div', id: 'hideId' + me.renderTo, style: 'display:none;'});
	 	this.setMapEvent();//设置地图事件
	 	this.chaDiv.on('click', function(e, t){
	 		var map = new ssh.Map({
				renderTo: render.dom.id,       				// 控件展示位置
				hideId: hideId.dom.id,						// 隐藏域
				width: 1200,							// 控件宽度
				height: 650,						// 控件高度
				cls: 'map-default',						// 控件样式
				ajaxUrl: 'servlet/MapServlet',			// 保存路径
				jsonIcon: {w:21,h:21,l:0,t:0,x:6,lb:5},
				def: me.def,		// 初始坐标
				mapSize: 17,						// 地图默认比例
				isWindow: true,						// 窗口中打开地图
				isAjax: false,						// 是否开启AJAX保存
				isOpenOve: true,					// 是否开启小地图		
				isOpenSca: true,					// 是否开启比例尺		
				isOpenNav: true,					// 是否开启缩放	
				isAdmin: false,						// 是否管理员（管理员可修改地图上的信息）
			//	callback: function(){alert('1');},			// 回调方法
			//	callbackchange: function(){ale);},	// 隐藏域改变的方法
			//	callbackClose: function(){alert('3');}, 	// 取消和关闭
				resNull: true,						// 点取消是否清空
				jsonArr: me.jsonArr
			});
			map.show();
	 	});
	 },
	 
	 /**
	 * 创建地图
	 */
	 show: function(){
	 	this.jsonIcon = {w:21,h:25,l:22,t:21,x:6,lb:5};
	    var wins = null;
	    var me = this;
	 	Ext.fly(this.renderTo).dom.innerHTML = '';
	 	if(this.isWindow == true){
	 		this.width = 720;
	 		this.height = 500;
	 		wins = this.openByWindow();
	 		this.renderTo = this.renderTo + '123';
	 	}
	 	if(this.jsonArr == null){
	 		this.jsonArr = [];
	 		this.jsonArr[0] = {title:"默认",content:"默认",point:"106.55824|29.571601"};
	 		this.def = [106.55824, 29.571601];
	 	}else{
	 		this.def = [this.jsonArr[0].point.split('|')[0], this.jsonArr[0].point.split('|')[1]];
	 	}
	 	this.initUI();
	 	this.initEvent();
	 	if(this.hide != null){
	 		this.hide.dom.value = '';
       	}
       	if(this.isWindow == true){
	 		wins.center();	 	
	 		var res = Ext.select('a[class=window-button]');
	 		if(Ext.fly(res.elements[1]) != null){
	 			Ext.fly(res.elements[1]).addClass('resBlue');
	 		}
	 	}
	 	
    	
   		
       	window.setTimeout(function(){
       		var nos = Ext.select('a[title=到百度地图查看此区域]');
       		if(me.hide != null){
	       		me.hide.dom.value = Ext.util.JSON.encode(me.jsonArr);
	       		me.callbackchange('null');
	       	}
    	},1000);
       
       	
	 	
	 },
	 
	 /**
	 * 增加数据
	 */
	 add: function(item){
	 	this.jsonArr.push({title: item.title, content: item.content, point: item.point});
	 	this.hide = Ext.get(this.hideId);
	 	if(this.isAjax == true){
	 		this.ajax(this.jsonArr);
	 	}
	 	if(this.hide != null){
	 		this.hide.dom.value = Ext.util.JSON.encode(this.jsonArr);
	 		this.callbackchange('null');
	 	}
	 },
	 
	/**
	 * 位标事件绑定
	 */
	 labelEvent: function(i, marker, label){
	 	var me = this;
	 	var index = i;
		this.iw[i] = this.createInfoWindow(i);
		var _marker = marker;
		_marker.addEventListener("click",function(){
		    this.openInfoWindow(me.iw[i]);
		})
		_marker.addEventListener("dragend",function(e, t){
			var point = this.getPosition();
			var title = e.target.siblingElement.children[1].innerHTML;
			var points = e.target._lastPt.lng + "|" + e.target._lastPt.lat;
			for(var i=0; i<me.jsonArr.length; i++){
				if(title == me.jsonArr[i].title){
					me.jsonArr[i].point = point.lng + "|" +point.lat;
					if(me.isAjax == true){
						me.ajax(me.jsonArr);
					}
					if(me.hide != null){
				 		me.hide.dom.value = Ext.util.JSON.encode(me.jsonArr);
				 		me.callbackchange(e.pixel.x + ',' + e.pixel.y);
				 	}
				}
			}
		})
		me.iw[i].addEventListener("open",function(){
			_marker.getLabel().hide();
		})
		me.iw[i].addEventListener("close",function(){
			 _marker.getLabel().show();
		})
		label.addEventListener("click",function(e, t){
			_marker.openInfoWindow(me.iw[i]);
		})
		if(this.isAdmin == true){
			this.rightClick(i, marker, label);
		}
	},
	 
	 /**
	 * 右键点击事件
	 */
	 rightClick: function(i, marker, label){
	 	var me = this;
	 	var contextMenu = new BMap.ContextMenu();
	 	// 修改
	 	var update = {
	 		text: '修改标题与备注',
	 		callback: function(a, b, c){
	 			var lab = Ext.select('label[class=BMapLabel]');
	 			var points = c._lastPt.lng + '|' + c._lastPt.lat;
	 			var content = '';
	 			var title = '';
	 			var count = 0;
	 			for(var i=0; i<me.jsonArr.length; i++){
	 				if(points == me.jsonArr[i].point){
	 					content = me.jsonArr[i].content;
	 					title = me.jsonArr[i].title;
	 					count = i;
	 				}
	 			}
	 			me.check(title, content, lab, count);
	 		}
	 	}
	 	// 删除位标
	 	var del = {
	 		text: '删除位标',
	 		callback: function(a, b, c){
	 			var lab = Ext.select('label[class=BMapLabel]');
	 			var points = c._lastPt.lng + '|' + c._lastPt.lat;
	 			var content = '';
	 			var count = 0;
	 			for(var i=0; i<me.jsonArr.length; i++){
	 				if(points == me.jsonArr[i].point){
	 					content = me.jsonArr[i].content;
	 					count = i;
	 				}
	 			}
	 			me.jsonArr.splice(count,1);
	 			Ext.get(lab.elements[count].previousSibling).remove();
	 			Ext.get(lab.elements[count]).remove();
	 			if(me.isAjax == true){
					me.ajax(me.jsonArr);
				}
				if(me.hide != null){
			 		me.hide.dom.value = Ext.util.JSON.encode(me.jsonArr);
			 		me.callbackchange();
			 	}
	 		}
	 	}
	 	// 添加事件
	// 	contextMenu.addItem(new BMap.MenuItem(update.text, update.callback, 100));
	// 	contextMenu.addItem(new BMap.MenuItem(del.text, del.callback, 100));
		
	//	marker.addContextMenu(contextMenu);
	 	 
	 },
	 
	 /**
	* Ajax连接数据库	 
	*/ 
	ajax: function(json){
		var zzz = Ext.util.JSON.encode(json);
		var me = this;
		Ext.Ajax.request({
			url: me.ajaxUrl,
			params: {
				jsons: zzz
			},
	   		success: function(response, opts) {
	     	//	me.items = Ext.util.JSON.decode(response.responseText); 
	     	},
	   		failure: function(response, opts) {
	      		console.log('服务端失效的状态代码： ' + response.status);
	   		}
		});
	},
	
	/**
	* 窗口控件
	*/
	check: function(title, content, lab, count){
		var win;
		var me = this;
    	if(Ext.isEmpty(win)){
			win = new ssh.Window({
	        	title : '修改标题与备注',
	       		cls : 'window-blue',
	       		html : '<br/><font style="font-size: 12">新标题：</font><input type="text" id="mapTitle" value="'+title+'" /><br/><br/>'
	       				+'<font style="font-size: 12">新备注：</font><textarea id="mapContent" >'+content+'</textarea><br/><br/>',
	        	isMask: false,
	        	isFixed: false,
	    		isCache: false,
	        	params : {},
	        	buttons:[{type:'custom', text:'确定', 
	        		callback: function(button, handle){
	        			button.on('click', function(){
	        				lab.elements[count].innerHTML = handle.content.dom.children[2].value;
				 			me.jsonArr[count].title = handle.content.dom.children[2].value; 
				 			me.iw[count] = me.createInfoWindow(count);
				 			me.jsonArr[count].content = handle.content.dom.children[6].value;
		 					me.iw[count] = me.createInfoWindow(count);
	        				if(me.isAjax == true){
								me.ajax(me.jsonArr);
							}
	        				if(me.hide != null){
						 		me.hide.dom.value = Ext.util.JSON.encode(me.jsonArr);
						 		me.callbackchange();
						 	}
	        				handle.close(); 
	        				win = null;
	        			})
	        		}}, 
	        	{type:'close',text:'取消'}],
	       		bind : function () {}
	    	});
   		}else{
        	win.show();
        }
    },
    
    // 在窗口控件中打开地图
    openByWindow: function(){
    	var wins;
		var me = this;
		this.beforeClose = function(){
			Ext.get(me.renderTo).dom.innerHTML = '';
		};
		if(Ext.isEmpty(wins)){
    		if(me.isAdmin == false){
    			wins = new ssh.Window({
		        	title : '地图',
		       		cls : 'window-blue',
		       		html : '<div id="'+me.renderTo+'123"></div>',		       		
		       		width: me.width + 15,
		       		callbackClose: me.callbackClose,
		       		beforeClose: me.beforeClose,
		        	isMask: true,
		        	isFixed: false,
		    		isCache: false,
		        	params : {},
		        	buttons:[
			        	{type:'close',text:'关闭', 
			        		callback: function(button, handle){
			        			button.on('click', function(e, t){
			        				if(me.hide != null){
			        				//	if(me.resNull == true){
			        				//		me.hide.dom.value = '';
			        				//	}else{
			        						me.hide.dom.value = Ext.util.JSON.encode(me.jsonArr);
			        				//	}
			        					me.callbackClose();
			        				}
			        			});
			        		}
			        	}
		        	],
		       		bind : me.bind
		    	});	
			}else if(me.isAdmin == true){
				wins = new ssh.Window({
		        	title : '地图',
		       		cls : 'window-blue',
		       		html : '<div id="'+me.renderTo+'123">',
		       		callbackClose: me.callbackClose,
		       		beforeClose: me.beforeClose,
		       		width: me.width + 15,
		        	isMask: true,
		        	isFixed: false,
		    		isCache: false,
		        	params : {},
		        	buttons:[
			        	{type:'custom', text:'确定', 
			        		callback: function(button, handle){
			        			button.on('click', function(e, t){
			        				me.callback();
			        				wins.close();
			        			});
			        		}
			        	}, 
			        	{type:'close',text:'取消', 
			        		callback: function(button, handle){
			        			button.on('click', function(e, t){
			        				if(me.hide != null){
			        					if(me.resNull == true){
			        						me.hide.dom.value = '';
			        					}else{
			        						me.hide.dom.value = Ext.util.JSON.encode(me.jsonArr);
			        					}
			        					me.callbackClose();
			        					
			        				}
			        			});
			        		}
			        	}
		        	],
		       		bind : me.bind
		    	});	
			}
			
   		}else{
        	wins.show();
        }
        return wins;
    },			
   	
   	//创建地图函数：
    createMap: function(){
    	var me = this;
    	var zs = Ext.fly(this.renderTo);
    	this.div.dom.style.width = this.width+"px";
        this.div.dom.style.height = this.height+"px";
        var map = new BMap.Map(this.div.dom.id);//在百度地图容器中创建一个地图
        var point = new BMap.Point(this.def[0], this.def[1]);//定义一个中心点坐标
        map.centerAndZoom(point, this.mapSize);//设定地图的中心点和坐标并将地图显示在地图容器中
        //增加右键菜单
        if(this.isAdmin == true){
        	var contextMenu = new BMap.ContextMenu();
			var txtMenuItem = 
			  {
			   text:'在此添加标注',
			   callback:function(p){
			
				var iconImg = me.createIcon(me.jsonIcon);
	            var marker = new BMap.Marker(p,{icon:iconImg});
				var label = new BMap.Label("新增",{"offset":new BMap.Size(me.jsonIcon.lb-me.jsonIcon.x+10,-20)});
				marker.setLabel(label);
				if(me.isAdmin == true){
					marker.enableDragging(true); 	
	            }
				map.addOverlay(marker);
	            label.setStyle({
	                        borderColor:"#808080",
	                        color:"#333",
	                        cursor:"pointer"
	            });
				me.add({title: '新增', content: '新增备注', point: p.lng + '|' + p.lat});
				label.title = me.jsonArr.length - 1;
				me.labelEvent(me.jsonArr.length - 1, marker, label);
			   }};
		//	contextMenu.addItem(new BMap.MenuItem(txtMenuItem.text, txtMenuItem.callback, 100));
		//	map.addContextMenu(contextMenu);
        }
		window.map = map;//将map变量存储在全局
    },
    
    //地图事件设置函数：
    setMapEvent: function(){
        map.enableDragging();//启用地图拖拽事件，默认启用(可不写)
        map.enableScrollWheelZoom();//启用地图滚轮放大缩小
        map.enableDoubleClickZoom();//启用鼠标双击放大，默认启用(可不写)
        map.enableKeyboard();//启用键盘上下左右键移动地图
    },
    
    //地图控件添加函数：
    addMapControl: function(){
		//向地图中添加缩放控件
		if(this.isOpenNav == true){
			var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
			map.addControl(ctrl_nav);
		}
		//向地图中添加比例尺控件
		if(this.isOpenSca == true){
			var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
			map.addControl(ctrl_sca);
		}
		//向地图添加缩略图控件
		if(this.isOpenOve == true){
			var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
			map.addControl(ctrl_ove);
		}
	},
    

    //创建marker
    addMarker: function(){
    	var me = this;
    	if(this.jsonArr[this.jsonArr.length - 1] == null){
    		this.jsonArr.length = this.jsonArr.length - 1;
    	}
    	for(var i=0;i<this.jsonArr.length;i++){
    		var json = this.jsonArr[i];
    		var p0 = json.point.split("|")[0];
            var p1 = json.point.split("|")[1];
           	var point = new BMap.Point(p0,p1);
			var iconImg = this.createIcon(this.jsonIcon);
            var marker = new BMap.Marker(point,{icon:iconImg});
            var iw = this.createInfoWindow(i);
			var label = new BMap.Label(json.title,{"offset":new BMap.Size(this.jsonIcon.lb-this.jsonIcon.x+10,-20)});
			label.title = i;
			marker.setLabel(label);
			// 管理员才可以拖动位标
			if(this.isAdmin == true){
				marker.enableDragging(true); 
            }
            map.addOverlay(marker);
            label.setStyle({
                        borderColor:"#808080",
                        color:"#333",
                        cursor:"pointer"
            });
			me.labelEvent(i, marker, label);
        }
    },
    
    //创建InfoWindow
    createInfoWindow: function(i){
        var json = this.jsonArr[i];
        var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>"+json.content+"</div><div style='display:none'>"+i+"</div>");
        return iw;
    },
   
    //创建一个Icon
    createIcon: function(json){
        var icon = new BMap.Icon("http://openapi.baidu.com/map/images/us_mk_icon.png", new BMap.Size(json.w,json.h),{imageOffset: new BMap.Size(-json.l,-json.t),infoWindowOffset:new BMap.Size(json.lb+5,1),offset:new BMap.Size(json.x,json.h)})
        return icon;
    }
})    

/**
 * 
 * http://xuemai.cn/
 * Copyright(c) 2010-2020, 学脉网.
 * @author 聂庆童
 * @version 1.0
 */
Ext.ns('ssh');
// 定义方法，继承基类                                                               
ssh.Hint = Ext.extend(Ext.util.Observable,{
	// 样式
	cls:'hint-default',
	// 是否Ajax提交
	isAjax:false,
	// ajax请求地址
	url:'',
	data:[],
	items:[],
	width:200,
	height:25,
	textValue:'',
	iframe:null,
	currentIndex:-1, //当前选项索引
	/**
	* 构造方法
	*/
	constructor: function(config) {		
		// 合并config中的内容
		Ext.apply(this, config);
		this.initUI();
		this.initEvents();
	},
	
     /**
     * 初始化界面
     */
     initUI: function(){
		// 显示文本框
		this.text = Ext.get(this.bind);	
		// 显示选择内容的DIV
		this.text.parent().createChild({
			tag: 'br'
		});		
		this.list = this.text.parent().createChild({
			tag: 'div'
		});
		// 隐藏的保存域
		this.hide = this.text.parent().createChild({
			tag: 'input',
			type: 'hidden',
			name: this.name,
			id: this.name
		});
		
		
		if(Ext.isIE6)
		{
			this.iframe =  this.list.parent().createChild({tag: 'iframe', cls: 'ux-menu-ie-iframe'})
                    .setWidth(this.list.getWidth())
                    .setHeight(this.list.getHeight());
		}
		
		this.text.dom.autocomplete = "off";		
		this.text.addClass(this.cls + '-text');
		this.list.addClass(this.cls +  '-list');	
		
		this.text.setWidth(this.width);
		this.text.setHeight(this.height);
		this.text.setStyle('line-height', this.height + 'px');
		this.list.setWidth(this.width);		
	},
     
     /**
     * 初始化事件
     */
	initEvents: function(){
		var me = this;
		
        this.hideTask = new Ext.util.DelayedTask(function() {
			me.cancel();
        });		
		
		this.text.on('focus', function(e, t){
			 if(me.isAjax == false && Ext.isEmpty(this.dom.value))
			 {
			 	me.find('');
			 }
		});	        
        
		this.text.on('blur', function(e, t){
			me.currentIndex == -1;
			me.hideTask.delay(200);	
		});		
		
		this.text.on('keyup', function(e, t){		
			if(e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13)
			{
				me.find(this.dom.value);
			}
		});
		
		
		this.text.on('keydown', function(e, t){		
			if(e.keyCode == 13 && me.currentIndex != -1)
			{
				me.update(me.items[me.currentIndex].name, me.items[me.currentIndex].value);	
				me.currentIndex = -1;
				me.cancel();
			}			
			
			if((e.keyCode == 38 || e.keyCode == 40) && me.list.getStyle('display') == 'block')
			{
				var lastIndex = Number(me.list.last().getAttribute('index'));	
                if(e.keyCode == 40)
                {                
	                if(me.currentIndex == -1)
					{
						me.currentIndex = 0;				
					}else if(me.currentIndex < lastIndex)				
					{
						me.currentIndex += 1;			
					}else if(me.currentIndex == lastIndex)
					{
						me.currentIndex = 0;
					}
                }else
                {
	                if(me.currentIndex == -1)
					{
						me.currentIndex = lastIndex;				
					}else if(me.currentIndex > 0)				
					{
						me.currentIndex -= 1;			
					}else if(me.currentIndex == 0)
					{
						me.currentIndex = lastIndex;
					}                
                	
                }
                Ext.fly(me.list.dom.childNodes[me.currentIndex]).radioClass(me.cls + '-item-over');	
				me.update(me.items[me.currentIndex].name, me.items[me.currentIndex].value);
			}
		});		
		
		
	},
	
	cancel:function()
	{
		this.list.setStyle('display', 'none');
		if(this.iframe)
		{
			this.iframe.setStyle('display', 'none');
		}		 
	},
	
	find:function(textValue) {
		this.textValue = ''
		this.hide.dom.value = '';	
		this.currentIndex = -1;
		this.items = [];
		if(this.isAjax)
		{
			this.ajax(textValue);		
		}else
		{				
			var length = this.data.length; 
			for(var i=0; i< length; i++)
			{				
				if(!Ext.isEmpty(textValue))
				{
					if(this.data[i].name.indexOf(textValue) != -1)
					{
						this.items.push(this.data[i]);
						if(this.data[i].name == textValue)
						{			
							this.update(this.data[i].name, this.data[i].value);
						}
					}
				}
				else
				{
					this.items.push(this.data[i]);					
				}			
			}
			if(this.items.length > 0)
			{
				this.create();
			}else
			{
				this.cancel();			
			}
		}
	},
	// 更新内容
	update: function(name, value)
	{
		this.text.dom.value = name;
		this.textValue = name;
		this.hide.dom.value = value;
		if(this.callback)
		{
			this.callback({name:name, value:value});			
		}
	},
	create: function()
	{
		var me = this;
		this.list.select('p:nth-child(n)').remove();		
		var length = this.items.length;

		for(var i=0; i<length; i++)
		{ 
			var p = this.list.createChild({
				tag: 'p'
			});
			
			p.dom.setAttribute('index', i);
			p.dom.innerHTML = this.items[i].name;		

			p.on('click', function(e, t){	
				var index = Number(this.getAttribute('index'));
				me.update(me.items[index].name, me.items[index].value);
				me.cancel();					
			});		
			
			p.hover(function(e, t){	 
				var index = Number(this.getAttribute('index'));
				me.currentIndex = index;
	     		Ext.fly(t).radioClass(me.cls + '-item-over');
			}, function(e, t){
				Ext.fly(t).removeClass(me.cls + '-item-over');
			});				
			
		}
		this.list.setStyle('display', 'block');
		
		if(Ext.isIE6 && this.iframe)
		{			
			this.iframe.setHeight(Ext.getBody().getHeight());
			this.iframe.setStyle('z-index', 100);
			this.iframe.setStyle('display', 'block');
		}
		
	},
	getIndex: function(current){
		var index = 0;
		var item = current.prev();
		while(item)
		{
			item = item.prev();
			index ++;
		}
		return index;	
	},	
	/**
	* Ajax连接数据库	 
	*/ 
	ajax: function(textValue){
		var me = this;
		Ext.Ajax.request({
			url: me.url,
			params: {
				value: textValue
			},			
	   		success: function(response, opts) {
	     		me.items = Ext.util.JSON.decode(response.responseText); 
	     		if(me.items && me.items.length > 0)
	     		{
	     			me.create();
	     		}else
	     		{
	     		   me.list.setStyle('display', 'none');
	     		}
	     	},
	   		failure: function(response, opts) {
	      		console.log('服务端失效的状态代码： ' + response.status);
	   		}
		});
	}
});   

