function tmt_confirm(msg){
	document.MM_returnValue=(confirm(unescape(msg)));
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_openBrWindowCentered(theURL,winName,features,width,height) { //v2.0

	var doPopUpX = (screen.width/2)-(width/2);
	//var doPopUpY = (screen.height/2)-(height/2);
	var doPopUpY = 30
	var pos = ",left="+doPopUpX+",top="+doPopUpY;		
	
	window.open(theURL,winName,features+pos);
}

//seleziona una "option" da menù "select" (passare id menù e value della option da selezionare)
function selectOption(id,value) {
	var selObj = document.getElementById(id);
	
	for(var i=0;i<selObj.length;i++) {
		if(selObj[i].value==value) {
			selObj.selectedIndex = i;
		}
	}
	
	
}


//MaxLength per textarea
function imposeMaxLength(Object, MaxLen) {
  return (Object.value.length <= MaxLen);
}

function checkNumeric(value){
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(value))
		return true;
	return false;
}

function checkInputNumeric(inputfield){

	numero = inputfield.value+'';
	numero = numero.replace('.','');
	numero = numero.replace(',','.');
	
	if (checkNumeric(numero)==false && numero!='') {
		alert("Solo valori numerici sono ammessi in questo campo");
		inputfield.value = 0;
		inputfield.focus();
		inputfield.select();		
	} else if (numero=='') {
		inputfield.value = 0;
	}
}

function checkInputDate(datafield){
	
	//lunghezza max 10 (tronca stringa se superiore)
	datafield.value = Left(datafield.value, 10)
	
	if (IsDate(datafield.value)==false && datafield.value!='') {
		alert("Data non valida. Inserire le date in formato gg/mm/aaaa.");
		datafield.value = '';
		datafield.focus();
		datafield.select();		
	}
}

function checkInputEmail(inputfield){
	
	if (isEmail(inputfield.value)==false && inputfield.value!='') {
		alert("Email non valida.");
		inputfield.value = '';
		inputfield.focus();
		inputfield.select();		
	}
}

//Inserisce separatore migliaia
function SeparatoreMigliaia(numero){
   numero=numero.toString();
   dp=numero.indexOf(",")!=-1?numero.substring(0,numero.indexOf(",")).length:numero.length;
   for (i=dp-3;i>0;i-=3)
      numero=numero.substring(0,i)+"."+numero.substr(i);
   numero=numero.replace(/-,/,"-");
   return numero
}
  

//Converte valore per elaborazione js (es. da FormatNumber ASP)
function NumeroJS(numero){
	numero = numero+'';
	numero = numero.replace('.','');
	numero = numero.replace(',','.');
		
	if (checkNumeric(numero)) {
		numero = parseFloat(numero);
	} else {
		numero = 0;
	}
	return numero
}

//Converte valore da js a FormatNumber ASP
function NumeroASP(numero){
	numero = numero.toFixed(2);
	numero = numero+'';
	numero = numero.replace('.',','); //sostituisce il punto (dec javascript) con la virgola (dec asp)
	numero = SeparatoreMigliaia(numero); //inserisce separatore migliaia
	return numero
}

function Left(str, n) {
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function Right(str, n) {
	if (n <= 0)
	  	return "";
	else if (n > String(str).length)
	  	return str;
	else  {
	  	var iLen = String(str).length;
	 	 return String(str).substring(iLen, iLen - n);
	}
}

function Mid(String, Start, Length) {
    if (String == null)
        return (false);
    
    if (Start > String.length)
        return '';
    
    if (Length == null || Length.length == 0)
        return (false);
    
    return String.substr((Start - 1), Length);
}


function InStr(String1, String2) {
    var a = 0;
    
    if (String1 == null || String2 == null)
        return (false);
    
    String1 = String1.toLowerCase();
    String2 = String2.toLowerCase();
    
    a = String1.indexOf(String2);
    if (a == -1)
        return 0;
    else
        return a + 1;
}

function Len(string) {
    if (string == null)
        return (false);
    
    return String(string).length;
}



