//
// JavaScript Utilities
// Copyright (c) 2003 Gulliver S.r.L.
// All Rights Reserved.
//
//----------------------------------------------------------------------------------------------------
//
// Variabili
//
        var basketCookieName = "basket";
		var basketCookiePersistenceInHours = 960;
		var basketCookie;
		var basketArray, basketArrayLength;
		var maxBasketArrayLength = 50;
		var spanBasketLength;		
		var attributes = new Array();
		var mFrame = top.frames['mainFrame']; 
        var eFrame = top.frames['nullFrame'];  
		
//----------------------------------------------------------------------------------------------------
//
// Funzioni di apertura pagina
//
        function loadHome() {
			top.location.href = "http://www.molemab.it/";
		}
		
		function loadContactsPage() {
		  document.pageForm.GB_TYPER.value = "MOLEMAB_CONTACTS";
		  document.pageForm.submit();
		}
		
		function loadCataloguePage(sectionCode) {
		  document.cataloguePageForm.sectionCode.value = sectionCode;
		  document.cataloguePageForm.submit();
		}
		
		function loadCataloguePagePR(sectionCode) {
		  document.cataloguePageFormPR.sectionCode.value = sectionCode;
		  document.cataloguePageFormPR.submit();
		}
		
		function loadCataloguePageCL(sectionCode) {
		  document.cataloguePageFormCL.sectionCode.value = sectionCode;
		  document.cataloguePageFormCL.submit();
		}
		
		function loadCataloguePageFornitore(nOfferteSpeciali,cFornitore) {
		  document.cataloguePageFormFornitore.numOfSpecialOffers.value = nOfferteSpeciali;
		  document.cataloguePageFormFornitore.cFornitore.value = cFornitore;
		  document.cataloguePageFormFornitore.submit();
		}
		
		function loadCataloguePageContatti(nOfferteSpeciali,cFornitore) {
		  document.cataloguePageFormContatti.numOfSpecialOffers.value = nOfferteSpeciali;
		  document.cataloguePageFormContatti.cFornitore.value = cFornitore;
		  document.cataloguePageFormContatti.submit();
		}		
		
		function loadSearchResultsPage() {
		  var searchTextCtrl = document.searchForm.searchTextCtrl;
		  var searchTextCtrlValue = searchTextCtrl.value;

		  if (searchTextCtrlValue == '') {
		    alert("Devi specificare qualcosa da cercare prima di avviare una ricerca. ");
		    document.searchForm.searchTextCtrl.focus();
		  } else {
		    document.searchResultsPageForm.searchText.value = searchTextCtrlValue;
		    document.searchResultsPageForm.submit();
		  }
		}

//----------------------------------------------------------------------------------------------------
//
// Funzioni di apertura finestra
//

        function showPrivacyBox(n,to, from, subject, body,email) {		 
		  openBrWindow("infobox-privacy.htm", "privacy", "width=450,height=350");
		}

        function showLegendInfoBox() {
			openBrWindow("infobox-legend.htm", "legendInfoBoxWin", "width=460,height=400");
		}

		function showSearchInfoBox() {
		  openBrWindow("infobox-search.htm", "searchInfoBoxWin", "width=420,height=300");
		}

          function showSiteMapBox() {
			openBrWindow("infobox-sitemap.htm", "sitemapBoxWin", "width=350,height=350");
		}          

		function showServiceAccessInfoBox() {
		  openBrWindow("infobox-serviceacc.htm", "serviceAccessInfoBoxWin", "width=420,height=420");
		}
		
		function showRestrictedAreaInfoBox() {
		    openBrWindow("infobox-restricted.htm", "serviceRestrictedAreaInfoBoxWin", "width=350,height=250");
		}
		
		function showBasketInfoBox() {
		  openBrWindow("infobox-basket.htm", "basketInfoBoxWin", "width=420,height=300");
		}

		function showBasketUsageInfoBox() {
		  openBrWindow("infobox-basketusage.htm", "basketUsageInfoBoxWin", "width=420,height=300");
		}
		
		function showDetailInfoBox(prefix) {
		  oProductCode = attributes[prefix + '_code'];
		  oProductName = attributes[prefix + '_name'];
		  oProductDesc = attributes[prefix + '_desc'];
		  oProductImg = attributes[prefix + '_img'];
		  detailInfoBoxWin = openBrWindow("infobox-detail.htm", prefix + "_detailInfoBoxWin", "width=420,height=275");
		}


    function openW() {

            var w2 = screen.width;

            var h2 = screen.height;

            var t = 0;

            var l = 0;

            w = 640;

            h = 480;

            l = (( w2 - w )/ 2 );

            t = (( h2 - (h + 30))/ 2 );

            var url="stampa_cartina.htm";

            var name="";

            var parametri="resizable=yes,scrollbars=yes,width=" + w + ",height=" + h + ",location=no, top=" + t + ",left=" + l;

            window.open(url,name,parametri);

    }



		
