// debug 

var bnlDebug = false;

// deprecato : vedremo se serve

// var PortalContext = "/wps/portal" ; deve essere determinato da JSP se il contesto è anonimo o autenticato



// function4bnlDebug

function alert2(obj)

{

	if ( bnlDebug ) 

		alert(obj);

}



// this function require path for URL call 

//  obj : url to call

//  new : true/false open new window



function manageUrl( listaElementi )

{
	//alert('manageUrl');
	//var PortalContext = "/wps/portal" ;
	
	var pos        = 0 ;
	var firstSlash = 0 ;
	var secondSlash= 0 ;
	var thirdSlash = -1 ;
	var forthSlash = -1 ;
	
	
	var startPCSlash = 0;
	var endPCSlash = 0;
	
	var localUrl = String(window.location);
	
	// localUrl = "http://10.232.82.137:30013/wps/portal/professionisti/MIGLIORA-LA-TUA-OPERATIVITA/Sistemi-di-incasso-e-pagamento/2/3/3/4/Incassi/POS_pagina";
	// localUrl = "http://10.232.82.137:30013/wps/portal/professionisti/MIGLIORA-LA-TUA-OPERATIVITA/MIGLIORA-LA-TUA-OPERATIVITA_page";
	// localUrl = "http://10.232.82.137:30013/wps/portal/professionisti/MIGLIORA-LA-TUA-OPERATIVITA";
	// localUrl = "http://10.232.82.137:30013/wps/portal/paentieistituzioni/Landing";
	// localUrl = "http://10.232.82.137:30013/wps/portal";
	
	// rimozione di eventuale caratere finale di #	
	if ( localUrl.indexOf("#")+1 == localUrl.length )
		localUrl = localUrl.substr(0,localUrl.length-1);
	

	//var indexFolder1 = localUrl.indexOf(PortalContext);
	//http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	//															 **5**                    

	// inizio il loop : 
	// nella forma http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	// cerco il riferimento "/" che segue il portal context - non uso il portal context per non dover modificare il js
	// 

	var count = 1;
	pos = localUrl.indexOf("/");

	while ( count < 5  ) {
   		count++;
   		pos = localUrl.indexOf("/",pos+1);
   		if ( count == 3 ) 
   			startPCSlash = pos ;		
   		//memorizzo il terzo perche' e' l'inizio del portal context
   		alert2('count:'+count+'     pos:'+pos);
	}

	// caso : http://10.232.82.137:30013/wps/portal
	if ( pos == -1 ) 
	{
		localUrl += '/';
		pos = localUrl.indexOf("/",localUrl.length-1);
		//alert2('count:5     pos:'+pos);
	}
	else
	{
		var ref = localUrl.indexOf("/",pos+1);
		if ( ref == -1 )
		{
			localUrl += '/';
		}
	}

	
	
	endPCSlash = pos;
	firstSlash = pos;
	

	
	secondSlash = localUrl.indexOf("/",firstSlash + 1 );
	//alert('secondSlash:'+secondSlash);
	if ( secondSlash != -1 )
	{
		thirdSlash = localUrl.indexOf("/",secondSlash + 1 );
		//alert('thirdSlash:'+thirdSlash);
	}

	if ( thirdSlash == -1 )
	{
		var ref = localUrl.indexOf("/",secondSlash+1);
		if ( ref == -1 )
		{
			//LocalUrl += '/';
		}
		thirdSlash = localUrl.length;
	}

	if ( secondSlash != -1 && thirdSlash != -1 )
	{	
		forthSlash = localUrl.indexOf("/",thirdSlash + 1 );
		//alert('forthSlash:'+forthSlash);
	}
	
	if ( forthSlash == -1 )
	{
		var ref = localUrl.indexOf("/",thirdSlash+1);
		if ( ref == -1 )
		{
			//LocalUrl += '/';
		}
		forthSlash = localUrl.length;
	}
		
	// nuovo parametro : PORTAL CONTEXT  ( c'e' sempre ) 
	listaElementi[3] = localUrl.substr(startPCSlash,endPCSlash-startPCSlash);
	
	/*
	if ( secondSlash != -1 )
	{
		secondSlash = localUrl.length;
	}
	*/
		
	alert2('startPCSlash '+startPCSlash);
	alert2('firstSlash   '+firstSlash);
	alert2('thirdSlash   '+thirdSlash);
	alert2('forthSlash   '+forthSlash);

	var segment = '';
	if ( secondSlash != -1 )
    	{
	    	// SEGMENT
		segment = localUrl.substr(firstSlash+1,secondSlash-firstSlash-1);
	}
	else
	{
		segment = 'Home Page';	
	}

	if ( secondSlash != -1 && thirdSlash != -1 )
    	{
		// nuovo parametro : FOLDER I LIVELLO DOPO SEGMENTO
		listaElementi[4] = localUrl.substr(secondSlash+1,thirdSlash-secondSlash-1);
	}
	else
	{
		listaElementi[4] = '';
	}

	if ( thirdSlash != -1 && forthSlash != -1 )
    	{
    		if ( thirdSlash == forthSlash  )
    		{
    			// caso : segmento/folder , senza pagina , come ultimo parametro passo il solo folder
			listaElementi[5] = listaElementi[4];
    		}
    		else
    		{
			// nuovo parametro : PATH PAGINA ESCLUSO : SEGMENTO E I LIVELLO
			listaElementi[5] = localUrl.substr(thirdSlash+1,localUrl.length-thirdSlash-1);
		}
	}
	else
	{
		listaElementi[5] = listaElementi[4];
	}

	// 
	// http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/page
	// http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page
	//                                                              ^ firstSlash
	//                                                                                    ^secondSlash

	if ( secondSlash != -1 ) 
	{
		pos = secondSlash;
		while ( pos != -1   ) {
	   		lastSlash=pos;
	   		pos = localUrl.indexOf("/",pos+1);
		}
	
		pathAliasMapping = localUrl.substr(firstSlash,lastSlash-firstSlash);
		pagenameAliasMapping = localUrl.substr(lastSlash+1);

	}	
	else
	{
		pathAliasMapping = '';
		pagenameAliasMapping = '';
		
		}

	listaElementi[0] = segment;
	listaElementi[1] = pathAliasMapping;
	listaElementi[2] = pagenameAliasMapping;
	

	// nuovo parametro : PORTAL CONTEXT 
	// listaElementi[3] = localUrl.substr(startPCSlash,endPCSlash-startPCSlash);
	
	//alert('end manageUrl');
	return listaElementi ;

	

}



