
var slideMoving = false;
var secondaryCheckForm = true;
var secondaryAnimation = false;



function dragSelect(s) {
	if (document.all) {
		document.documentElement.onselectstart = function() {
			if (s == "none") {
				return false;
			} else {
				return true;
			}
		}
	} else {
		document.documentElement.style.MozUserSelect = s;
	}
}


function setDateInputField() {
	$.each($(":input[rel='date|1']"), function() {
		if ($(this).attr("value") == "") {
			$(this).attr("value", "GG/MM/AAAA");
		}
	});
	$(":input[rel^='date|']").focus(function(){
		if ($(this).attr("value") == "GG/MM/AAAA") {
			$(this).attr("value", "");
		}
	});
	$(":input[rel='date|1']").blur(function(){
		if ($(this).attr("value") == "") {
			$(this).attr("value", "GG/MM/AAAA");
		}
	});
}


function setCurrencyFormat(val, cur, format) {
	val = val.toString().replace(/\,/g, ".");
	val = val.replace("€", "");
	val = val.replace(/\s/g, "");
	var newVal = "";
	var countDots = 0;
	for (var i=val.length; i>0; i--) {
		if (val.substring(i-1, i) == ".") {
			countDots++;
			if (countDots > 1) {
				i--;
			}
		}
		if (i > 0) {
			newVal = val.substring(i-1, i) + newVal;
		}
	}
	if (newVal.substring(newVal.length-1, newVal.length) == ".") {
		newVal = newVal.substring(0, newVal.length-1);
	}
	val = Number(newVal).toFixed(2).toString();
	val = val.replace(".", ",");
	if (format) {
		if (val.indexOf(",") > -1) {
			leftPart = val.substring(0, val.indexOf(","));
			rightPart = val.substring(val.indexOf(","), val.length);
		} else {
			leftPart = val;
			rightPart = "";
		}
		val = "";
		for (var i=leftPart.length; i>0; i--) {
			if ((val.replace(/\./g, "").length%3==0) && (val.length > 2)) {
				val = "." + val;
			}
			val = leftPart.substring(i-1, i) + val;
		}
		val += rightPart.toString();
	}
	if (cur) {
		val = "€ " + val;
	}
	return val;
}



function copyToClipboard(val) {
    if (window.clipboardData && clipboardData.setData) {
        clipboardData.setData("text", val);
    }
}



function checkInputTextDigitLength(obj) {
	if (obj == null) {
		obj = $(":input[max='counting']");
	}
	$.each(obj, function(i){
		if ($($(this).parent().children().get($(this).parent().children().size()-1)).attr("rel") != "counting") {
			var lengthInfo = $("<span>");
			lengthInfo.attr("rel", "counting");
			lengthInfo.addClass("info");
			lengthInfo.css("position", "relative");
			lengthInfo.text("Caratteri disponibili ("+$(this).attr("value").length+"/"+$(this).attr("maxlength")+")");
			$(this).parent().append("<br />");
			$(this).parent().append(lengthInfo);
		}
	});
	obj.bind("keydown", function(e){
		if ($(this).attr("value").length > parseInt($(this).attr("maxlength"))) {
			return false;
		} else {
			$(this).bind("keyup", function(){
				$(this).parent().children("span").text("Caratteri disponibili ("+$(this).attr("value").length+"/"+$(this).attr("maxlength")+")");
				return true;
			});
	}
	});
}


function selectGraphicRadio() {
	var obj = $("a[rel^='selectGraphicRadio(']");
	obj.children("input").hide();
	$.each(obj, function(i){
		if ($(this).attr("rel").substring($(this).attr("rel").lenght-2, $(this).attr("rel").lenght) == "1)") {
			$(this).children("input").attr("checked", "checked");
			$(this).attr("class", "selectGraphicRadio_ON");
		} else {
			$(this).children("input").attr("checked", false);
			$(this).attr("class", "selectGraphicRadio_OFF");
		}
	});

	obj.bind("click", function(){
		$(this).children("input").attr("checked", "checked");
		$(this).attr("class", "selectGraphicRadio_ON");
	});
	return false;
}


function fbs_click(fbUrl, fbTitle, fbDescription, fbPicture) {
	window.open("http://www.facebook.com/sharer.php?s=100&p[title]="+encodeURIComponent(fbTitle)+"&p[summary]="+encodeURIComponent(fbDescription)+"&p[url]="+encodeURIComponent(fbUrl)+"&p[images][0]="+encodeURIComponent(fbPicture), "sharer", "toolbar=0, status=0, width=600, height=400");
	return false;
}