//----------------------------------------------------------------------------------------------------
//
// Fuinzioni del cestello
//

       function doBasketOpen() {
			if (basketArrayLength == 0) {
				alert("Non hai nessun prodotto nel cestello! ");
			} else {
			  document.productsListPageByPrefixesForm.GB_TYPER.value = "MOLEMAB_BASKET";
			  document.productsListPageByPrefixesForm.prefixes.value = basketArray.join(",");
			  document.productsListPageByPrefixesForm.submit();
			}
		}

		function doBasketClear() {
			if (basketArrayLength == 0) {
				alert("Non hai nessun prodotto nel cestello! ");
			} else {
				if (confirm("Sei sicuro di voler svuotare il cestello? ")) {
				  var prefix, td1, td2;
					while (basketArrayLength > 0) {
						prefix = basketArray.pop();
						basketArrayLength--;
						td1 = MM_findObj('_TD1_' + prefix);
						if (td1) {
						  td2 = MM_findObj('_TD2_' + prefix);
						  td1.innerHTML = '<a href="javascript:addToBasket(' + "'" + prefix + "')" + '">Metti nel cestello</a>';
						  td2.innerHTML = '<img src="imgs/gstuff31.gif" width="22" height="22" alt="" border="0"/>';
						}
					}
		    		basketCookie.data = basketArray.join("|");
		    		basketCookie.store();
					spanBasketLength.innerHTML = 'Il tuo cestello &egrave; <strong>vuoto</strong><br/>';
				}
			}
		}

		function doBasketBudget() {
			if (basketArrayLength == 0) {
				alert("Non hai nessun prodotto nel cestello! ");
			} else {
			  document.productsListPageByPrefixesForm.GB_TYPER.value = "MOLEMAB_BUDGET";
			  document.productsListPageByPrefixesForm.prefixes.value = basketArray.join(",");
			  document.productsListPageByPrefixesForm.submit();
			}
		}

//----------------------------------------------------------------------------------------------------
//
// Funzioni varie
//

		function doLogon() {
		  var userTextCtrlValue = document.logonForm.userTextCtrl.value;
		  var passwordCtrlValue = document.logonForm.passwordCtrl.value;

		  if (userTextCtrlValue == '') {
		    alert("Devi specificare un nome utente ed una password per l'accesso! ");
		    document.logonForm.userTextCtrl.focus();
		  } else if (passwordCtrlValue == '') {
		    alert("Devi specificare un nome utente ed una password per l'accesso! ");
		    document.logonForm.passwordCtrl.focus();
		  } else {
		        document.brexForm.USER.value = userTextCtrlValue;
    		    document.brexForm.PWD.value = passwordCtrlValue;
    		    document.brexForm.submit();    		  				  				  				      
		  }
		}
		
		function typeNavigation(type) {
		      eFrame.type = type;
		      if (type == 1) {
        		     loadCataloguePageFornitore(3,1);		 
        		 } else {
        		         loadCataloguePageFornitore(3,0);
        		     }
		 }

//----------------------------------------------------------------------------------------------------
//
// Funzione onload init, controllo cookies e refresh
//

        function testCookies() { 
    	 var exp = new Date(); 
    	 exp.setTime(exp.getTime() + 1800000); 
    	 // first write a test cookie 
    	 setCookie("cookies", "cookies", exp, false, false, false); 
    	 if (document.cookie.indexOf('cookies') != -1) { 
    	   //alert("Got Cookies!"); 
    	 } 
    	 else { 
    		alert("Per una corretta visione del sito abilitare i cookie."); 
    	 } 
    	 // now delete the test cookie 
    	  exp = new Date(); 
    	  exp.setTime(exp.getTime() - 1800000); 
    	  setCookie("cookies", "cookies", exp, false, false, false); 
    	 }
    	
    	function setCookie(name, value, expires, path, domain, secure) { 
    	 var curCookie = name + "=" + escape(value) + 
    		((expires) ? "; expires=" + expires.toGMTString() : "") + 
    		((path) ? "; path=" + path : "") + 
    		((domain) ? "; domain=" + domain : "") + 
    		((secure) ? "; secure" : ""); 
    	 document.cookie = curCookie; 
    	}


        function init() {
          
          testCookies();
            
		  spanBasketLength = MM_findObj('_SPAN_BASKET_LENGTH');

		  basketCookie = new Cookie(document, basketCookieName, basketCookiePersistenceInHours);
		  if (!(basketCookie.load() && basketCookie.data)) {
		    basketArray = new Array();
		    basketArrayLength = basketArray.length;
		  } else {
		    basketArray = basketCookie.data.split("|");
		  	if (basketArray.length > maxBasketArrayLength) {
		      basketArray = basketArray.slice(0, maxBasketArrayLength - 1);
		    }
		    basketArrayLength = basketArray.length;
		  }

		  if (basketArrayLength == 1) {
		    spanBasketLength.innerHTML = 'Hai <strong>un solo</strong> prodotto nel cestello<br/>';
		  } else if (basketArrayLength > 1) {
		    spanBasketLength.innerHTML = 'Hai <strong>' + basketArrayLength + '</strong> prodotti nel cestello<br/>';
		  } else {
		    spanBasketLength.innerHTML = 'Il tuo cestello &egrave; <strong>vuoto</strong><br/>';
		  }
		}
		
		function refreshSupplierMenu() {
		  var td1, td2, txt;
	       		  				            		   
			    td1 = MM_findObj('_' + supplier + '_TDIMG');
			    if (td1) {    				
		    	        td2 = MM_findObj('_' + supplier + '_TDTXT');
		    	        txt = texts['_' + supplier + '_TDTXT'];
		    	        td1.innerHTML = '<td width="16"><img src="imgs/gstuff28_1.gif" width="16" height="15" alt="" border="0"/></td>';
			        td2.innerHTML = '&nbsp;' + txt;	 
			    }     
		 }
		
//----------------------------------------------------------------------------------------------------
//
// Funzioni create dal dreamweaver
//
        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_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];}
		}
		
//----------------------------------------------------------------------------------------------------