var ie4 = false;
var szam_ = 0;
if(document.all) {
  ie4 = true;
}

//---------------------------------------------------------------------------------//

function GoBack() {
  history.go(-1);
  return false;
}

function GoTop() {
  if (document.body) {
    document.body.scrollTop = 0;
    return false;
  } else {
    return true;
  }
}

function GoBottom() {
  if (document.body) {
    document.body.scrollTop = document.body.scrollHeight;
    return false;
  } else {
    return true;
  }
}

//---------------------------------------------------------------------------------//

function mo(szoveg) {
  window.status=szoveg;
}

function mu() {
  window.status='';
}


var win= null;
function NewWindow(mypage,myname,w,h,scroll) {
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}


function regisztracio(azonosito) {
  NewWindow("regisztracio.php?status=regisztracio&azonosito="+azonosito,"regisztracio",320,300,"no");
}

function modpass(azonosito) {
  NewWindow("regisztracio.php?status=modpass&azonosito="+azonosito,"modpass",320,350,"no");
}

function lostpass(azonosito) {
  NewWindow("regisztracio.php?status=lostpass&azonosito="+azonosito,"lostpass",320,300,"no");
}

function login(azonosito,SID) {
  NewWindow("regisztracio.php?status=login&azonosito="+azonosito+"&"+SID,"lostpass",500,300,"no");
}

function logout(azonosito,SID) {
  NewWindow("regisztracio.php?status=logout&azonosito="+azonosito+"&"+SID,"logout",500,300,"no");
}

function moderalas(azonosito) {
  NewWindow("regisztracio.php?status=moderalas&azonosito="+azonosito,"moderalas",320,300,"no");
}

function admin(azonosito) {
  NewWindow("admin.php?azonosito="+azonosito,"admin",600,500,"yes");
}


function DoP(action) {
  var rvmsg;
  var cmsg = document.newmessage.fmessage.value;

  if (action == "url") {
    var thisURL = prompt("Add meg a beszúrandó link URL-jét!   A http:// vagy ftp:// előtagot kötelező tartalmaznia!", "http://");
    if (thisURL.length>8) {
      var thisTitle = prompt("Mi a link neve?", "");
    }
    var urlcode = "[URL="+thisURL+"]"+thisTitle+"[/URL]";
    rvmsg = cmsg+urlcode;
    if (thisURL.length>8 && thisTitle.length>1) {
      document.newmessage.fmessage.value=rvmsg;
    }
    document.newmessage.fmessage.focus();
    return;
  }

  if (action == "img") {
    var thisImage = prompt("Add meg a beszúrandó kép URL-jét!", "http://");
    var imagecode = "[IMG]"+thisImage+"[/IMG]";
    rvmsg = cmsg+imagecode;
    if (thisImage.length>8) {
      document.newmessage.fmessage.value=rvmsg;
    }
    document.newmessage.fmessage.focus();
    return;
  }
}

function help() {
  window.open("popup.php?id=help","help","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=400");
}

function szmajlik() {
  window.open("popup.php?id=smiles","smiles","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=200");
}

function pictures(urlget) {
  window.open("popup.php?id=pictures&"+urlget,"pictures","fullscreen=yes,scrollbars=yes,status=no,resizable=yes");
  return false;
}

//---------------------------------------------------------------------------------//
function setContent(name, value, szam) {
  var d;
  if (ie4) {
    d = document.all[name];
  } else {
    d = document.getElementById(name);
  }
//  alert(d.innerHTML);
  if ((szam == 0) || (szam != szam_)) {
    d.innerHTML = value;
    if (szam != 0)
      szam_ = szam;
  }
}

function IconDown(melyik) {
  melyik.className = 'icon3';
}

function IconUp(melyik) {
  melyik.className = 'icon';
}

function IconOver(melyik) {
  melyik.className = 'icon2';
}

