﻿// JScript File

var panes = new Array();

var m_CurrentNewsFlashPos = 0;
var m_ScrollerPause = 4000;
var m_CoverDiv = null;


function setupPanes(containerId, defaultTabId) {
// go through the DOM, find each tab-container
// set up the panes array with named panes
// find the max height, set tab-panes to that height
panes[containerId] = new Array();
var maxHeight = 0; var maxWidth = 0;
var container = document.getElementById(containerId);
var paneContainer = container.getElementsByTagName("div")[0];
var paneList = paneContainer.childNodes;
for (var i=0; i < paneList.length; i++ ) {
var pane = paneList[i];
if (pane.nodeType != 1) continue;
if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
if (pane.offsetWidth > maxWidth ) maxWidth = pane.offsetWidth;
panes[containerId][pane.id] = pane;
pane.style.display = "none";
}
paneContainer.style.height = maxHeight + "px";
paneContainer.style.width = maxWidth + "px";
document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
// make tab active class
// hide other panes (siblings)
// make pane visible

for (var con in panes) {
activeTab.blur();
activeTab.className = "tab-active";
if (panes[con][paneId] != null) { // tab and pane are members of this container
var pane = document.getElementById(paneId);
pane.style.display = "block";
var container = document.getElementById(con);
var tabs = container.getElementsByTagName("ul")[0];
var tabList = tabs.getElementsByTagName("a")
for (var i=0; i<tabList.length; i++ ) {
var tab = tabList[i];
if (tab != activeTab) tab.className = "tab-disabled";
}
for (var i in panes[con]) {
var pane = panes[con][i];
if (pane == undefined) continue;
if (pane.id == paneId) continue;
pane.style.display = "none"
}
}
}
return false; 
}


var prepend = "";
if(window.location.pathname.indexOf("NewsFlash") > -1)
    prepend = "../";

function setSelectButton() {
    var pageId = document.getElementById("Id-div");
    var tabId = pageId.parentNode.getAttribute("id");
    var topRightImageType = tabId;
// Reset the tabs

// make tab active class
  if (tabId == "Home") {
    setTabHighlightStyles(docHome);
  }
  else if (tabId == "Sol"){
    setTabHighlightStyles(docSol);
  }
  else if (tabId == "Whyus"){
    setTabHighlightStyles(docWhyus);
  }
  else if (tabId == "Partners"){
    setTabHighlightStyles(docPartners);
  }
  else if (tabId == "Contact"){
    setTabHighlightStyles(docContact);
  }
  else if (tabId == "Latest"){
    setTabHighlightStyles(docLatest);
  }
  else if (tabId == "Resource"){
    setTabHighlightStyles(docResource);
  }
  else if (tabId == "Offer"){
    setTabHighlightStyles(docOffer);
  }
  else if (tabId == "Buy"){
    setTabHighlightStyles(docBuy);
    topRightImageType = "BLANK";
  }
  else if (tabId == "TheftProd")
  {
    setTabHighlightStyles(docTheft);
  }
  else if (tabId == "FleetProd")
  {
    setTabHighlightStyles(docFleet);
  }
  else if (tabId == "Police")
  {
    setTabHighlightStyles(docPolice);
}
else if (tabId == "Traffic") {
    setTabHighlightStyles(docTraffic);
}
  
 SetImageTopRight(topRightImageType);
 
 return false; 
}

function SetImageTopRight(type)
{
    var oImage = document.getElementById("ctl00_ctl00_topRightImage");
    if(oImage)
    {
        switch(type)
        {
            case "BLANK":
                oImage.style.visibility = "hidden";
                break;
            default:
                oImage.style.visibility = "";
                break;
        }
    }
}

function setTabHighlightStyles(tab)
{
    //First change div styles
    var oDivs = tab.getElementsByTagName("DIV");
    if(oDivs)
    {
        for(var i = 0;i < oDivs.length;i++)
        {
            var classN = oDivs[i].className;
            var newClass = "";
            switch(classN)
            {
                case  "stdTabLeft":
                    newClass = "highlightTabLeft";
                    break;
                case  "stdTabCenter":
                    newClass = "highlightTabCenter";
                    break;
                case  "stdTabText":
                    newClass = "highlightTabText";
                    break;
                case  "stdTabRight":
                    newClass = "highlightTabRight";
                    break;
            }
            
            if(newClass != "")
                oDivs[i].className = newClass;
        }
        var oLinks = tab.getElementsByTagName("A");
        if(oLinks)
        {
            for(var i = 0;i < oLinks.length;i++)
            {
                var classN = oLinks[i].className;
                var newClass = "";
                switch(classN)
                {
                    case  "TabTextLink":
                        newClass = "highlightTabTextLink";
                        break;
                }
                
                if(newClass != "")
                    oLinks[i].className = newClass;
            }
        }
    }
}

