﻿// File JScript

    function AddOption(control,value,selected) {
        var theOption;
        //theOption=document.createElement("OPTION");
        //theOption.appendChild(document.createTextNode(value));
        //control.appendChild(theOption);
        control.options[control.options.length] = new Option(value, value);
    }


    function FuncNoJs() {
        doc = document.getElementById('wzdStep_StartNavigationTemplateContainerID_NoJsStart');
        if (doc!=null) doc.style.display='none';
        doc = document.getElementById('wzdStep_StepNavigationTemplateContainerID_NoJsStep');
        if (doc!=null) doc.style.display='none';
        doc = document.getElementById('wzdStep_FinishNavigationTemplateContainerID_NoJsFinish');
        if (doc!=null) doc.style.display='none';

    }
    
    function MostraChangeLog() {
        var doc = document.getElementById('DivChangeLog');
        frm = document.getElementById('FormPrincipale');
        if (doc == null) { 
            //frm.appendChild(document.createElement('BR'));
            var newdiv = document.createElement('div');
            var newdiv2 = document.createElement('div');
            newdiv2.id="DivChangeLog";
            newdiv2.align = "center";
            newdiv2.style.width = "800px";
            frm.appendChild(newdiv2);
            newdiv.id="DivChangeLogPrinc";
            newdiv.align = "left";
            newdiv.style.position = "relative";
            newdiv.innerHTML = ChangeLog;
            newdiv2.appendChild(newdiv);
         } else {
            frm.removeChild(doc);
         }
    }

    function ShowErrors(controls,FocusTo) {
        //passo le labels da mostrare, e la textbox a cui dare il fuoco (di solito la prima della lista...
        for (i=0;i<controls.length;i++) {
            document.getElementById(controls[i]).style.display='inline';
        }
        if (!(FocusTo == null)) {
            document.getElementById(FocusTo).focus();
            document.getElementById(FocusTo).select();
        }
    }
   
    function ResetErrors(controls) {
        for (i=0;i<controls.length;i++) {
            document.getElementById(controls[i]).style.display='none';
        }
    }
    
    function CheckInput(control,regularexp) {
        
        var reg = new RegExp(regularexp);
        if (!reg.test(control.value)) {
            return false;
        } else {
            return true;
        }
    }

    function CheckNumber(control,allownull,decimali) {
        if (control.value == '' && allownull == true) return true;
        var reg
        if (decimali == 0) {
            reg = new RegExp("^\\d+?$");
        } else {
            reg = new RegExp("^\\d+((\\" + DecimalSeparator + ")\\d{1," + decimali + "})?$");
        }
        
            
        if (!reg.test(control.value)) {
            return false;
        } else {
            return true;
        }
    }    
    
        
    function NegShowHideRadChk(RadChk,ObjectId) {
    	var object = document.getElementById(ObjectId);
        if(!RadChk.checked) {
            object.style.display = '';
        } else {
            object.style.display = 'none';
        }
    }
    
    function ShowHideRadChk(RadChk,ObjectId) {
    	var object = document.getElementById(ObjectId);
        if(RadChk.checked) {
            object.style.display = '';
        } else {
            object.style.display = 'none';
        }
    }
    
    
    function EnDisRadChk(RadChk,ObjectId) {
    	var object = document.getElementById(ObjectId);
        if(!RadChk.checked) {
            object.disabled = true;
        } else {
            object.disabled = false;
        }
    }
    
    function NegEnDisRadChk(RadChk,ObjectId) {
    	var object = document.getElementById(ObjectId);
        if(RadChk.checked) {
            object.disabled = true;
        } else {
            object.disabled = false;
        }
    }
    
    function Select(control) {
        control.select();
    }    
    
    function ConvertiInNumero(Stringa) {
        var tmp = Stringa + ''; //forzo in stringa
        tmp = tmp.replace(DecimalSeparator,".");
        if (isNaN(tmp) || !isFinite(tmp)) {
            return 0;
        } else { 
            return parseFloat(tmp);
        }
    }
    
    function ConvertiInStringa(Numero,NumeroDecimali) {
        //verifico che il numero non sia NaN e sia finito
        var tmp;
        if (isNaN(Numero) || !isFinite(Numero)) tmp = 0;
        else tmp = Numero;
        if (NumeroDecimali>0) tmp = tmp.toFixed(NumeroDecimali);
        tmp = tmp + '';
        return tmp.replace(".",DecimalSeparator) + '';
    }
    
    function Arrotonda (Numero, Decimali) {
        if (Decimali == 0) return (parseInt(Numero));
        if (isNaN(Numero) || !isFinite(Numero) || Numero == 0) return 0;
        else return Math.round(Numero * Math.pow(10,Decimali))/Math.pow(10,Decimali);
    }
    
    function log10(numero) {
        return Math.log(numero) / Math.log(10);
    }