// this function require path for Server call 



function manageServer()

{

	var localServer = String(window.location);

	// localServer = 'http://10.232.83.201:8080/pippo/pluto';
	// localServer = 'http://10.232.83.137:8080/pippo/pluto';

	alert2(localServer );
	var serverCalled = '';

        //alert2(localServer);
        //alert2(PortalContext.length);
        //alert2(PortalContext);

	//var indexFolder1 = localServer.indexOf(PortalContext);
	//http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	//															 **5**                    

	// 
	// inizio il loop : 
	// nella forma http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	// cerco il riferimento "/" che segue il portal context - non uso il portal context per non dover modificare il js
	// 

	var count = 1;
	pos = localServer.indexOf("/");
	while ( count < 3  ) {
   		count++;
   		pos = localServer.indexOf("/",pos+1);
	}



	firstSlash = pos;

	alert2('firstSlash '+firstSlash);

	

	var secondReference ;

	

	secondReference = localServer.indexOf(":",localServer.indexOf("/")); // per superare il primo ":" contenuto in  HTTPS:// oppure in  HTTPS://

	alert2('secondReference::'+secondReference);

	if ( secondReference != -1 )

		firstSlash = secondReference;	// se ci sonbo i ":" prendo quelli come riferimento

	

	

	// senza porta

	// http://server/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//        ^8    ^ firstSlash

	// con porta

	// http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//              ^ firstSlash

	alert2('start     ::'+localServer.indexOf("//"));
	alert2('firstSlash::'+firstSlash);

	server = localServer.substr(localServer.indexOf("//")+2,firstSlash-localServer.indexOf("//")-2);

	serverCalled = 'http://' + server;

	if ( server == '10.4.22.73' )
	{
		serverCalled = 	'http://10.4.22.73:8080'
	}

	if ( server == '10.232.82.201' || server == '10.232.82.204' || server == 'wwwcoll.bnl.it' || server == 'stagcoll.bnl.it')
	{
		// serverCalled = 	'https://cconlinecoll.newstage.e-family.it';
		serverCalled = 	'https://cconlinecoll.wwwcoll.bnl.it';
	}

	if ( server == '10.232.82.137' || server == '10.232.82.140' || server == 'wwwprod.bnl.it' || server == 'www.bnl.it' || server == 'staging.bnl.it')
	{
		serverCalled = 	'https://cconline.bnl.it';
	}	

	return serverCalled;

	

}


function manageServerBL()

