var ns  = (document.layers)? true:false; 
var ie4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true:false;
var ie5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true:false;
var ie6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true:false;
var ie7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true:false;
var ie = ie4 || ie5 || ie6 || ie7;
var dom = (document.getElementById) ? true:false;
var splashWin = null;








var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var spc =",._@$%()[]{};<>/ !-:'?*";



function GetDay(nDay){
var Days  =new Array("sunday","monday","tuesday","wendesday","thursday","friday","saturday");
return Days[nDay]
}

function GetMonth(nMonth){
var Months = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
return Months[nMonth]
}

function DateString(){
var Today = new Date();
var strDate = GetDay(Today.getDay()) + " " + Today.getDate();
strDate += " " + GetMonth(Today.getMonth()) + ", " + Today.getFullYear()+" ";
return strDate;
}


function initializare(){
   document.formular.BENEFICIAR.value = "";
   document.formular.OBIECTIV.value = "";
   document.formular.LUNGIME.value = "";               //input
   document.formular.LATIME.value = "";                //input
   document.formular.INALTIME.value = "";              //input
   document.formular.SPARDOSELE.value = "";
   document.formular.VOLUM.value = "";
   document.formular.TR.value = "";                    //input
   document.formular.TA.value = "";
   document.formular.TS.value = "";                    //input
   document.formular.TE.value = "";                    //input
   document.formular.TRTE.value = "";
   document.formular.TATE.value = "";
   document.formular.TA1TA2.value = "";                 //input
   document.formular.TP.value = 0;
   document.formular.TXXX.value = 0;
   document.formular.N.value = "";                      //input
   document.formular.SI_PARDOSEALA.value = "";
   document.formular.UNGHI.value = "";                  //input
   document.formular.SI_ACOPERIS.value = "";
   document.formular.SI_PERETE_EXTERIOR.value = "";
   document.formular.SI_PERETE_INTERIOR.value = "";     //input
   document.formular.SI_FEREASTRA.value = "";           //input
   document.formular.SI_LUMINATOR.value = "";           //input
   document.formular.SI_USA_EXTERIOARA.value = "";      //input
   document.formular.SI_XXX.value = "";                 //input
   document.formular.SI_XXXX.value = "";                //input
   document.formular.SI_XXXXX.value = "";               //input

   document.formular.CT_PARDOSEALA.value = "";          //input
   document.formular.CT_ACOPERIS.value = "";            //input
   document.formular.CT_PERETE_EXTERIOR.value = "";     //input
   document.formular.CT_PERETE_INTERIOR.value = "";     //input
   document.formular.CT_FEREASTRA.value = "";           //input
   document.formular.CT_LUMINATOR.value = "";           //input
   document.formular.CT_USA_EXTERIOARA.value = "";      //input
   document.formular.CT_XXX.value = "";                 //input
   document.formular.CT_XXXX.value = "";                //input
   document.formular.CT_XXXXX.value = "";               //input


   document.formular.CL_PARDOSEALA_1.value = "";   
   document.formular.CL_PARDOSEALA_2.value = "";      
   document.formular.CL_PARDOSEALA_3.value = "";
   document.formular.CL_PARDOSEALA_FINAL.value = "";

   document.formular.CL_ACOPERIS_1.value = "";   
   document.formular.CL_ACOPERIS_2.value = "";      
   document.formular.CL_ACOPERIS_3.value = "";
   document.formular.CL_ACOPERIS_FINAL.value = "";


   document.formular.CL_PERETE_EXTERIOR_1.value = "";   
   document.formular.CL_PERETE_EXTERIOR_2.value = "";      
   document.formular.CL_PERETE_EXTERIOR_3.value = "";
   document.formular.CL_PERETE_EXTERIOR_FINAL.value = "";

   document.formular.CL_PERETE_INTERIOR_1.value = "";   
   document.formular.CL_PERETE_INTERIOR_2.value = "";      
   document.formular.CL_PERETE_INTERIOR_3.value = "";
   document.formular.CL_PERETE_INTERIOR_FINAL.value = "";


   document.formular.CL_FERESTRE_1.value = "";   
   document.formular.CL_FERESTRE_2.value = "";      
   document.formular.CL_FERESTRE_3.value = "";
   document.formular.CL_FERESTRE_FINAL.value = "";


   document.formular.CL_LUMINATOR_1.value = "";   
   document.formular.CL_LUMINATOR_2.value = "";      
   document.formular.CL_LUMINATOR_3.value = "";
   document.formular.CL_LUMINATOR_FINAL.value = "";


   document.formular.CL_USA_EXTERNA1_1.value = "";   
   document.formular.CL_USA_EXTERNA1_2.value = "";      
   document.formular.CL_USA_EXTERNA1_3.value = "";
   document.formular.CL_USA_EXTERNA_FINAL1.value = "";

   document.formular.CL_USA_EXTERNA2_1.value = "";   
   document.formular.CL_USA_EXTERNA2_2.value = "";      
   document.formular.CL_USA_EXTERNA2_3.value = "";
   document.formular.CL_USA_EXTERNA_FINAL2.value = "";


   document.formular.CL_USA_EXTERNA3_1.value = "";   
   document.formular.CL_USA_EXTERNA3_2.value = "";      
   document.formular.CL_USA_EXTERNA3_3.value = "";
   document.formular.CL_USA_EXTERNA_FINAL3.value = "";


   document.formular.CL_USA_EXTERNA4_1.value = "";   
   document.formular.CL_USA_EXTERNA4_2.value = "";      
   document.formular.CL_USA_EXTERNA4_3.value = "";
   document.formular.CL_USA_EXTERNA_FINAL4.value = "";

   document.formular.TOTAL_QT.value = "";   
   document.formular.TOTAL1.value = "";   
   //document.formular.TOTAL2.value = "";
   //document.formular.TOTAL3.value = 0.36;
   document.formular.TOTAL2.value = 0.36;
   document.formular.TOTAL3.value = "";

   document.formular.TOTAL4.value = "";

   document.formular.TOTAL_FINAL_1.value = "";
   document.formular.TOTAL_FINAL_2.value = "";

   document.formular.RANDAMENT.value = "";
   document.formular.FINAL_X.value = "";
   document.formular.FINAL_Y.value = "";

   initformular();

}






