///------------------------------------------
/// FileName:   USCSCommon.js
/// Summary:    Common Fuc Class
/// Method:     
///             
/// CreateDate: 2006/12/18
/// Author:     Turtles zhou
/// Version     1.0
///------------------------------------------


/// <funcName>Import</funcName>
/// <summary>Import script into page</summary>
/// <param>Path names, comma split</param>
function Import()
{
      var headobj = document.getElementsByTagName('head')[0];
      var scripts = document.getElementsByTagName("script");
      var sobj; 
      var srcs = Array();
      
      $A(scripts).each(function(v){ if(v.src)srcs.push(v.src.toLowerCase());});
      $A(arguments).each(function(v){ 
        if(srcs.indexOf(v.toLowerCase()) == -1){
            sobj = document.createElement('script');
            sobj.type = "text/javascript";
            sobj.src = v;
            headobj.appendChild(sobj);
            }
        });
}

/// <funcName>Object.extend</funcName>
/// <summary>copy properties from source to destination</summary>
/// <param name="d">destination</param>
/// <param name="s">source</param>
Object.extend = function(d, s) {
  for (var p in s) {
    d[p] = s[p];
  }
  return d;
}


var $break    = new Object();
var $continue = new Object();

/// <funcName>Array</funcName>
/// <summary>extend Array Object</summary>
Object.extend(Array.prototype,{ 
    each: function(iterator) {   
    var i = 0;   
    var len = this.length;
    try { 
      this._each(function(v) {   
        try {   
          iterator(v, i++, len);   
        } catch (e) {
          if (e != $continue) throw e;   
        }   
      });   
    } catch (e) {   
      if (e != $break) throw e;   
    }   
  },
  
  _each: function(iterator) {
    for (var i = 0; i < this.length; i++)
      iterator(this[i]);
  },
  
  max: function(iterator) {
    var r;
    this.each(function(v, i) {
      v = (iterator || function(v){return v;})(v, i);
      if (r == undefined || v >= r)
        r = v;
    });
    return r;
  },

  min: function(iterator) {
    var r;
    this.each(function(v, i) {
      v = (iterator || function(v){return v;})(v, i);
      if (r == undefined || v < r)
        r = v;
    });
    return r;
  },

  indexOf: function(o) {
    var index = -1;
    this.each(function(v,i){ if(v == o) index = i;});
    return index;
  },
  
  sortBy: function(sFunc,order) {
    var A = this,r = [],temp = [];
    this.each( function(v, i){ temp.push([sFunc(v,i),i]); });
    temp.sort();    
    if(order == "desc") temp.reverse();
    temp.each( function(v){ r.push(A[v[1]]);});
    return r;
  }
});

/// <funcName>String</funcName>
/// <summary>extend String Object</summary>
Object.extend( String.prototype, {
    len: function(){
        return this.replace(/[^\x00-\xff]/g,"aa").length;
    },
    
    format: function(){
        var s = r = this,re = /\{\d\}/g;
        var arr;
        while ((arr = re.exec(s)) != null)
        {
            i = parseInt(arr.toString().slice(1,2));
            r = r.replace(arr,arguments[i]);
        }
        return r;
    }
});

/// <funcName>$</funcName>
/// <summary>instead of document.getElementById()</summary>
/// <param></param>
function $() 
{
  var elements = new Array();   
  for (var i = 0; i < arguments.length; i++) 
  {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;
    
    if(element != null)
    elements.push(element);
  }

  return elements;
}

/// <funcName>$C</funcName>
/// <summary>instead of document.createElement()</summary>
/// <param name="element">element name</param>
function $C(el) 
{
    return document.createElement(el);
}

/// <funcName>$G</funcName>
/// <summary>Get value from HTML element</summary>
/// <param></param>
function $G()
{
    var sValue;
    var o = $(arguments[0]);
    if(!o){ alert("can't find the object!"); return;}
    switch(o.tagName.toLowerCase()) 
    {
        case "input":   if(o.type == "checkbox") sValue = o.checked;
                        sValue = o.value;
                        break;
        case "select":  sValue = (arguments.length>1)?o.options[o.selectedIndex].text:o.options[o.selectedIndex].value;
                        break;
        case "div":     sValue = o.innerHTML;
                        break;
        case "span":    sValue = o.innerHTML;
                        break;
        case "textarea":sValue = o.value;
                        break;
    }
    return sValue;
}

