

function LTrim(str) {
	for (var i=0; str.charAt(i)==" "; i++);
	return str.substring(i,str.length);
}
  
function RTrim(str) {
	for (var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0,i+1);
}
  
function Trim(str) {
	return LTrim(RTrim(str));
}


function myVoid() {
}
  
//*** controllo se la lugnhezza dei caratteri che digito è corretta ***
function cntrlCountKeyPress(obj, max)  {
    if ((obj.value).length + 1 > max) event.returnValue = false
}
  
//*** controllo se "sdate" è una data "dd/mm/yyyy"
function isDate(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
    if (matchArray == null) {
        alert("Inserire una data nel formato dd/mm/aaaa o dd-mm-aaaa.");
        return false;
	}

	day = matchArray[1]; // parse date into variables
	month = matchArray[3];
	year = matchArray[5];
    if (month < 1 || month > 12) { // check month range
		alert("Il mese deve essere tra 1 e 12.");
		return false;
	}

    if (day < 1 || day > 31) {
        alert("Il giorno deve essere tra 1 e 31.");
        return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert("Mese "+month+" non ha 31 giorni!")
        return false;
	}

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            alert("Febbraio " + year + " non ha " + day + " giorni!");
            return false;
		}
	}
    return true; // date is valid
}
  
function chkDigit() {
    var string="1234567890."
    var num = String.fromCharCode(event.keyCode)
    
    if (string.indexOf(num) != -1) 
    {
      return
  }
    
    event.returnValue=false;
}

//Accetta solamente i valori da 0 a 9
function chk0to9() {
	var string="0123456789"
	var num = String.fromCharCode(event.keyCode)
	if (string.indexOf(num) != -1) {
		return
	}
    event.returnValue=false;
}

function chkDataFattura() {
	var string="0123456789- :"
	var num = String.fromCharCode(event.keyCode)
	if (string.indexOf(num) != -1) {
		return
	}
    event.returnValue=false;
}

function isDigit(val) 
  {
    var string="1234567890"
    //var num = String.fromCharCode(event.keyCode)
    
    if (string.indexOf(val) != -1) 
    {
      return true
  }
    
    return false
}
 function isNumeric(val) 
   {
     var dp = false;
     
     if (val.length == 0) return false
     
     for (var i=0; i < val.length; i++) 
     {
       if (!isDigit(val.charAt(i))) 
       { 
         if (val.charAt(i) == '.') 
         {
           if (dp == true) { return false; } // already saw a decimal point
	   else { dp = true; }
	 }
	else 
	{
	  return false; 
	}
    }
  }
    return true;
}

function chkShPChar() 
  {
    var string="1234567890ABCDEFGHILMNOPQRSTUVZWXYKJabcdefghilmnopqrstuvzwxykj "
    var num = String.fromCharCode(event.keyCode)
    
    if (string.indexOf(num) != -1) 
    {
      return
  }
    
    event.returnValue=false;
}
  
  
function chkYear(value)
  {
    
    if (value.length !== 4)
    {
      alert("L'anno deve essere di quattro cifre!!!")
      return false
  }
    return true 
}

function chkMonth(value)  {    
    if (value < 1 || value > 12) {
        alert("Il mese deve essere tra 1 e 12.");
        return false;
  }
    return true 
}
  
    //*** Disabilito l'immisione di testo ***
function disableKeyPress()  {
      event.returnValue = false
      return
}
  
//setto il focus sul campo
function setFocus(objFocus){
	objFocus.focus()
	return
}  

 
//piu....
function piu(campo){
	alert(campo.value);
	campo.value=(campo.value*1)+1;
}  
//meno....
function meno(campo){
	campo.value=campo.value-1;
}     

//validazione mail
function checkEmail(strEmail,sAlerttxt)
{
	re = /^([\w\.\-\_])+@([\w*\.\-\_])+\.\w+$/;
	
	if (!re.test(strEmail)) 
		{
			alert(sAlerttxt);
			return false
		}else{
			return true
		}
}

//validazione mail
function checkEmailSimple(strEmail)
{
	re = /^([\w\.\-\_])+@([\w*\.\-\_])+\.\w+$/;
	
	if (!re.test(strEmail)) 
		{
			return false
		}else{
			return true
		}
}


var LeftPosition = (screen.width) ? (screen.width-515)/2 : 0;
var TopPosition = (screen.height) ? (screen.height-350)/2 : 0;
function popUp(url) {
	var r;
	r = window.open(url,"win1","scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,top=35,left=35, x=1, y=1,width=550,height=450");
	r.focus();
}
