function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function sort_desc(a, b){
    return b - a;
}

function sort_asc(a, b){
    return a - b;
}

var _isIE = (document.all)?true:false;

function $(o) { try{ return document.getElementById(o); } catch(e) { alert("$"); } return null; }
function hide(o) { try{ o.style.display="none"; } catch(e) { alert("hide"); } return; }
function show(o) { try{ o.style.display="block"; } catch(e) { alert("show"); } return; }
function inline(o) { try{ o.style.display="inline"; } catch(e) { alert("inline"); } return; }
function toggle(o) { try{ if(o.style.display=="none") show(o); else hide(o); } catch(e) { alert("toggle"); } return; }
function $c(t) { try { return document.createElement(t); } catch(e) { alert("$c");} return null; }
function $s(o,s,v) { try { o.setAttribute(s, v); } catch(e) { alert("$s"); } return; }
function $a(o1, o2) { try { o1.appendChild(o2); } catch(e) { alert("$a"); } return; }
function $t(s) { try { return document.createTextNode(s); } catch(e) { alert("$t"); } return null; }
function $g(o,s) { try{ return o.getAttribute(s); } catch(e) { throw(e); } return ""; }
function $e(o,e,f) { try{ if(o.addEventListener) o.addEventListener(e,f,false); else if(o.attachEvent) o.attachEvent("on"+e,f); else eval("o.on"+e+"=f;"); }catch(ex) { alert("$e"); } return; }
function $d(o,e,f) { try{ if(o.removeEventListener) o.removeEventListener(e,f,false); else if(o.detachEvent) o.detachEvent("on"+e,f); else eval("o.on"+e+"=null;"); }catch(ex) { alert("$d"); } return; }
function $o(o,v) { try { o.style.opacity = v/100; o.style.filter = 'alpha(opacity=' + v + ')'; } catch(e) { alert("$o"); } return;}
function $target(e) { try{ var targ; if(e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement; if (targ.nodeType == 3) targ = targ.parentNode; return targ; } catch(e) {} return null; }
function trim(s) { return s.replace(/^\s+|\s+$/g,""); }


// start Ajax operation
function ajax_load(url,method,data,callback) {
    var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    if(method.toUpperCase() == "GET") {
        http_request.open("GET", url, true);
        http_request.send(null);
    } else if(method.toUpperCase() == "POST") {
        http_request.open("POST", url, true);
        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=gb2312");
        http_request.setRequestHeader("Content-length", url.length);
        http_request.send(data);
    }
    http_request.onreadystatechange = 
        function() {
            if (http_request.readyState == 4) 
                if (http_request.status == 200) 
                    callback(http_request.responseText); 
                else
                    alert("some error occurs ... code = " + http_request.status);
        }

    return false;
}

function zretcode(s) {
    var ret = {"code":"","msg":"","rem":[]};
try {

    if(s.indexOf("|") > 0) {
        var sa = s.split("|");
        ret.code = parseInt(sa.shift());
        if(sa.length > 0)
            ret.msg = sa.shift();
        if(sa.length > 0)
            ret.rem = sa;
    } else
        ret.code = parseInt( s );

} catch(e) {
    return s;
}

    return ret;
}

// end Ajax operation

// seccode
function load_seccode(seccode_id, secimg_id, callback) {
    ajax_load("gensec.php?"+(new Date()).getTime(),"get","", function(res) {
            $(seccode_id).value = res;
            $(secimg_id).src = "seccode.php?code="+res;
            if(callback!=null) callback();
        });
    return;
}

// cookie library for javascript from http://www.netspade.com/2005/11/16/javascript-cookies/
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    if(getCookie(name))
        deleteCookie(name, path, domain);
    
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
