/*=========================================20081218 添加：SunRise_Dom.js====================================*/
(function(){
	
	var getStyle,          
        setStyle,           
        propertyCache = {}, 
        reClassNameCache = {},        
        document = window.document; 

    // brower detection
    var isOpera = SunRise.ua.opera,
        isSafari = SunRise.ua.webkit, 
        isGecko = SunRise.ua.gecko,
        isIE = SunRise.ua.ie; 
    
    // regex cache
    var patterns = {
        HYPHEN: /(-[a-z])/i, // to normalize get/setStyle
        ROOT_TAG: /^body|html$/i, // body for quirks mode, html for standards,
        OP_SCROLL:/^(?:inline|table-row)$/i
    };

    var toCamel = function(property) {
        if ( !patterns.HYPHEN.test(property) ) {
            return property; // no hyphens
        }
        
        if (propertyCache[property]) { // already converted
            return propertyCache[property];
        }
       
        var converted = property;
 
        while( patterns.HYPHEN.exec(converted) ) {
            converted = converted.replace(RegExp.$1,
                    RegExp.$1.substr(1).toUpperCase());
        }
        
        propertyCache[property] = converted;
        return converted;
        //return propertSunRise.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug
    };
    
    var getClassRegEx = function(className) {
        var re = reClassNameCache[className];
        if (!re) {
            re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
            reClassNameCache[className] = re;
        }
        return re;
    };

    // branching at load instead of runtime
    if (document.defaultView && document.defaultView.getComputedStyle) { // W3C DOM method
        getStyle = function(el, property) {
            var value = null;
            
            if (property == 'float') { // fix reserved word
                property = 'cssFloat';
            }

            var computed = el.ownerDocument.defaultView.getComputedStyle(el, '');
            if (computed) { // test computed before touching for safari
                value = computed[toCamel(property)];
            }
            
            return el.style[property] || value;
        };
    } else if (document.documentElement.currentStyle && isIE) { // IE method
        getStyle = function(el, property) {                         
            switch( toCamel(property) ) {
                case 'opacity' :// IE opacity uses filter
                    var val = 100;
                    try { // will error if no DXImageTransform
                        val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;

                    } catch(e) {
                        try { // make sure its in the document
                            val = el.filters('alpha').opacity;
                        } catch(e) {
                        }
                    }
                    return val / 100;
                case 'float': // fix reserved word
                    property = 'styleFloat'; // fall through
                default: 
                    // test currentStyle before touching
                    var value = el.currentStyle ? el.currentStyle[property] : null;
                    return ( el.style[property] || value );
            }
        };
    } else { // default to inline only
        getStyle = function(el, property) { return el.style[property]; };
    }
    
    if (isIE) {
        setStyle = function(el, property, val) {
            switch (property) {
                case 'opacity':
                    if ( SunRise.lang.isString(el.style.filter) ) { // in case not appended
                        el.style.filter = 'alpha(opacity=' + val * 100 + ')';
                        
                        if (!el.currentStyle || !el.currentStyle.hasLayout) {
                            el.style.zoom = 1; // when no layout or cant tell
                        }
                    }
                    break;
                case 'float':
                    property = 'styleFloat';
                default:
                el.style[property] = val;
            }
        };
    } else {
        setStyle = function(el, property, val) {
            if (property == 'float') {
                property = 'cssFloat';
            }
            el.style[property] = val;
        };
    }
	
	SunRise.Dom = SunRise.Dom||{
	 get: function(el) {
            if (el && (el.nodeType || el.item)) { // Node, or NodeList
                return el;
            }

            if (SunRise.lang.isString(el) || !el) { // id or null
                return document.getElementById(el);
            }
            
            if (el.length !== undefined) { // array-like 
                var c = [];
                for (var i = 0, len = el.length; i < len; ++i) {
                    c[c.length] = SunRise.Dom.get(el[i]);
                }
                
                return c;
            }

            return el; // some other object, just pass it back
        },    
        getStyle: function(el, property) {
            property = toCamel(property);
            
            var f = function(element) {
                return getStyle(element, property);
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },    
       
        setStyle: function(el, property, val) {
            property = toCamel(property);
            
            var f = function(element) {
                setStyle(element, property, val);
                
            };
            
            SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },
               
        getXY: function(el) {
            var f = function(el) {
                // has to be part of document to have pageXY
                if ( (el.parentNode === null || el.offsetParent === null ||
                        this.getStyle(el, 'display') == 'none') && el != el.ownerDocument.body) {
                    return false;
                }
                
                return getXY(el);
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },        
       
        getX: function(el) {
            var f = function(el) {
                return SunRise.Dom.getXY(el)[0];
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },               
        getY: function(el) {
            var f = function(el) {
                return SunRise.Dom.getXY(el)[1];
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },        
       
        setXY: function(el, pos, noRetry) {
            var f = function(el) {
                var style_pos = this.getStyle(el, 'position');
                if (style_pos == 'static') { // default to relative
                    this.setStyle(el, 'position', 'relative');
                    style_pos = 'relative';
                }

                var pageXY = this.getXY(el);
                if (pageXY === false) { // has to be part of doc to have pageXY
                    return false; 
                }
                
                var delta = [ // assuming pixels; if not we will have to retry
                    parseInt( this.getStyle(el, 'left'), 10 ),
                    parseInt( this.getStyle(el, 'top'), 10 )
                ];
            
                if ( isNaN(delta[0]) ) {// in case of 'auto'
                    delta[0] = (style_pos == 'relative') ? 0 : el.offsetLeft;
                } 
                if ( isNaN(delta[1]) ) { // in case of 'auto'
                    delta[1] = (style_pos == 'relative') ? 0 : el.offsetTop;
                } 
        
                if (pos[0] !== null) { el.style.left = pos[0] - pageXY[0] + delta[0] + 'px'; }
                if (pos[1] !== null) { el.style.top = pos[1] - pageXY[1] + delta[1] + 'px'; }
              
                if (!noRetry) {
                    var newXY = this.getXY(el);

                    // if retry is true, try one more time if we miss 
                   if ( (pos[0] !== null && newXY[0] != pos[0]) || 
                        (pos[1] !== null && newXY[1] != pos[1]) ) {
                       this.setXY(el, pos, true);
                   }
                }        
        
            };
            
            SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },        
      
        setX: function(el, x) {
            SunRise.Dom.setXY(el, [x, null]);
        },        
        
        setY: function(el, y) {
            SunRise.Dom.setXY(el, [null, y]);
        }, 
        getClientWidth: function() {
            return SunRise.Dom.getViewportWidth();
        },
        getClientHeight: function() {
            return SunRise.Dom.getViewportHeight();
        },
        getElementsByClassName: function(className, tag, root, apply) {
            tag = tag || '*';
            root = (root) ? SunRise.Dom.get(root) : null || document; 
            if (!root) {
                return [];
            }

            var nodes = [],
                elements = root.getElementsByTagName(tag),
                re = getClassRegEx(className);

            for (var i = 0, len = elements.length; i < len; ++i) {
                if ( re.test(elements[i].className) ) {
                    nodes[nodes.length] = elements[i];
                    if (apply) {
                        apply.call(elements[i], elements[i]);
                    }
                }
            }
            
            return nodes;
        },
        hasClass: function(el, className) {
            var re = getClassRegEx(className);

            var f = function(el) {
                return re.test(el.className);
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },
        addClass: function(el, className) {
            var f = function(el) {
                if (this.hasClass(el, className)) {
                    return false; // already present
                }
                
                
                el.className = SunRise.lang.trim([el.className, className].join(' '));
                return true;
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },
        removeClass: function(el, className) {
            var re = getClassRegEx(className);
            
            var f = function(el) {
                if (!className || !this.hasClass(el, className)) {
                    return false; // not present
                }   
                var c = el.className;
                el.className = c.replace(re, ' ');
                if ( this.hasClass(el, className) ) { // in case of multiple adjacent
                    this.removeClass(el, className);
                }

                el.className = SunRise.lang.trim(el.className); // remove any trailing spaces
                return true;
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        }, 
        replaceClass: function(el, oldClassName, newClassName) {
            if (!newClassName || oldClassName === newClassName) { // avoid infinite loop
                return false;
            }
            
            var re = getClassRegEx(oldClassName);
			
            var f = function(el) {
            
                if ( !this.hasClass(el, oldClassName) ) {
                    this.addClass(el, newClassName); // just add it if nothing to replace
                    return true; // NOTE: return
                }
            
                el.className = el.className.replace(re, ' ' + newClassName + ' ');

                if ( this.hasClass(el, oldClassName) ) { // in case of multiple adjacent
                    this.replaceClass(el, oldClassName, newClassName);
                }

                el.className = SunRise.lang.trim(el.className); // remove any trailing spaces
                return true;
            };
            
            return SunRise.Dom.batch(el, f, SunRise.Dom, true);
        },        
       
        batch: function(el, method, o, override) {
            el = (el && (el.tagName || el.item)) ? el : SunRise.Dom.get(el); // skip get() when possible

            if (!el || !method) {
                return false;
            } 
            var scope = (override) ? o : window;
            
            if (el.tagName || el.length === undefined) { // element or not array-like 
                return method.call(scope, el, o);
            } 

            var collection = [];
            
            for (var i = 0, len = el.length; i < len; ++i) {
                collection[collection.length] = method.call(scope, el[i], o);
            }
            
            return collection;
        },
        getDocumentHeight: function() {
            var scrollHeight = (document.compatMode != 'CSS1Compat') ? document.body.scrollHeight : document.documentElement.scrollHeight;

            var h = Math.max(scrollHeight, SunRise.Dom.getViewportHeight());
            return h;
        },   
        getDocumentWidth: function() {
            var scrollWidth = (document.compatMode != 'CSS1Compat') ? document.body.scrollWidth : document.documentElement.scrollWidth;
            var w = Math.max(scrollWidth, SunRise.Dom.getViewportWidth());
            return w;
        },        
        getViewportHeight: function() {
            var height = self.innerHeight; // Safari, Opera
            var mode = document.compatMode;        
            if ( (mode || isIE) && !isOpera ) { // IE, Gecko
                height = (mode == 'CSS1Compat') ?
                        document.documentElement.clientHeight : // Standards
                        document.body.clientHeight; // Quirks
            }
        
            return height;
        },   
        getViewportWidth: function() {
            var width = self.innerWidth;  // Safari
            var mode = document.compatMode;
            
            if (mode || isIE) { // IE, Gecko, Opera
                width = (mode == 'CSS1Compat') ?
                        document.documentElement.clientWidth : // Standards
                        document.body.clientWidth; // Quirks
            }
            return width;
        }
    };
    
    var getXY = function() {
        if (document.documentElement.getBoundingClientRect) { // IE
            return function(el) {
                var box = el.getBoundingClientRect();

                var rootNode = el.ownerDocument;
                return [box.left + SunRise.Dom.getDocumentScrollLeft(rootNode), box.top +
                        SunRise.Dom.getDocumentScrollTop(rootNode)];
            };
        } else {
            return function(el) { // manually calculate by crawling up offsetParents
                var pos = [el.offsetLeft, el.offsetTop];
                var parentNode = el.offsetParent;

                // safari: subtract body offsets if el is abs (or any offsetParent), unless body is offsetParent
                var accountForBody = (isSafari &&
                        SunRise.Dom.getStyle(el, 'position') == 'absolute' &&
                        el.offsetParent == el.ownerDocument.body);

                if (parentNode != el) {
                    while (parentNode) {
                        pos[0] += parentNode.offsetLeft;
                        pos[1] += parentNode.offsetTop;
                        if (!accountForBody && isSafari && 
                                SunRise.Dom.getStyle(parentNode,'position') == 'absolute' ) { 
                            accountForBody = true;
                        }
                        parentNode = parentNode.offsetParent;
                    }
                }

                if (accountForBody) { //safari doubles in this case
                    pos[0] -= el.ownerDocument.body.offsetLeft;
                    pos[1] -= el.ownerDocument.body.offsetTop;
                } 
                parentNode = el.parentNode;

                // account for any scrolled ancestors
                while ( parentNode.tagName && !patterns.ROOT_TAG.test(parentNode.tagName) ) 
                {
                    if (parentNode.scrollTop || parentNode.scrollLeft) {
                        // work around opera inline/table scrollLeft/Top bug (false reports offset as scroll)
                        if (!patterns.OP_SCROLL.test(SunRise.Dom.getStyle(parentNode, 'display'))) { 
                            if (!isOpera || SunRise.Dom.getStyle(parentNode, 'overflow') !== 'visible') { // opera inline-block misreports when visible
                                pos[0] -= parentNode.scrollLeft;
                                pos[1] -= parentNode.scrollTop;
                            }
                        }
                    }
                    
                    parentNode = parentNode.parentNode; 
                }

                return pos;
            };
		
		}
	}	
})();
/*=========================================20081218 添加：SunRise_AJAX.js====================================*/
(function(){
	
	SunRise.Ajax = function(config){
		this.URL = config.URL;
		this.method = config.method || "GET" ;
		this.header = config.header || "GET" ;
		this.beforeRequest = config.beforeRequest || null ; 
		this.isAsynchronism = config.isAsynchronism || true;
	}
	
	
	SunRise.Ajax.prototype = {	
		
		send : function(callback){
			var xmlhttp = createAjaxRequestObject();
			var data = (callback && callback.postData)?callback.postData:null;
			var url = this.URL;
			xmlhttp.onreadystatechange = function(){callback.success(xmlhttp)};
			xmlhttp.open(this.method,url,this.isAsynchronism);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); 
			//xmlhttp.send(encodeURIComponent(data));
			xmlhttp.send(data);
		}
	}
	
	 function createAjaxRequestObject(){
		var o;
		if(SunRise.ua.ie == 0){
			o = new XMLHttpRequest();
		}else{
			o = new ActiveXObject("Microsoft.XMLHTTP");
		}
		return o;
	}
	
})();
/*=========================================20081218 添加：SunRise_Validate.js====================================*/
(function(){
	SunRise.Validate = function(){
		
	}
	
	SunRise.Validate.prototype = {
		//判断是否是数字
		isNumber : function(n){
			var r = /[^0-9]/;
			return !r.test(n);
		},
		//判断是否是移动手机号码
		isMobile : function(m){
			var pattern = /^1(34|35|36|37|38|39|47|50|51|52|57|58|59|87|83|88|82)[0-9]{8}$/;
			var result = pattern.exec(m);
			if(result==null){
				return false;
			}
			return true;
		},
		//判断是否是联通手机号码
		isChinaUnicom : function(m){
			var pattern = /^1(30|31|32|33)[0-9]{8}$/;
			var result = pattern.exec(m);
			if(result != null){
				return true;
			}else{
				return false;
			}
		},
		//判断是字母或者文字
		isLetterAndNumber : function(n){
			var r = /[^a-zA-Z0-9]/;
			return !r.test(n);
		},
		//判断是否已字母开始
		isStartLetter : function(n){
			var r = /^[a-zA-Z]/;
			return r.test(n);
		},
		//验证邮箱地址
		isEmail : function(n){
			var r = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
			return r.test(n);
		},
        //验证电话号码
        isPhone:function(n){
		    var r = /^(\(\d+\))*(\d)+(-(\d)+)*$/;
		    return r.test(n);
        },
        //验证资金数目
		  isFund:function(n){
			  var r=new RegExp(/^[\-\+]?([0-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)(\.\d+)?$/); 
			  return r.test(n); 
		 },
		  //验证身份证号
 		  isIdentityCard:function(n){
			 var r=new RegExp(/^([\d]{15}|[\d]{18}|[\d]{17}[x|X])$/); 
			 return r.test(n); 
		  }, 
		  //验证邮编
		 isPostcode:function(n){
				var r=new RegExp(/^(\d){6}$/); 
				return r.test(n); 
		 },
		 //字符长度判断	
	     isLength:function(s,n){
	        var len = s.length;
	        return len!=n;
	     },
	     //弱密码判断
	     isWeak:function(s){
	        var rpassward = "000000&111111&222222&333333&444444&555555&666666&777777&888888&999999"
		        +"&012345&123456&234567&345678&456789&567890&543210&654321&765432&876543&987654&098765"
		        +"&00000000&11111111&22222222&33333333&44444444&55555555&66666666&77777777&88888888&99999999"
		        +"&01234567&12345678&23456789&34567890&76543210&87654321&98765432&09876543"; 
	        return rpassward.indexOf(s)!=-1;
	     }
	     


	}
}
)();

