// const
var _ZOrderLines          =   100;
    _ZOderSelectBox       =  1000;
    _ZOrderOpener         = 10000;
    _ZOrderDynamicWindow  = 20000;
function _ZOrderDynamicWindowInc() { return ++_ZOrderDynamicWindow; }


// variables
var TypePlateImages,TypePlateImagesNo,TypePlateImagesName,
    Opener1,Opener2,Opener3,Opener4,
    SPCSelectBoxId,SPCSymbolsRePositionLast;

// general handlers
function SPCMasterLoad() {
  var aPosA,aPosB,elem;

  // already-loaded-check
  if (SPCSelectBoxId) return;

  // order-iframe
  xDKIExternalGET('SPCOrderExternalGET','empty.html','SPCOrderExternalGETLoaded()');
  SPCOrderedTimeOut = 0;
  SPCAfterOrderDialog_Top = 250;
  SPCOrderedPageType = 'Master';

  // init custom controls
  xDKIInitCustomControls();

  // reset
  SPCSymbolsRePositionLast = 0;
  SPCResetRePosition();

  // TypePlateImages
  TypePlateImagesNo = -1;
  TypePlateImages = new Array(4);
  TypePlateImages[0] = new Image();
  TypePlateImages[0].src = 'images/SPC/TypePlate1.gif';
  TypePlateImages[1] = new Image();
  TypePlateImages[1].src = 'images/SPC/TypePlatePartNo1.gif';
  TypePlateImages[2] = new Image();
  TypePlateImages[2].src = 'images/SPC/TypePlateType1.gif';
  TypePlateImages[3] = new Image();
  TypePlateImages[3].src = 'images/SPC/TypePlateSeriesNo1.gif';

  // symbols: special positioning, symbols should stay at the same position
  xDKIIconUpperRight_Make('closewindow1','closewindow2','closewindow2small');
  xDKIAddEvent(window,'scroll',new Function('','setTimeout("SPCSymbolsRePosition()",10)'));
  xDKIAddEvent(window,'resize',new Function('','setTimeout("SPCSymbolsRePosition()",10)'));
  SPCSymbolsRePosition();

  // Resize
  xDKIAddEvent(window,'resize',new Function('','setTimeout("SPCResetRePosition()",10)'));

  // special for IE 5
  if (xDKIBrowser_IE5()) {
     elemById('search_spare_parts_body_picture').style.width = '197px';
     elemById('TypePlate_Type').style.width = '123px';
     elemById('TypePlate_PartNo').style.width = '123px';
     elemById('Usage').style.width = '123px';
     elemById('search_for_spare_part_div3').style.width = '47px';
     elemById('spc_search_input_seriesno_div').style.width = '129px';
  }

  // advanced search versus simple search
  if (SPCIsAdvancedSearch()) SPCToAdvancedSearch(); else SPCToSimpleSearch();

  // set field 'ScrollBarWidth' for detail
  elemById('ScrollBarWidth').value = xDKIScrollBarWidth();

  // special for long 'in results only'
  if (xDKIExistId('search_for_spare_part_div5')) {
     if (xDKIBrowser_IE()) {
        elemById('search_spare_parts').style.height = '175px';
        elemById('search_spare_parts_body').style.height = '153px';
        elemById('search_spare_parts_usage').style.height = '175px';
        elemById('search_spare_parts_usage_body').style.height = '153px';
     }
     else {
        elemById('search_spare_parts').style.height = '169px';
        elemById('search_spare_parts_body').style.height = '147px';
        elemById('search_spare_parts_usage').style.height = '169px';
        elemById('search_spare_parts_usage_body').style.height = '147px';
        elemById('SPCReset').style.top = '289px';
     }
  }

  // special for large font
  elem = elemById('AInResultsOnly');
  aPosA = xDKIPositionId('AInResultsOnly');
  aPosB = xDKIPositionId('SPCReset');
  if ((aPosA[0]+elem.offsetWidth > aPosB[0]) && (aPosA[1]+elem.offsetHeight > aPosB[1]))
     elemById('search_for_spare_part_div').style.paddingTop = '13px';

  // set focus
  SPCStandardFocus();

  // search result: view
  SPCSelectBoxId = xDKISelectBox_Create('search_result_view',
                                        valueById('search_result_view_text'),
                                        valueById('SearchResultViewOld'),
                                        '64px','17px','18px','2px','2px',_ZOderSelectBox,
                                        '#ffffff','#f0f0f0','1px','solid','#808080','#f6f6f6',
                                        'arrowdown','0.85em','center',
                                        'SPCMasterRefresh','SearchResultView',0,null,
                                        '10','20','50','100');
}
function SPCSymbolsRePosition() {
  var t;
  t = new Date().getTime();
  if ((t - SPCSymbolsRePositionLast) < 500) return;
  xDKIIconUpperRight_Resize('closewindow1',26,20,xDKIWindowScrollLeft());
  SPCSymbolsRePositionLast = t;
}
function SPCResetRePosition() {
  var aParent,aPos;
  with (elemById('SPCReset').style) {
       aParent = elemById('search_spare_parts');
       aPos = xDKIPosition(aParent);
       position = 'absolute';
       left = px(aPos[0]+aParent.offsetWidth-16);
       top = px(aPos[1]+aParent.offsetHeight-18);
       display = 'block';
  }
}


