<!--
// Globals
// Major version of Flash required

var requiredMajorVersion = 10;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 12;

// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

var flashMsg = 'Flash: Unknown : Unknown';
var osBrowserComboMsg = 'OS Browser Combo: Unknown : Unknown,Unknown';

var requestNotesForTYSlogging = "TYS Action: Anonymous: Unknown | "+flashMsg +"| Server Accessibility: Unknown: Unknown | Cookies: Unknown: Unknown | "+osBrowserComboMsg+" | Browser: Unknown : Unknown | Screen Resolution: Unknown: Unknown | Bandwidth: Unknown: Unknown | Windows Media Player: Unknown: | Real Player: Unknown: | "

if((!hasValidOSBrowserImpl() || !hasProductInstall || !hasRequestedVersion) && isHtm){
    //make this mehthod call only when the client is an Html page and if the above tests fails.
    getLocalizedMessages();
}

if(!hasValidOSBrowserImpl()){
    if(!isHtm){
        requestNotesForTYSlogging = requestNotesForTYSlogging.replace(osBrowserComboMsg,'OS Browser Combo: Fail :'+ os+','+ browser);
        logTYSData();
    }
    document.write(getErrorMessage('browseros'))
} else if ( !hasProductInstall ) {
    if(!isHtm){
        requestNotesForTYSlogging = requestNotesForTYSlogging.replace(flashMsg,'Flash: Fail : Not Installed')
        logTYSData();
    }
    document.write(getErrorMessage('flashnotinstalled'))
} else if ( hasProductInstall && !hasRequestedVersion ) {
    if(!isHtm){
        var userFlashVersion = GetSwfVer().replace("WIN ", "");
        //doing this replace because flash version for IE is coming back as comma separated values
        // from GetSwfVer().replace("WIN ", "") method above;
        userFlashVersion = userFlashVersion.replace(/,/g,'.');
        requestNotesForTYSlogging = requestNotesForTYSlogging.replace(flashMsg,'Flash: Fail : '+userFlashVersion)
        logTYSData();
    }
    document.write(getErrorMessage('flashnotvalidversion'))
/*var alternateContent =  '<div id="installFlash">This content requires the latest version of Adobe Flash Player. '
   	+ '<a href="http://www.adobe.com/go/getflash/" target="_blank">Get Flash</a></div>';
    document.write(alternateContent);  // insert non-flash content*/
} else if (hasRequestedVersion) {
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
	
    flashVariables += "&flashversion=" + GetSwfVer().replace("WIN ", "")
        + "&cookieenabled=" + isCookieEnabledImpl()
        +  "&validosbrowser=" + hasValidOSBrowserImpl()
        +  "&os=" + getOSName()
        +  "&validbrowser=" + hasValidBrowserImpl()
        +  "&btype=" + getBrowserType()
        +  "&bversion=" + getBrowserVersion()
        +  "&hasreal=" + detectRealImpl()
        +  "&haswindowsmedia=" + detectWindowsMediaImpl()
        +  "&screenresolution=" + screenWidth + "x" +  screenHeight
        +  "&realbuild=" + getRealPlayerBuild()
        +  "&wmbuild=" + getWMPlayerBuild();
	
    //alert(flashVariables)
	
    AC_FL_RunContent(
        "src", SWFSource,
        "FlashVars", flashVariables,
        "width", "100%",
        "height", "100%",
        "align", "middle",
        "id", "VirtualTradeshow",
        "quality", "high",
        "bgcolor", "#869ca7",
        "name", "VirtualTradeshow",
        "allowScriptAccess","sameDomain",
        "type", "application/x-shockwave-flash",
        "pluginspage", "http://www.adobe.com/go/getflashplayer"
        );
} else {  // flash is too old or we can't detect the plugin
    var alternateContent =  'An error has occured. please contact technical support.';
    document.write(alternateContent);  // insert non-flash content
}


