
doc = document;
ie = doc.all;
ns4 = doc.layers;
ns6 = (doc.getElementById&&!doc.all);

s = ie?".style":ns6?"').style":"";
lr = ie?"doc.all.":ns6?"doc.getElementById('":"doc.layers['menu'].document.layers.";
en = ie?"":ns6?"')":"";

var btn_mouse_left   = (ie) ? 1 : 0;
var btn_mouse_middle = (ie) ? 4 : 1;
var btn_mouse_right  = (ie) ? 2 : 2;

doc.oncontextmenu=new Function("return false");
visible='block';
hidden='none';


function MenuMouseRight(evnt){
   e = (ie) ? event : evnt;
   return (e.button == btn_mouse_right ? true : false);
}

function MenuMouseLeft(evnt){
   e = (ie) ? event : evnt;
   return (e.button == btn_mouse_left ? true : false);
}

function _addEvent(el, evname, func) {
	if(ie)  el.attachEvent("on" + evname, func);
	else    el.addEventListener(evname, func, true);
}
function _removeEvent(el, evname, func) {
	if(ie)  el.detachEvent("on" + evname, func);
	else    el.removeEventListener(evname, func, true);
}

function menu(noN,laN){
  if(eval(lr+laN+s+'.display')=='none'){
    show(laN);
    eval(lr+noN+en+'.innerHTML="-"');
  } else {
    hide(laN);
    eval(lr+noN+en+'.innerHTML="+"');
  }
}


//display
function show(laN){
  if((ob =  doc.getElementById(laN)) != null) ob.style.display=visible;
}
function hide(laN){
  if((ob =  doc.getElementById(laN)) != null) ob.style.display=hidden;
}
function display(laN){
  if((ob =  doc.getElementById(laN)) != null){
    return (ob.style.display == visible ? true : false);
  } else return null;
}
//visibility
function v_show(laN){
  if((ob =  document.getElementById(laN)) != null) ob.style.visibility='visible';
}
function v_hide(laN){
  if((ob =  document.getElementById(laN)) != null) ob.style.visibility='hidden';
}
function visible(laN){
  if((ob =  doc.getElementById(laN)) != null){
    return (ob.style.visibility == 'visible' ? true : false);
  } else return null;
}


// funkcja ustawia styl dla podanego obiektu - /IE, NN6
function swap_style(obj,cN){
		obj.className = cN;
}

///////// =[
function showHelpWindow(WindowLocation,WindowTitle,WindowHeight,WindowWidth) {
newWin1=window.open(WindowLocation,WindowTitle,'toolbar=0,status=0,menubar=0,location=0,resizable=yes,scrollbars=no,width='+WindowWidth+',height='+WindowHeight+',left=5,top=5,screenX = 5,screenY = 5');
newWin1.focus()
}


// obsluga formularzy //

var Form_const_mail = /^([-a-z0-9_.]+\@[-a-z0-9_.]+\.[-a-z0-9]{2,}(;|,)?)+$/i;
//                    /^[-0-9a-z._]+@[-0-9a-z]+(\.[-0-9a-z])+$/i

function Form_Del_Confirm(command,msg)
{
  if(msg != '') msg = "\n\n"+msg;
  if(confirm("Na pewno chcesz usun±ć wybran± pozycję?"+msg)) location = command;
}

/*
  Funkcja tworzy obiekt o 3 wlasciwosciach:
  text = komunikat wyswietlany
  reg = zawiera wyrazenie regularne do sprawdzenia danych
        uzywane gdy input jest typu: 'text', 'file', 'textarea', 'password'
        'radio', 'checkbox', 'select' tego pola nie wymaga
  required = wymusza wypelnienie danego pola

  new Form_Add_Var('test ...', /^[0-9]{2,8}$/i, 1);
*/
function Form_Add_Var(text,reg,required,new_style)
{
  this.text = text;
  this.reg = reg;
  if(typeof required == "undefined" || required == false)
    this.required = false;
  else
    this.required = true;
  if(typeof new_style != "undefined") this.new_style = new_style;
}


/*
  <button type="submit" onclick="return Form_Check(form_tab1);">Wyslij</button>
*/
function Form_Check(check)
{
  if(check == null) return false;
  destroyEditor();
  for (var i in check)
  {
    if(check[i].constructor == Array)
    {
      var wymagane = false;
      var grupa = false;
      var komunikat = '';
      var el = null;
      for(var j in check[i])
      {
        if(check[i][j].required && !wymagane) {wymagane = true; komunikat = check[i][j].text; el=document.getElementById(j);}
        if( Form_Check_Parse(check[i],j,true) ) grupa = true;
      }
      if(wymagane && !grupa)
      {
        alert(komunikat);
        el.select();
        el.focus();
        return false;
      }
      else
      {
        //przywracamy styl dla danej grupy
        for(var j in check[i])
        {
          var el = document.getElementById(j);
          var pr = el.parentNode;
          if(typeof el.old_style == "undefined") el.old_style = el.style.cssText;
          if(typeof pr.old_style == "undefined") pr.old_style = pr.style.cssText;
          el.style.cssText = el.old_style;
          pr.style.cssText = pr.old_style;
        }
      }
    }
    else
    {
      if(!Form_Check_Parse(check,i)) return false;
    }
  }
  return true;
};

