function addLoadEventVis(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function collapse_network() {
  
var newagt = navigator.userAgent.toLowerCase();

// Top
var div_banner_top = document.getElementById("advtop");
var div_header_top = document.getElementById("topheader");
var div_ge_network = document.getElementById("ge-network");
var div_ge_network_top = document.getElementById("ge-network-top");
var div_ge_network_bottom = document.getElementById("ge-network-bottom");

if (newagt.indexOf("msie") != -1) {
	if (div_banner_top != null) { altezza_top = div_banner_top.offsetHeight; }
} else {
	if (div_banner_top != null) { altezza_top = document.defaultView.getComputedStyle(div_banner_top, '').getPropertyValue("height"); }
	if (div_banner_top != null) { check_altezza_top = altezza_top.split('px'); }
	if (div_banner_top != null) { altezza_top = check_altezza_top[0]; }
}

// Top
if ((div_banner_top != null) && (altezza_top < 25)) {
	div_banner_top.style.display = "none";
  if( div_ge_network != null ) {
  	div_ge_network.style.height = "auto";
  	div_ge_network.style.width = "auto";
  	div_ge_network.style.background = "none";
  }
  
  if (div_header_top != null) {
  	div_header_top.style.backgroundColor = "#e6e6e6";
  	div_header_top.style.paddingBottom = "3px";
  }
  
  if (div_ge_network_top != null)	{ div_ge_network_top.style.marginTop = "12px"; }
} 

}




///////////////////////////


// RICERCA
var debug = false;
var msrep_flag = 0;
var lista = new Array(["","",0],["","_img",0],["","_vid",0],["","_news",0],["","annunci",1],["","shopping",1],["","rep",1]);
var valore = lista[0][0];
var newaction = lista[0][1];
var multiricerca;



function cambiabrand(stato) {
	cba = document.getElementById('cambiabrand');
	cbb = cba.style.backgroundColor;
	//alert(cbb);
	if (stato == 0) {
		 cba.style.backgroundPosition = "100% 0";
		} else {
		 cba.style.backgroundPosition = "100% -999px";
		}
	}


function cambia(quale) {
	valore = lista[quale][0];
	newaction = lista[quale][1];
	if (msrep_flag == 1)	document.secSearch.query1.value = lista[quale][0];
	
		multiricerca = document.getElementById('multiricerca');
		opzioni = multiricerca.getElementsByTagName("a");
		opzioneAttiva = quale;
	
		for (var i = 0; i < opzioni.length; i++) { opzioni[i].className = ""}	
	 	opzioni[quale].className = "active";
		cambiabrand(lista[quale][2])

		fp_debug(1,valore + "  ++++++  " + newaction + " *** " + lista[quale][2])
	}



function newmultisearchRepubblica(f) {

	fp_debug(2, f.name + " <strong> "+ newaction +" </strong> " + f.query1.value);

	//if (f.query1.value == "") { alert(valore +': inserire una parola per la ricerca'); return false; }
	if (f.query1.value == "") { alert('Inserire almeno una parola per la ricerca'); return false; }
	
	tse = f.query1.value;
	msnse = "";
		for (g=0 ; g <= tse.length ; g++) {
			if (tse.charAt(g) == " ") {
				msnse = msnse + "+"; 
			} 
			else {
				msnse = msnse + tse.charAt(g); 
			}
		}
	
		if (newaction == "rep" ) {
			f.action = "http://localsearch.kataweb.it/searchbin/repSearch.pl";
			f.submit();
			fp_debug(2, "REP > "+ valore);
		} else if (newaction == "annunci") {
			f.action = "http://annunci.repubblica.it/italia/tutti/-/ricerca-" + tse;
			f.submit();
			fp_debug(1, "Annunci > "+ f.action );
		} else if (newaction == "shopping") {
		    f.string.value = tse;
    		f.action = "http://costameno.repubblica.it/search.php";
    		f.submit(); 
			fp_debug(1, "shopping > "+ f.action );	
		} else {
			f.action = "http://ricerca.repubblica.it/result" + newaction + ".jsp";
			f.q.value=msnse;
			fp_debug(2, "OTHER submit > "+ valore);
			f.submit();
		}
		return false;
	}
	
	
function fp_debug(chi,cosa) {
	if(debug) {
		document.getElementById('debug'+chi).innerHTML = cosa;
		return true;
		}
	}//voip


///////////////////////////


	
	
//voip
function popcallwindow(url)
{
	tastierinoWnd=window.open(url,'popcallwin','height=600,width=800,scrollbars=yes,menubar=no,location=no,status=yes,toolbar=no,top=0,left=0');
	if (window.focus) {tastierinoWnd.focus()}
	return false;
}



//Finestre popup
function openwin(url, windowname, atrib, radio, channel) {
    window.open(url, windowname, atrib);
}



//Menu a tendina
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



// Funzione per il link delle select
function yup_jumpMenu(targ,selObj,restore,urlA,urlB){ //v3.0
//url = 'http://' + urlA;
eval(targ+".location='"+urlA+selObj.options[selObj.selectedIndex].value+urlB+"'");
if (restore) selObj.selectedIndex=0;
}




function setDefaults() {
	// Create global variables for elements:
	supportNav = document.getElementById('tabsNav');
	theTabs = supportNav.getElementsByTagName("a");
	marginesotto = 0;
	// Set class for default tab:
	theTabs[0].className = "activeTab";
	var container = document.getElementById('boxcont');

	
	// Determine height of included tables to adjust 
	// margin-bottom for breadcrumbs calculated on togglePanes:
	// Set the position value for panes:
	thePanes = container.getElementsByTagName('div');
	for (var i = 0; i < thePanes.length; i++) {
		thePanes[i].style.borderLeft = "1px solid #999999";
		thePanes[i].style.borderBottom = "1px solid #999999";
		thePanes[i].style.borderRight = "1px solid #999999";
}
	// Hide all but default pane:
	for (var j = 1; j < thePanes.length; j++) {
		thePanes[j].style.display = "none";
	}
	// Show the default pane:
	thePanes[0].style.display = "block";
	// Set global value for default tab:
	defaultTab = 0;
//   	container.style.marginBottom = (document.getElementById("strillorot1").offsetHeight) + "px";	

}
    
function prepareToggle() {
	for (var i = 0; i < theTabs.length; i++) {
		theTabs[i].onclick = function() {
			return togglePanes(this);
		}
	}
}

function togglePanes(clickedTab) {
	var container = document.getElementById('boxcont');
	for (var i = 0; i < theTabs.length; i++) {
		if (i != defaultTab && theTabs[i] == clickedTab) {
			thePanes[i].style.display = "block";
			theTabs[i].className = "activeTab";
			// Toggle the default tab:
			thePanes[defaultTab].style.display = "none";
			theTabs[defaultTab].className = "";	
            var pid = "strillorot" + (i+1);
//		   	container.style.marginBottom = (document.getElementById("strillorot" + (i+1)).offsetHeight) + "px";  
			defaultTab = i;
		
			return false;
		} else if (i == defaultTab && theTabs[i] == clickedTab){
			return false;
		}
	}
}

//spalla
addLoadEventVis(collapse_network);
addLoadEventVis(setDefaults);
addLoadEventVis(prepareToggle);
addLoadEventVis(togglePanes);
