function getCookie( name ) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}
 
function setCookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+'='+escape( value ) +
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
        ( ( path ) ? ';path=' + path : '' ) +
        ( ( domain ) ? ';domain=' + domain : '' ) +
        ( ( secure ) ? ';secure' : '' );
}
 
function deleteCookie( name, path, domain ) {
    if ( getCookie( name ) ) document.cookie = name + '=' +
            ( ( path ) ? ';path=' + path : '') +
            ( ( domain ) ? ';domain=' + domain : '' ) +
            ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}





function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
} 







function isValidEmail (email, strict)
{
 if ( !strict ) email = email.replace(/^\s+|\s+$/g, '');
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}





function trim(s)
{
  return rtrim(ltrim(s));
}

function ltrim(s)
{
  return s.replace(/^\s+/, ''); 
}

function rtrim(s)
{
  return s.replace(/\s+$/, ''); 
}





var URL;

(function() {
var isIE = window.navigator.userAgent.indexOf('MSIE') != -1;

URL = function(url) {
    var data = {href: '', protocol: '', host: '', hostname: '', port: '', pathname: '', search: '', hash: ''};
    
    var gs = {
        getHref: function() {
            return data.href;
        },
        setHref: function(val) {
            data.href = val;
            parseURL.call(this);
            return data.href;
        },
        
        getProtocol: function() {
            return data.protocol;
        },
        setProtocol: function(val) {
            if (!val)
                val = data.protocol || window.location.protocol; // update || init
            data.protocol = val;
            updateURL.call(this);
            return data.protocol;
        },

        getHost: function() {
            return data.host;
        },
        setHost: function(val) {
            val = val || '';
            var v = val.split(':');
            var h = v[0], p = v[1] || '';
            data.host = val;
            data.hostname = h;
            data.port = p;
            updateURL.call(this);
            return data.host;
        },
        
        getHostname: function() {
            return data.hostname;
        },
        setHostname: function(val) {
            if (!val)
                val = data.hostname || window.location.hostname; // update || init
            data.hostname = val;
            data.host = val + (("" + data.port) ? ":" + data.port : "");
            updateURL.call(this);
            return data.hostname;
        },
        
        getPort: function() {
            return data.port;
        },
        setPort: function(val) {
            data.port = val;
            data.host = data.hostname + (("" + data.port) ? ":" + data.port : "");
            updateURL.call(this);
            return data.port;
        },
        
        getPathname: function() {
            return data.pathname;
        },
        setPathname: function(val) {
            if (val.indexOf("/") != 0) { // relative url
                var _p = (data.pathname || window.location.pathname).split("/");
                _p[_p.length - 1] = val;
                val = _p.join("/");
            }
            data.pathname = val;
            updateURL.call(this);
            return data.pathname;
        },
        
        getSearch: function() {
            return data.search;
        },
        setSearch: function(val) {
            return data.search = val;
        },
        
        getHash: function() {
            return data.hash;
        },
        setHash: function(val) {
            return data.hash = val;
        }
    };

    if (isIE) { // IE5.5+
        var el=document.createElement('div');
        el.style.display='none';
        document.body.appendChild(el);
        el.assign = URL.prototype.assign;
        el.replace = URL.prototype.replace;
        var keys = ["href", "protocol", "host", "hostname", "port", "pathname", "search", "hash"];
        el.onpropertychange=function(){
            var pn = event.propertyName;
            var pv = event.srcElement[event.propertyName];
            if (this._holdOnMSIE || pn == '_holdOnMSIE')
                return pv;
            this._holdOnMSIE = true;
            for (var i = 0, l = keys.length; i < l; i++)
                el[keys[i]] = data[keys[i]];
            this._holdOnMSIE = false;
            for (var i = 0, l = keys.length; i < l; i++) {
                var key = keys[i];
                if (pn == key) {
                    var sKey = 'set' + key.substr(0, 1).toUpperCase() + key.substr(1);
                    return gs[sKey].call(el, pv);
                }
            }
        }
        url = url || "";
        parseURL.call(el, url);
        return el;
    } else if (URL.prototype.__defineSetter__) { // FF
        var keys = ["href", "protocol", "host", "hostname", "port", "pathname", "search", "hash"];
        for (var i = 0, l = keys.length; i < l; i++) {
            (function(i) {
                var key = keys[i];
                var gKey = 'get' + key.substr(0, 1).toUpperCase() + key.substr(1);
                var sKey = 'set' + key.substr(0, 1).toUpperCase() + key.substr(1);
                URL.prototype.__defineGetter__(key, gs[gKey]);
                URL.prototype.__defineSetter__(key, gs[sKey]);
            })(i);
        }
        url = url || "";
        parseURL.call(this, url);
    }
}

URL.prototype = {
    assign: function(url) {
        parseURL.call(this, url);
        window.location.assign(this.href);
    },
    
    replace: function(url) {
        parseURL.call(this, url);
        window.location.replace(this.href);
    }
}

function parseURL(url) {
    if (this._innerUse)
        return;
    
    url = url || this.href;
    var pattern = "^(([^:/\\?#]+):)?(//(([^:/\\?#]*)(?::([^/\\?#]*))?))?([^\\?#]*)(\\?([^#]*))?(#(.*))?$";
    var rx = new RegExp(pattern);
    var parts = rx.exec(url);
    
    // Prevent infinite recursion
    this._innerUse = true;
    
    this.href = parts[0] || "";
    this.protocol = parts[1] || "";
    //this.host = parts[4] || "";
    this.hostname = parts[5] || "";
    this.port = parts[6] || "";
    this.pathname = parts[7] || "/";
    this.search = parts[8] || "";
    this.hash = parts[10] || "";
    
    if (!isIE)
        delete this._innerUse;
    else
        this._innerUse = false;

    updateURL.call(this);
}

function updateURL() {
    if (this._innerUse)
        return;

    // Prevent infinite recursion
    this._innerUse = true;
    
    this.href = this.protocol + '//' + this.host + this.pathname + this.search + this.hash;
    
    if (!isIE)
        delete this._innerUse;
    else
        this._innerUse = false;
}

})()






function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getClientCenterX()
{
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY()
{
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}





function getClientBottomY()
{
	return getClientHeight()+getBodyScrollTop();
}