String.prototype.LPad=function(n,s) {
  if(n<0) return;
  if(typeof s=='undefined') s=' ';
  var res=this;
  while(res.length<n) res=s+res;
  return res;
}
Number.prototype.toCurrency=function(n) {
    if(!n) n=0;
    var i=parseInt(this);
    var d=(''+Math.round((this-i)*Math.pow(10,n))).LPad(2,'0');
    return i+','+d;
  }


CreateHTTP =function (){
	
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			return  new XMLHttpRequest();
        } catch(e) {
			return  false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	return  new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		return  new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		return  false;
        	}
		}
    }
	return false

  
}


function loadXMLDoc(Nome,param,Place,fine,msod,fafter) {
if(Place != null){ Place.innerHTML="<br><b>Wait...<br><br>"}

	if(fine == null)fine = '<!--fine-->';
	if(msod == null)msod = true;

	try{
			
 	  Nome.onreadystatechange=function() {
		if(msod){
			 
		  if (Nome.readyState==4) {
   		// alert(Nome.responseXML)
			Risposta = Nome.responseText
	     	Risposta.substr(0,Risposta.indexOf(fine));
			if(Place != null){
		
		   if(Place.value != undefined){
				
				Place.value=Risposta; 
				}else{
			 Place.innerHTML=Risposta;		
				
				}
    
	    if(fafter == 1)	{
		Pa1 = Risposta.indexOf('<!--DataRif');
		Pa1 = Pa1 + 11;
		Vara = Risposta.substr(Pa1,8); 
		selectDate(document.getElementById(Vara))
		}
		else if(fafter == 2){
		
			Old=document.getElementById('dataListPrezzi').value
	Old=Old.replace('/','');Old=Old.replace('/','');
	P = Old
	PREZZO=document.getElementById(P).getAttribute('prezzo');
	document.getElementById('CostoTotale').innerHTML = PREZZO*document.getElementById('squantita').value
    Tprez = document.getElementById('CostoTotale').innerHTML
	Tprez=parseFloat(Tprez)
	resa = Number(Tprez);
	document.getElementById('CostoTotale').innerHTML=resa.toCurrency(2);
	document.getElementById('quantita').value=document.getElementById('squantita').value;

		}
			}}
		  else if(Place != null){{ Place.innerHTML="<br><b>Wait...<br><br>"}
	
		  }
		}
	
	}
		if(param != undefined ){
			
			Nome.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			Nome.send(param);
		}
		else{
		Nome.send("");
		
		}
		if(!msod){
			
			Risposta = Nome.responseText
		 Place.innerHTML=Risposta.substr(0,Risposta.indexOf(fine));	
		}

	}
	catch (e){
		
	return false}
}





