//------------------------------------------------------------------------------
// declareation of global variables
//------------------------------------------------------------------------------
var prjArray = new Array();
var prjFoundArrayTemp;
var partserver;
var root;
var ROWSSHOWN = 6;
var prjStart = 0;
var prjShown = ROWSSHOWN;

//------------------------------------------------------------------------------
// cycle through all projects and table rows
//------------------------------------------------------------------------------
function shockSearch(div) {
  deselectAll();
  // declaration of local variables
  prjStart = 0;
  prjShown = ROWSSHOWN;
  
  var param1, param2, param3, param4, param5;
  param1 = param2 = param3 = param4 = param5 = "";
  
  var prjFoundArray = new Array();
  
  // distinction which parameters are searched for
  if(document.getElementById('partA').checked == true || document.getElementById('partB').checked == true) {
    var param5 = document.getElementById("efmass").value;
    var param1 = document.getElementById("gph").value;
    var param2 = document.getElementById("gpst").value;
    var param3 = document.getElementById("mag").value;    
    param3 = param3.replace(/,/, ".");
  } else if(document.getElementById('partC').checked == true) {
    var param4 = document.getElementById("sTyp").value;
    param4 = param4.replace(/,/, ".");
    param4 = param4.replace(/ /g, "");
  }
  
  var prjCounter = 0;
  
  for(var i = 0; i < prjArray.length; i++) {
    var table = prjArray[i].tabArray;
    
    for(var j = 0; j < table.length; j++) {
      var colArr = getKeyValuePairs(table[j].rowValues);
      var rowId = table[j].rowId;
      var idNr = table[j].idNr;
      
      // check if a item was found
      if(shockSearchB(colArr, param1, param2, param3, param4, param5)) {
        prjFoundArray[prjCounter] = new foundObject(prjArray[i].prjPath, prjArray[i].prjName, prjArray[i].prjPreview,prjArray[i].normNumber, colArr, rowId, idNr);
        prjCounter++;
      }
    }
  }
  // if results where found. show them!
  if(prjCounter > 0) {
    showFoundShock(prjFoundArray, prjStart, prjShown, div);
    document.getElementById(div).style.visibility = "hidden";
  }
  else {
    document.getElementById("theResults").style.visibility = "hidden";
    alert(noShocksFound);
  }
}

//------------------------------------------------------------------------------
// search every cell if they match one of the parameters
//------------------------------------------------------------------------------
function shockSearchB(colArr, param1, param2, param3, param4, param5) {
var pBool1 = 0;
var pBool2 = 0;
var pBool3 = 0;
var pBool4 = 0;
var pBool5 = 0;
var pBool6 = 0;
var regExp = new RegExp(param4, "i");

for(var k = 0; k < colArr.length; k++) {
  if(colArr[k].varName == "EPH" && (param1 == "" || parseFloat(param1) == 0.0 || parseFloat(param1) == 0.1 || colArr[k].varValue >= parseFloat(param1)))
    pBool1 = 1;
  if(colArr[k].varName == "EPS" && (param2 == "" || parseFloat(param2) == 0.0 || colArr[k].varValue >= parseFloat(param2)))
    pBool2 = 1;
  if(colArr[k].varName == "AGEMIN" && (param3 == "" || parseFloat(param3) == 0.0 || parseFloat(param3) == 0.1 || parseFloat(param3) == 0.01 || parseFloat(param3) == 0.44 || (colArr[k].varValue <= parseFloat(param3) && colArr[k+1].varValue >= parseFloat(param3))))
    pBool3 = 1;
  if(colArr[k].varName == "EFMMAX" && (param5 == "" || parseFloat(param5) == 20.01 || parseFloat(param1) == 200100.0 || parseFloat(param1) == 0.0 || colArr[k].varValue >= parseFloat(param5)))
    pBool5 = 1;
  if(colArr[k].varName == "EFMMIN" && (param5 == "" || parseFloat(param5) == 20.01 || parseFloat(param1) == 200100.0 || parseFloat(param5) == 0.0 || parseFloat(colArr[k].varValue) <= parseFloat(param5))) {
    pBool6 = 1;
  }
  if(colArr[k].varName == "BESTNUM" && (param4 == "" || colArr[k].varValue.search(regExp) != -1))
    pBool4 = 1;
  if(pBool1 == 1 && pBool2 == 1 && pBool3 == 1 && pBool4 == 1 && pBool5 == 1 && pBool6 == 1) {
    return true;
    break;
  }
}
return false;
}