function openOverTextarea(objId, objName, objTitle, objMessage, objMaxlength, objValue, dbTable, formMethod, formAction) {
	var sending = false;

	var mask = $("<div id='openOverTextarea_DIV'>");
	mask.css("z-index", "1000");
	mask.css("position", "fixed");
	mask.css("top", "0px");
	mask.css("left", "0px");
	mask.css("width", "500px");
	mask.css("height", "auto");
	mask.css("min-height", "50px");
	mask.css("overflow", "hidden");
	mask.css("padding", "0px 0px 0px 0px");
	mask.css("margin", "0px 0px 0px 0px");

	var inTop = $("<div>");
	inTop.css("width", "500px");
	inTop.css("height", "20px");
	inTop.css("background", "url(/images/template/textareaOver_TOP.png) 0% 0% no-repeat");

	var inMiddle = $("<div>");
	inMiddle.css("position", "relative");
	inMiddle.css("width", "460px");
	inMiddle.css("height", "auto");
	inMiddle.css("minheight", "50px");
	inMiddle.css("background", "url(/images/template/textareaOver_MIDDLE.png) 0% 0% repeat-y");
	inMiddle.css("padding", "0px 20px 0px 20px");

	var inBottom = $("<div>");
	inBottom.css("width", "500px");
	inBottom.css("height", "20px");
	inBottom.css("background", "url(/images/template/textareaOver_BOTTOM.png) 0% 0% no-repeat");

	if ((objTitle != null) && (objTitle != "")) {
		var inTitle = $("<div>");
		inTitle.addClass("info");
		inTitle.css("font-weight", "bold")
		inTitle.css("padding", "0px 0px 7px 0px");
		inTitle.html(objTitle);
		inMiddle.append(inTitle);
	}

	if ((objMessage != null) && (objMessage != "")) {
		var inMessage = $("<div>");
		inMessage.css("padding", "0px 0px 7px 0px");
		inMessage.html(objMessage);
		inMiddle.append(inMessage);
	}

	var inForm = $("<form>");
	inForm.attr("id", "overlayTextarea_FORM");
	inForm.attr("name", "overlayTextarea_FORM");
	inForm.attr("method", formMethod);
	inForm.attr("action", formAction);

	var inTextarea = $("<textarea>");
	inTextarea.attr("id", objName);
	inTextarea.attr("name", objName);
	inTextarea.addClass("inputTextarea");
	inTextarea.css("width", "450px");
	inTextarea.css("height", "100px");
	inTextarea.text(objValue);
	if ((objMaxlength != null) && (objMaxlength != "")) {
		inTextarea.attr("max", "counting");
		inTextarea.attr("maxlength", objMaxlength);
	}
	inForm.append(inTextarea);
	inMiddle.append(inForm);

	var inMiddleButton = $("<div>");
	inMiddleButton.css("width", "460px");
	inMiddleButton.css("height", "auto");
	inMiddleButton.css("background", "url(/images/template/textareaOver_MIDDLE.png) 0% 0% repeat-y");
	inMiddleButton.css("padding", "10px 20px 0px 20px");
	inMiddleButton.css("text-align", "right");

	var inButtonSend = $("<button>");
	inButtonSend.css("margin", "0px 20px 0px 0px");
	inButtonSend.css("border", "1px solid #cccccc");
	inButtonSend.css("border-left", "5px solid #cccccc");
	inButtonSend.css("cursor", "pointer");
	inButtonSend.css("width", "auto");
	inButtonSend.css("height", "20px");
	inButtonSend.css("line-height", "16px");
	inButtonSend.css("font-weight", "bold");
	inButtonSend.css("font-family", "verdana");
	inButtonSend.css("font-size", "10px");
	inButtonSend.css("color", "#666666");
	inButtonSend.hover(
		function(){
			$(this).css("border", "1px solid #81b2e9");
			$(this).css("border-left", "5px solid #81b2e9");
			$(this).css("color", "#047b99");
		},
		function(){
			$(this).css("border", "1px solid #cccccc");
			$(this).css("border-left", "5px solid #cccccc");
			$(this).css("color", "#666666");
		}
	);
	inButtonSend.bind("click", function(){
		if (!sending) {
			sending = true;
			$(this).css("border", "1px solid #cccccc");
			$(this).css("border-left", "5px solid #cccccc");
			$(this).attr("disabled", "disbled");
			$(this).parent().prev().children("form").children("textarea").attr("disabled", "disbled");
			var inLoading = $("<img border='0' align='absmiddle' src='/images/template/videoContainerLoading_White.gif'>");
			inLoading.css("position", "absolute");
			inLoading.css("top", Math.round(parseInt($(this).parent().prev().height()/2)-8).toString()+"px");
			inLoading.css("left", Math.round(parseInt($(this).parent().prev().width()/2)-8).toString()+"px");
			//inLoading.css("top", "16px");
			//inLoading.css("left", Math.round(parseInt($(this).parent().parent().width()-30)).toString()+"px");
			inLoading.css("width", "16px");
			inLoading.css("height", "16px");
			$(this).parent().prev().append(inLoading);
			//$(this).parent().parent().append(inLoading);
			//return false;
			ajaxScript($("#overlayTextarea_FORM").attr("method"), $("#overlayTextarea_FORM").attr("action"), objId, objName);
		}
	});
	inButtonSend.text("SALVA");
	inMiddleButton.append(inButtonSend);

	var inButtonAbort = $("<button>");
	inButtonAbort.css("margin", "0px 20px 0px 0px");
	inButtonAbort.css("border", "1px solid #cccccc");
	inButtonAbort.css("border-left", "5px solid #cccccc");
	inButtonAbort.css("cursor", "pointer");
	inButtonAbort.css("width", "auto");
	inButtonAbort.css("height", "20px");
	inButtonAbort.css("line-height", "16px");
	inButtonAbort.css("font-weight", "bold");
	inButtonAbort.css("font-family", "verdana");
	inButtonAbort.css("font-size", "10px");
	inButtonAbort.css("color", "#666666");
	inButtonAbort.hover(
		function(){
			$(this).css("border", "1px solid #81b2e9");
			$(this).css("border-left", "5px solid #81b2e9");
			$(this).css("color", "#047b99");
		},
		function(){
			$(this).css("border", "1px solid #cccccc");
			$(this).css("border-left", "5px solid #cccccc");
			$(this).css("color", "#666666");
		}
	);
	inButtonAbort.bind("click", function(){
		closeOverlayDiv();
	});
	inButtonAbort.text("ANNULLA");
	inMiddleButton.append(inButtonAbort);

	mask.append(inTop);
	mask.append(inMiddle);
	mask.append(inMiddleButton);
	mask.append(inBottom);

	$(document.body).append(createAlphaBody("#ffffff", "0.6")).append(mask);
	checkInputTextDigitLength($("#openOverTextarea_DIV").children("div").children("form").children("textarea"));
	$("#openOverTextarea_DIV").css("left", Math.round(parseInt($(window).width()/2)-parseInt($("#openOverTextarea_DIV").width()/2)).toString()+"px");
	$("#openOverTextarea_DIV").css("top", Math.round(parseInt($(window).height()/2)-parseInt($("#openOverTextarea_DIV").height()/2)).toString()+"px");
}


function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
    } else {
		return document[movieName];
    }
}



function videoPlayerInfoVideo(movieId, info) {
	$("#"+movieId+"_info").text(info);
}


function videoPlayerChangeVideo(videoUrl, movieId) {
	var flashFunction = thisMovie("gWebPlayer_"+movieId);
	flashFunction.setNewVideoFromJs(videoUrl);
}

