function winTuttoSchermo(url,nomeWin) {
	window.open(url,nomeWin,'toolbar=no,scrollbars=yes,status=no,menubar=no,width='+(screen.availWidth-10)+',height='+(screen.availHeight-31)+',left=0,top=0')
} 

function conferma_eliminaz(dom,url) {
	if (confirm(dom)) {
		window.location=url
	}
} 
/*function conferma_eliminaz(dom,url,newwin="",w="300",h="200") {
	if (confirm(dom)) {
		if (newwin=="") {
			window.location=url
		} else	{
			window.open(url,newwin,'width='+w+'px,height='+h+'px')
		}
	}
} */

function safeNumJs(num) {
	//converte l'ultimo . o , in . e elimina tutti gli altri char non numerici
	lung=num.length
	new_num=""
	numchr=0
	for (i=lung-1;i>=0;i--) {
		if (num.charAt(i)=="," || num.charAt(i)==".") {
			if (numchr==0) {
				new_num="."+new_num			
			}
			numchr++
		} else {
			new_num=num.charAt(i)+new_num
		}
	}
	//alert(new_num)
	return new_num
}

function roundNumber(num,rlength) {
	//var rlength = 2; // The number of decimal places to round to
	var newnumber = Math.round(num*Math.pow(10,rlength))/Math.pow(10,rlength);
	return newnumber;
}

function fn(num,dec) {
	var newNum=roundNumber(num,dec)
	var pInt=Math.floor(newNum)
	var s=newNum.toString()
	var s2=pInt.toString()
	var pDec=s.replace(s2,"")
	var pDec=pDec.replace(".","")
	
	if (pDec.length<dec) {
		for (i=pDec.length; i<dec; i++)  {
			pDec=pDec+"0"
		}
	}
	return s2+"."+pDec
}

function roundEuro(num) {
	//il separatore decimale deve essere . non va messo separatore migliaia
	var v2=fn(num,3)
	var v2string=v2.toString()
	var terz=v2string.charAt(v2string.length-1)
	
	if (terz>4) {
		agg=0.01
	} else {
		agg=0
	}
	
	v2=v2string.substring(0,v2string.length-1) //toglie l'ultimo decimale
	return fn(parseFloat(v2)+agg,2);
}

function noSepMigl(num) { //elimina il separatore delle migliaia se esiste
//converte tutti i simboli non numerici (.,) in .
//se c'è più di un punto  tiene solo il primo a destra e cancella gli altri
//tronca a 2 i num dopo il punto
	
	var numFin='';
	if (num+''!='') {
		num=num+'';
		var numV=num.replace(/,/g,".");
		var arrV=numV.split(".");
		
		numV=arrV.length;
		for ( var i=0; i<numV; i++) {
			ts=arrV[i];
			if (i==numV-1 && i!=0) {
				numFin=numFin+"."
				if (ts.length>2) { //se è + lungo di 2 caratteri lo tronca
					ts=ts.substring(0,2)
				}				
			} 
			numFin=numFin+ts
		}
	}
	return numFin;
}
function isNumeric(sText) {
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;
	
   if (sText==null || sText=='' ) {
	   IsNumber=false
   } else {
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
				 if (i==0 && Char!='-') { // controlla se ha il segno negativo
			 		IsNumber = false;
			 	}
			 }
		  }
   } // end s tex=null 
   return IsNumber;
}

function not_change(ogg) {
	ogg.checked = !ogg.checked
}
function isDate(txt){
	var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
	if(re.test(txt)){
		var adata = txt.split('/');
		var gg = parseInt(adata[0],10);
		var mm = parseInt(adata[1],10);
		var aaaa = parseInt(adata[2],10);
		var xdata = new Date(aaaa,mm-1,gg)
		if((y2k(xdata.getYear())==aaaa) && (xdata.getMonth()==mm-1) && (xdata.getDate()==gg))
			return xdata
		else return false
	}else return false
}

function dateDiff(dataa,datab){
	var diffMilli = dataa.getTime()-datab.getTime()
	var divisore = 86400000
	return Math.round(diffMilli/divisore)
}

function findLike(txt,c) {
	var v
	v=txt.replace(c,"XXXXX")
	if (v==txt) {
		return false
	} else {
		return true
	}
}

function findPosX(ogg) { //x=findPosX(document.getElementById('ifrm'))
	if (!ogg.offsetParent) {
		return 0
	} else {
		//alert(ogg.tagName+" "+ogg.offsetTop)
		return ogg.offsetLeft+findPosX(ogg.offsetParent)
	}
}
function findPosY(ogg) { //y=findPosY(document.getElementById('ifrm'))
	if (!ogg.offsetParent) {
		return 0
	} else {
		return ogg.offsetTop+findPosY(ogg.offsetParent)
	}
}

function myShowModal(ind,opz)
//apre una finestra modale preservando le varibili di sessione e l'id session
{
	var args = new Object;
	args.window = window;
	showModalDialog(ind, args, opz);
}

function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}


function setCookie(NameOfCookie, value, expiredays) { 
	var ExpireDate = new Date (); 
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000)); 
	  document.cookie = NameOfCookie + "=" + escape(value) + 
	  ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); 
} 

function getCookie(NameOfCookie){ 
	if (document.cookie.length > 0) {              
	begin = document.cookie.indexOf(NameOfCookie+"=");       
	if (begin != -1) {           
	  begin += NameOfCookie.length+1;       
	  end = document.cookie.indexOf(";", begin); 
	  if (end == -1) end = document.cookie.length; 
		return unescape(document.cookie.substring(begin, end)); 
	} 
  } 
  return null; 
} 

function delCookie (NameOfCookie) {
//alert(NameOfCookie)
  if (getCookie(NameOfCookie)) { 
	document.cookie = NameOfCookie + "=" + 
	"; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
  } 
} 

function isInArray(arr,x) { //restituisce la posizione del x cercato nell'array arr, se non lo trova restitusce -1
	trovato=false
	pos=-1
	i=0
	while (trovato==false && i<arr.length) {
	//for(i=0;i<arr.length;i++) {
		//alert(arr[i]+" - "+x)
		if (arr[i]==x) {
			trovato=true
			pos=i
		}
		i++;	
	}
	return pos
}

function delFromArray(arr,val) { // rimuove l'elemnto val dall'array e restituisce la posizione in cui era
	pos=isInArray(arr,val)
	if (pos>-1) {
		arr.splice(pos,1)
	}
	return pos
}


function isMail(mail) {
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if (!espressione.test(mail)) {
		return false;
	} else  {
		return true;
	}
}

// crea l'oggetto per la comunicazione AJAX con il server   
function crea_http_req() {
	var req = false;   
	if (typeof XMLHttpRequest != "undefined")   
		req = new XMLHttpRequest();   
	if (!req && typeof ActiveXObject != "undefined") {   
		try {   
			req=new ActiveXObject("Msxml2.XMLHTTP");   
		} catch (e1) {   
			try {   
				req=new ActiveXObject("Microsoft.XMLHTTP");   
			} catch (e2) {   
				try {   
					req=new ActiveXObject("Msxml2.XMLHTTP.4.0");   
				} catch (e3) {   
					req=null;   
				}   
			}   
		}   
	}   
  
	if(!req && window.createRequest) {
		req = window.createRequest();
	}
	
	
	if (!req) alert("Il browser non supporta AJAX");   
  
	return req;   
}