/// <funcName>$S</funcName>
/// <summary>Set value to HTML element</summary>
/// <param></param>
function $S()
{
    var o = $(arguments[0]);
    if(!o){ alert("can't find the object!"); return;}
    switch(o.tagName.toLowerCase()) 
    {
        case "input":   if(o.type == "checkbox") o.checked = arguments[1];
                        o.value = arguments[1];
                        break;
        case "select":  $A(o.options).each(function(v){
                            v.selected = ((v.text == arguments[1] && arguments[2] == "text")||( v.value == arguments[1] && arguments[1] == "value"))? true:false;   });
                        break;
        case "div":     o.innerHTML = arguments[1];
                        break;
        case "span":    o.innerHTML = arguments[1];
                        break;
        case "textarea":o.value = arguments[1];
                        break;
    }
}

/// <funcName>$A</funcName>
/// <summary>convert collection to Array</summary>
/// <param></param>
function $A()
{
  iterable = arguments[0];
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0, length = iterable.length; i < length; i++)
      results.push(iterable[i]);
    return results;
  }
}

Uscs =
{
    Common:
    {
        /// <funcName>Init</funcName>
        /// <summary>Initialize</summary>
        /// <param></param>
        Init: function(){
            this.Browser.GBrowser();
            this.Flash.GVer();
            this.CrossBrowser();
        },
        
        /// <funcName>Browser</funcName>
        /// <summary>check client broswer</summary>
        /// <param></param>
        Browser:
        { 
            Name:"",
            Version:"",
            /// <funcName>GBrowser</funcName>
            /// <summary>browser type</summary>
            /// <param></param>
            GBrowser:function(){
                var browsers = ["Opera","Firefox","Safari","Netscape6/","Netscape","Gecko","MSIE","Mozilla"];
                var me = this;
                browsers.each(function(v){
                    var ver = me.GVer(v);
                    var n = v.replace(/[^a-z0-9]/gi,"")     
                    if(ver != null && n != null)
                    {
                        me.Name = n;
                        me.Version = ver;
                        throw $break;
                    }
                });
            },
            
            /// <funcName>GVer</funcName>
            /// <summary>browser version</summary>
            /// <param name="name"></param>
            GVer:function(name){
                var ua = navigator.userAgent;
                var i = ua.indexOf(name);
                return i!=-1?parseFloat(ua.substr(i + name.length).replace(/^[^0-9.]+/,"")):null;
            }   
        },
        
        /// <funcName>SetCookie</funcName>
        /// <summary> Save Cookies </summary>
        /// <param name="expires">a Date Object</param>
        /// <param name="path">
        /// a folder path. e.g. we had create a cookie in http://www.zdnet.com/devhead/index.html, then the pages under http://www.zdnet.com/devhead/ all can access the cookie, but if the page under http://www.zdnet.com/zdnn/ wants to access the cookie we need to set the path = "/",  and if http://www.zdnet.com/devhead/filters/ and http://www.zdnet.com/devhead/stories/ want to share cookies, path = "/devhead".
        /// </param>
        /// <param name="domain"> 
        /// if http://catalog.mycompany.com and http://shoppingcart.mycompany.com want to share the cookies, domain = "mycompany.com".
        /// </param>
        /// <param name="Secure">
        /// value = "secure"/"", if set to "secure", when passing data from web server and client side will be encoded by using https or other security protocal.
        /// </param>
        SetCookie:function(name, value){
            var argv = arguments;
            var argc = arguments.length;
            var expires = (argc > 2) ? argv[2] : null;
            var path = (argc > 3) ? argv[3] : null;
            var domain = (argc > 4) ? argv[4] : null;
            var secure = (argc > 5) ? argv[5] : false;
            document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
        },
        
        /// <funcName>GetCookie</funcName>
        /// <summary>get Cookie by name</summary>
        /// <param name="name">the cookie name</param>
        GetCookie:function(name){
            var prefix = name + "=";
            var cookieStartIndex = document.cookie.indexOf(prefix);
            if (cookieStartIndex == -1)
                return null;
            var cookieEndIndex = document.cookie.indexOf(";", eval(cookieStartIndex + prefix.length));
            if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length;
            return unescape(document.cookie.substring(eval(cookieStartIndex + prefix.length),  cookieEndIndex));
        },
        
        /// <funcName>ClearCookie</funcName>
        /// <summary>clear Cookie by name</summary>
        /// <param name="name">the cookie name</param>
        ClearCookie:function(name){
            var expires = new Date('1901/1/1');
            this.SetCookie (name, null, expires);
        },
        
        /// <funcName>Load</funcName>
        /// <summary>load xml to create XMLDOM object</summary>
        /// <param name="url">a xml file url</param>
        Load:function(url){
            var oXml = null;
            // code for IE  
            if (window.ActiveXObject)
                oXml = new ActiveXObject("Microsoft.XMLDOM");
            // code for Mozilla, etc.
            else if (document.implementation && document.implementation.createDocument)
                oXml= document.implementation.createDocument("text/xml","",null)
            if(oXml)
            {
                oXml.async=false;
                oXml.load(url);
            }
            return oXml;
        },
        
        /// <funcName>LoadXML</funcName>
        /// <summary>load xml to create XMLDOM object</summary>
        /// <param name="xml">a xml document string</param>
        LoadXML:function(xml)
        {   
            var oXml = null;
            // code for IE  
            if (window.ActiveXObject)
                oXml = new ActiveXObject("Microsoft.XMLDOM");
            // code for Mozilla, etc.
            else if (document.implementation && document.implementation.createDocument)
                oXml= document.implementation.createDocument("text/xml","",null);
            if(oXml)
            {
                oXml.async=false;
                oXml.loadXML(xml);
            }
            return oXml;
        },
        
        /// <funcName>GNodes</funcName>
        /// <summary>Get a NodeList</summary>
        /// <param name="oXml">XmlDom object</param>
        /// <param name="path">XPath</param>
        GNodes: function(oXml,path){
            var oNodes = null;
            if(oXml) oNodes = oXml.selectNodes(path);
            return oNodes;
        },
        
        /// <funcName>GNode</funcName>
        /// <summary>Get a Node</summary>
        /// <param name="oXml">XmlDom object</param>
        /// <param name="path">XPath</param>
        GNode: function(oXml,path){
            var oNode = null;
            if(oXml) oNode = oXml.selectSingleNode(path);
            return oNode;
        },
        
        /// <funcName>GNodeValue</funcName>
        /// <summary>Get a Node's text value</summary>
        /// <param name="oXml">XmlDom object</param>
        /// <param name="path">XPath</param>
        GNodeValue: function(oXml,path){
            var oNode = null;
            var sValue = "";
            if(oXml)
            {
                oNode = oXml.selectSingleNode(path);    
                if(oNode) sValue = oNode.text;
            }
            return sValue;
        },
        
        /// <funcName>SNodeValue</funcName>
        /// <summary>Set a NodeList's text value</summary>
        /// <param name="oXml">XmlDom object</param>
        /// <param name="path">XPath</param>
        SNodeValue: function(oXml,path,value){
            var oNode = null;
            if(oXml)
            {
                oNode = oXml.selectSingleNode(path);
                if(oNode) oNode.text = value;
            }
        },
        
        /// <funcName>GNodeAttr</funcName>
        /// <summary>Get a Node's attribute value</summary>
        /// <param name="node">node object</param>
        /// <param name="attr">attribute name</param>
        GNodeAttr: function(node,attr){
            var sAttr = "";
            if(node) sAttr = node.getAttribute(attr);
            return sAttr;
        },
        
        /// <funcName>SNodeAttr</funcName>
        /// <summary>Set a Node's attribute value</summary>
        /// <param name="node">node object</param>
        /// <param name="attr">attribute name</param>
        SNodeAttr: function(node,attr,value){
            if(node) node.setAttribute(attr,value);
        },
        
        /// <funcName>Toggle</funcName>
        /// <summary> show or hide an object </summary>
        /// <param name="obj">the obj</param>
        Toggle: function(obj){
            obj.style.display = (obj.style.display == 'none')? 'block':'none';
        },
        
        /// <funcName>ToggleCss</funcName>
        /// <summary> switch an object's css class </summary>
        /// <param name="obj">the obj</param>
        /// <param name="css1">css className1</param>
        /// <param name="css2">css className2</param>
        ToggleCss: function(obj, css1, css2){
            obj.className = (obj.className == css1)? css2:css1;
        },
        
        /// <funcName>Show</funcName>
        /// <summary> show an object </summary>
        /// <param name="obj">the obj</param>
        Show: function(obj){
            obj.style.display ='block';
        },
        
        /// <funcName>Hide</funcName>
        /// <summary> Hide an object </summary>
        /// <param name="obj">the obj</param>
        Hide: function(obj){
            obj.style.display ='none';
        },
        
        /// <funcName>QS</funcName>
        /// <summary>Retrieve parameters collection </summary>
        QS: function(){
            var oParams = new Object();
            var sUrl = window.location.href;
            if(sUrl.indexOf("?")>-1)
            {
                var oParameters = sUrl.slice(sUrl.indexOf("?")+1).split("&");
                var oParamArray = $A(oParameters);
                if(oParamArray != "")
                {
                    var iterator = function(item,i,len){
                        eval("oParams.{0}='{1}'".format(item.split("=")[0],item.split("=")[1]));
                        eval("oParams.{0}='{1}'".format(item.split("=")[0].toLowerCase(),item.split("=")[1]));
                    };
                    oParamArray.each(iterator);
                }
            }
            return oParams;                 
        },
        
        /// <funcName>AddToFavorite</funcName>
        /// <summary>Add To Favorites</summary>
        /// <param></param>
        AddToFavorite: function()
        {
            title = document.title;
            url = window.location.href;
            // Mozilla Firefox Bookmark
            if (window.sidebar)
                window.sidebar.addPanel(title, url, "");
    
            // Windows IE Favorite
            else if(navigator.platform.indexOf('Mac')<0 && window.external && Opt.Browser.Name != "Netscape")
                window.external.AddFavorite(url, title);
    
            // other browsers
            else
                alert("Mac user: please use Command+D for Bookmarking this page\n\nPC user: pleasse use Ctrl+D for Bookmarking this page\n");
        },
        
        /// <funcName>SendToFriend</funcName>
        /// <summary>create a mail</summary>
        /// <param name="subject"></param>
        /// <param name="cnt">body</param>
        SendToFriend: function(subject,cnt)
        {
            if(window.location.href.indexOf("ocid=email")>-1)   {
                cnt += location.href;}
            else if (window.location.href.indexOf(".aspx?")>-1) {
                cnt += location.href + "&ocid=email";}
            else{ cnt += location.href + "?ocid=email";}
            location.href = "mailto:?email=&subject="+escape(subject)+"&body="+escape(cnt);
        },
        
        /// <funcName>Test</funcName>
        /// <summary>test if the string matches the specific RegExp, return true/false </summary>
        /// <param name="str">the string for test</param>
        /// <param name="reg">RegExp:can be some special cases or nomal RegExp</param>  
        Test: function (str, reg)
        {
            var myReg = "";
            switch(reg.toLowerCase())
            {
                case "number":  myReg = /^[-]{0,1}\d+$/; break;
                case "email":   myReg = /^\w+@([-\w]+\.)+[-\w]{2,3}$/; break;
                case "url":     myReg = /^(http|https):\/\/([\w-]+\.)*(\w+)$/; break;
                case "chinese": myReg = /^[\u4e00-\u9fa5]*$/; break;
                case "ip":      myReg = /^\d+\.\d+\.\d+\.\d+$/; break;
                case "date":    myReg = /^((((19|20)(([02468][048])|([13579][26]))[-\/]02[-\/]29))|((20[0-9][0-9])|(19[0-9][0-9]))[-\/]((((0[1-9])|(1[0-2]))[-\/]((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))[-\/]31)|(((01,3-9])|(1[0-2]))[-\/](29|30)))))$/;break;
                default: myReg = eval(reg);
            }
            try
            {
                if(myReg.test(str)) return true;
                return false;
            }
            catch(e){ 
                alert("Test Error:"+ e);
            }
        },
        
        /// <funcName>Replace</funcName>
        /// <summary>replace string which matches the specific RegExp, return replaced string </summary>
        /// <param name="str">the string for replace</param>
        /// <param name="reg">RegExp:can be some special cases or nomal RegExp</param>
        /// <param name="repstr">replace string</param>
        Replace: function(str, reg, repstr)
        {
            var myReg = "";
            switch(reg.toLowerCase())
            {
                case "htmltag": myReg = /<(.*)>(.*)<\/\1>|<(.*)\/>/gi; repstr = "$2"; break;
                case "blank":   myReg = /[\s\n\r]/g; break;
                case "trim":    myReg = /^\s*|\s*$/g;break;
                default: myReg = eval(reg);
            }
            
            try
            {
                str = str.replace(myReg,repstr);
                return str;
            }
            catch(e){ 
                alert("Replace Error:"+ e);
            }
        },
    
        /// <funcName>Flash</funcName>
        /// <summary>Flash operation</summary>
        /// <param></param>
        Flash:
        {
            Version:"",
            /// <funcName>Build</funcName>
            /// <summary>create a flash object</summary>
            /// <param name="src">swf source</param>
            /// <param name="w">swf width</param>
            /// <param name="h">swf height</param>
            /// <param name="params">other params: e.g.{bgColor: "#FFFFFF", menu: false}</param>
            /// <param name="flashvars">flash variables</param>
            Build:function(id, src, w, h, params, flashvars) 
            {
                var str = "";
                var fv="";
                if(flashvars != null) 
                {   
                    for(var i in flashvars) {fv+=i+"="+flashvars[i]+"&";}
                }
                str += "<embed id=\"{0}\" AllowScriptAccess=\"always\" src=\"{1}\" flashVars=\"{2}\" width=\"{3}\" height=\"{4}\"".format(id,src,fv,w,h);
                for(var i in params) { str += " " + i + "=\"" + params[i] + "\""; }
                str += "></embed>";
                return str;
            },
            
            /// <funcName>GVer</funcName>
            /// <summary>return browser flash version</summary>
            /// <param name=""></param>
            GVer: function(){
                var p = window.navigator.plugins;
                if (p && p.length)
                {
                    var FlashObject = p["Shockwave Flash"] || p["Shockwave Flash 2.0"];
                    if ( FlashObject && (f = FlashObject.description)) this.Version = parseInt(f.substring(f.indexOf(".") - 2));
                }
                else if (window.ActiveXObject)
                {
                    for (i=15; i>2; --i)
                    {
                        try
                        {
                            var FlashObject = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i);
                            this.Version = i;
                            break;
                        } catch (e) {}
                    }
                }
            }
        },
    
        /// <funcName>CrossBrowser</funcName>
        /// <summary>Add xml property,LoadXML,selectNodes,selectSingleNode method to XMLDocument in NON-IE Broswers.</summary>
        /// <param></param>
        CrossBrowser: function(){       
            if(this.Browser.Name == "Firefox" || this.Browser.Name == "Netscape" && XMLDocument)
            {
                XMLDocument.prototype.loadXML = function(xmlString)
                {
                    var childNodes = this.childNodes;
                    for (var i = childNodes.length - 1; i >= 0; i--)
                        this.removeChild(childNodes[i]);
            
                    var dp = new DOMParser();
                    var newDOM = dp.parseFromString(xmlString, "text/xml");
                    var newElt = this.importNode(newDOM.documentElement, true);
                    this.appendChild(newElt);
                };
                Node.prototype.__defineGetter__("text", function(){return this.textContent;});
                Node.prototype.__defineSetter__("text", function(d){this.textContent = d;});
                Node.prototype.__defineGetter__("xml",function(){
                var oSerializer = new XMLSerializer();
                return oSerializer.serializeToString(this,"text/xml");
                })
            
                // check for XPath implementation
                if( document.implementation.hasFeature("XPath", "3.0") )
                {
                   // prototying the XMLDocument
                   XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
                   {
                      if( !xNode ) { xNode = this; } 
                      var oNSResolver = this.createNSResolver(this.documentElement)
                      var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
                                   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
                      var aResult = [];
                      for( var i = 0; i < aItems.snapshotLength; i++)
                      {
                         aResult[i] =  aItems.snapshotItem(i);
                      }
                      return aResult;
                   }
            
                   // prototying the Element
                   Element.prototype.selectNodes = function(cXPathString)
                   {
                      if(this.ownerDocument.selectNodes)
                      {
                         return this.ownerDocument.selectNodes(cXPathString, this);
                      }
                      else{throw "For XML Elements Only";}
                   }
                }
            
                // check for XPath implementation
                if( document.implementation.hasFeature("XPath", "3.0") )
                {
                   // prototying the XMLDocument
                   XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
                   {
                      if( !xNode ) { xNode = this; } 
                      var xItems = this.selectNodes(cXPathString, xNode);
                      if( xItems.length > 0 )
                      {
                         return xItems[0];
                      }
                      else
                      {
                         return null;
                      }
                   }
                   
                   // prototying the Element
                   Element.prototype.selectSingleNode = function(cXPathString)
                   {    
                      if(this.ownerDocument.selectSingleNode)
                      {
                         return this.ownerDocument.selectSingleNode(cXPathString, this);
                      }
                      else{throw "For XML Elements Only";}
                   }
                }
                
                
                HTMLElement.prototype.__defineGetter__("outerHTML",function()
                {
                    var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
                    if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
                    if(!this.canHaveChildren) return str+" />";
                    return str+">"+this.innerHTML+"</"+this.tagName+">";
                });
                
                HTMLElement.prototype.__defineSetter__("outerHTML",function(s)
                {
                    var r = this.ownerDocument.createRange();
                    r.setStartBefore(this);
                    var df = r.createContextualFragment(s);
                    this.parentNode.replaceChild(df, this);
                    return s;
                });
                
                HTMLElement.prototype.__defineGetter__("canHaveChildren",function()
                {
                    return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
                });
                
                HTMLElement.prototype.__defineGetter__("className",function()
                {
                    return this.getAttribute("class");
                });
                
                HTMLElement.prototype.__defineSetter__("className",function(s)
                {
                    this.setAttribute("class",s);
                });
                
                HTMLElement.prototype.__defineGetter__("parentElement",function()
                {
                     n=this.parentNode;
                     while (n && n.nodeType!=1) n=n.parentNode;
                     return n;
                });
                    
                HTMLElement.prototype.__defineGetter__("innerText",function()
                {
                    try 
                    {return this.textContent;} 
                    catch(ex) 
                    {
                        var str = "";
                        for (var i=0;i<this.childNodes.length;i++)
                        {
                            if (this.childNodes[i].nodeType==3)
                                str += this.childNodes[i].textContent;
                        }
                        return str;
                    }
                });
                
                HTMLElement.prototype.__defineSetter__("innerText",function(s)
                {
                    var n = document.createTextNode(s);
                    this.innerHTML = "";
                    this.appendChild(n);
                });
                  
                HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
                switch(where){
                    case "beforeBegin":
                        this.parentNode.insertBefore(parsedNode,this);
                        break;
                    case "afterBegin":
                        this.insertBefore(parsedNode,this.firstChild);
                        break;
                    case "beforeEnd":
                        this.appendChild(parsedNode);
                        break;
                    case "afterEnd":
                        if(this.nextSibling)
                            this.parentNode.insertBefore(parsedNode,this.nextSibling);
                        else
                            this.parentNode.appendChild(parsedNode);
                        break;
                    }
                }
                HTMLElement.prototype.insertAdjacentHTML=function(where,htmlStr){
                    var r=this.ownerDocument.createRange();
                    r.setStartBefore(this);
                    var parsedHTML=r.createContextualFragment(htmlStr);
                    this.insertAdjacentElement(where,parsedHTML);
                }
                HTMLElement.prototype.insertAdjacentText=function(where,txtStr){
                    var parsedText=document.createTextNode(txtStr);
                    this.insertAdjacentElement(where,parsedText);
                }
                
                HTMLElement.prototype.__defineGetter__("currentStyle",function(){
                 return this.ownerDocument.defaultView.getComputedStyle(this,null);
                });
                
                Window.prototype.attachEvent = HTMLDocument.prototype.attachEvent=
                HTMLElement.prototype.attachEvent=function(en, func, cancelBubble)
                {
                    var cb = cancelBubble ? true : false;
                    this.addEventListener(en.toLowerCase().substr(2), func, cb);
                };
                
                Window.prototype.detachEvent = HTMLDocument.prototype.detachEvent=
                HTMLElement.prototype.detachEvent=function(en, func, cancelBubble)
                {
                    var cb = cancelBubble ? true : false;
                    this.removeEventListener(en.toLowerCase().substr(2), func, cb);
                };
                
                 var t=Event.prototype;
                  t.__defineSetter__("returnValue", function(b){if(!b)this.preventDefault();  return b;});
                  t.__defineSetter__("cancelBubble",function(b){if(b) this.stopPropagation(); return b;});
                  t.__defineGetter__("offsetX", function(){return this.layerX;});
                  t.__defineGetter__("offsetY", function(){return this.layerY;});
                  t.__defineGetter__("x", function(){return this.pageX;});
                  t.__defineGetter__("y", function(){return this.pageY;});
                  t.__defineGetter__("srcElement", function(){var n=this.target; while (n.nodeType!=1)n=n.parentNode;return n;}); 
                  t.__defineGetter__("fromElement",function(){ 
                                        var node; 
                                        if(this.type=="mouseover") node=this.relatedTarget;
                                        else if(this.type=="mouseout") node=this.target;
                                        if(!node)return;
                                        while(node.nodeType!=1)node=node.parentNode;
                                        return node;});
                  t.__defineGetter__("toElement",function(){
                                        var node; 
                                        if(this.type=="mouseout") node=this.relatedTarget;
                                        else if(this.type=="mouseover") node=this.target;
                                        if(!node)return;
                                        while(node.nodeType!=1)node=node.parentNode;
                                        return node;});
                  
                
                  
            }
            
            if(this.Browser.Name == "Opera")
            {
                Document.prototype.loadXML = function(xmlString)
                {
                    var childNodes = this.childNodes;
                    for (var i = childNodes.length - 1; i >= 0; i--)
                        this.removeChild(childNodes[i]);
            
                    var dp = new DOMParser();
                    var newDOM = dp.parseFromString(xmlString, "text/xml");
                    var newElt = this.importNode(newDOM.documentElement, true);
                    this.appendChild(newElt);
                };
                
                        
                Node.prototype.xml = function(){
                var oSerializer = new XMLSerializer();
                return oSerializer.serializeToString(this,"text/xml");
                };
                
            
                if( document.implementation.hasFeature("XPath", "3.0") )
                {
                   // prototying the XMLDocument
                   Document.prototype.selectNodes = function(cXPathString, xNode)
                   {
                      if( !xNode ) { xNode = this; } 
                      var oNSResolver = this.createNSResolver(this.documentElement)
                      var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
                                   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
                      var aResult = [];
                      for( var i = 0; i < aItems.snapshotLength; i++)
                      {
                         aResult[i] =  aItems.snapshotItem(i);
                      }
                      return aResult;
                   }
            
                   // prototying the Element
                   Element.prototype.selectNodes = function(cXPathString)
                   {
                      if(this.ownerDocument.selectNodes)
                      {
                         return this.ownerDocument.selectNodes(cXPathString, this);
                      }
                      else{throw "For XML Elements Only";}
                   }
                }
            
                // check for XPath implementation
                if( document.implementation.hasFeature("XPath", "3.0") )
                {
                   // prototying the XMLDocument
                   Document.prototype.selectSingleNode = function(cXPathString, xNode)
                   {
                      if( !xNode ) { xNode = this; } 
                      var xItems = this.selectNodes(cXPathString, xNode);
                      if( xItems.length > 0 )
                      {
                         return xItems[0];
                      }
                      else
                      {
                         return null;
                      }
                   }
                   
                   // prototying the Element
                   Element.prototype.selectSingleNode = function(cXPathString)
                   {    
                      if(this.ownerDocument.selectSingleNode)
                      {
                         return this.ownerDocument.selectSingleNode(cXPathString, this);
                      }
                      else{throw "For XML Elements Only";}
                   }
                }
            }
        },
        
        /// <funcName>Ajax</funcName>
        /// <summary>Ajax operation</summary>
        /// <param></param>
        Ajax:
        {       
            /// <funcName>Init</funcName>
            /// <summary>Init xmlHttp object</summary>
            Init: function(){
                var xmlHttp = null;
                try 
                {
                    xmlHttp = new XMLHttpRequest();
                } 
                catch(trymicrosoft)
                {
                    try 
                    {           
                        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (othermicrosoft) 
                    {
                        try 
                        {
                            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (failed) 
                        {
                            xmlHttp = false;
                        }
                    }
                }
                return xmlHttp;
            },
            
            /// <funcName>AjaxSend</funcName>
            /// <summary>Ajax send request</summary>
            /// <param name="method">Post,Get</param>
            /// <param name="url">send url</param>  
            /// <param name="callbackfuc">callback function(string)</param> 
            /// <param name="params">if it is POST, send(params)</param>
            /// <param name="contenttype">if it is POST,content-type "text/html"/"text/xml"</param>
            /// <param name="user">optional user account</param>
            /// <param name="psw">optional user psw</param> 
            Send: function(method, url, callbackfuc, params, contenttype){
                var me = this;
                var oXmlHttp = me.Init();
                if(oXmlHttp)
                {   
                    try
                    {
                        var aLen = arguments.length;        
                        user = (aLen>5)?arguments[5]:null;
                        psw = (aLen>5)?arguments[6]:null;
                        
                        url = encodeURI(url);
                        if(method.toUpperCase() == "GET")
                        {
                            oXmlHttp.open("GET", url, true, user, psw);
                            oXmlHttp.onreadystatechange = function(){ me.CallBack(callbackfuc,oXmlHttp);}
                            oXmlHttp.send(null); 
                        }
                        else
                        {
                            oXmlHttp.open("POST", url, true, user, psw);
                            oXmlHttp.onreadystatechange = function(){ me.CallBack(callbackfuc,oXmlHttp);} 
                            oXmlHttp.setRequestHeader('Content-Type', contenttype);
                            oXmlHttp.send(params);  
                        }
                    }
                    catch(e)
                    {
                        alert(e);
                    }
                }
                else
                {
                    alert("Can't create xmlhttp object!");
                }
            },
    
            /// <funcName>CallBack</funcName>
            /// <summary>receive the server data and invoke the callback function</summary>
            /// <param name="callbackfuc">the callback function name(string)</param>
            /// <param name="oXmlHttp">xmlHttp object</param>
            CallBack:function(callbackfuc,oXmlHttp)
            {
                if (oXmlHttp.readyState==4)
                {
                    if (oXmlHttp.status == 200) 
                    {
                        eval(callbackfuc + "('"+escape(oXmlHttp.responseText)+"')");
                    }
                    else if(oXmlHttp.status == 404) 
                    {
                        alert("Requested file not found");
                    }
                    else 
                    {
                        alert("Error has occurred with status code: "+oXmlHttp.status);
                    }
                
                }
            }
        },
        
        /// <funcName>FilterPNG</funcName>
        /// <summary>Make PNG transparent in IE6</summary>
        /// <param></param>
        FilterPNG: function (){
            if((Opt.Browser.Name == "MSIE" && parseInt(Opt.Browser.Version) < 7)||(Opt.Browser.Name == "Netscape" && navigator.userAgent.toLowerCase().indexOf("msie")>-1))
            {
                arguments[0].each(function(v){
                img = $(v);
                imgID = (img.id)?"id='{0}'".format(img.id):"";
                imgClass = (img.className)?"class='{0}'".format(img.className):"";
                imgTitle = (img.title)?"title='{0}'".format(img.title):"title='{0}'".format(img.alt);
                imgStyle = "display:inline-block;{0}".format(img.style.cssText);
                if (img.align == "left") imgStyle = "float:left;{0}".format(imgStyle);
                if (img.align == "right") imgStyle = "float:right;{0}".format(imgStyle);
                if (img.parentElement.href) imgStyle = "cursor:hand;{0}".format(imgStyle);
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
                img.outerHTML = strNewHTML;
                });
            }
        },
        
        /// <funcName>GroupSAttr</funcName>
        /// <summary>save attributes to one element</summary>
        /// <param></param>
        GroupSAttr: function(obj,a){
            try{
            a.each(function(v){
                            if(v[1])
                            {
                                if([ "onclick",
                                     "ondblclick",
                                     "onmouseover",
                                     "onmouseout",
                                     "onmousemove",
                                     "onmousedown",
                                     "onmouseup",
                                     "onkeydown",
                                     "onkeypress",
                                     "onkeyup"].indexOf(v[0])>-1){
                                            obj.attachEvent(v[0],v[1]);
                                    }
                                    else if(typeof eval("obj.{0}".format(v[0])) != "undefined")
                                    {
                                        eval("obj.{0} = '{1}'".format(v[0],v[1]));
                                    }
                                    else
                                    {
                                        obj.setAttribute(v[0],v[1]);
                                    }
                            }
                });
            }
            catch(e){
                alert(e);
            }
        },
        
        /// <funcName>GroupSValue</funcName>
        /// <summary>save values</summary>
        /// <param></param>
        GroupSValue: function(a){
            a.each(function(v){
                v[0] = v[1];
            });
        }
    }
}

var Opt = Uscs.Common;
Opt.Init();