var formSubmitted='0';

function fnBodyKeyDown(){
    if (event.keyCode>=112 && event.keyCode<=123) {
        if (event.shiftKey) {
            var fnum = event.keyCode - 111;
            var fn = 'SHIFTFUN' + fnum;
            var oButton=document.getElementById(fn);
            if (oButton != null) {
                oButton.click();
                event.returnValue=false;
                event.cancelBubble=true;
            }
        }
        else if (event.altKey) {
            var fnum = event.keyCode - 111;
            var fn = 'ALTFUN' + fnum;
            var oButton=document.getElementById(fn);
            if (oButton != null) {
                oButton.click();
                event.returnValue=false;
                event.cancelBubble=true;
            }
        }
        else if (event.ctrlKey) {
            var fnum = event.keyCode - 111;
            var fn = 'CTRLFUN' + fnum;
            var oButton=document.getElementById(fn);
            if (oButton != null) {
                oButton.click();
                event.returnValue=false;
                event.cancelBubble=true;
            }
        }
        else {
            var fnum = event.keyCode - 111;
            if (fnum == '9') {
                var butName = document.activeElement.name + 'F9';
                var oBut=document.getElementById(butName);
                if (oBut != null) {
                    oBut.click();
                    event.returnValue=false;
                    event.cancelBubble=true;
                }
            }
            else {
                var fn = 'FUN' + fnum;
                var oButton=document.getElementById(fn);
                if (oButton != null) {
                    oButton.click();
                    event.returnValue=false;
                    event.cancelBubble=true;
                }
            }
        }
    }
}

function condSubmit(formName, target, typReq, action) {
    if (formSubmitted == '0') {
        var oBody = document.body;
        oBody.style.cursor='wait';
        formSubmitted = '1';
        formSubmit(formName, target, typReq, action);
    }

}

function formSubmit(formName, target, typReq, action) {
 //showdiv('message');
 var oBody = document.body;
        oBody.style.cursor='wait';
 if (typReq != null) {
            var oTypReq=document.getElementById('typReq');
            if (oTypReq != null) {
                oTypReq.value=typReq;
            }
        }
        if (action != null) {
            var oAction=document.getElementById('action');
            if (oAction != null) {
                oAction.value=action;
            }
        }
        var oBarPosY=document.getElementById('barPosY');
        if (oBarPosY != null) {
            var oFloatDiv=document.getElementById('floatDiv');
            if (oFloatDiv != null) {
                oBarPosY.value=oFloatDiv.scrollTop;
            }
            else {
                oBarPosY.value=0;
            }
        }
        var oBarPosY1=document.getElementById('barPosY1');
        if (oBarPosY1 != null) {
            var oFloatDiv1=document.getElementById('floatDiv1');
            if (oFloatDiv1 != null) {
                oBarPosY1.value=oFloatDiv1.scrollTop;
            }
            else {
                oBarPosY1.value=0;
            }
        }
        var oFormId=document.getElementById(formName);
        if (oFormId != null) {
            var oTarget=oFormId.target;
            if (target != null) {
                oFormId.target=target;
            }
            oFormId.submit();
            oFormId.target=oTarget;
        }
}

function closeWindow(typReq) {
    closeWindow(typReq, null);
}

function closeWindow(typReq, action) {
	
        if (typReq != null) {
            var oTypReq=document.getElementById('typReq');
            if (oTypReq != null) {
                oTypReq.value=typReq;
            }
        }
        if (action != null) {
            var oAction=document.getElementById('action');
            if (oAction != null) {
                oAction.value=action;
            }
        }
        window.close();
}

function sendRequest(typReq) {
    condSubmit("MainForm", null, typReq, null);
}

function sendRequest(typReq, action) {
    condSubmit("MainForm", null, typReq, action);
}

function exitGest() {
    parent.refreshing = true;
    condSubmit("MainForm", '_parent', 'exitGest', null);
}

function selectField(nameId) {
   var oField=document.getElementById(nameId);
   if (oField!=null){
        oField.focus();
   }
}

function errorsLoad(errorTxt) {
   window.alert(errorTxt);
}

function startAllErrorsView() {
   window.open('ErrorsS', 'ErrorPage', 'height=440, width=630, status=no, toolbar=no, resizable=yes, top=85, left=85');
}

function startWarningView() {
   window.open('WarningsS', 'WarningPage', 'height=440, width=630, status=no, toolbar=no, resizable=yes, top=85, left=85');
}

function startPrint(servlet) {
    window.open(servlet, 'print', 'height=600, width=900, toolbar=no, resizable=yes,top=150,left=20');
}

function startATS() {
  return  window.open("StreamATS", 'ATS', 'height=600, width=900, toolbar=no, resizable=yes,top=150,left=20');
}

function startPick(field) {
    window.open('about:blank', 'pickList', 'height=600, width=800, toolbar=no, resizable=yes,top=110,left=30');
    condSubmit('MainForm', 'pickList', 'getPick', field);
}

function doSaveDoc(outtext) {
    if (confirm(outtext)) {
        sendRequest('doSaveDoc');
    }
}

