// Funzione per aprire la pagina nella pagina di apertura del pop-up
var ImgSelezionata = ''
var BullSelezionata = ''
var tAlt = ''
// cartellaBull == "bull_small" se tipo sito = "small"; "bull" se tipo sito <> "small"
var cartellaBull = 'bull';
var tipoSitoSelezionato = '';
var pathSitoCamera = ''

if (tipoSito == 'small'){
	cartellaBull += '_small';
	pathSitoCamera = 'http://www.camera.it'
}
if (tipoWinSito == 'normale') tipoSitoSelezionato = 'normale';

function AP(urlpage){
	// tipoWinSito == "normale" i link al deputato si apre su nuova finestraa
	if (tipoSitoSelezionato == 'normale'){
		window.open('http://www.camera.it'+urlpage);
	}else{
		parent.window.opener.parent.location.href=urlpage;
		parent.window.opener.parent.focus();
		parent.window.close();
		//document.focus();
	}
}


// Questa funzione serve solo per il sito legXV
function SD(posto){
	//alert(posto);
	//var pathSitoCamera = '/';
	var postosec = posto;
	if (ImgSelezionata != ''){
/*
		tAlt = document.getElementById(ImgSelezionata).getAttribute("alt");
		if (tAlt.indexOf("Governo") == -1){
			document.getElementById(ImgSelezionata).src = pathSitoCamera + '/img/second/emiciclo/' + cartellaBull + '/bull_'+BullSelezionata+'.gif';
		}
		else{
			document.getElementById(ImgSelezionata).src = pathSitoCamera + '/img/second/emiciclo/' + cartellaBull + '/bull_disattivi.gif';
		}
*/
		document.getElementById(ImgSelezionata).src = pathSitoCamera + '/img/second/emiciclo/' + cartellaBull + '/bull_'+BullSelezionata+'.gif';
	}

	ImgSelezionata = "img"+posto;
	BullSelezionata = persons[posto].gruppo;

/*
	if (posto == 84){
		document.getElementById('divnominativo').innerHTML = '';
		document.getElementById('imgfoto').src = '/img/dot.gif';
	}else{
*/
		NomeGruppo(persons[posto].gruppo);
		nCollegamento = persons[posto].collegamento;
		//alert(persons[posto].cognome);
		//if (persons[posto].cognome == 'GALATI') nCollegamento = '50258';
		//if (persons[posto].cognome == 'ORSINI') nCollegamento = '300299';
		if (nCollegamento != '#'){
			//sUrl = 'javascript:LD(\'\cartellecomuni\leg16\include\contenitore_dati.asp?tipopagina=&deputato=d302077&source=%2Fdeputatism%2F240%2Fdocumentoxml%2Easp&position=Deputati\La%20Scheda%20Personale&Pagina=Deputati/Composizione/SchedeDeputati/SchedeDeputati.asp%3Fdeputato=d302077&Nominativo=ACERBO Maurizio\')';
			sUrl = '/cartellecomuni/leg16/include/contenitore_dati.asp?tipopagina=&deputato=d'+ nCollegamento +'&source=%2Fdeputatism%2F240%2Fdocumentoxml%2Easp&position=Deputati\La%20Scheda%20Personale&Pagina=Deputati/Composizione/SchedeDeputati/SchedeDeputati.asp%3Fdeputato=d'+nCollegamento;
			sTestoLink = '<a href="' + sUrl + '" >';
		}else{
			sTestoLink = '';
		}
/*
		sTestoIns = '<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" rowspan="2">';
		sTestoIns += sTestoLink + '<br><img src="' + pathSitoCamera + '/img/second/emiciclo/' + cartellaBull + '/bull_selezionato.gif" alt="" vspace="0" hspace="0" border="0">';
		if (nCollegamento != '#') sTestoIns += sTestoLink + '</a>';
		sTestoIns += sTestoLink + '</td>';
		sTestoIns += '<td class="corpotitolo"><br>' + sTestoLink + persons[posto].cognome + ' ' + persons[posto].nome + '</a></td></tr>';
		sTestoIns += '<tr><td class="corpotestoleft">' + sGruppo + '</td></tr></table>'
*/

		sTestoIns = '<p style="margin:8px 0 0 0; padding:0; font-size:12px; font-weight:bold;">'
		//sTestoIns += sTestoLink + '<img src="' + pathSitoCamera + '/img/second/emiciclo/' + cartellaBull + '/bull_selezionato.gif" alt="" border="0">';
		sTestoIns += '<img src="' + pathSitoCamera + '/img/second/emiciclo/' + cartellaBull + '/bull_selezionato.gif" alt="" style="margin:0 5px 0 0; border:0;" />';
		//if (nCollegamento != '#'){
		//	sTestoIns += sTestoLink + '</a>';
		//}
		sTestoIns += sTestoLink + persons[posto].cognome + ' ' + persons[posto].nome + '</a>';
		sTestoIns += '</p>'
		sTestoIns += '<p style="margin:8px 0 0 0; padding:0 0 0 14px; font-size:12px; font-weight:bold;">'
		sTestoIns += sGruppo
		sTestoIns += '</p>'
		document.getElementById('divnominativo').innerHTML = sTestoIns;
		//tAlt = document.getElementById('img'+posto).getAttribute("alt");
		//if (tAlt.indexOf("Governo") == -1){
			document.getElementById('img'+posto).src = pathSitoCamera + '/img/second/emiciclo/' + cartellaBull + '/bull_selezionato.gif';
		//}
		document.getElementById('imgfoto').src = pathSitoCamera + '/_dati/leg16/SchedeDeputatiPrototipo/foto/scheda_small/d'+nCollegamento+'.jpg';
		document.getElementById('fcerca').nominativi.value = posto;
//	}
}

