//popup privacy
var usescroll='no'
function loadwindow(url,wid,hei,wtit){
var sW = (window.screen.width-wid)/2;
var sH = (window.screen.height-hei)/2;
	var miawin=window.open(url,wtit,
"toolbar=no,menubar=no,location=no,scrollbars="+usescroll+",resizable=no,height="+hei+",width="+wid+",top="+sH+",left="+sW);
miawin.focus();
}

//preload immagini
/*
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
*/
//var preloadFlag = false;
function preloadImages() {
	//if (document.images) {
	//	menu_01_over = newImage("img/menu_01-over.gif");	
	//	preloadFlag = true;
	//}
}




//convalida form contatti
//document.getElementById('XXX')
function formValidate() {
	if(document.forms[0].nome.value == ""){
		alert("Il campo 'Nome' è obbligatorio");
		document.forms[0].nome.focus();
		return false;		
	}
		else if(document.forms[0].cognome.value == ""){
		alert("Il campo 'Cognome' è obbligatorio");
		document.forms[0].cognome.focus();
		return false;		
	}
		else if(document.forms[0].mail.value == ""){
		alert("Il campo 'E-mail' è obbligatorio");
		document.forms[0].mail.focus();
		return false;		
	}
	else { return true }
}

//correggi PNG
function correggiPNG() 
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}


// ridimensiona immagini
function resize_img(immagine, w_max, h_max) {
	img=document.getElementById(immagine)
	var img1 = new Image;
	img1.src = img.src;

if (img1.width > w_max || img1.height > h_max) {
		var scale_w = w_max / parseInt(img1.width);
		var scale_h = h_max / parseInt(img1.height);
		var h = img1.height * scale_w;
		if (h > h_max) {
			img.width = img1.width * scale_h;
			img.height = (img1.height > h_max) ? h_max : img1.height;
		}
		else {
			img.width = (img1.width > w_max) ? w_max : img1.width;
			img.height = h;
		}
	}
	img.style.display = "inline";
}

//limita caratteri text area
function limitaText(areaName,counter,limit)
{
	if (areaName.value.length>limit) {
		areaName.value=areaName.value.substring(0,limit);
		alert("Hai superato il limite massimo di caratteri consentiti!");
	}
	else
		counter.value = limit - areaName.value.length +" caratteri disponibili";
}
