langs = 0;
files = 0;
reffiles = 0;

function check_company() {
    var s;
    if (s = document.getElementById("compSelect")) {
      if (s.value == "other") {
        var c = document.getElementById("company");
        c.type = "text";
      } else {
        var c = document.getElementById("company");
        c.type = "hidden";
      }
    }
}

function startlanguages() {
  i = 1;
  stLangs = document.getElementById("startlangs").value;
  while (i < stLangs) {
    addLang();
    document.getElementById("trTarget_" + i).value=document.getElementById("sttarget_" + i).value;
    i++;
  }

}

function hideStuff(stuff) {
  if (document.getElementById) {
    // this is the way the standards work
    var style2 = document.getElementById(stuff).style;
    style2.display = "none";
  } else if (document.all) {
    // this is the way old msie versions work
    var style2 = document.all[stuff].style;
    style2.display = "none";
  } else if (document.layers) {
    // this is the way nn4 works
    var style2 = document.layers[stuff].style;
    style2.display = "none";
  }
}

function showStuff(stuff) {
  if (document.getElementById) {
    // this is the way the standards work
    var style2 = document.getElementById(stuff).style;
    style2.display = "";
  } else if (document.all) {
    // this is the way old msie versions work
    var style2 = document.all[stuff].style;
    style2.display = "";
  } else if (document.layers) {
    // this is the way nn4 works
    var style2 = document.layers[stuff].style;
    style2.display = "";
  }
}

function translationSelected() {
  hideStuff("proofreading");
  showStuff("translation");
}

function proofreadingSelected() {
  hideStuff("translation");
  showStuff("proofreading");
}

function quoteSelected() {
  hideElementArray(getElementsByClassName(document, "*", "order"));
  showElementArray(orders = getElementsByClassName(document, "*", "quote"));
}

function orderSelected() {
  hideElementArray(getElementsByClassName(document, "*", "quote"));
  showElementArray(orders = getElementsByClassName(document, "*", "order"));
}

function hideElementArray(e) {

  var x = 0;
  do {
    if (e[x]) {
      e[x].style.display="none";
    }
  x++;
  } while (e[x]);

}

function showElementArray(e) {

  var x = 0;
  do {
    if (e[x]) {
      e[x].style.display="";
    }
  x++;
  } while (e[x]);

}


function addLang() {
  // clearContent(document.getElementById("newLangs"));
  langs++;
  copyNode("trTarget", "newLangs", langs);
  showStuff("deltargetlang");
}

function addFile() {
  files++;
  copyNode("file", "newFile", files);
  showStuff("delfile");
}

function addRefFile() {
  reffiles++;
  copyNode("reffile", "newRefFile", reffiles);
  showStuff("delreffile");
}

function delLang() {

  var node = document.getElementById("trTarget_" + langs);
  var node2 = node.previousSibling;
  node2.parentNode.removeChild(node2);
  node.parentNode.removeChild(node);
  langs--;
  if (langs == 0) {
    hideStuff("deltargetlang");
  }

}

function delFile() {

  var node = document.getElementById("file_" + files);
  var node2 = node.previousSibling;
  node2.parentNode.removeChild(node2);
  node.parentNode.removeChild(node);
  files--;
  if (files == 0) {
    hideStuff("delfile");
  }

}

function delRefFile() {

  var node = document.getElementById("reffile_" + reffiles);
  var node2 = node.previousSibling;
  node2.parentNode.removeChild(node2);
  node.parentNode.removeChild(node);
  reffiles--;
  if (reffiles == 0) {
    hideStuff("delreffile");
  }

}

function clearContent(el) {
  // first clone the object, without it???s child elements.
  var nEl = el.cloneNode(false);
  // Pop the new element in before the old one.
  el.parentNode.insertBefore(nEl,el);
  // Now get rid of the one that has all that icky content
  el.parentNode.removeChild(el);
}

function copyNode(source, dest, cnt) {
  // Get source content
  var sEl = document.getElementById(source).cloneNode(true);
  // add a line break
  var br = document.createElement("br");
  document.getElementById(dest).appendChild(br);
  // add source content onto dest content
  document.getElementById(dest).appendChild(sEl);
  var dest = document.getElementById(dest).lastChild;
  dest.name = document.getElementById(source).name + "_" + cnt;
  dest.id = source + "_" + cnt;

}

/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function showNode(node) {

  alert (node.name + "\n" + node.type);

}
