var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
}

// Version check based upon the values entered above in "Globals"
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

var alternateContent = '<center><div style="width: 100%; height: 100%; background: #ffffff; margin-left: auto; margin-right: auto; font-family:verdana,arial,helvetica,sans-serif;color:#000000;font-size:12px; padding-toP: 200px;">Per visualizzare correttamente questo sito &egrave; necessario installare il plug-in Adobe Flash Player, versione '+requiredMajorVersion+' o successiva<br><br><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" style="color: red;">Installa Flash</a></div></center>';






function calc_left (w) {
	var left = (screen.availWidth / 2) - (w / 2);
	return (left);
}

function calc_top (h) {
	var top = (screen.availHeight / 2) - (h / 2);
	return (top);
}

function open_popup(url, w, h, scrollbar,toolbar,status,menubar,id) {
 //alert(scrollbar)
 if(!scrollbar){scrollbar = 'no'}
 if(!toolbar){toolbar = 'no'}
 if(!status){status = 'no'}
 if(!menubar){menubar = 'no'}
 if(!id){id = ''}
 
	var top = calc_top (h);
	var left = calc_left (w);

	popup = window.open (url,id,'width='+w+',height='+h+',left='+left+',top='+top+',screenX='+left+',screenY='+top+'status='+status+', menubar='+menubar+', toolbar='+toolbar+', scrollbars='+scrollbar);
	popup.focus();
}


function addFlash (objId, flashSrc, w, h, bgcolor, vars) {
	obj = document.getElementById(objId);

	if (hasReqestedVersion) {
	
       if (vars != '') {
           var embedVars  = ' flashvars="'+vars+'" ';
   		var objectVars = ' <param name="flashvars" value="'+vars+'" /> ';
       }
   	else {
           var embedVars  = '';
   		var objectVars = '';
   	}
   
   	htmlCode = ''+
   		'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" id="banner_home" align="middle">'+
   		'<param name="allowScriptAccess" value="sameDomain" />'+
   		'<param name="movie" value="'+flashSrc+'" />'+
   		'<param name="quality" value="high" />'+
   		'<param name="bgcolor" value="'+bgcolor+'" />'+
           objectVars +
   		'<embed src="'+flashSrc+'" '+embedVars+' quality="high" bgcolor="'+bgcolor+'" width="'+w+'" height="'+h+'" name="banner_home" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
   		'</object>';
   
   	obj.innerHTML = htmlCode;
	}
	else {
	  obj.innerHTML = alternateContent;
	}
	
}


function popup_linea (codice_linea, lingua) {
   open_popup('/popup/prodotto.php?lang='+lingua+'&l='+codice_linea, 815, 535, 'no','no','no','no','popup_prodotto');  
}

function popup_prodotto (codice_prodotto,lingua) {
   open_popup('/popup/prodotto.php?lang='+lingua+'&p='+codice_prodotto, 815, 535, 'no','no','no','no','popup_prodotto');  
}

function open_puntivendita (lingua) {
   open_popup('/popup/punti_vendita.php?lang='+lingua, 350, 450, 'no','no','no','no','popup_puntivendita');
}


function visualizza_prodotto (codice_prodotto, lingua) {
   new Ajax.Request('/comuni/ajax/visualizza_prodotto.ajax.php',
   {
     method: 'get',
     parameters: { i:codice_prodotto, lang:lingua },
     onFailure: function(){ alert('Something went wrong...') }
   });
}


function popup_comunicazione (id) {
   comunicazionePopup = window.open('/popup/comunicazione.php?i='+id,'comunicazione','width=390,height=550');
   comunicazionePopup.focus();
}


function popup_certificato (id) {
   certificatoPopup = window.open('/popup/certificato.php?i='+id,'certificato','width=390,height=550');
   certificatoPopup.focus();
}






function addPng (imgUrl, w, h, className) {

	str = "<style>"+
					"."+className+" {"+
					"  background-image:url('"+imgUrl+"');"+
					"  background-repeat: no-repeat;"+
					"}"+
					"* html ."+className+" {"+
					"  filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgUrl+"', sizingMethod='scale');"+
					"  background-image:none;"+
					"  background-repeat: no-repeat;"+
					"}"+
					"</style>";

	
   str += "<img src=\"/img/1x1.gif\" border=\"0\" width=\""+w+"\" height=\""+h+"\" class=\""+className+"\" />";
	
   document.write(str);
}



function popup_fettexfette (lingua) {
   open_popup('/popup/fettexfette/index_'+lingua+'.html', 600, 500, 'no','no','no','no','fettexfette');  
}
