String.prototype.trim = function() {
    val = this;
    if (val) {
        return val.replace(/(^\s*)|(\s*$)/g, "");
    } else {
        return "";
    }
}
String.prototype.contains = function(text) {
    val = this;
    return (val.indexOf(text) > -1);
}
String.prototype.endsWith = function(text) {
    val = this;
    if (!val) return false;
    return val.match(text + '$');
}

function $(el) {
  return document.getElementById(el);
}

function OI(obj) {
  var msg = Array();
  
  for (p in obj) {
    msg[msg.length] = p;
  }
  msg = msg.join(", ");
  alert(msg);
}
function getX(e) {
  var x = 0;
  while(e) {
    x += e.offsetLeft;
    e = e.offsetParent;
  }
  return x;
}

function OpenWindow(url, height, width, scrollable) {
    if (!height) height = 300;
    if (!width) width = 300;
    scrollable = scrollable ? ",scrollbars" : "";
    var win = window.open(url, "", "resizable=1,toolbar=1,location=0,status=0,menubar=0" + scrollable + ",width=" + width + ",height=" + height);
    win.focus();
}

function ValidateFeedback(form) {
try {
    if ($('sg_other').checked && $('sg_other_specify').value.trim() == '') {
      alert('Please clarify your "Other" selection for the stakeholder group.');
      $('sg_other_specify').focus();
      return false;
    }
    var sections = ['stakeholder_group','credentials_in_comprehensive_care','certifying_better_you','certifying_better_patients','certifying_better_hcds'];
    for (var y=0;y<sections.length;y++) {
        var checked = false;
        var section = sections[y];
        for (var x=0;x<form[section].length;x++) {
            if (form[section][x].checked) {
                checked = true;
                break;
            }
        }
        if (!checked) {
            alert('Please ensure that you have selected an answer for each question before selecting "Send".');
            return false;
        }
    }
    return true;    
}
catch(ex) {
      alert("error");
}
return false;
}