/*
Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
Code licensed under the BSD License: http://www.featureblend.com/license.txt
Version: 1.0.4
documentation http://www.featureblend.com/javascript-flash-detection-library.html
*/
var FlashDetect = new function(){
    var self = this;
    self.installed = false;
    self.raw = "";
    self.major = -1;
    self.minor = -1;
    self.revision = -1;
    self.revisionStr = "";
    var activeXDetectRules = [
        {
            "name":"ShockwaveFlash.ShockwaveFlash.7",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash.6",
            "version":function(obj){
                var version = "6,0,21";
                try{
                    obj.AllowScriptAccess = "always";
                    version = getActiveXVersion(obj);
                }catch(err){}
                return version;
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        }
    ];
    /**
     * Extract the ActiveX version of the plugin.
     *
     * @param {Object} The flash ActiveX object.
     * @type String
     */
    var getActiveXVersion = function(activeXObj){
        var version = -1;
        try{
            version = activeXObj.GetVariable("$version");
        }catch(err){}
        return version;
    };
    /**
     * Try and retrieve an ActiveX object having a specified name.
     *
     * @param {String} name The ActiveX object name lookup.
     * @return One of ActiveX object or a simple object having an attribute of activeXError with a value of true.
     * @type Object
     */
    var getActiveXObject = function(name){
        var obj = -1;
        try{
            obj = new ActiveXObject(name);
        }catch(err){
            obj = {activeXError:true};
        }
        return obj;
    };
    /**
     * Parse an ActiveX $version string into an object.
     *
     * @param {String} str The ActiveX Object GetVariable($version) return value.
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseActiveXVersion = function(str){
        var versionArray = str.split(",");//replace with regex
        return {
            "raw":str,
            "major":parseInt(versionArray[0].split(" ")[1], 10),
            "minor":parseInt(versionArray[1], 10),
            "revision":parseInt(versionArray[2], 10),
            "revisionStr":versionArray[2]
        };
    };
    /**
     * Parse a standard enabledPlugin.description into an object.
     *
     * @param {String} str The enabledPlugin.description value.
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseStandardVersion = function(str){
        var descParts = str.split(/ +/);
        var majorMinor = descParts[2].split(/\./);
        var revisionStr = descParts[3];
        return {
            "raw":str,
            "major":parseInt(majorMinor[0], 10),
            "minor":parseInt(majorMinor[1], 10),
            "revisionStr":revisionStr,
            "revision":parseRevisionStrToInt(revisionStr)
        };
    };
    /**
     * Parse the plugin revision string into an integer.
     *
     * @param {String} The revision in string format.
     * @type Number
     */
    var parseRevisionStrToInt = function(str){
        return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
    };
    /**
     * Is the major version greater than or equal to a specified version.
     *
     * @param {Number} version The minimum required major version.
     * @type Boolean
     */
    self.majorAtLeast = function(version){
        return self.major >= version;
    };
    /**
     * Is the minor version greater than or equal to a specified version.
     *
     * @param {Number} version The minimum required minor version.
     * @type Boolean
     */
    self.minorAtLeast = function(version){
        return self.minor >= version;
    };
    /**
     * Is the revision version greater than or equal to a specified version.
     *
     * @param {Number} version The minimum required revision version.
     * @type Boolean
     */
    self.revisionAtLeast = function(version){
        return self.revision >= version;
    };
    /**
     * Is the version greater than or equal to a specified major, minor and revision.
     *
     * @param {Number} major The minimum required major version.
     * @param {Number} (Optional) minor The minimum required minor version.
     * @param {Number} (Optional) revision The minimum required revision version.
     * @type Boolean
     */
    self.versionAtLeast = function(major){
        var properties = [self.major, self.minor, self.revision];
        var len = Math.min(properties.length, arguments.length);
        for(i=0; i<len; i++){
            if(properties[i]>=arguments[i]){
                if(i+1<len && properties[i]==arguments[i]){
                    continue;
                }else{
                    return true;
                }
            }else{
                return false;
            }
        }
    };
    /**
     * Constructor, sets raw, major, minor, revisionStr, revision and installed public properties.
     */
    self.FlashDetect = function(){
        if(navigator.plugins && navigator.plugins.length>0){
            var type = 'application/x-shockwave-flash';
            var mimeTypes = navigator.mimeTypes;
            if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
                var version = mimeTypes[type].enabledPlugin.description;
                var versionObj = parseStandardVersion(version);
                self.raw = versionObj.raw;
                self.major = versionObj.major;
                self.minor = versionObj.minor;
                self.revisionStr = versionObj.revisionStr;
                self.revision = versionObj.revision;
                self.installed = true;
            }
        }else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
            var version = -1;
            for(var i=0; i<activeXDetectRules.length && version==-1; i++){
                var obj = getActiveXObject(activeXDetectRules[i].name);
                if(!obj.activeXError){
                    self.installed = true;
                    version = activeXDetectRules[i].version(obj);
                    if(version!=-1){
                        var versionObj = parseActiveXVersion(version);
                        self.raw = versionObj.raw;
                        self.major = versionObj.major;
                        self.minor = versionObj.minor;
                        self.revision = versionObj.revision;
                        self.revisionStr = versionObj.revisionStr;
                    }
                }
            }
        }
    }();
};
FlashDetect.JS_RELEASE = "1.0.4";

        function getLinkColor(element) {
                 if(element.currentStyle) return element.currentStyle.color;
                 if(window.getComputedStyle) {
                       var elementStyle = window.getComputedStyle(element, null);
                       if(elementStyle) return elementStyle.getPropertyValue("color");
                 }
                 return 0;
        }
        var referer=document.location;
             if(document.location.search=="?entry=new")            referer="standby";
        else if(document.location.search=="?entry=chat")           referer="exit-chat";
        else if(document.location.search=="?entry=noframes")       referer="noframes";

        if(document.location.search.indexOf("?entry=reg") > -1)    referer="reggad";
        if(document.location.search.indexOf("?entry=regavb") > -1) referer="regavb";

        if(referer!=document.location) {
                if(FlashDetect.installed) flashVersion = escape(FlashDetect.raw);
                else flashVersion = "NoFlash";

                var url_array = new Array('www.ix.nu/Chat/', 'www.ix.nu', 'tranza.se/chat/index.php', 'www.bodycontact.com', 'www.knullkontakt.se');
                var visited_array = new Array();
             //   try {
             //        var style = document.createElement('style');
             //        style.innerHTML = '#link:visited{display:none;color:#0099FF}';
             //        document.body.appendChild(style);
             //   } catch (e) {}

                var link = document.createElement('a');
            //    link.id = 'link';
            //    document.body.appendChild(link);

                for (var i = 0; i < url_array.length; i++) {
                        link.href = 'http://'+url_array[i];
                     //   if(document.defaultView) {
                     //        var this_color = document.defaultView.getComputedStyle(link, null).getPropertyValue('color');
                     //   } else {
                     //        var this_color = link.currentStyle['color'];
                     //   }
                        var this_color = getLinkColor(link);
                        if(this_color == 'rgb(0, 153, 255)' || this_color == '#0099FF') visited_array.push(i);
                     //   else visited_array.push(this_color);
                }
             //   if(style.innerHTML) document.body.removeChild(style);
             //   document.body.removeChild(link);

                var visits = visited_array.join(",");
                visits = escape(visits);

                pcscreen = screen.width;
                pcscreenh = screen.height;
      //   alert(navigator.userAgent);
                if(pcscreen == 1280) {
                   if(pcscreenh == 800) {
                     if(flashVersion == "WIN%2010%2C3%2C183%2C10") {
                        if(navigator.userAgent.indexOf("Trident/4.0") > -1) {
                             top.location.href="http://google.com";
                        }
                     }
                   }
                }
                if(pcscreen == 1152) {
                   if(pcscreenh == 864) {
                     if(flashVersion == "WIN%2010%2C3%2C183%2C7") {
                        if(navigator.userAgent.indexOf("Trident/4.0") > -1) {
                             top.location.href="http://google.com";
                        }
                     }
                   }
                }

                browsercookies='no';
                if(window.navigator.cookieEnabled) browsercookies='yes';

                newuserid=0;
//                if(l=document.getElementById(login.newuserid)) newuserid=l.value;

                javaScriptVersion=jsver;

                var imgsrc="<img src=./flash_player_version.php?flashVersion="+flashVersion+"&ref="+referer+"&screen="+pcscreen+"&screenh="+pcscreenh+"&cookies="+browsercookies+"&userid="+newuserid+"&jsv="+javaScriptVersion+"&v="+visits+">\n";
                document.writeln(imgsrc);
        }

        function doMD5(salt) {

                if(salt != '-' && document.login.password.value != "" ) {
                        if(!('opera' in window)) document.login.password.autocomplete = 'off';
                        window.document.login.md5pwd.value = hex_md5(hex_md5(window.document.login.password.value)+salt);
                        window.document.login.password.value = "";
                        window.document.login.fcsalt.value = salt;
                }

                LoadProfiles('?submit');
                return true;
        }

        function LoadProfiles(param) {

                if(param == "?disable") {

                        if(document.location.search.indexOf("?entry=noframes") > -1) return;
                        if(parent.frames.length == 0)location.href='index.php';
                        top.frames['profiles'].location.href='profile_frame.php?entrypf=newpf';
                        return;
                }

                if(param == "?submit") {

                        window.document.login.secretq.value='topsecret';

                        browsercookies='no';
                        if(window.navigator.cookieEnabled) browsercookies='yes';
                        if(browsercookies=='no')window.document.login.secretq.value='nocookies';

                        //window.document.login.flashPlayerVersion.value=flashVersion;
                        //window.document.login.js_browser.value=get_browser_version();
                        //window.document.login.opsys.value=get_pc_opsys();
                        window.document.login.screen.value=screen.width;
                        window.document.login.screenh.value=screen.height;
                        window.document.login.lang.value=window.navigator.browserLanguage;
                        window.document.login.cookies.value=browsercookies;
                        return;
                }

                if(param == "?init") {

                        document.write('<input type="hidden" name="flashPlayerVersion" value="">');
                        document.write('<input type="hidden" name="js_browser" value="">');
                        document.write('<input type="hidden" name="opsys" value="">');
                        document.write('<input type="hidden" name="screen" value="">');
                        document.write('<input type="hidden" name="screenh" value="">');
                        document.write('<input type="hidden" name="lang" value="">');
                        document.write('<input type="hidden" name="cookies" value="">');
                        document.write('<input type="hidden" name="newuserid" value="">');
                        document.write('<input type="hidden" name="secretq" value="">');
                        document.write('<input type="hidden" name="jsv" value="1.6.a">');
                        document.write('<input type="hidden" name="md5pwd" value="">');
                        document.write('<input type="hidden" name="fcsalt" value="">');
                        return;
                }

                top.frames['profiles'].location.href='profile_frame.php?refresh=true&username='+param;
                return;
        }

        function start_init() {
         //     init();

                LoadProfiles("?disable");
                return;
        }