{

	var localServer = String(window.location);

	// localServer = 'http://10.232.83.201:8080/pippo/pluto';
	// localServer = 'http://10.232.83.137:8080/pippo/pluto';

	alert2(localServer );
	var serverCalled = '';

        //alert2(localServer);
        //alert2(PortalContext.length);
        //alert2(PortalContext);

	//var indexFolder1 = localServer.indexOf(PortalContext);
	//http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	//															 **5**                    

	// 
	// inizio il loop : 
	// nella forma http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	// cerco il riferimento "/" che segue il portal context - non uso il portal context per non dover modificare il js
	// 

	var count = 1;
	pos = localServer.indexOf("/");
	while ( count < 3  ) {
   		count++;
   		pos = localServer.indexOf("/",pos+1);
	}



	firstSlash = pos;

	alert2('firstSlash '+firstSlash);

	

	var secondReference ;

	

	secondReference = localServer.indexOf(":",localServer.indexOf("/")); // per superare il primo ":" contenuto in  HTTPS:// oppure in  HTTPS://

	alert2('secondReference::'+secondReference);

	if ( secondReference != -1 )

		firstSlash = secondReference;	// se ci sonbo i ":" prendo quelli come riferimento

	

	

	// senza porta

	// http://server/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//        ^8    ^ firstSlash

	// con porta

	// http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//              ^ firstSlash

	alert2('start     ::'+localServer.indexOf("//"));
	alert2('firstSlash::'+firstSlash);

	server = localServer.substr(localServer.indexOf("//")+2,firstSlash-localServer.indexOf("//")-2);

	
	serverCalled = 'http://' + server;

	if ( server == '10.4.22.73' )
	{
		// serverCalled = 	'http://10.4.22.73:8080'
		// non fornito 
		serverCalled = 'http://' + server;
	}

	if ( server == '10.232.82.201' || server == '10.232.82.204' || server == 'wwwcoll.bnl.it' || server == 'stagcoll.bnl.it')
	{
		
		// serverCalled = 	'http://branchlocatorcoll.bnl.it';
		serverCalled = 	'http://branchlocatorcoll.bnl.it/trovafiliale/InitTrovaFiliale.do';
	}

	if ( server == '10.232.82.137' || server == '10.232.82.140' || server == 'wwwprod.bnl.it' || server == 'www.bnl.it' || server == 'staging.bnl.it')
	{

		//serverCalled =  'http://branchlocator.bnl.it';
		serverCalled =  'http://trovafiliale.bnl.it/trovafiliale/InitTrovaFiliale.do';
	}	

	return serverCalled;

	

}

/*

	

	1° parametro chiamata alla funzione applicativa

	2° parametro apertura popup



*/

function sendCallWSegment(url2Call , newW)

{



	/*

		listaElementi [0] --> Segmento

		listaElementi [1] --> path preso dall'alias name

		listaElementi [2] --> page preso dall'alias name

	*/



	var listaElementi = new Array(6);

	var url2Call      = '' ;

	

	listaElementi = manageUrl(listaElementi);

	

	// chiamata ( simulata ) per sondaggi ....

	url2Call = url2Call + '?Segment=' + listaElementi[0] ;

	

	

	if ( newW == true) 

	{

		window.open(url2Call,'BNL','status=0,resizable=1');	

	}

	else

	{

		window.location = url2Call;	

	}

	

}

function getServer()

{

	var localServer = String(window.location);

	// localServer = 'http://10.232.83.201:8080/pippo/pluto';

	alert2(localServer );
	var serverCalled = '';

	// localServer = 'http://10.232.82.137:30013/wps/portal/professionisti/MIGLIORA-LA-TUA-OPERATIVITA/Sistemi-di-incasso-e-pagamento/Incassi/POS';
	//var indexFolder1 = localServer.indexOf(PortalContext);
	//http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	//															 **5**                    

	

	// 
	// inizio il loop : 
	// nella forma http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	// cerco il riferimento "/" che segue il portal context - non uso il portal context per non dover modificare il js
	// 

	var count = 1;
	pos = localServer.indexOf("/");

	while ( count < 3  ) 
	{
   		count++;
   		pos = localServer.indexOf("/",pos+1);
	}



	firstSlash = pos;

	alert2('firstSlash '+firstSlash);

	

	var secondReference ;

	secondReference = localServer.indexOf(":",localServer.indexOf("/")); // per superare il primo ":" contenuto in  HTTPS:// oppure in  HTTP://
	alert2('secondReference::'+secondReference);

	if ( secondReference != -1 )
		firstSlash = secondReference;	// se ci sonbo i ":" prendo quelli come riferimento
		
	// senza porta

	// http://server/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//        ^8    ^ firstSlash

	// con porta

	// http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//              ^ firstSlash
	server = localServer.substr(localServer.indexOf("//")+2,firstSlash-localServer.indexOf("//")-2);
	return server	;

}