function videoPlayerResize(movieId, w, h) {
	$("#"+movieId).css("width", w.toString() + "px");
	$("#"+movieId).css("height", h.toString() + "px");
	$("#"+movieId).children("object").css("width", w.toString() + "px");
	$("#"+movieId).children("object").css("height", h.toString() + "px");
	$("#"+movieId).children("embed").attr("width", w.toString());
	$("#"+movieId).children("embed").attr("height", h.toString());
	$("#"+movieId+" div[rel='videoContainerLoading']").remove();
	return false;
}





function fixMiddleHeight() {
	var leftDiv = "#middlePage_Left_DIV";
	var centerDiv = "#middlePage_Center_DIV";
	var rightDiv = "#middlePage_Right_DIV";
	if (objExists("div", "middlePage_Left_DIV")) {
		var pageLeft = $(leftDiv).height();
		var pageRight = $(rightDiv).height();
		if (pageLeft < pageRight) {
			$(leftDiv).css("minHeight", pageRight.toString()+"px");
			$(centerDiv).css("minHeight", pageRight.toString()+"px");
		} else {
			$(rightDiv).css("minHeight", pageLeft.toString()+"px");
			$(centerDiv).css("minHeight", pageLeft.toString()+"px");
		}
	}
}


/*

function addVideoJs(videoUrl, videoId, videoWidth, videoPic, originalWidth, originalHeight) {
	var videoHeight = videoRisizeFix(originalWidth, originalHeight, videoWidth);
	var videoType = videoUrl.substring(videoUrl.length-3, videoUrl.length);
	var video = $("<video width='"+videoWidth+"' height='"+videoHeight+"' src='"+videoUrl+"' type='video/"+videoType+"' id='videoPlayer_"+videoId+"' poster='"+videoPic+"' controls='controls' preload='none'>")
	$(video).appendTo($("#videoContainer_"+videoId));
	$("#videoPlayer_"+videoId).mediaelementplayer({
		success: function(player, node) {
			$("#" + node.id + "-mode").html("mode: " + player.pluginType);
		}
	});
}
*/



function videoRisizeFix(w, h, wNew) {
	var s = 0;
	if (!isNaN(wNew)) {
		s = Math.floor((h/w)*wNew);
	}
	return s;
}



function absoluteContainerPositioning(objId) {
	var obj;
	if ($("#createAlpha_DIV")) {
		obj = $("#createAlpha_DIV");
		$(obj).css("width", $(window).width());
		$(obj).css("height", $(window).height());
	}
	if ($("#"+objId)) {
		obj = $("#"+objId);
		$(obj).css("top", parseInt($(window).height()/2)-parseInt($(obj).height()/2)-13-30);
		$(obj).css("left", parseInt($(window).width()/2)-parseInt($(obj).width()/2)-11);
	}
}



function checkPwdLevelBar(obj, e) {
	var pwdLevel = -1;
	if (obj.val().length >= 6) {
		var riseStr = "!-_#";
		pwdLevel += 1;
		for (i=0; i<obj.val().length; i++) {
			newChr = obj.val().charAt(i);
			if ($.isNumeric(newChr)) {
				pwdLevel += 1;
				break;
			}
		}
		for (i=0; i<obj.val().length; i++) {
			newChr = obj.val().charAt(i);
			if (riseStr.indexOf(newChr) > -1) {
				pwdLevel += 1;
				break;
			}
		}
		if (!isNaN(obj.val())) {
			pwdLevel = 0;
		}
	}
	$("#pwdBar_DIV div[rel^='level_']").css("background-color", "#cccccc");
	for (var i=0; i<pwdLevel+1; i++) {
		$("#pwdBar_DIV div[rel='level_"+i+"']").css("background-color", "#81b2e9");
	}
	return pwdLevel;
}



function browserSize(side) {
	switch (side.toLowerCase()) {
		case "w":
			side = $(window).width();
			break;
		case "h":
			side = $(window).height();
			break;
		default:
			side = 0;
			break;
	}
	return side;
}







function addMiniPic(id, macrocategory, macroname) {
	var obj = $("#"+id);

	var div = $("<div>");
	div.css("width", "100px");
	div.css("height", "90px");
	div.css("text-align", "center");
	div.css("float", "left");

	var img =$("<img>");
	img.attr("align", "absmiddle");
	img.attr("border", "0");
	img.attr("width", "50");
	img.attr("height", "50");
	img.attr("src", "/images/macrocategory/png/"+macrocategory+"_S.png");
	img.css("width", "50px");
	img.css("height", "50px");
	img.hover(
		function() {
			$(this).animate({width:60, height:60}, 200, function(){});
		},
		function() {
			$(this).animate({width:50, height:50}, 200, function(){});
		}
	);

	var a = $("<a>");
	a.attr("href", "javascript:void(0);");
	a.bind("click", function(){
		$("div[rel^='macrocategory(']").hide();
		$("div[rel='macrocategory("+macrocategory+")']").show();
		$(window).scrollTop($("div[rel='macrocategory("+macrocategory+")']").offset().top);
		return false;
	});
	a.append(img);
	a.append("<br />"+macroname)

	div.append(a);
	obj.append(div);
	obj.show();
}







function tempIframe(iframeId) {
	var iframeTemp = $("<iframe id='"+iframeId+"' name='"+iframeId+"' scrolling='auto' frameborder='0' width='0' height='0' src='/_blank.htm'>");
	$(iframeTemp).css("position", "absolute");
	$(iframeTemp).css("top", "0");
	$(iframeTemp).css("left", "0");
	$(iframeTemp).css("z-index", "4");
	return $(iframeTemp);
	//$(iframeTemp).appendTo(document.body);
}



function hideSwf(opt) {
	if ((vis == "visible") || (vis == "hidden")) {
		cssFunction = "visibility";
	} else {
		cssFunction = "display";
	}
	$("div[rel='swf_hide']").css(cssFunction , opt);
}







