
function changeDay(id){
	var weekDays = new Array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
	var obj;
	for(i in weekDays)
	{
		obj = getObject(weekDays[i]);
		if(obj!=null)
			obj.style.display = 'none';
	}
	obj = getObject(id);
	if(obj!=null)
		obj.style.display = '';
	changeMenuDay(id);
}

function changeMenuDay(id){
	var weekDays = new Array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
	var obj;
	for(i in weekDays)
	{
		obj = getObject(weekDays[i]+'MenuOn');
		if(obj!=null)
			obj.style.display = 'none';
		obj = getObject(weekDays[i]+'MenuOff');
		if(obj!=null)
			obj.style.display = '';
	}
	obj = getObject(id+'MenuOn');
	if(obj!=null)
		obj.style.display = '';
	obj = getObject(id+'MenuOff');
	if(obj!=null)
		obj.style.display = 'none';
}

function printWindow() {if (document.all||document.getElementById) {window.print();}} //display print dialog

//get browser info in order to detect if the browser supports filters and if the browser is IE 5.0 (if 5.0 requires the hiding of select boxes)
function csBrowserInfo()
{
	var csUserAgent = String(navigator.userAgent);
	if (!document.getElementById) return -1;
	else if(csUserAgent.indexOf("MSIE 5") > -1) return 0;
	else if(csUserAgent.indexOf("Opera") > -1) return 1;
	else if(csUserAgent.indexOf("MSIE 6") > -1) return 2;
	else if(csUserAgent.indexOf("Netscape6") > -1) return 3;
	else if(csUserAgent.indexOf("Netscape") > -1) return 4;
	else if(csUserAgent.indexOf("Firefox") > -1) return 5;
	else return 1;
}

//hide selects for ie 5.0 since the iframe hack does not work
function hideSelects(action) {
	var numberForms = document.forms.length;
	for (formIndex = 0; formIndex < numberForms; formIndex++)
	{
	   var numberElems; numberElems = document.forms[formIndex].elements.length
	   for (formElemIndex = 0; formElemIndex < numberElems; formElemIndex++)
		{
		   if (document.forms[formIndex].elements[formElemIndex].tagName=='SELECT') {
			document.forms[formIndex].elements[formElemIndex].style.visibility=action;
		   }
		}
	}
}

//função para simular submit de botões da aplicação - retirar após lançamento
function doSubmit(url) {
	document.forms[0].action=url;document.forms[0].method="get";document.forms[0].submit();
}
//função geral de mesagens - apagar esta função após lançamento
function message(type){
	if (type==0){alert("Não Disponível");}
	else if (type==1){alert("Funcionalidade de Ordenar\nLista pela coluna\nseleccionada");}
}
//função geral que retorna referência a um objecto por id
function getObject(id) {
	if (document.all){return(document.all(id))}
	if (document.getElementById){return(document.getElementById(id))}
}

//this function writes an iframe used to hide form elements that would otherwise show up through a html layer
var iframe; //reference to the frame object
var browser = String(navigator.userAgent);
//writeFrame(); //write the frame to the browser			//PJCLARO 20060322 Prevents Javascript error on Posting create
function writeFrame() {
	if (iframe!=true) {
		//alert(browser+csBrowserInfo())
		if (csBrowserInfo()!=1 && csBrowserInfo()!=0) {
		document.write("<iframe id=\"iframe\" style=\"display: none; width:0px; height:0px; left:0px; position:absolute; top: 0px; z-index:1000;\" src=\"javascript:false;\" frameBorder=\"1\" scrolling=\"no\"></iframe>")
		iframe = document.getElementById("iframe");
		}
	}
}

// retornam a posição de um objecto no ecrã

function getRealTop(obj){var curtop = 0;if (obj.offsetParent) {while (obj.offsetParent){curtop += obj.offsetTop;obj = obj.offsetParent;}} else if (obj.y) curtop += obj.y; return curtop;}
function getRealLeft(xobj){var curleft = 0;if (xobj.offsetParent) {while (xobj.offsetParent){curleft += xobj.offsetLeft;xobj = xobj.offsetParent;}} else if (xobj.x) curleft += xobj.x; return curleft;}
function getHeight(objID) {return objID.offsetHeight}
function getWidth(objID) {return objID.offsetWidth}

