function adjustImgSrc(){

	animatedcollapse.addDiv('aperto', 'fade=1,height=52px');
	animatedcollapse.addDiv('sotto', 'fade=1');
	animatedcollapse.addDiv('nomibanche', 'fade=1,height=270px');
	animatedcollapse.init();
	
	var ilist = document.getElementsByTagName("img");
	
	for(var i = 0; i < ilist.length; i++) {		
	    if(ilist[i].src.indexOf(webDynamicPath)!=-1) {
	    	ilist[i].src=ilist[i].src.replace(webDynamicPath,webStaticPath);//definita in head.jsp
	    }
	}
	
	adjustLinkSrc();
	//gestisciVisibilita();
	
	animatedcollapse.hide('nomibanche');
				
	fixBarre();
	
	checkHeightCloseBars();
	
	loading(false);
	updateFooter();
}

function toOpenInNewWindow(url){
	if(	
        url.indexOf('ct=application/')!=-1 ||
        url.indexOf('.pdf')!=-1 || 
		url.indexOf('.doc')!=-1 || 
		url.indexOf('.jpg')!=-1 || 
		url.indexOf('.png')!=-1 || 
		url.indexOf('.gif')!=-1 ||
		url.indexOf('.zip')!=-1 ||  
		url.indexOf('.xls')!=-1 || 
		url.indexOf('.zip')!=-1 
	)
		return true;
	else
		return false; 
}

function adjustLinkSrc(){
	
	var oneTwoPath = "/scriptWeb20/vetrina/contentData/view";

	//PER L'AMBIENTE DI PREVIEW	
	if(webDynamicPath.indexOf('Pwst0')!=-1)
		oneTwoPath = "/scriptPwst0/vetrina/contentData/view";
		
	//var oneTwoPath = "http://localhost:7159/scriptWeb20/vetrina/contentData/view/Eventi?id=";
	//var oneTwoPath = "http://swwmos55.sede.corp.sanpaoloimi.com:8574/scriptWeb20/vetrina/contentData/view?id=";
	var jsPath = "javascript:loadContent3('"
	
	var ilist = document.getElementsByTagName("a");
	
	for(var i = 0; i < ilist.length; i++) {		
	    if(	ilist[i].href.indexOf(oneTwoPath)!=-1 && 
            ilist[i].href.indexOf('ct=application/')==-1 &&
	    	ilist[i].href.indexOf('.pdf')==-1 && 
	    	ilist[i].href.indexOf('.doc')==-1 && 
	    	ilist[i].href.indexOf('.jpg')==-1 && 
	    	ilist[i].href.indexOf('.png')==-1 && 
	    	ilist[i].href.indexOf('.gif')==-1 && 
	    	ilist[i].href.indexOf('.xls')==-1 && 
	    	ilist[i].href.indexOf('.zip')==-1) {
	    	
	    	//ilist[i].href=ilist[i].href.replace(oneTwoPath,jsPath)+"')";
	    	var id = ilist[i].href.substr( ilist[i].href.length - 20 );
	    	ilist[i].href = jsPath + id + "')";
	    }
	    else{
	    	if(	
	    		toOpenInNewWindow(ilist[i].href)
	    	){
	    		ilist[i].setAttribute("href", ilist[i].href);
	    		ilist[i].setAttribute("target", "_blank");
				//ilist[i].setAttribute("onclick", "javascript:window.open('"+ilist[i].href+"', '_blank');");  	
	    	}
	    }
	}
	// fix Stringa "I PIU RICERCATI"
	var arTD = document.getElementsByTagName('td');
	for (var i = arTD.length - 1; i >= 0; i--) {
		var elmTD = arTD[i];
		if (elmTD.getAttribute("class") == "google_tabella_tags") {
			if ((elmTD.innerHTML).indexOf('ricercati:') != -1) {
				elmTD.innerHTML = 'I pi&ugrave ricercati:';
			}
		}
	}
}

