
/* Funções Validators*/
function ValidaLocalizacaoLoja(source, arguments)
{
	var iConta;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao1Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao2Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao3Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao4Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao5Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxLocalizacao6Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputTextLocalizacaoOutraLoja.value != '') iConta=1;

	if (iConta==1) 
		arguments.IsValid=true 
	else 
		arguments.IsValid=false
}

function ValidaServicosAssociadosLoja(source, arguments)
{
	var iConta;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados1Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados2Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados3Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados4Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados5Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados6Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputCheckBoxServicosAssociados7Loja.checked) iConta=1;
	if (document.HtmlFormCandidatura.HtmlInputTextServicosAssociadosOutrosLoja.value != '') iConta=1;

	if (iConta==1) 
		arguments.IsValid=true 
	else 
		arguments.IsValid=false
}

/* Funções Validators*/

function Noticia(arg1) {
	document.__FORM.action = '/noticias/noticia.aspx';
	document.__FORM.recordId.value = arg1;
	document.__FORM.IdNoticia.value = arg1;
	
	document.__FORM.submit();
}

function Tema(arg1) {
	document.__FORM.action = '/noticias/lista.aspx';
	document.__FORM.recordId.value = arg1;
	document.__FORM.IdTemaNoticia.value = arg1;
	document.__FORM.tipo.value = 4;
	
	document.__FORM.submit();
}

function PressRelease(arg1) {
	document.__FORM.action = '/pressrelease/pressrelease.aspx';
	document.__FORM.recordId.value = arg1;
	
	document.__FORM.submit();
} 

function Emitente(arg1,arg2) {
	document.__FORM.action = '/emitentes/emitente.aspx';
	document.__FORM.recordId.value = arg1;

	if (arg2 > 0) document.__FORM.IdConcelho.value = arg2;
	
	document.__FORM.submit();
}

function EmitenteC() {
	var id = document.getElementById("ComboDistrito").value
	var arg1 = document.getElementById("ComboConcelho"+id).value;
	
	document.__FORM.action = '/emitentes/concelho.aspx';
	document.__FORM.recordId.value = arg1;

	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = id;
	
	document.__FORM.tipo.value = 7;
	
	document.__FORM.submit();	
}

function AgenteD(arg1,arg9) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value
	if (arg9 == undefined) arg9 = ''

	document.__FORM.action = '/agentes/distrito.aspx';
	document.__FORM.IdDistrito.value = arg1;
	document.__FORM.tipo.value = 1;

	document.__FORM.IdServico.value = arg9;

	document.__FORM.submit();
}

function AgenteC(arg1,arg2,arg9) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value
	if (arg2 != undefined && (arg2.value || arg2.value == '')) arg2 = arg2.value
	if (arg9 == undefined) arg9 = ''

	document.__FORM.action = '/agentes/concelho.aspx';
	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = arg2;
	document.__FORM.tipo.value = 2;

	document.__FORM.IdServico.value = arg9;

	document.__FORM.submit();
}

function AgenteF(arg1,arg2,arg3,arg9) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value
	if (arg2 != undefined && (arg2.value || arg2.value == '')) arg2 = arg2.value
	if (arg3 != undefined && (arg3.value || arg3.value == '')) arg3 = arg3.value
	if (arg9 == undefined) arg9 = ''

	document.__FORM.action = '/agentes/freguesia.aspx';
	document.__FORM.IdFreguesia.value = arg1;
	document.__FORM.IdConcelho.value = arg2;
	document.__FORM.IdDistrito.value = arg3;
	document.__FORM.tipo.value = 3;

	document.__FORM.IdServico.value = arg9;

	document.__FORM.submit();
}

function Agente(arg1) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value

	document.__FORM.action = '/agentes/agente.aspx';
	document.__FORM.IdLoja.value = arg1;
	
	document.__FORM.submit();
}

function Cadeia(arg1) {
	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value

	document.__FORM.action = '/agentes/rede.aspx';
	document.__FORM.IdRetalhista.value = arg1;
	document.__FORM.tipo.value = 6;

	document.__FORM.submit();
}