function doHasWarning(outtext) {
    if (confirm(outtext)) {
        sendRequest('doHasWarning');
    }
}

function startPicker(field) {
    window.open('about:blank', 'pickList', 'height=600, width=800, toolbar=no, resizable=yes,top=110,left=30');
    condSubmit('MainForm', 'pickList', 'getPickStandard', field);
}



function startNewWindow(param) {
    window.open('about:blank', 'NewWin', 'height=600, width=800, toolbar=no, resizable=yes,top=110,left=30');
    condSubmit('MainForm', 'NewWin' , param, null);
}

function startPickTab(field) {
    window.open('about:blank', 'pickList', 'height=600, width=800, toolbar=no, resizable=yes,top=110,left=30');
    condSubmit('MainForm', 'pickList', 'getPickTab', field);
}

function startPrint() {
	sendRequest('printList');
  note= window.open('PreviewS', 'PreviewS', 'height=550, width=630, status=no, toolbar=no,scrollbar=yes, resizable=yes, top=85, left=85');
	return note;
}
function startPrintPDF() {
  //sendRequest('printList');

  window.open('PDFPreviewS', 'PDFPreviewS', 'height=550, width=630, status=no, toolbar=no,scrollbar=yes, resizable=yes, top=85, left=85');
}
function hide(which){
document.getElementById(which).style.visibility="hidden";
}

function controlloNumeriDecimali(campo){
counter = 0;
  if (campo.value.length > 0){
   valore = campo.value.replace(".",",");
   check=true;
   decimali=false;
   errori=false;

   	for (i=0;i<valore.length;i++){

         if (valore.charCodeAt(i)>47 && valore.charCodeAt(i)<58 && counter<2){
   			check=false;
   			if(decimali){
   				++counter;
   			}
			}

	else if (valore.charAt(i)==","){
   			if(!decimali){
			check=false;
			decimali=true;
			}else{
			errori=true;
			}
			}
	else{
			check=true;
         }
		 }



   if (check || errori){
     alert("Sintassi non corretta.\nIl valore deve avere la seguente forma\n##,##");
	 campo.value="";
     }else{

     if (!check && !decimali)
         	campo.value = valore + ",00";
         else if (!check && counter == 0)
         	campo.value = valore + "00";
         else if (!check && counter == 1)
         	campo.value = valore + "0";
         else
         	campo.value=valore;

     }

  }
   }
function controlloNumeri(campo){
 if (campo.value.length > 0){
   check=true;

   	for (i=0;i<campo.value.length;i++){

         if (campo.value.charCodeAt(i)>47 && campo.value.charCodeAt(i)<58){
   			check=false;
			}
	else{
			check=true;
         }
		 }

   if (check){
     alert("Sintassi non corretta.\nIl valore deve avere la seguente forma\n##");
	 campo.value="";
     }

   }
}

function controlloNumeriPerc(campo){
 if (campo.value.length > 0){
  valore = campo.value.replace(".",",");
   check=true;
   decimali=false;
   errori=false;

   if (valore.length > 5){
   errori = true;
   }else{
		for (i=0;i<2;i++){
			if (valore.charCodeAt(i)>47 && valore.charCodeAt(i)<58){
			check=false;
			}else{
			check=true;
			}// fine if
		}// fine for

		if (valore.charAt(3) == ","){
		decimali=true;
		} //fine if
		for (i=4;i<valore.length;i++){
			if (valore.charCodeAt(i)>47 && valore.charCodeAt(i)<58){
			check=false;
			}else{
			check=true;
			}
		}//fine for


		}// fine if else



         if (!check && !decimali){
		 if (valore.length == 2)
         	campo.value = valore + ",00";
			if (valore.length == 3)
         	campo.value = valore + "00";
			if (valore.length == 4)
         	campo.value = valore + "0";
			}


   if (check || errori){
     alert("Sintassi non corretta.\nIl valore deve avere ##,##");
	 campo.value="";
     }
 }
   }


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function resizeApp(){

var oBarPosY=document.getElementById('barPosY');
        if (oBarPosY != null) {
            var oFloatDiv=document.getElementById('floatDiv');
            if (oFloatDiv != null) {
                oBarPosY.value=oFloatDiv.scrollTop;
            }
            else {
                oBarPosY.value=0;
            }
        }
        var oBarPosY1=document.getElementById('barPosY1');
        if (oBarPosY1 != null) {
            var oFloatDiv1=document.getElementById('floatDiv1');
            if (oFloatDiv1 != null) {
                oBarPosY1.value=oFloatDiv1.scrollTop;
            }
            else {
                oBarPosY1.value=0;
            }
        }

}



function showdiv(divname) {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(divname).style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.hideshow.visibility = 'visible';
}
else { // IE 4
document.all.hideshow.style.visibility = 'visible';
}
}
}

function hidediv(divname) {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(divname).style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hideshow.visibility = 'hidden';
}
else { // IE 4
document.all.hideshow.style.visibility = 'hidden';
}
}
}


