
   var sIDString = '';
   
   function savePassword()
   {
   	
      var pOldPass   = $('#old_password');
      var pNewPass1  = $('#new_password');
      var pNewPass2  = $('#re_password');
//      var pOldPass   = getElement('old_password');
//      var pNewPass1  = getElement('new_password');
//      var pNewPass2  = getElement('re_password');
      if(pOldPass != null && pNewPass1 != null && pNewPass2 != null)
      {
         if(pNewPass1.value != pNewPass2.value)
         {
            alert("Podane hasła nie są identyczne. Wprowadź je jeszcze raz.");
            pNewPass1.focus();
            pNewPass1.select();
            return;
         }
         else
         if(pNewPass1.value =='')
            if (!confirm("Hasło jest puste. Akceptujesz to?"))
               return;

         if(window.document.formMain)
         {
            window.document.formMain.action1.value = 'change_password';
            window.document.formMain.submit();
         }
         else
         if(window.document.formUser)
         {
            window.document.formUser.action.value = 'change_password';
            window.document.formUser.submit();
         }
 
      }
   }
function ValidEmail(email) {
  invalid = " /:,;";
  if (email == "") return false;
  for (i = 0; i < invalid.length; i++) {
    bad = invalid.charAt(i);
    if (email.indexOf(bad, 0) != -1) return false;
  }
  at = email.indexOf("@", 0);
  if ((at == -1) || (at == 0)) return false;
  if (email.indexOf("@", at+1) != -1) return false;
  period = email.indexOf(".", at);
  if ((period == -1) || (period == at+1)) return false;
  if (period+3 > email.length == -1) return false;
  return true;
}

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header

// Set the message for the alert box
am = "This function is not allowed!";

// do not edit below this line
// ===========================
bV  = parseInt(navigator.appVersion)
bNS = navigator.appName=="Netscape"
bIE = navigator.appName=="Microsoft Internet Explorer"

function nrc(e) {
   if (bNS && e.which > 1){
      alert(am)
      return false
   } else if (bIE && (event.button >1)) {
     alert(am)
     return false;
   }
}
        
function disable_rightbutton() {
        document.onmousedown = nrc;
        if (document.layers) window.captureEvents(Event.MOUSEDOWN);
        if (bNS && bV<5) window.onmousedown = nrc;
}

// inicjacja strony - ustawienie parametrów drukarki, powiększenie okna

function init(portrait) {
        printing = factory.printing;
        printing.portrait = portrait; // false: poziomo, true: pionowo
        printing.leftMargin = 5;
  printing.topMargin = 5;
  printing.rightMargin = 8;
  printing.bottomMargin = 5;
        printing.header = '';
  printing.footer = '';
        //printing.printBackground = false;

        window.moveTo(0,0);
        window.resizeTo(screen.availWidth,screen.availHeight);
}

// -----------------------------------------------------------
// OBSŁUGA COOKIE --- S T A R T
// -----------------------------------------------------------

// utworzenie nowego cookie

function newcookie(name,value) {
  document.cookie = name + "=" + value;
}

// pobranie wartości danego cookie
  
  
function getcookie(name) {
  var cookiefound = false;
  var start = 0;
  var end = 0;
  var cookiestring = document.cookie;
  
  var i = 0;
  
  // scan the cookie for NAME
  while (i <= cookiestring.length) {
    start = i;
    end = start + name.length;
    if (cookiestring.substring(start,end) == name) {
      cookiefound = true;
      break;
    }
  i++;
  }
  
  // is NAME found?
  if (cookiefound) { 
    start = end + 1;
    end = document.cookie.indexOf(";", start);
    if (end < start) end = document.cookie.length;
    return document.cookie.substring (start,end);
  }
  return "";
}

// -----------------------------------------------------------
// OBSŁUGA COOKIE --- K O N I E C
// -----------------------------------------------------------

// -----------------------------------------------------------
// SPRAWDZANIE DATY --- S T A R T
// -----------------------------------------------------------

// sprawdzenie czy znak jest cyfra

function czy_cyfra(cyfra) {
  if (cyfra >= "0" && cyfra <= "9") {
    return true;
  } else {
    return false;
  }
}

// sprawdzenie czy odstęp w dacie jest prawidłowy

function czy_odstep(znak) {
  if (znak == "-") { 
    return true;
  } else {
    return false;
  }
}

// sprawdzenie poprawności wpisanej daty