/* link verso CCOnline - popUpApplicazioni */
function popUpApplicazioni(locType)
{

	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*
		listaElementi [0] --> Segmento
		listaElementi [1] --> path preso dall'alias name
		listaElementi [2] --> page preso dall'alias name
	*/

	// Default Server di sviluppo
	serverCalled = manageServer();

	var URLSegnalazioni = '';
	var titleWin        = '' ;

	if ( locType == '1')
	{
		// segnalazioni a bnl
		URLSegnalazioni=serverCalled +'/cconline/CCONLINE/ExecuteRichiestaSegnalazioni.do?CodProv=S&Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
		titleWin = 'Segnalazioni a BNL' ;
	}

	

	if ( locType == '2')
	{	
		//
		URLSegnalazioni=serverCalled +'/cconline/CCONLINE/ExecuteRichiestaSegnalazioni.do?CodProv=S2&Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
		titleWin = 'Manda una email' ;
	}

	

	if ( locType == '3')
	{
		//fatti ricontattare
		URLSegnalazioni=serverCalled +'/cconline/CCONLINE/ExecuteRichiestaMail.do?&Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
		titleWin = 'Fatti richiamare' ;
	}	

	if ( locType == '4')
	{
		//prendi un appuntamento
		URLSegnalazioni=serverCalled +'/cconline/CCONLINE/ExecuteRichiestaAppuntamento.do?Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
		titleWin = 'Prendi un appuntamento' ;
	}

	popUpLayer(URLSegnalazioni,titleWin,'formLarge','2');

}

// 
// New Function AddGrafo per  passaggio valore relativo a server chiamante ( server name del browser )
//
function addGrafo  (server_http_risorse,portal_context,path,larghezza,altezza,transp,variabili,name)
{
	var server_risorse = '';
	var portalContext  = '';
	//server_risorse = 'http://' + getServer();

        var variabileDati = 'xmllink=' + server_risorse  + variabili.substr(variabili.indexOf("/",1));	
	
	//alert('201 :: addGrafoEngine('+server_risorse+','+portalContext+','+server_risorse+path+','+larghezza+','+altezza+','+transp+','+variabileDati+','+name+')');
	addGrafoEngine(server_risorse,portalContext,server_risorse+path,larghezza,altezza,transp,variabileDati,name);
}

/* link verso CCOnline - Segnalazioni */
function popupSegnalazioni(var1){
	
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*
		listaElementi [0] --> Segmento
		listaElementi [1] --> path preso dall'alias name
		listaElementi [2] --> page preso dall'alias name
	*/
	
	URLSegnalazioni=manageServer()+'/cconline/CCONLINE/ExecuteRichiestaSegnalazioni.do?CodProv=S&ArgInt='+var1+'&Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
	popUpLayer(URLSegnalazioni, 'Segnalazioni a BNL', 'formLarge', 'Segnalazioni')
}

/* link verso CCOnline - InviaEmail */
function popupInviaEmail(var1){
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*
		listaElementi [0] --> Segmento
		listaElementi [1] --> path preso dall'alias name
		listaElementi [2] --> page preso dall'alias name
	*/

	URLSegnalazioni=manageServer()+'/cconline/CCONLINE/ExecuteRichiestaSegnalazioni.do?CodProv=S2&ArgInt='+var1+'&Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
	popUpLayer(URLSegnalazioni, 'Manda una email', 'formLarge', 'InvioEmail')

}


/* link verso CCOnline - FattiRicontattare*/
function popupFattiRicontattare(var1){
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*
		listaElementi [0] --> Segmento
		listaElementi [1] --> path preso dall'alias name
		listaElementi [2] --> page preso dall'alias name
	*/

	URLSegnalazioni=manageServer()+'/cconline/CCONLINE/ExecuteRichiestaMail.do?ArgInt='+var1+'&Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
	popUpLayer(URLSegnalazioni, 'Fatti Ricontattare', 'formLarge', 'FattiRicontattare')

}
/* 
	nb x marco
	le due funzioni sotto si posso unire in una se lato bnl si accetta il valore nullo
	popupPrendiUnAppuntamento(var) con url  &source=prendiappuntamento&source_params='+var1;
	popupPrendiUnAppuntamento() con url  &source=prendiappuntamento&source_params=';
*/
/* link 'prendi appuntamento' - 19/12/2008 */
function popupPrendiUnAppuntamento(var1){

	// funzione chiamata dalla spalla destra
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	URLBL=manageServerBL()+'?lingua=it&type='+listaElementi[0]+'&source=prendiappuntamento&source_params='+var1;
	//alert(URLBL);
	popUpLayer(URLBL, 'Prendi Un Appuntamento', 'large-bl', 'PrendiUnAppuntamento')
	
}
/* link 'prendi appuntamento' - 19/12/2008 */
function popupPrendiApp(){
	
	// funzione chiamata dalla spalla destra
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	URLBL=manageServerBL()+'?lingua=it&type='+listaElementi[0]+'&source=prendiappuntamento';
	//alert(URLBL);
	popUpLayer(URLBL, 'Prendi Un Appuntamento', 'large-bl', 'PrendiUnAppuntamento');
}