function fixBarre(){
	try{
		// Should check if they are open or not
		if(document.getElementById('aperto').style.display != "none") {
			document.getElementById('chiuso').style.borderRight="none";
			//document.getElementById('chiuso').style.width="205px"; //IE6 fix
			/* new */            
			document.getElementById('aperto').style.border = "1px solid #CDCDCD";			
			document.getElementById('aperto').style.borderLeft = "0px";		
		}
			
		if(document.getElementById('sotto').style.display != "none"){
			document.getElementById('chiuso2').style.borderRight="none";
			//document.getElementById('chiuso2').style.width="205px"; //IE6 fix	
			/* new */
			document.getElementById('sotto').style.border = "1px solid #CDCDCD";			
			document.getElementById('sotto').style.borderLeft = "0px";
		}
	}
	catch(e){}	
}
function hideBoxesGoogle(val){
// Nasconde ComboBox coperte dal Google Search
	if(val) {
		try {
			document.getElementById('finanziamento').style.visibility="hidden";
			document.getElementById('settore').style.visibility="hidden";
		} catch(e) {}
	}
	else {
		try {
			document.getElementById('finanziamento').style.visibility="visible";
			document.getElementById('settore').style.visibility="visible";
		} catch(e) {}
	}
}

function hideBoxes(val){
// Nasconde ComboBox coperte dalla barra Servizi
	if(val) {
		try {
			document.getElementById('tipologia').style.visibility="hidden";
		} catch(e) {}
	}
	else {
		try {
			document.getElementById('tipologia').style.visibility="visible";
		} catch(e) {}
	}
}

function checkHeightCloseBars(){
	hideBoxes();
	// Should check if they are open or not	
	if(document.getElementById('content3').offsetHeight >380) {
		animatedcollapse.hide('aperto');
		changeme('myIMG', 'block');
		animatedcollapse.hide('sotto');
		changeme2('myIMG2', 'block');		
	}	
}

function loadMainContent(contentId){
	
	if(directLoad)  {
		var sUrl=onetwoContentPath; //contenuto di onetwo per la pagina iniziale contenitrice
		sUrl=sUrl+onetwoContentMenu;

		var ajax = new Ajax("redirect.jsp?noDiv=1&sUrl="+sUrl, {
				method: 'post',
				evalScripts : true,
				update : 'colContainerLeftExt',
				onComplete : function() {	updateBoxEventi(); loadBoxes(); adjustImgSrc(); }
		});
		ajax.request();
		
		var sUrl=onetwoContentPath; //contenuto di onetwo per la pagina iniziale contenitrice
		var contentToLoad=self.location.href.substring(self.location.href.indexOf("=")+1);
		sUrl=sUrl+contentToLoad;
		var ajax = new Ajax("redirect.jsp?noDiv=1&sUrl="+sUrl, {
				method: 'post',
				evalScripts : true,
				update : 'wrapperContainer3',
				onComplete : function() {	updateBoxEventi(); loadBoxes(); adjustImgSrc(); }
		});
		ajax.request();
	}
	else	
	{
		var sUrl=onetwoContentPath; //contenuto di onetwo per la pagina iniziale contenitrice
		sUrl=sUrl+contentId;
		var ajax = new Ajax("redirect.jsp?noDiv=1&sUrl="+sUrl, {
				method: 'post',
				evalScripts : true,
				update : 'colMacro',
				onComplete : function() {	updateBoxEventi(); loadBoxes(); adjustImgSrc(); }
		});
		ajax.request();
	}
	
	loading(true);

	//updateHeader();
	//updateFooter();
}

function loadBoxes(){
	// Load both boxes on the right
	var sUrl=onetwoContentPath; //contenuto di onetwo per la pagina iniziale contenitrice
	var dUrl=sUrl+onetwoContentBox1;
	var box1 = new Ajax("redirect.jsp?noDiv=1&sUrl="+dUrl, {
			method: 'post',
			evalScripts : true,
			update : 'boxL2' /* boxR1 */
				});				
	box1.request();
	
	dUrl=sUrl+onetwoContentBox2;
	var box2 = new Ajax("redirect.jsp?noDiv=1&sUrl="+dUrl, {
			method: 'post',
			evalScripts : true,
			update : 'boxR2'
				});				
	box2.request();
		
	dUrl=sUrl+onetwoContentBox3;
	var box0 = new Ajax("redirect.jsp?noDiv=1&sUrl="+dUrl, {
			method: 'post',
			evalScripts : true,
			update : 'bannerContainerLeft' 
				});				
	box0.request();

}