function LD(posto){
	if (posto != 84){
		nCollegamento = persons[posto].collegamento;
		//document.location.href = 'http://www.camera.it/chiosco.asp?position=Deputati|barraindietro|La%20Scheda%20Personale&source=/deputatiSM/240/documentoxml.ASP&cp=1&content=deputati/Composizione/01.camera/nuovacomposizione/framedeputato.asp?Deputato=0d'+nCollegamento;
		document.location.href = '/cartellecomuni/leg16/include/contenitore_dati.asp?tipopagina=&deputato=d'+ nCollegamento +'&source=%2Fdeputatism%2F240%2Fdocumentoxml%2Easp&position=Deputati\La%20Scheda%20Personale&Pagina=Deputati/Composizione/SchedeDeputati/SchedeDeputati.asp%3Fdeputato=d'+nCollegamento;
	}
}

function NomeGruppo(nome){
	sGruppo = nome;
	if (nome == 'PDL') sGruppo = 'POPOLO DELLA LIBERT&#192;';
	if (nome =='PD') sGruppo = 'PARTITO DEMOCRATICO';
	if (nome =='LNP') sGruppo = 'LEGA NORD PADANIA';
	if (nome =='UDC') sGruppo = 'UNIONE DI CENTRO';
	if (nome =='IDV') sGruppo = 'ITALIA DEI VALORI';
	if (nome =='M-MPA') sGruppo = 'MPA MISTO-MOVIMENTO PER L\'AUTONOMIA';
	if (nome =='M-MIN') sGruppo = 'MISTO MINORANZE LINGUISTICHE';
	if (nome =='M-LDR') sGruppo = 'MISTO LIBERAL DEMOCRATICI-REPUBBLICANI';
	if (nome =='M-ALT') sGruppo = 'MISTO';
}

/*function CercaNome(){
	var nPostoSelect;
	var count = 0;
	ApriLista();
	var ok = 'no';
	for (var i=0; i<persons.length; i++){
		if (persons[i].cognome.substring(0, document.getElementById('fcerca').cognomenome.value.length).toUpperCase() == document.getElementById('fcerca').cognomenome.value.toUpperCase()){
			document.getElementById('fcerca').nominativi.selectedIndex = i;
			ok = 'si';
			SD(i);
			break
		}
	}
	if (ok == 'no') alert('Nessun nome soddisfa la ricerca');
}*/
function CercaNome(){
	var nPostoSelect;
	var count = 0;	
	ApriLista();	
	var ok = 'no';
	//alert(persons[persons.length].cognome+" "+persons[persons.length].nome)
	for (var i=0; i<persons.length; i++){		
			if ((persons[i].cognome.substring(0, document.getElementById('fcerca').cognomenome.value.length).toUpperCase() == 
				document.getElementById('fcerca').cognomenome.value.toUpperCase())
				||
				(persons[i].cognome+" "+persons[i].nome==document.getElementById('fcerca').cognomenome.value.toUpperCase()))
			{
				document.getElementById('fcerca').nominativi.selectedIndex = i;
				ok = 'si';
				SD(i);
				break
			}
	}
	if (ok == 'no') alert('Nessun nome soddisfa la ricerca');
}

function ScriviNome(){
	//ChiudiLista();
	intposto = document.getElementById('nominativi').value;
	//alert(intposto);
	SD(intposto);
}

function LincaNome(){
	//ChiudiLista();
	intposto = document.getElementById('fcerca').nominativi.value
	//alert(intposto);
	LD(intposto)
}

function ChiudiLista(){
	if (tipoSito == 'small') document.getElementById('nominativi').style.visibility='hidden';
	else document.getElementById('divselect').style.visibility='hidden';
}

function ApriLista(){
	if (tipoSito == 'small') document.getElementById('nominativi').style.visibility='visible';
	else document.getElementById('divselect').style.visibility='visible';
}