function currency(n) {
	n = n.toString();
	var nCheck = 0;
	var nCurrency = "";
	var nPart = "";
	for (var i=n.length; i>0; i--) {
		nPart = n.substring(i-1, i);
		if (!isNaN(nPart)) {
			nCheck++;
			if (nCheck == 3) {
				nCurrency = "," + nCurrency;
			} else {
				if ((nCurrency.indexOf(",") == 3) || (nCurrency.indexOf(".") == 3)) {
					nCurrency = "." + nCurrency;
				}
			}
			nCurrency = nPart + nCurrency;
		}
	}
	if ((nCurrency == "") || (nCurrency == null)) {
		nCurrency = "0,00";
	}
	return nCurrency;
}


function convertDouble(n) {
	n = n.replace(/\./g, "");
	n = n.replace(/\,/g, ".");
	return Number(n);
}




function getQueryString(query) {
	var qNew = null;
	var qString = location.href.toLowerCase().split("?");
	qString = qString[1].split("&");
	for (var i=0; i<qString.length; i++) {
		if (qString[i].substring(0, 2) == query.toLowerCase()+"=") {
			qNew = qString[i].substring(2, qString[i].length);
			break;
		}
	}
	return qNew == null ? null : qNew;
}







function setNewCookie(cookieName, cookieValue, expireDays, cookiePath, cookieDomain) {
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate() + expireDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + ((expireDays==null) ? "" : "; expires=" + expireDate.toUTCString()) + ((cookiePath==null) ? "" : "; path=" + cookiePath) + ((cookieDomain==null) ? "" : "; domain=" + cookieDomain);
}



function getOldCookie(cookieName) {
	if (document.cookie.length > 0) {
  		cookieStart = document.cookie.indexOf(cookieName + "=");
		if (cookieStart > -1) {
    		cookieStart = cookieStart + cookieName.length + 1;
    		cookieEnd = document.cookie.indexOf(";", cookieStart);
    		if (cookieEnd == -1) {
    			cookieEnd = document.cookie.length;
    		}
   	 		return unescape(document.cookie.substring(cookieStart, cookieEnd));
    	}
	}
	return "";
}















function setDbForm(pageId, pageValue, formId) {
	if (objExists("input", pageId)) {
		$("#"+pageId).attr("value", pageValue);
	}
	sendForm(formId);
}



function setProvince(obj) {
	var arr = $(obj).attr("value").split("|");
	if ($(arr).size() > 1) {
		$("#province").attr("value", $(arr).get(0));
		$("#region").attr("value", $(arr).get(1));
		$("#country").attr("value", $(arr).get(2));
	} else {
		$("#province").attr("value", "");
		$("#region").attr("value", "");
		$("#country").attr("value", "");
	}
}




var gSpamCode = "";
function releaseSpamCode(min, max, objId, wh) {
 	$("#"+objId).hide();
	var img;
	var tmp_code;
	gSpamCode = ""
	var spamCode = "";
	var chr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	max = Math.round((Math.random() * parseInt(max-min)) + min);
	$("#"+objId).html("");
	for (var i=0; i<max; i++) {
		tmp_code = chr.charAt(Math.round(Math.random() * chr.length)).toUpperCase();
 		if (tmp_code == "") {
 			tmp_code = "0"
 		}
 		gSpamCode += String(tmp_code);
 		spamCode += String(tmp_code);
 		var img = $("<img style='background-color:#ffffff;' id='spamCode_IMG_"+i+"' border='0' align='absmiddle' width='"+wh+"' height='"+wh+"' src='/images/spamCode/"+tmp_code+".gif'>");
		$("#"+objId).append(img);
 		$("#sph").attr("value", spamCode);
 	}
 	$("#"+objId).fadeIn(600);
}



function checkSpamCode(objId) {
	var obj = $("#"+objId).attr("value")
	if (obj == "") {return false;}
	obj = obj.toUpperCase();
	if (obj != gSpamCode) {
		return false;
	} else {
		return true;
	}
}



function opencloseWin(id, s) {
	obj = $("#win_count_"+id);
	if ((obj.prev().children(0).children(0).children(0).attr("src").toLowerCase() == "/images/template/closetitle.gif") || (s == 1)) {
		obj.slideUp(300);
		obj.prev().children(0).children(0).children(0).attr("src", "/images/template/opentitle.gif");
		obj.prev().children(0).children(0).children(0).attr("alt", "MOSTRA");
	} else if ((obj.prev().children(0).children(0).children(0).attr("src").toLowerCase() == "/images/template/opentitle.gif") || (s == 0)) {
		obj.slideDown(300);
		obj.prev().children(0).children(0).children(0).attr("src", "/images/template/closetitle.gif");
		obj.prev().children(0).children(0).children(0).attr("alt", "NASCONDI");
	}
}




function CheckRegExpression(str, regPattern) {
	var regExpression = new RegExp(regPattern);
	return regExpression.test(str);
}



function checkDate(d, obj) {
	if (!CheckRegExpression(d, /^(\d{1,})+(\-|\/)+(\d{1,})+(\-|\/)+(\d{4})$/)) {
	//n{\-,\/}
		return false;
	} else {
		var today = new Date();
		d = d.split("/");
		var bornDay = String(d[0]);
		var bornMonth = String(d[1]);
		var bornYear = String(d[2]);
		if (bornDay.charAt(0) == "0") {bornDay = bornDay.replace("0", "");}
		if (bornMonth.charAt(0) == "0") {bornMonth = bornMonth.replace("0", "");}
		if (	(((bornMonth == 4) || (bornMonth == 9) || (bornMonth == 9) || (bornMonth == 11)) && (bornDay > 30)) ||
				((bornMonth == 2) && (bornDay > 29)) ||
				((bornMonth == 2) && (bornDay > 28) && ((bornYear % 4) != 0)) ||
				(bornDay < 1) ||
				(bornMonth < 1) ||
				(bornYear > today.getFullYear())
			) {return false;}
	}
	if (String(bornDay).length < 2) {bornDay = String("0" + bornDay);}
	if (String(bornMonth).length < 2) {bornMonth = String("0" + bornMonth);}
	obj.value = bornDay + "/" + bornMonth + "/" + bornYear;
	return true;
}




