var isIE = navigator.appName.indexOf("Microsoft") != -1;


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;

	}
	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 = "navegacao_nova_mexida";


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 document.getElementById(movieName);
	  
  } else {
    
	return document.embeds[movieName];
	
    	// para o firefox e retornada uma nodelist, dai aparecer [1]
    	//return window.document[movieName][1];
  }
}

// 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, area, padrinho) {

	if (movieIsLoaded(thisMovie(movieName))) {
		//PRessupoe que seccaoFlash ja foi SET first
		thisMovie(movieName).SetVariable( "/_level0:area", area);
		thisMovie(movieName).SetVariable( "/_level0:keyPadrinho", padrinho);
		thisMovie(movieName).GotoFrame(3);
		thisMovie(movieName).play();


	}
}


function actualizaFotoGaleria(movieName, path) {

	if (movieIsLoaded(thisMovie(movieName))) {
		//PRessupoe que seccaoFlash ja foi SET first
		//alert(path);
		//alert(thisMovie(movieName));
		thisMovie(movieName).SetVariable( "/_level0:imagem", path);
		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 > 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();
		//alert('play:' + movieName +  'var1:' + nomeVar1 + '; val1=' + value1 + ';var2:' + nomeVar2 + '=' + value2 + ';frame='+ frame);
	}
}



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(".");

	if(ficheiroPromo != ''){
	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 mudaBackgroundSantos(){
	parent.document.body.style.backgroundImage = 'url(img/bg_santos.jpg)';
}	
function mudaBackground(){
	parent.document.body.style.backgroundImage = 'url(img/bg.jpg)';
}	

//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){
	document.write('<object 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 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>');
}

//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 printFlashEncode(src, srcEncode, width, height, menu, wmode, version){
	document.write('<object 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 src=\"' + srcEncode + '\" 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 gotoAndGo(movieName, area, frameNumber, indice) {
	//if (movieIsLoaded(thisMovie(movieName))) {
		//PRessupoe que seccaoFlash ja foi SET first
		
		thisMovie(movieName).SetVariable( "/_level0:area", area);
		thisMovie(movieName).SetVariable( "/_level0:indice", indice);
		thisMovie(movieName).GotoFrame(frameNumber);
		thisMovie(movieName).Play();
		/*
		thisMovie(movieName).SetVariable( "/_level0:area", area);
		thisMovie(movieName).SetVariable( "/_level0:indice", indice);
		thisMovie(movieName).GotoFrame(frameNumber);
		thisMovie(movieName).play();*/
	//}
}

function gotoAndGoMenu(movieName, area, frameNumber, indice, navegacaoSubMenu) {
	//if (movieIsLoaded(thisMovie(movieName))) {
		//PRessupoe que seccaoFlash ja foi SET first
		thisMovie(movieName).SetVariable( "/_level0:area", area);
		thisMovie(movieName).SetVariable( "/_level0:indice", indice);
		thisMovie(movieName).SetVariable( "/_level0:navegacaoSubMenu", navegacaoSubMenu);
		thisMovie(movieName).GotoFrame(frameNumber);
		thisMovie(movieName).Play();
	//}
}


