function addEvent(obj, evType, fn){ if (obj.addEventListener){obj.addEventListener(evType, fn, true);return true; } else if (obj.attachEvent){var r = obj.attachEvent("on"+evType, fn);return r;} else {return false; }}

function removeEvent(obj, evType, fn, useCapture){ if (obj.removeEventListener){obj.removeEventListener(evType, fn, useCapture);return true;}  else if (obj.detachEvent){var r = obj.detachEvent("on"+evType, fn);return r;} else {}}

function removePX(what){try {what=""+what+'';ofset=what.indexOf('px');if (ofset>0) what=what.substring(0,ofset);return parseInt(what,0);} catch (e) {return window.undefined;}}

// pobiera rozmiar widocznego okna w pikselach
function getViewportHeight() {var _y=null;if (self.innerHeight) _y = removePX(self.innerHeight);
else if (document.documentElement && document.documentElement.clientHeight) _y = removePX(document.documentElement.clientHeight);
else if (document.body) _y = removePX(document.body.clientHeight);return _y;}

// pobiera rozmiar widocznego okna w pikselach
function getViewportWidth() {var _x=null;if (self.innerWidth) _x = removePX(self.innerWidth);
else if (document.documentElement && document.documentElement.clientWidth) _x = removePX(document.documentElement.clientWidth);
else if (document.body) _x = removePX(document.body.clientWidth);return _x;}

// pokazuje obiekt o podanym ID
function showObject(objectID){try {var  el= document.getElementById(objectID);if (el!=null)el.style.visibility = 'visible';} catch (e) {}}

function displayObject(objectID){try {var  el= document.getElementById(objectID);if (el!=null)el.style.display = 'block';} catch (e) {}}

function GetDisplayObject(objectID){try {var  el= document.getElementById(objectID);if (el!=null) return el.style.display ;} catch (e) {}return null;}

function notDisplayObject(objectID){try {var  el= document.getElementById(objectID);if (el!=null)el.style.display = 'none';} catch (e) {}}

//chowa obiekt o podanym ID
function hideObject(objectID){try {var  el= document.getElementById(objectID);if (el!=null){el.style.visibility = 'hidden';}} catch (e) {}}

// zamienia tekst w obiektach 
function replaceTextInObject(objectID,newText){var  el= document.getElementById(objectID);
if (el!=null){var old_text = el.firstChild;   var new_text = document.createTextNode(newText);
if (old_text)  el.replaceChild(new_text, old_text);else   el.innerText=newText;}}

// ustawia VAL dla drop down list (o id=IDX)  
function setDropDownValue(IDX,VAL){e= document.getElementById(IDX);if (e!=null){i = e.length;for (k=0; k<i; k++) { e.options[k].selected=false;}
for (k=0; k<i; k++) { if (e.options[k].value==VAL) { e.options[k].selected=true; } }}}

function getDropDownValue(IDX){e= document.getElementById(IDX);if (e!=null){return e.value;}return null;}

 function NumericKeyPress(e) {if(document.selection != null) {if(document.selection.createRange().text != '')
document.selection.clear();	}	var keyCode = event.keyCode;if (keyCode<48 || keyCode>57) event.keyCode=null;}

// usuwa zawartość schowka - numeric box
function NumericPaste(object){window.clipboardData.setData("Text","");return true;}
// sprawdza poprawność waluty
//ValidateNullCurrency - zezwala na puste i minusowe
//ValidateNullNotMinusCurrency - zezwala na puste nie zezwala na minusowe
//ValidateNonMinusCurrency - nie zezwala na null i minus
//ValidateCurrency - nie zezwala na null zezwala na minus

function CurrencyIsValid(s)  // sprawdza czy poprawnie wprowadzono walute
{try {if (s!=""){s=removeChar(removeChar (s, 32),160);s=s.replace(",","."); var i= parseFloat(s);
 var ns=""+i; var li=ns.indexOf(".",0); if (li<0) ns+=".00"; else if (li>=ns.length-2) ns+="0"; if (ns==s && ""+i!="NaN") return true;}} catch(e) {}return false;}

function ValidateNullCurrency(oSrc, args){var s=""+Remove0(args.Value); if (s=="" || CurrencyIsValid(s)) args.IsValid=true; else args.IsValid= false; return args.IsValid;}