function initformular(){
   document.formular.CT_PARDOSEALA.value="";
   document.formular.CT_ACOPERIS.value="";
   document.formular.CT_PERETE_EXTERIOR.value="";
   document.formular.CT_PERETE_INTERIOR.value="";
   document.formular.CT_FEREASTRA.value="";
   document.formular.CT_LUMINATOR.value="";
   document.formular.CT_USA_EXTERIOARA.value="";
   document.formular.CT_XXX.value="";
   document.formular.CT_XXXX.value="";
   document.formular.CT_XXXXX.value="";
   //document.formular.TOTAL3.value = 0.36;
   document.formular.TOTAL2.value = 0.36;
   document.formular.TP.value = 0;
   document.formular.TXXX.value = 0;


}



function verificare(tip){

   success = true;  
   error = new Array();
   i = 0;
   if( trim(document.formular.BENEFICIAR.value) == ""){error[i++]     = "Camp [Beneficiar] eronat/necompletat"; success=false;} 
   if( trim(document.formular.OBIECTIV.value) == ""){error[i++]       = "Camp [Obiectiv] eronat/necompletat"; success=false;} 

   if(!_verif(document.formular.LUNGIME.value)){error[i++]             = "Camp [Lungime] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.LATIME.value)){error[i++]              = "Camp [Latime] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.INALTIME.value)){error[i++]            = "Camp [Inaltime] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.TR.value)){error[i++]                  = "Camp [Temperatura halei] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.TS.value)){error[i++]                  = "Camp [Temperatura radiatiilor] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.TE.value)){error[i++]                  = "Camp [Temperatura exterioara max. conf DIN 4701] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.TA1TA2.value)){error[i++]              = "Camp [Diferenta de temperatura incapere vecina (ta1 - ta2)] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.N.value)){error[i++]                   = "Camp [Numarul schimburilor de aer] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.UNGHI.value)){error[i++]               = "Camp [Acoperis Plat/Ascutit] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.SI_PERETE_INTERIOR.value)){error[i++]  = "Camp [Perete interior] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.SI_FEREASTRA.value)){error[i++]        = "Camp [Fereastra] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.SI_LUMINATOR.value)){error[i++]        = "Camp [Luminator] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.SI_USA_EXTERIOARA.value)){error[i++]   = "Camp [Usa exterioara] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.SI_XXX.value)){error[i++]              = "Camp [Suprafete inchideri - XXX] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.SI_XXXX.value)){error[i++]             = "Camp [Suprafete inchideri - XXXX] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.SI_XXXXX.value)){error[i++]            = "Camp [Suprafete inchideri - XXXXX] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_PARDOSEALA.value)){error[i++]       = "Camp [Coeficient transfer - Pardoseala] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_ACOPERIS.value)){error[i++]         = "Camp [Coeficient transfer - Acoperis] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_PERETE_EXTERIOR.value)){error[i++]  = "Camp [Coeficient transfer - Perete exterior] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_PERETE_INTERIOR.value)){error[i++]  = "Camp [Coeficient transfer - Perete interior] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_FEREASTRA.value)){error[i++]        = "Camp [Coeficient transfer - Fereastra] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_LUMINATOR.value)){error[i++]        = "Camp [Coeficient transfer - Luminator] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_USA_EXTERIOARA.value)){error[i++]   = "Camp [Coeficient transfer - Usa exterioara] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_XXX.value)){error[i++]              = "Camp [Coeficient transfer - XXX] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_XXXX.value)){error[i++]             = "Camp [Coeficient transfer - XXXX] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.CT_XXXXX.value)){error[i++]            = "Camp [Coeficient transfer - XXXXX] eronat/necompletat"; success=false;}
   if(!_verif(document.formular.RANDAMENT.value)){error[i++]           = "Camp [RANDANENT] eronat/necompletat"; success=false;}  
   if(tip == 0){
    //verificare, dupa care urmeaza calculul
    if(success)bigcalcul();
    else alert("A fost depistate erori culegere date. \nVerificati si corectati.");
   }
   else{
    //verificare de sine statatoare
      errorstring = "";
      if(error.length > 0){
         for(i=0;i<error.length;i++){
            errorstring += error[i]+"\n";
         }
         alert(errorstring);
      }
      else {
         alert ("Nu am depistat erori. \nTotul pare a fi ok.");
      }
   }
}