//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 printFlashComId(id, src, width, height, menu, wmode, version){
	document.write('<object name=\"'+id+'\" 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('<param name=\"allowScriptAccess\" value=\"always\">');
	document.write('<embed allowScriptAccess=\"always\" id=\"'+id+'\" name=\"'+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 changeSwf(d, id, src, width, height){
	var obj = document.getElementById(d);
	obj.innerHTML = '<object id=\"'+id+'\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"' + width + '\" height=\"' + height + '\"><param name=\"movie\" value=\"' + src + '\"><param name=\"quality\" value=\"high\"><param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"transparent\"><embed name=\"'+id+'\" src=\"' + src + '\" quality=\"high\" wmode=\"transparent\" menu=\"false\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"' + width + '\" height=\"' + height + '\"></embed></object>';
}

function changeIframe(d, id, src, width, height){
	var obj = document.getElementById(d);
	obj.innerHTML = '<iframe name=\"'+id+'\" id=\"'+id+'\" src=\"'+src+'\" frameborder="0" allowtransparency="true" width=\"'+width+'\" height=\"'+height+'\" vspace="0" marginwidth="0" marginheight="0" hspace="0" scrolling="no"></iframe>';
}

// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s(id){
var obj = null;
if(document.getElementById){
/* Prefer the widely supported W3C DOM method, if
available:-
*/
obj = document.getElementById(id);
}else if(document.all){
/* Branch to use document.all on document.all only
browsers. Requires that IDs are unique to the page
and do not coincide with NAME attributes on other
elements:-
*/
obj = document.all[id];
}
/* If no appropriate element retrieval mechanism exists on
this browser this function always returns null:-
*/
return obj;
}



/****** FUNCOES PARA A ACTUALIZACAO DOS FLASHES PEQUENO E PODEROSO *****/

/* chamada quando se escolhe a peca de roupa do lado direito actualiza o flash da esquerda */
function escolheRoupa(area){
	movieName = 'PP_lateralRoupa';
	thisMovie(movieName).SetVariable( "/_level0:area", area);
	thisMovie(movieName).GotoFrame(6);
	thisMovie(movieName).Play();
}


/* Actualiza o artigo escolhido no flash da direita quando nos encontramos na area 'porque pequeno e poderoso' */
function actualizaConteudo(movieName, indiceArtigo){
	thisMovie(movieName).SetVariable("/_level0:indiceArtigo", indiceArtigo);
}

/* chamada quando se escolhe um item do menu do lado esquerdo, de forma a mudar o swf */
function trocaSwfPP(id, src){
	width = '381';
	height = '304';
	obj = document.getElementById('flashGrande');
	if(id=='PP_centralMessage'){
		obj.innerHTML = '<object id=\"'+id+'\" name=\"'+id+'\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"' + width + '\" height=\"' + height + '\"><param name=\"movie\" value=\"' + src + '\"><param name=\"quality\" value=\"high\"><param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"transparent\"><embed name=\"'+id+'\" src=\"' + src + '\" quality=\"high\" wmode=\"transparent\" menu=\"false\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"' + width + '\" height=\"' + height + '\"></embed></object>';
	}else{
		obj.innerHTML = '<object id=\"'+id+'\" name=\"'+id+'\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"' + width + '\" height=\"' + height + '\"><param name=\"movie\" value=\"' + src + '\"><param name=\"quality\" value=\"high\"><param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"transparent\"><embed name=\"'+id+'\" src=\"' + src + '\" quality=\"high\" wmode=\"transparent\" menu=\"false\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"' + width + '\" height=\"' + height + '\"></embed></object>';
	}
}

/* chamada quando se escolhe uma peca dos pequenos e poderosos */
function escolhePeca(area, indiceArtigo){
	movieName = 'PP_lateralRoupa';
	thisMovie(movieName).SetVariable( "/_level0:area", area);
	thisMovie(movieName).SetVariable( "/_level0:indiceArtigo", indiceArtigo);
	thisMovie(movieName).GotoFrame(6);
	thisMovie(movieName).Play();
}
function escolhePecaRoupa(roupa){
	movieName = 'PP_main';
	thisMovie(movieName).SetVariable( "/_level0:azul", roupa);
}

/* Actualiza o artigo escolhido no flash da direita quando nos encontramos na area 'porque pequeno e poderoso' */
function actualizaVariavelFlash(movieName, nomeVar, valorVar){
	thisMovie(movieName).SetVariable("/_level0:"+nomeVar, valorVar);
}


function removeActiveX(){
	var objs = document.getElementsByTagName('object');
	objs[2].outerHTML = objs[2].outerHTML;
}


function objectFocus(objectId){
 objectId = 'content';
 var obj = parent.document.getElementById(objectId);
 obj.focus();
}