﻿// Utile per le textbox a più righe, limita l'inserimento di più caratteri di quanto è necessario
// In asp.net l'attributo maxlength non funziona
function textboxMaxNumber(control,maxLength)
{  
    try{
        if(control.value.length > (maxLength)) {
            var cont = control.value;
            control.value = cont.substring(0,(maxLength));
            return false;
        };
    }
    catch(e){
    }
}

// Quando si incolla del testo questo viene troncato alla lunghezza massima
function doBeforePaste(control,maxLength){
     if(maxLength)
     {
          event.returnValue = false;
     }
}

// Quando si incolla del testo questo viene troncato alla lunghezza massima
function doPaste(control,maxLength){
    value = control.value;
     if(maxLength){
          event.returnValue = false;
          maxLength = parseInt(maxLength);
          var oTR = control.document.selection.createRange();
          var iInsertLength = maxLength - value.length + oTR.text.length;
          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
          oTR.text = sData;
     }
}

// Permette l'inserimento di soli numeri e slash (es. date)
function isNumberSlashKey(evt)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 47 || charCode > 57))
        return false;

    return true;
}

// Permette l'inserimento di soli numeri (es. cap)
function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

// Verifica il valore, se è vuoto lo imposta a 0
function checkValue(control)
{
    if(control.value.length == 0)
    {
        control.value = 0;
    }
}

function AssegnaClasse(nome, classe)
{
    TBrowser=""
    if(document.layers) {
      	TBrowser="document.layers."+nome;
  	}
  	else {
  		TBrowser="document.getElementById('"+nome+"')";
  	}
  	
  	eval(TBrowser+'.className="'+classe+'"');
}

function Is() 
  {
    agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns = ((agent.indexOf('mozilla') != -1) &&
    (agent.indexOf('spoofer') == -1) &&
    (agent.indexOf('compatible') == -1) &&
    (agent.indexOf('opera') == -1) &&
    (agent.indexOf('webtv') == -1) &&
    (agent.indexOf('hotjava') == -1));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4 = (this.ns && (this.major == 4));
    this.ns6 = (this.ns && (this.major >= 5));
    this.ie = ((agent.indexOf("msie") != -1) &&
    (agent.indexOf("opera") == -1));
    this.ie3 = (this.ie && (this.major < 4));
    this.ie4 = (this.ie && (this.major == 4) &&
    (agent.indexOf("msie 4") != -1));
    this.ie5 = (this.ie && (this.major == 4) &&
    (agent.indexOf("msie 5.") != -1) &&
    (agent.indexOf("msie 5.5") == -1) &&
    (agent.indexOf("mac") == -1));
    this.iem5 = (this.ie && (this.major == 4) &&
    (agent.indexOf("msie 5.") != -1) &&
    (agent.indexOf("mac") != -1));
    this.ie55 = (this.ie && (this.major == 4) &&
    (agent.indexOf("msie 5.5") != -1));
    this.ie6 = (this.ie && (this.major == 4) &&
    (agent.indexOf("msie 6.") != -1));
    this.ie7 = (this.ie && (this.major == 4) &&
    (agent.indexOf("msie 7.") != -1));
    this.nsdom = (this.ns4 || this.ns6);
    this.ie5dom = (this.ie5 || this.iem5 || this.ie55);
    this.iedom = (this.ie4 || this.ie5dom || this.ie6);
    this.w3dom = (this.ns6 || this.ie6 ||this.ie7);
  }