function _verif(num){
 
 if  (trim(num) == "" || !isNumeric(num) )return false;
 return true;
}





function bigcalcul(){
  calculDimCladiri(); calcTempAer(); calcDifTemp1(); calcDifTemp2(); calcSuprafete(); calcMatrice(); calcFinal();
  alert("Calcul efectuat !");

}



function calculDimCladiri(){
  document.formular.SPARDOSELE.value=Math.round(document.formular.LUNGIME.value*document.formular.LATIME.value);
  document.formular.VOLUM.value=Math.round(document.formular.LUNGIME.value*document.formular.LATIME.value*document.formular.INALTIME.value);
}

function calcTempAer(){
   document.formular.TA.value = Math.round(parseFloat(document.formular.TR.value) - parseFloat(document.formular.TS.value)); 
  
}

function calcDifTemp1(){
   document.formular.TRTE.value = Math.round(-1*parseFloat(document.formular.TE.value) + parseFloat(document.formular.TR.value) );

}
function calcDifTemp2(){
   document.formular.TATE.value = Math.round(-1*parseFloat(document.formular.TE.value) + parseFloat(document.formular.TA.value));
}

function calcSuprafete(){
     document.formular.SI_PARDOSEALA.value = Math.round( parseFloat(document.formular.SPARDOSELE.value) );
     document.formular.SI_ACOPERIS.value   = Math.round((parseFloat(document.formular.LATIME.value)/Math.sin((90-parseFloat(document.formular.UNGHI.value))*Math.PI/180))*parseFloat(document.formular.LUNGIME.value) - parseFloat(document.formular.SI_LUMINATOR.value) );
     
     document.formular.SI_PERETE_EXTERIOR.value = Math.round( parseFloat(document.formular.LATIME.value)*parseFloat(document.formular.INALTIME.value)*2+parseFloat(document.formular.LUNGIME.value)*(parseFloat(document.formular.INALTIME.value)-Math.sin(parseFloat(document.formular.UNGHI.value)*Math.PI/180)*parseFloat(document.formular.LATIME.value)/Math.sin((90-parseFloat(document.formular.UNGHI.value))*Math.PI/180)/4)*2-parseFloat(document.formular.SI_PERETE_INTERIOR.value)-parseFloat(document.formular.SI_FEREASTRA.value)-parseFloat(document.formular.SI_USA_EXTERIOARA.value)      );
}

