/***************************/
/*        COUNTDOWN        */
/***************************/

var _countDowncontainer=0;
var _currentSeconds=0;

function ActivateCountDown(strContainerID, initialValue) {
	
	_countDowncontainer = document.getElementById(strContainerID);
	
	if (!_countDowncontainer) {
		alert("count down error: container does not exist: "+strContainerID+
			"\nmake sure html element with this ID exists");
		return;
	}
	
	SetCountdownText(initialValue);
	CountDownTick();
	//window.setTimeout("CountDownTick()", 1000);
}

function CountDownTick() {
    //if(document.getElementById("preventMultipleTicks").value=="true")
    //{
      //  document.getElementById("preventMultipleTicks").value="false";
        //return;
    //}
	if (_currentSeconds <= 0) {
        var frmToSubmit = document.getElementById("aspnetForm");
	    frmToSubmit.submit();
		return;
	}
	
	SetCountdownText(_currentSeconds-1);
	window.setTimeout("CountDownTick()", 1000);
}

function SetCountdownText(seconds) {
	//store:
	_currentSeconds = seconds;
	
	//get minutes:
	var minutes=parseInt(seconds/60);
	
	//shrink:
	seconds = (seconds%60);
	
	//get hours:
	//var hours=parseInt(minutes/60);
	
	//shrink:
	minutes = (minutes%60);
	
	//build text:
	//var strText = AddZero(minutes) + ":" + AddZero(seconds);
	var strText = AddZero(minutes) + AddZero(seconds);

	//apply:
	//_countDowncontainer.innerHTML = strText;
	_countDowncontainer.innerHTML = //'<table>' +
	                                //'<tr>' +
	                                //'<td style="height: 45px; width:5px; padding: 0 0 0 0; margin: 0 0 0 0;">' +
	                                '<pre>' +
	                                '<img src="' + imagesDigits[strText.substring(0,1)].src + '" id="mn1" alt="">' +
	                                //'</td>' +
	                                //'<td style="height: 45px; width:5px; padding: 0 0 0 0; margin: 0 0 0 0;">' +
	                                '<img src="' + imagesDigits[strText.substring(1,2)].src + '" id="mn1" alt="">' +
	                                //'</td>' +
	                                //'<td style="height: 45px; width:5px; padding: 0 0 0 0;margin: 0 0 0 0;">' +
	                                '<img src="' + imageSeparator.src + '" id="s" alt="">' +
	                                //'</td>' +
	                                //'<td style="height: 45px; width:5px; padding: 0 0 0 0; margin: 0 0 0 0;">' +
	                                '<img src="' + imagesDigits[strText.substring(2,3)].src + '" id="mn1" alt="">' +
	                                //'</td>' +
	                                //'<td style="height: 45px; width:5px; padding: 0 0 0 0; margin: 0 0 0 0;">' +
	                                '<img src="' + imagesDigits[strText.substring(3,4)].src + '" id="mn1" alt="">' +
	                                '</pre>';
	                                //'</td>' +
	                                //'</tr>' +
	                                //'</table>';
}

function AddZero(num) {
	return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}

/***************************/
/*      FIM COUNTDOWN      */
/***************************/


/***************************/
/*        MODALBOX         */
/***************************/
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Steve Chipman | http://slayeroffice.com/ */

// constants to define the title of the alert and button text.
var ALERT_TITLE = "BilheteiraOnline";
var ALERT_BUTTON_TEXT = 'Prosseguir'+String.fromCharCode('160')+String.fromCharCode('187');

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
  window.alert = function(txt) {
    createCustomAlert(txt);
  }
}
function VerificarSeBrowserIE6()
{
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
    { //test for MSIE x.x;
        var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion<7)
            return true;
     }
     return false;
}
function ConfigurarModalContainer(mObj)
{
    mObj.style.height = document.documentElement.scrollHeight + "px";
    mObj.style.width = document.documentElement.scrollWidth + "px";
    //Excepções ie6
    if (VerificarSeBrowserIE6())
    {
        MostrarSelects(false);
        mObj.style.backgroundImage="url(/imagens/imagensDefault/internet/layout/Fundo_Prompt_IE6.gif)"; 
        mObj.style.backgroundColor ="transparent";
    } 
}
function ConfigurarAlertBox(alertObj)
{
    if (VerificarSeBrowserIE6())
    {
        alertObj.style.top = document.documentElement.scrollTop + "px";
        alertObj.style.position = 'absolute'; 
    }

    alertObj.style.left = (document.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
}
function MostrarSelects(mostrar)
{
    if (VerificarSeBrowserIE6())
    {
        var x = document.getElementsByTagName("select");

        for (i = 0; i < x.length; i++) 
        {
            if(mostrar)
                x[i].style.display = "";
            else
                x[i].style.display = "none";
        }
    }
}
function createCustomAlert(txt) {
  // shortcut reference to the document object
  d = document;

  // if the modalContainer object already exists in the DOM, bail out.
  if(d.getElementById("modalContainer")) return;

  // create the modalContainer div as a child of the BODY element
  
  mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
  mObj.id = "modalContainer";
  mObj.className = "modalContainer";
   // make sure its as tall as it needs to be to overlay all the content on the page

  // create the DIV that will be the alert 
  alertObj = mObj.appendChild(d.createElement("div"));
  alertObj.id = "alertBox";
  alertObj.className = "alertBox";


  // create an H1 element as the title bar
  h1 = alertObj.appendChild(d.createElement("h1"));
  h1.appendChild(d.createTextNode(ALERT_TITLE));

  // create a paragraph element to contain the txt argument
  msg = alertObj.appendChild(d.createElement("p"));
  msg.innerHTML = txt;

  tableObj= alertObj.appendChild(d.createElement("table"));
  tbodyObj = tableObj.appendChild(d.createElement("tbody"));
  trObj = tbodyObj.appendChild(d.createElement("tr"));
  tdObj = trObj.appendChild(d.createElement("td"));

  // create an anchor element to use as the confirmation button.
  btn = tdObj.appendChild(d.createElement("a"));
  btn.id = "closeBtn";
  btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
  btn.href = "#";
  btn.className="LinkBtnNormal";
  ConfigurarModalContainer(mObj);
  ConfigurarAlertBox(alertObj);
  // set up the onclick event to remove the alert when the anchor is clicked
  btn.onclick = function() { removeCustomAlert();return false; }
}


// removes the custom alert from the DOM
function removeCustomAlert()
{
    MostrarSelects(true);
    document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
    if(Boolean(typeof elementoParaFocusAposMensagem != 'undefined' && elementoParaFocusAposMensagem))
        elementoParaFocusAposMensagem.focus();
}

/***************************/
/*      FIM MODALBOX       */
/***************************/

/***************************/
/*     SCRIPTSGERAIS       */
/***************************/
function findPosX(obj)
{
    var curleft = 0;
    
    if(obj.offsetParent)
        while(1) 
        {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;

    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    
    if(obj.offsetParent)
        while(1)
        {
            curtop += obj.offsetTop;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    
    return curtop;
}



/***************************/
/*    FIM SCRIPTSGERAIS    */
/***************************/