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_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_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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function page_Over(idImage,message) {	
	if (document.getElementById(idImage)) {
		myImage = document.getElementById(idImage).src;
		document.getElementById(idImage).src = myImage.replace('.gif','Over.gif');
		document.getElementById('pageMessage').innerHTML = message;
	}
}

function page_Out(idImage,message) {
	if (document.getElementById(idImage)) {
		myImage = document.getElementById(idImage).src;
		document.getElementById(idImage).src = myImage.replace('Over.gif','.gif');
		document.getElementById('pageMessage').innerHTML = message;
	}
}

	var TabSelected=0;
	var TabLimit=20;

	function OpenCloseTab(me){

		TabSelected=me;
		for (i=0;i<=20;i++) {

			if (i!=me) {
				if (document.getElementById('Tab' + i)) {
					document.getElementById('Tab' + i).style.visibility="hidden";
					document.getElementById('Tab' + i).style.display="none";
					document.getElementById('Tab' + i).style.height="0px";			
					document.getElementById('TabCapSX' + i).src="template/img_struct/tabPartSX.gif";
					document.getElementById('TabCapDX' + i).src="template/img_struct/tabPartDX.gif";
					document.getElementById('TabCapBg' + i).style.backgroundImage="url(template/img_struct/tabBgr.gif)";
					document.getElementById('TabCapBg' + i).style.fontWeight="normal";
					document.getElementById('TabCapBg' + i).style.fontColor="#333333";
				}
			} else {
				if (document.getElementById('Tab' + i)) {
					document.getElementById('Tab' + me).style.visibility="visible";
					document.getElementById('Tab' + me).style.display="";
					document.getElementById('Tab' + me).style.height="auto";
					document.getElementById('TabCapSX' + i).src="template/img_struct/tabPartSXOver.gif";
					document.getElementById('TabCapDX' + i).src="template/img_struct/tabPartDXOver.gif";
					document.getElementById('TabCapBg' + i).style.backgroundImage="url(template/img_struct/tabBgrOver.gif)";
					document.getElementById('TabCapBg' + i).style.fontWeight="bold";
					document.getElementById('TabCapBg' + i).style.fontColor="#000000";
				}
			}
		}
	}

	function OpenCloseTabForm(me){

		TabSelected=me;
		i=me;
		
		if (document.getElementById('Tab' + i)) {
					
					if (document.getElementById('Tab' + i).style.visibility=="hidden") {
						document.getElementById('Tab' + i).style.visibility="visible";
						document.getElementById('Tab' + i).style.display="";
						document.getElementById('Tab' + i).style.height="auto";
					} else {
						document.getElementById('Tab' + i).style.visibility="hidden";
						document.getElementById('Tab' + i).style.display="none";
						document.getElementById('Tab' + i).style.height="0px";			
					}
					
		}
			
	
	}
	
	function OnTab(i) {
		if (i!=TabSelected) {
			if (document.getElementById('Tab' + i)!='undefined' ) {
				document.getElementById('TabCapSX' + i).src="template/img_struct/tabPartSXOn.gif";
				document.getElementById('TabCapDX' + i).src="template/img_struct/tabPartDXOn.gif";
				document.getElementById('TabCapBg' + i).style.backgroundImage="url(template/img_struct/tabBgrOn.gif)";		
			}
		}
	}
	
	function OffTab(i) {
		if (i!=TabSelected) {
			if (document.getElementById('Tab' + i)!='undefined' ) {
				document.getElementById('TabCapSX' + i).src="template/img_struct/tabPartSX.gif";
				document.getElementById('TabCapDX' + i).src="template/img_struct/tabPartDX.gif";
				document.getElementById('TabCapBg' + i).style.backgroundImage="url(template/img_struct/tabBgr.gif)";		
			}
		}
	}
	
	function SelectItem(idSelect) {
	
		index = document.getElementById('cmp'+idSelect+'_selector').selectedIndex;
	
		valueSelected = document.getElementById('cmp'+idSelect+'_selector').options[index].value;
		
		if (valueSelected!="---") {
		
			document.getElementById('cmp'+idSelect+'_show').options[document.getElementById('cmp'+idSelect+'_show').options.length] = new Option(valueSelected,valueSelected,false,false);
	
		}
		
		ReinitItem(idSelect);
	
		//alert(valueSelected);
	
	}
	
	function DeleteItem(idSelect) {
	
		index = document.getElementById('cmp'+idSelect+'_show').selectedIndex;
		totElement = document.getElementById('cmp'+idSelect+'_show').options.length;
		
		//alert('Index: '+index+' > Tot: '+totElement);
		/*
		for (var i=index; i<totElement-2; i++ ) {
			document.getElementById('cmp'+idSelect+'_show').options[i].value = document.getElementById('cmp'+idSelect+'_show').options[i+1].value;
		}
		*/

		document.getElementById('cmp'+idSelect+'_show').options[index] =  null;
		//document.getElementById('cmp'+idSelect+'_show').options.length = totElement-1;

		//valueSelected = document.getElementById('cmp'+idSelect+'_selector').options[index].value;
		
		//document.getElementById('cmp'+idSelect+'_show').options[document.getElementById('cmp'+idSelect+'_show').options.length] = new Option(valueSelected,valueSelected,false,false);
	
		ReinitItem(idSelect);
		
		//alert(valueSelected);
	
	}
	
	function ReinitItem(idSelect) {
		
		totElement = document.getElementById('cmp'+idSelect+'_show').options.length;
		//alert(totElement);
		document.getElementById('cmp'+idSelect).value="";
		for (var i=0; i<totElement; i++ ) {
			document.getElementById('cmp'+idSelect).value = document.getElementById('cmp'+idSelect).value+document.getElementById('cmp'+idSelect+'_show').options[i].value+'\n';
		}
		
		//alert(document.getElementById('cmp'+idSelect).value);
		
	}
	
	function ControlForm10() {

		error = false;

		//Controllo il tipo di codice inserito
		control = ControlMatricola(document.getElementById('cmp1').value,document.getElementById('cmp2').value);
		if (control=="Error") {
			error = true;
		} else {
			quotaArray = document.getElementById('cmp1').value.split("-");
			quota = quotaArray[1];
			alert("La tua quota di accensione č di "+quota+" Euro");
		}
		
		CAP = document.getElementById('cmp7').value*1;
		if ((document.getElementById('cmp7').value.length<5)||(CAP!=document.getElementById('cmp7').value)) {
			alert("Formato CAP non valido");
			error = true;
		}
		
		var data = new Date()
		//dd = data.getDate()+"";
		//mm = data.getMonth()+"";
		//yy = data.getFullYear();
		dd = dateD;
		mm = dateM;
		yy = dateY;
		/*
		if (dd<10) {
			dd = "0"+dd;
		}
		if (mm<10) {
			mm = "0"+mm;
		}
		*/
		today = yy+"/"+mm+"/"+dd;
		//alert(today);		
		
		if ((document.getElementById('cmp3_A').selectedIndex==0)||(document.getElementById('cmp3_B').selectedIndex==0)||(document.getElementById('cmp3_C').selectedIndex==0)) {
			alert("Data collaudo non valida!");
			error = true;
		}
		DC = document.getElementById('cmp3_C').options[document.getElementById('cmp3_C').selectedIndex].value+"/"+document.getElementById('cmp3_B').options[document.getElementById('cmp3_B').selectedIndex].value+"/"+document.getElementById('cmp3_A').options[document.getElementById('cmp3_A').selectedIndex].value;
		if (today<DC) {
			alert("Data collaudo non valida!");
			error = true;
		}
		if ((document.getElementById('cmp10_A').selectedIndex==0)||(document.getElementById('cmp10_B').selectedIndex==0)||(document.getElementById('cmp10_C').selectedIndex==0)) {
			alert("Data acquisto non valida!");
			error = true;
		}
		DA = document.getElementById('cmp10_C').options[document.getElementById('cmp10_C').selectedIndex].value+"/"+document.getElementById('cmp10_B').options[document.getElementById('cmp10_B').selectedIndex].value+"/"+document.getElementById('cmp10_A').options[document.getElementById('cmp10_A').selectedIndex].value;
		if (today<DA) {
			alert("Data acquisto non valida!");
			error = true;
		}
		if ((document.getElementById('cmp16_A').selectedIndex==0)||(document.getElementById('cmp16_B').selectedIndex==0)||(document.getElementById('cmp16_C').selectedIndex==0)) {
			alert("Data installazione non valida!");
			error = true;
		}
		DI = document.getElementById('cmp16_C').options[document.getElementById('cmp16_C').selectedIndex].value+"/"+document.getElementById('cmp16_B').options[document.getElementById('cmp16_B').selectedIndex].value+"/"+document.getElementById('cmp16_A').options[document.getElementById('cmp16_A').selectedIndex].value;
		if (today<DI) {
			alert("Data installazione non valida!");
			error = true;
		}

		if (DI<DA) {
			alert("La Data di installazione deve essere pių recente della Data di acquisto");
			error = true;
		}

		if (DC<DI) {
			alert("La Data di collaudo deve essere pių recente della Data di installazione");
			error = true;
		}

		//Controllo GARANZIA
		DC30 = document.getElementById('cmp3_C').options[document.getElementById('cmp3_C').selectedIndex].value*365+document.getElementById('cmp3_B').options[document.getElementById('cmp3_B').selectedIndex].value*30+document.getElementById('cmp3_A').options[document.getElementById('cmp3_A').selectedIndex].value*1;
		DA30 = document.getElementById('cmp10_C').options[document.getElementById('cmp10_C').selectedIndex].value*365+document.getElementById('cmp10_B').options[document.getElementById('cmp10_B').selectedIndex].value*30+document.getElementById('cmp10_A').options[document.getElementById('cmp10_A').selectedIndex].value*1;
		
		DDiff = DC30-DA30;
		if (DDiff>730) {
			alert("Attenzione! La garanzia risulta scaduta in quanto la Data di collaudo č superiore di 2 anni rispetto alla Data di acquisto");
			error = true;
		}

		if (error==true) {
			return false;
		} else {
			return true;
		}
		
	}
	
	function ControlMatricola(Modello,Matricola) {
	
		Matricola = Matricola.toUpperCase();
		retString = "Error";
		
		if (Modello.substr(0,3)=="her") {			
			var pattern = /[0-9]{5}\/[0-9]{2}.[0-9]{2}/
			var result = Matricola.search(pattern);
			if ((result==-1)||(Matricola.length!=11)) {
				alert("Matricola non valida! [01234/01.01]");
			} else {
				//alert("Matricola valida! [01234/01.01]");
				retString = "HER";
			}

		}
		
		if (Modello.substr(0,3)=="bsg") {
			var pattern = /N[0-9]{9}/
			var result = Matricola.search(pattern);
			if ((result==-1)||(Matricola.length!=10)) {
				alert("Matricola non valida! [N012345678]");
			} else {
				//alert("Matricola valida! [N012345678]");
				retString = "BSG";
			}
		}
		
		if (Modello.substr(0,3)=="bal") {
			var pattern = /[0-9]{7}/
			var result = Matricola.search(pattern);
			if ((result==-1)||(Matricola.length!=7)) {
				alert("Matricola non valida! [0123456]");
			} else {
				//alert("Matricola valida! [0123456]");
				retString = "BAL";
			}
		}
		
		if (Modello.substr(0,4)=="bong") {
			var pattern = /[0-9a-zA-Z]{9}/
			var result = Matricola.search(pattern);
			if ((result==-1)||(Matricola.length!=9)) {
				alert("Matricola non valida! [01AB23489F]");
			} else {
				//alert("Matricola valida! [01AB23489F]");
				retString = "BONG";
			}
		}
		
		if (Modello.substr(0,5)=="vaill") {
			var pattern = /[0-9]{26}N[0-9]{1}/
			var result = Matricola.search(pattern);
			if ((result==-1)||(Matricola.length!=28)) {
				alert("Matricola non valida! [01234567890123456789012345N7]");
			} else {
				//alert("Matricola valida! [01234567890123456789012345N7]");
				retString = "VAILL";
			}
		}
		
		if (Modello.substr(0,3)=="ham") {
			var pattern = /M[0-9]{2}X[0-9]{3}IT-[0-9]{4}A/
			var result = Matricola.search(pattern);
			if ((result==-1)||(Matricola.length!=15)) {
				alert("Matricola non valida! [M01L012IT-0123A]");
			} else {
				//alert("Matricola valida! [M01L012IT-0123A]");
				retString = "HAM";
			}
		}
		
		return retString;
	
	}