function calcMatrice(){
       document.formular.CL_PARDOSEALA_1.value = document.formular.SI_PARDOSEALA.value;
       document.formular.CL_PARDOSEALA_2.value = document.formular.CT_PARDOSEALA.value;
       document.formular.CL_PARDOSEALA_3.value = document.formular.TP.value;
       document.formular.CL_PARDOSEALA_FINAL.value = myFormat((parseFloat(document.formular.CL_PARDOSEALA_1.value)*parseFloat(document.formular.CL_PARDOSEALA_2.value)*parseFloat(document.formular.CL_PARDOSEALA_3.value))/1000,2);


       document.formular.CL_ACOPERIS_1.value = document.formular.SI_ACOPERIS.value;
       document.formular.CL_ACOPERIS_2.value = document.formular.CT_ACOPERIS.value;
       document.formular.CL_ACOPERIS_3.value = document.formular.TATE.value;
       document.formular.CL_ACOPERIS_FINAL.value = myFormat((parseFloat(document.formular.CL_ACOPERIS_1.value)*parseFloat(document.formular.CL_ACOPERIS_2.value)*parseFloat(document.formular.CL_ACOPERIS_3.value))/1000,2);

       document.formular.CL_PERETE_EXTERIOR_1.value = document.formular.SI_PERETE_EXTERIOR.value;
       document.formular.CL_PERETE_EXTERIOR_2.value = document.formular.CT_PERETE_EXTERIOR.value;
       document.formular.CL_PERETE_EXTERIOR_3.value = document.formular.TATE.value;
       document.formular.CL_PERETE_EXTERIOR_FINAL.value = myFormat((parseFloat(document.formular.CL_PERETE_EXTERIOR_1.value)*parseFloat(document.formular.CL_PERETE_EXTERIOR_2.value)*parseFloat(document.formular.CL_PERETE_EXTERIOR_3.value))/1000,2);


       document.formular.CL_PERETE_INTERIOR_1.value = document.formular.SI_PERETE_INTERIOR.value;
       document.formular.CL_PERETE_INTERIOR_2.value = document.formular.CT_PERETE_INTERIOR.value;
       document.formular.CL_PERETE_INTERIOR_3.value = document.formular.TA1TA2.value;
       document.formular.CL_PERETE_INTERIOR_FINAL.value = myFormat((parseFloat(document.formular.CL_PERETE_INTERIOR_1.value)*parseFloat(document.formular.CL_PERETE_INTERIOR_2.value)*parseFloat(document.formular.CL_PERETE_INTERIOR_3.value))/1000,2);

       document.formular.CL_FERESTRE_1.value = document.formular.SI_FEREASTRA.value;
       document.formular.CL_FERESTRE_2.value = document.formular.CT_FEREASTRA.value;
       document.formular.CL_FERESTRE_3.value = document.formular.TATE.value;
       document.formular.CL_FERESTRE_FINAL.value = myFormat((parseFloat(document.formular.CL_FERESTRE_1.value)*parseFloat(document.formular.CL_FERESTRE_2.value)*parseFloat(document.formular.CL_FERESTRE_3.value))/1000,2);


       document.formular.CL_LUMINATOR_1.value = document.formular.SI_LUMINATOR.value;
       document.formular.CL_LUMINATOR_2.value = document.formular.CT_LUMINATOR.value;
       document.formular.CL_LUMINATOR_3.value = document.formular.TATE.value;
       document.formular.CL_LUMINATOR_FINAL.value = myFormat((parseFloat(document.formular.CL_LUMINATOR_1.value)*parseFloat(document.formular.CL_LUMINATOR_2.value)*parseFloat(document.formular.CL_LUMINATOR_3.value))/1000,2);


       document.formular.CL_USA_EXTERNA1_1.value = document.formular.SI_USA_EXTERIOARA.value;
       document.formular.CL_USA_EXTERNA1_2.value = document.formular.CT_USA_EXTERIOARA.value;
       document.formular.CL_USA_EXTERNA1_3.value = document.formular.TATE.value;
       document.formular.CL_USA_EXTERNA_FINAL1.value = myFormat((parseFloat(document.formular.CL_USA_EXTERNA1_1.value)*parseFloat(document.formular.CL_USA_EXTERNA1_2.value)*parseFloat(document.formular.CL_USA_EXTERNA1_3.value))/1000,2);


       document.formular.CL_USA_EXTERNA2_1.value = document.formular.SI_XXX.value;
       document.formular.CL_USA_EXTERNA2_2.value = document.formular.CT_XXX.value;
       document.formular.CL_USA_EXTERNA2_3.value = document.formular.TXXX.value;
       document.formular.CL_USA_EXTERNA_FINAL2.value = myFormat((parseFloat(document.formular.CL_USA_EXTERNA2_1.value)*parseFloat(document.formular.CL_USA_EXTERNA2_2.value)*parseFloat(document.formular.CL_USA_EXTERNA2_3.value))/1000,2);

       document.formular.CL_USA_EXTERNA3_1.value = document.formular.SI_XXXX.value;
       document.formular.CL_USA_EXTERNA3_2.value = document.formular.CT_XXXX.value;
       document.formular.CL_USA_EXTERNA3_3.value = document.formular.TXXX.value;
       document.formular.CL_USA_EXTERNA_FINAL3.value = myFormat((parseFloat(document.formular.CL_USA_EXTERNA3_1.value)*parseFloat(document.formular.CL_USA_EXTERNA3_2.value)*parseFloat(document.formular.CL_USA_EXTERNA3_3.value))/1000,2);

       document.formular.CL_USA_EXTERNA4_1.value = document.formular.SI_XXXXX.value;
       document.formular.CL_USA_EXTERNA4_2.value = document.formular.CT_XXXXX.value;
       document.formular.CL_USA_EXTERNA4_3.value = document.formular.TXXX.value;
       document.formular.CL_USA_EXTERNA_FINAL4.value = myFormat((parseFloat(document.formular.CL_USA_EXTERNA4_1.value)*parseFloat(document.formular.CL_USA_EXTERNA4_2.value)*parseFloat(document.formular.CL_USA_EXTERNA4_3.value))/1000,2);

}