function doOpenProject(i)
{
  /* This function is necessary, because 'openProject' is a global function
     declared in 'commonfunctions.js'. These cannot be used as event handlers.
     The purpose of this function is to 'redirect' calls from the event handler
     to the function in 'commonfunctions.js'. */
  openProject(i);
}

//------------------------------------------------------------------------------
// show found items
//------------------------------------------------------------------------------
function showFoundShock(prjFoundArray, prjStart, prjShown, div) {
  removeTable();
  prjFoundArrayTemp = prjFoundArray;
  partserver = document.partserverCheck.partserver.value;
  root = document.partserverCheck.root.value;
  
//------------------------------------------------------------------------------
// Create Table Header
//------------------------------------------------------------------------------
  var table = document.createElement("table");
  
  var cellspacing = document.createAttribute("cellspacing");
  cellspacing.nodeValue="0";
  table.setAttributeNode(cellspacing);
  
  var width = document.createAttribute("width");
  width.nodeValue="100%";
  table.setAttributeNode(width);
  
  var tbody = document.createElement("tbody");
  
  var startCol = 1;
  
// initialize first row with column names
  var headerRow = document.createElement("tr");
  
  var bgcolor = document.createAttribute("bgcolor");
  bgcolor.nodeValue = "#006699";
  headerRow.setAttributeNode(bgcolor);
  
  var fontColor = document.createAttribute("color");
  fontColor.nodeValue = "white";
  headerRow.setAttributeNode(fontColor);
  
  var textNode1 = document.createTextNode(article);
  var textNode2 = document.createTextNode(energyPerLift);
  var textNode3 = document.createTextNode(energyPerHour);
  var textNode4 = document.createTextNode(lift);
  var textNode5 = document.createTextNode(minCollisionVelocity);
  var textNode6 = document.createTextNode(maxCollisionVelocity);
  var textNode7 = document.createTextNode(minEffectiveMass);
  var textNode8 = document.createTextNode(maxEffectiveMass);
  
  for(i = startCol; i < 10; i++) {
    var td = document.createElement("td");
    
    var align = document.createAttribute("align");
    align.nodeValue = "center";
    td.setAttributeNode(align);
    
    var font = document.createElement("font");
    
    var color = document.createAttribute("color");
    color.nodeValue = "white";
    font.setAttributeNode(color);
    
    td.appendChild(font);
    
    if(i > 1)
      eval("font.appendChild(textNode" +(i-1)+")");
      
    headerRow.appendChild(td);
  }
  tbody.appendChild(headerRow);
  
// initialize second row with column units
  var unitRow = document.createElement("tr");
  var UnitNode1 = document.createTextNode("[Nm]");
  var UnitNode2 = document.createTextNode("[Nm/h]");
  var UnitNode3 = document.createTextNode("[mm]");
  var UnitNode4 = document.createTextNode("[m/s]");
  var UnitNode5 = document.createTextNode("[m/s]");
  var UnitNode6 = document.createTextNode("[kg]");
  var UnitNode7 = document.createTextNode("[kg]");
  
  for(i = startCol; i < 10; i++) {
    var td = document.createElement("td");
    
    var align = document.createAttribute("align");
    align.nodeValue = "center";
    td.setAttributeNode(align);
    
    if(i > 2)
      eval("td.appendChild(UnitNode" + (i-2) + ")");
      
    unitRow.appendChild(td);
  }
  tbody.appendChild(unitRow);
  
//------------------------------------------------------------------------------
// Create Table content
//------------------------------------------------------------------------------
  var background = 1;
  
  // check for last page
  if(prjShown > prjFoundArray.length)
    prjShown = prjFoundArray.length;
    
  for(i = prjStart; i < prjShown; i++) {
    var tableRow = document.createElement("tr");
    
    var onclickProject = document.createAttribute("onclick");
    if(partserver == 0)
      onclickProject.nodeValue = "javascript:doOpenProject("+i+");";
    else
      onclickProject.nodeValue = "javascript:parent.setOrderFrame("+i+");";    
    tableRow.setAttributeNode(onclickProject);
    
    var bgColor = document.createAttribute("bgcolor");
    if (background == 1) {
      bgColor.nodeValue = "#CCCCCC";
      background *= -1;
    }
    else {
      bgColor.nodeValue = "#FFFFFF";
      background *= -1;
    }

    if(i==iStaticOldIndex)
    {
      sStaticOldBgColor=bgColor.nodeValue;
      bgColor.nodeValue="#ffffcc"; // Highlight the row to be selected
    }
    tableRow.setAttributeNode(bgColor);
    // Create unique row id
    var oRowid = document.createAttribute("id");
    oRowid.nodeValue=("tableRow"+i);
    tableRow.setAttributeNode(oRowid);
    
    openProjectLink(tableRow, i);
    
// fill in the row values
    var row = prjFoundArray[i].colArr;
    for(j = 0; j < row.length; j++) {
      if(row[j].varName == "BESTNUM" || row[j].varName == "EPH" || row[j].varName == "EPS" || row[j].varName == "S" || row[j].varName == "AGEMIN" || row[j].varName == "AGEMAX" || row[j].varName == "EFMMIN" || row[j].varName == "EFMMAX") {
        var tableCol = document.createElement("td");
        var cellValue = document.createTextNode(row[j].varValue);
        
        var align = document.createAttribute("align");
        align.nodeValue = "center";
        
        if(row[j].varName != "BESTNUM")
          tableCol.setAttributeNode(align);
          
        tableCol.appendChild(cellValue);
        tableRow.appendChild(tableCol);
      }
    }
    tbody.appendChild(tableRow);
  }
  table.appendChild(tbody);
  document.getElementById("showResult").appendChild(table);
  
  // hide the search area and show the result area
  document.getElementById("search").style.visibility = "hidden";
  document.getElementById("showResult").style.visibility = "visible";
  
  backToSearch(div);
  previousPage(prjFoundArray, div);
  pageCounter(prjFoundArray);
  nextPage(prjFoundArray, div);
}