/*
function loadImages() {
	var images = "/images/loading/gLoading100.png";
	images = images.split(images, ", ");
	var pic = null;
	for (var i=0; i<images.length; i++) {
		pic = new Images();
		pic.src = images[i];
	}
}
loadImages();
*/




/* ----------------------to delete

*/









//////////////////---------old------




function addSelectOption(optionId, optionValue, optionShow, optionSelect) {
	var obj = document.getElementById(optionId);
	if (!obj) {return false;}
	var opt = document.createElement("option");
	opt.setAttribute("value", optionValue);
	opt.appendChild(document.createTextNode(optionShow));

	if (optionSelect == 1) {
		opt.selected = true;
	}
	obj.appendChild(opt);
}













function hideWtbProvince(pv) {
	if (pv == "") {return false;}
	var obj = document.getElementsByTagName("div");
	for (var i=0; i<obj.length; i++) {
		if (obj[i].getAttribute("rel")) {
			if (obj[i].getAttribute("rel") == "PROVINCE|"+pv) {
				obj[i].style.display = "block";
			} else if (obj[i].getAttribute("rel").indexOf("PROVINCE|") > -1) {
				obj[i].style.display = "none";
			}
		}
	}
}





function screenSize(side) {
	switch (side.toLowerCase()) {
		case "w":
			side = screen.availWidth;
			break;
		case "h":
			side = screen.availHeight;
			break;
		default:
			side = 0;
			break;
	}
	return side;
}








function posBottompage() {
	var divId = "bottomPage_DIV";
	if (document.getElementById(divId)) {
		if (bodySize("h") < browserSize("h")) {
			//alert(browserSize("h"));
			document.getElementById(divId).style.position = "absolute";
			document.getElementById(divId).style.left = "0px";
			document.getElementById(divId).style.top = String((browserSize("h")-document.getElementById(divId).offsetHeight-1)+"px");
		} else {
			document.getElementById(divId).style.position = "relative";
		}
	}
	return false;
}


function bodyType() {
	var bod = null;
	if (navigator.appName=="Netscape") {
		if (document.documentElement) {
			//alert("document.documentElement");
			bod = document.documentElement;
		} else {
			//alert("window");
			bod = window;
		}
	} else if (navigator.appName.indexOf("Microsoft") > -1) {
		//alert("document.body");
		bod = document.body;
	}
	return bod;
}


function bodySize(side) {
	//alert(navigator.appName);
	if (navigator.appName=="Netscape") {
		if (side == "h") {
			if (document.documentElement) {
				side = document.documentElement.offsetHeight;
			} else {
				side = window.innerHeight;
			}
		} else if (side == "w") {
			if (document.documentElement) {
				side = document.documentElement.offsetWidth;
			} else {
				side = window.innerWidth;
			}
		}
	} else if (navigator.appName.indexOf("Microsoft") > -1) {
		if (side == "h") {
			side = document.body.offsetHeight;
		} else if (side == "w") {
			side = document.documentElement.offsetWidth;
		}
	}
	return side;
}






function overlayDivCloseButton() {
	var closeButton = createHtmlObject("a", "href:#", "border:0px solid #ff0000;position:absolute;left:50px;top:190px;height:10px;lineHeight:10px;fontSize:10px;color:#ffffff;fontWeight:normal", "CLICCA QUI O PREMI ESC PER CHIUDERE");
	closeButton.onmouseover = function() {this.style.color = "#047b99";}
	closeButton.onmouseout = function() {this.style.color = "#ffffff";}
	closeButton.onclick = function() {
		closeOverlayDiv();
	}
	return closeButton;
}



function hideBodyScroll(s) {
	var docBody = bodyType();
	if (s == 0) {
		docBody.setAttribute("scroll", "no");
		docBody.style.overflow = "hidden";
		docBody.style.width = String(screenSize("w") + "px");
	} else if (s == 1) {
		docBody.setAttribute("scroll", "auto");
		docBody.style.overflow = "visible";
		docBody.style.width = "auto";
		hideSwf("visible");
	}
}






