var bannerNum = 0;
var bannerImages = new Array();

function rotateBanner() 
{
    if (++bannerNum >= bannerImages.length)
        bannerNum = 0;
    var banner = document.getElementById("ttbanner");
    if(!banner)
    {
        if(bannerNum == 0)
            banner = document.getElementById("ttbanner"+( bannerImages.length));
        else
            banner = document.getElementById("ttbanner"+(bannerNum));
    }
    if(banner)
    {
        if(bannerImages.length > 0)
        {
            var parent = banner.parentNode;
            parent.replaceChild(bannerImages[bannerNum],banner);
        }
    }
    window.setTimeout('rotateBanner();', 3000);
}

function includeImage(result)
{
    bannerImages[bannerImages.length] = result;
}

function preloadBanner()
{
    for(var imgCount = 1;imgCount<5;imgCount++)
    {
        var newImage = document.createElement("IMG");
        newImage.src = "Images/banner" + imgCount + ".png";
        newImage.id = "ttbanner"+imgCount;
        if(!newImage)
            break;
        newImage.onload = function(newImage){includeImage(this);}
    }
    window.setTimeout("rotateBanner();",3000);
}

var m_CurrentNewsFlash = null;
var m_OldNewsFlash = null;
var m_Scrolling = false;


function PopulateFirstNewsFlash()
{
    m_CurrentNewsFlash = document.getElementById("CurrentNewsFlash");
    m_OldNewsFlash = document.getElementById("NewNewsFlash");
    
    if(m_CurrentNewsFlash)
    {
        m_CurrentNewsFlash.style.top = 5;
            m_CurrentNewsFlash.innerHTML = "<a href='"+m_NewsFlashArray[m_CurrentNewsFlashPos][1]+"' target='"+m_NewsFlashArray[m_CurrentNewsFlashPos][2]+"'>"+m_NewsFlashArray[m_CurrentNewsFlashPos][0]+"</a>";
            m_CurrentNewsFlashPos++;
        window.setTimeout(MoveNewsFlash,m_ScrollerPause);
    }
}

function SetupNewsFlash()
{
    
    if(m_NewsFlashArray.length == m_CurrentNewsFlashPos)
    {
        m_CurrentNewsFlashPos = 0;
    }
    m_CurrentNewsFlash.innerHTML = "<a href='"+m_NewsFlashArray[m_CurrentNewsFlashPos][1]+"' target='"+m_NewsFlashArray[m_CurrentNewsFlashPos][2]+"'>"+m_NewsFlashArray[m_CurrentNewsFlashPos][0]+"</a>";
    m_CurrentNewsFlashPos++;
    MoveNewsFlash();
}

function MoveNewsFlash()
{
    var topCurrent = parseInt(m_CurrentNewsFlash.style.top.replace("px",""));
    topCurrent--;
    if(topCurrent <= 4 && m_Scrolling == true)
    {
        window.setTimeout(SetupNewsFlash,m_ScrollerPause);
        m_Scrolling = false;
    }
    else if(topCurrent <= -50 && m_Scrolling == false)
    {
        topCurrent = 60;
        if(m_NewsFlashArray.length == m_CurrentNewsFlashPos)
        {
            m_CurrentNewsFlashPos = 0;
        }
        m_CurrentNewsFlash.innerHTML = "<a href='"+m_NewsFlashArray[m_CurrentNewsFlashPos][1]+"' target='"+m_NewsFlashArray[m_CurrentNewsFlashPos][2]+"'>"+m_NewsFlashArray[m_CurrentNewsFlashPos][0]+"</a>";
        m_CurrentNewsFlash.style.top = topCurrent;
        m_Scrolling = true;
        window.setTimeout(MoveNewsFlash,10);
    }
    else
    {
        m_CurrentNewsFlash.style.top = topCurrent;
        window.setTimeout(MoveNewsFlash,10);
    }
}