//------------------------------------------------------------------------------
// add an item to the basket
//------------------------------------------------------------------------------
function toBasketLink(tableRow, index) {
  // create the "to Basket" link
  var tdBasket = document.createElement("td");
  var aBasket = document.createElement("a");
  
  var hrefBasket = document.createAttribute("href");
  hrefBasket.nodeValue = "javascript:toBasket("+index+")";
  aBasket.setAttributeNode(hrefBasket);
  
  // create the "to Basket" image
  var imgBasket = document.createElement("img");
  
  var srcBasket = document.createAttribute("src");
  srcBasket.nodeValue = root + "/guide/images/tobasket.jpg";
  imgBasket.setAttributeNode(srcBasket);
  
  deleteBorder(imgBasket);
  
  // add the link to the project row
  aBasket.appendChild(imgBasket);
  tdBasket.appendChild(aBasket);
  tableRow.appendChild(tdBasket);
}

//------------------------------------------------------------------------------
// get a preview of the selected item
//------------------------------------------------------------------------------
function previewLink(tableRow, index) {
  // create the "preview" link
  var tdPreview = document.createElement("td");
  var aPreview = document.createElement("a");
  
  var hrefPreview = document.createAttribute("href");
  hrefPreview.nodeValue = "javascript:preview("+index+")";
  aPreview.setAttributeNode(hrefPreview);
  
  // create the "preview" image
  var imgPreview = document.createElement("img");
  
  var srcPreview = document.createAttribute("src");
  srcPreview.nodeValue = root + "/guide/images/preview.gif";
  
  imgPreview.setAttributeNode(srcPreview);
  
  deleteBorder(imgPreview);
  
  // add the link to the project row
  aPreview.appendChild(imgPreview);
  tdPreview.appendChild(aPreview);
  tableRow.appendChild(tdPreview);
}

