
//Actualiza apresentação de mapa contactos
function actualizaNav(area){
	var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
    flash = isInternetExplorer ? parent.document.all.menuTop : parent.document.menuTop[1];
	flash.actualizaMenuExterno(area);
}


//paramIN: altura em pixeis para o Ifram
//paramOUT: void
//summary: faz o resize da iframe onde o documento actual está carregado
//			se o valor newHeight passar em branco o valor é calculado conforme a altura do body


function abrirJanelaScrollCentrada(url, largura, altura){
    var larguraEcra = window.screen.width;
    var alturaEcra = window.screen.height;
    var posicaoX = (larguraEcra / 2) - (largura / 2);
    var posicaoY = (alturaEcra / 2) - (altura / 2);
	window.open(url,"","left="+posicaoX+",top="+posicaoY+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+largura+", height="+altura);
}

function resizeIframe(newHeight) {

	// Must launched on the body onload event handler for IE
	// Use document.documentElement if you are in Compat mode


	i = parent.document.getElementById(window.name)
	
	if (newHeight == undefined){

		newHeight = document.body.scrollHeight;
		if(newHeight==528) newHeight +=35;/*isto e mega parvo, mas n sei pq a altura das promos n tava a dar bem...*/
		
	}
	
	i.style.height = newHeight + "px";
	
	
	
	//alert('height = ' + i.style.height);
}

/**
* Abre uma janela simples centrada
*
* @param string $url
* @param int $largura
* @param int $altura
* @author jose.almeida@t-bsolutions.com
*/

function abrirJanelaCentrada(url, largura, altura){
    var larguraEcra = window.screen.width;
    var alturaEcra = window.screen.height;
    var posicaoX = (larguraEcra / 2) - (largura / 2);
    var posicaoY = (alturaEcra / 2) - (altura / 2);
	window.open(url,"","left="+posicaoX+",top="+posicaoY+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+largura+", height="+altura);
}

function abrirJanelaCentradaComScroll(url, largura, altura){
    var larguraEcra = window.screen.width;
    var alturaEcra = window.screen.height;
    var posicaoX = (larguraEcra / 2) - (largura / 2);
    var posicaoY = (alturaEcra / 2) - (altura / 2);
	window.open(url,"","left="+posicaoX+",top="+posicaoY+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+largura+", height="+altura);
}

/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
function validateNotEmpty( strValue ) {

   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }
   return false;
}

function validateEmail( str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
function trimAll( strValue ) {

 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

/**
* Chamada ao HttpRequest
*
* @param string $url
* @author joao.brites@t-bsolutions.com
*/

var req;

/**
* Chamada ao HttpRequest
*
* @param string $url
* @author joao.brites@t-bsolutions.com
*/

var req;

function loadXMLDoc(url) 
{
	
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function loadXMLDocHandler(url, readyHandler) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = readyHandler;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = readyHandler;
            req.open("GET", url, true);
            req.send();
        }
    }
}


/*
*
*
*
*/

//METODOS DE CONTROLO DO MENU FLASH

var movieName = "menu";

function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
	return parent.window[movieName]
  }	else {
    return parent.document[movieName]
  }
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
   var movie = eval(theMovie)
  if (typeof(movie) != "undefined") {
	return movie.PercentLoaded() == 100;
  } else {
    return false;
  }
}

function actualizaNavegacao(movieName, seccao) {

		
	if (movieIsLoaded(thisMovie(movieName))) {

		//PRessupoe que seccaoFlash ja foi SET first
		thisMovie(movieName).SetVariable( "/_level0:seccao", seccao);
		thisMovie(movieName).GotoFrame(2);
		thisMovie(movieName).play();


	}
}


function actualizaNavegacao2(movieName, nomeVar, value, frame) {
	if (movieIsLoaded(thisMovie(movieName))) {
		//PRessupoe que seccaoFlash ja foi SET first
		thisMovie(movieName).SetVariable( "/_level0:"+nomeVar, value);
		if(frame.length > 0){
			thisMovie(movieName).GotoFrame(frame);
		}
	}
}

