//show and hide inline pop-up windows
function Point(x,y) {  this.x = x; this.y = y; }
mouseLocation = new Point(-500,-500);
function getMouseLoc(e)
{
  if(!document.all)  //NS
  {
    mouseLocation.x = e.pageX;
    mouseLocation.y = e.pageY;
  }
  else               //IE
  {
    mouseLocation.x = event.x + document.body.scrollLeft;
    mouseLocation.y = event.y + document.body.scrollTop;
  }
  return true;
}
//NS init:
if(document.layers){ document.captureEvents(Event.MOUSEMOVE); document.onMouseMove = getMouseLoc; }

function showPopUpLayer(a)
{
  if (document.layers) getMouseLoc;     //NS
  else if (document.all) getMouseLoc(); //IE
  if (document.all) {
	clearTimeout(timerPopUpLayer)
	if (document.all(activeLayer).style.visibility=='visible') {document.all(activeLayer).style.visibility='hidden';}
	document.all(a).style.left=''+(mouseLocation.x+10)+'px';
	document.all(a).style.top=''+(mouseLocation.y+10)+'px';
	document.all(a).style.visibility='visible';
  } else if (document.getElementById) {
	clearTimeout(timerPopUpLayer)
	if (document.getElementById(activeLayer).style.visibility=='visible') {document.getElementById(activeLayer).style.visibility='hidden';}
	document.getElementById(a).style.left=''+(mouseLocation.x+10)+'px';
	document.getElementById(a).style.top=''+(mouseLocation.y+10)+'px';
	document.getElementById(a).style.visibility='visible';
  }
}
var timerPopUpLayer;
var activeLayer;
function hidePopUpLayer(a) {
	activeLayer = a;
	timerPopUpLayer = setTimeout("hideLayer()",50);
}
function hideLayer() {
	document.all(activeLayer).style.visibility='hidden';
}

//populate multicanal textbox
function populateMCTextBox(a,b) {
	if (document.all) {
		if (document.all(a).value.length < 8) {
		document.all(a).value=document.all(a).value+b;
		} else {
		alert("Apenas pode indicar 8 digitos numericos\ncomo Chave Multicanal")
		}
	} else if (document.getElementById)  {
		document.getElementById(a).value=document.getElementById(a).value+b;
	}
}

//populate multicanal textbox
function populatePassTextBox(a,b) {
	if (document.all) {
		if (document.all(a).value.length < 3 ) {
		document.all(a).value=document.all(a).value+b;
		} else {
		alert("Apenas pode indicar os 3 digitos \nalfnumericos como requesitados")
		}
	} else if (document.getElementById)  {
		document.getElementById(a).value=document.getElementById(a).value+b;
	}
}

//places the focus on a designated form element
//handles attempts to enter the password box when numeric and letter pad is present
function reFocus(a) {
if (document.all) {document.all(a).focus();} else if (document.getElementByID) {document.getElementByID(a).focus();}
}

//fires the printer dialog window
function printPage(){
   browserVersion = parseInt(navigator.appVersion)
   if (browserVersion >= 4) {
   window.print()
   }
}

//preload images that will be used application wide
// Example:
// Preload( '01.gif', '02.gif' ); 
function Preload()
{ 
  var args = Preload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}
//used to swap images when necessary
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

Preload( '/ca/images/menuServ/seguros_on.gif','/ca/images/menuServ/poupar_on.gif','/ca/images/menuServ/contas_on.gif','/ca/images/menuServ/cartoes_on.gif','/ca/images/menuServ/credito_on.gif'); 

// preload application buttons (normal off state and over state)
// eg Preload('images/button_back_large.gif','images/button_back_large_over.gif');


//changes application buttons to over and off again
//a = button name or id
//b = type of button (there are three widths: small, medium, large)
function changeButtonOver(a,b)
{
	if (b=='small')	{if (ie4) {document.all(a).className='buttonsmallover'} else {document.getElementById(a).className='buttonsmallover'}}
	if (b=='medium') {if (ie4) {document.all(a).className='buttonmediumover'} else {document.getElementById(a).className='buttonmediumover'}}
	if (b=='large') 	{if (ie4) {document.all(a).className='buttonlargeover';} else {document.getElementById(a).className='buttonolargeover'}}
}
function changeButtonOff(a,b)
{
	if (b=='small')	{if (ie4) {document.all(a).className='buttonsmall'} else {document.getElementById(a).className='buttonsmall'}}
	if (b=='medium') {if (ie4) {document.all(a).className='buttonmedium'} else {document.getElementById(a).className='buttonmedium'}}
	if (b=='large') 	{if (ie4) {document.all(a).className='buttonlarge';} else {document.getElementById(a).className='buttonlarge'}}
}

//functions to change element styles on the fly
//change class of element on focus
function changeOnFocus(a,b) {
	if (document.all) {
		document.all(a).className=b;
	} else if (document.getElementById)  {
		document.getElementById(a).className=b;
	}
}

//change class of element on blur
function changeOnBlur(a,b) {
	if (document.all) {
		document.all(a).className=b;
	} else if (document.getElementById)  {
		document.getElementById(a).className=b;
	}
}


//show help section
function showQuickHelp(a) {
	if (document.all) {
		if (document.all(a).style.display=='') {document.all(a).style.display='none';} else {document.all(a).style.display='';}
	} else if (document.getElementById)  {
		if (document.getElementById(a).style.display=='') {document.getElementById(a).style.display='none';} else {document.getElementById(a).style.display='';}
	}
}