// reset
function SPCReset() {
  var aTr,aTd;
  elemById('SearchAdvanced').value = '';
  elemById('SearchUsage').value = '';
  elemById('LastWasSearchUsage').value = '';
  elemById('OrderP').value = '';
  elemById('OrderT').value = '';
  elemById('PageNo').value = '';
  elemById('NumberOfPages').value = '';
  elemById('RefreshMode').value = '';
  elemById('HistPartNo').value = '';
  elemById('HistType').value = '';
  elemById('HistSeriesNo').value = '';
  elemById('HistUsage').value = '';

  elemById('RBTypePlate').value = '';
  elemById('TypePlate_Type').value = '';
  elemById('TypePlate_PartNo').value = '';
  elemById('TypePlate_SeriesNo').value = '';
  elemById('CBInResultsOnly').value = '0';
  xDKISelectCBEx('InResultsOnly','checkbox');

  elemById('Usage').value = '';

  xDKIInitCustomControls();
  SPCToSimpleSearch(false);

  if (xDKIExistId('search_result_count')) elemById('search_result_count').innerHTML = '';
  with (elemById('result_table')) {
       while (rows.length > 1) deleteRow(rows.length-1);
       aTr = insertRow(1);
       aTd = aTr.insertCell(0);
       aTd.className = 'result1';
       aTd = aTr.insertCell(1);
       aTd.className = 'result2';
       aTd = aTr.insertCell(2);
       aTd.className = 'result3';
       aTd = aTr.insertCell(3);
       aTd.className = 'result4a';
       aTd = aTr.insertCell(4);
       aTd.className = 'result4b';
       aTd = aTr.insertCell(5);
       aTd.className = 'result5';
  }
  if (xDKIExistId('SPCFooter')) elemById('SPCFooter').innerHTML = '';
  elemById('SortField1').src='images/SortUp_Disabled.gif';
  elemById('SortField2').src='images/SortUp_Disabled.gif';
  elemById('SearchResultViewOld').value = '10';
  elemById('SearchResultView').value = '10';
  elemById(SPCSelectBoxId[0]).innerHTML = '10';

  xDKIDynamicMoveableWindow_CloseAll();
}