function loadPageInId(url,divId) {
	
	if (url.indexOf("/home.jsp?id=") != -1) {
		// fix the div
		document.getElementById('content3').style.border = "1px solid #DADADA";
		document.getElementById('wrapperContainer3').style.padding = "10px";
		url = url.replace("/home.jsp?id=","/redirect.jsp?sUrl=mc/load_content.jsp?id=");
	}

	var ajax = new Ajax(url, {
		method: 'get',
		evalScripts : true,
		update : divId,
		onComplete : adjustImgSrc
		});
	
	loading(true);
	ajax.request();
}

function loadPage(url){
	//loadPageInId(url,'content3');
	document.getElementById('content3').style.border = "0px";
	document.getElementById('wrapperContainer3').style.padding = "0px";
	loadPageInId(url,'wrapperContainer3');	
}

function updateBox(contentId,divId){
	var sUrl=onetwoContentPath; //contenuto di onetwo per la pagina iniziale contenitrice
	var dUrl=sUrl+contentId;
	var box = new Ajax("redirect.jsp?noDiv=1&sUrl="+dUrl, {
		method: 'post',
		evalScripts : true,
		update : divId
	});	
	box.request();
}

function loadContent3(contentId){

	displayFixes();
	
	var sUrl=onetwoContentPath; //contenuto di onetwo per la pagina iniziale contenitrice
	sUrl=sUrl+contentId;
	
	// if HTML update the DIV
	var ajax = new Ajax("redirect.jsp?sUrl="+sUrl, {
		method: 'post',
		evalScripts : true,
		update : 'wrapperContainer3', /* 'content3' */
		onComplete : adjustImgSrc
	});
	// hide the backButton div
	removeHistory();
	
	loading(true);			
	ajax.request();
}

function displayFixes(){
	try
	{
		// fix the div
		document.getElementById('content3').style.border = "1px solid #DADADA";
		document.getElementById('wrapperContainer3').style.padding = "10px";
		// fix the back button
		removeHistory();
	}
	catch(e)
	{ 
	}

}

function loadContent3SelectRegion(regionId){
	var sUrl=onetwoContentPath; //contenuto di onetwo per la pagina iniziale contenitrice
	sUrl=sUrl+onetwoRicercaAgevolazioni; //contenuto pagina html in onetwo con la ricerca agevolazioni
	
	// if HTML update the DIV
	var ajax = new Ajax("redirect.jsp?sUrl="+sUrl, {
		method: 'post',
		evalScripts : true,
		update : 'wrapperContainer3',
		onComplete : function(){
				adjustImgSrc();
				highlightRegion2(regionId);
		}
	});
	
	loading(true);			
	ajax.request();
}

function checkFileType(sUrl){
	var xmlobj=null;
    try{
        // instantiate object for Firefox, Nestcape, etc.
        xmlobj=new XMLHttpRequest();
    }
    catch(e){    
    	xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
    }
    
    //alert(sUrl);
	xmlobj.open("GET", sUrl, false);
	//xmlobj.onreadystatechange = useHttpResponse(xmlobj);
	xmlobj.send(null);
	
	
	if ( te == "chunked" ){
		return true;
	}
	else {
		return false;
	}	
}

function move_in(img_name,img_src) {
	document[img_name].src=basePath+webStaticPath+"images/"+img_src;
		
	}

function move_out(img_name,img_src) {
	document[img_name].src=basePath+webStaticPath+"images/"+img_src;
}

//funzione provvisoria, per evitare emergenze per cambio footer
function updateFooter(){
	var footerHtml ='<ul class="voci-tbl"><li><div class="title-name"><img src="/portalWeb20/vetrina/mediocredito/images/copirigth.gif"><strong> Mediocredito Italiano 2009 </strong></div><div class="title-piva"><strong>Partita Iva 13300400150</strong></div><div class="title-space"></div><div><a href="javascript:loadContent3('+ onetwoSchedaDatiSociali +');updateBoxEventi();">Dati Sociali</a></div><div><a href="javascript:loadContent3('+ onetwoPolicyPrivacy +');updateBoxEventi();">Policy Privacy</a></div><div><a href="javascript:loadContent3('+onetwoTrasparenza+');updateBoxEventi();">Trasparenza e Reclami</a>	</div><div><a href="javascript:loadContent3('+oneTwoSchedaPrivacy+');updateBoxEventi();">Privacy</a>	</div></li></ul>';
	var googleopen = '<script type="text/javascript">function googleopen(url){saveHistory();obj = document.getElementById(\'googleopenlink\');if (window.location.protocol == \"https:\") {	obj.setAttribute(\"href\", url.replace(\"http:\",\"https:\"));} else {obj.setAttribute(\"href\", url);}	loadPage(obj.href);} </script>';
	document.getElementById('footer_div').innerHTML=footerHtml+googleopen;
	updateHeader();
}