function ValidDate(item) {
  var i, tekst = "";
   
//        alert(item.value); 
  for (i = 0; i < item.value.length; i++) {
    znak = item.value.charAt(i);
  if (znak != " ") tekst += item.value.charAt(i);   
  }

  item.value = tekst;
    
  i = 0;
  if (czy_cyfra(tekst.charAt(i++))) {
    if (czy_cyfra(tekst.charAt(i)))
      if (czy_cyfra(tekst.charAt(++i)))
        if (czy_cyfra(tekst.charAt(++i))) i++;
  } else {
    item.focus();
    alert ('Rok został wpisany błędnie! Pamiętaj o prawidłowym formacie daty (rrrr-mm-dd).');
    return false;
  }
  if (!czy_odstep(tekst.charAt(i++))) {
    item.focus();
  alert ('Brak myślnika pomiędzy rokiem, a miesiącem! Pamiętaj o prawidłowym formacie daty (rrrr-mm-dd).');
    return false;
  }
  if (czy_cyfra(tekst.charAt(i++))) {
    if (czy_cyfra(tekst.charAt(i))) i++;
  } else {
    item.focus();
  alert ('Miesiąc został wpisany błędnie! Pamiętaj o prawidłowym formacie daty (rrrr-mm-dd).');
    return false;
  }
  if (!czy_odstep(tekst.charAt(i++))) {
    item.focus();
  alert ('Brak myślnika pomiędzy miesiącem, a dniem! Pamiętaj o prawidłowym formacie daty (rrrr-mm-dd).');
    return false;
  }
  if (czy_cyfra(tekst.charAt(i++))) {
    if (czy_cyfra(tekst.charAt(i))) i++;
  } else {
    item.focus();
  alert ('Dzień został wpisany błędnie! Pamiętaj o prawidłowym formacie daty (rrrr-mm-dd).');
    return false;
  }
  if (tekst.length != i) {
    item.focus();
  alert ('Niespodziewany znak na końcu daty! Pamiętaj o prawidłowym formacie daty (rrrr-mm-dd).');
    return false;
  }
  
  return true;
}

// -----------------------------------------------------------
// SPRAWDZANIE DATY --- K O N I E C
// -----------------------------------------------------------

//------------------------------------------------------------
//- DAREK
//------------------------------------------------------------

//nazwa aktualnie otwartego kalendarza
var calendarName;

// czmienna logiczna, czy dany numer zlecenia już istnieje 
var bPrintOrderNumber;
bPrintOrderNumber = false;

//--------------------
//- newText funkcja tworzy nową wiadomość
//- parametry:
//- group - mazwa grupy
//--------------------
function newText(group)
{
  document.formMain.action.value='add_info';
  document.formMain.group.value=group;
  document.formMain.text_id.value='';
  document.formMain.submit();
}

//--------------------
//- deleteText funkcja usuwa wiadomość
//- parametry:
//- id          - numer wiadomości 
//- group - mazwa grupy
//--------------------
function deleteText(id,group)
{
  if (confirm("Jesteś pewien, że chcesz usunąć tą wiadomość? Dane zostaną bezpowrotnie usunięte"))        
  {        
          document.formMain.action.value='delete_info';
          document.formMain.group.value=group;
          document.formMain.text_id.value=id;
          document.formMain.submit();
  }
}

//--------------------
//- editText edytuje istniejącą wiadomość
//- parametry:
//- id          - numer wiadomości 
//- group - mazwa grupy
//--------------------
function editText(id,group)
{
  document.formMain.action.value='edit_info';
  document.formMain.group.value=group;
  document.formMain.text_id.value=id;
  document.formMain.submit();
}



function userInfo(id)
{
         document.history_list.id.value = id;
         document.history_list.action1.value = 'modify';
        document.history_list.submit();        
}

   /**
   *  funkcja ustala pozycję na okna popup ekranie przeglądarki     
   *  @param int popW szerokość okna
   *  @param int shiftX przesunięcie w poziomie
   */
   function GetCenterX(popW, shiftX)
   {
      var w = 680;
      if (ie4)
         w = document.body.clientWidth;
      else
      if (ns4||ns6)
         w = window.innerWidth;
      var nValue = parseInt((w-popW)/2) + parseInt(shiftX);
      return nValue;
   }


   /**
   *  funkcja ustala pozycję na okna popup ekranie przeglądarki     
   *  @param int popH wysokość okna
   *  @param int shiftY przesunięcie w pionie
   */
   function GetCenterY(popH, shiftY)
   {
      var h = 340;
      if (ie4)
         h = document.body.clientHeight;
      else
      if (ns4||ns6)
         h = window.innerHeight;
      var nValue = parseInt((h-popH)/2) + parseInt(shiftY);
      return nValue;
   }

   /**
   *  funkcja otwiera formularza do tworzenia maila w celu odrzucenia zamówienia
   */
   function openWindowCancelOrder()
   {
      if (confirm('Jesteś pewien, że chcesz odrzuć to zamówienie?')) 
      {
         newWindow = window.open('./cancelOrder.php', '','width=530,height=380,top=' + GetCenterY(380) + ',left='+ GetCenterX(530));
         newWindow.document.close();
      }
   }

   /**
   *  zatwierdzenie formularza z mailem wysyłanym w przypadku odrzucenia zamówienia
   */
   function submitCancelOrder()
   {
      parentWindow = window.opener;
      parentWindow.document.historia.action1.value = 'refuse_order';
      parentWindow.document.historia.action2.value = '';
      parentWindow.document.historia.text.value = window.document.formMain.textareaMailText.value;
      parentWindow.document.historia.submit();
      window.close();
   }

   function adminShowDevice()
   {
      window.document.history_list.action2.value = "details";
      window.document.history_list.action3.value = "adminAddDevice";
      if(window.document.history_list.selectDevice.value=='')
      {
         alert("Nie wybrano żadnej pozycji na liście urządzeń");
      }
      else
      {
         window.document.history_list.device_id.value = window.document.history_list.selectDevice.value;
         submitOrder();
         window.document.history_list.submit();
      }
   }

   //------------------
   //- adminDeleteDevice usunięcie urządzenia z zamówiania
   //------------------
   function adminDeleteDevice()
   {
  window.document.history_list.action2.value = "edit_details";
  window.document.history_list.action3.value = "adminDeleteDevice";
  if(window.document.history_list.selectDevice.value=='')
  {
           alert("Nie wybrano żadnej pozycji na liście urządzeń");
  }
  else
  {
         if (confirm('Jesteś pewien, że chcesz usunąć to urządzenie? Dane zostaną bezpowrotnie usunięte.')) 
         {
                   window.document.history_list.device_id.value = window.document.history_list.selectDevice.value;
                  submitOrder();
                   
                   window.document.history_list.submit();
          }
  }
}

