
// #############################################
// These are the user defined globals.
// Modify the following variables to customize the inspection behaviour.

// Version the user needs to view site (max 6, min 2)
var requiredVersion = 5;


// #############################################
// *************
// Everything below this point is internal until after the BODY tag.
// Do not modify! Proceed to the BODY tag for further instructions.
// *************

// System globals
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var maxVersion = 6;             // highest version we can actually detect
var actualVersion = 0;          // version the user really has
var hasRightVersion = false;    // boolean. true if it's safe to embed the flash movie in the page
var jsVersion = 1.0;            // the version of javascript supported

/*
// Css preload
imgMain0_on            = new Image();
imgMain0_on.src         = '/css/img_css/bg_main_li_on_home.gif';
imgMain0_off         = new Image();
imgMain0_off.src      = '/css/img_css/bg_main_li_off_home.gif';
imgMain0_sel         = new Image();
imgMain0_sel.src      = '/css/img_css/bg_main_li_sel_home.gif';

imgMain1_on            = new Image();
imgMain1_on.src         = '/css/img_css/bg_main_li_on_aboutus.gif';
imgMain1_off         = new Image();
imgMain1_off.src      = '/css/img_css/bg_main_li_off_aboutus.gif';
imgMain1_sel         = new Image();
imgMain1_sel.src      = '/css/img_css/bg_main_li_sel_aboutus.gif';

imgMain2_on            = new Image();
imgMain2_on.src         = '/css/img_css/bg_main_li_on_news.gif';
imgMain2_off         = new Image();
imgMain2_off.src      = '/css/img_css/bg_main_li_off_news.gif';
imgMain2_sel         = new Image();
imgMain2_sel.src      = '/css/img_css/bg_main_li_sel_news.gif';

imgMain3_on            = new Image();
imgMain3_on.src         = '/css/img_css/bg_main_li_on_catalog.gif';
imgMain3_off         = new Image();
imgMain3_off.src      = '/css/img_css/bg_main_li_off_catalog.gif';
imgMain3_sel         = new Image();
imgMain3_sel.src      = '/css/img_css/bg_main_li_sel_catalog.gif';
*/

imgMain4_on            = new Image();
imgMain4_on.src         = '/css/img_css/mail_main_on.gif';

imgTools0_on            = new Image();
imgTools0_on.src         = '/css/img_css/pdf_hover.gif';

imgTools1_on            = new Image();
imgTools1_on.src         = '/css/img_css/pdf_zoom_hover.gif';


imgTools2_on            = new Image();
imgTools2_on.src         = '/css/img_css/back_zoom_hover.gif';

imgTools3_on            = new Image();
imgTools3_on.src         = '/css/img_css/zoom_hover.gif';

imgTools4_on            = new Image();
imgTools4_on.src         = '/css/img_css/thumbnails_on.gif';

imgTools5_on            = new Image();
imgTools5_on.src         = '/css/img_css/list_on.gif';

imgCredits_on            = new Image();
imgCredits_on.src         = '/css/img_css/firma_on.gif';


//-------------------------------------------------------------------
//
// Codice per gestione degli Errori
//
//window.onerror = HandleError
//
//function HandleError(message, url, line) {
//  var str = "An error has occurred in this dialog." + "\n\n"
//  + "Error: " + line + "\n" + message;
//  alert(str);
//  //window.close();
//  return true;
//}



//-------------------------------------------------------------------
//
// Sommatore eventi [onload]
//
fin = {
   onloads:[],
   add:function(funz){this.onloads[this.onloads.length]=funz},
   init:function(){for(var x in this.onloads) eval(this.onloads[x])}
};

// setto l' onload
window.onload=function(){fin.init()}   



//-------------------------------------------------------------------
//
// WinOpen
//
function winOpen(oUrl,oWinName,oWinLayout){
	window.open(oUrl,oWinName,oWinLayout);
	return false;
}



//-------------------------------------------------------------------
//
// Recuera la posizione assoluta di un elemnto dom presente nella pagina
//
function getPageCoords (element) { // thanks to 'Martin Honnen' for this function
   var coords = {x: 0, y: 0};
   while (element) {
      coords.x += element.offsetLeft;
      coords.y += element.offsetTop;
      element = element.offsetParent;
   }

   //alert(coords.x);
   //(alert(coords.y);

   return coords;  
}



