function CreateFlash(divId, width, height, url)
{
	var d = document.getElementById(divId);
	d.innerHTML = '<embed pluginspage=http://www.macromedia.com/go/getflashplayer align=baseline src='+url+' width='+width+' height='+height+' type=application/x-shockwave-flash quality="high"></embed>';
}
function FormatCost(cost, currencySymbol, decimalPlaces)
{
    var iDecimalPlaces = parseInt(decimalPlaces);
    var multiplier = Math.pow(10, iDecimalPlaces);
    var fCost = parseFloat(cost);
    fCost = Math.round(fCost*multiplier) / (multiplier*1.0);
    var sCost = currencySymbol+fCost;
    var indexOfPoint = sCost.indexOf('.');
    var extraZeros;
    if (indexOfPoint == -1)
    {
        sCost += '.';
        extraZeros = decimalPlaces;
    }
    else
        extraZeros = indexOfPoint - (sCost.length-iDecimalPlaces-1);
    for (var i=0; i<extraZeros; i++)
        sCost += '0';
    return sCost;
}
function getWindowHeight()
{
    var windowHeight = 0;
    if (typeof(window.innerHeight) == 'number')
	    windowHeight = window.innerHeight;
	else
	{
	    if (document.documentElement && document.documentElement.clientHeight)
		    windowHeight = document.documentElement.clientHeight;
	    else if (document.body && document.body.clientHeight)
			windowHeight = document.body.clientHeight;
	}
    return windowHeight;
}
function getWindowWidth()
{
    var windowWidth = 0;
    if (typeof(window.innerWidth) == 'number')
	    windowWidth = window.innerWidth;
	else
	{
	    if (document.documentElement && document.documentElement.clientWidth)
		    windowWidth = document.documentElement.clientWidth;
	    else if (document.body && document.body.clientWidth)
			windowWidth = document.body.clientWidth;
	}
    return windowWidth;
}
function AttachScrollEvent(element, eventHandler)
{
    if (element.addEventListener)
        element.addEventListener("scroll", eventHandler, false);
    else if (element.attachEvent)
        element.attachEvent("onscroll", eventHandler);
    else
        element.onscroll = eventHandler;
}
function GetNextArrayIndex(array, curIndex)
{
    if (curIndex == array.length - 1)
        return 0;
    else
        return curIndex + 1;
}
function GetPrevArrayIndex(array, curIndex)
{
    if (curIndex == 0)
        return array.length - 1;
    else
        return curIndex - 1;
}
function GetPageScrollTop()
{
    return document.documentElement.scrollTop >= document.body.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
}
function GetPageScrollLeft()
{
    return document.documentElement.scrollLeft >= document.body.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
}

var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
  if (element != null)                              //the image fading out may have been removed from under us if JumpTo has been invoked
  {
      if(element.FadeTimeLeft <= elapsedTicks)
      {
        element.style.opacity = element.FadeState == 1 ? '1' : '0';
        element.style.filter = 'alpha(opacity = ' 
            + (element.FadeState == 1 ? '100' : '0') + ')';
        element.FadeState = element.FadeState == 1 ? 2 : -2;
        return;
      }
     
      element.FadeTimeLeft -= elapsedTicks;
      var newOpVal = element.FadeTimeLeft/TimeToFade;
      if(element.FadeState == 1)
        newOpVal = 1 - newOpVal;

      element.style.opacity = newOpVal;
      element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
      
      setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
  }
}

//preload
var pic1 = new Image();
pic1.src = "AdminImages/LoadingMessageBackground.png";
var pic2 = new Image();
pic1.src = "AdminImages/Loading.gif";

function doLoadingPanel(loadingPanelMessage) {
    var contentDiv = document.getElementById('divContent');
    var div = document.createElement("div");
    div.style.position = "absolute";
    div.style.top = "0px";
    div.style.left = "0px";
    div.style.bottom = "0px";
    div.style.right = "0px";
    div.style.backgroundImage = "url(AdminImages/LoadingMessageBackground.png)";
    div.style.zIndex = "2000";
    div.innerHTML = "<table align='center' style='margin-top: " + (getWindowHeight() / 2) + "px'><tr><td style='background-color: #ffffff; text-align: center'><img src='AdminImages/Loading.gif' /></td><td style='font-size: 16px; font-weight:bold; background-color: #ffffff'>" + loadingPanelMessage + "</td></tr></table>";
    document.body.appendChild(div);
}