//------------------
//- adminAddDevice dodanie urządzenia do zamówianie
//------------------
function adminAddDevice()
{
   window.document.history_list.action2.value = "edit_details";
   window.document.history_list.action3.value = "adminAddDevice";
   window.document.history_list.device_id.value = "";

   submitOrder();
   window.document.history_list.submit();
}

//------------------
//- adminEditDevice edycja urządzenia w zamówianie
//------------------
function adminEditDevice()
{
   window.document.history_list.action2.value = "edit_details";
   window.document.history_list.action3.value = "adminAddDevice";
   if(window.document.history_list.selectDevice.value=='')
   {
      alert("Nie wybrano żadnej pozycji na liście urządzeń");
   }
   else
   {
      window.document.history_list.device_id.value = window.document.history_list.selectDevice.value;
      submitOrder();
      window.document.history_list.submit();
   }
}

//------------------
//- adminSaveDevice zapisanie urządzenia do zamówianie
//------------------
function adminSaveDevice()
{
  window.document.history_list.action2.value = "edit_details";
  window.document.history_list.action3.value = "adminSaveDevice";
 
  submitOrder();
  window.document.history_list.hiddevname.value = 
          window.document.history_list.devname.value ;
  window.document.history_list.hiddevdescription.value = 
          window.document.history_list.devdescription.value ;
  window.document.history_list.hiddevequipment.value = 
          window.document.history_list.devequipment.value ;
  window.document.history_list.hiddevexpertise.value = 
          window.document.history_list.devexpertise.value ;
  window.document.history_list.hiddevpayment_limit.value = 
          window.document.history_list.devpayment_limit.value ;
 

  window.document.history_list.submit();
}

//------------------
//- adminCancelDevice wyjście z edycji/dodawania urządzenia
//------------------
function adminCancelDevice()
{
  window.document.history_list.action2.value = "edit_details";
  window.document.history_list.action3.value = "";
  
  submitOrder();
  window.document.history_list.submit();
}

//------------------
//- saveOrder zapisanie danych zamówienia
//------------------
function saveOrder()
{
  window.document.history_list.action1.value = "save_order";
  window.document.history_list.action3.value = '';
  window.document.history_list.action5.value = '';
   
  submitOrder();
  window.document.history_list.submit();
}

//------------------
//- addOrder dodanie zamówienia
//------------------
function addOrder()
{
   window.document.history_list.action2.value = "edit_details";
   window.document.history_list.action5.value = 'adminAddOrder';
   window.document.history_list.submit();
}

//------------------
//- editOrder edycja zamówienia
//------------------
function editOrder()
{
  window.document.history_list.action2.value = "edit_details";
  window.document.history_list.submit();
}

//------------------
//- cancelEditOrder zaniechanie edycji zamówienia
//------------------
function cancelEditOrder()
{
  window.document.history_list.action2.value = "details";
  window.document.history_list.submit();
}

//------------------
//- deleteOrder usunięcie zamówienia
//------------------
function showDeviceList()
{
//  window.document.history_list.action1.value = "delete_order";
//  window.document.history_list.submit();
}


//------------------
//- doneOrder usunięcie zamówienia
//------------------
function doneOrder()
{
 if (confirm('Jesteś pewien, że chcesz kontynuować akcję?')) 
 {
        window.document.history_list.action1.value = "done_order";
   window.document.history_list.submit();
 }
}

//------------------
//- realizeOrder przyjęcie zamówienia do realizacji
//------------------
function realizeOrder()
{
 if (confirm('Jesteś pewien, że chcesz zatwierdzić to zamówienie?')) 
 {
        window.document.history_list.action1.value = "realize_order";
   window.document.history_list.submit();
 }
}