//capture mouse position for quick help functionality
var xpos, ypos;
if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=getMouseCoordinates;

function getMouseCoordinates(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {xpos = e.pageX;ypos = e.pageY;}
	else if (e.clientX || e.clientY){xpos = e.clientX + document.body.scrollLeft;ypos = e.clientY + document.body.scrollTop;}
	// xpos and ypos contain the mouse position relative to the document
}

// buscar altura de scroll da página
function getScrollY() {
  scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {scrOfY = window.pageYOffset;} //Netscape compliant
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {scrOfY = document.body.scrollTop;}//DOM compliant
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {scrOfY = document.documentElement.scrollTop;}//IE6 standards compliant mode
  return(scrOfY);
}

// buscar tamanho da janela de browser
function windowSize(type) {
	var wWidth, wHeight;
	if( typeof( window.innerWidth ) == 'number' ) {wWidth = window.innerWidth;wHeight = window.innerHeight;}//Non-IE
  	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {wWidth = document.documentElement.clientWidth;wHeight = document.documentElement.clientHeight;}//IE 6+ in 'standards compliant mode'
  	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {wWidth = document.body.clientWidth;wHeight = document.body.clientHeight;}//IE 4 compatible
	if(type=="w"){return(wWidth);}else{return(wHeight);}
}

function screenWidth(){
	return(screen.width);
}

// pop-up windows
function popUpWindow(URLStr, windowSettings) 
{
	var popUpWin;
	var width = 865;
	if (windowSettings=='virtualtour') {
		if (screenWidth()<801) {width=600}
		windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height=465,top=100,left=100,screenX=100,screenY=100';
		if (URLStr=='') {URLStr = "virtualtour.aspx";}
	} else {
		windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=540,height=390,top=100,left=100,screenX=100,screenY=100';
	}
	if(popUpWin) {if(!popUpWin.closed) popUpWin.close();}popUpWin = open(URLStr, 'popUpWin', windowSettings);
}