function calcFinal(){
      document.formular.TOTAL_QT.value = myFormat(parseFloat(document.formular.CL_PARDOSEALA_FINAL.value)+
                                         parseFloat(document.formular.CL_ACOPERIS_FINAL.value)+
                                         parseFloat(document.formular.CL_PERETE_EXTERIOR_FINAL.value)+
                                         parseFloat(document.formular.CL_PERETE_INTERIOR_FINAL.value)+
                                         parseFloat(document.formular.CL_FERESTRE_FINAL.value)+
                                         parseFloat(document.formular.CL_LUMINATOR_FINAL.value)+
                                         parseFloat(document.formular.CL_USA_EXTERNA_FINAL1.value),2);

       document.formular.TOTAL1.value = document.formular.VOLUM.value;
       document.formular.TOTAL2.value = 0.36;
       document.formular.TOTAL3.value = document.formular.N.value;
       document.formular.TOTAL4.value = document.formular.TATE.value;
       document.formular.TOTAL_FINAL_1.value = myFormat(( parseFloat(document.formular.TOTAL1.value)*parseFloat(document.formular.TOTAL2.value)*parseFloat(document.formular.TOTAL3.value)*parseFloat(document.formular.TOTAL4.value) )/1000,2);

       document.formular.TOTAL_FINAL_2.value = myFormat(parseFloat(document.formular.TOTAL_QT.value)+parseFloat(document.formular.TOTAL_FINAL_1.value),2);
       document.formular.QANUMARATOR.value   = myFormat(parseFloat(document.formular.TOTAL_FINAL_2.value),2);
       document.formular.QANUMITOR.value     = myFormat(parseFloat(document.formular.RANDAMENT.value)/100,2);
       document.formular.FINAL_X.value       = myFormat(parseFloat(document.formular.TOTAL_FINAL_2.value)/parseFloat(document.formular.RANDAMENT.value)*100,2);
       document.formular.FINAL_Y.value       = myFormat((parseFloat(document.formular.FINAL_X.value)/parseFloat(document.formular.VOLUM.value))*1000,2);

}



function isValid(parm,val) {
  if (parm == "") return true;
  parm = eliminateChar(parm,"\n"); parm = eliminateChar(parm,"\r"); 
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}
 