//--------------
//- setDevice
//--------------
function setDevice()
{
        window.document.formMain.itemID.value                 = window.document.formMain.selectDevice.value;
         window.document.formMain.payment.value         = window.document.formMain.editPaymentLimit.value;        
        window.document.formMain.expertise.value         = window.document.formMain.editExpertise.value;
   window.document.formMain.orderNumber.value         = window.document.formMain.editOrderNumber.value;
   window.document.formMain.kindRepair.value         = window.document.formMain.selectRepair.value;
  

        window.document.formMain.submit();
}
         
function setDeviceParam(serialNumber,equipment,failure,name)
{
   window.document.formMain.name.value                         = name;        
        window.document.formMain.serialNumber.value         = serialNumber;        
        window.document.formMain.equipment.value                 = equipment;
        window.document.formMain.failure.value                 = failure;
 
}
   
   /**
   *  drukowanie dokumentu
   */
   function printOrderDocument() 
   {
      windowParent = window.parent.print2;
      windowParent.document.formMain.actionPrint.value = 'print';
        
      windowParent.document.formMain.name.value          = window.document.formMain.name.value;        
      windowParent.document.formMain.serialNumber.value  = window.document.formMain.serialNumber.value;        
      windowParent.document.formMain.equipment.value     = window.document.formMain.equipment.value;
      windowParent.document.formMain.failure.value       = window.document.formMain.failure.value;
      
      var nIndex = 0;
      var nLastIndex = 0;
      
      var sTempString = window.document.formMain.id_list.value;
      var sIDIndex;
      
      var pElement;
      var pPrintElement;
      
      var sName = '';
      
      while(sTempString!='')
      {
         nLastIndex  = sTempString.indexOf(',');
         if(nLastIndex !=-1)
         {
            sIDIndex =  sTempString.substring(nIndex,nLastIndex);
            sTempString =  sTempString.substring(nLastIndex+1,sTempString.length);
         }
         else
         if(sTempString !='')
         {
            sIDIndex = sTempString;
            sTempString = '';
         }  
         else
            sTempString = '';
         
         sName = 'expertise' + sIDIndex;
         pElement = getMyElement(sName);
         if(typeof(pElement)!='undefined')
         {
            pPrintElement = windowParent.getMyElement(sName);
            if(typeof(pPrintElement)!='undefined')
            {
               pPrintElement.value = pElement.value;
            }
         }
        
         sName = 'payment' + sIDIndex;
         pElement = getMyElement(sName);
         if(typeof(pElement)!='undefined')
         {
            pPrintElement = windowParent.getMyElement(sName);
            if(typeof(pPrintElement)!='undefined')
               pPrintElement.value = pElement.value;
         }
      }
      
      
      windowParent.document.formMain.submit();
      windowParent.focus();
   }

   /**
   *  drukowanie dokumentu
   */
   function printDeviceDocument() 
   {
      windowParent = window.parent.print2;
      windowParent.document.formMain.actionPrint.value = 'print';
        
      windowParent.document.formMain.submit();        
      windowParent.focus();
   }

   /**
   *  wydruk zlecenia
   */
   function printOrder()
   {
      var result = true;
      if(bPrintOrderNumber)
         result = confirm('Zamówienie o tym numerze już istnieje w bazie danych. Kontynuować ?');
      if(result)
         setTimeout('window.print()',10);
   }

//----------------
//- setShowInfo - metoda zatwierdza status wyswietlana danej informacji
//- parametry:
//- boolShow         - status wiadomosci
//- id                                 - identyfikator wiadomosci
//----------------
function setShowInfo(boolShow,id,group)
{
   window.document.formMain.action.value = 'show_info';        
   window.document.formMain.hidshow.value = boolShow;
   window.document.formMain.text_id.value = id;
   window.document.formMain.group.value = group;

   window.document.formMain.submit();
}

function openCalendar(calendar) {
  calendarName=calendar;
  switch(calendarName) {
    case 'data_pobranie':        
      var element = getElement('data_pobranie');
      if (element.value != '' && element.value != '0000-00-00') {
        var dateString = element.value;
        var dateArray = dateString.split("-");
        setCalendar(dateArray[0],dateArray[1],dateArray[2]);
      }        
      rebuildCalendar();
      SetLayerPos('calendarOrder',GetCenterX(200)+320,GetCenterY(200));
      showLayer('calendarOrder');
      break;
    case 'dateTo':        
      var element = getElement('eddateTo');
      if(element.value != '' && element.value != '0000-00-00') {
        var dateString = element.value;
        var dateArray = dateString.split("-");
        setCalendar(dateArray[0],dateArray[1],dateArray[2]);
      }        
      rebuildCalendar();
      SetLayerPos('calendarOrder',GetCenterX(200)+320,GetCenterY(200)+150);
      showLayer('calendarOrder');
      break;
    case 'dateFrom':        
      var element = getElement('eddateFrom');
      if (element.value != '' && element.value != '0000-00-00') {
        var dateString = element.value;
        var dateArray = dateString.split("-");
        setCalendar(dateArray[0],dateArray[1],dateArray[2]);
      }        
      rebuildCalendar();
      SetLayerPos('calendarOrder',GetCenterX(200)+320,GetCenterY(200)+150);
            showLayer('calendarOrder');
      break;
    case 'req_date':        
      var element = getElement('edreq_date');
      if (element.value != '' && element.value != '0000-00-00') {
        var dateString = element.value;
        var dateArray = dateString.split("-");
        setCalendar(dateArray[0],dateArray[1],dateArray[2]);
      }        
      rebuildCalendar();
      SetLayerPos('calendarOrder',GetCenterX(200)+320,GetCenterY(200)+150);
      showLayer('calendarOrder');
      break;
    case 'edUserInsystem':        
      var element = getElement('edUserInsystem');
      if (element.value != '') {
              var dateString = element.value;
        var dateArray = dateString.split("-");
              setCalendar(dateArray[0],dateArray[1],dateArray[2]);
      }        
      rebuildCalendar();
      SetLayerPos('calendarOrder',GetCenterX(200)+320,GetCenterY(200)+150);
      showLayer('calendarOrder');
      break;
  }
}