/* link Trova Agenzia */
function popupBL(){
	
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	// URLBL=manageServerBL()+'/branchlocator/InitBranchLocator.do?lingua=it&type='+listaElementi[0]+'&service=\'\'';
	URLBL=manageServerBL()+'?lingua=it&type='+listaElementi[0] ; //+'&service=\'\''; modifica 1 dic
	//popUpLayer(URLBL, 'Trova Agenzia', 'form', 'TrovaAgenzia')
	window.open(URLBL,'popup','width=800,height=600,toolbar=no,locations=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=100,left=100');
}



/* 

bnlgroup/CFPScopriBnl_en 
bnlgruppo/CFPScopriBnl 

corporate/CFPCorporate 
corporate_en/CFPCorporate_en 

imprese/CFPImprese 
imprese_en/CFPImprese_en 

individuals/CFPIndividuiFamiglie_en 
individuiefamiglie/CFPIndividuiFamiglie 

paandinstitutions/CFPPaEntiIstituzioni_en 
paentieistituzioni/CFPPaEntiIstituzioni 

private/CFPPRivate 
private_en/CFPPRivate_en 

professionals/CFPProfessionisti_en 
professionisti/CFPProfessionisti 


*/
function linkIndiceCFP()
{	

	var linkCFP   		= '';
	var listaElementi 	= new Array(4);
	var urlMappingCFP 	= '' ;
	
	listaElementi = manageUrl(listaElementi);

	urlMappingCFP = 'CFP' + listaElementi[0];
								
	// cfp = alias name della pagina indice di CFP
	linkCFP = listaElementi[3] + '/' + listaElementi[0] + '/' + urlMappingCFP ; 
	
	//alert(linkCFP);
	window.location.href = linkCFP;
	
}


function isProduction()
{

	var server = getServer();
		
	if ( server == 'www.bnl.it')
	{
		return true ;
	}		

	return false;	
}

//function googleAnalytics()
function executeWeboramaScript()
{

	document.write('<script language="JavaScript" type="text/javascript" >');
	document.write('_uacct = "UA-268046-2";');
	document.write('urchinTracker();');
	document.write('</script>');
//	alert("analitycs");

}

//function executeWeboramaScript()
function googleAnalytics()
{

	var WRP_ID= 375982;
	var WRP_SECTION='';
	var WRP_SUBSECTION='';
	var WRP_SECTION_GRP= WRP_ID;
	var WRP_SUBSECTION_GRP= WRP_SECTION;
	var WRP_CONTENT= '';
	var WRP_CHANNEL= '';
	
	
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*	listaElementi [0] --> Segmento
		listaElementi [1] --> path preso dall'alias name
		listaElementi [2] --> page preso dall'alias name
		listaElementi [3] --> Portal Context
		listaElementi [4] --> Folder di I livello ( la prima dopo il segmento ) 
		listaElementi [5] --> path pagina escluso segmento e I Livello Folder
	*/
	WRP_SECTION    = listaElementi [0];
	WRP_SUBSECTION = listaElementi [4];
	WRP_CONTENT    = listaElementi [5];


	/* Profondeur Frame */
	var WRP_ACC=0;
	
	wreport_ok=0;
	
alert2( WRP_SECTION + ' - ' + WRP_SUBSECTION + ' - ' + WRP_CONTENT);

	var w_counter = new wreport_counter(WRP_SECTION, WRP_SUBSECTION, WRP_ID, WRP_ACC, WRP_CHANNEL, WRP_SECTION_GRP, WRP_SUBSECTION_GRP);
	w_counter.add_content(WRP_CONTENT);
	w_counter.count();
	
}

function querystring(id) {
  var query = location.search;
  query = query.substring(1,query.length);
  var parametro = query.split('&');
  for (j=0;j<parametro.length;j++) {
    var voce = parametro[j].split('=');
    if (voce[0]==id) {
      var ap = voce[1].split('+');
      voce[1] = ap[0];
      for (k=1;k<ap.length;k++) voce[1] += ' ' + ap[k];
      voce[1] = unescape(voce[1]);
      return voce[1];
    }
  }
}


