﻿// our minimum version
var strMinVer = "8.0.0";
var boolHasGoodVersion = swfobject.hasFlashPlayerVersion(strMinVer);

function checkForRedir() {
    // check to see if we have the right player
    if(boolHasGoodVersion) {
        // check to see if we have a hash mark, ?, or page extension in the URL
        boolHasHash = (/#/.test(location.href));
        boolHasQuestionMark = (/\?/.test(location.href));
        boolHasPage = (/.aspx/.test(location.href));
        // get the path from the location bar
        strPath = location.href.split(location.host)[1];
        
        // if we have a ? with a page extension, put a / before it so we can extract the page
        if(boolHasQuestionMark) {
            strPath = strPath.replace("?","/?");
        }
        
        // if we have a page in there, we need to remove it
        // first split into an array
        if(boolHasPage) {
            arrPathParts = strPath.split('/');
            strPath = "";
            // loop through and find the in the array
            for(i=0;i<arrPathParts.length;i++) {
                if((/.aspx/.test(arrPathParts[i]))) {
                    // don't do anything
                } else {
                    // add this array element to the path string
                    strPath += "/" + arrPathParts[i];
                }
            }
        }
        
        // if we removed the page, but didn't have a querystring, be sure we have a trailing slash
        if(boolHasPage && !boolHasQuestionMark) {
             strPath = strPath + "/";
        }
        
        // now remove any double //
        strPath = strPath.replace("//","/");
        
        // if we don't already have a hash, add it...
        if(!boolHasHash) {
            strPath = '/#' + strPath;
        }
        
        
        
        
        
        // now redirect
        location.replace(strPath);
    }
}