//------------------------------------------------------------------------------
// Create the link to get to the next page
//------------------------------------------------------------------------------
function nextPage(prjFoundArray, div) {
  if (prjShown < prjFoundArray.length) {
    // create the next link
    var next = document.createElement("a");
    
    var hrefNext = document.createAttribute("href");
    hrefNext.nodeValue = "javascript:showNext('"+div+"')";
    next.setAttributeNode(hrefNext);
    
    var id = document.createAttribute("id");
    id.nodeValue = "next";
    next.setAttributeNode(id);
    
    next.style.position = "absolute";
    next.style.left = "440px";
    next.style.top = iNaviTop + 'px';
    
    document.getElementById("showResult").appendChild(next);
    
    // create the next image
    var nextImg = document.createElement("img");
    
    var nextImgSrc = document.createAttribute("src");
    nextImgSrc.nodeValue = root + "/guide/images/next.gif";
    nextImg.setAttributeNode(nextImgSrc);
    
    deleteBorder(nextImg);
    
    document.getElementById("next").appendChild(nextImg);
  }
}

function showNext(div) {
  // show the next page
  prjStart += ROWSSHOWN;
  prjShown += ROWSSHOWN;
  showFoundShock(prjFoundArrayTemp, prjStart, prjShown, div);
}

//------------------------------------------------------------------------------
// Create the link to get to the previous page
//------------------------------------------------------------------------------
function previousPage(prjFoundArray, div) {
  if (prjShown > ROWSSHOWN) {
    // create the back link
    var back = document.createElement("a");
    
    var hrefBack = document.createAttribute("href");
    hrefBack.nodeValue = "javascript:showPrevious('"+div+"')";
    back.setAttributeNode(hrefBack);
    
    var id = document.createAttribute("id");
    id.nodeValue = "back";
    back.setAttributeNode(id);
    
    back.style.position = "absolute";
    back.style.left = "300px";
    back.style.top = iNaviTop + 'px';
    
    document.getElementById("showResult").appendChild(back);
    
    // create the back image
    var backImg = document.createElement("img");
    
    var backImgSrc = document.createAttribute("src");
    backImgSrc.nodeValue = root + "/guide/images/back.gif";
    backImg.setAttributeNode(backImgSrc);
    
    deleteBorder(backImg);
    
    document.getElementById("back").appendChild(backImg);
  }
}

function showPrevious(div) {
  // show the previous page
  prjStart -= ROWSSHOWN;
  prjShown -= ROWSSHOWN;
  showFoundShock(prjFoundArrayTemp, prjStart, prjShown, div);
}

//------------------------------------------------------------------------------
// show the search results on the screen
//------------------------------------------------------------------------------
function showSearch(div) {
  document.getElementById("showResult").style.visibility = "hidden";
  document.getElementById("theView").style.visibility = "hidden";
  try {
    document.getElementById("theResults").style.visibility = "hidden";
  } catch(e) {}
  
  if(div == "search")
    setSearchVisible();
  else {
    document.getElementById("orderFrame").style.visibility = "hidden";
    document.getElementById("2dPreviewSmall").style.visibility = "hidden";
    document.getElementById("3dPreview").style.visibility = "hidden";
    document.getElementById(div).style.visibility = "visible";
  }
}


//------------------------------------------------------------------------------
// calculation examples
//------------------------------------------------------------------------------
function setSearchInvisible() {
  document.getElementById("search").style.visibility = "hidden";
}

function setSearchVisible() {
  document.getElementById("orderFrame").style.visibility = "hidden";
  document.getElementById("2dPreviewSmall").style.visibility = "hidden";
  document.getElementById("3dPreview").style.visibility = "hidden";
  document.getElementById("theView").style.visibility="hidden";
  document.getElementById("search").style.visibility = "visible";
}

// open the chosen calculation example
function next() {
  var aInput = document.getElementById("fallBsp").value;
  
  if(aInput == 0) { // default
  }
  else {
    setSearchInvisible();
    var style = eval("document.getElementById('calcExample" + aInput + "').style");
    style.visibility = "visible";
  }
}

// get back to search div
function back(id) {
  document.getElementById(id).style.visibility = "hidden";
  document.getElementById("gph").value = "";
  document.getElementById("gpst").value = "";
  document.getElementById("mag").value = "";
  document.getElementById("efmass").value = "";
  setSearchVisible();
}

// delete input
function deleteInput() {
  for(i = 0; i < deleteInput.arguments.length; ++i)
    document.getElementById(deleteInput.arguments[i]).value = "";
}

