﻿function getElementStyle(elemID, IEStyleProp, CSSStyleProp) {
    var elem = document.getElementById(elemID);
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}

// requires jquery to use fadeOut/fadeIn
function change_large(container_id, turn_on_id, turn_off_class) {
  var turnOn = document.getElementById(turn_on_id);
  var turnOnCaption = document.getElementById(turn_on_id + "_C");
  var turnOff = null;
  var turnOffCaption = null;

  // get the element that contains all of the images
  var container = document.getElementById(container_id);

  if (container != null) {
    for (var i = 0; i < container.childNodes.length; i++) {
      try {
        if (container.childNodes[i].className == turn_off_class) {
          if (getElementStyle(container.childNodes[i].id, "display", "display").toLowerCase() == 'block') {
            turnOff = container.childNodes[i];
            turnOffCaption = document.getElementById(turnOff.id + "_C");
            break;		
          }
        }
      } catch(e) {}
    }
    if (turnOn != null && turnOff != null && turnOnCaption != null && turnOffCaption != null && (turnOn != turnOff)) {
      turnOff.style.display = "none";
      turnOffCaption.style.display = "none";
      turnOn.style.display = "block";
      turnOnCaption.style.display = "block";
      //$("#" + turnOff.id).fadeOut("fast");
      //$("#" + turnOn.id).fadeIn("slow");		
    }
  }
}

// used by cad image change
function toggle_img(id1, id2, idLnk) { 		
  if (document.getElementById(id1).style.display == "none") { 		
    document.getElementById(idLnk).src="../../../images/zoom_in.gif";
	document.getElementById(id1).style.display = "block";
	document.getElementById(id2).style.display = "none";
  } else {
	document.getElementById(idLnk).src="../../../images/zoom_out.gif";
	document.getElementById(id1).style.display = "none";
	document.getElementById(id2).style.display = "block";
  }
}

function toggle_highlight(turn_on_id, turn_off_container_id, turn_off_class) {
  var turnOn = document.getElementById(turn_on_id);
  var turnOff = null;

  // get the element that contains all of the images
  var container = document.getElementById(turn_off_container_id);

  if (container != null) {
    for (var i = 0; i < container.childNodes.length; i++) {
      try {
        if (container.childNodes[i].className == turn_off_class) {
          if (getElementStyle(container.childNodes[i].id, "display", "display").toLowerCase() == 'block') {
            turnOff = container.childNodes[i];
            break;		
          }
        }
      } catch(e) {}
    }
    
    if (turnOn != null && turnOff != null && (turnOn != turnOff)) {
      turnOff.style.display = "none";
      turnOn.style.display = "block";
    }
  }
}

String.prototype.trim = function () {
  return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

