/*
		url - The URL of the page to open. Example: "http://scriptasylum.com". 
		w - The width of the window in pixels. 
		h - The height of the window in pixels (doesn't include menubars). 
		tb - Toolbar visible? 1 = yes, 0 = no. 
		stb - Status bar visible? 1 = yes, 0 = no. 
		L - Linkbar visible? 1 = yes, 0 = no. 
		mb - Menubar visible? 1 = yes, 0 = no. 
		sb - Scrollbars visible? 1 = yes, 0 = no. 
		rs - Resizable window? 1 = yes, 0 = no. 
		x - The horizontal position of the window from the left of the screen. 
		y - The vertical position of the window from the top of the screen. 
*/
function openWindow(url,w,h,tb,stb,l,mb,sb,rs,x,y){
var t=(document.layers)? ',screenX='+x+',screenY='+y: ',left='+x+',top='+y; //A LITTLE CROSS-BROWSER CODE FOR WINDOW POSITIONING
tb=(tb)?'yes':'no'; 
stb=(stb)?'yes':'no'; 
l=(l)?'yes':'no';
mb=(mb)?'yes':'no'; 
sb=(sb)?'yes':'no'; 
rs=(rs)?'yes':'no';
var x=window.open(url, 'newWin'+new Date().getTime(), 'scrollbars='+sb+',width='+w+',height='+h+',toolbar='+tb+',status='+stb+',menubar='+mb+',links='+l+',resizable='+rs+t);
x.focus();
return false;
}

 // check if email is valid
function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      alert('O Email que indicou não é válido!');
      return false;
   }
}

/*
 // check if field is empty
 // could pass an array of fields
function emptyField (form_id, checkField) {
	var fieldOK = true;
	if (checkField == array) {
		for each checkField {
			var fieldName = checkField[x]
			var fieldName = document.forms[form_id].elements[fieldName].value;
			if (checkName == '') {
				fieldOK = false;
			}				
		}
		
	} else {
		if (checkField = '') {
			fieldOK = false;
		}
	}
	return fieldOK;
}
*/

/*
	local		= >	1  = Lisboa
				2 = Porto
*/
function newLocation (local){
	// Referência para a instância de GMap2
	// para o google maps
	var mapaobj;
    // Cria o objeto principal referenciando a div 'mapa'
//    mapaobj = new GMap2(document.getElementById("map"), { size: new GSize(600,mapHeight) } );
    mapaobj = new GMap2(document.getElementById("map"));
	// adiciona o controlo de zoom ao mapa
	mapaobj.addControl(new GSmallMapControl());	
    // Adiciona as opções de visualização do mapa.
    // As opções disponíveis são: normal, híbrido e satélite
    mapaobj.addControl(new GMapTypeControl());
	
	var lat = 0;
	var lng = 0;
	
	switch (local)
	{
	case 1:
		lat =38.748946;
		lng = -9.137428;
		var info = '<p style="text-align:left;"><span style="color:#173CA2;font-size:1.1em;font-weight:bold;">STT - Sindicato dos Trabalhadores <br />de Telecomunicações e Comunicação Audiovisual </span><br /><span style="color:#C00000;;font-size:1.1em;font-weight:bold;">Sede (Lisboa) </span> <br/><span style="font-size:0.9em;font-weight:normal;">Avenida Estados Unidos da América, 53, 15º Esq<br />1700-165 Lisboa<br />Portugal</span></p>'
		break;
	case 2:
		lat = 41.14825;
		lng = -8.612777;
		var info = '<p style="text-align:left;"><span style="color:#173CA2;font-size:1.1em;font-weight:bold;">STT - Sindicato dos Trabalhadores <br />de Telecomunicações e Comunicação Audiovisual </span><br /><span style="color:#C00000;;font-size:1.1em;font-weight:bold;">Delegação (Porto) </span> <br/><span style="font-size:0.9em;font-weight:normal;">Praça D. Filipa de Lencastre<br />4050-259 Porto<br />Portugal</span></p>'		
	  break;
	}

	
	var p = new GLatLng(lat, lng)

	
	// Centraliza o mapa na coordenada dada com nível de zoom 17
    mapaobj.setCenter(p, 17);
    
	// Cria um novo marcador que sera exibido no ponto p solicitado
    marcador = new GMarker(p);

    // Adiciona o marcador ao mapa
    mapaobj.addOverlay(marcador);

    // Exibe uma caixa de informação com o texto informado
    // Note que esse método aceita qualquer string com uma
    // formatação html arbitrária
    marcador.openInfoWindowHtml(info);    
}

 // getWH = FALSE return Height
 // getWH = TRUE return Width
function windowSize(getWH) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	if (getWH)
		return myWidth;
	else	
		return myHeight;
}

/*
	local		= >	1  = Lisboa
				2 = Porto
	showHide	=>	0 = hide
				1 = show
*/
function showMap (local, showHide){
	resizeDiv(showHide);
	 // if = 0 is to hide
	if (showHide != 0)
		newLocation (local);	
	return false;
}	

 // makes the div#local the same height as the browser window 
 // returns the window height, for google maps
function getDivHeight (){
	var divLocal	= document.getElementById('local');
	var winH 		= windowSize(false);
	divLocal.style.height = winH;
	return winH;
}	
    //<![CDATA[

function load() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(37.4419, -122.1419), 13);
  }
}

    //]]>

/* 
	resizes the map area to fit the screen and/or hides the map div
*/
function resizeDiv(showHide) {
	var aux='';//used to convert px in number
	var divLocal	= document.getElementById('local');
	var divCont 	= document.getElementById('cont');
	var divMap 		= document.getElementById('map');
	var divMenu		= document.getElementById('map_menu');
		
	divCont.style.width = 740+'px'; // default value
	divCont.style.height = 600+'px'; // default value
	divCont.style.left= 0+'px'; // default value
	divMap.style.width = 600+'px' ; // default value
	divMap.style.height = 92+'%'; // default value	
	
	//alert (divMap.style.width);
	
	divLocal.style.display	= (showHide == 0) ? 'none' : 'block';
	divCont.style.display	= (showHide == 0) ? 'none' : 'block';
	 // center horizonttaly and vertically div#cont
	var screenWidth 	= windowSize (true);
	aux 				= parseInt(divCont.style.width);
	 
	if (aux < screenWidth){
		 // scrren wider than div#cont
		var divLeft			= (screenWidth - aux)/2;
		divCont.style.left 	= divLeft + 'px';
	} else {
		 // screen narrow than the div#cont, resize div#cont and div#map
		divCont.style.left	= 0;
		divCont.style.width = 100+'%';

		divMap.style.width 	= 95+'%';
	}
	
	var screenHeight	= windowSize(false);
	aux					= parseInt(divCont.style.height);
	
	if (aux < screenHeight){
		 // scrren taller than div#cont
		var divTop			= (screenHeight - aux)/2;
		divCont.style.top 	= divTop + 'px';
	} else {
		 // screen lower than the div#cont, resize div#cont and div#map
		divCont.style.top		= 0+'px';
		divCont.style.height	= (screenHeight - 50)+'px';
		divMap.style.height 	= 90+'%';
	}
	divMenu.style.width	= divMap.style.width;
	divLocal.style.height=screenHeight;	
}