﻿/*
    This source performs flash detection and install or upgrade
    BUT, it need ths following other files in oder to worj correctly
    
    
    <script src="browserDetect.js" type="text/javascript"></script>
    <script src="FlashVerDetection.js" type="text/javascript"></script>
    <script src="flashDetect.js" type="text/javascript" ></script>
    <script language="javascript" type="text/javascript" src="swfobject.js"></script>  
*/

var FlashDetect = { 
    init : function () {
        this.InstallFlashPage = 'installFlash.aspx';
        this.UpgradeFlashPage = '';
        this.NotSupportedPage= 'notSupported.aspx';
        
        this.FlashDetectionControl = '/CommonContent/FlashDetection/playerProductInstall.swf';
    },   
    IsSupportedBrowser : function () { 
        if( BrowserDetect.OS =='Mac' ) {
            if( BrowserDetect.browser == 'Explorer' )
                return false;
            if( BrowserDetect.browser == 'Firefox' && BrowserDetect.version >= 1 ) {
                return true;
            }                
            if( BrowserDetect.browser == 'Mozilla' && BrowserDetect.version >= 1 ) {
                return true;
            }                
            if( BrowserDetect.browser == 'Netscape' && BrowserDetect.version >= 7 ) {
                return true;
            }                
            if( BrowserDetect.browser == 'Opera' && BrowserDetect.version >= 6 ) {
                return true;
            }                
            if( BrowserDetect.browser == 'Safari' && BrowserDetect.version  >= 1 ) {
                return true;
            }                       
            return false;
        } else if( BrowserDetect.OS == 'Windows' ) {
            if( BrowserDetect.browser == 'Explorer' && BrowserDetect.version >= 6 ) {
                return true;
            }                        
            if( BrowserDetect.browser == 'Firefox' && BrowserDetect.version >= 1 ) {
                return true;
            }                
            if( BrowserDetect.browser == 'Mozilla' && BrowserDetect.version >= 1 ) {
                return true;
            }                
            if( BrowserDetect.browser == 'Netscape' && BrowserDetect.version >= 7 ) {
                return true;
            }                
            if( BrowserDetect.browser == 'Opera' && BrowserDetect.version >= 6 ) {
                return true;
            }               
            return false;
        }
        return false;    
    },    
    IsFlashCurrent : function() {
        var hasFlash6 = DetectFlashVer(6, 0, 65);
        var hasFlash7 = DetectFlashVer(7, 0, 0);
        if( hasFlash7 ) {
            return 2;       // Flash is OK
        } else {            
            if( hasFlash6 && !hasFlash7) {
                return 1;  // Flash needs Update
            } else {
                if( !hasFlash6 ) {
                    return 0;   // Needs to install Flash
                }                
            }
        }
        return -1;
    },                    
    DoExpressInstall : function( reloadPage ) {    
    	document.write("<br /><br /><br /><br />");
    	document.write("<div id='flashController' style='width:100%;text-align:center;margin-top:10pt'></div>" );
        document.title = document.title.slice(0, 47);	    
        
        var playerType = (isIE == true) ? "ActiveX" : "PlugIn";
	    var so_FlashDetectionControl = new SWFObject(this.FlashDetectionControl, 
	                                "FlashDetectionControlObj", "215", "138", "6", "#FFFFFF", true, "high", true);
		
	    so_FlashDetectionControl.addVariable("MMredirectURL", reloadPage );
	    so_FlashDetectionControl.addVariable("MMplayerType", playerType );
	    so_FlashDetectionControl.addVariable("MMdoctitle", document.title.slice(0, 47) + " - Flash Player Installation");
		
	    so_FlashDetectionControl.write('flashController');	
	    document.write("<br /><br /><br /><br />");	            
    },    
    DoDownloadFlash : function ( writeToDiv, writeBefore, langMsg, topLine,  helpline ) {
    
        var warndiv;
        var dwnlddiv;
        var msgText = '';
        var outtext = '';
        var helpurl = '';
        var cntr;
        
        warndiv 			= document.createElement('div');
        warndiv.id			= 'warndiv';                        
        warndiv.style.width = '100%';	        
        warndiv.style.border = 'red 2px';
        warndiv.style.borderStyle ='solid';    
        warndiv.style.background = '#FACECD';
        warndiv.style.zIndex = '999';

        if( langMsg ) {       
            if( langMsg.length > 0 ) {
                msgText = langMsg;
            }                                
        }
        warndiv.style.font.weight = 'bold';
        warndiv.style.fontSize = "1.0em";//pt";

		//var flashRequired = "Flash Plugin Required";
        
        if( msgText != '' ) {            
            outtext = '<center><p>' + msgText + '</p></center>';        
        } else {
            outtext = '<center><strong>' + flashRequired + '</strong></center>';                
        }       
        
        //var flashRequiredMsg1 = 'To play at our web site you will require the Adobe Flash Plugin, click the image below to download.';
        //var flashRequiredMsg2 = 'If you are unable to download or install the plugin you may not have suffient privilages on your computer to perform these actions.';
        
        if( topLine ) {       
            if( topLine.length > 0 ) {
                topLineMsg = topLine;
            }                                
        }       
        
        if( helpline ) {
            if( helpline.length > 0 ) {
                helpLineMsg = helpline;            
            }            
        }        
        
        warndiv.innerHTML = outtext;
        
        dwnlddiv            = document.createElement('div');
        dwnlddiv.id			= 'downloadDiv';        
        dwnlddiv.style.width = '50%';	        
        dwnlddiv.style.border = 'silver 2px';
        dwnlddiv.style.borderStyle ='solid';    
        dwnlddiv.style.background = '#F6F1F1'; 
        dwnlddiv.style.display = 'block';
        dwnlddiv.style.zIndex = '999';
        
        dwnlddiv.innerHTML = "<div id='warndiv' style='width:100%;border:#FF0000 2px;border-style:solid;background:#FACECD;zIndex:999;font-weight:bold;font-size:1.0em;'><center><strong>" + flashRequired + "</strong></center></div>";
        dwnlddiv.innerHTML += '<center><br /><br /><br /><br />';
        dwnlddiv.innerHTML += '<p>' + flashRequiredMsg1 + '</p><br>';
        
        dwnlddiv.innerHTML += '<p>' + flashRequiredMsg2 + '</p><br>';        
        dwnlddiv.innerHTML += '<p><a href=\'http://www.adobe.com/go/getflashplayer\' target=\'_blank\'><img border=\'0\' src=\'/CommonContent/Assets/Images/get_flash_player.gif\' /></a></p></center>';
      
        cntr = document.createElement( 'center' );
        
        if( !writeToDiv ) { 
            writeToDiv = document.getElementsByTagName('body')[0];
        }
             
        if( writeBefore ) {                                 
            //writeToDiv.insertBefore( warndiv, writeBefore );
            //writeToDiv.insertBefore( document.createElement( 'br' ), writeBefore );             	                    
            cntr.appendChild( dwnlddiv );
            writeToDiv.insertBefore( cntr, writeBefore );                    
        } else {
            //writeToDiv.appendChild( warndiv );
            //writeToDiv.appendChild( document.createElement( 'br' ) );             	                    
            cntr.appendChild( dwnlddiv );
            writeToDiv.appendChild( cntr );            
        }        
    },    
    UnsupportedSystem: function ( writeToDiv, writeBefore, langMsg, topLine ) {
    
        var warndiv;
        var dwnlddiv;
        var cntr;
        var msgText = '';
        var outtext = '';
        var helpurl = '';
        
//        if( helplink ) helpurl = helplink;

        warndiv 			= document.createElement('div');
        warndiv.id			= 'warndiv';                        
        warndiv.style.width = '100%';	        
        warndiv.style.border = 'red 2px';
        warndiv.style.borderStyle ='solid';    
        warndiv.style.background = '#FACECD';
        warndiv.style.display = 'block';
        warndiv.style.zIndex = '999';

        if( langMsg ) {       
            if( langMsg.length > 0 ) {
                msgText = langMsg;
            }                                
        }
        warndiv.style.font.weight = 'bold';
        warndiv.style.fontSize = "1.0em";//pt";

		//var flashRequired = "Flash Plugin Required";
        
        if( msgText != '' ) {            
            outtext = '<center><p>' + msgText + '</p></center>';        
        } else {
            outtext = '<center><strong>' + flashRequired + '</strong></center>';                
        }        
        
        //var unsupportedMsg1 = 'Our poker site is only compatible with the Windows PC Platform.  At this time we are unable to support other systems.';
        //var unsupportedMsg2 = 'Please accept our apologies for the inconvenience.';
            
        if( topLine ) {       
            if( topLine.length > 0 ) {
                topLineMsg = topLine;
            }                                
        }       
                
        warndiv.innerHTML = outtext;
        
        dwnlddiv            = document.createElement('div');
        dwnlddiv.id			= 'downloadDiv';
        dwnlddiv.style.width = '50%';	        
        dwnlddiv.style.border = 'silver 2px';
        dwnlddiv.style.borderStyle ='solid';    
        dwnlddiv.style.background = '#F6F1F1';
        dwnlddiv.style.display = 'block';
        dwnlddiv.style.zIndex = '999';
        
        dwnlddiv.innerHTML = "<div id='warndiv' style='width:100%;border:#FF0000 2px;border-style:solid;background:#FACECD;zIndex:999;font-weight:bold;font-size:1.0em;'><center><strong>Flash Plugin Required</strong></center></div>";
		dwnlddiv.innerHTML += '<br /><br />';
        dwnlddiv.innerHTML += '<p>' + unsupportedMsg1 + '</p><br />';  
        dwnlddiv.innerHTML += '<p>' + unsupportedMsg2 + '</p><br />';  
        
        cntr = document.createElement( 'center' );
        
        if( !writeToDiv )          {
            writeToDiv = document.getElementsByTagName('body')[0];
        }            
        
        if( writeBefore ) {                    
            //writeToDiv.insertBefore( warndiv, writeBefore );
            //writeToDiv.insertBefore( document.createElement( 'br' ), writeBefore );             	                    
            cntr.appendChild( dwnlddiv );            
            writeToDiv.insetrBefore( cntr, writeBefore);                                
        } else {
            //writeToDiv.appendChild( warndiv );
            //writeToDiv.appendChild( document.createElement( 'br' ) );             	                    
            cntr.appendChild( dwnlddiv );
            writeToDiv.appendChild( cntr );                    
        }
    },    
    CanPlayFlashGame : function() {
        if( BrowserDetect.OS == 'Windows' && BrowserDetect.browser == 'Explorer' ){
            return 2;                   //can play no worries
        } else if( BrowserDetect.OS == 'Windows' && BrowserDetect.browser != 'Explorer' ) {
            return 1;                   // can play, but need to be warned about Need for IE
        }
        return 0;                       // Cant Play at all
    },    
    CanDownloadClient : function() {    
        if( BrowserDetect.OS =='Windows' ) 
            return 2;                   // can Download            
        return 0;                       // Cant Download    
    },    
    RunFlashCheck : function( ) {
        var vIsSupported = this.IsSupportedBrowser();
        var vIsFlashCurrent;
        if(  vIsSupported ) {        
            vIsFlashCurrent = this.IsFlashCurrent();

            switch( vIsFlashCurrent ) {
                case 0:     // Need to do complete Install
                    return 0;
                case 1:
                    if( this.UpgradeFlashPage != '' ) {
                        this.DoExpressInstall(this.UpgradeFlashPage );
                    } else {
                        this.DoExpressInstall( window.location );
                    }                        
                    return 1;
                    break;
                case 2:  
                    return 2;
                    break;
            }
        } else {
            return -1;
        }
    },
    RunGameCheck : function() {
        switch( this.CanPlayFlashGame() ) {
            case 0:
                window.location = '';
                break;
            case 1:
                window.location = '';                    
                break;
            case 2:
                return true;
        }
    },    
    RunDownloadClientCheck : function () {
        switch( this.CanDownloadClient() ) {
            case 1:
                return false;
                break;
            case 2:
                return true;
        }
    }
};
FlashDetect.init();	