function ValidateNullNotMinusCurrency(oSrc, args){var s=""+Remove0(args.Value);if ((s.indexOf("-",0)<0) && (s=="" || CurrencyIsValid(s) )) args.IsValid=true; else args.IsValid= false; return args.IsValid;}

function ValidateNonMinusCurrency (oSrc, args){var s=""+Remove0(args.Value);if (s.indexOf("-",0)<0 && CurrencyIsValid(s))args.IsValid= true; else args.IsValid= false;return args.IsValid;}
 
function ValidateCurrency(oSrc, args) {var s=""+Remove0(args.Value);if (s!="" && CurrencyIsValid(s))args.IsValid= true; else args.IsValid= false;return args.IsValid;}

function removeChar (text, znak) {text=""+text;if (text!=""){ s="";for (i=0; i<text.length; i++){ ch=text.charCodeAt(i);if (ch!=znak) s+=text.charAt(i);}return s;}return text;}

// sprawdza poprawność daty
function ValidateCalendar(oSrc, args) { args.IsValid=Valid_Date(args.Value); }
 
function Remove0(text) { if (text!=null && text+""!="") { text=""+text+""; while (text.length>0 && text.charAt(0)=='0' ) text=text.substring(1,text.length) ; } return text;}
 
function Valid_Date (text){ try { if (text.length<10) return false; var year= Remove0(text.substring(0,4));
var month= Remove0(text.substring(5,7)); var day= Remove0(text.substring(8,10)); var sep= ""+text.substring(4,5) +text.substring(7,8);
if (sep!="--") return false; var y=parseInt(year,0); var m= parseInt(month,0);
var d= parseInt(day,0); if (y=="NaN" || m=="NaN" || d=="NaN") return false;
if (y<1900 || y>3000 || d<1 ||d>31 || m<1 || m>12) return false;
if (m==1 || m%2!=0) if (d>30) return false;
if (m==2) { if (y%4==0 && (y%100!=0 || y%1000==0))  { if (d>29) return false;}   else if (d>28) returntrue;  }
return true;   } catch (e) {} return false; }
  
function SWAPIMAGE(obj,s) { obj.src=s; } 
 
function Scroller(obiekt,parent,child){ var ny=0;var ntop=0;var theBody = document.documentElement;try {ny= theBody.scrollHeight;
ntop=  theBody.scrollTop;} catch (e) {}var _x=0; var _y=0;_x=getViewportWidth();_y=getViewportHeight();
var w=250;	var h=50;	var el=document.getElementById(obiekt);	if(el)
{if (el.style.width) w= removePX(el.style.width);if (el.style.height) h= removePX(el.style.height);
var scLeft = parseInt(theBody.scrollLeft,10);var scTop = parseInt(theBody.scrollTop,10);
var pap=0;if (parent && parent.style && parent.style.width) pap=removePX( parent.style.width);
if (ny<_y) ny=_y;var newW=(_x-pap)/2;if (newW<0) newW=0;var top = (_y-h) /2;var left = (_x-w) /2;
var ofs = parseInt(theBody.scrollTop,10);var scLeft = parseInt(theBody.scrollLeft,10);
if (!parent) newW=0;if( left<=0 ) left = 10;el.style.left = scLeft+left-newW + 'px';el.style.top =ofs+top + 'px';
if (!parent) newW=0;var k=document.getElementById(child);if (k!=null){k.style.left=(scLeft+(-newW))+'px';	k.style.width=(_x)+'px';k.style.height=ny+'px';}}}

function getElementAbsPosX(el){var dx = 0;if (el.offsetParent) {dx = el.offsetLeft + 8;while (el = el.offsetParent) {dx += el.offsetLeft;}}return dx;}

function getElementAbsPosY(el){var dy = 0;if (el.offsetParent) {dy = el.offsetTop ;while (el = el.offsetParent) {dy += el.offsetTop;}}return dy;}

function HideValidator(UID){v=document.getElementById("TSOFT_Validator"); if (v!=null) { v.style.left=0+'px';
v.style.top= 0+'px'; v.style.visibility='hidden';  v.style.display='none'; el= document.getElementById(UID);
if (el!=null)  el.style.backgroundColor=''; }}