function actualizaNavegacao3(movieName, nomeVar1, value1, nomeVar2, value2, frame) {

	if (movieIsLoaded(thisMovie(movieName))) {
			
		//PRessupoe que seccaoFlash ja foi SET first
		thisMovie(movieName).SetVariable( "/_level0:"+nomeVar1, value1);
		thisMovie(movieName).SetVariable( "/_level0:"+nomeVar2, value2);
		thisMovie(movieName).GotoFrame(frame);
		thisMovie(movieName).play();
	}
}



function actualizaGama(movieName, idProduto) {

	if (movieIsLoaded(thisMovie(movieName))) {
		//PRessupoe que seccaoFlash ja foi SET first
		
		thisMovie(movieName).SetVariable( "/_level0:idProduto", idProduto);
		
	}
}



/**
* tratamento de recepção da resposta
*
* 
* @author joao.brites@t-bsolutions.com
*/

function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
      response  = req.responseXML.documentElement;

      method    = response.getElementsByTagName('method')[0].firstChild.data;

      result    = response.getElementsByTagName('result')[0].firstChild.data;

      eval(method + '(\'\', result)');
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

function apresentaPromocional(pathPromo, ficheiroPromo, width, height, href, target) {
	var temp = "";
	tmpArray = ficheiroPromo.split(".");
	extensaoFich = tmpArray[1];
	
	if(extensaoFich.toLowerCase() != "swf") {

		if(href != '') {
			temp = "<a href=\"" + href + "\"";
			
			if(target != '') {
				temp += " target=\"" + target + "\""; 
			}
			temp += ">";
		}
		
		temp += "<img src=\"" + pathPromo + ficheiroPromo + "\" width=\"" + width + "\" height=\"" + height + "\" border=\"0\">";
	
		if(href != '') {
			temp += "</a>";
		}
		
		//alert(temp);
	} 
	else {
		temp = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + width + "\" height=\"" + height + "\">" +
						"<param name=\"movie\" value=\"" + pathPromo + ficheiroPromo + "?link=" + href + "\">" +
						"<param name=\"wmode\" value=\"transparent\">" +
						"<param name=\"menu\" value=\"false\" />" +
						"<param name=\"quality\" value=\"high\">" +
						"<embed src=\"" + pathPromo + ficheiroPromo + "?link=" + href + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"" + width + "\" height=\"" + height + "\"></embed>" +
			   "</object>";
	} 
	
	return temp;
}



/**********************************************************************************************************************/
/* Description: Valida se a data thisData está bem formatada */
/* Params IN: thisData:string */
/* Params OUT: boolean */
/* Returns: true se a data for composta por 2 digitos para dia, 2 digitos para mes e 4 para ano */
function validaDataComposta(thisData){

var objRegExp = /^\d{2}-\d{2}-\d{4}$/

  //check to see if in correct format
  if(!objRegExp.test(thisData))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = thisData.substring(2,3) //find date separator
    var arrayDate = thisData.split(strSeparator); //split date into month, day, year
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[0],10);

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true; //found in lookup table, good date
    }

    //check for February (bugfix 20050322)
    var intMonth = parseInt(arrayDate[1],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2],10);
       if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true; //Feb. had valid number of days
       }
  }
  return false; //any other values, bad date
  
}




function jumpLogin2(){
	var obj = parent.parent.document.getElementById("divFlash2");
	obj.style.display = '';
	//actualizaNavegacao2("flashLogin2", "", "", 2); 
}