// relógio e cronometro
var date = new Date();
var segundos = date.getSeconds();
var minutos = date.getMinutes();
var hora = date.getHours();
var min;
var sec;
function processTimer()
{
	//prepare output format
	sec = segundos;
	min = minutos;
	hor = hora;
	if (hora<10) {hor="0"+hor}
	if (segundos<10) {sec="0"+segundos}
	if (minutos<10) {min="0"+minutos}
	//render timer value
	if (document.all) {
		if (document.all('hora')) {
		document.all('hora').innerHTML=hor+":"+min+":"+sec+"";
		}
	} else if (document.getElementById) {
		if (document.getElementById('hora')) {
		document.getElementById('hora').innerHTML=hor+":"+min+":"+sec+"";
		}
	}
	//next second
	if (segundos==60) {
	minutos++;
	segundos = 0
	}
	if (minutos==60) {
	hora++;
	minutos = 0;
	}
	if (hora==24) {
	hora = 0;
	}
	segundos++
}
setInterval('processTimer()',1000);
	
	
	function loginclean()
	{
		document._ctl0_numAdesao.value='';
		document._ctl0_chaveMC.value='';
	}


	function showCalendar (calid, mode)
	{
		var divname;
		
		if (calid==1) divname = "startcalendarDiv";
		else divname = "endcalendarDiv";
		
		startcalendarDiv
		if (mode)
		{
			if (document.all) 
			{
				document.all(divname).style.visibility='visible';
				//document.all('_ctl1_showcalendar').value='dateField';
			} 
			else 
			{
				if (document.getElementById) 
				{
					document.getElementById(divname).style.visibility='visible';
					//document.getElementById('_ctl1_showcalendar').value='dateField';
				}
			}
		}
		else
		{
/*			
			if (document.all) 
			{
				document.all(divname).style.visibility='hidden';
				//document.all('_ctl1_showcalendar').value='dateField';
			} 
			else 
			{
				if (document.getElementById) 
				{
					document.getElementById(divname).style.visibility='hidden';
					//document.getElementById('_ctl1_showcalendar').value='dateField';
				}
			}
*/
		}
	}


function populatePassTextBox2(a,b) {
	if (document.all) {
		if (document.all(a).value.length < 3 ) {
		document.all(a).value=document.all(a).value+b;
		} else {
		alert("Apenas pode indicar os 3 digitos \nalfnumericos como requesitados")
		}
	} else if (document.getElementById)  {
		document.getElementById(a).value=document.getElementById(a).value+b;
	}
}

function matchelement( k )
{
	var i, n, c;
	
	for (i=0; i<=document.forms(0).elements.length; i ++)
	{
		try
		{
			n = document.forms(0).elements(i).name;
			if (n.length >= k.length )
			{
				c = n.substr ( n.length - k.length, k.length );
				if ( c == k ) return document.forms(0).elements(i);
				
			}
		}
		catch (e) {}
	}
	
	return "undefined";
}

function populatePassTextBox(a,b) 
{
	var e = matchelement (a);
	
	if (e != "undefined" )
	{
		if ( e.value.length < 3 ) 
		{
			e.value=e.value+b;
		} 
		else 
		{
			alert("So pode indicar \nos tres digitos indicados")
		}
	}
}

// SwapButton is called from the WebMenu OnShow and OnHide events
// state is true for selected or false unselected and id is the WM.Group ID property
function SwapButton(id, state)
{
	//if(state)
	//	eval("document." + id + "_image.src='images/menuServ/" + id + "_on.gif'");
	//else
	//	eval("document." + id + "_image.src='images/menuServ/" + id + "_off.gif'");
}

	var popUpWin=0;
	function safeOpenWindow(URLStr)
	{
		var height;
		var width;
		var left ='';
		var top = '';
		var centermode = 1;
		
		height = 600;
		width  = 1100;
		
		if ( screen.availHeight < height ) 
		{
			centermode = 0;
			height = screen.availHeight - 30;
		}	
		if ( screen.availWidth < width ) 
		{
			centermode = 0;
			width = screen.availWidth - 10;
		}	

		if ( !centermode )
		{
			left = 0;
			top = 0;
		}
		else
		{
			left = (screen.availWidth-10 - width) / 2;
			top = (screen.availHeight-20 - height) / 2;
		}
		
		if(popUpWin)
		{
			//if(!popUpWin.closed) popUpWin.close();
		}
		popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

	}	
	function alertUnescape(sMsg)
	{
		var s = unescape(sMsg);
		
		alert(s);
		
	}

	function submitToCA(submitType)
	{
		//if ( popUpWin == 0 )
		//{
			//safeOpenWindow("");
			//if ( popUpWin != 0 )
			//{

				if(document.Form1.ad.value.length != 8)
				{
					alertUnescape("N%FAmero de ades%E3o inv%E1lido");
					return;
				}
				if( submitType == "1")
				{
					document.subform.ad.value = document.Form1.ad.value;
					document.subform.submit();
				}
				if( submitType == "2")
				{
					document.subform1.ad.value = document.Form1.ad.value;
					document.subform1.submit();
				}
					
			//}
		//}
	}	
	
	function startLogin(URLStr, obj)
	{
		n_adesao = document.getElementById(obj);
		if ( n_adesao.value != null && n_adesao.value != "" )
		{
			url = URLStr + '?nadesao='+ n_adesao.value;
		}
		else
		{
			url = URLStr;
		}
		safeOpenWindow(url);
	}

	function positiveIntInputOnly(e) { // KEYPRESS event 
	// returns true if 0-9 or BS hit, or can't get key value; otherwise false 

		var k = -1; 

		if (e && e.which) k = e.which; // NS 
		else if (window.event && window.event.keyCode) k = window.event.keyCode; // IE 

		return (k > -1 ? ((k > 47 && k < 58) || k == 8) : true); 

	}
	
//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["ulMainMenu"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
		}
		else{ //else if this is a sub level menu (ul)
			ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
			ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
		}
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.visibility="visible"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)