function updateHeader(){
/*	var headerHtml ='<div id="sopra_voci"><div id="sopra_voci_space"></div></div><div id="sopra_voci"><a href="javascript:loadContent3('+onetwoSchedaAzienda+');updateBox('+onetwoBoxAzienda+',\'boxNews\');">CHI SIAMO</a></div><div id="sopra_voci"><a href="javascript:loadElencoEventi();updateBoxEventi();">NEWS</a></div><div id="sopra_voci"><a href="javascript:loadContent3('+onetwoSchedaContatti+');updateBoxEventi();" >CONTATTI</a></div>'+				
			'<div id=sopra_voci><A href="javascript:animatedcollapse.toggle(\'nomibanche\')">INTESA SANPAOLO<IMG src="http://www.intesasanpaolo.com/portalIbve/retail20/RetailIntesaSanpaolo/css/img_costruzione/frecciabanca.gif" border=0></A></div><DIV id="nomibanche" style="HEIGHT:420px HEIGHT:270px; filter:alpha(opacity=80); -moz-opacity: 0.80; opacity:0.8; display: none;"><DIV id=spaziobanche></DIV><iframe frameborder= "0"  scrolling= "no" height="420px" height="270px" src="http://www.intesasanpaolo.com/scriptIbve/retail20/RetailIntesaSanpaolo/nop/ita/home/tendina/ita_tendina_banche.jsp"></iframe></DIV>';
*/
    var headerHtml ='<div id="sopra_voci"><div id="sopra_voci_space"></div></div><div id="sopra_voci"><a href="javascript:loadContent3('+onetwoSchedaAzienda+');updateBox('+onetwoBoxAzienda+',\'boxNews\');">CHI SIAMO</a></div><div id="sopra_voci"><a href="javascript:loadElencoEventi();updateBoxEventi();">NEWS</a></div><div id="sopra_voci"><a href="javascript:loadContent3('+onetwoSchedaContatti+');updateBoxEventi();">CONTATTI</a></div><div id=sopra_voci><A href="javascript:animatedcollapse.toggle(\'nomibanche\')">INTESA SANPAOLO<IMG src="http://www.intesasanpaolo.com/portalIbve/retail20/RetailIntesaSanpaolo/css/img_costruzione/frecciabanca.gif" border=0></A></div><DIV id="nomibanche" style="WIDTH:420px; HEIGHT:270px; filter: alpha(opacity=80); -moz-opacity: 0.80; opacity: 0.8"><DIV id=spaziobanche></DIV><iframe frameborder="0" scrolling="no" width="420" height="270px" src="http://www.intesasanpaolo.com/scriptIbve/retail20/RetailIntesaSanpaolo/nop/ita/home/tendina/ita_tendina_banche.jsp"></iframe></DIV>';
    document.getElementById('sopra_cont').innerHTML=headerHtml;
    animatedcollapse.addDiv('nomibanche', 'hide=1,fade=1,height=270px');
	animatedcollapse.init();
    animatedcollapse.hide('nomibanche');
}

var kindOfHistory=true;

function saveHistory2(){
	document.getElementById('backupGoogle').innerHTML=document.getElementById('wrapperContainer3').innerHTML;
	document.getElementById('backButton').style.display = "block";
	kindOfHistory = false;
}

function saveHistory(){
	document.getElementById('backupGoogle').innerHTML=document.getElementById('wrapperContainer3').innerHTML;
	document.getElementById('backButton').style.display = "block";
	kindOfHistory = true;
}

function loadHistory(){
	document.getElementById('wrapperContainer3').innerHTML=document.getElementById('backupGoogle').innerHTML;
	//document.getElementById('content3').innerHTML=document.getElementById('backupGoogle').innerHTML;
	if( kindOfHistory ) {
		document.getElementById('content3').style.border = "none";
		document.getElementById('wrapperContainer3').style.padding = "0px";
	}
	removeHistory();
}

function removeHistory(){
	try{
		document.getElementById('backButton').style.display = "none";
	}
	catch(e)
	{ 
	}
}