function logTYSData(){

    var link = appServer+"/eventManager/EventLogServlet";

    var params = "sessionid=1&actioncategorycode=audit&eventid="+showId+"&mode=insert&usertypecode=eventuser&userid=1&actiontypecode=insert&requestnotes="+requestNotesForTYSlogging+"&requestdetails=VS-TYS-Anonymous";

    $.ajax({
        type:'POST',
        data:params,
        url: link,
        async:false
    });
}
   

function getErrorMessage(code){
    var messageHead= '<div id="mainContent"><div id="pageHeader">'+i18narr['vshow.tys.system.test.column.title']+'</div> <div id="statusMessageHeader"> <div class="message">'+i18narr['vshow.tys.text.message.criticalError']+'</div>	</div><div id="statusMessage">'+i18narr['vshow.tys.text.message.config.failed']+'</div>	<div id="testResult">		<table width="100%" cellpadding="0" cellspacing="0" border="1">			<tr><td class="TYSGridHeaderItem" width="170">'+i18narr['vshow.tys.system.test.column.title']+'</td><td class="TYSGridHeaderItem" width="285">'+i18narr['vshow.tys.system.req.column.title']+'</td><td class="TYSGridHeaderItem" width="195">'+i18narr['vshow.tys.system.config.column.title']+'</td><td class="TYSGridHeaderItem" width="90">'+i18narr['vshow.tys.system.status.column.title']+'</td><td class="TYSGridHeaderItem" width="160">'+i18narr['vshow.tys.system.info.column.title']+'</td></tr>'
    if(localeExists()){
        messageHead= '<div id="mainContent"><div id="pageHeader">'+i18narr['vshow.tys.system.test.column.title']+'</div> <div id="statusMessageHeader"> <div class="message">'+i18narr['vshow.tys.text.message.criticalError']+'</div>'+getLocaleDropDown()+'</div><div id="statusMessage">'+i18narr['vshow.tys.text.message.config.failed']+'</div>	<div id="testResult">		<table width="100%" cellpadding="0" cellspacing="0" border="1">			<tr><td class="TYSGridHeaderItem" width="170">'+i18narr['vshow.tys.system.test.column.title']+'</td><td class="TYSGridHeaderItem" width="285">'+i18narr['vshow.tys.system.req.column.title']+'</td><td class="TYSGridHeaderItem" width="195">'+i18narr['vshow.tys.system.config.column.title']+'</td><td class="TYSGridHeaderItem" width="90">'+i18narr['vshow.tys.system.status.column.title']+'</td><td class="TYSGridHeaderItem" width="160">'+i18narr['vshow.tys.system.info.column.title']+'</td></tr>'
    }
    var messageTail="</table><div><br><br>\n\<input type='button' value='"+i18narr['vshow.tys.button.testAgain']+"' onclick='handleTestAgain()'/></div></div></div>"
    //var messageTail="</table><div><br><br>\n\<input type='button' value='"+i18narr['vshow.tys.button.testAgain']+"' onclick='window.top.location.reload();return false;'/></div></div></div>"
    //var messageTail='</table><div><br><br><input type="button" value="Test Again" onclick="window.top.location.reload()"/></div>	</div></div>'
	
    var messageBody = "";
	
    if(code=='browseros'){
        messageBody = '<tr class="gridRowFailure"><td>'+i18narr['vshow.tys.system.test.os.combo']+'</td><td>'+ osbrowsereq(i18narr['vshow.tys.system.req.os.win'],i18narr['vshow.tys.system.req.browser.ie'],i18narr['vshow.tys.text.with']) +', '
        + osbrowsereq(i18narr['vshow.tys.system.req.os.win'],i18narr['vshow.tys.system.req.browser.fx'],i18narr['vshow.tys.text.with'])+', '
        + osbrowsereq(i18narr['vshow.tys.system.req.os.win'],i18narr['vshow.tys.system.req.browser.ch'],i18narr['vshow.tys.text.with'])+', '
        + osbrowsereq(i18narr['vshow.tys.system.req.os.mac'],i18narr['vshow.tys.system.req.browser.sf'],i18narr['vshow.tys.text.with'])+', '
        + osbrowsereq(i18narr['vshow.tys.system.req.os.mac'],i18narr['vshow.tys.system.req.browser.fx'],i18narr['vshow.tys.text.with'])+', '
        + osbrowsereq(i18narr['vshow.tys.system.req.os.mac'],i18narr['vshow.tys.system.req.browser.ch'],i18narr['vshow.tys.text.with'])+', '
        + osbrowsereq(i18narr['vshow.tys.system.req.os.lnx'],i18narr['vshow.tys.system.req.browser.fx'],i18narr['vshow.tys.text.with'])+
        '</td><td>'+getUserBrowserConfigI18N()+'</td><td align="center"><img src="/view/vts/tys/images/icon_fail_red.png"/></td><td><a href="http://'+location.host+'/clients/vshow/systemtest/help.html#OSBrowser" target="_blank">'+i18narr['vshow.tys.system.info.combo']+'</a></td></tr>'
    } else if(code=='flashnotinstalled'){
        messageBody = '<tr class="gridRowFailure"><td>'+i18narr['vshow.tys.system.test.flash']+'</td><td>'+i18narr['vshow.tys.system.req.flash']+'</td><td>'+i18narr['vshow.tys.system.config.notInstalled']+'</td><td align="center"><img src="/view/vts/tys/images/icon_fail_red.png"/></td><td><a href="http://vshow.on24.com/clients/vshow/systemtest/help.html#Flash" target="_blank">'+i18narr['vshow.tys.system.info.flashPlayer']+'</a></td></tr>'
    } else if(code=='flashnotvalidversion'){
        messageBody = '<tr class="gridRowFailure"><td>'+i18narr['vshow.tys.system.test.flash']+'</td><td>'+i18narr['vshow.tys.system.req.flash']+'</td><td>'+i18narr['vshow.tys.system.config.flash']+ GetSwfVer().replace("WIN ", "")+'</td><td align="center"><img src="/view/vts/tys/images/icon_fail_red.png"/></td><td><a href="http://vshow.on24.com/clients/vshow/systemtest/help.html#Flash" target="_blank">'+i18narr['vshow.tys.system.info.flashPlayer']+'</a></td></tr>'
    }
	
    return messageHead + messageBody + messageTail;
}