function createHtmlObject(tag, atr, stl, txt) {
	var obj = document.createElement(tag);
	var splitChar = ":";

	if (atr != "") {
		atr = atr.replace(/; /g, ";").split(";");
		for (var i=0; i<atr.length; i++) {
			if (atr[i].indexOf(splitChar) > -1) {
				a = atr[i].split(splitChar);
				obj.setAttribute(a[0], a[1]);
			}
		}
	}

	if (stl != "") {
		stl = stl.replace(/; /g, ";").split(";");
		for (var i=0; i<stl.length; i++) {
			if (stl[i].indexOf(splitChar) > -1) {
				s = stl[i].split(splitChar);
				sProperty = s[1].toString();
				switch (s[0].toLowerCase()) {
					case "width":
						obj.style.width = sProperty;
						break;
					case "height":
						obj.style.height = sProperty;
						break;
					case "lineheight":
						obj.style.lineHeight = sProperty;
						break;
					case "minwidth":
						obj.style.minWidth = sProperty;
						break;
					case "minheight":
						obj.style.minHeight = sProperty;
						break;
					case "maxwidth":
						obj.style.maxWidth = sProperty;
						break;
					case "maxheight":
						obj.style.maxHeight = sProperty;
						break;
					case "overflow":
						obj.style.overflow = sProperty;
						break;
					case "display":
						obj.style.display = sProperty;
						break;
					case "visibility":
						obj.style.visibility = sProperty;
						break;
					case "float":
						obj.style.cssFloat = sProperty;
						obj.style.styleFloat = sProperty;
						break;
					case "stylefloat":
						obj.style.cssFloat = sProperty;
						obj.style.styleFloat = sProperty;
						break;
					case "cssfloat":
						obj.style.cssFloat = sProperty;
						obj.style.styleFloat = sProperty;
						break;
					case "clear":
						obj.style.cssClear = sProperty;
						obj.style.styleClear = sProperty;
						break;
					case "styleclear":
						obj.style.cssClear = sProperty;
						obj.style.styleClear = sProperty;
						break;
					case "cssclear":
						obj.style.cssClear = sProperty;
						obj.style.styleClear = sProperty;
						break;
					case "position":
						obj.style.position = sProperty;
						break;
					case "top":
						obj.style.top = sProperty;
						break;
					case "left":
						obj.style.left = sProperty;
						break;
					case "color":
						obj.style.color = sProperty;
						break;
					case "fontsize":
						obj.style.fontSize = sProperty;
						break;
					case "fontfamily":
						obj.style.fontFamily = sProperty;
						break;
					case "fontweight":
						obj.style.fontWeight = sProperty;
						break;
					case "fontstyle":
						obj.style.left = sProperty;
						break;
					case "fontstyle":
						obj.style.fontStyle = sProperty;
						break;
					case "textalign":
						obj.style.textAlign = sProperty;
						break;
					case "texttransform":
						obj.style.textTransform = sProperty;
						break;
					case "textdecoration":
						obj.style.textDecoration = sProperty;
						break;
					case "margin":
						obj.style.margin = sProperty;
						break;
					case "margintop":
						obj.style.marginTop = sProperty;
						break;
					case "marginright":
						obj.style.marginRight = sProperty;
						break;
					case "marginbottom":
						obj.style.marginBottom = sProperty;
						break;
					case "marginleft":
						obj.style.marginLeft = sProperty;
						break;
					case "padding":
						obj.style.padding = sProperty;
						break;
					case "paddingtop":
						obj.style.paddingTop = sProperty;
						break;
					case "paddingright":
						obj.style.paddingRight = sProperty;
						break;
					case "paddingbottom":
						obj.style.paddingBottom = sProperty;
						break;
					case "paddingleft":
						obj.style.paddingLeft = sProperty;
						break;
					case "backgroundcolor":
						obj.style.backgroundColor = sProperty;
						break;
					case "border":
						obj.style.border = sProperty;
						break;
					case "bordertop":
						obj.style.borderTop = sProperty;
						break;
					case "borderright":
						obj.style.borderRight = sProperty;
						break;
					case "borderbottom":
						obj.style.borderBottom = sProperty;
						break;
					case "borderleft":
						obj.style.borderLeft = sProperty;
						break;
					case "background":
						obj.style.background = sProperty;
						break;
					case "backgroundimage":
						obj.style.backgroundImage = sProperty;
						break;
					case "backgroundposition":
						obj.style.backgroundPosition = sProperty;
						break;
					case "backgroundrepeat":
						obj.style.backgroundRepeat = sProperty;
						break;
					case "zindex":
						obj.style.zIndex = sProperty;
						break;
					case "cursor":
						obj.style.cursor = sProperty;
						break;
					case "filter":
						obj.style.filter = sProperty;
						break;
					case "opacity":
						obj.style.opacity = sProperty;
						break;
					case "class":
					case "classname":
						if (document.getElementById("checkCssClass")) {
							if (document.getElementById("checkCssClass").getAttribute("class")) {
								obj.setAttribute("class", sProperty);
							} else {
								obj.setAttribute("className", sProperty);
							}
						}
						break;
					case "maxlength":
						obj.maxLength = sProperty;
						break;

				}
			}
		}
	}

	if (txt != "") {
		obj.innerHTML = txt;
	}
	return obj;
}



function addProvince(id, pv, pvName) {
	var a = createHtmlObject("a", "", "cursor:pointer", pvName);
	a.onclick = function() {
		hideWtbProvince(pv);
		return false;
	}
	document.getElementById(id).appendChild(a);
}










function ms_tooltip(obj, s) {
	if (s == 1) {
		//obj.style.position = "relative";
		obj.lastChild.style.display = "block";
	} else if (s == 0) {
		obj.lastChild.style.display = "none";
		//obj.style.position = "static";
	}
}


function ftpClick(obj) {
	for (var i=1; i< obj.parentNode.childNodes.length; i++) {
		if (obj.parentNode.childNodes[i].style.display == "none") {
			obj.parentNode.childNodes[i].style.display = "block";
		} else {
				obj.parentNode.childNodes[i].style.display = "none";
		}
	}
}





function miniPicOpenDiv(r) {
	var obj = document.getElementsByTagName("DIV");
	for (var i=0; i<obj.length; i++) {
		if ((obj[i].getAttribute("rel")) && (obj[i].getAttribute("rel") == r)) {
			obj[i].style.display = "block";
		} else if ((obj[i].getAttribute("rel")) && (obj[i].getAttribute("rel").indexOf(r.substring(1, r.indexOf("macrocategory_"))) > -1)) {
			obj[i].style.display = "none";
		}
	}
	setBottom();
}



function productChangePage(obj, b) {
	obj = obj.parentNode.parentNode;
	for (var i=1; i<4; i++) {
		obj.childNodes[i].style.display = "none";
	}
	switch (b) {
		case 1:
			label = "Specifiche Tecniche";
			break;
		case 2:
			label = "Galleria Immagini";
			break;
		case 3:
			label = "Galleria Video";
			break;
	}
	document.getElementById("modelTitle_DIV").innerHTML = label;
	obj.childNodes[b].style.display = "block";
}




function showHideId(id) {
	obj = document.getElementById(id);
	if (!obj) {return false;}
	if (obj.style.display == "none") {
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}
}


/*
	function moveSlideMoving(pos, id) {
		var obj = document.getElementById(id);
		sPos = parseInt(obj.style.left.replace("px", ""));
		if (sPos > pos) {
			obj.style.left = String(parseInt(sPos-67) + "px");
			document.getElementById("asusbusinessMask_DIV").style.display = "block";
			var slideMove = setTimeout("moveSlideBusiness("+pos+")", 10);
		} else if (sPos < pos) {
			obj.style.left = String(parseInt(sPos+67) + "px");
			document.getElementById("asusbusinessMask_DIV").style.display = "block";
			var slideMove = setTimeout("moveSlideBusiness("+pos+")", 10);
		} else {
			document.getElementById("asusbusinessMask_DIV").style.display = "none";
			slideMoving = false;
			var objButt = document.getElementById("businessSlideButton_DIV");
		}
		return false;
	}
*/


