var popup;
var temp;
function OpenWindow(addrs,param,title) {
  // Open a Window
  popup = window.open(addrs + "?" + param,title,'width=400,height=350,scrollbars=yes,resize=no');
  popup.focus();
}

function QuickJump(loc) {
  // Run Quick Jump Code
  if (loc != -1 && loc.substring(0,4) != "Open")
    window.location = loc;
  // Run JavaScript Code
  else if (loc.substring(0,4) == "Open")
    eval(loc + ";");
  // WTF is going on! :-p
  else if (loc != -1)
    alert(loc);
}

function VerifyMark(cats, str, value) {
  var newArray = eval("temp" + cats + "");
  
  // Check/UnCheck all Sub Elements and Main Elements
  for(var el in newArray) {
    if (value) {
      eval("document.getElementById('remove" + str + "_" + el + "').checked = \"checked\";");
      VerifyMark(cats + "[" + el + "]", str + "_" + el, value);
    } else {
      eval("document.getElementById('remove" + str + "_" + el + "').checked = \"\";");
      VerifyMark(cats + "[" + el + "]", str + "_" + el, value);
    }
  }
  
  // If /Checking/Unchecking a Sub Element, Check/Uncheck its Parent Elements as well
  var parentLocation = str.split("_");
  if ((parentLocation.length > 1 || parentLocation[0] != "") && !value) {
    var newString = "";
    // find location that needs unchecked
    for(var i = 0; i < parentLocation.length - 1; i++) {
      if (i == 0)
        newString = parentLocation[i];
      else
        newString += "_" + parentLocation[i];
      
      eval("document.getElementById('remove" + newString + "').checked = \"\";");
    }
  } else {
    if (document.getElementById('removeParents').checked)
      CheckParents(str);
  }
}

function CheckParents(str) {
  if (str.indexOf("_") > -1)
    var parentLocation = str.split("_");
  else
    return false;
  
  var newString = "";
  var newArrayString = "";
  // Make array string, and form name string
  for(var i = 0; i < parentLocation.length - 1; i++) {
    if (i == 0) {
      newString = parentLocation[i];
      newArrayString = "[" + parentLocation[i] + "]";
    } else {
      newString += "_" + parentLocation[i];
      newArrayString += "[" + parentLocation[i] + "]";
    }
  }
  
  // Find all possible scenarios
  var newArray = eval("temp" + newArrayString + "");
  
  // Search for an unchecked box
  var found = false;
  for(var el in newArray) {
    if (!eval("document.getElementById('remove" + newString + "_" + el + "').checked")) {
      found = true;
    }
  }
  
  // Was an unchecked box found?
  if (found) {
    eval("document.getElementById('remove" + newString + "').checked = \"\";");
  } else {
    eval("document.getElementById('remove" + newString + "').checked = \"checked\";");
    CheckParents(newString);
  }
}

function radioClick(id_name) {
  eval("document.getElementById('" + id_name + "').checked = \"checked\";");
}

function checkClick(id_name) {
  if (!eval("document.getElementById('" + id_name + "').checked")) {
    eval("document.getElementById('" + id_name + "').checked = \"checked\";");
  } else {
    eval("document.getElementById('" + id_name + "').checked = \"\";");
  }
}