function handleTestAgain() {
    runTestAgainImpl();
}


function osbrowsereq(os, browser, withstr){
    str = withstr.replace("{0}",os).replace("{1}",browser);
    return str;
}

function getLocaleDropDown(){
    str = "<div class='localepref'><select name='locale' onchange='handleLocaleSelection(this)'>";
    for (var v in locales) {
        str +="<option value='"+v+"' ";
        if(v == currentLocale){
            str+=" selected ";
        }
        str+=">"+locales[v]+"</option>";
    }
    str+="</select></div>";
    return str;
}


function localeExists(){
    if(locales){
        for(var l in locales){
            return true;
        }
    }
    return false;
}

function handleLocaleSelection(element){
    writeLocalePreferenceCookie(element.value);

    runTestAgainImpl(element.value);
}

function getUserBrowserConfigI18N(){
    var os = getOSName();
    var browser = getBrowserType();
    var osstr="";
    var browserstr ="";
    if(os=="win"){
        osstr = i18narr['vshow.tys.system.req.os.win'];
    } else if(os=="mac"){
        osstr = i18narr['vshow.tys.system.req.os.mac'];
    } else if(os=="lnx"){
        osstr = i18narr['vshow.tys.system.req.os.lnx'];
    }

    if(osstr != ""){
        if(browser=="ie"){
            browserstr= i18narr['vshow.tys.system.req.browser.ie'];
        } else if(browser=="fx"){
            browserstr=i18narr['vshow.tys.system.req.browser.fx'];
        } else if(browser=="sf"){
            browserstr= i18narr['vshow.tys.system.req.browser.sf'];
        } else if(browser=="ch"){
            browserstr= i18narr['vshow.tys.system.req.browser.ch'];
        }
    }
    if(osstr == "" || browserstr == "") {
        return i18narr['vshow.tys.system.config.notSupported'];
    } else {
        return osbrowsereq(osstr, browserstr, i18narr['vshow.tys.text.with']);
    }
    
}

