
function popUp (sURL, sName, x, y, dx, dy) {
  if(!sURL) return;
  window.open(sURL, sName, 'left='+x+',top='+y+',width='+dx+',height='+dy+',scrollbars=1,resizable=1');
}

function GoURL(s){
  document.location = s;
}

function Add2Fav(){
  if (document.all)
    window.external.AddFavorite(document.location.href,document.title)
}

function OpenPreview(sURL) {
  if(!sURL) return;
  var w_s = 50;
  var h_s = 50;
  var w = window.screen.width;
  var h = window.screen.height;
  popUp(sURL,'PreviewWin', w_s, h_s, w-2*w_s, h-2*h_s-50);
}

function OpenImages(id,f){
  OpenPreview('index.php?page=images&id='+id+'&f='+f);
}

function hwReloadCat(page,cid,hwJsCats){

  var catbox = document.frm.cid;
  var new_cid = catbox.options[catbox.selectedIndex].value;
  var f1,f2,s1,s2;
  s1 = '|' + new_cid + '|';
  s2 = '|' + cid + '|';
  
  for (i = 0; i < hwJsCats.length; i++) {
    f1 = hwJsCats[i].indexOf(s1) != -1;
    f2 = hwJsCats[i].indexOf(s2) != -1;
    if(f1 && f2) return;
    if(f1 || f2) break;
  }
  
  var ch_sep = page.indexOf('?') != -1 ? '&' : '?';  
  document.location = page + ch_sep + 'cid=' + new_cid;
}

function txtCount(f, countf, max) {
  
  if(isNaN(max)) return txtCountW(f, countf, max);

  if (f.value.length > max) f.value = f.value.substring(0, max);
  else countf.value = max - f.value.length;

}

function txtCountW(f, countf, max) {
  var num = 0;
  for (x=0;x<f.value.length;x++) {
    // Counts the spaces while ignoring double spaces, usually one in between each word
    if (f.value.charAt(x) == " " && f.value.charAt(x-1) != " ")  num++;
    if (num > 250) f.value = f.value.substring(0, x);
    else countf.value = parseInt(max) - num;
  }
}

function hwGetMenuValue(ctl){
  ctl = eval('document.' + ctl);
  return ctl.options[ctl.selectedIndex].value;
}

function SwitchItemsAdm (block) {
  if(!block) block = 'chk_id';
  var on = document.frm.chk_all.checked;
  var el = document.frm.elements;
  for (var i=0; i<el.length; i++) {
    if (el[i].name.substr(0,block.length)== block && !el[i].disabled) el[i].checked=on;
  }
}

function LookupUserAdm(ctl){
  popUp('index.php?page=lookup_uid&tg='+escape(ctl),'LookupUID', 50, 50, 400, window.screen.height-150);
}

function hwGetElementById(id){
  if (document.getElementById) return (document.getElementById(id));
  else if (document.all) return (document.all[id]);
  else if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) return (document.layers[id]);
}

function hwShowPass(ctl){
  alert(eval('document.frm.'+ctl).value);
}

function SwitchBlock(Id, bShow) {
  var el;
  if(document.getElementById) el = document.getElementById(Id);
  else { el = document.all ? document.all[Id] : new Object(); }
  if(!el) return;
  if(el.style) el = el.style;
  if( typeof( el.display ) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ) { alert('Browser Error!'); return; }
  el.display = bShow ? 'block' : 'none';
}