function OnDateChange()
{
          
         switch(calendarName)
          {
                case 'data_pobranie':
                          setValue('data_pobranie',dateYear+'-'+dateMonth+'-'+dateDay);        
                          break;
                case 'dateTo':
                          setValue('eddateTo',dateYear+'-'+dateMonth+'-'+dateDay);        
                          break;
                case 'dateFrom':
                             setValue('eddateFrom',dateYear+'-'+dateMonth+'-'+dateDay);        
                          break;
                case 'req_date':        
                     setValue('edreq_date',dateYear+'-'+dateMonth+'-'+dateDay);        
                          break;
                case 'edUserInsystem':        
                   setValue('edUserInsystem',dateYear+'-'+dateMonth+'-'+dateDay);        
                          break;
          }

}

function OnTextDateChange()
{
          
         switch(calendarName)
          {
                case 'data_pobranie':
                        var element = getElement('data_pobranie');
                         if(element.value !='')        
                           {
                                  var dateString = element.value;
                                   var dateArray = dateString.split("-");
                                  setCalendar(dateArray[0],dateArray[1],dateArray[2]);
                                setValue('data_pobranie',dateYear+'-'+dateMonth+'-'+dateDay);        
                     }
                        break;
                case 'dateTo':
                        var element = getElement('eddateTo');
                        if(element.value !='')        
                            {
                                   var dateString = element.value;        
                                   var dateArray = dateString.split("-");
                                  setCalendar(dateArray[0],dateArray[1],dateArray[2]);
                             setValue('eddateTo',dateYear+'-'+dateMonth+'-'+dateDay);        
                          }
                        break;
                case 'dateFrom':
                        var element = getElement('eddateFrom');
                        if(element.value !='')        
                            {
                                var dateString = element.value;
                                   var dateArray = dateString.split("-");
                                  setCalendar(dateArray[0],dateArray[1],dateArray[2]);
                                 setValue('eddateFrom',dateYear+'-'+dateMonth+'-'+dateDay);        
                          }
                        break;
                case 'req_date':
                        var element = getElement('edreq_date');
                        if(element.value !='')        
                            {
                                var dateString = element.value;
                                   var dateArray = dateString.split("-");
                                  setCalendar(dateArray[0],dateArray[1],dateArray[2]);
                                setValue('edreq_date',dateYear+'-'+dateMonth+'-'+dateDay);        
                          }
                        break;
                case 'edUserInsystem':        
                          var element = getElement('edUserInsystem');
                        if(element.value !='')
                        {        
                                  var dateString = element.value;
                                   var dateArray = dateString.split("-");
                                  setCalendar(dateArray[0],dateArray[1],dateArray[2]);
                                  setValue('edUserInsystem',dateYear+'-'+dateMonth+'-'+dateDay);        
                          }
                        break;
          }

}

function searchUserInSystem()
{
        window.document.formMain.action2.value='search_param';
          window.document.formMain.hidName.value=window.document.formMain.selectName.value;        
          window.document.formMain.hidFirm.value=window.document.formMain.selectFirm.value;        
          window.document.formMain.hidDate.value=window.document.formMain.edUserInsystem.value;        
        window.document.formMain.submit();
}

function searchDevice()
{
        window.document.formMain.action2.value='search_param';
          window.document.formMain.hidName.value=window.document.formMain.selectName.value;        
          window.document.formMain.hidFirm.value=window.document.formMain.selectFirm.value;        
          window.document.formMain.hidDeviceName.value=window.document.formMain.edDeviceName.value;        
          window.document.formMain.hidSerial.value=window.document.formMain.edSerial.value;        
          window.document.formMain.hidNumber.value=window.document.formMain.edNumber.value;        
        window.document.formMain.submit();
}

function searchModel()
{
        window.document.formMain.action2.value='search_param';
          window.document.formMain.hidModelName.value=window.document.formMain.edModelName.value;        
          window.document.formMain.hidCategory.value=window.document.formMain.selectCategory.value;        
         window.document.formMain.submit();
}