// typeplate
function SPCTypePlate_TypeChanged(e) {
  e = (e) ? e : ((event) ? event : null);
  if (((e && (!xDKIControlChar(e.keyCode) || xDKICtrlPressed(e,['V']) || xDKIShiftPressed(e,[45])))) &&
     (valueById('RBTypePlate') != '2'))
     xDKISelectRBEx('RBTypePlate','radio',2,2);
}
function SPCTypePlate_PartNoChanged(e) {
  e = (e) ? e : ((event) ? event : null);
  if (((e && (!xDKIControlChar(e.keyCode) || xDKICtrlPressed(e,['V']) || xDKIShiftPressed(e,[45])))) &&
     ((valueById('RBTypePlate') != '') && (valueById('RBTypePlate') != '1')))
     xDKISelectRBEx('RBTypePlate','radio',1,2);
}
function SPCSetImage(aName,aNo) {
  var aParent,aPos1,aPos2,e,h1,h2,l1,l2,l3;

  if (!TypePlateImages) return;

  if (TypePlateImagesNo == aNo) return;
  if (!SPCIsAdvancedSearch() && (aNo==2)) return;
  TypePlateImagesNo = aNo;
  TypePlateImagesName = aName;

  elemById(aName).src = TypePlateImages[aNo].src;

  aParent = elemById('search_spare_parts_body');
  l1 = xDKIMakeOrGetALine('line1',_ZOrderLines,aParent);
  l2 = xDKIMakeOrGetALine('line2',_ZOrderLines,aParent);
  l3 = xDKIMakeOrGetALine('line3',_ZOrderLines,aParent);
  switch(aNo) {
    case 0: l1.style.display = 'none';
            l2.style.display = 'none';
            l3.style.display = 'none';
            xDKIChangeClassNameId('RBTypePlate1_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            xDKIChangeClassNameId('RBTypePlate2_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            xDKIChangeClassNameId('RBTypePlate3_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            break;

    case 1: aPos1 = xDKIPosition(elemById('TypePlate'));
            e = elemById('RBTypePlate1');
            aPos2 = xDKIPosition(e);
            h1 = parseInt(e.offsetHeight);
            h2 = (aPos1[1]+86)-(aPos2[1]+h1/2)+2;
            with (l1.style) {
                 left = px(aPos1[0]+176);
                 top  = px(aPos1[1]+86);
                 width = px(9);
                 height = px(1);
                 display = 'inline';
            }
            with (l2.style) {
                 left = px(aPos1[0]+184);
                 if (h2 < 0) top = px(aPos1[1]+86); else top = px(aPos1[1]+86-h2);
                 width = px(1);
                 if (h2 < 0) height = px(-h2); else height = px(h2+1);
                 display = 'inline';
            }
            with (l3.style) {
                 if (aPos1[0] > aPos2[0]) left = px(aPos1[0]+184 - (SPCIsAdvancedSearch() ? 8 : 24)); else left = px(aPos1[0]+184);
                 top  = px(aPos1[1]+86-h2);
                 width = px(SPCIsAdvancedSearch() ? 10 : 26);
                 height = px(1);
                 display = 'inline';
            }
            xDKIChangeClassNameId('RBTypePlate1_Text','spc_typeplate_bk_normal','spc_typeplate_bk_selected');
            xDKIChangeClassNameId('RBTypePlate2_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            xDKIChangeClassNameId('RBTypePlate3_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            break;

    case 2: aPos1 = xDKIPosition(elemById('TypePlate'));
            e = elemById('RBTypePlate2');
            aPos2 = xDKIPosition(e);
            h1 = parseInt(e.offsetHeight);
            h2 = (aPos1[1]+72)-(aPos2[1]+h1/2)+2;
            with (l1.style) {
                 left = px(aPos1[0]+176);
                 top  = px(aPos1[1]+72);
                 width = px(9);
                 height = px(1);
                 display = 'inline';
            }
            with (l2.style) {
                 left = px(aPos1[0]+184);
                 if (h2 < 0) top = px(aPos1[1]+72); else top = px(aPos1[1]+72-h2);
                 width = px(1);
                 if (h2 < 0) height = px(-h2); else height = px(h2+1);
                 display = 'inline';
            }
            with (l3.style) {
                 if (aPos1[0] > aPos2[0]) left = px(aPos1[0]+176); else left = px(aPos1[0]+184);
                 top  = px(aPos1[1]+72-h2);
                 width = px(10);
                 height = px(1);
                 display = 'inline';
            }
            xDKIChangeClassNameId('RBTypePlate1_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            xDKIChangeClassNameId('RBTypePlate2_Text','spc_typeplate_bk_normal','spc_typeplate_bk_selected');
            xDKIChangeClassNameId('RBTypePlate3_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            break;

    case 3: aPos1 = xDKIPosition(elemById('TypePlate'));
            e = elemById('RBTypePlate3_Text');
            aPos2 = xDKIPosition(e);
            h1 = parseInt(e.offsetHeight);
            h2 = (aPos1[1]+96)-(aPos2[1]+h1/2)+2;
            with (l1.style) {
                 left = px(aPos1[0]+176);
                 top  = px(aPos1[1]+96);
                 width = px(9);
                 height = px(1);
                 display = 'inline';
            }
            with (l2.style) {
                 left = px(aPos1[0]+184);
                 if (h2 < 0) top = px(aPos1[1]+96); else top = px(aPos1[1]+96-h2);
                 width = px(1);
                 if (h2 < 0) height = px(-h2); else height = px(h2+1);
                 display = 'inline';
            }
            with (l3.style) {
                 if (aPos1[0] > aPos2[0]) left = px(aPos1[0]+160); else left = px(aPos1[0]+184);
                 top  = px(aPos1[1]+96-h2);
                 width = px(26);
                 height = px(1);
                 display = 'inline';
            }
            xDKIChangeClassNameId('RBTypePlate1_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            xDKIChangeClassNameId('RBTypePlate2_Text','spc_typeplate_bk_selected','spc_typeplate_bk_normal');
            xDKIChangeClassNameId('RBTypePlate3_Text','spc_typeplate_bk_normal','spc_typeplate_bk_selected');
            break;

    default: break;
  }
}


// focus
function SPCStandardFocus() {
  if (SPCIsAdvancedSearch() && (valueById('LastWasSearchUsage') != ''))
      elemById('Usage').focus();
  else if ((valueById('TypePlate_SeriesNo') != '') && (valueById('TypePlate_Type') == '') && (valueById('TypePlate_PartNo') == ''))
     elemById('TypePlate_SeriesNo').focus();
  else if (SPCIsAdvancedSearch() && (valueById('RBTypePlate') == '2'))
     xDKIFocusId('TypePlate_Type');
  else
     xDKIFocusId('TypePlate_PartNo');
}


// advanced search versus simple search
function SPCIsAdvancedSearch() {
  return valueById('SearchAdvanced');
}
function SPCAdvancedToggle() {
  if (SPCIsAdvancedSearch()) SPCToSimpleSearch(true);
  else SPCToAdvancedSearch(true);
}
function SPCToAdvancedSearch(aNotFromLoad) {
  elemById('SearchAdvanced').value = '1';

  if (aNotFromLoad) {
     xDKIOpener_Open('search_spare_parts_usage','opener1','Opener1','#ffffff',15,_ZOrderOpener,10);
     xDKIOpener_Open('AInResultsOnly','opener2','Opener2','#f6f6f6',6,_ZOrderOpener,10);
     xDKIOpener_Open('search_for_spare_part_div5','opener4','Opener4','#f6f6f6',6,_ZOrderOpener,10);
     xDKIOpener_Open('advanced_search_header','opener3','Opener3','#ffffff',6,_ZOrderOpener,10);
  }

  xDKIChangeClassNameId('search_spare_parts_body_input_type','hidden','visible');
  xDKIChangeClassNameId('TypePlate_Type','hidden_ex','visible_exi');
  xDKIChangeClassNameId('to_advanced_search','visible_exi','hidden_ex');
  xDKIChangeClassNameId('to_simple_search','hidden_ex','visible_exi');
  xDKIChangeClassNameId('AInResultsOnly','hidden','visible');
  xDKIChangeClassNameId('search_for_spare_part_div5','hidden','visible');
  xDKIChangeClassNameId('advanced_search_header','hidden','visible');
  if (valueById('RBTypePlate') == '2') {
     xDKIChangeClassNameId('RBTypePlate2','radio_empty','radio_on');
     xDKIChangeClassNameId('RBTypePlate2','radio_off','radio_on');
     if (xDKIChangeClassNameId('RBTypePlate1','radio_empty','radio_off')) xDKIEnableAnchorId('RBTypePlate1','#');
     xDKIChangeClassNameId('RBTypePlate1','radio_on','radio_off');
  }
  if ((valueById('RBTypePlate') == '') || (valueById('RBTypePlate') == '1')) {
     xDKIChangeClassNameId('RBTypePlate2','radio_empty','radio_off');
     xDKIChangeClassNameId('RBTypePlate2','radio_on','radio_off');
     if (xDKIChangeClassNameId('RBTypePlate1','radio_empty','radio_on')) xDKIEnableAnchorId('RBTypePlate1','#');
     xDKIChangeClassNameId('RBTypePlate1','radio_off','radio_on');
  }
  xDKIShowId('search_spare_parts_usage');
  SPCStandardFocus();
}
function SPCToSimpleSearch(aNotFromLoad) {
  if (aNotFromLoad) {
     xDKIOpener_CloseInit(xDKIExistId('search_for_spare_part_div5') ? 4 : 3,'SPCToSimpleSearch1()');
     xDKIOpener_Close('search_spare_parts_usage','opener1','Opener1','#ffffff',15,_ZOrderOpener,10);
     xDKIOpener_Close('AInResultsOnly','opener2','Opener2','#f6f6f6',6,_ZOrderOpener,10);
     xDKIOpener_Close('search_for_spare_part_div5','opener4','Opener4','#f6f6f6',6,_ZOrderOpener,10);
     xDKIOpener_Close('advanced_search_header','opener3','Opener3','#ffffff',6,_ZOrderOpener,10);
  }
  else SPCToSimpleSearch1();
}
function SPCToSimpleSearch1() {
  elemById('SearchAdvanced').value = '';
  xDKIChangeClassNameId('search_spare_parts_body_input_type','visible','hidden');
  xDKIChangeClassNameId('TypePlate_Type','visible_exi','hidden_ex');
  xDKIChangeClassNameId('to_advanced_search','hidden_ex','visible_exi');
  xDKIChangeClassNameId('to_simple_search','visible_exi','hidden_ex');
  xDKIChangeClassNameId('advanced_search_header','visible','hidden');
  xDKIChangeClassNameId('AInResultsOnly','visible','hidden');
  xDKIChangeClassNameId('search_for_spare_part_div5','visible','hidden');
  xDKIChangeClassNameId('RBTypePlate2','radio_on','radio_empty');
  xDKIChangeClassNameId('RBTypePlate2','radio_off','radio_empty');
  xDKIChangeClassNameId('RBTypePlate1','radio_on','radio_empty');
  xDKIChangeClassNameId('RBTypePlate1','radio_off','radio_empty');
  if (xDKIHasClassNameId('RBTypePlate1','radio_empty')) xDKIDisableAnchorId('RBTypePlate1');
  xDKIHideId('search_spare_parts_usage');
  SPCStandardFocus();
}


// set a cursor for the whole page
function SPCSetCursorWholePage(aCursor) {
  TheDoc().body.style.cursor = aCursor;
  elemById('TypePlate_Type').style.cursor = aCursor;
  elemById('TypePlate_PartNo').style.cursor = aCursor;
  elemById('TypePlate_SeriesNo').style.cursor = aCursor;
  elemById('Usage').style.cursor = aCursor;
}


// master
function SPCMaster(aMode) {
  if (SPCCheckOffline()) return;

  SPCSetCursorWholePage('wait');
  xDKIGotoField1('SPCMasterV1','RefreshMode',aMode);
}
function SPCSearch() {
  if (SPCCheckOffline()) return;

  SPCSetCursorWholePage('wait');
  xDKIGotoField1('SPCMasterV1','LastWasSearchUsage','');
}
function SPCSearchUsage() {
  if (SPCCheckOffline()) return;

  SPCSetCursorWholePage('wait');
  xDKIGotoField1('SPCMasterV1','SearchUsage',1);
}
function SPCMasterRefreshFromGotoPages(aPageNo) {
  elemById('PageNo').value = aPageNo;
  SPCMaster('1');
}
function SPCMasterRefreshFromOrder(aField) {
  if (aField == 1) {
      if (valueById('OrderP') == '1') elemById('OrderP').value = '2';
      else if (valueById('OrderP') == '2') elemById('OrderP').value = '1';
      else { elemById('OrderP').value = -valueById('OrderP');
             elemById('OrderT').value = -valueById('OrderT'); }
  }
  if (aField == 2) {
      if (valueById('OrderT') == '1') elemById('OrderT').value = '2';
      else if (valueById('OrderT') == '2') elemById('OrderT').value = '1';
      else { elemById('OrderT').value = -valueById('OrderT');
             elemById('OrderP').value = -valueById('OrderP'); }
  }
  SPCMaster('2');
}
function SPCMasterRefresh() {
  SPCMaster('3');
}


// order
function SPCMasterOrder(aPartNo,aType,aDesignation,aVariant) {
  var aInnerWidth,aInnerHeight,aSpcOrder,aTable,aTr,aTd,s,s1,s2,s3,sDesignation,
      aQuantityElem,aADiv,aA1Elem,aA2Elem;

  // close possible open messagebox or orderwindow
  xDKIDynamicMoveableWindow_Close('xDKIMessageBox');
  xDKIDynamicMoveableWindow_Close('spc_orderwindow');

  // width / height
  aInnerWidth = 405;
  aInnerHeight = 30+95+30;

  // main-div
  aSpcOrder = TheDoc().createElement('div');
  aSpcOrder.className = 'spc_order';

  // table
  aTable = TheDoc().createElement('table');
  with (aTable) {
       setAttribute('border','0');
       setAttribute('cellpadding','0');
       setAttribute('cellspacing','0');
       if (xDKIBrowser_IE6Up()) {
          style.position = 'relative';
          style.top = '-2px';
       }
       else if (!xDKIBrowser_IE()) {
          style.position = 'relative';
          style.left = '2px';
       }
  }
  aSpcOrder.appendChild(aTable);

  // hints
  aTr = aTable.insertRow(0);
  aTd = aTr.insertCell(0);
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  aTd.className = 'detail6 main_tdr spc_detail_bigsel';
  aTd.colSpan = '4';
  aTd.innerHTML = TxtRepairNotPossible;

  // header
  aTr = aTable.insertRow(1);
  aTd = aTr.insertCell(0);
  aTd.className = 'detail2_header main_td_header';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  makeTextNode(aTd,TxtPartNo);

  aTd = aTr.insertCell(1);
  aTd.className = 'detail3_header main_td_header';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  aTd.innerHTML = '<div>'+TxtType+'<div /><div>'+TxtDesignation+'</div>';

  aTd = aTr.insertCell(2);
  aTd.className = 'detail4_header main_td_header';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  makeTextNode(aTd,TxtQuantity);

  aTd = aTr.insertCell(3);
  aTd.className = 'detail5_header main_tdr_header';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  makeTextNode(aTd,TxtQuantityUnit);

  // data
  aTr = aTable.insertRow(2);
  // partno
  aTd = aTr.insertCell(0);
  aTd.className = 'detail2 detail2_order main_td spc_detail_bigsel';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  aTd.id = 'PartNoOrder';
  aTd.innerHTML = aPartNo;
  // designation
  aTd = aTr.insertCell(1);
  aTd.className = 'detail3 main_td spc_detail_bigsel';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  aTd.id = 'DesignationOrder';
  if (aType != '')        s1 = '1'; else s1 = '0';
  if (aDesignation != '') s2 = '1'; else s2 = '0';
  if (aVariant != '')     s3 = '1'; else s3 = '0';
  s = s1+s2+s3;
  switch(s) {
    case '000': sDesignation = '';
                break;
    case '100': sDesignation = '<div>'+aType+'</div><div>&nbsp;</div>';
                break;
    case '010': sDesignation = '<div>'+aDesignation+'</div><div>&nbsp;</div>';
                break;
    case '110': sDesignation = '<div>'+aType+'</div><div>'+aDesignation+'</div>';
                break;
    case '001': sDesignation = '<div>'+aVariant+'</div><div>&nbsp;</div>';
                break;
    case '101': sDesignation = '<div>'+aType+'</div><div>'+aVariant+'</div>';
                break;
    case '011': sDesignation = '<div>'+aDesignation+'</div><div>'+aVariant+'</div>';
                break;
    case '111': sDesignation = '<div>'+aType+'</div><div>'+aDesignation+'</div><div>'+aVariant+'</div>';
                break;
  }
  aTd.innerHTML = sDesignation;
  // quantity
  aTd = aTr.insertCell(2);
  aTd.className = 'detail4 main_td spc_detail_bigsel';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  aQuantityElem = TheDoc().createElement('input');
  with (aQuantityElem) {
       id = 'QuantityOrder';
       type = 'text';
       className = 'edit17';
       style.width = '25px';
       style.textAlign = 'center';
       value = '1';
  }
  xDKIAddEvent(aQuantityElem,'keypress',new Function ('e','if (!e) e = window.event;if (xDKINewLinePressed(e)) SPCOrder()'));
  aTd.appendChild(aQuantityElem);
  // quantity unit
  aTd = aTr.insertCell(3);
  aTd.className = 'detail5 main_tdr spc_detail_bigsel';
  if (xDKIBrowser_IE()) aTd.style.borderWidth = '0px';
  aTd.id = 'QuantityUnitOrder';
  aTd.innerHTML = SPCOrderQuantityUnit(aPartNo);

  // cancel-buttons
  aADiv = TheDoc().createElement('div');
  aADiv.className = 'spaceabove10';
  aSpcOrder.appendChild(aADiv);
  aA1Elem = TheDoc().createElement('a');
  with (aA1Elem) {
       className = 'spc_order1 left nohint arrow2right_layoutleft link';
       href = 'javascript:SPCOrderClose()';
  }
  makeTextNode(aA1Elem,TxtClose);
  aADiv.appendChild(aA1Elem);

  // order-buttons
  aA2Elem = TheDoc().createElement('a');
  with (aA2Elem) {
       className = 'spc_order2 right nohint arrow2right_layoutleft link';
       href = 'javascript:SPCOrder()';
  }
  makeTextNode(aA2Elem,TxtAddToBasket);
  aADiv.appendChild(aA2Elem);

  // show
  xDKIDynamicMoveableWindow_Show('spc_orderwindow',aSpcOrder,null,'',
                                 xDKIMessageBoxPosition(aInnerWidth),240,aInnerWidth,aInnerHeight,
                                 _ZOrderDynamicWindowInc(),'_ZOrderDynamicWindowInc()',
                                 false,false,'#ffffff','SPCOrderClose');
}
function SPCOrder() {
  // check offline
  if (SPCCheckOffline()) return;

  // check, if already ordering
  if (xDKIIsWaiting()) return;

  // partno
  SPCOrderedPartNo = getNumberOutOfTagId('PartNoOrder');
  if (SPCOrderedPartNo.length == 0) return;

  // designation
  SPCOrderedDesignation = elemById('DesignationOrder').innerHTML;

  // quantity
  SPCOrderedQuantity = valueById('QuantityOrder');
  if ( (SPCOrderedQuantity.length <= 0) || (SPCOrderedQuantity.length > 5) || (/[^0-9]/).test(SPCOrderedQuantity) ||
       (SPCOrderedQuantity == '0') || (SPCOrderedQuantity == '00') || (SPCOrderedQuantity == '000') || (SPCOrderedQuantity == '0000') ) {
     xDKIMessageBox('',TxtIncorrectQuantity,TxtOk,xDKIMessageBoxPosition(200),270,200,85,
                    _ZOrderDynamicWindowInc(),'_ZOrderDynamicWindowInc()',
                    'a=function() {xDKIFocusId("QuantityOrder");};a');
     return;
  }

  // quantityunit
  SPCOrderedQuantityUnit = elemById('QuantityUnitOrder').innerHTML;

  // order
  SPCExternalGET('SPCOrderExternalGET',SPCOrderURL(SPCOrderedPartNo,SPCOrderedQuantity));
}
function SPCOrderBeforeMessageBox() {
}
function SPCOrderAfterMessageBox() {
}
function SPCOrderClose() {
  xDKIDynamicMoveableWindow_Close('spc_orderwindow');
}
function SPCOrderQuantityUnit(aPartNo) {
  var i;
  for (i = 0;i <= PartNos.length-1;i++)
      if (PartNos[i] == aPartNo) return QuantityUnits[i];
  return '';
}


// detail
function SPCDetail(aPartNo,aBOM,aDrawing,aType,aDesignation,aVariant,aFromSerialNo,aToSerialNo,aFromSerialNo_,aToSerialNo_) {
  var w,h,aID;

  if (SPCCheckOffline()) return;

  if (aDrawing.toLowerCase().indexOf('.pdf') >= 0) {
     xDKICall('SPCLogging',document.URL,'SPCDatV1',valueById('xDKI_SessionID'),valueById('xDKI_Language'),
              'WantedOperation','LoggingPDFOLD','Drawing',aDrawing);
     window.open('data/SPC/'+ActualSet+'/PDF/'+aDrawing,'');
  }   
  else {
     aID = xDKIRandomString(20);
     w = window.open('',aID);
     h = xDKIWindowHeight(w,-1);
     if (h < 0) h = xDKIWindowHeight();
     document.forms['Form-A2'].target = aID;
     xDKISubmitField1_Form('Form-A2',
                           'xDKI_Receiver','SPCDetailV1',
                           'xDKI_SessionID',valueById('xDKI_SessionID'),
                           'xDKI_Language',valueById('xDKI_Language'),
                           'PartNo',aPartNo,'BOM',aBOM,'Drawing',aDrawing,
                           'Type',aType,'Designation',aDesignation,'Variant',aVariant,
                           'FromSerialNo',aFromSerialNo,'ToSerialNo',aToSerialNo,
                           'FromSerialNo_',aFromSerialNo_,'ToSerialNo_',aToSerialNo_,
                           'ScrollBarWidth',valueById('ScrollBarWidth'),
                           'Usage',valueById('LastWasSearchUsage') ? valueById('Usage') : '' ,
                           'OrderNotAllowed',valueById('OrderNotAllowed'),
                           'WindowHeight',h);
  }
}


// contact to
function SPCContactTo(aPartNo,aType,aDesignation,aVariant,aFromSerialNo,aToSerialNo,aId) {

  function _Repl(c) {
    return c.replace(/%partno%/gi,aPartNo).replace(/%type%/gi,aType).replace(/%designation%/gi,aDesignation).replace(/%variant%/gi,aVariant).replace(/%fromserialno%/gi,aFromSerialNo).replace(/%toserialno%/gi,aToSerialNo);
  }

  var aPosition;
  if (xDKIExist(elemById('xDKIMessageBox'))) xDKIDynamicMoveableWindow_Close('xDKIMessageBox');
  if (SPCCheckOffline()) return;
  aPosition = xDKIPositionId(aId);
  xDKIMessageBoxUrgent('',_Repl(unescape(valueById('ContactTo'))),'',aPosition[0]-200,aPosition[1]+20,300,'',
                       _ZOrderDynamicWindowInc(),'_ZOrderDynamicWindowInc()','','#0099d8',true,[0,4,1]);
}


// photo
function SPCShowPhoto(aPic,aImg,aAImg,aCaption,w,h) {
  if (SPCCheckOffline()) return;
  xDKIShowPhoto(aPic,aImg,aAImg,aCaption,_ZOrderDynamicWindowInc(),'_ZOrderDynamicWindowInc()',43,17,w,h);
}


// helppage
function SPCShowHelp(aCaption) {
  var aMainDiv,
      aParent,aParentPosition,
      aPictureElement,aPictureElementPosition,aPictureElementWidth,
      aPartNoElement,aPartNoElementPosition,aPartNoElementHeight,
      aSeriesNoElement,aSeriesNoElementPosition,aSeriesNoElementHeight,
      aTypeCodeElement,aTypeCodeElementPosition,aTypeCodeElementHeight;

  if (SPCCheckOffline()) return;
  aMainDiv = xDKIDynamicMoveableWindow_Show('spc_helpwindow',elemById('spc_help').cloneNode(true),null,aCaption,
                                            200,25,467,-1,_ZOrderDynamicWindowInc(),'_ZOrderDynamicWindowInc()',
                                            true);

  // draw additional lines
  if (aMainDiv) {
     aParent = elemById('spc_helpwindow');
     aParentPosition = xDKIPosition(aParent);

     aPictureElement = sonElemById('TypePlateHelp',aParent);
     aPictureElementPosition = xDKIPosition(aPictureElement);
     aPictureElementWidth = 137;
     aPictureElementPosition[0] += (aPictureElement.offsetWidth-aPictureElementWidth)/2-aParentPosition[0];
     aPictureElementPosition[1] -= aParentPosition[1];

     aPartNoElement = sonElemById('TypePlateHelp_PartNo',aParent);
     aPartNoElementPosition = xDKIPosition(aPartNoElement);
     aPartNoElementPosition[0] -= aParentPosition[0];
     aPartNoElementPosition[1] -= aParentPosition[1];
     aPartNoElementHeight = parseInt(aPartNoElement.offsetHeight);

     aSeriesNoElement = sonElemById('TypePlateHelp_SeriesNo',aParent);
     aSeriesNoElementPosition = xDKIPosition(aSeriesNoElement);
     aSeriesNoElementPosition[0] -= aParentPosition[0];
     aSeriesNoElementPosition[1] -= aParentPosition[1];
     aSeriesNoElementHeight = parseInt(aSeriesNoElement.offsetHeight);

     aTypeCodeElement = sonElemById('TypePlateHelp_TypeCode',aParent);
     aTypeCodeElementPosition = xDKIPosition(aTypeCodeElement);
     aTypeCodeElementPosition[0] -= aParentPosition[0];
     aTypeCodeElementPosition[1] -= aParentPosition[1];
     aTypeCodeElementHeight = parseInt(aTypeCodeElement.offsetHeight);

     // PartNo-line
     xDKILine(aMainDiv,aPictureElementPosition[0]-10,aPictureElementPosition[1]+74,11,1,_ZOrderDynamicWindow);
     xDKILine(aMainDiv,aPictureElementPosition[0]-10,aPictureElementPosition[1]+74,1,
                       aPartNoElementPosition[1]+(aPartNoElementHeight/2)-(aPictureElementPosition[1]+74),_ZOrderDynamicWindow);
     xDKILine(aMainDiv,aPictureElementPosition[0]-10,aPartNoElementPosition[1]+(aPartNoElementHeight/2),9,1,_ZOrderDynamicWindow);

     // SeriesNo-line
     xDKILine(aMainDiv,aPictureElementPosition[0]+aPictureElementWidth,
                       aPictureElementPosition[1]+74,12,1,_ZOrderDynamicWindow);
     xDKILine(aMainDiv,aPictureElementPosition[0]+aPictureElementWidth+12,aPictureElementPosition[1]+74,1,
                       aSeriesNoElementPosition[1]+(aSeriesNoElementHeight/2)-(aPictureElementPosition[1]+74),_ZOrderDynamicWindow);
     xDKILine(aMainDiv,aPictureElementPosition[0]+aPictureElementWidth+3,
                       aSeriesNoElementPosition[1]+(aSeriesNoElementHeight/2),10,1,_ZOrderDynamicWindow);
     // TypeCode-line
     xDKILine(aMainDiv,aPictureElementPosition[0]+aPictureElementWidth,
                       aPictureElementPosition[1]+57,22,1,_ZOrderDynamicWindow);
     xDKILine(aMainDiv,aPictureElementPosition[0]+aPictureElementWidth+22,aPictureElementPosition[1]+57,1,
                       aTypeCodeElementPosition[1]+(aTypeCodeElementHeight/2)-(aPictureElementPosition[1]+57),_ZOrderDynamicWindow);
     xDKILine(aMainDiv,aPictureElementPosition[0]+aPictureElementWidth+3,
                       aTypeCodeElementPosition[1]+(aTypeCodeElementHeight/2),20,1,_ZOrderDynamicWindow);
  }
}