function AreaActividade() {
	var oArea = document.getElementById("ComboArea");
	
	if (oArea.value > 0) {
		document.__FORM.action = '/emitentes/area.aspx';
		document.__FORM.IdAreaActividade.value = oArea.value;
		document.__FORM.tipo.value = 5;		
		
		document.__FORM.submit();	
	} else {
		alert('Seleccione a Área de Actividade!\n')
	}
}

function ListarConteudo(arg1) {
	switch (arg1)
	{
		case 1: //Noticias
			window.location='/noticias/';
			break;
		case 2: //Press Release
			window.location='/pressrelease/';
			break;
		case 3: //Newsletter
			window.location='/newsletter/';
			break;
		case 4: //Clipping
			window.location='/noticias/';
			break;			
	}
}

function DoSearch(arg1,arg2) {
	document.__FORM.action = arg1;
	document.__FORM.searchText.value = arg2;

	document.__FORM.submit();
}


function GoToPage(arg1,arg2,arg3,arg4,arg5) { 
	document.__FORM.action = arg1;
	document.__FORM.pag.value = arg2;
	document.__FORM.tipo.value = arg3;

	document.__FORM.searchText.value = arg3;

	document.__FORM.IdServico.value = arg4;

	switch (arg3)
	{
		case '1': //Agentes - Distrito
			document.__FORM.IdDistrito.value = arg5;
			break;
		case '2': //Agentes - Concelho
			document.__FORM.IdConcelho.value = arg5;
			document.__FORM.IdDistrito.value = document.getElementById("IdDistrito2").value;
			break;
		case '3': //Agentes - Freguesia
			document.__FORM.IdFreguesia.value = arg5;
			break;
		case '4': //Noticias - Lista
			document.__FORM.IdTemaNoticia.value = arg4;
			break;
		case '5': //Emitentes - AreaActividade
			document.__FORM.IdAreaActividade.value = arg4;
			break;		
		case '6': //Agentes - Rede
			document.__FORM.IdRetalhista.value = arg4;
			break;		
		case '7': //Emitentes - Concelho
			document.__FORM.recordId.value = arg4;
			document.__FORM.IdConcelho.value = arg4;
			document.__FORM.IdDistrito.value = document.getElementById("IdDistrito2").value;
			break;
	}
	
	document.__FORM.submit();
}

function EmitenteConcelho(arg1) {
	var id = document.getElementById("IdDistrito2").value

	if (arg1 != undefined && (arg1.value || arg1.value == '')) arg1 = arg1.value
	
	document.__FORM.action = '/emitentes/concelho.aspx';
	document.__FORM.recordId.value = arg1;

	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = id;
	document.__FORM.tipo.value = 7; //necessario para a navegacao
	
	document.__FORM.submit();	
}

function AgenteConcelho() {
	var id = document.getElementById("IdDistrito2").value
	var arg1 = document.getElementById("ComboConcelho").value;

	document.__FORM.action = '/agentes/concelho.aspx';
	document.__FORM.IdConcelho.value = arg1;
	document.__FORM.IdDistrito.value = id;
	document.__FORM.tipo.value = 2; //necessario para a navegacao
	
	document.__FORM.submit();	
}


// --------------------------------------------------
//  AGENTES e EMITENTES : combo Distrito/Concelho
// --------------------------------------------------

function HideAll_ShowActive(objDistrito,objDistritoValue,accao) {
	var oDistritoTotal = objDistrito.length - 1;
	var oDistritoValue = objDistritoValue;
	
	//hide all
	for (i = 1;i <= oDistritoTotal;i++) { 
		ii = eval(objDistrito[i].value)
		document.getElementById("DivConcelho"+ii).style.display = 'none'	
		document.getElementById("SpanConcelho").style.display = 'none'	
		
		if (accao==1) document.getElementById("ComboConcelho"+ii).selectedIndex = 0
	}

	//show active
	if (oDistritoValue > 0) {
		document.getElementById("DivConcelho"+oDistritoValue).style.display = ''
		
		//Freguesia
		var oDivFreguesia = document.getElementById("DivFreguesia")
		
		if (oDivFreguesia != undefined) {
			var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value

			if (oConcelhoValue > 0) { 
				oDivFreguesia.style.display='';
			} else {
				oDivFreguesia.style.display='none';
			}
		}
	}
} //end function