function writeLocalePreferenceCookie(userlocale){
    if(userlocale && userlocale != ""){
        objCookieUtils.setEscapedCookie("locale"+showId, userlocale,dateAfterOneYear, "/", ".on24.com");
    }
}

function getCookieLocale(){
    return objCookieUtils.getCookieValue("locale"+showId);
}

function getBrowserLocale(){
    return browserLocale;
}


function querySt(ji) {
    var hu = window.location.search.substring(1);
    var ps = hu.split("#");
    var gy = ps[0].split("&");
    for (var i=0;i<gy.length;i++) {
        var ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}


var reloadCalled = false;
function runTestAgainImpl(locale){
    if(reloadCalled) return;
    reloadCalled = true;

    var browser = getBrowserType();
    if(locale){
        var qslocale = querySt("l");
        var ps;
        var suf;

        if (browser == "ie")
        {
            if(qslocale){
                // replace the value with the new value if changed, else reload
                if (qslocale == locale) {
                    window.location.reload();
                } else {
                    window.location.href = window.location.href.replace('='+qslocale,'='+locale);
                }
            } else {
                ps = window.location.href.split("#");
                suf = "";
                if (ps.length > 1) {
                    suf = "#" + ps[1];
                }
                window.location.href = ps[0] + (ps[0].indexOf("?") == -1?"?":"&") + "l="+locale + suf;
		
            }
        }
        else
        {
            if(qslocale){
                // replace the value with the new value if changed, else reload
                if (qslocale == locale) {
                    location.reload();
                } else {
                    location.href = location.href.replace('='+qslocale,'='+locale);
                }
            } else {
                ps = location.href.split("#");
                suf = "";
                if (ps.length > 1) {
                    suf = "#" + ps[1];
                }
                location.href = ps[0] + (ps[0].indexOf("?") == -1?"?":"&") + "l="+locale + suf;
            }
        }

    }
    else
    {
        if (browser == "ie")
        {
            window.location.reload();
        }
        else
        {
            location.reload();
        }
    }
}

function continueToShowImpl(locale){
    objCookieUtils.setEscapedSessionCookie ("vshow-tys-status", "success","/", location.host);

    var browser = getBrowserType();
    if(locale){
        var qslocale = querySt("l");
        var ps;
        var suf;

        if (browser == "ie")
        {
            if(qslocale){
                // replace the value with the new value if changed, else reload
                if (qslocale == locale) {
                    window.location.reload();
                } else {
                    window.location.href = window.location.href.replace('='+qslocale,'='+locale);
                }
            } else {
                ps = window.location.href.split("#");
                suf = "";
                if (ps.length > 1) {
                    suf = "#" + ps[1];
                }
                window.location.href = ps[0] + (ps[0].indexOf("?") == -1?"?":"&") + "l="+locale + suf;
		
            }
        }
        else
        {
            if(qslocale){
                // replace the value with the new value if changed, else reload
                if (qslocale == locale) {
                    location.reload();
                } else {
                    location.href = location.href.replace('='+qslocale,'='+locale);
                }
            } else {
                ps = location.href.split("#");
                suf = "";
                if (ps.length > 1) {
                    suf = "#" + ps[1];
                }
                location.href = ps[0] + (ps[0].indexOf("?") == -1?"?":"&") + "l="+locale + suf;
            }
        }

    }
    else
    {
        if (browser == "ie")
        {
            window.location.reload();
        }
        else
        {
            location.reload();
        }
    }
}

function testBandwidth(){
    var kbps = 0;
    var startDate = new Date();
    $.ajax({
        url: "/utils/test/images/testImage.jpg?time="+new Date().getTime(),
        complete:function (request){
            var length = parseInt(request.getResponseHeader("Content-Length"));
            var bits = parseInt(length) * 8;
          
            var time = new Date().getTime() -  startDate.getTime();
            kbps = ((bits * 1000)/ time)/1024;
        },
        async:false,
        dataType:"image/jpg"
    });
    return kbps.toFixed();
}
// -->
