function ___ww_msieversion() {
    var ua= window.navigator.userAgent;
    if (ua.toLowerCase().indexOf("opera")>=0) return 0;
    var msie = ua.indexOf("MSIE ");
    if (msie>0)
        return parseInt(ua.substring(msie+5,ua.indexOf(".",msie)));
    else
        return 0;
}
function ___ww_netscapeversion() {
    if (___ww_msieversion()!=0) return 0;
    var p;
    if (window.navigator.appName.toLowerCase()!="netscape") {
        var ua= window.navigator.userAgent.toLowerCase();
        p = ua.indexOf("opera");
        if (p>=0)
            if (ua.indexOf("opera/6")==p || ua.indexOf("opera/7")==p
                || ua.indexOf("opera/8")==p || ua.indexOf("opera/9")==p || ua.indexOf("opera/10")==p)
                // need to be accurate: "Opera/6" if Identify as Opera, but "Opera 6" in other cases
                return 5; // try to work with Opera 6+ as with Mozilla (for this file only, not for wwserv.js
            else
                return 0;
    }
    var version = window.navigator.appVersion;
    if (version==null || version.length<2) return 0;
    p = version.indexOf(".");
    if (p<=0) return 0;
    return parseInt(version.substring(0,p));
}

if (window.___ww!=null && window.___ww_assignCookie!=null) { //called from WW
    ___ww_assignCookie("ww___wwpanelsenabled=no;path=/;expires="
        +(new Date((new Date()).getTime()+1*60*60*1000)).toUTCString());
} else if (window.ww___notOptimize==null || !window.ww___notOptimize) {
    var url= document.location.href;
    var host= document.location.host+"";
    var path= document.location.pathname+"";
    var ref= document.referrer+"";
    var p= ref.indexOf("?");
    if (p!=-1) {
      ref= ref.substring(0,p);
    }
    var msiev= ___ww_msieversion();
    var netscapev= ___ww_netscapeversion();
    var wwsite= "http://webwarper.net/";
    var wwarg= "~av/";
    if (url.indexOf("http://webwarper.net/")!=0      // if 0, it means webwarper.net site: disable autooptimizing
        && url.indexOf("http://algart.net/")!=0      // if 0, it means algart.net site: disable autooptimizing (incompatible with shortest names: "ru/" is WW-script)
        && url.indexOf("http://www.algart.net/")!=0  // if 0, it means algart.net site: disable autooptimizing (incompatible with shortest names: "ru/" is WW-script)
        && url.indexOf("http://algart.org/")!=0      // if 0, it means algart.org site: disable autooptimizing (incompatible with shortest names: "ru/" is WW-script)
        && url.indexOf("http://www.algart.org/")!=0  // if 0, it means algart.org site: disable autooptimizing (incompatible with shortest names: "ru/" is WW-script)
        && (msiev>=4 || netscapev>=5)
        && url.indexOf("http://")==0
        && document.location.host.indexOf(".")!=-1 // not a simple one-word host name
        && (document.cookie+"").toLowerCase().indexOf("ww___optimizationdisabled=yes")==-1
    ) {
        if (document.location.search.indexOf("?noww")!=-1 ||
            document.location.search.indexOf("&noww")!=-1 || // "noww..." argument blocks webwarpering
            ref == wwsite+"ww/0"+path ||                     // coming from this webwarp'ed page, special case of algart.net and similar
            ref == wwsite+"ww/"+host+path ||                 // coming from this webwarp'ed page, usual case
            ref == wwsite+"ru/0"+path ||                     // coming from this webwarp'ed page, special case of algart.net and similar
            ref == wwsite+"ru/"+host+path                    // coming from this webwarp'ed page, usual case
        ) {                                                  // saving no-webwarped mode for future
            document.cookie= "ww___optimizationdisabled=yes;path=/;expires="
               +(new Date((new Date()).getTime()+7*24*60*60*1000)).toUTCString(); // 7 days
        } else {
            var wwscript= "ww";
            if (window.ww___lang=="ru") wwscript= "ru";
            if (url.indexOf(wwsite)==0) { // avoiding extra redirection
                url= "0/"+url.substring(wwsite.length);
            } else {
                url= url.substring("http://".length);
            }
            if (msiev>=4 || (msiev==0 && document.location.replace != null))
                // MSIE 5.X doesn't allow checking "document.location.replace != null"
                document.location.replace(wwsite+wwscript+"/"+wwarg+url);
            else
                document.location= wwsite+wwscript+"/"+wwarg+url;
        }
    }
}
