﻿function GWErowover(pObj) {
    if (pObj.className != 'PopupGridViewEmptyRowStyle')
        pObj.className = 'PopupGridViewHoverRowStyle';
}
function GWErowout(pObj,pTyp) {
    if (pObj.className != 'PopupGridViewEmptyRowStyle')
        pObj.className = pTyp == 0 ? 'PopupGridViewRowStyle' : 'PopupGridViewARowStyle';
}



function GWEonselect(pRow,pId,pType)
{
    window['PCE_'+pId+'_ACTIV']=false;
    if (pRow.className != 'PopupGridViewEmptyRowStyle') {
        var f = window['PCE_'+pId+'_FieldsArray'];
        var c = window['PCE_'+pId+'_ColumnsArray'];
        for (var i=0; i < f.length& i < pRow.cells.length; i++) { 
          var targetel=$get(f[i]);targetel.value='';
    }
    for (var i=0; i < f.length& i < pRow.cells.length; i++) { 
      var targetel=$get(f[i]);
      var leer='';
      var fvalue=pRow.cells[parseInt(c[i])].innerText;
      if (fvalue == '') fvalue=pRow.cells[parseInt(c[i])].innerHTML;
      if(targetel.value>'')leer=' ';
      if (pType == 1 & i > 0) {
          if (fvalue.length < 7) fvalue = '';
          targetel.style.color = fvalue;
          targetel.style.backgroundColor = fvalue;
      } else if (pType == 2) {
          targetel.value += leer + fvalue.replace('.', '');
      } else {
          targetel.value += leer + fvalue;
      }
    }
    for (var i=0; i < f.length& i < pRow.cells.length; i++) { 
      var targetel=$get(f[i]);
      if(targetel.onchange!=null){
      try{ if(HasPageValidator(targetel.id) == false) targetel.onchange();} catch(e){targetel.onchange();}}

   }
   if (typeof (window['PCE_' + pId + '_OnAfterSelect']) != 'undefined') window['PCE_' + pId + '_OnAfterSelect'](pRow.cells[0].innerText);
   $find(IDPRAEFIX + 'PCE_' + pId).hidePopup();
  }
}

function GWEfilterrequestobj() {
    this.value = false;
}
function GWEfilterobj() {
    this.value = new Array();
}

function GWEonfilterfield(pTextbox, pLoschen, pId, w, pFullname, FilterRequest,Filter) {
    var o = $get(IDPRAEFIX+pId);
    var odel = null;
    if (w > 0)
        odel=$get(IDPRAEFIX + pId + '_del');
    if (pTextbox) {
        if (o.id == pTextbox.id) {
            if (pLoschen)
                o.value = '';
            FilterRequest.value = true;
        }
    }
    if (pTextbox == null) {
        if (pLoschen) {
            o.value = ''; 
            FilterRequest.value = true; 
        } 
    } else {
        try { $get(pTextbox.id + '_del').parentNode.style.display = pTextbox.value > '' ? '' : 'none'; } catch (e) { }
    }
    if ( (o.value != '') && (o.value != ' ') ) {
        if (odel) 
            odel.src = '../Images/Icons/Delete.ICO';
        Filter.value.push(pFullname);
        Filter.value.push(o.value);
    } else {
        o.value = '';
        if (odel) 
            odel.src = '../Images/Icons/DeletePassiv.ICO';
    }
}