function MostraConcelho(accao) {
	var oDistrito = document.getElementById("ComboDistrito");
	var oSpanConcelho =  document.getElementById("SpanConcelho")

	HideAll_ShowActive(oDistrito,oDistrito.value,accao)
	
	if (oDistrito.selectedIndex > 0) {
		oSpanConcelho.style.display='';
	} else {
		oSpanConcelho.style.display='none';
	}
}

function VerDistrito(idx) {
	var oDistrito = document.getElementById("ComboDistrito");
	oDistrito.value=idx
	
	HideAll_ShowActive(oDistrito,idx)
}

function Emitente_MostraFreguesia() {
	var oServicoValue = document.getElementById("ComboServico").value;
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value;

	var oServicoTempValue = document.getElementById("HiddenServico").value;

	if (oConcelhoValue > 0) {
		//document.__FORM.action = '/agentes/default.aspx';
		document.__FORM.action = 'default.aspx';
		document.__FORM.IdConcelho.value = oConcelhoValue;
		document.__FORM.IdDistrito.value = oDistritoValue;
		document.__FORM.IdServico.value = oServicoValue;
		document.__FORM.recordId.value = oServicoTempValue;
		document.__FORM.submit();
		
	} else {
		//alert('Seleccione o Concelho!\n')
	}
}

function Agente_MostraFreguesia() {
	var oServicoValue = document.getElementById("ComboServico").value;
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value;

	if (oConcelhoValue > 0) {
		//document.__FORM.action = '/agentes/default.aspx';
		document.__FORM.action = 'default.aspx';
		document.__FORM.IdConcelho.value = oConcelhoValue;
		document.__FORM.IdDistrito.value = oDistritoValue;
		document.__FORM.IdServico.value = oServicoValue;
		document.__FORM.submit();
		
	} else {
		//alert('Seleccione o Concelho!\n')
	}
}

function Agente_ListarDistrito() {
	var oServicoValue = document.getElementById("ComboServico").value;
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	
	if (oDistritoValue > 0) {
		AgenteD(oDistritoValue,oServicoValue)
	} else {
		//alert('Seleccione o Distrito!\n')
	}
}

function Agente_ListarConcelho() {
	var oServicoValue = document.getElementById("ComboServico").value;
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value;

	if (oConcelhoValue > 0) {
		AgenteC(oConcelhoValue,oDistritoValue,oServicoValue)
	} else {
		//alert('Seleccione o Concelho!\n')
	}
}

function Agente_ListarFreguesia() {
	var oServicoValue = document.getElementById("ComboServico").value;
	var oDistritoValue = document.getElementById("ComboDistrito").value;
	var oConcelhoValue = document.getElementById("ComboConcelho"+oDistritoValue).value;
	var oFreguesiaValue = document.getElementById("ComboFreguesia").value;

	if (oFreguesiaValue > 0) {
		AgenteF(oFreguesiaValue,oConcelhoValue,oDistritoValue,oServicoValue)
	} else {
		//alert('Seleccione a Freguesia!\n')
	}
}

function Emitente_NextPage() {
	var oDistrito = document.getElementById("ComboDistrito");
	var oDistritoValue = oDistrito.value;
	
	if (oDistritoValue > 0) {
		var oConcelho = document.getElementById("ComboConcelho"+oDistritoValue)
		if (oConcelho.value == "") { alert('Seleccione o Concelho!\n') } else { EmitenteC() }
	} else {
		alert('Seleccione o Distrito!\n')
	}
}

function Home_ListarDistrito() {

	Agente_ListarDistrito()
	
}