function autoResize(id){
		var newheight;
		frame = document.getElementById(id);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		newheight = innerDoc.body.scrollHeight;
		//alert("frame: " + id + "; nova altura: " + newheight)
		document.getElementById(id).height= (newheight) + "px";
		return newheight;
	}
	
	function autoResizeDuplo(id){
		var newheight;
		frame = parent.document.getElementById(id);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		newheight = innerDoc.body.scrollHeight;
		//alert("frame: " + id + "; nova altura: " + newheight)
		parent.document.getElementById(id).height= (newheight) + "px";
		
		frame = parent.parent.document.getElementById('frameInterior');
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		newheight = innerDoc.body.scrollHeight;
		//alert("frame: " + id + "; nova altura: " + newheight)
		parent.parent.document.getElementById('frameInterior').height= (newheight) + "px";
		return newheight;
	}
	
	function autoResizeDuploComId(id1, id2){
		var newheight;
		frame = parent.document.getElementById(id1);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		newheight = innerDoc.body.scrollHeight;
		//alert("frame: " + id1 + "; nova altura: " + newheight)
		parent.document.getElementById(id1).height= (newheight) + "px";
		
		frame = parent.parent.document.getElementById(id2);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		newheight = innerDoc.body.scrollHeight;
		//alert("frame: " + id2 + "; nova altura: " + newheight)
		parent.parent.document.getElementById(id2).height= (newheight) + "px";
		return newheight;
	}
	
	function autoResizeTamanho(id, tamanho){
		var newheight;
		//alert("frame: " + id + "; nova altura: " + newheight)
		parent.document.getElementById(id).height= (tamanho) + "px";
		
		frame = parent.parent.document.getElementById('frameInterior');
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		newheight = innerDoc.body.scrollHeight;
		//alert("frame: " + id + "; nova altura: " + newheight)
		parent.parent.document.getElementById('frameInterior').height= (newheight) + "px";
		return newheight;
	}
	
	function resizeTamanho(id, tamanho){
		var newheight;
		alert("frame: " + id + "; nova altura: " + tamanho);
		document.getElementById(id).height= (tamanho) + "px";
		return newheight;
	}




// VALIDACAO DE FORMULARIOS

function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

//paramIN:	src:string - source do movie;
//			width:int - comprimento;
//			heigth:int - altura;
//			menu:string - permite ver menu (mousse right click)
//			wmode:string - permite transparent
//			version:string - versao do flash player
//paramOUT: void
//summary: faz o render do objecto flash
function printFlash(src, width, height, menu, wmode, version, id){
	document.write('<object id=\"'+id+'\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + '\" width=\"' + width + '\" height=\"' + height + '\">');
	document.write('<param name=\"movie\" value=\"' + src + '\">');
	document.write('<param name=\"quality\" value=\"high\">');
	document.write('<param name=\"menu\" value=\"' + menu + '\">');
	document.write('<param name=\"wmode\" value=\"' + wmode + '\">');
	document.write('<embed name=\"'+id+'\" id=\"'+id+'\" src=\"' + src + '\" quality=\"high\" wmode=\"' + wmode + '\" menu=\"' + menu + '" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"' + width + '\" height=\"' + height + '\"></embed>');
	document.write('</object>');
}

function resizeMe(){
	//tratamento do resize do iframe
	//alert(parent.document.getElementById('frameInterior'));
	frame = parent.document.getElementById('frameInterior');
	var newheight;
	innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	newheight = innerDoc.body.scrollHeight;
	//alert("frame: " + 'frameInterior' + "; nova altura: " + newheight)
	parent.document.getElementById('frameInterior').height= (newheight) + "px";
}

function resizeMeId(id){
	//tratamento do resize do iframe
	//alert(parent.document.getElementById('frameInterior'));
	frame = parent.document.getElementById(id);
	var newheight;
	innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	newheight = innerDoc.body.scrollHeight;
	//alert("frame: " + 'frameInterior' + "; nova altura: " + newheight)
	parent.document.getElementById(id).height= (newheight) + "px";
}

function escondePesquisa(){
	var pesquisa;
	pesquisa = parent.document.getElementById('pesquisa');
	pesquisa.style.display = 'none';
}
function mostraPesquisa(){
	var pesquisa;
	pesquisa = parent.document.getElementById('pesquisa');
	pesquisa.style.display = '';
}