function GWEonfilterend(pTextbox, pLoschen, pId, pPaging, Relation, Selectarg, FilterRequest, Filter) {
    var Sort = '';
    var FirstSort = $get(IDPRAEFIX+'PCE_'+pId+'_SORT');
    if (FirstSort) 
        Sort = FirstSort.value;
    var intFirstRow = 1;
    if (pPaging) {
         if ( pTextbox==null) FilterRequest.value = true;
          var FirstRow = $get(IDPRAEFIX+'PCE_'+pId+'_FIRSTROW');
          var CurrentPage = $get(IDPRAEFIX+'PCE_'+pId+'_CURRENTPAGE');
          var PageCount = $get(IDPRAEFIX+'PCE_'+pId+'_PAGECOUNT');
          var RowCount = $get(IDPRAEFIX+'PCE_'+pId+'_ROWCOUNT');

          var intFirstRow = parseInt(FirstRow.value);
          var intCurrentPage = parseInt(CurrentPage.innerHTML);
          var intPageCount = parseInt(PageCount.innerHTML);
          var intRowCount = parseInt(RowCount.innerHTML);

          var NextPage = $get(IDPRAEFIX+'PCE_'+pId+'_NEXTPAGE');
          var PrevPage = $get(IDPRAEFIX+'PCE_'+pId+'_PREVPAGE');
          var LastPage = $get(IDPRAEFIX+'PCE_'+pId+'_LASTPAGE');
          var FirstPage = $get(IDPRAEFIX+'PCE_'+pId+'_FIRSTPAGE');

          if (pTextbox)if (pTextbox.id == NextPage.id) { 
            if (intCurrentPage < intPageCount) {
              intFirstRow += window['PCE_'+ pId + '_Maxrows'];
              intCurrentPage ++;
            }
          }
          if (pTextbox)if (pTextbox.id == PrevPage.id) { 
            if (intCurrentPage > 1) {
              intFirstRow -= window['PCE_'+ pId + '_Maxrows'];
              intCurrentPage --;
            }
          }
          if (pTextbox)if (pTextbox.id == LastPage.id) { 
            if (intCurrentPage < intPageCount) {
              intFirstRow = parseInt( (intPageCount-1) * window['PCE_'+ pId + '_Maxrows'] + 1);
              intCurrentPage = intPageCount;
            }
          }
          if (pTextbox)if (pTextbox.id ==FirstPage.id) { 
            if (intCurrentPage > 1) {
              intFirstRow = 1;
              intCurrentPage = 1;
            }
          }
          CurrentPage.innerHTML = intCurrentPage;
          FirstRow.value = intFirstRow;

          if (FilterRequest.value == true) {
            intFirstRow = 1;
            intCurrentPage = 1;
            FirstRow.value = intFirstRow;
            CurrentPage.innerHTML = intCurrentPage;
            DataService.GetDatatableByRelation2(Relation, Filter.value, Sort, intFirstRow, window['PCE_' + pId + '_Maxrows'], Selectarg, true, window['PCE_'+pId + '_OnFilter' + '_CountResult']);
          }
    }
    DataService.GetDatatableByRelation2(Relation, Filter.value, Sort, intFirstRow, window['PCE_' + pId + '_Maxrows'], Selectarg, false, window['PCE_'+pId + '_OnFilter' + '_Result']);
 }
 function GWEonfiltercount(pId, pDatatable) {
     var CurrentRowCount = $get(IDPRAEFIX+'PCE_'+pId+'_CURRENTROWCOUNT');
     var RowCount = $get(IDPRAEFIX+'PCE_'+pId+'_ROWCOUNT');
     var PageCount = $get(IDPRAEFIX+'PCE_'+pId+'_PAGECOUNT');
     var intRowCount = pDatatable.rows[0]['rowcount'];
     var intPageCount = parseInt(intRowCount / window['PCE_'+ pId + '_Maxrows']);
     if (parseInt(intRowCount % window['PCE_' + pId + '_Maxrows']) > 0)  
        intPageCount ++;
     RowCount.innerHTML = intRowCount;
     PageCount.innerHTML = intPageCount;
     if (intRowCount < window['PCE_'+ pId + '_Maxrows']) 
        CurrentRowCount.innerHTML = intRowCount; 
     else
         CurrentRowCount.innerHTML = window['PCE_' + pId + '_Maxrows'];
 }
 function GWEonfilterresult(pId, pDatatable,pPaging,Rowheight,pHeader,pInfoPanel) {
     var Htmltable = $get('GRV_'+pId);
     var Datatable = Sys.Preview.Data.DataTable.parseFromJson(pDatatable);
     var Datarows = Datatable.get_length();
     var Hiddenrows = window['PCE_'+ pId + '_Maxrows']-Datarows;
     if (pPaging) {
         var CurrentRowCount = $get(IDPRAEFIX+'PCE_'+pId+'_CURRENTROWCOUNT');
         if (Datarows < window['PCE_'+ pId + '_Maxrows']) 
            CurrentRowCount.innerHTML = Datarows; 
         else 
            CurrentRowCount.innerHTML = window['PCE_'+ pId + '_Maxrows'];
     }
     for (var i=0; i < Datarows & i < window['PCE_'+ pId + '_Maxrows']; i++) {
         var r;
         if (pHeader)
                r = Htmltable.rows[i+1];
         else
                r = Htmltable.rows[i];
         if(typeof(r)=='undefined')break;
         for (var c=0; c<r.cells.length&c<pDatatable.columns.length;c++){
             var colName = pDatatable.columns[c].name;
             var colType  = pDatatable.columns[c].dataType;
             var value = pDatatable.rows[i][colName];
             var strvalue = '';
             if (value != null) 
             {
                strvalue = value.toString();
                if (colType == 'Date') strvalue = value.localeFormat('d');
                if (window['PCE_' + pId + '_format'][c] > '0') strvalue = value.localeFormat(window['PCE_' + pId + '_format'][c]);
             }
             var cell = r.cells[c]; cell.title='';
             if (value != null){ 
                  if (strvalue=='')  cell.innerHTML = '';
                  else if(strvalue=='true')cell.innerHTML='<IMG border=0 src=\"../images/KugelGreen.gif\">';
                  else if(strvalue=='false')cell.innerHTML='<IMG border=0 src=\"../images/KugelRed.gif\">';
                  else  {cell.innerHTML = strvalue;cell.title=strvalue;}
             }else {cell.innerHTML = ''; cell.title='';}
         }
         if (i % 2 != 0)  r.className='PopupGridViewARowStyle';
         else r.className='PopupGridViewRowStyle';
     }
     if (pHeader)i++;
     for (; i<Htmltable.rows.length; i++) {
        var r = Htmltable.rows[i];
        r.className='PopupGridViewEmptyRowStyle';
        for (var c=0; c<r.cells.length;c++){
             r.cells[c].innerHTML = ' ';r.cells[c].title=''
        }
     }
     if (pInfoPanel){
         var infop=document.getElementById(IDPRAEFIX+'INF_'+pId);
         if(Datarows==0){ 
            infop.style.visibility='visible';
            infop.style.zIndex='501';
            if(typeof(window[pId+'_nothing'])!='undefined')
                window[pId+'_nothing'](infop); } 
         else {
            infop.style.visibility='';
            infop.style.zIndex='';
         }
     }else
        window['PCE_' + pId + '_onClick_ext']();
}

