
/* Maschera per il blocco input */
function nn_mask(loadingImagePath) {
	var imgLoader = new Image();// preload image
	imgLoader.src = loadingImagePath;

	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
			$("#TB_overlay").click(tb_remove);
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
			$("#TB_overlay").click(tb_remove);
		}
	}

	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}

	$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
	$('#TB_load').show();//show loader
}

/* Maschera per sblocco input */
function nn_unmask() {
	//$("#TB_load").remove();
	tb_remove();
}

function featureCodeIndex(featureCode) {
	switch(featureCode) {
		case 'collo_stile': return 0;
		case 'collo_optionals': return 4;
		case 'polso': return 8;
		case 'taschino': return 12;
		case 'cifre_tipo': return 16;
		case 'cifre_posizione': return 18;
		case 'cifre_colore': return 22;
		case 'vestibilita': return 25;
		case 'manica': return 28;
		case 'impuntura': return 31;
		case 'finta': return 34;
		case 'bottone': return 40;
		case 'finiture': return 43;
		case 'cucitura_fianco': return 47;
		case 'modellistica': return 51;
		case 'finitura_contrasto': return 55;
		case 'asola_colore': return 61;
		case 'bottone_colore': return 64;
		case 'non_usato': return 67;

		default: return -1;
	}
}

function replaceCodeValue(actualCodeModel, featureCode, valueCode) {
	var index = featureCodeIndex(featureCode);
	var lastIndex = index + valueCode.length;

	var returnString = '';

	/* inizio */
	if (index == 0) {
		returnString = valueCode + actualCodeModel.substring(lastIndex);
	}
	/* fine */
	else if (lastIndex == actualCodeModel.length) {
		returnString = actualCodeModel.substring(0, index) + valueCode;
	}
	/* al centro */
	else {
		returnString = actualCodeModel.substring(0, index) + valueCode + actualCodeModel.substring(lastIndex);
	}

	return returnString;

}