//-------------------------------------------------------------------
//
// Codice per l'urlencode delle stringhe
//
function urlencode(strText) {
	// Autore: 			Charles Toepfer
	// Link articolo:	http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3623&lngWId=2

	var isObj;

	var trimReg;

	if( typeof(strText) == "string" ) {

		if( strText != null ) {

			trimReg = /(^\s+)|(\s+$)/g;

			strText = strText.replace( trimReg, '');

			for(i=32;i<256;i++) {

				strText = strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));
				//strText = strText.replace(strText.fromCharCode(i),escape(strText.fromCharCode(i)));

			}

		}

	}
	return strText;

}


//-------------------------------------------------------------------
//
// Codice per la stampa
//
function stampa(nomeDiv){

	if( nomeDiv == 'TestoL' && window.print())
		window.print();
	else{
		elementToPrint = document.getElementById(nomeDiv);
		winOpen('/4U/pop.php?action=print','winstampa','width=770,height=400,scrollbars=yes,resizable=yes');
	}


	return false;
}


//-------------------------------------------------------------------
//
// Codice per dare il focus alla finestra
//
function daiFocus(){
	this.focus();
}


//-------------------------------------------------------------------
//
// Codice per mostrare un blocco
//
function showBlock(id){
	document.getElementById(id).style.display='inline';
}


//-------------------------------------------------------------------
//
// Codice per nascondere un blocco
//
function hideBlock(id){
	document.getElementById(id).style.display='none';
}


//-------------------------------------------------------------------
//
// Codice per nascondere un blocco
//
function showHide(id){
	document.getElementById(id).style.display= (document.getElementById(id).style.display == 'block')? 'none' : 'block' ;

	if(document.getElementById('lbl'+id))
		document.getElementById('lbl'+id).innerText= (document.getElementById('lbl'+id).innerText == 'show')? 'hide' : 'show';

	if(document.getElementById('img'+id))
		document.getElementById('img'+id).src = (document.getElementById(id).style.display == 'block')? imgBaseDir+'/globali/bulletMenu_on.gif' :  imgBaseDir+'/globali/1pxA.gif';


	return false;
}


//-------------------------------------------------------------------
//
// Codice per il rollover delle immagini
//
function rollon(imgName) {
	if (ok_img) document[imgName].src = eval(imgName + "_on.src");
}

function rolloff(imgName) {
	if (ok_img) document[imgName].src = eval(imgName + "_off.src");
}


//-------------------------------------------------------------------
//
// Codice per il rollover delle immagini
//
var imgOk = false;
function rollover(elParent) {
	if(imgOk){
		s = elParent.firstChild.src;
		s = elParent.firstChild.src.replace('.gif','')
		elParent.firstChild.src = s + '_on' + '.gif';
	}
}

function rollout(elParent) {
	if(imgOk) elParent.firstChild.src = elParent.firstChild.src.replace('_on','');
}


function PreloadImg(){
	img1_on				= new Image();
	img1_on.src			= '/globali/colours_norm_on.gif';
	img1_off			= new Image();
	img1_off.src		= '/immagini/catalogo/colours_norm.gif';
	
	img2_on				= new Image();
	img2_on.src			= '/globali/catalogo/macro_cat/metal_btn_on.gif.gif';
	img2_off			= new Image();
	img2_off.src		= '/immagini/catalogo/macro_cat/metal_btn.gif';
	
	img3_on				= new Image();
	img3_on.src			= '/globali/catalogo/macro_cat/plastic_btn_on.gif';
	img3_off			= new Image();
	img3_off.src		= '/immagini/catalogo/macro_cat/plastic_btn.gif';	
	
	img4_on				= new Image();
	img4_on.src			= '/globali/catalogo/macro_cat/plastic_metal_btn_on.gif';
	img4_off			= new Image();
	img4_off.src		= '/immagini/catalogo/macro_cat/plastic_metal_btn.gif';		
	
	imgOk = true;
}



//-------------------------------------------------------------------
//
// Funzione per effettuare un PostBack
//
function __DoPostBack( formName, sender, argument) {

   // Devo includere nella pagina i seguenti HiddenFilds
   // Nella stessa form che richiamo con il parametro "formName"
   // <input type="hidden" name="__Sender" value="">
   // <input type="hidden" name="__Argument" value="">

   //alert(sender);

   document.forms[formName].__Sender.value = sender;
   document.forms[formName].__Argument.value = argument;

   document.forms[formName].submit();

   return false;
}


