
function setSelect( elm, val ){
  for(i=0;i<elm.options.length;i++){
    if ( elm.options[i].value == val ){
      elm.selectedIndex=i;
      return true;
    }
  }
  return false;
}

function popup(filename, name, width, height) {
  var top = (screen.height - height) / 2;
  var left = (screen.width - width) / 2;
  var param = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",location=no,menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no";
  newWindow = window.open(filename, name, param);
}

function trim(string){
  return string.replace(/(^\s*)|(\s*$)/g,'');
}

function get_element(id){
	return document.getElementById(id);
}


function confirm_logout( msg, url ){
  if ( confirm(msg) ){
    window.location=url;
  }
}

function submit_form( func ){
	document.frmAdmin.func.value=func;
	try {
		document.frmAdmin.onsubmit();
  }catch(e){}
	document.frmAdmin.submit();
}

function toolbar_button( func ){
    submit_form( func );
}

function toolbar_button_checked( func, check_counter, check_msg, bconfirm, confirm_msg ){
    var frm = document.frmAdmin;
    cnt = eval( 'frm.' + check_counter );
    if (cnt) {
      if ( cnt.value == 0 ){
         alert( check_msg );
      }else{
        if ( bconfirm ){
          if ( !confirm(confirm_msg) )
            return;
        }
        toolbar_button( func );
      }
    }
}

function toolbar_button_confirm( func, bconfirm, confirm_msg ){
    var frm = document.frmAdmin;
    if ( bconfirm ){
      if ( !confirm(confirm_msg) )
        return;
    }
    toolbar_button( func );
}

function check_all_stat( cnt, elmt, stat ) {
  var frm = document.frmAdmin;
  if (!elmt) elmt = 'zcb';
  for (i=0; i < cnt; i++) {
		cb = eval( 'frm.' + elmt + '' + i );
		if (cb) {
			cb.checked = stat;
		}
	}
}

function check_all( cnt, elmt, flag, counter ) {
  if (!elmt) elmt = 'zcb';
  if (!flag) flag = '_check_all';
  if (!counter) counter = '_checked_count';
	var frm = document.frmAdmin;
	var chkall = false;
	var count = 0;
	ca = eval( 'frm.' + flag );
	if ( ca )
	 chkall = ca.checked;
	for (i=0; i < cnt; i++) {
		cb = eval( 'frm.' + elmt + '' + i );
		if (cb) {
			cb.checked = chkall;
			count++;
		}
	}
 cnt = eval( 'frm.' + counter );
 if (cnt){
  if ( chkall )
    cnt.value = count;
  else
    cnt.value = 0;
 }

}

function check_update_count( chk, elmt ) {
  if (!elmt) elmt = '_checked_count';
	var frm = document.frmAdmin;
  cnt = eval( 'frm.' + elmt );
  if (cnt) {
    if ( chk.checked )
		  cnt.value++;
    else
      cnt.value--;
	}
}

function func_check_process( func, elmt ) {
    var frm = document.frmAdmin;
    cb = eval( 'frm.' + elmt );
    if (cb) {
        for (i = 0; true; i++) {
            cbx = eval('frm.cb'+i);
            if (!cbx) break;
            cbx.checked = false;
        }
        cb.checked = true;
        toolbar_button( func );
    }
    return false;
}

function func_process(  func, elmt, val  ) {
 var frm = document.frmAdmin;
  el = eval( 'frm.' + elmt );
  if ( el ){
    el.value = val;
  }
  submit_form( func );
  return false;
}

function xreplace(checkMe,toberep,repwith){
  var temp = checkMe;
  var i = temp.indexOf(toberep);
  while(i > -1){
    temp = temp.replace(toberep, repwith);
    i = temp.indexOf(toberep);
  }
  return temp;
}