// validacja do obiektu smart validator - sprwdza czy jest liczba
function TsoFtSmartValidNumber(UID,text) { rv= false; el= document.getElementById(UID); v=document.getElementById("TSOFT_Validator");
if (el!=null && v!=null){x= getElementAbsPosX(el); y= getElementAbsPosY(el); i= parseInt(el.value)+""; 
if (i==NaN || i!=el.value+"" || i<0){ v.style.left=x+ removePX(el.style.width)-10+'px';  v.style.top= y+'px';
v.style.visibility='visible';  v.style.display='block';  el.style.backgroundColor='#ffcccc';  replaceTextInObject("TSOFT_ValidatorLabel",text);} 
else{ el.style.backgroundColor=''; rv=true;}}return rv;}

// validacja do obiektu smart validator - sprwdza czy cokolwiek wprowadzono
function TsoFtSmartValidExists(UID,text) 
{  el= document.getElementById(UID);v=document.getElementById("TSOFT_Validator");
if (el!=null && v!=null){ x= getElementAbsPosX(el); y= getElementAbsPosY(el); i= el.value+""; 
if (el.value=="") {  v.style.left=x+ removePX(el.style.width)-20+'px';  v.style.top= y+'px';
v.style.visibility='visible';  v.style.display='block';  replaceTextInObject("TSOFT_ValidatorLabel",text);
el.style.backgroundColor='#ffcccc'; return false;} else  { el.style.backgroundColor=''; return true;}} return false;}

// walidacja wszystkich obiektów z req na końcu nazwy
function TsoFtCheckAllReq(formID,text,number) { var go=false;f= document.forms[0];
if (f==null) {f= document.getElementById(formID); } if (f!=null) {var i; for (i=f.length-1; i>=0; i--)
{var obj=f.elements[i];s=obj.id+"";if (s.substring(s.length-3 ,s.length)=='req') 
{if (obj.type=='text'||obj.type=='textarea') {if (number) go=TsoFtSmartValidNumber(obj.id,text); else
go=TsoFtSmartValidExists(obj.id,text); }}}}return go;}






    function calculateVAT(obj, my,vat,b)
    {
    var m= document.getElementById(my);
    if (m!=null )
    {
    
    try {
    var s= m.value;
      if (s!="")
      {s=removeChar(removeChar (s, 32),160);s=s.replace(",","."); 
      var i= parseFloat(s);
     // var ns=""+i; 
     // var li=ns.indexOf(".",0); 
      //if (li<0) ns+=".00"; else if (li>=ns.length-2) ns+="0"; 
      if ( ""+i!="NaN") 
       {
       // ustaw
       
       var dv=1+ parseInt(vat ,0)/100.0;
       var brutto=0;
       if (b==1) brutto=  i*dv ; else brutto=i/dv;
       brutto =""+ Math.round(brutto*100)/100.0;
       var el= document.getElementById(obj);
       if (el!=null) el.value=brutto.replace(".",","); ;
       
       return true;
       }
      }}
       catch(e) {}
       }
       return false;
       }
       
       
       
       

    function TSetRed(obj)
  	{
  	 for(var i=0;i<document.links.length;i++)
      {
       s=""+document.links[i].href;
       sa=""+document.links[i].className; 
       if (s!="" && s!="javascript:void(0)" && sa=="MyMenu_Active") document.links[i].className="MyMenu";
      }   
     obj.className="MyMenu_Active"; 
    }

function TSetRedByGuid(guid)
{
  for(var i=0;i<document.links.length;i++)
  {
   s=""+document.links[i].href;
   sa=""+document.links[i].className;
   if (s!="" && s!="javascript:void(0)" && sa=="MyMenu_Active") document.links[i].className="MyMenu";
   if (s.indexOf(guid,0)>0) document.links[i].className="MyMenu_Active";
  }   
}

var IMG_PATH="../../images/Menu/";

    function chngIMG(ID,to)
    {
    var el=document.getElementById(ID);
    if (el!=null) el.src=to;
    }
    
    function TMenu(NodeID,onlyExpand)
    {
    
     var disp=GetDisplayObject("N"+NodeID);
     if ((disp==null || disp=='block' || disp=='') && onlyExpand!=1) 
     { 
      notDisplayObject("N"+NodeID);
      chngIMG(NodeID+"_I",IMG_PATH+"plus.gif");
     } else
     {
     displayObject("N"+NodeID);
     chngIMG(NodeID+"_I",IMG_PATH+"minus.gif");
      }
    }
   