function DoSearchHomepage(arg1,arg2) {
	var id = document.getElementById("ComboDistrito").value
	var id2 = '';
	
	if (id != '') id2 = document.getElementById("ComboConcelho"+id).value;

	document.__FORM.action = arg1;
	document.__FORM.searchText.value = arg2;
	document.__FORM.IdDistrito.value = id;
	document.__FORM.IdConcelho.value = id2;

	document.__FORM.submit();
}

function GoToPage2(arg1,arg2,arg3,arg4,arg5) { 
	//Homepage - Pesquisa
	document.__FORM.action = arg1;
	document.__FORM.pag.value = arg2;

	document.__FORM.searchText.value = arg3;
	document.__FORM.IdDistrito.value = arg4;
	document.__FORM.IdConcelho.value = arg5;

	document.__FORM.submit();
}


function FazerPesquisa(tipoPesquisa) {
	var oTexto
	var oServico = document.getElementById("ComboServico").value
	var oDistrito = document.getElementById("ComboDistrito").value
	var oConcelho = ""
	var oFreguesia = ""

	var destino = ""
	var tipo = 0

	if (oServico > 0) { destino="servico.aspx"; tipo=3; }

	if (oDistrito > 0) { oConcelho = document.getElementById("ComboConcelho"+oDistrito).value; destino="distrito.aspx"; tipo=1; }
	if (oConcelho > 0) { oFreguesia = document.getElementById("ComboFreguesia").value; destino="concelho.aspx"; tipo=2; }
	if (oFreguesia > 0) { destino="freguesia.aspx"; tipo=3; }

	if (tipoPesquisa == 1) {
		if (oDistrito > 0) {

			document.__FORM.action = '/agentes/' + destino;
			document.__FORM.IdFreguesia.value = oFreguesia;
			document.__FORM.IdConcelho.value = oConcelho;
			document.__FORM.IdDistrito.value = oDistrito;
			document.__FORM.tipo.value = tipo;

			document.__FORM.IdServico.value = oServico;

			document.__FORM.submit();

		} else {
			alert('Seleccione Distrito!\n')
		}	
	}
	else {
		oTexto = document.getElementById("TextoPesquisa").value
		
		if (oTexto.length > 1) {
		
			document.__FORM.action = '/agentes/pesquisa.aspx';
			document.__FORM.searchText.value = oTexto;
			document.__FORM.submit();
			
		} else {
			alert('O nome de Agente a pesquisar deverá ter 2 ou mais caracteres!\n')
		}
	}

}














// --------------
//  falta ver
// --------------
function Mapa() {
	window.open('/auxiliar/mapa.aspx','mapa','toolbar=no,width=400,height=400,location=no,status=no,directories=no,menubar=no,scrollbars=yes,resizable=no');
}

function RedirectMap(lnk) {
	window.opener.location = (lnk);
	window.close()
}

function Anterior() {
	history.back();
}

function Topo() {
	scrollTo();
}

function Fechar() {
	window.close();
}

function Imprimir() {
	window.print();
}

function abre(tid,n) {
	if (eval("document.all."+tid+".style.display")=="none") {
                for (i=1;i<=n;i++) {
		eval("document.all.t"+i+".style.display='none'");
                }
		eval("document.all."+tid+".style.display=''");
		}
	else {
		eval("document.all."+tid+".style.display='none'");
	}	
}

function imprime(numero) {
	for (i=1;i<numero+1;i++) {
                eval("document.all.t"+i+".style.display=''");
        }
        print();
        for (i=1;i<numero+1;i++) {
                eval("document.all.t"+i+".style.display='none'");
        }

}

// funcoes active content

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function homeTopo(dia,mes){
	var filme;
		filme = "bannerHome_amnistia_08062010";	
		//if(mes >= 6){if(dia >= 6){filme = "bannerHome_23042010";}}
	AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '309',
		'height', '200',
		'src', '/flash/home/'+filme,
		'quality', 'best',
		'pluginspage', 'http://www.adobe.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'transparent',
		'devicefont', 'false',
		'id', 'bannerHome',
		'name', 'bannerHome',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', '/flash/home/'+filme,
		'salign', ''
		); //end AC code
}