function destroyEditor() {}
function Form_Check_Parse(check,i,group)
{
   var new_style = (typeof check[i].new_style == "undefined") ? "background-color: #EE8888" : check[i].new_style;
   var el = document.getElementById(i);
   var pr = el.parentNode;
   if(typeof el.old_style == "undefined") el.old_style = el.style.cssText;
   if(typeof pr.old_style == "undefined") pr.old_style = pr.style.cssText;
   el.style.cssText = el.old_style;
   pr.style.cssText = pr.old_style;

     if( (typeof el.value != "undefined" && el.value != '' && !check[i].required) || check[i].required || group)
     {
//     alert(el.value+' : '+el.type+' : '+el.checked);
       switch(el.type)
       {
         case 'select-one':
             if(el.selectedIndex == -1 || el.selectedIndex == 0)
             {
               el.style.cssText = el.old_style +';'+ new_style;
               if(!group)
               {
                 alert(check[i].text);
                 el.focus();
               }
               return false;
             }
           break;
         case 'select-multiple':
             if(el.selectedIndex == -1)
             {
               el.style.cssText = el.old_style +';'+ new_style;
               if(!group)
               {
                 alert(check[i].text);
                 el.focus();
               }
               return false;
             }
           break;

         case 'checkbox':
             if(!el.checked)
             {
               if(ie)
                 el.style.cssText = new_style;
               else
                 pr.style.cssText = pr.old_style +';'+new_style;

               if(!group)
               {
                 alert(check[i].text);
                 el.select();
                 el.focus();
               }
               return false;
             }
           break;


         case 'radio':
             if(!el.checked)
             {
               var zliczaj = 1;
               var checked = false;

               while(1){
                 next_i = i + zliczaj++;
                 var el_next = document.getElementById(next_i);
                 try{
                   if(el_next.name == el.name && el_next.checked) checked = true;
                 } catch (e) { 
                   break;
                 }
               }
               if(checked) break;

               if(ie)
                 el.style.cssText = new_style;
               else
                 pr.style.cssText = pr.old_style +';'+new_style;

               if(!group)
               {
                 alert(check[i].text);
                 el.select();
                 el.focus();
               }
               return false;
             }
           break;

         case 'text':
         case 'file':
         case 'textarea':
         case 'password':
             if (!check[i].reg.test(el.value)) 
             {
//               el.style.cssText = new_style;
               el.style.cssText = el.old_style +';'+ new_style;
               if(!group)
               {
                 alert(check[i].text);
                 el.select();
                 el.focus();
               }
               return false;
             }
           break;
       }
     }
  return true;
}

/*

  przyklad:

  var form_def = 
  {
      'f_padding_h':new Form_Add_Var('wypelnij pole', '', 1 ,"border: 1 solid red;"), //pole wymagane
      'f_padding_e':new Form_Add_Var('zaznacz jedn± z opcji', /./i, 1 ), // pole wymagane
      'f_padding_a':new Form_Add_Var('podana warto¶ć musi być liczb± nie dłuższ± niż 8 znaków', /^[0-9]{1,8}$/i ),
      'f_padding_b':new Form_Add_Var('wpisz tekst nie krótszy niż 2 znaki i nie dłuższy niż 21 znaków', /^.{2,21}$/i, 1 ), //pole wymagane
      'f_padding_c':new Form_Add_Var('zaznacz opcję', '', 1) //pole wymagane
  };
  <button type="submit" onClick="return Form_Check(form_def);">Wy¶lij</button >
*/


/* do odpalania PopUp'ów */
CMS2_PopUp = null;
CMS2_Exit = true;
function CMS2_Start(){return}
function CMS2_Stop(){return}
function CMS2_Link(){ CMS2_Exit=false; }


/* obsluga podmiany grafiki */
/*  stałe globalne  */
var root="";              // ścieżka katalogu z grafiką
var CMS2_TabImages = Array();  // tablica obrazków do podmiany
function CMS2_Img(id,off,on){
	// właściwości
	this.id=id;
	this.img_on = new Image();
	this.img_off = new Image();
	this.img_off.src = root + off;
	this.img_on.src = root + on;
	// metody
	this.on = CMS2_ImgOn;
	this.off = CMS2_ImgOff;
	this.to_img = CMS2_swapImg;
}
function CMS2_ImgOn(){ self.document.images[this.id].src=this.img_on.src; }
function CMS2_ImgOff(){ self.document.images[this.id].src=this.img_off.src; }
function CMS2_swapImg(nowy){
	temp = this.img_on.src;
	this.img_on.src = nowy.img_on.src;
	nowy.img_on.src = temp;

	temp = this.img_off.src;
	this.img_off.src = nowy.img_off.src;
	nowy.img_off.src = temp;

	temp = this.img_go.src;
	this.img_go.src = nowy.img_go.src;
	nowy.img_go.src = temp;
}
function CMS2_add_img(id, plik_off, plik_on){ CMS2_TabImages[id]=new CMS2_Img(id, plik_off, plik_on); }
// zgaś
function CMS2_off(id){ CMS2_TabImages[id].off(); }
// zapal
function CMS2_on(id){ CMS2_TabImages[id].on(); }
// zamień
function CMS2_to_img(id,id2){ CMS2_TabImages[id].to_img(CMS2_TabImages[id2]); }

//    add_g('plik');