function searchCategory()
{
        window.document.formMain.action2.value='search_param';
          window.document.formMain.hidCategoryName.value=window.document.formMain.edCategoryName.value;        
   window.document.formMain.submit();
}

function overCell(nameElement)
{
  var element = getElement(nameElement);
  element.bgColor = "#EEEEEEFF";
}

function outCell(nameElement)
{
  var element = getElement(nameElement);
  element.bgColor = "#ffffff";
}

function setFocus(nameElement)
{
  var element = getElement(nameElement);
  element.focus();
}

function editCategory(id)
{
   window.document.formMain.action2.value='edit_category';
   window.document.formMain.id.value=id;
   window.document.formMain.order_table.value='category_list';        
   window.document.formMain.submit();
}
 

   /**
   * funkcja wywołuje zapisywanie danych kategorii modelu
   * @param int id identyfikator kategorii modelu
   */
   function saveCategory(id)
   {
      if(id != '')
         window.document.formMain.id.value = id;
      window.document.formMain.action1.value='save_category';
      window.document.formMain.submit();
   }

   /**
   * funkcja wywołuje zapisywanie danych części zamiennych
   * @param int id identyfikator części zamiennej
   */
   function saveReplacement(id)
   {
      if(id != '')
         window.document.formMain.id.value = id;
      if(isNaN(window.document.formMain.edCost.value))
      {
         alert('cena nie jest liczbą');
         return;
      }
      window.document.formMain.action1.value='save_replacement';
      window.document.formMain.submit();
   }

//-------------------
//- editModel edycja modelu
//- parametry:
//- id - identyfikator modelu
//-------------------
function editModel(id)
{
   window.document.formMain.action2.value='edit_model';
   window.document.formMain.id.value=id;
   window.document.formMain.order_table.value='add_device';        
   window.document.formMain.submit();
}


   /**
   *  zapisanie danych modelu
   *  @param int identyfikator modelu
   */
   function saveModel(id)
   {
      if(id != '')
         window.document.formMain.id.value = id;
      var pElement = getElement('selectCategory');
      
      window.document.formMain.action1.value='save_model';
      window.document.formMain.action2.value='';
      window.document.formMain.category_id.value = pElement.options[pElement.selectedIndex].value;
      window.document.formMain.submit();
   }

function changeCategory()
{
   window.document.formMain.action.value                 = 'selectedCategory';
         window.document.formMain.idCategory.value = window.document.formMain.selectCategory.value;
        window.document.formMain.idModel.value = '-1';
        window.document.formMain.submit(); 
}