function isNum(parm) {return isValid(parm,numb);}
function isSpc(parm) {return isValid(parm,spc);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphaNum(parm) {return isValid(parm,lwr+upr+numb+spc);} 


//--ltrim,rtrim, trim
function ltrim ( s ){return s.replace( /^\s*/, "" );}

function rtrim ( s ){return s.replace( /\s*$/, "" );}

function trim ( s ){return rtrim(ltrim(s));}






function myFormat(num,decimals)
  {
    var numobj=new NumberFormat();  numobj.setNumber(num);  numobj.setCurrency(false); numobj.setPlaces(decimals);
	return numobj.toFormatted();
  }	


function NumberFormat(num)
{
//this.COMMA = ',';
this.COMMA='';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.setInputDecimal(this.PERIOD); 
this.setNumber(num); 
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(true);
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num)
{
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal)
{
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
}
else
{
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp;
}
function setPlacesNF(p)
{
this.places = p;
}
function toFormattedNF()
{
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
if (nStr.indexOf(this.PERIOD) == -1)
{
splitString[0] = nStr;
splitString[1] = '';
}
else
{
splitString = nStr.split(this.PERIOD, 2);
}
if (this.hasSeparators)
{
pos = splitString[0].length;
while (pos > 0)
{
pos -= 3;
if (pos <= 0) break;
splitString[0] = splitString[0].substring(0,pos)
+ this.separatorValue
+ splitString[0].substring(pos, splitString[0].length);
}
}
if (splitString[1].length > 0)
{
nStr = splitString[0] + this.decimalValue + splitString[1];
}
else
{
nStr = splitString[0];
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
}
else if (this.currencyPosition == this.LEFT_INSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0)
{
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getRoundedNF(val)
{
var factor;
var i;
factor = 1;
for (i=0; i<this.places; i++)
{	factor *= 10; }
val *= factor;
val = Math.round(val);
val /= factor;
return (val);
}
function preserveZerosNF(val)
{
var i;
val = val + '';
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1)
{
val += '.';
for (i=0; i<this.places; i++)
{
val += '0';
}
}
else
{
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++)
{
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
val = (val==null) ? 0 : val;
var newVal = val + ""; 
var isPercentage = false;
var isFormattedNeg = false;
if (newVal.indexOf('%') != -1)
{
newVal = newVal.replace(/\%/g, '');
isPercentage = true;
}
if (newVal.indexOf(this.DASH) != -1
|| (newVal.indexOf(this.LEFT_PAREN) != -1 && newVal.indexOf(this.RIGHT_PAREN) != -1))
{
newVal = newVal.replace(/[\-\(\)]/g, '');
isFormattedNeg = true;
}
if (this.inputDecimalValue != this.PERIOD)
{
newVal = newVal.replace(/\./g, '');
}
var itrDecimal;
var tempVal = '';
var foundDecimal = false;
for (itrDecimal=0; itrDecimal<newVal.length; itrDecimal++)
{
if (newVal.charAt(itrDecimal) == this.inputDecimalValue)
{
if (foundDecimal)
{
}
else
{
tempVal = tempVal + this.PERIOD;
foundDecimal = true;
}
}
else
{
tempVal = tempVal + newVal.charAt(itrDecimal);
}
}
newVal = tempVal;
if (isFormattedNeg) newVal = '-' + newVal;
if (isNaN(newVal))
{
newVal = parseFloat(newVal.replace(/[^\d\.\-]/g, ''));
newVal = (isNaN(newVal) ? 0 : newVal); 
}
else if (!isFinite(newVal))
{
newVal = 0;
}
if (isPercentage)
{
newVal = newVal / 100;
}
return newVal;
}


function isNumeric(sText){
   var ValidChars = "-0123456789.";
   var IsNumber=true;
   var xChar;
   var pointCounters = 0;
   var i;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
       xChar = sText.charAt(i); 
       if (ValidChars.indexOf(xChar) == -1) 
         {
            IsNumber = false;
         }
	 if (xChar == '.') pointCounters++;
         if (xChar == '-' && i > 0) IsNumber = false;
      }
   if (pointCounters > 1) IsNumber = false;    
   return IsNumber;   
}


function zwindow(source,name,width,height,nHow)
{
  /*
  nHow == 0 - centered;
  nHow == 1 - up left
  */
  var screenWidth,screenHeight,splashWin; 
  screenWidth  = screen.availWidth;
  screenHeight = screen.availHeight;  
  if(nHow == 0)
  {
    if(ie||dom) { splashWin = window.open(source,name, "width="+width+",height="+height+",left="+(screenWidth-width)/2+",top="+(screenHeight-height)/2+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
    if(ns) { splashWin = window.open(source,name, "width="+width+",height="+height+",screenX="+(screenWidth-width)/2+",screenY="+(screenHeight-height)/2+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
  }
  if(nHow == 1)
  {
    if(ie||dom) { splashWin = window.open(source,name, "width="+width+",height="+height+",left=7,top=18,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
    if(ns) { splashWin = window.open(source,name, "width="+width+",height="+height+",screenX=0,screenY=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
  }
  
}

function putvalue1(valuex){	
   opener.document.getElementById('N').value = valuex;
   alert("ok, valoarea "+valuex+" a fost selectata... !");
   window.close();
}