function showSpallaDx()
{
	var listaElementi = new Array(6);
	
	if(querystring('segmento')){
		listaElementi[0] = querystring('segmento');
	} else {
		listaElementi = manageUrl(listaElementi);
	}
	
	if ( listaElementi[0] == 'individuiefamiglie' || listaElementi[0] == 'individuiefamiglie_en') 
	{
		$('cosanepensi_1').style.display = "block";
		$('cosanepensi_2').style.display = "none";
		$('cosanepensi_3').style.display = "none";
		$('cosanepensi_4').style.display = "none";	
		$('entraincontatto_1').style.display = "block";
		$('entraincontatto_2').style.display = "none";
		$('entraincontatto_3').style.display = "none";
		$('entraincontatto_4').style.display = "none";			
		
	}else if ( listaElementi[0] == 'imprese' || listaElementi[0] == 'imprese_en' || listaElementi[0] == 'professionisti_en' || listaElementi[0] == 'professionisti' ) {
	
		$('cosanepensi_1').style.display = "none";
		$('cosanepensi_2').style.display = "block";
		$('cosanepensi_3').style.display = "none";
		$('cosanepensi_4').style.display = "none";	
		$('entraincontatto_1').style.display = "none";
		$('entraincontatto_2').style.display = "block";
		$('entraincontatto_3').style.display = "none";
		$('entraincontatto_4').style.display = "none";			
		
	} else if ( listaElementi[0] == 'paentieistituzioni' ||  listaElementi[0] == 'paentieistituzioni_en' ) 	{
	
		$('cosanepensi_1').style.display = "none";
		$('cosanepensi_2').style.display = "none";
		$('cosanepensi_3').style.display = "block";
		$('cosanepensi_4').style.display = "none";	
		$('entraincontatto_1').style.display = "none";
		$('entraincontatto_2').style.display = "none";
		$('entraincontatto_3').style.display = "block";
		$('entraincontatto_4').style.display = "none";			
		
	} else if ( listaElementi[0] == 'corporate' || listaElementi[0] == 'corporate_en'  ) {
	
		$('cosanepensi_1').style.display = "none";
		$('cosanepensi_2').style.display = "none";
		$('cosanepensi_3').style.display = "none";
		$('cosanepensi_4').style.display = "block";	
		$('entraincontatto_1').style.display = "none";
		$('entraincontatto_2').style.display = "none";
		$('entraincontatto_3').style.display = "none";
		$('entraincontatto_4').style.display = "block";		
			
	} else if ( listaElementi[0] == 'scopribnl' || listaElementi[0] == 'scopribnl_en' || listaElementi[0] == 'private' || listaElementi[0] == 'private_en'  ) {

	
		$('cosanepensi_1').style.display = "none";
		$('cosanepensi_2').style.display = "none";
		$('cosanepensi_3').style.display = "none";
		$('cosanepensi_4').style.display = "none";	
		$('entraincontatto_1').style.display = "none";
		$('entraincontatto_2').style.display = "none";
		$('entraincontatto_3').style.display = "none";
		$('entraincontatto_4').style.display = "none";		
			
	} else {
	
		$('cosanepensi_1').style.display = "none";
		$('cosanepensi_2').style.display = "none";
		$('cosanepensi_3').style.display = "none";
		$('cosanepensi_4').style.display = "block";	
		$('entraincontatto_1').style.display = "none";
		$('entraincontatto_2').style.display = "none";
		$('entraincontatto_3').style.display = "none";
		$('entraincontatto_4').style.display = "block";			
	}	
}