function GWEonclickext(pId) {
    if(window['PCE_'+pId + '_hasfocus']=='')return;
    var setfocusel = document.getElementById(window['PCE_' + pId + '_hasfocus']);
    if (setfocusel != null) {
        if($get(IDPRAEFIX+pId).readOnly)
            setTimeout('GWEonclickext2("' + pId + '")', 100);
    }

}
function GWEonclickext2(pId){
    if(window['PCE_'+pId+'_ACTIV']==true&$find(IDPRAEFIX+'PCE_'+pId)._popupVisible==true)
        document.getElementById(window['PCE_'+pId+'_hasfocus']).focus();    
}
function GWEonclickcustom(pId, pHeader, pRefresh1) {
    var table = $get('GRV_'+pId);
    if(!table) table = $get(IDPRAEFIX+'GRV_'+pId);
    if(!table) return;
    table.className='PopupGridViewStyle';
    var panel = $get('PNL_'+pId);
    if(!panel) { panel = $get(IDPRAEFIX+'PNL_'+pId); }
    var i=0;
    if (pHeader) {
        table.rows[0].className='PopupGridViewHeaderStyle';
        i=1;
    }
    for (; i < table.rows.length; i++) {
        var r = table.rows[i];
        if (r.className != 'PopupGridViewEmptyRowStyle') {
            if (pHeader) {
                if (i % 2 == 0) r.className = 'PopupGridViewARowStyle';
                else r.className = 'PopupGridViewRowStyle';
            } else {
                if (i % 2 != 0) r.className = 'PopupGridViewARowStyle';
                else r.className = 'PopupGridViewRowStyle';
            }
        }
        if (pRefresh1) {
            if (window['PCE_' + pId + '_' + 'refreshed'] == false) {
                window['PCE_' + pId + '_' + 'refreshed'] = true;
                setTimeout('window["PCE_' + pId + '_OnFilter"]()', 50);
            }
        }
    }
}
function GWEonafterselectres(pDatatable, pId, pFullname, pAppend) {
     var Datatable = Sys.Preview.Data.DataTable.parseFromJson(pDatatable);
     var Datarows = Datatable.get_length();
     if (Datarows == 1) {
         var value = pDatatable.rows[0][pFullname];
         var e = $get(IDPRAEFIX + pId);
        if (pAppend){ 
            if (e.value == '')   
                e.value += value; 
            else 
                e.value += '\\n' + value;
        }else 
            e.value = value;
    }
}

function hideGWE(pId) {
    var pPopupElement = $find(IDPRAEFIX+pId);
    if (pPopupElement)
        if (pPopupElement._popupVisible == true)
            pPopupElement.hidePopup();
}
function triggerGWE(pObj,pId) {
    var pPopupElement = $find(IDPRAEFIX + pId);
    if (pObj.value.length > 1) {
        if (pPopupElement._popupVisible != true)
            pPopupElement.showPopup();
            if(typeof(window[pId+'_OnFilter'])!="undefined")
                window[pId+'_OnFilter']();
    } else {
        if (pPopupElement._popupVisible == true)
            pPopupElement.hidePopup();
    }
}