function promoFlash(m, r) {
	switch (m) {
		case 0:
			document.getElementById("promoStep1_SELECT_"+r).selectedIndex = 0;
			document.getElementById("promoStep2_SELECT_"+r).selectedIndex = 0;
			document.getElementById("email_"+r).value = document.getElementById("emailRel_IMG").getAttribute("rel");
			document.getElementById("email_"+r).style.border = "1px solid #cccccc";
			document.getElementById("promoStep1_DIV_"+r).style.display = "none";
			document.getElementById("promoStep2_DIV_"+r).style.display = "none";
			document.getElementById("promoStep3_DIV_"+r).style.display = "none";
			document.getElementById("promoStep4_DIV_"+r).style.display = "none";
			break;
		case 1:
			document.getElementById("promoStep1_DIV_"+r).style.display = "block";
			document.getElementById("promoStep3_DIV_"+r).style.display = "block";
			break;
		case 2:
			if (document.getElementById("promoStep1_SELECT_"+r).options[document.getElementById("promoStep1_SELECT_"+r).selectedIndex].value != "") {
				document.getElementById("promoStep2_DIV_"+r).style.display = "block";
			} else {
				document.getElementById("promoStep2_DIV_"+r).style.display = "none";
			}
			break;
		case 3:
			if (document.getElementById("promoStep2_SELECT_"+r).options[document.getElementById("promoStep2_SELECT_"+r).selectedIndex].value != "") {
				document.getElementById("promoStep4_DIV_"+r).style.display = "block";
			} else {
				document.getElementById("promoStep4_DIV_"+r).style.display = "none";
			}
			break;
		case 4:
			var email = document.getElementById("email_"+r).value;
			if (!CheckRegExpression(email, /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})$/)) {
				document.getElementById("email_"+r).style.border = "1px solid #ff0000";
				return false;
			} else {
				document.getElementById("email_"+r).style.border = "1px solid #cccccc";
			}
			if (document.getElementById("promoStep1_INPUT_"+r)) {
				qty = document.getElementById("promoStep1_INPUT_"+r).value;
			} else {
				qty = document.getElementById("promoStep1_SELECT_"+r).options[document.getElementById("promoStep1_SELECT_"+r).selectedIndex].value;
			}
			promoLink = "/dealerarea/promoFlash.asp?add=1&idonline="+document.getElementById("idonline").value+"&promoId="+document.getElementById("promoId_"+r).value+"&promoFamily="+document.getElementById("promoFamily_"+r).value+"&promoQuantity="+qty+"&promoDistributor="+document.getElementById("promoStep2_SELECT_"+r).options[document.getElementById("promoStep2_SELECT_"+r).selectedIndex].value+"&email="+document.getElementById("email_"+r).value;
			location.href = promoLink;
			break;
		case 5:
			if (CheckRegExpression(document.getElementById("promoStep1_INPUT_"+r).value, /^\-?\d{1,}$/)) {
				document.getElementById("promoStep2_DIV_"+r).style.display = "block";
			} else {
				document.getElementById("promoStep2_SELECT_"+r).selectedIndex = 0;
				document.getElementById("promoStep2_DIV_"+r).style.display = "none";
			}
			break;
	}
}