function delete_item(itemID,redirect){
   bConfirm = confirm( 'Sei sicuro di voler procedere con l\'eliminazione?\nL\'operazione sarà irreversibile.' );

   if( bConfirm ){
      window.location.href = redirect+'?elimina=1&id_content='+itemID ;
   }

   return false;
}

function checkEmail(strEmail){
	var email_re = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$");
	return email_re.test(strEmail);

}


// Custom --------------------------------------------------------------
function checkPenneHome(frmObj,limit){
   countCheck = 0;
   for(var i=0; i<frmObj.elements.length; i++){
      //alert(frmObj.elements[i].type);
      if(frmObj.elements[i].type.substring(0,8) == "checkbox"){
         if(frmObj.elements[i].checked)
            countCheck++;
      }
   }

   if( countCheck < limit ){
      alert( 'Attenzione! Devi settare almeno '+limit+' penne da mostrare in Home Page.' );
      return false;
   }

   return true;
}

function ClearAllPenn(frmName){
   frmObj = document.forms[frmName];
   for(var i=0; i<frmObj.elements.length; i++){
      //alert(frmObj.elements[i].type);
      if(frmObj.elements[i].type.substring(0,8) == "checkbox"){
         frmObj.elements[i].checked = false;
      }
   }

   return false;
}

function CaricaFlash(checkFlash,movieName,w,h){

   use_flash = true;

   if(checkFlash)
      use_flash = detectFlash();

   //alert(use_flash);

   if(use_flash){
      document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'">');
      document.writeln('  <param name="movie" value="/swf/'+movieName+'" />');
      document.writeln('   <param name="quality" value="high" />');
      document.writeln('   <param name=FlashVars value="clickTag=/it/software/mx2004/index.html&clickTarget=_self" />');
      document.writeln('   <embed flashvars="clickTag=clickTag=/it/software/mx2004/index.html&clickTarget=_self" src="/swf/'+movieName+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
      document.writeln('</object>');
   }else{
      document.writeln('<img src="/swf/'+movieName+'.jpg" alt="'+movieName+'.jpg" width="'+w+'" height="195" />');
      /*
      document.writeln('  <map id="homepage_fma" name="homepage_fma">');
      document.writeln('    <area shape="rect" coords="657,163,737,187" href="/it/buy/promos/mvlp/" alt="Mag. Info" />');
      document.writeln('</map>');
      */
   }
}



function detectFlash() {

   // Check the browser...we're looking for ie/win
   var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
   var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows
   // This is a js1.1 code block, so make note that js1.1 is supported.
   jsVersion = 1.1;

   // Write vbscript detection on ie win. IE on Windows doesn't support regular
   // JavaScript plugins array detection.
   if(isIE && isWin){

     document.write('<SCRIPT LANGUAGE=VBScript\> \n');
     document.write('on error resume next \n');
     document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
     document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
     document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
     document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
     document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
     document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
   }

   // If navigator.plugins exists...
   if (navigator.plugins) {
      // ...then check for flash 2 or flash 3+.

      if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {

        // Some version of Flash was found. Time to figure out which.
        // Set convenient references to flash 2 and the plugin description.
        var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
        var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

        // DEBUGGING: uncomment next line to see the actual description.

        // alert("Flash plugin description: " + flashDescription);

        // A flash plugin-description looks like this: Shockwave Flash 4.0 r5
        // We can get the major version by grabbing the character before the period
        // note that we don't bother with minor version detection.
        // Do that in your movie with $version or getVersion().
        var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

        // We found the version, now set appropriate version flags. Make sure
        // to use >= on the highest version so we don't prevent future version
        // users from entering the site.
        flash2Installed = flashVersion == 2;
        flash3Installed = flashVersion == 3;
        flash4Installed = flashVersion == 4;
        flash5Installed = flashVersion == 5;
        flash6Installed = flashVersion >= 6;
      }
   }

   // loop through all versions we're checking, and set actualVersion to highest detected version
   for (var i = 2; i <= maxVersion; i++) {
      if (eval("flash" + i + "Installed") == true) actualVersion = i;
   }

   // if we're on webtv, the version supported is 2 (pre-summer2000, or 3, post-summer2000)
   // note that we don't bother sniffing varieties of webtv. you could if you were sadistic...
   if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;

   //alert(actualVersion);

   return (actualVersion >= requiredVersion)? true:false;
}

//rollover di dreamwever
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_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];}
}