// calculation function for Example 01
function calcExample01(div) {
  var temp = document.getElementById("input01_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input01_2").value;
  document.calcVariables.h.value = temp.replace(/,/, ".");
  temp = document.getElementById("input01_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input01_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 02
function calcExample02(div) {
  var temp = document.getElementById("input02_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input02_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input02_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input02_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 03
function calcExample03(div) {
  var temp = document.getElementById("input03_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input03_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input03_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input03_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input03_5").value;
  document.calcVariables.u.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 04
function calcExample04(div) {
  var temp = document.getElementById("input04_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input04_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input04_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input04_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input04_5").value;
  document.calcVariables.P.value = temp.replace(/,/, ".");
  temp = document.getElementById("input04_6").value;
  document.calcVariables.HM.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 05
function calcExample05(div) {
  var temp = document.getElementById("input05_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input05_2").value;
  document.calcVariables.h.value = temp.replace(/,/, ".");
  temp = document.getElementById("input05_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input05_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input05_5").value;
  document.calcVariables.beta.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 06
function calcExample06(div) {
  var temp = document.getElementById("input06_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input06_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input06_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 07
function calcExample07(div) {
  var temp = document.getElementById("input07_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input07_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input07_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input07_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input07_5").value;
  document.calcVariables.F.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 08
function calcExample08(div) {
  var temp = document.getElementById("input08_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input08_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input08_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input08_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input08_5").value;
  document.calcVariables.R.value = temp.replace(/,/, ".");
  temp = document.getElementById("input08_6").value;
  document.calcVariables.M.value = temp.replace(/,/, ".");
  temp = document.getElementById("input08_7").value;
  document.calcVariables.L.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 09
function calcExample09(div) {
  var temp = document.getElementById("input09_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input09_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input09_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input09_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input09_5").value;
  document.calcVariables.R.value = temp.replace(/,/, ".");
  temp = document.getElementById("input09_6").value;
  document.calcVariables.M.value = temp.replace(/,/, ".");
  temp = document.getElementById("input09_7").value;
  document.calcVariables.L.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 10
function calcExample10(div) {
  var temp = document.getElementById("input10_1").value;
  document.calcVariables.J.value = temp.replace(/,/, ".");
  temp = document.getElementById("input10_2").value;
  document.calcVariables.w.value = temp.replace(/,/, ".");
  temp = document.getElementById("input10_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input10_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input10_5").value;
  document.calcVariables.R.value = temp.replace(/,/, ".");
  temp = document.getElementById("input10_6").value;
  document.calcVariables.M.value = temp.replace(/,/, ".");
  temp = document.getElementById("input10_7").value;
  document.calcVariables.L.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

// calculation function for Example 11
function calcExample11(div) {
  var temp = document.getElementById("input11_1").value;
  document.calcVariables.m.value = temp.replace(/,/, ".");
  temp = document.getElementById("input11_2").value;
  document.calcVariables.v.value = temp.replace(/,/, ".");
  temp = document.getElementById("input11_3").value;
  document.calcVariables.n.value = temp.replace(/,/, ".");
  temp = document.getElementById("input11_4").value;
  document.calcVariables.s.value = temp.replace(/,/, ".");
  temp = document.getElementById("input11_5").value;
  document.calcVariables.R.value = temp.replace(/,/, ".");
  temp = document.getElementById("input11_6").value;
  document.calcVariables.M.value = temp.replace(/,/, ".");
  temp = document.getElementById("input11_7").value;
  document.calcVariables.L.value = temp.replace(/,/, ".");
  document.calcVariables.calc.value = "1";
  document.calcVariables.div.value = div;
  document.calcVariables.submit();
}

function selectDiv(div) {
  document.getElementById(div).style.visibility = "visible";
}

function trim(sString)
{
  return sString.replace(/^\s+/,'').replace(/\s+$/,'');
}

function doShockAutosearch(iEhub, iEstunde, iVmax, sDtyp)
{
  /* Fill in the search form */
  if(trim(sDtyp)=='')
  {
    /* If there is no type specified, search for parameters or values */
    document.getElementById("gph").value=iEhub;
    document.getElementById("gpst").value=iEstunde;
    document.getElementById("mag").value=iVmax;
    document.getElementById('partB').checked=true; /* radio button 'search for params' */
  } else {
    /* If there is a type specified, search for that particular type */
    document.getElementById("sTyp").value=sDtyp;
    document.getElementById('partC').checked=true; /* radio button 'search for type' */
  }
  shockSearch('search'); /* perform a quick search */
}