//generic pop window funtion that accepts window settings and url parameters
//if no window settings defaults to set small pop-up window
function popUpWindowFlash(URLStr, windowSettings) {
var popUpWin;
if (windowSettings=='flash'){windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=550,height=310,top=100,left=100,screenX=100,screenY=100'}
if(popUpWin) {if(!popUpWin.closed) popUpWin.close();}popUpWin = open(URLStr, 'popUpWin', windowSettings);
}

//show/hide highlites
var timer;
var iframetimer;
var toHide;
var yOffset = 3;
var xOffset = -1;
function showHighlite(id) {

	var sender = getObject("Highlights_"+id+"_img");
	var layer = getObject(id+"_highlite");
	
	var top = getRealTop(sender)-getHeight(layer)+yOffset+"px";
	var left = getRealLeft(sender)+xOffset+"px";
	
	if(timer){clearTimeout(timer);} // clear timers
	if ((layer.style.top=="-2000px")||(layer.style.top=="")) {
		if(iframetimer){clearTimeout(iframetimer);} // clear timers
		hideHighliteNow() //hide any visible layer
		if (csBrowserInfo()==0) {hideSelects('hidden');} //hide selects on page for ie5/5.5
		if (csBrowserInfo()==2) {//if i.e 6 then place layer transition effects
			layer.style.display='none';
			layer.style.top = top;
			layer.style.left = left;
			layer.style.filter = "progid:DXImageTransform.Microsoft.RevealTrans(transition=4, duration=0.2)";layer.filters.item(0).enabled=1;layer.filters.item(0).apply(); //apply the filter only if this is the first time the meun is shown
			layer.style.display='block';
			layer.filters.item(0).play();
			iframetimer = setTimeout("placeIframe('"+id+"')",200);
		} else if (csBrowserInfo()==3) {
			layer.style.display='none';
			layer.style.top = top;
			layer.style.left = left;
			layer.style.display='block';
		} else {
			layer.style.top = top;
			layer.style.left = left;
			placeIframe(id)
		}
		toHide=layer; //set the layer to hide as the layer that was shown
	}
}
function hideHighlite() {timer = setTimeout("hideHighliteNow()",500)}
function hideHighliteNow() {
	if(toHide){
		if (iframe) {iframe.style.top = '0px';iframe.style.left = '0px';iframe.style.width = '0px';iframe.style.height = '0px';iframe.style.display = 'none';}
		toHide.style.top="-2000px";toHide.style.left="-2000px";
		if (csBrowserInfo()==0) {hideSelects('visible');}
		toHide = null;
	}
}
function placeIframe(id) {
	var layer = getObject(id+"_highlite");
	if (iframe) {iframe.style.top=getRealTop(layer)+3+"px";iframe.style.left=layer.style.left;iframe.style.width=getWidth(layer);iframe.style.height=getHeight(layer)-3+"px";iframe.style.display='';layer.style.zIndex=2000;}
}

// mostrar tool tip
function showTip(id){
	var obj = getObject(id); var left; var top;
	if((xpos+4+125)>windowSize("w")) {left = xpos-100-15;} else {left = xpos+4;} //correct for tool tips going off screen
//PJC20060411	if( typeof( window.innerWidth ) == 'number' ){top=ypos+12;} else {top=getScrollY()+ypos+12;} //if non ie no need to allow for scroll
	top=ypos+12;
	if (obj) {obj.style.left=left+'px';obj.style.top=top+'px';if (obj.style.display!='block'){obj.style.display='block';}}
}
function hideTip(id) {
	if (iframe) {iframe.style.top = '0px';iframe.style.left = '0px';iframe.style.width = '0px';iframe.style.height = '0px';iframe.style.display = 'none';}
	getObject(id).style.display="none";
}

function zoomIn() {
	var mapIn = getObject('In_Image'); var mapOut = getObject('Out_Image'); var mapDefault = getObject('Default_Image');
	if ((mapDefault.style.display=='block')||(mapDefault.style.display=='')) {
		mapOut.style.display='none';mapDefault.style.display='none';mapIn.style.display='block';
	} else if (mapOut.style.display=='block') {
		mapIn.style.display='none';mapOut.style.display='none';mapDefault.style.display='block';
	}
}

function zoomOut() {
	var mapIn = getObject('In_Image'); var mapOut = getObject('Out_Image'); var mapDefault = getObject('Default_Image');
	if ((mapDefault.style.display=='block')||(mapDefault.style.display=='')) {
		mapDefault.style.display='none';mapIn.style.display='none';mapOut.style.display='block';
	} else if (mapIn.style.display=='block') {
		mapIn.style.display='none';mapOut.style.display='none';mapDefault.style.display='block';
	}
}

function doVirtualTour(id) {
	var combo = getObject(id);
	var URL = "clubs/" + combo[combo.selectedIndex].value + "/virtualtour.aspx";
	popUpWindow(URL, "virtualtour");
}

function doInscricao(id) {
	var combo = getObject(id);
	var URL = "clubs/" + combo[combo.selectedIndex].value + "/inscricao.aspx";
	window.location=URL;
}

function onClubCheck(){
	var clientCheck = document.getElementById('UCLoader1_uc_trainingacademy_form_socio')
	var clubSelect = document.getElementById('UCLoader1_uc_trainingacademy_form_clubSelect')

	if(clubSelect!=null && clientCheck!=null)
	{
		if(clientCheck.checked)
		{
			clubSelect.disabled = false;
		}
		else
		{
			clubSelect.selectedIndex = 0;
			clubSelect.disabled = true;
		}
	}
}

function input_onkeypress(ev)
{
    var evt = ev ? ev : window.event;
    var elem, key, kchar;
    if (evt) 
    {
		elem = evt.target ? evt.target : evt.srcElement;
		key = evt.keyCode ? evt.keyCode : evt.which;
		kchar =(typeof evt.charCode != "undefined") ? evt.charCode : evt.keyCode;
	}

	if ( void 0==elem ) return true;

	var accepted = true;
	
	accepted = acceptOnlyNumbers(evt, elem, kchar, false);
	
	return accepted;
}


function replaceKey(evt,elem,kchar)
{
	if (evt.preventDefault)
	{
		evt.preventDefault();
		triggerKeyEvent (elem, "keypress", kchar, true, false, false, false, false );
	}
	else
	{
		// IE
		evt.keyCode = kchar;
	}
}

function cancelKey(evt)
{
	if (evt.preventDefault)
	{
		// W3C DOM
		evt.preventDefault();
		evt.stopPropagation();
	}
	else
	{
		// IE
		evt.keyCode = 0;
		evt.returnValue = false;
	}
}

function acceptOnlyNumbers (evt, elem, kchar, allowDecimalPoint)
{
	var ret = false;
	
	if ( kchar==0 ) 
	{
		//FF 
		ret = true;
	}
	else if ( kchar==Keys.TAB || kchar==Keys.ESC || kchar==Keys.BACKSPACE || kchar>63000 )
	{
		//Safari TAB,Shift+TAB,backspace,delete
		ret = true;
	}
	else if ( kchar==Keys.Enter ) ret=true;
	else if ( kchar>=Keys.n0 && kchar<= Keys.n9 ) ret=true;
	else if ( kchar==46 || kchar==44 )
	{
		if ( elem.value.indexOf(",") < 0 )	// Only allows one ','
		{
			ret = true;
			if (kchar == 46)
			{
				// replace '.'=46 with ','=44
				replaceKey(evt, elem, 44);
			}
		}
	}
		
	if (!ret)
	{
		cancelKey(evt);
	}
		
	return ret;
}

var Keys =
{
   BACKSPACE : 8, TAB : 9, 
   NUMPADCLEAR : 12, ENTER : 13, 
   SHIFT : 16, CTRL : 17, ALT : 18, PAUSE : 19, CAPS : 20, 
   ESC : 27, 
   SPACEBAR : 32, PAGEUP : 33, PAGEDN : 34, END : 35, HOME : 36, LEFT : 37, UP : 38, RIGHT : 39, DOWN : 40, 
   PRTSC : 44, INSERT : 45, DELETE : 46,
   n0 : 48, n1 : 49, n2 : 50, n3 : 51, n4 : 52, n5 : 53, n6 : 54, n7 : 55, n8 : 56, n9 : 57,
   SEMICOLON : 59,
   A : 65, B : 66, C : 67, D : 68, E : 68, F : 70, G : 71, H : 72, I : 73, J : 74, K : 75,
   L : 76, M : 77, N : 78, O : 79, P : 80, Q : 81, R : 82, S : 83, T : 84, U : 85, V : 86,
   W : 87, X : 88, Y : 89, Z : 90,
   WINLEFT : 91, WINRIGHT : 92, SELECT : 93, 
   NUM0 : 96, NUM1 : 97, NUM2 : 98, NUM3 : 99, NUM4 : 100, NUM5 : 101, 
   NUM6 : 102, NUM7 : 103, NUM8 : 104, NUM9 : 105, MULTIPLY : 106, ADD : 107, 
   SUBTRACT : 109, DECIMAL : 110, DIVIDE : 111, 
   F1 : 112, F2 : 113, F3 : 114, F4 : 115, F5 : 116, F6 : 117, F7 : 118, F8 : 119, F9 : 120, F10 : 121, F11 : 122, F12 : 123, 
   NUMLOCK : 144, SCROLLLOCK : 145,
   SEMICOLON : 186, EQUAL : 187, COMMA : 188, DASH : 189, PERIOD : 190, FORWARDSLASH : 191, GRAVEACCENT : 192,
   OPENBRACKET : 219, BACKSLASH : 220, CLOSEBRACKET : 221, QUOTE : 222
};

function popUpWindowImg(URLStr, position){
	var popUpWin;	
	if (position=="H"){
		width=640;
		height=480;
	}
	if (position=="V"){
		width=480;
		height=640;
	}
	windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',top=100,left=100,screenX=100,screenY=100';	
	if(popUpWin) {if(!popUpWin.closed) popUpWin.close();}popUpWin = open(URLStr, 'popUpWin', windowSettings);
}