function ShowPopup(popupType)
{
    if(m_PopupDiv)
    {
        var oDiv = null;
        oDiv = document.getElementById(popupType+"Extra");
        if(oDiv)
        {        
            var contentDiv = 1;
            if(m_PopupDiv.childNodes.length > 3)
            {
                contentDiv = 3;
            }
            m_PopupDiv.childNodes[contentDiv].innerHTML = oDiv.innerHTML;
            
            if(!m_CoverDiv)
            {
                m_CoverDiv = document.createElement("DIV");
                m_CoverDiv.className = "PopupDivCoverStyle";
                document.body.appendChild(m_CoverDiv);
            }
            
            var scrollSize = GetScrollOffsetSize();
            
            m_CoverDiv.style.width = scrollSize[0];
            m_CoverDiv.style.height = scrollSize[1];
            
            m_CoverDiv.style.display = "block";
            
            if(popupType == "Emergency")
            {
                m_PopupDiv.style.width = 650;
                m_PopupDiv.style.height = 400;
                m_PopupDiv.className = "PopupDivStyleEmergency";
            }
            else
            {
                m_PopupDiv.style.width = 500;
                m_PopupDiv.style.height = 0;
                m_PopupDiv.className = "PopupDivStyle";
            }
            
            m_PopupDiv.style.display = "block";
            
            //Need to hide flash if it exists
            var oFlash = document.getElementById("DefaultFlashMovie");
            if(!oFlash)
            {
                oFlash = document.getElementById("TrackingMovie");
            }
            
            if(oFlash)
            {
                oFlash.style.visibility = "hidden";
//                m_PopupDiv.style.width = oFlash.width;
//                m_PopupDiv.style.height = oFlash.height;
            }
            
            //Now need to hide the drop downs on the page
            var oDropDowns = document.getElementsByTagName("SELECT");
            for(var a = 0; a <oDropDowns.length;a++)
            {
                oDropDowns[a].style.visibility = "hidden";
            }
            
            showdeadcenterdiv(m_PopupDiv.clientWidth,m_PopupDiv.clientHeight);
            
        }
        else
        {
            alert("Content not available for " + popupType + "!");
        }
        
    }
    else
    {
        alert("Popup not available for " + popupType + "!");
        return false;
    }
    
}

function showdeadcenterdiv(Xwidth,Yheight) { 
// First, determine how much the visitor has scrolled 

var scrolledX, scrolledY; 
if( self.pageYoffset ) { 
scrolledX = self.pageXoffset; 
scrolledY = self.pageYoffset; 
} else if( document.documentElement && document.documentElement.scrollTop ) { 
scrolledX = document.documentElement.scrollLeft; 
scrolledY = document.documentElement.scrollTop; 
} else if( document.body ) { 
scrolledX = document.body.scrollLeft; 
scrolledY = document.body.scrollTop; 
} 

// Next, determine the coordinates of the center of browser's window 

var centerX, centerY; 
if( self.innerHeight ) { 
centerX = self.innerWidth; 
centerY = self.innerHeight; 
} else if( document.documentElement && document.documentElement.clientHeight ) { 
centerX = document.documentElement.clientWidth; 
centerY = document.documentElement.clientHeight; 
} else if( document.body ) { 
centerX = document.body.clientWidth; 
centerY = document.body.clientHeight; 
} 

// Xwidth is the width of the div, Yheight is the height of the 
// div passed as arguments to the function: 
var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
var topoffset = scrolledY + (centerY - Yheight) / 2; 
// The initial width and height of the div can be set in the 
// style sheet with display:none; divid is passed as an argument to // the function 
var o=m_PopupDiv; 
var r=o.style;
if(topoffset < 0)
    topoffset = 0;
if( leftoffset < 0)
    leftoffset = 0; 
r.top = topoffset + 'px'; 
r.left = leftoffset + 'px'; 
}



function ClosePopup()
{
    //Need to hide flash if it exists
    var oFlash = document.getElementById("DefaultFlashMovie");
    if(!oFlash)
    {
        oFlash = document.getElementById("TrackingMovie");
    }
    if(oFlash)
    {
        oFlash.style.visibility = "visible";
    }
    if(m_PopupDiv)
    {
       m_PopupDiv.style.display = "none";
       m_CoverDiv.style.display = "none";
    }
    else
    {
        alert("Popup not available!");
        return false;
    }
    //Now need to display the drop downs on the page
    var oDropDowns = document.getElementsByTagName("SELECT");
    for(var a = 0; a <oDropDowns.length;a++)
    {
        oDropDowns[a].style.visibility = "visible";
    }
}

function GetInnerWindowSize()
{
    var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth,myHeight];

}

function GetScrollOffsetSize()
{
    var scrOfX = 0, scrOfY = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
      } else if( document.body && document.body.scrollLeft ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
      } else if( document.documentElement &&  document.documentElement.scrollLeft  ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
      return [ document.body.scrollWidth, document.body.scrollHeight ];

}

function StartWithScene2()
{
     var oFlash = document.embeds['DefaultFlashMovieEmbed'];
     if(!oFlash)
        oFlash = document.getElementById("DefaultFlashMovie");
     if(oFlash)
     {
            oFlash.StopPlay();
            oFlash.GotoFrame(1);
            oFlash.SetVariable("m_Scene2", "true");
            oFlash.Play(); 
     }
}

function DisplayOrHide(id,span)
{
    var oDiv = document.getElementById(id);
    if(oDiv)
    { 
        if(oDiv.style.display == 'none') 
        {
            oDiv.style.display = '';
            span.nextSibling.innerHTML = "&uarr;";
        } 
        else 
        {
            oDiv.style.display = 'none';
            span.nextSibling.innerHTML = "&darr;";
        }
    }
    return false;
}