function openDatasMenu(menu, obj) {
	obj = obj.parentNode;
	switch(menu) {
		case 101:
			divId = "vat_new_DIV";
			if (document.getElementById(divId)) {
				document.getElementById(divId).parentNode.removeChild(document.getElementById(divId));
				return false;
			}
			mainDiv = createHtmlObject("div", "id:"+divId, "clear:both", "");
			div = createHtmlObject("div", "", "clear:both;margin:3px 0px 3px 0px", "");
			div.appendChild(createHtmlObject("strong", "", "class:info", "*#"));
			div.appendChild(createHtmlObject("strong", "", "", " Nuova P. IVA "));
			div.appendChild(createHtmlObject("input", "rel:vat|1;type:text;name:vat_new;id:vat_new", "class:inputText;width:130px;maxlength:11", ""));
			mainDiv.appendChild(div);
			div = createHtmlObject("div", "", "clear:both;", "");
			div.appendChild(createHtmlObject("strong", "", "class:info", "*"));
			div.appendChild(createHtmlObject("strong", "", "", " RICHIEDO la modifica della P. IVA "));
			div.appendChild(createHtmlObject("input", "rel:checkbox|1;type:checkbox;name:vat_confirm;value:1", "", ""));
			mainDiv.appendChild(div);
			break;

		case 102:
			divId = "email_new_DIV";
			if (document.getElementById(divId)) {
				document.getElementById(divId).parentNode.removeChild(document.getElementById(divId));
				return false;
			}
			div = createHtmlObject("div", "id:"+divId, "clear:both", "");
			div.appendChild(createHtmlObject("strong", "", "class:info", "*#"));
			div.appendChild(createHtmlObject("strong", "", "", " Nuova email "));
			div.appendChild(createHtmlObject("input", "rel:email|1;type:text;name:email_new;id:email_new", "class:inputText;width:130px", ""));
			div2 = createHtmlObject("div", "", "clear:both;", "");
			div2.appendChild(createHtmlObject("strong", "", "class:info", "*"));
			div2.appendChild(createHtmlObject("strong", "", "", " RICHIEDO la modifica dell'email "));
			div2.appendChild(createHtmlObject("input", "rel:checkbox|1;type:checkbox;name:email_confirm;value:1", "", ""));
			div.appendChild(div2);
			break;

		case 103:
			var divId = "password_new_DIV";
			var pwd = obj.getAttribute("rel");
			var pwdStep = -1;
			if (document.getElementById(divId)) {
				document.getElementById(divId).parentNode.removeChild(document.getElementById(divId));
				return false;
			}
			mainDiv = createHtmlObject("div", "id:"+divId, "clear:both;textalign:right", "");

			//old pwd
			div = createHtmlObject("div", "", "clear:both;margin:3px 0px 3px 0px", "");
			div.appendChild(createHtmlObject("strong", "", "", "Vecchia password "));
			oldPwd = createHtmlObject("input", "rel:text|1;type:password;name:pwd_old;id:pwd_old", "class:inputText;width:100px", "");
			oldPwd.onblur = function() {
				pwdStep = matchPasswords(pwd);
			}
			div.appendChild(oldPwd);
			mainDiv.appendChild(div);

			//new pwd
			div = createHtmlObject("div", "", "clear:both;margin:3px 0px 3px 0px;display:none", "");
			div.appendChild(createHtmlObject("strong", "", "", "Nuova password "));
			newPwd = createHtmlObject("input", "rel:pwd|1;type:password;name:pwd_new;id:pwd_new", "class:inputText;width:100px", "")
			newPwd.onkeyup = function() {
				checkPwdLevel(this);
			}
			newPwd.onblur = function() {
				matchPasswords(pwd);
			}
			div.appendChild(newPwd);
			mainDiv.appendChild(div);

			//check pwd
			div = createHtmlObject("div", "id:pwd_level", "clear:both;height:10px;margin:3px 0px 3px 0px;display:none", "");
			div.appendChild(createHtmlObject("div", "title:LIVELLO DI PROTEZIONE ALTO", "float:right;width:60px;height:10px;lineheight:10px;backgroundcolor:#666666;textalign:center;color:#ffffff;fontsize:8px;margin:0px 0px 0px 1px", "ALTO"));
			div.appendChild(createHtmlObject("div", "title:LIVELLO DI PROTEZIONE MEDIO", "float:right;width:60px;height:10px;lineheight:10px;backgroundcolor:#666666;textalign:center;color:#ffffff;fontsize:8px;margin:0px 0px 0px 1px", "MEDIO"));
			div.appendChild(createHtmlObject("div", "title:LIVELLO DI PROTEZIONE BASSO", "float:right;width:60px;height:10px;lineheight:10px;backgroundcolor:#666666;textalign:center;color:#ffffff;fontsize:8px;margin:0px 0px 0px 1px", "BASSO"));
			div.appendChild(createHtmlObject("div", "", "float:right;color:#81b2e9;fontweight:bold", "Livello&nbsp;"));
			mainDiv.appendChild(div);

			//repeat pwd
			div = createHtmlObject("div", "", "clear:both;margin:3px 0px 3px 0px;display:none", "");
			div.appendChild(createHtmlObject("strong", "", "", "Ripeti nuova password "));
			repeatPwd = createHtmlObject("input", "rel:pwd|1;type:password;name:pwd_repeat;id:pwd_repeat", "class:inputText;width:100px;", "");
			repeatPwd.onblur = function() {
				matchPasswords(pwd);
			}
			div.appendChild(repeatPwd);

			mainDiv.appendChild(div);
			break;
	}
	obj.appendChild(mainDiv);
}



function matchPasswords(pwd) {
	var pwdOld = document.getElementById("pwd_old");
	var pwdNew = document.getElementById("pwd_new");
	var pwdRepeat = document.getElementById("pwd_repeat");
	var pwdLevel = document.getElementById("pwd_level");
	var pwdOk = document.getElementById("pwd_ok");
	var step = -1;
	if (pwdOld.value == pwd) {
		pwdNew.parentNode.style.display = "block";
		pwdOld.parentNode.style.color = "#000000";
		pwdLevel.style.display = "block";
		step += 1;
	} else if (pwdOld.value != "") {
		pwdRepeat.value = "";
		pwdRepeat.parentNode.style.display = "none";
		pwdLevel.style.display = "none";
		pwdNew.value = "";
		pwdNew.parentNode.style.display = "none";
		pwdOld.parentNode.style.color = "#ff0000";
		step -= 1;
	}
	if ((pwdNew.value != "") && (step > -1)) {
		if (pwdNew.value != pwdOld.value) {
			if (secondaryCheckForm) {
				pwdRepeat.parentNode.style.display = "block";
				pwdNew.parentNode.style.color = "#000000";
			} else {
				pwdNew.parentNode.style.color = "#ff0000";
				pwdRepeat.value = "";
				pwdRepeat.parentNode.style.display = "none";
			}
			step += 1;
		} else {
			pwdNew.parentNode.style.color = "#ff0000";
			step -= 1;
		}
	}
	if ((pwdRepeat.value != "") && (step > 0)) {
		if (pwdRepeat.value == pwdNew.value) {
			pwdRepeat.parentNode.style.color = "#000000";
			step += 1;
		} else {
			pwdRepeat.parentNode.style.color = "#ff0000";
			step -= 1;
		}
	}
	step += checkPwdLevel(pwdNew);
	document.getElementById("pwdStepInfo").innerHTML = step;
	if (step == 2) {
		pwdOk.setAttribute("src", "/images/systemicon/png/unlock.png");
	} else {
		pwdOk.setAttribute("src", "/images/systemicon/png/lock.png");
	}
	return step;
}




function checkIfDifferentMovement(id0, id1, movement) {
	//alert(0);
	if (document.getElementById(id0) && document.getElementById(id1)) {
		switch(movement) {
			case 101:
			case 102:
			case 103:
				//alert(1);
				if (document.getElementById(id0).value == document.getElementById(id1).value) {
					//alert(2);
					document.getElementById(id1).parentNode.style.color = "#ff0000";
					return false;
				}
				break;
		}
	}
	return true;
}




function changePasswordText(id) {
	if (document.getElementById(id)) {
		obj = document.getElementById(id);
		objValue = obj.value
		var objParent = obj.parentNode;
		if (obj.getAttribute("type").toLowerCase() == "text") {
			objParent.removeChild(obj);
			objParent.appendChild(createHtmlObject("input", "rel:pwd|1;id:pwd;name:password;type:password;value:"+objValue, "class:inputText;width:150px", ""));
		} else {
			objParent.removeChild(obj);
			objParent.appendChild(createHtmlObject("input", "rel:pwd|1;id:pwd;name:password;type:text;value:"+objValue, "class:inputText;width:150px", ""));
		}
	}
}
