var newwin = null;
function closewin() {
  if (newwin != null) { if(!newwin.closed) newwin.close(); }
}

function popup(strurl,strtype,strheight,strwidth) {
  closewin();
  var stroptions="";
  if (strtype=="console") stroptions="scrollbars,resizable,status=no,height="+strheight+",width="+strwidth+",left=1,top=1";
  if (strtype=="faq") stroptions="scrollbars,resizable,status=no,menubar=no,height="+strheight+",width="+strwidth+",left=1,top=1";
  newwin = window.open(strurl, 'newwin', stroptions);
  newwin.focus();
}

function givefocus() {
  if (!arguments[0]) return false;
  var _elm = document.getElementsByName(arguments[0]);
  if (_elm[0]) _elm[0].focus();
}

function visible() {
  var _elem = document.getElementById("text_refer");
  var dis = _elem.style.display;
  if (dis=='none') _elem.style.display = 'block';
  else _elem.style.display = 'none';
}

// ************************************************
// CHECK
// @param id: string, id of the select element
// @param array: array, [0]=>array('text'=>'', 'value'=>'')
// @param selected option: string, value of the selected element
// ************************************************
var aCheck = function(event) {
  var key = window.event ? window.event.keyCode : event.which;
  var confKey = new Array();
  switch (arguments[1]) {
    case "NUMBER" :
      var confKey = new Array('0','8','9','13','32','44','45','46','48','49','50','51','52','53','54','55','56','57','99','114','118');
      break;
    case "INT" :
      var confKey = new Array('0','8','9','13','48','49','50','51','52','53','54','55','56','57','99','114','118');
      break;
    case "DATE" :
      var confKey = new Array('0','8','9','13','47','48','49','50','51','52','53','54','55','56','57','99','114','118');
      break;
    default :
      var confKey = new Array('0','8','9','13','45','46','48','49','50','51','52','53','54','55','56','57','99','114','118');
      break;
  }
  if (!in_array(key,confKey)) {
    if (window.event) { window.event.returnValue = false; }
    else {
      event.returnValue = false;
      event.cancelBubble = true;
      event.preventDefault();
      event.stopPropagation();
    }
  }
}
