﻿// JScript File
var timeLeft = 3;
var timerID = 0;
var contextTimerID = 0;
var contextTimeLeft = 3;
var fResponse = 0;
var debug = 0;
function Glow(obj, css)
{
    obj.className=css;    
}

function dbg(output)
{
//alert(output);
    if (debug)
    {
        var dbg = document.getElementById('pnlDebug');
        if (dbg)
        {
            dbg.innerHTML +=output + '<br />';            
        }        
    }    
    //alert(output);
}

function BodyClick()
{
    dbg('bodyclick');
    fResponse = 1;
}

function UseTimer(timeLimit)
{
    dbg('userTimer:' + timeLimit);
    timeLeft = timeLimit + 1;
    UpdateTimeDisplay();
    timerID = setTimeout("UpdateTimer()", 1000);
}

function UseContextTimer(contextTimeLimit)
{
    if (contextTimeLimit > 0)
    {
        dbg('contextTimer:' + contextTimeLimit);
        contextTimeLeft = contextTimeLimit + 1;

        showContextOverlay();
        contextTimerID = setTimeout("OnContextTimer()", contextTimeLimit);
    }
}

function OnContextTimer() {

   if(contextTimerID)
   {
        clearTimeout(contextTimerID);
   }      
    battleStart();
}



function showContextOverlay()
{      
    dbg('showContextOverlay');
    var objOverlay= document.getElementById(CONTEXTADID);        
    if (objOverlay != null)
    {
        objOverlay.className = 'pnlContextAdVisible';    
    }

    var blinkControls = document.getElementById(BLINKITEMSID);    
    if (blinkControls != null)
    {
        blinkControls.className = 'pnlBlinkItemsHidden';        
    }
}

function hideContextOverlay()
{      
    dbg('hideContextOverlay');
   
    var objOverlay= document.getElementById(CONTEXTADID);    
    if (objOverlay != null)
    {
       objOverlay.className = 'pnlContextAdHidden';    
    }
    
    var blinkControls = document.getElementById(BLINKITEMSID );    
    if (blinkControls != null)
    {    
        blinkControls.className = 'pnlBlinkItemsVisible';
    }
}


function UpdateTimer() {
    UpdateTimeDisplay();

   if(timerID)
   {
        clearTimeout(timerID);
   }
   
   if (timeLeft > 0)
   {   
        timerID = setTimeout("UpdateTimer()", 1000);
   }
   else
   {        
        if (fResponse == 0)
        {
            showPartialOverlay();
        }
   }
}

function UpdateTimeDisplay()
{
    dbg('UpdateTimeDisplay:' + timeLeft);
    var timeDisplay = document.getElementById("timeDisplay")
    dbg(timeDisplay.innerHTML);
    timeLeft--;

    var timerMsg = timeLeft + '&nbsp;second';
    if (timeLeft != 1) timerMsg +='s';
    timerMsg +='&nbsp;left';
    
    if (timeLeft == 0) timerMsg = '&nbsp;';    
    timeDisplay.innerHTML = timerMsg ;
}

function ClearTimeDisplay()
{

   if(timerID)
   {        
        clearTimeout(timerID);
   }

    dbg('ClearTimeDisplay:' + timeLeft);
    var timeDisplay = document.getElementById("timeDisplay")    
    timeDisplay.innerHTML = '&nbsp;';
}



function showPartialOverlay()
{      
    var blinkControls = document.getElementById(BLINKITEMSID);    
    var docW = blinkControls.offsetWidth;
    var docH = blinkControls.offsetHeight;
   
    var objOverlay= document.getElementById("BlinkOverlay");    
    objOverlay.style.height=docH + 'px';
    objOverlay.style.width=docW + 'px';
    if (blinkControls != null)
    {
        blinkControls.className = 'pnlBlinkItemsHidden';
        objOverlay.style.display = 'block';    
    }
}

function AcknowledgeExpiration()
{
    window.location.reload();    
}


function ReturnFromModal(vote, priority)
{
    var o = new Object();
    o.Priority =  priority;   
    o.Vote = vote;
    window.returnValue = o;
    window.close();
}


function ReturnFromVoting()
{
    ReturnFromModal (1,1)
}


function ShowSurvey(itemGUID, votepage)
{    

    var features = "status:no; scroll:yes; edge:raised; resizable:yes; help:no; center:yes; dialogWidth:820px; dialogHeight:600px;";
    //features = "status:yes; scroll:yes; edge:raised; resizable:yes; help:yes; center:yes; dialogWidth:680px; dialogHeight:412px;";

    var urlString = votepage + ".aspx?GUID=" + itemGUID;

	var objWin = null;
	if(window.showModalDialog)
	{
	    showFullPageOverlay();
	    objWin = window.showModalDialog(urlString, "", features);        
        hideOverlay();
	}
	else
	{
		objWin = window.open(urlString,"","width=680px,height=412px;status:no;help:no;");
		window.onfocus = function() {
			if(objWin && !objWin.closed)
				objWin.focus();
		}
	}
}


function SetWindowSize()
{	
	if (window.sizeToContent)
	{
		window.resizeTo( window.outerWidth, window.outerHeight );
		window.sizeToContent();	 
	}else
	{		
		window.dialogHeight=window.document.body.offsetHeight + 20 + 'px';
    }
    window.status='';
}




	function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function showFullPageOverlay()
{    
    var arrayPageSize = getPageSize();
    var overlay = document.getElementById("overlay")
    var pageHeight=0;
    if (self.pageYOffset) 
    {
        // alert("self.pageYOffset=" + self.pageYOffset);
        pageHeight = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
        //alert("document.documentElement.scrollTop=" + document.documentElement.scrollTop);
        pageHeight = document.documentElement.scrollTop;
    } 
    else if (document.body) 
    {
        //alert("document.body.scrollTop=" + document.body.scrollTop);
        pageHeight = document.body.scrollTop;
    }    
   // alert(document.body.clientHeight);
    overlay.style.top = pageHeight + 'px';
    overlay.style.height='1600px';
    overlay.style.display = 'block';    

}
function hideOverlay()
{    
    document.getElementById("overlay").style.display = 'none';
}





var lastTabName="";
var lastTabIndex=-1;

function ShowTab(tabName, tabIndex, tabMax)
{	

    tabName = "ctl00_CPH1_" + tabName;
   
	if (tabName != lastTabName)
	{
		document.getElementById(tabName + '_FIGR').style.display="";		
		document.getElementById(tabName + '_TabCell').className="tabForeground";

		if (lastTabName.length > 0)
		{
			document.getElementById(lastTabName + '_FIGR').style.display="none";	
			document.getElementById(lastTabName + '_TabCell').className="tabBackground";
		}

		lastTabName = tabName;			
		lastTabIndex=tabIndex;		
	}
}
