﻿var __nonMSDOMBrowser = (window.navigator.appName.toLowerCase().indexOf('explorer') == -1);

function FlashLibraryActivate2(swfFile,width,height,bgcolor,ver,altFormat,movieName)
{
    var t = this;
    var activeX = false;
    t.hasVersion = function(ver)
    {
        t.swf = false;
        if(!ver)
        {
            ver = 0;
        }
        var n = navigator;
        if(n.plugins && n.plugins.length > 0)
        {
            var m,tp,d,v;
            m = n.mimeTypes;
            tp = 'application/x-shockwave-flash';
            if(m && m[tp] && m[tp].enabledPlugin && m[tp].enabledPlugin.description)
            {
                d = m[tp].enabledPlugin.description;
                v = d.charAt(d.indexOf('.')-1);
                t.swf = (v >= ver) ? true : false;
            }
        }
        else if(n.appVersion.indexOf("Mac") == -1 && window.execScript)
        {
            ieFlashObj = null;
            activeX = true;
            for(var i=ver; i<=10&&i!=1&& ieFlashObj!=true; i++)
            {
                execScript('on error resume next: ieFlashObj=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash'+((i==0)?'':'.'+i)+'"))','VBScript');
                if ( ieFlashObj == true )
                {
                    t.swf = true;
                    break;
                }
            }
        }
        else
        {
            t.swf = false;
        }
        return t.swf;
    }
    t.getPluginTag = function()
    {
        var fixedVer = "";
        if( ver == 7)
        {
            fixedVer = "7,0,0,0";
        }
        else if( ver > 7 )
        {
            fixedVer = "8,0,0,0";
        }
        else
        {
            fixedVer = "6,0,21,0";
        }
        var s = '';
        var win = (navigator.appVersion.toLowerCase().indexOf("win") != -1);
        var ie = (navigator.appName=="Microsoft Internet Explorer");
        if(t.hasVersion(ver) && swfFile || win && ie && swfFile)
        {
            var additionalParams = '';
            var qPos  = swfFile.indexOf ( "?" );
            if ( qPos > -1 && qPos + 1 < swfFile.length && ver == 6 )
            {
                var ta = 'FlashVars';
                var v = swfFile.substring ( qPos + 1 );
                swfFile = swfFile.substring ( 0 , qPos );
                additionalParams += (activeX)?'\t<param name="' + ta + '" value="' + v + '" />\n': ' '+ ta + '="' + v + '"';
            }
            if(activeX)
            {
                s = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + fixedVer + '" id="' + movieName + '" width="' + width + '" height="' + height + '">\n';
                s += '\t<param name="movie" value="' + swfFile + '" />\n';
                s += '\t<param name="quality" value="high" />\n';
                s += '\t<param name="menu" value="false" />\n';
                s += '\t<param name="wmode" value="opaque" />\n';
                s += '\t<param name="bgcolor" value="' + bgcolor + '" />\n';
                s += additionalParams;
                //s += params;
                s += altFormat;
                s += '</object>\n\n';
                return s;
            }
            else
            {
                s = '<embed src="' + swfFile + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" wmode="opaque" type="application/x-shockwave-flash" name="' + movieName + '" width="' + width + '" height="' + height + '" bgcolor="' + bgcolor + '"' + additionalParams + '></embed>\n';
                return s;
            }
        }
        else
        {
            return altFormat;
        }
    }
}


function SetFlashVersion()
{
    var flashversion = 0;
    var MSDetect = false;
    if (navigator.plugins && navigator.plugins.length)
    {
        x = navigator.plugins["Shockwave Flash"];
        if (x)
        {
            if (x.description)
            {
                y = x.description;
                return y.charAt(y.indexOf('.')-1);
            }
        }
        if (navigator.plugins["Shockwave Flash 2.0"])
        {
            return 2;
        }
    }
    else
    {
        MSDetect = true;
    }
    if( MSDetect )
    {
        var vs = 0;
        for( v=2;v<15;v++ )
        {
            ieFlashObj = null;
            window.execScript('on error resume next: ieFlashObj = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + v + '"))','VBScript');
            if( ieFlashObj )
            {
                vs = v;
            }
        }
        return vs;
    }
    return 0;
}


function RenderFlashContainer(flashPath, altImgPath, containerWidth, containerHeight)
{
    var altFormat = "<img alt=\"\" src=\"images/" + altImgPath + "\" style=\"width: " + containerWidth + "px;height:" + containerHeight + "px\" />\n";
    if ( (flashPath) && flashPath != '')
    { 
        var fDiv = getAnElement('flashImgTD');
        if (fDiv)
        {
            fDiv.innerHTML = new FlashLibraryActivate2('images/' + flashPath, containerWidth, containerHeight, '#FFFFFF', 7, altFormat, 'flashObject').getPluginTag();
        }//,132
    }
}

function getAnElement(id)
{
	return document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : document.layers[id];
}

function centerAll() 
{
    var pageX = (document.all)?document.body.offsetWidth:window.innerWidth;
    var pageY = (document.all)?document.body.offsetHeight:window.innerHeight;
    for (x=0;x<objID.length;x++) 
    {
        var objRef = document.getElementById(objID[x]);
        var objW = objRef.offsetWidth;
        var objH = objRef.offsetHeight;
        objRef.style.left = ((pageX/2)-(objW/2))+"px";
        objRef.style.top = ((pageY/2)-(objH/2))+"px";
    }
}

function ToggleImage(ctrl)
{
    var imgUrl = ctrl.getAttribute("src");
    var onIndex = imgUrl.indexOf("_on");
    if(onIndex > 0)
    {
        imgUrl = imgUrl.replace("_on" ,"_off");
    }
    else
    {
        imgUrl = imgUrl.replace("_off" ,"_on");
    }
    ctrl.setAttribute("src", imgUrl);
}


function RedirectPage(url, ctrlId)
{
    if(ctrlId != null)
    {
        location.href = 'SiteSearch.aspx?search=' + document.getElementById('Header1_' + ctrlId).value;
    }
    else
    {
        location.href = url;
    }
}


function FireDefaultButton(event, target)
{
    if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) 
    {
        var defaultButton;
        if (__nonMSDOMBrowser) 
        {
            defaultButton = document.getElementById(target);
        }
        else 
        {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof(defaultButton.click) != "undefined") 
        {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation)
            {
                event.stopPropagation();
            }
            return false;
        }
    }
    return true;
}

function DisplayText(ctrl)
{
    if(ctrl.value == 'Search...')
    {
        ctrl.value = '';
    }
    else if(ctrl.value == "")
    {
        ctrl.value='Search...';
    }
}