function changeModel()
{
         window.document.formMain.idModel.value = window.document.formMain.selectModel.value;
}

   /**
   *  zamknięcie okna edytora wybory urządzenia
   */
   function submitDeviceEditor()
   {
   	 
//   		$('#textDevice',window.opener.frames['mainIFrame'].document).val('aaa');
//   		window.opener.$(window.frames['#mainIFrame'] #textDevice').val('aaa');
   	
//      parentWindow = window.opener.frames['mainIFrame'];
      parentWindow_admin = window.opener.frames['mainIFrame'];
      parentWindow_klient = window.opener;
      
      if(window.document.formMain.idModel.value == '' || window.document.formMain.idModel.value == '-1')
         alert('nie wybrano modelu urządzenia');
      else
      {
         if(parentWindow_klient.document.zamowienie)        
            parentWindow_klient.document.zamowienie.device_name.value = window.document.formMain.idModel.value;
         else
         if(parentWindow_admin.document.history_list)        
            parentWindow_admin.document.history_list.devname.value = window.document.formMain.idModel.value;
         else
         if(parentWindow_admin.document.admin_order){   
            parentWindow_admin.document.admin_order.textDevice.value = window.document.formMain.idModel.value;
         }
         window.close();        
      } 
   }

   /**
   *  otwarcie edytora wyboru modelu urządzenia
   */
   function openDeviceEditor()
   {
      newWindow = window.open('./deviceEditor.php', '','width=220,height=155,top=' + GetCenterY(120,200) + ',left='+ GetCenterX(200,300));
      newWindow.document.close();
   }

   function showMailDetail(sElement)
   {
      var element;
      element = getElement(sElement);
      if(element.style.display == 'none')
      {
         element.style.display = 'block';
      }
      else
      if(element.style.display == 'block')
      {
         element.style.display = 'none';
      }
   }

   /**
   *  obsluga click w menu
   *  @param string hlnk adres 
   */
   function myLink(hlnk)
   { 
      switch(hlnk)
      {
         case 'body.php?action=logout':
            if(confirm('Na pewno chcesz się wylogować ?'))
            {
            //   parent.page_body.location.href=hlnk;
            }
            break;
         default:
            //parent.page_body.location.href=hlnk;
      }
   }

   /**
   *  funkcja pokazuje lub chowa szczegóły naprawy
   *  @param int id itentyfikator
   */
   function showExpertisionOption(id)
   {

      var pDetail = document.getElementById('option_detail'+id);
      if(pDetail == null)
         return;
      if(pDetail.style.display=='block')
         pDetail.style.display='none';
      else
         pDetail.style.display='block';

   }

   /**
   *  funkcja wywołuje usunięcie zaznaczonych modeli
   */
   function deleteModels()
   {
      if (confirm('Jesteś pewien, że chcesz usunąć zaznaczone pozycje. Dane zostaną bezpowrotnie usunięte.')) 
      {
         var pElement ='';
         var sID ='';
         var nRow=0;
         while((pElement = getElement('model_' + nRow))!=null)
         {
            if(pElement.checked == true)
            {
               if(sID == '')
                  sID += pElement.value;
               else
                  sID += ', ' + pElement.value;
            }
            nRow++;
            
 
         }
         var pList = getElement('id_list');
         pList.value = sID;
         document.mainForm.action1.value='delete_models';
         document.mainForm.submit();
      }
   }

   /**
   *  wywowanie otwarcia okna wyboru kategorii modelu
   */
   function windowModelCategory()
   {
      newWindow = window.open('./Popup.inc.php?popup=model_category','','width=200,height=60,top=' + GetCenterY(60,250) + ',left='+ GetCenterX(200,180));
      newWindow.document.close();
   }
 
   function changeModels()
   {
      var pElement ='';
      var sID ='';
      var nRow=0;
      while((pElement = getElement('model_' + nRow))!=null)
      {
         if(pElement.checked == true)
         {
            if(sID == '')
               sID += pElement.value;
            else
               sID += ', ' + pElement.value;
         }
         nRow++;
      }
      
      var pList = getElement('id_list');
      pList.value = sID;
      document.mainForm.action1.value='change_models';
      document.mainForm.submit();
   }
   
   /**
   *  metoda uaktualnia menu administratora, poczas zmian ilości zleceń
   *  @param int nCount1 ilość rekordów
   *  @param int nCount2 ilość rekordów
   *  @param int nCount3 ilość rekordów
   *  @param int nCount4 ilość rekordów
   *  @param int nCount5 ilość rekordów
   *  @param int nCount6 ilość rekordów
   *  @param int nCount7 ilość rekordów
   */
   function refreshAdminMenu(nCount1,nCount2,nCount3,nCount4,nCount5,nCount6,nCount7,nCount8)
   {
      var pWindow = window.parent.menu;
      // sprawdzam czy czasem nie wywołuje odświeżana z poziomu zakładki
      if(pWindow == null)
         pWindow = window.parent.parent.menu;
      
      var pItem1 = pWindow.getElement('menu_1');
      if(pItem1!=null)
         pItem1.innerHTML = '(' + nCount1 + ')';
      var pItem2 = pWindow.getElement('menu_2');
      if(pItem2!=null)
         pItem2.innerHTML = '(' + nCount2 + ')';

      var pItem3 = pWindow.getElement('menu_3');
      if(pItem3!=null)
         pItem3.innerHTML = '(' + nCount3 + ')';

      /*var pItem4 = pWindow.getElement('menu_4');
      if(pItem4!=null)
         pItem4.innerHTML = '(' + nCount4 + ')';
      
      var pItem5 = pWindow.getElement('menu_5');
      if(pItem5!=null)
         pItem5.innerHTML = '(' + nCount5 + ')';
      */
      // nie odswieżamy zrealizowany i odrzuconych 2004.05.07
           
      var pItem6 = pWindow.getElement('menu_6');
      if(pItem6!=null)
         pItem6.innerHTML = '(' + nCount6 + ')';

      var pItem7 = pWindow.getElement('menu_7');
      if(pItem7!=null)
         pItem7.innerHTML = '(' + nCount7 + ')';
     
      var pItem8 = pWindow.getElement('menu_8');
      if(pItem8!=null)
         pItem8.innerHTML = '(' + nCount8 + ')';
   }

   /**
   *  metoda uaktualnia menu zalogowanego użytkownika, poczas zmian ilości zleceń
   *  @param int nCount1 ilość rekordów
   *  @param int nCount2 ilość rekordów
   *  @param int nCount3 ilość rekordów
   *  @param int nCount4 ilość rekordów
   *  @param int nCount5 ilość rekordów
   *  @param int nCount6 ilość rekordów
   *  @param int nCount7 ilość rekordów
   */
   function refreshUserMenu(nCount1,nCount2,nCount3,nCount4,nCount5,nCount6,nCount7,nCount8)
   {
      var pWindow = window.parent.menu;
      if(pWindow == null)
         pWindow = window.parent.parent.menu;
      var pItem1 = pWindow.getElement('menu_1');
      if(pItem1!=null)
         pItem1.innerHTML = '(' + nCount1 + ')';

      var pItem2 = pWindow.getElement('menu_2');
      if(pItem2!=null)
         pItem2.innerHTML = '(' + nCount2 + ')';

      var pItem3 = pWindow.getElement('menu_3');
      if(pItem3!=null)
         pItem3.innerHTML = '(' + nCount3 + ')';

      var pItem4 = pWindow.getElement('menu_4');
      if(pItem4!=null)
         pItem4.innerHTML = '(' + nCount4 + ')';

      var pItem5 = pWindow.getElement('menu_5');
      if(pItem5!=null)
         pItem5.innerHTML = '(' + nCount5 + ')';
      var pItem6 = pWindow.getElement('menu_6');
      
      if(pItem6!=null)
         pItem6.innerHTML = '(' + nCount6 + ')';

      var pItem7 = pWindow.getElement('menu_7');
      if(pItem7!=null)
         pItem7.innerHTML = '(' + nCount7 + ')';

      var pItem8 = pWindow.getElement('menu_8');
      if(pItem8!=null)
         pItem8.innerHTML = '(' + nCount8 + ')';
   }
   
   function openChange()
   {
      var pSelect    = getMyElement('selStatus');
      var pMailing   = getMyElement('cbMailing');
      var pButton    = getMyElement('buttonOK');
      var pText      = getMyElement('textMailing');
      var pLine      = getMyElement('breakLine');
      if(typeof(pSelect)!='undefined')
      {
         if(pSelect.style.display=='block')
         {
            pSelect.style.display='none';
            pButton.style.display='none';
            pMailing.style.display='none';
            pText.style.display='none';
            pLine.style.display='none';
         }
         else
         {
            pSelect.style.display='block'
            pButton.style.display='block';
            pMailing.style.display='inline';
            pText.style.display='inline';
            pLine.style.display='block';
         }
      }
      
      
   }
   
   function changeStatus()
   {
      if(!confirm('Jesteś pewien, że chcesz zmienić status zaznaczonych pozycji. Dane zostaną bezpowrotnie zmienione.'))
         return;
   
      var iItem = 0;
      sIDString ='';
      while(typeof(pElement = getMyElement("order_id_"+ iItem))!='undefined')
      {  
         if(pElement.checked == true)
         {
            if(sIDString == '')
               sIDString += pElement.value 
            else
               sIDString += ', ' + pElement.value 
         }
         iItem++;
      }
      if(sIDString == '')
      {
         alert('Nie zostały zaznaczone żadne zlecenia');
         return;
      }
      window.document.mainForm.id_list.value = sIDString;
      window.document.mainForm.tab_action.value = 'change_status_list_orders';
      window.document.mainForm.submit();
   }
   
   function deleteOrders()
   {
      if(!confirm('Jesteś pewien, że chcesz usunąć zaznaczone pozycje. Dane zostaną bezpowrotnie usunięte.'))
         return;
      var iItem = 0;
      var pElement;
      var bEnd = 0;
      sIDString ='';
      while(typeof(pElement = getMyElement("order_id_"+ iItem))!='undefined')
      {  
         if(pElement.checked == true)
         {
            if(sIDString == '')
               sIDString += pElement.value 
            else
               sIDString += ', ' + pElement.value 
         }
         iItem++;
      }
      if(sIDString == '')
      {
         alert('Nie zostały zaznaczone żadne zlecenia');
         return;
      }
      window.document.mainForm.id_list.value = sIDString;
      window.document.mainForm.tab_action.value = 'delete_list_orders';
      window.document.mainForm.submit();
   }

   function printOrders()
   {
      var iItem = 0;
      var pElement;
      var bEnd = 0;
      sIDString ='';
      while(typeof(pElement = getMyElement("order_id_"+ iItem))!='undefined')
      {  
         if(pElement.checked == true)
         {
            if(sIDString == '')
               sIDString += pElement.value 
            else
               sIDString += ',' + pElement.value 
         }
         iItem++;
      }
      if(sIDString == '')
      {
         alert('Nie zostały zaznaczone żadne zlecenia')
         return;
      }   
      newWindow = window.open('', '','scrollbars=1,resizable=1');
      newWindow.moveTo(0,0);
      if (document.all) 
      {
         newWindow.resizeTo(screen.availWidth,screen.availHeight);
      }
      else 
      if (document.layers||document.getElementById) 
      {
         if (newWindow.outerHeight<screen.availHeight||newWindow.outerWidth<screen.availWidth)
         {
            newWindow.outerHeight = screen.availHeight;
            newWindow.outerWidth = screen.availWidth;
         }  
      }
      newWindow.document.write('<HTML><HEAD><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=iso-8859-2"><TITLE>Drukowanie zlecenia naprawy</TITLE><frameset rows=\'100%,*\' border=0>');
      newWindow.document.write('<FRAME src=\'printOrder.php?id_list='+sIDString+'\' scrolling=yes   name=\'print1\' NORESIZE>');
      newWindow.document.write('<FRAME src=\'printOrder.php?id_list='+sIDString+'\' scrolling=no border=0 frameborder=0 framespacing=0 bordercolor=white name=\'print2\' NORESIZE>');
      newWindow.document.write('</FRAMESET></HEAD><BODY></BODY></HTML>');
      
   }