var md5_included;
var adminnotes_loaded;
var fake_element;

function ExtGetElementById(id){
  if(document.getElementById(id)){
    return document.getElementById(id);
  }
  else if(document.all[id]){
    return document.all[id];
  }
  else if (document.layers && document.layers[id]){
    return (document.layers[id]);
  }
  else{
    return fake_element;
  }
}

function popUpPreview(sURL) 
{
  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, 'scrollbars=1');
}

function popUpScroll(sURL,sName, x, y, dx, dy)
{
  popUp(sURL,sName,x,y,dx,dy,'scrollbars=1')
}

function popUpFull(sURL,sName)
{
  popUp(sURL,sName,0,0,window.screen.width,window.screen.height,'fullscreen=1')
}

function popUp(sURL, sName, x, y, dx, dy, addon) 
{
  if (addon) addon = ', ' + addon;
  else addon = '';
  window.open(sURL, sName, 'directories=0, resizable=1, status=0, toolbar=0, menubar=0, location=0, left=' + x + ', top=' + y + ', width=' + dx + ', height=' + dy + addon);
}

function GoURL(s)
{
  document.location = s;
}

function Add2Fav()
{
  if (document.all) {
    window.external.AddFavorite(document.location.href,document.title)
  }
}

function Print()
{
  var url = document.location.href;
  if (url.indexOf('print=yes')!=-1) var q = '';
  else if (url.indexOf('?')!=-1) var q = '&print=yes';
  else var q = '?print=yes';
  window.open(url + q);
}

function PostNullCheckboxes(f)
{
  var el = f.elements;
  for (var i=0; i<el.length; i++) {
    if ((el[i].type=='checkbox') && (el[i].checked==false)) {
      el[i].checked = true;
      el[i].value = 0;
    }   
  }
  f.submit();
}

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].checked=on;
  }
}

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';
}

function ShowPwd(ctl){
  alert(eval('document.frm.'+ctl).value);
}

function inline_popup(img_id) {
  var winWidth = 640;
  var winHeight = 480;
  var w = (screen.width - winWidth)/2;
  var h = (screen.height - winHeight)/2 - 60;
  var url = '/phpfaber_cms/cms_content/system_inlineimages/'+img_id;
  var name = 'name';
  var features = 'scrollbars=yes,resizable=yes,toolbar=yes,width='+winWidth+',height='+winHeight+',top='+h+',left='+w;
  window.open(url,name,features);
}

function getCookie(NameOfCookie) {
  if (document.cookie.length > 0) {
    begin = document.cookie.indexOf(NameOfCookie+"=");
    if (begin != -1) {
      begin += NameOfCookie.length+1;
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(begin, end));
    }
  }
  return null;
}

function setCookie(NameOfCookie, value, expiredays) {
  var ExpireDate = new Date ();
  ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
  document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie(NameOfCookie) {
  if (getCookie(NameOfCookie)) {
    document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function str_replace(search,replace,subject) {
  s = subject;
  while (s.indexOf(search)!=-1) {
    s = s.replace(search,replace);
  }
  return s;
}

function UpdateDateControl(obj_id,full)
{

  var time = new Date();
  var date = time.getDate();
  var month = time.getMonth() + 1;
  var year = time.getFullYear();
  //if (date < 10) date = "0" + date;
  //if (month < 10) month = "0" + month;

  var id_d = ExtGetElementById(obj_id+'[d]');
  id_d.value = date;
  var id_m = ExtGetElementById(obj_id+'[m]');
  id_m.value = month;
  var id_y = ExtGetElementById(obj_id+'[y]');
  id_y.value = year;
  
  if (full) {
    var hour = time.getHours();
    var minute = time.getMinutes();
    if (hour < 10) hour = "0" + hour;
    if (minute < 10) minute = "0" + minute;

    var id_hh = ExtGetElementById(obj_id+'[hh]');
    id_hh.value = hour;
    var id_mm = ExtGetElementById(obj_id+'[mm]');
    id_mm.value = minute;
  }
}

function JSInclude(script_filename) {
  document.write('<' + 'script');
  document.write(' language="javascript"');
  document.write(' type="text/javascript"');
  document.write(' src="' + script_filename + '">');
  document.write('</' + 'script' + '>');
}