function InsertTag(cel, tag, ptl){
  var d;
  if (ie4) {
    d = document.all[cel];
  } else {
    d = document.getElementById(cel);
  }
  d.focus();

  //IE support
  if (document.selection) {
    sel = document.selection.createRange();
    if (tag.substring(0, 1)=='[')
      sel.text += tag;
    else if (ptl)
      sel.text += '['+tag+']';
    else
      sel.text = '['+tag+']' + sel.text + '[/'+tag+']';
    d.focus();
  //MOZILLA/NETSCAPE support
  } else if (d.selectionStart || d.selectionStart == '0') {
    var startPos = d.selectionStart;
    var endPos = d.selectionEnd;
//    alert(startPos+' '+endPos+' '+d.value.substring(startPos, endPos));
    if (tag.substring(0, 1)=='[') {
      d.value = d.value.substring(0, endPos) + tag + d.value.substring(endPos, d.value.length);
      d.selectionStart = d.selectionEnd = endPos+tag.length;
    } else if (ptl) {
      d.value = d.value.substring(0, endPos) + '['+tag+']' + d.value.substring(endPos, d.value.length);
      d.selectionStart = d.selectionEnd = endPos+tag.length+2;
    } else {
      d.value = d.value.substring(0, startPos) + '['+tag+']' + d.value.substring(startPos, endPos) + '[/'+tag+']' + d.value.substring(endPos, d.value.length);
      d.selectionStart = d.selectionEnd = endPos+tag.length*2+5;
    }
  } else {
    if (ptl)
      d.value += '['+tag+']';
    else
      d.value += '['+tag+']' + '[/'+tag+']';
  }
}

function InsertObj(cel, tag, ptl) {
  if (tag == "url") {
    var thisURL = prompt("Add meg a beszúrandó link URL-jét!   A http:// vagy ftp:// előtagot kötelező tartalmaznia!", "http://");
    if (thisURL.length>8) {
      var thisTitle = prompt("Mi a link neve?", "");
    }
    var urlcode = "[URL="+thisURL+"]"+thisTitle+"[/URL]";
    if (thisURL.length>8 && thisTitle.length>1) {
      InsertTag(cel, urlcode, 0==0);
    }
  }
  if (tag == "img") {
    var thisImage = prompt("Add meg a beszúrandó kép URL-jét!", "http://");
    var imagecode = "[IMG]"+thisImage+"[/IMG]";
    if (thisImage.length>8) {
      InsertTag(cel, imagecode, 0==0);
    }
  }

}


function popup(url, X, Y) {

  if (document.all)
    var xMax = screen.width, yMax = screen.height;
  else if (document.layers)
    var xMax = window.outerWidth, yMax = window.outerHeight;
  else
    var xMax = 800, yMax=600;

  var xOffset = (xMax - X)/2;
  var yOffset = (yMax - Y)/2-30;

  newwin = open(url, '_blank', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes,copyhistory=no,width='+X+',height='+Y+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
  newwin.focus();
  return false;
}

function thumbnail2image(tn) {
  tn = tn.replace(/\/t([^\/]*)$/g, '/$1');
//  alert(tn);
  return tn;
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function'){
    window.onload = func;
  } else {
    window.onload = function(){
      oldonload();
      func();
    }
  }
}

function galeria_init() {
  var gallery;
  if (document.all)
    gallery = document.all['gallery'];
  else
    gallery = document.getElementById('gallery');
  if (gallery) {
    var allanchors = document.getElementsByTagName('img');
    for (i=0; i<allanchors.length; i++)
      if (allanchors[i].className && (allanchors[i].className=='gallery')) {
        allanchors[i].onclick = function () {gallery.src=thumbnail2image(this.src); return false;}
      }
  }
}

function limit_init() {
  var alldiv = document.getElementsByTagName('div');
  for (i=0; i<alldiv.length; i++)
    if (alldiv[i].className && (alldiv[i].className=='limit')) {
      if (document.all) {
        if (alldiv[i].scrollWidth != alldiv[i].offsetWidth) {
          alldiv[i].style.height = (alldiv[i].offsetHeight + 20) + 'px';
        } 
      } else {
//          alldiv[i].style.height = (alldiv[i].offsetHeight + 1) + 'px';
      }
    }
}

addLoadEvent(galeria_init);
addLoadEvent(limit_init);