function callDoubleClick()
{

	var refPage1 = 'centopercento' ;
	var refPage2 = 'Appuntamento 1' ;
	var refPage3 = 'Appuntamento 2' ;
	var refPage4 = 'Appuntamento 3' ;
	var refPage5 = 'landing-TrasformaMutuo-BNL' ;
	var refPage6 = 'Surroga' ;
	var refPage7 = 'PRIVATE';
		
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*	listaElementi [0] --> Segmento
		listaElementi [1] --> path preso dall'alias name
		listaElementi [2] --> page preso dall'alias name
		listaElementi [3] --> Portal Context
		listaElementi [4] --> Folder di I livello ( la prima dopo il segmento ) 
		listaElementi [5] --> path pagina escluso segmento e I Livello Folder
	*/
	
	var parametro1 = '';
	var parametro2 = '';
	
	if ( listaElementi[2] == refPage1 ){ 		
	
		parametro1 = 'istit990';
		parametro2 = 'landi902';
		
	} else if ( listaElementi[2] == refPage2 ){ 		
	
		parametro1 = 'istit990';
		parametro2 = 'appun625';
		
	} else if ( listaElementi[2] == refPage3 ){ 		
	
		parametro1 = 'istit990';
		parametro2 = 'appun775';
		
	} else if ( listaElementi[2] == refPage4 ){ 		
	
		parametro1 = 'istit990';
		parametro2 = 'appun590';
		
	} else if ( listaElementi[2] == refPage5 ){ 		
	
		parametro1 = 'mutuo376';
		parametro2 = 'datir064';
		
	} else if ( listaElementi[2] == refPage6 ){ 		
	
		parametro1 = 'mutuo376';
		parametro2 = 'mutui030';
		
	} else if( listaElementi[2] == refPage7 ){
	
		parametro1 = 'bnlql482';
		parametro2 = 'priva368';
	}
	

	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	document.write('<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1453247;type='+parametro1+';cat='+parametro2+';ord='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>');

}


//Home Page Beta
function manageServerHPB()
{

	var localServer = String(window.location);

	// localServer = 'http://10.232.83.201:8080/pippo/pluto';
	// localServer = 'http://10.232.83.137:8080/pippo/pluto';

	alert2(localServer );
	var serverCalled = '';

        //alert2(localServer);
        //alert2(PortalContext.length);
        //alert2(PortalContext);

	//var indexFolder1 = localServer.indexOf(PortalContext);
	//http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	//															 **5**                    

	// 
	// inizio il loop : 
	// nella forma http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/...
	// cerco il riferimento "/" che segue il portal context - non uso il portal context per non dover modificare il js
	// 

	var count = 1;
	pos = localServer.indexOf("/");
	while ( count < 3  ) {
   		count++;
   		pos = localServer.indexOf("/",pos+1);
	}



	firstSlash = pos;

	alert2('firstSlash '+firstSlash);

	

	var secondReference ;

	

	secondReference = localServer.indexOf(":",localServer.indexOf("/")); // per superare il primo ":" contenuto in  HTTPS:// oppure in  HTTPS://

	alert2('secondReference::'+secondReference);

	if ( secondReference != -1 )

		firstSlash = secondReference;	// se ci sonbo i ":" prendo quelli come riferimento

	

	

	// senza porta

	// http://server/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//        ^8    ^ firstSlash

	// con porta

	// http://server:porta/portalcontext_parte1/portalcontext_parte2/FOLEDER_PRIMO_LIVELLO/SECONDO_LIVELLO/page

	//              ^ firstSlash

	alert2('start     ::'+localServer.indexOf("//"));
	alert2('firstSlash::'+firstSlash);

	server = localServer.substr(localServer.indexOf("//")+2,firstSlash-localServer.indexOf("//")-2);

	serverCalled = 'http://' + server;

	if ( server == '10.4.22.73' )
	{
		serverCalled = 	'https://efa.secure.bnl.it:30045'
	}

	if ( server == '10.232.82.201' || server == '10.232.82.204' || server == 'wwwcoll.bnl.it' || server == 'stagcoll.bnl.it')
	{
		// serverCalled = 	'https://cconlinecoll.newstage.e-family.it';
		serverCalled = 	' https://bankcoll.secure.bnl.it';
	}

	if ( server == '10.232.82.137' || server == '10.232.82.140' || server == 'wwwprod.bnl.it' || server == 'www.bnl.it' || server == 'staging.bnl.it')
	{
		serverCalled = 	'https://banking.secure.bnl.it';
	}	

	return serverCalled;

	

}

function linkHomePageBetaPrivati()
{	
	var server = serverCalled = manageServerHPB();
	
	// cfp = alias name della pagina indice di CFP
	var linkPrivati = server + '';
	
	//alert(linkCFP);
	window.location.href = linkPrivati;
	
	return false;
	
}

function linkHomePageBetaAziende()
{	
	var server = serverCalled = manageServerHPB();
	
	// cfp = alias name della pagina indice di CFP
	var linkPrivati = server + '';
	
	//alert(linkCFP);
	window.location.href = linkPrivati;
	
	return false;
}

function googleEnhanced()
{

document.write('<script language="JavaScript" type="text/javascript">');
document.write('var google_conversion_id = 1051707610;');
document.write('var google_conversion_language = "it";');
document.write('var google_conversion_format = "1";');
document.write('var google_conversion_color = "ffffff";');
document.write('var google_conversion_label = "jaiMCPaeYhDakb_1Aw";');
document.write('</script>');

document.write('<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">');
document.write('</script>');
document.write('<noscript>');
document.write('<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1051707610/?label=jaiMCPaeYhDakb_1Aw&amp;script=0"></img>');
document.write('</noscript>');

document.write('<script language="JavaScript" type="text/javascript">');
document.write('var google_conversion_id = 1052810994;');
document.write('var google_conversion_language = "it";');
document.write('var google_conversion_format = "1";');
document.write('var google_conversion_color = "ffffff";');
document.write('var google_conversion_label = "m9ZfCOiYXxDyvYL2Aw";');
document.write('</script>');

document.write('<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">');
document.write('</script>');
document.write('<noscript>');
document.write('<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1052810994/?label=m9ZfCOiYXxDyvYL2Aw&amp;script=0"></img>');
document.write('</noscript>');

}


/* link verso CCOnline - FattiRichiamare*/
function popupFattiRichiamare(var1){
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*
	 listaElementi [0] --> Segmento
	 listaElementi [1] --> path preso dall'alias name
	 listaElementi [2] --> page preso dall'alias name
	*/

	URLSegnalazioni=manageServer()+'/cconline/CCONLINE/ExecuteRichiestaMail.do?ArgInt='+var1+'&Segmento='+listaElementi[0]+'&ACTION_TO_CALL=/ToCCOnlineAction.do';
	popUpLayer(URLSegnalazioni, 'Fatti Richiamare', 'formLarge','FattiRichiamare');
}


function scriptPerPagina()
{

	var urlToMath1 = 'PRESTITI-PER-I-TUOI-DESIDERI/landing-prestito-BNL-pensione-dinamica';
	var urlToMath2 = 'Tool/Cessione_del_quinto';
	var urlAttuale = '';	
	var listaElementi = new Array(6);
	listaElementi = manageUrl(listaElementi);
	/*	listaElementi [0] --> Segmento
		listaElementi [1] --> path preso dall'alias name
		listaElementi [2] --> page preso dall'alias name
		listaElementi [3] --> Portal Context
		listaElementi [4] --> Folder di I livello ( la prima dopo il segmento ) 
		listaElementi [5] --> path pagina escluso segmento e I Livello Folder
	*/
	
	if ( listaElementi[0] != 'individuiefamiglie' && listaElementi[0] != 'individuiefamiglie_en'){ 		
	
		return false ;
		
	} else {
	
		urlAttuale = listaElementi [4] + '/' + listaElementi [5];
		
		if(urlAttuale == urlToMath1) {
		
			// write primo script
			
			// Tag for Activity Group: CDQ, Activity: Landing CDQ 
			// Web site URL where tag should be placed: http://www.bnl.it/wps/portal/individuiefamiglie/PRESTITI-PER-I-TUOI-DESIDERI/landing-prestito-BNL-pensione-dinamica 
			
			document.write('<SCRIPT language="JavaScript">');
			document.write('var axel = Math.random()+"";');
			document.write('var a = axel * 10000000000000;');
			document.write('document.write(\'<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1453247;type=cdqyf338;cat=landi961;ord=\'+ a + \'?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>\');');
			document.write('</SCRIPT>');
			document.write('<NOSCRIPT>');
			document.write('<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1453247;type=cdqyf338;cat=landi961;ord=1?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>');
			document.write('</NOSCRIPT>');

			// Google Code for Landing CDQ Conversion Page 
			document.write('<script language="JavaScript" type="text/javascript">');
			document.write('<!--');
			document.write('var google_conversion_id = 1051513684;');
			document.write('var google_conversion_language = "it";');
			document.write('var google_conversion_format = "3";');
			document.write('var google_conversion_color = "ffffff";');
			document.write('var google_conversion_label = "-_v6CIrQiwEQ1Kaz9QM";');
			document.write('//-->');
			document.write('</script>');
			document.write('<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">');
			document.write('</script>');
			document.write('<noscript>');
			document.write('<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1051513684/?label=-_v6CIrQiwEQ1Kaz9QM&amp;guid=ON&amp;script=0"/>');
			document.write('</noscript>');
			
		} else if (urlAttuale == urlToMath2){
		
			// write secondo script
			
			// Tag for Activity Group: CDQ, Activity: Simula CDQ 
			// Web site URL where tag should be placed: http://www.bnl.it/wps/portal/individuiefamiglie/Tool/Cessione_del_quinto?state=solo 
			document.write('<SCRIPT language="JavaScript">');
			document.write('var axel = Math.random()+"";');
			document.write('var a = axel * 10000000000000;');
			document.write('document.write(\'<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1453247;type=cdqyf338;cat=simul073;ord=\'+ a + \'?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>\');');
			document.write('</SCRIPT>');
			document.write('<NOSCRIPT>');
			document.write('<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1453247;type=cdqyf338;cat=simul073;ord=1?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>');
			document.write('</NOSCRIPT>');
		
			// Google Code for Simulatore Conversion Page 
			document.write('<script language="JavaScript" type="text/javascript">');
			document.write('<!--');
			document.write('var google_conversion_id = 1051513684;');
			document.write('var google_conversion_language = "it";');
			document.write('var google_conversion_format = "3";');
			document.write('var google_conversion_color = "ffffff";');
			document.write('var google_conversion_label = "UTrECOTQiwEQ1Kaz9QM";');
			document.write('//-->');
			document.write('</script>');
			document.write('<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">');
			document.write('</script>');
			document.write('<noscript>');
			document.write('<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1051513684/?label=UTrECOTQiwEQ1Kaz9QM&amp;guid=ON&amp;script=0"/>');
			document.write('</noscript>');

		}
	}	
}
