/* CSS STYLESHEET */
// La funzione per cambiare i fogli di stile
function setStyleSheet(){
	var expdate = new Date();
	expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	SetCookie("style", arguments[0], expdate, "/", null, false);
	if(!document.styleSheets || navigator.userAgent.indexOf("Safari")!=-1 || (navigator.userAgent.indexOf("Konqueror")!=-1)){
		var ss = getAllSheets() //non dom
	}else{
		var ss = document.styleSheets; //Dom
	}
	// disabilita tutti i fogli di stile con un titolo 
	// tranne quello passato per argomento alla funzione
		//alert("setStyleSheet");
	for( var x = 0; x < ss.length; x++ ) {
		ss[x].disabled=true;			
		if(ss[x].title=="ie_css" && arguments[0]=="advanced"){
			ss[x].disabled=false;			
		}
		if(arguments[0]=="default"){
			if( ! ss[x].title ) {
				ss[x].disabled=false;
			}
		}else{
			if( ss[x].title == arguments[0]) {
				ss[x].disabled=false;
			}			
		}
	}
	if( !ss.length ) { 
		alert( 'Il tuo browser non è abilitato a cambiare i fogli di stile CSS' );
	}
}

// ---------------------------------------------------------------------------------

// Funzione per Opera
function getAllSheets(){
	if( document.getElementsByTagName ) {
		var Lt = document.getElementsByTagName('LINK');
		var St = document.getElementsByTagName('STYLE');
	} else {
		// browser minori - restituisce array vuoto
		return []; 
	}
	//per tutti i tag link ...
	for( var x = 0, os = []; Lt[x]; x++ ) {
		//controlla l'attributo rel per vedere se contiene 'style'
		if( Lt[x].rel ) {
			var rel = Lt[x].rel;
		} else if( Lt[x].getAttribute ) {
			var rel = Lt[x].getAttribute('rel');
		} else {
			var rel = '';
		}
		if(typeof(rel)=='string'&&rel.toLowerCase().indexOf('style')+1){
			//riempe la variabile os con i stylesheets linkati
			os[os.length] = Lt[x];
		}
	}
	//include anche tutti i tags style e restituisce l'array
	for( var x = 0; St[x]; x++ ) {
		os[os.length] = St[x];
	}
	return os;
}

/* COOKIE  */
function SetCookie(name, value){		
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	   document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}
function GetCookie(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen){
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
			break; 
	}
	return null;
}
function getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}
function RemoveCookie(name){
	document.cookie = name+"=; path=/";	
}

function setCheckCookieStyle(){
	st=GetCookie("style");
	if(st==null || st=="null"){
		setStyleSheet("advanced");				
	}else if(st=="undefined"){
		setStyleSheet();
	}else{
		setStyleSheet(st);		
	}
}

var old_sez;

window.onload = function(){
	MM_preloadImages('/_images/acquesalute_f2.jpg');
	var tmp = window.location.href
	if (tmp.indexOf('/BrandsProducts/')!=-1) {
		tmp = tmp.substring(tmp.indexOf('/BrandsProducts/'),tmp.length).length
		//	alert(tmp);
		if(tmp==16){
			MM_preloadImages('/_images/h-marchi_rocchetta_f2.png','/_images/h-marchi_brioblu_f2.png','/_images/h-marchi_elisir_f2.png');
		} else if(tmp>16){
			MM_preloadImages('/_images/loghi/brioblu_f2.gif','/_images/loghi/rocchetta_f2.gif','/_images/loghi/uliveto_f2.gif','/_images/loghi/elisir_f2.gif');
		}
	} else if (tmp.indexOf('/distributors/')!=-1) {
		document.getElementById('africaMiddleEast').style.display = "none";
		document.getElementById('northSouthAmerica').style.display = "none";
		document.getElementById('asiaPacific').style.display = "none";
		old_sez = 'europe';
	}
}
function popupwindow(LarghezzaCont,AltezzaCont,Pagina,nome,scrol,stat) {
	var lsBrowser = navigator.appName;
	var navInfo = navigator.userAgent;
	if (scrol == "yes") {
		if (navInfo == "Mac" && lsBrowser.indexOf("Microsoft") >= 0) {
				aw = 0;
		} else {
		aw = 17;
		}		
	} else {
		aw = 0;
	}		
    var iMyWidth;
    var iMyHeight;
    var LarghezzaPagina;
    var AltezzaPagina;
    LarghezzaPagina = screen.availWidth;
    AltezzaPagina = screen.availHeight;
    LarghezzaCont=LarghezzaCont.toUpperCase()
    AltezzaCont=AltezzaCont.toUpperCase()
    if (LarghezzaCont == "FULL") {
            LarghezzaWindow = screen.availWidth;
        } else {
            LarghezzaWindow = parseInt(LarghezzaCont) + aw;
        }
	    if (AltezzaCont == "FULL") {
            AltezzaWindow = screen.availHeight;
        } else {
            AltezzaWindow = AltezzaCont;
        }
    iMyWidth = (LarghezzaPagina/2) - (LarghezzaWindow/2);
    iMyHeight = (AltezzaPagina/2) - (AltezzaWindow/2);
    win = window.open(Pagina,nome,"height=" + AltezzaWindow + ",width="	+ LarghezzaWindow 
	+ ",menubar=0,resizable=0,scrollbars=" + scrol + ",status=" + stat + ",titlebar=0,toolbar=0,left="
	+ iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + "");
    win.focus();
}

function showZoom() {
	if (old_sez) {
		popupwindow('800','600','/_asp/mediaViewer.asp?mm=/_images/labels/zoom/'+old_sez+'.jpg','zoom','yes','yes')
	}
}

function show(trgt) {
	if (old_sez) {
		document.getElementById(old_sez).style.display = "none";
	}
	document.getElementById(trgt).style.display = "block";
	old_sez = trgt;
	/*if (trgt.indexOf('img') != -1) {
		if (trgt == 'img0') {
			document.getElementById('zoom').style.display = "none";
		} else {
			document.getElementById('zoom').style.display = "inline";
		}
	}*/
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
