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;
	}
}


loaderIDSelected = 0;

function OpenCloseMenu(me) {

		if (loaderIDSelected!=me) {

			//document.getElementById('Menu02Icon' + me).src = "img_struct/arrow.Menu02.Selected.gif";
			document.getElementById('PMenu' + me).style.display = "";
			loaderIDSelected = me;
		
		} else {
			//document.getElementById('Menu02Icon' + me).src = "img_struct/arrow.Menu02.gif";
			document.getElementById('PMenu' + me).style.display = "none";
			loaderIDSelected = -1;
		
		}

}

function calendarSendAction(myLink) { 

	//alert("Check: "+myIDCheck + ": "+myLink);
	
	//Metto lo stato del CHECK in Pausa
	//document.getElementById(myIDCheck).src = "img_struct/checkQuery.gif";
	document.getElementById('calendarTitle').innerHTML="<img src=\"/system/img_struct/loaderCircle.gif\" border=\"0\" />";

    var httpCheck = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        httpCheck = new XMLHttpRequest();
        if (httpCheck.overrideMimeType) {
            httpCheck.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            httpCheck = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                httpCheck = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

	
	//Rifinisco la stringa di Link
	var myLink = myLink + "&callNumber="+Math.random();

    if (!httpCheck) {
		//Nel caso il browser non supporti l'oggetto XMLHttpRequest eseguo un semplice redirect
		return false;
	}

	//alert("Check: "+myIDCheck + ": "+myLink);
	
    httpCheck.open('GET', myLink); 
    httpCheck.onreadystatechange = function() { calendarResponse(httpCheck); };
    httpCheck.send(null);  
}

function calendarResponse(httpCheck) {  

    if (httpCheck.readyState == 4) {
    
    	if (httpCheck.status == 200) {
    	
    		//alert(httpCheck.responseText);
    	    var response = httpCheck.responseText;  
       	 	var update = new Array();  
       	 	
        	if (response == "LOGOUT") {  
  		  		window.location="actionphp/logout.php";
  		  	} else {
	        	if (response.indexOf('|' != -1)) {
	            	//Aggiorno il contenuto lista
	            	document.getElementById('calendarArea').innerHTML = response;
   		        }
    	
    		}
            
        }  
        
    }  
    
}

function getActiveText(textEl){
	if(textEl.createTextRange)
    textEl.caretPos = document.selection.createRange().duplicate();
	textE1 = (document.all) ? document.selection.createRange().text : window.getSelection();
}
	
	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);
		
	}
	
	var matricolaValida = false;
	
	function ControlForm10() {
		error = false;

		//Controllo il tipo di codice inserito
		control = ControlMatricola(document.getElementById('cmp2').value);
		
		return false;
	}
		
	function ControlForm10PostValidMatricola() {
		
		var error = false;
		
		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 e' superiore di 2 anni rispetto alla Data di acquisto");
			error = true;
		}

		if (error==true) {
			return false;
		} else {
			document.getElementById("formRequest").submit();
			return true;
		}
		
	}
	
	function ControlForm9() {

		error = false;

		//Controllo il tipo di codice inserito
		control = ControlMatricola(document.getElementById('cmp3').value,document.getElementById('cmp4').value);
		if (control=="Error") {
			error = true;
		} else {
			quotaArray = document.getElementById('cmp3').value.split("-");
			quota = quotaArray[1];
		}
		
		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('cmp2_A').selectedIndex==0)||(document.getElementById('cmp2_B').selectedIndex==0)||(document.getElementById('cmp2_C').selectedIndex==0)) {
			alert("Data sostituzione non valida!");
			error = true;
		}
		DS = document.getElementById('cmp2_C').options[document.getElementById('cmp2_C').selectedIndex].value+"/"+document.getElementById('cmp2_B').options[document.getElementById('cmp2_B').selectedIndex].value+"/"+document.getElementById('cmp2_A').options[document.getElementById('cmp2_A').selectedIndex].value;
		if (today<DS) {
			alert("Data sostituzione non valida!");
			error = true;
		}
		if ((document.getElementById('cmp5_A').selectedIndex==0)||(document.getElementById('cmp5_B').selectedIndex==0)||(document.getElementById('cmp5_C').selectedIndex==0)) {
			alert("Data installazione non valida!");
			error = true;
		}
		DI = document.getElementById('cmp5_C').options[document.getElementById('cmp5_C').selectedIndex].value+"/"+document.getElementById('cmp5_B').options[document.getElementById('cmp5_B').selectedIndex].value+"/"+document.getElementById('cmp5_A').options[document.getElementById('cmp5_A').selectedIndex].value;
		if (today<DI) {
			alert("Data installazione non valida!");
			error = true;
		}
		if ((document.getElementById('cmp6_A').selectedIndex==0)||(document.getElementById('cmp6_B').selectedIndex==0)||(document.getElementById('cmp6_C').selectedIndex==0)) {
			alert("Data prima accensione non valida!");
			error = true;
		}
		DA = document.getElementById('cmp6_C').options[document.getElementById('cmp6_C').selectedIndex].value+"/"+document.getElementById('cmp6_B').options[document.getElementById('cmp6_B').selectedIndex].value+"/"+document.getElementById('cmp6_A').options[document.getElementById('cmp6_A').selectedIndex].value;
		if (today<DA) {
			alert("Data prima accensione non valida!");
			error = true;
		}

		if (DS<DI) {
			alert("La Data di installazione deve essere più recente della Data di sostituione o acquisto");
			error = true;
		}

		//Controllo GARANZIA
		DS30 = document.getElementById('cmp2_C').options[document.getElementById('cmp2_C').selectedIndex].value*365+document.getElementById('cmp2_B').options[document.getElementById('cmp2_B').selectedIndex].value*30+document.getElementById('cmp2_A').options[document.getElementById('cmp2_A').selectedIndex].value*1;
		DI30 = document.getElementById('cmp5_C').options[document.getElementById('cmp5_C').selectedIndex].value*365+document.getElementById('cmp5_B').options[document.getElementById('cmp5_B').selectedIndex].value*30+document.getElementById('cmp5_A').options[document.getElementById('cmp5_A').selectedIndex].value*1;
		
		DDiff = DS30-DI30;
		if (DDiff>730) {
			alert("Attenzione! La garanzia risulta scaduta in quanto la Data di installazione è superiore di 2 anni rispetto alla Data di sostituzione/installazione");
			error = true;
		}
		
		if (error==true) {
			return false;
		} else {
			return true;
		}
		
	}
	
	
	
	function ControlMatricola(Matricola) {
	
		Matricola = Matricola.toUpperCase();
		retString = "Error";
		
		var httpAJAXList = false;
	
	    if (window.XMLHttpRequest) { // Mozilla, Safari,...
	        httpAJAXList = new XMLHttpRequest();
	        if (httpAJAXList.overrideMimeType) {
	            httpAJAXList.overrideMimeType('text/xml');
	        }
	    } else if (window.ActiveXObject) { // IE
	        try {
	            httpAJAXList = new ActiveXObject("Msxml2.XMLHTTP");
	        } catch (e) {
	            try {
	                httpAJAXList = new ActiveXObject("Microsoft.XMLHTTP");
	            } catch (e) {}
	        }
	    }

		//Rifinisco la stringa di Link
		//var myLink = "php/action/create.List.Messages.php";
	
	    if (!httpAJAXList) {
			//Nel caso il browser non supporti l'oggetto g eseguo un semplice redirect
			return false;
		}
	
	    httpAJAXList.open('GET', "actionphp/request.Matricola.php?matricola="+Matricola, true); 
	    httpAJAXList.onreadystatechange = function() { responseContentMatricola(httpAJAXList); };
	    httpAJAXList.send(null)
	    
		return retString;
	
	}
	

	function responseContentMatricola(httpAJAXList) {  
	
	    if (httpAJAXList.readyState == 4) {
	    
	    	if (httpAJAXList.status == 200) {
	    	    
	    	    var response = httpAJAXList.responseText;  

	        	if (response.indexOf('|' != -1)) {
		      
		       		if ((response!="Error")&&(response!="")) {
		       			matricolaValida = true;
		       			alert("Matricola Valida associata a "+response);
		       			ControlForm10PostValidMatricola();
		       		} else {
		       			alert("Matricola NON valida! La matricola potrebbe essere gia' stata inserita o esser stata digitata in un formato non valido.");
		       		}
						
	   		    }
	    	
	        }  
	        
	    }  
	    
	}
	

	function requestContent(myLink) { 
	
	    var httpAJAXList = false;
	
	    if (window.XMLHttpRequest) { // Mozilla, Safari,...
	        httpAJAXList = new XMLHttpRequest();
	        if (httpAJAXList.overrideMimeType) {
	            httpAJAXList.overrideMimeType('text/xml');
	        }
	    } else if (window.ActiveXObject) { // IE
	        try {
	            httpAJAXList = new ActiveXObject("Msxml2.XMLHTTP");
	        } catch (e) {
	            try {
	                httpAJAXList = new ActiveXObject("Microsoft.XMLHTTP");
	            } catch (e) {}
	        }
	    }
	
		
		//Rifinisco la stringa di Link
		//var myLink = "php/action/create.List.Messages.php";
	
	    if (!httpAJAXList) {
			//Nel caso il browser non supporti l'oggetto g eseguo un semplice redirect
			return false;
		}
	
	    httpAJAXList.open('GET', myLink, true); 
	    httpAJAXList.onreadystatechange = function() { responseContentMessage(httpAJAXList); };
	    httpAJAXList.send(null);  
	    
	}

	function responseContentMessage(httpAJAXList) {  
	
	    if (httpAJAXList.readyState == 4) {
	    
	    	if (httpAJAXList.status == 200) {
	    	
				//Disattivo il loader su INBOX
				//myLoader = document.getElementById('loaderMsgINBOX').src;
				//document.getElementById('loaderMsgINBOX').src = myLoader.replace("loader.gif","spacer.gif");

	    		//clearTimeout(xhrTimeout);
	    		
	    		//alert(httpAJAXList.responseText);
	    	    
	    	    var response = httpAJAXList.responseText;  

	        	if (response.indexOf('|' != -1)) {
		            //Aggiorno il contenuto lista
		            //...
		            update = response.split('|');
					modello = update[0];
					dataI = update[1];
					dataC = update[2];
					name = update[3];
					address = update[4];
					cap = update[5];
					city = update[6];
					
					if (modello!="undefined") {

						for (i=0;i<document.getElementById('cmp3').options.length;i++) {
							if (document.getElementById('cmp3').options[i].value == modello) {
								document.getElementById('cmp3').selectedIndex = i;
							}
						}
						
						setDataSelect(dataI,'cmp5');
						setDataSelect(dataC,'cmp6');
						
						document.getElementById('cmp8').value = name;
						document.getElementById('cmp9').value = address;
						document.getElementById('cmp10').value = city;
						
					}
						
	   		    }
	    	
	        }  
	        
	    }  
	    
	}
	
	function setDataSelect(data,field) {
	
		dataA = data.split('/');

		for (i=0;i<document.getElementById(field+'_A').options.length;i++) {
			if (document.getElementById(field+'_A').options[i].value == dataA[2]) {
				document.getElementById(field+'_A').selectedIndex = i;
			}
		}

		for (i=0;i<document.getElementById(field+'_B').options.length;i++) {
			if (document.getElementById(field+'_B').options[i].value == dataA[1]) {
				document.getElementById(field+'_B').selectedIndex = i;
			}
		}

		for (i=0;i<document.getElementById(field+'_C').options.length;i++) {
			if (document.getElementById(field+'_C').options[i].value == dataA[0]) {
				document.getElementById(field+'_C').selectedIndex = i;
			}
		}
	
	}
