<!--
	// Controlla gli spazi vuoti nella compilazione dei campi di testo
	function trim(stringa){
		while(stringa.substring(0, 1) == " ")
			stringa = stringa.substring(1, stringa.length);
		
		while(stringa.substring(stringa.length-1, stringa.length) == " ")
			stringa = stringa.substring(0, stringa.length-1);
		
		return stringa;
	}
	
	// Googlemaps
	//<![CDATA[
	var map;
	var addIcon;
	var geocoder;
	
	function initialize(cntValue, textValue){
		if(GBrowserIsCompatible()){
			map = new GMap2(document.getElementById("mappa"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(46.305201, 9.747620), 9);
			geocoder = new GClientGeocoder();
			addMarkers(cntValue, textValue);
			var ovcontrol = new GOverviewMapControl(new GSize(150, 150)); 
      		map.addControl(ovcontrol);
		}
	}
	
	function addMarkers(cntValue, textValue){
		if(trim(cntValue) != "")
			var imageIcon = "icon_rivs.png"
		else
			var imageIcon = "icon_points.png";
		
		if(trim(textValue) != ""){
			var splitted = textValue.split("||");
			
			for(i in splitted){
				var textAddress = splitted[i];
				
				if(geocoder){
					geocoder.getLatLng(
						textAddress, 
						function(point){
							if(point){
								var addIcon = new GIcon();
								addIcon.image = "http://www.crazyidea.it/images/" + imageIcon;
								addIcon.iconAnchor = new GPoint(0, 15);
								markerOptions = { icon:addIcon };
								marker = new GMarker(point, markerOptions);
								map.addOverlay(marker);
							}
						}
					);
				}
			}
		}		
	}
	
	function addAddressToMap(response){
    map.clearOverlays();
		
    if(!response || response.Status.code != 200)
        alert("Al momento non ci è possibile interpretare le coordinate richieste: riprovate più tardi, grazie...");
 		else{
			loc_riv = "Crazy Idea";
			
			if(trim(window.loc) != "")
				loc_riv = trim(window.loc);
			
      place = response.Placemark[0];
      point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
			addIcon = new GIcon();
			addIcon.image = "http://www.crazyidea.it/images/" + window.icon_marker;
			addIcon.iconAnchor = new GPoint(0, 15);
			addIcon.infoWindowAnchor = new GPoint(20, 8);
			markerOptions = { icon:addIcon };
      marker = new GMarker(point, markerOptions);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.addOverlay(marker);
			
			if(trim(window.description) == "")
	     	marker.openInfoWindowHtml('<div style="width: 190px; height: 200px;"><font style="font-family: Verdana; font-size: 10px; color: #000000;"><font style="font-weight: bold; color: #DF0017;">' + loc_riv + '</font><br /><img src="' + window.image + '" border="0" vspace="5" style="border: 1px solid #C5C2BE;"><br />' + place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName + '<br />' + place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber + ' ' + place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName.toUpperCase() + '<br />(' + place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName + ')</div>');
			else
	     	marker.openInfoWindowHtml('<div style="width: 190px; height: 200px;"><font style="font-family: Verdana; font-size: 10px; color: #000000;"><font style="font-weight: bold; color: #DF0017;">' + loc_riv + '</font><br /><img src="' + window.image + '" border="0" vspace="5" style="border: 1px solid #C5C2BE;"><br />' + window.description + '</div>');
    }
  }
	
	function showLocation(loc, address, image, description, icon_marker){
		window.loc = loc;
		window.image = image;
		window.description = description;
		window.icon_marker = icon_marker;
		geocoder = new GClientGeocoder();
  	geocoder.getLocations(address, addAddressToMap);
  }
	//]]>
	
	// Swap immagini
	function MM_preloadImages(){
		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(){
		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){
		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(){
		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];}
	}
	
	// Mostra/nasconde il display dell'elemento "id"
	function showHideDiv(id, who){
		if(document.getElementById('' + id + '').style.display == "none"){
			if(navigator.appName == "Microsoft Internet Explorer")
				document.getElementById('' + id + '').style.display = "block";
			else if(navigator.appName == "Netscape")
				document.getElementById('' + id + '').style.display = "table-row";
		}
		
		if(id == "subcat" && who == "sport"){
			document.getElementById('section_white').style.backgroundColor = "";
			document.getElementById('prod').style.display = "none";
			document.getElementById('categorie').style.backgroundImage = "url(images/bg_categorie_sport.gif)";
		}
		else if(id == "subcat" && who == "fish"){
			document.getElementById('section_white').style.backgroundColor = "";
			document.getElementById('prod').style.display = "none";
			document.getElementById('categorie').style.backgroundImage = "url(images/bg_categorie_fish.gif)";
		}
	}
	
	// Caricamento AJAX div content
	var bustcachevar = 1;
	var loadedobjects = "";
	var rootdomain = "http://" + window.location.hostname;
	var bustcacheparameter = "";
	
	function ajaxpage(url, containerid){
		var page_request = false;
		
		if(window.XMLHttpRequest)
			page_request = new XMLHttpRequest();
		else if (window.ActiveXObject){
			try{
				page_request = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			
			catch(e){
				try{
					page_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				
				catch(e){}
			}
		}
		else
			return false;
		
		page_request.onreadystatechange=function(){
			loadpage(page_request, containerid);
		}
		
		if(bustcachevar)
			bustcacheparameter = (url.indexOf("?") != -1)? "&" + new Date().getTime() : "?" + new Date().getTime();
		
		page_request.open('GET', url+bustcacheparameter, true);
		page_request.send(null);
	}
	
	function loadpage(page_request, containerid){
		if(page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1))
			document.getElementById(containerid).innerHTML = page_request.responseText;
		else
			showloadingimage(containerid);
	}
	
	function showloadingimage(divid){
    var el = document.getElementById(divid);
    if(el){
    	el.innerHTML = '<img src="images/loading.gif" border="0" style="margin-left: 152px;">';
      $(divid).show();
    }
  }
	
	function loadobjs(){
		if(!document.getElementById)
			return;
		
		for(i=0; i<arguments.length; i++){
			var file = arguments[i];
			var fileref = "";
			
			if(loadedobjects.indexOf(file) == -1){
				if(file.indexOf(".js") != -1){
					fileref = document.createElement("script");
					fileref.setAttribute("type", "text/javascript");
					fileref.setAttribute("src", file);
				}
				else if (file.indexOf(".css") != -1){
					fileref = document.createElement("link");
					fileref.setAttribute("rel", "stylesheet");
					fileref.setAttribute("type", "text/css");
					fileref.setAttribute("href", file);
				}
			}
			
			if(fileref != ""){
				document.getElementsByTagName("head").item(0).appendChild(fileref);
				loadedobjects += file + " ";
			}
		}
	}
	
	// Popup centrata per immagini
	function popupCenter(imageURL){
		var AutoClose = true;
		
		var w = 150;
		var h = 150;
		var l = 100;
		var t = 100;
		
		if(parseInt(navigator.appVersion.charAt(0))>=4){
			var isNN = (navigator.appName == "Netscape")?1:0;
			var isIE = (navigator.appName.indexOf("Microsoft")!=-1)?1:0;
		}
		
		var optNN = 'scrollbars=no, resizable=yes, width=' + w + ', height=' + h + ', left=' + l + ', top=' + t;
		var optIE = 'scrollbars=no, resizable=yes, width=' + w + ', height= ' + h + ', left=' + l + ', top=' + t;
		
		if(isNN)
			imgWin = window.open('about:blank', '', optNN);
		
		if(isIE)
			imgWin = window.open('about:blank', '', optIE);
		
		with(imgWin.document){
			writeln('<html>\n<head>\n<title>Loading...</title>\n<style>\nbody{padding: 0px; margin: 0px; background-color: #FFFFFF;}</style>');
			writeln('<sc' + 'ript>');
			writeln('var isNN, isIE;');
			writeln('if(parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN = (navigator.appName == "Netscape")?1:0;');
			writeln('isIE = (navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			writeln('if(isIE){');
			writeln('window.resizeTo(150, 150);');
			writeln('width = 520;');
			writeln('height = 590;');
			writeln('window.resizeTo(width, height);}');
			writeln('if(isNN){');       
			writeln('width = 520;');
			writeln('height = 590;');
			writeln('window.innerWidth = document.images["lavoro"].width;');
			writeln('window.innerHeight = document.images["lavoro"].height;}}');
			writeln('function doTitle(){document.title = "Crazy Idea - Abbigliamento tecnico sportivo e tempo libero";}');
			writeln('</sc' + 'ript>');
			
			if(!AutoClose)
				writeln('</head>\n<body scroll="no" onload="javascript:reSizeToImage(); doTitle(); self.focus();">')
			else
				writeln('</head>\n<body scroll="no" onload="javascript:reSizeToImage(); doTitle(); self.focus();" onblur="javascript:self.close();">');
			
			writeln('<img name="lavoro" src="' + imageURL + '" border="0" style="display: block;">\n</body>\n</html>');
			close();
		}
	}
	
	// Popup centrata per pagine
	var win = null;
	
	function popupCenterPage(mypage, myname, w, h, scroll){
		leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		topPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings = 'height=' + h + ', width=' + w + ', top=' + topPosition + ', left=' + leftPosition + ', scrollbars=' + scroll + ', resizable';
		
		win = window.open(mypage, myname, settings);
	}
	
	// Submit di ricerca pagina nel catalogo
	function passForPid(cidValue, pageValue, orderbyValue, senseValue){
		if(trim(cidValue) != "")
			window.location.href = 'contents.php?cmd=catalogo&cid=' + cidValue + '&page=' + pageValue + '';
		else
			window.location.href = 'contents.php?cmd=catalogo&page=' + pageValue + '&orderby=' + orderbyValue + '&sense=' + senseValue + '';
	}
	
	// Submit di ordinamento pagina nel catalogo
	function passForOid(sidValue, pageValue, whoValue, orderValue){
		if(whoValue == "" || whoValue == "N")
			alert("Attenzione!\nIl campo d'ORDINAMENTO non è stato selezionato correttamente...");
		else{
			if(document.getElementById('button_value').value == 'Crescente')
				orderValue = "ASC";
			else if(document.getElementById('button_value').value == 'Decrescente')
				orderValue = "DESC";
			
			window.location.href = 'contents.php?cmd=catalogo&sid=' + sidValue + '&page=' + pageValue + '&orderby=' + whoValue + '&sense=' + orderValue;
		}
	}
	
	// Submit di ordinamento pagina nel catalogo per sesso
	function passForSex(cidValue, pageValue, whoValue){
		if(whoValue == "" || whoValue == "N")
			alert("Attenzione!\nIl campo d'ORDINAMENTO non è stato selezionato correttamente...");
		else{
			if(document.getElementById('button_value').value == 'Crescente')
				orderValue = "ASC";
			else if(document.getElementById('button_value').value == 'Decrescente')
				orderValue = "DESC";
			
			window.location.href = 'contents.php?cmd=catalogo&cid=' + cidValue + '&page=' + pageValue + '&orderby=' + whoValue;
		}
	}
	
	// Sostituisce l'immagine di default dei prodotti nel catalogo
	function changeImg(default_immagini_product, where, img_width, i){
		var img_default_path = document.getElementById('img_default').src;
		
		var img_default = img_default_path.split("/");
		var img_default_length = img_default.length-1;
		var img_default = img_default[img_default_length];
		
		document.getElementById('default_' + i).innerHTML = "<a href=\"javascript:changeImg('" + img_default + "', '" + where + "', '" + img_width + "', '" + i + "')\"><img src=\"images/" + where + "/zoom/" + img_default + "\" id=\"img_" + i + "\" width=\"" + img_width + "\" border=\"0\" class=\"img_highlight\" style=\"margin-bottom: 5px;\" onmouseover=\"javascript:document.getElementById('img_" + i + "').className='img_highlight_hover';\" onmouseout=\"javascript:document.getElementById('img_" + i + "').className='img_highlight';\"></a>";
		document.getElementById('default').innerHTML = "<a href=\"javascript:popupCenter('images/" + where + "/zoom/" + default_immagini_product + "');\"><img src=\"images/" + where + "/" + default_immagini_product + "\" border=\"0\" id=\"img_default\" class=\"img_section\"></a>";
	}
	
	// Controlla l'input type text della RICERCA prodotti
	function checkSearch(){
		if(trim(document.getElementById('search').value) == ""){
			alert("Attenzione!\nIl campo di RICERCA non è stato compilato correttamente...");
			document.getElementById('search').focus();
		}
		else
			window.location.href = 'contents.php?cmd=catalogo&sid=' + trim(document.getElementById('search').value);
	}
	
	// Controlla l'input type text della RICERCA prodotti alla pressione del tasto INVIO
	function keyCheckSearch(){
		if(event.keyCode == 13)
			checkSearch();
	}
	
	// Submit di ricerca pagina nei gadgets
	function passForDid(cidValue, pageValue, orderbyValue, senseValue){
		if(trim(cidValue) != "")
			window.location.href = 'contents.php?cmd=gadgets&cid=' + cidValue + '&page=' + pageValue + '';
		else
			window.location.href = 'contents.php?cmd=gadgets&page=' + pageValue + '&orderby=' + orderbyValue + '&sense=' + senseValue + '';
	}
	
	// Elimina il carrello
	function delBasket(){
		if(confirm("Siete sicuri di voler svuotare il carrello?"))
			window.location.href = 'carrello.php?cnt=del';
	}
	
	// Elimina il prodotto dal carrello
	function delProdBasket(i){
		if(confirm("Siete sicuri di voler eliminare questo prodotto dal carrello?"))
			window.location.href = 'carrello.php?cnt=del&pid=' + i;
	}
	
	// Controlla la compilazione della form in CARRELLO
	function checkBasket(i, tot, ids, products, id_section, where, what){
		j = 0;
		
		if(ids.indexOf(";") != -1)
			id = ids.split(";");
		else{
			id = new Array();
			id[0] = ids;
		}
		
		if(products.indexOf(";") != -1)
			product = products.split(";");
		else{
			product = new Array();
			product[0] = products;
		}
		
		for(k=0; k<i; k++){
			x = 0;
			
			if(document.getElementById('size_' + id[k]) && (document.getElementById('size_' + id[k]).value == "" || document.getElementById('size_' + id[k]).value == "N")){
				alert("Attenzione!\nIl campo TAGLIA/MISURA per il prodotto \"" + product[k] + "\" non è stato selezionato...");
				j++;
				
				break;
			}
			
			if(document.getElementById('quantity_' + id[k]) && (document.getElementById('quantity_' + id[k]).value == "" || document.getElementById('quantity_' + id[k]).value == "N" || document.getElementById('quantity_' + id[k]).value == 0)){
				alert("Attenzione!\nIl campo QUANTITÀ per il prodotto \"" + product[k] + "\" non è stato compilato...");
				eval("document.carrello.quantity_" + id[k] + ".focus()");
				j++;
				
				break;
			}
			else if(document.getElementById('quantity_' + id[k]) && (isNaN(document.getElementById('quantity_' + id[k]).value))){
				alert("Attenzione!\nIl campo QUANTITÀ per il prodotto \"" + product[k] + "\" deve essere numerico...");
				eval("document.carrello.quantity_" + k + ".focus()");
				j++;
				
				break;
			}
			
			if(tot > 1){
				for(z=0; z<tot; z++){
					if(eval("document.carrello.color_" + id[k] + "[" + z + "]") && (eval("document.carrello.color_" + id[k] + "[" + z + "].checked == true") || eval("document.carrello.color_" + id[k] + "[" + z + "].style.display == 'none'")))
						x++;
				}
				
				if(x == 0){
					alert("Attenzione!\nIl campo COLORE per il prodotto \"" + product[k] + "\" non è stato selezionato...");
					return false;
				}
			}
		}
		
		if(j == 0){
			document.carrello.to_do.value = "reload";
			var add_url = "";
			
			if(trim(id_section) != "")
				add_url = "&cid=" + id_section;
			
			if(where == "contents"){
				document.carrello.action = "contents.php?cmd=catalogo" + add_url;
				document.carrello.submit();
			}
			else if(where == "carrello"){
				document.carrello.action = "carrello.php?cnt=" + what + add_url;
				document.carrello.submit();
			}
		}
	}
	
	// Controlla la compilazione della form in CARRELLO
	function confBasket(id_section){
		var goodEmail = document.dati.mail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		
		if(document.dati.nome.value == ""){
			alert("Attenzione!\nIl campo NOME non è stato compilato correttamente...");
			document.dati.nome.focus();
		}
		else if(document.dati.cognome.value == ""){
			alert("Attenzione!\nIl campo COGNOME non è stato compilato correttamente...");
			document.dati.cognome.focus();
		}
		else if(!goodEmail){
			alert("Attenzione!\nIl campo E-MAIL non è stato compilato correttamente...");
			document.dati.mail.focus();
		}
		else if(document.dati.telefono.value == ""){
			alert("Attenzione!\nIl campo TELEFONO non è stato compilato correttamente...");
			document.dati.telefono.focus();
		}
		else if(document.dati.indirizzo.value == ""){
			alert("Attenzione!\nIl campo INDIRIZZO non è stato compilato correttamente...");
			document.dati.indirizzo.focus();
		}
		else if(document.dati.privacy.checked == false)
			alert("Attenzione!\nIl campo PRIVACY non è stato contrassegnato...");
		else{
			document.dati.cnt.value = "do_acq";
			document.dati.cid.value = id_section;
			document.dati.submit();
		}
	}
	
	// Controlla la password in DOWNLOADS
	function checkPwd(allegato, pwd){
		if(trim(document.getElementById('pwd').value) == "")
			alert("Attenzione!\nLa PASSWORD inserita non è corretta...");
		else if(trim(document.getElementById('pwd').value) == trim(pwd))
			window.open('images/downloads/' + allegato + '', 'download');
		else
			alert("Attenzione!\nLa PASSWORD inserita non è corretta...");
	}
//-->