ctwice=0;amp='&';refr=20000;rndom=0;ldd=0;onff=1;turing=1;timezone=0;ifocus=0;

if(typeof document.layers=='object'){ window.location='terminal.php?reason=0'; }

if(typeof document.all=='object'){
  use_rnd=1;
  document.write('<meta http-equiv="Page-Enter" content="revealtrans(duration=0)"><meta http-equiv="Page-Exit" content="revealtrans(duration=0)">')
  document.write('<link rel="stylesheet" type="text/css" href="msie.css">');
}

/* bottom frame accessible */
function cdone(){
  if((top.length!=0)&&(typeof top.b.b2=='object')&&(typeof top.b.b2.ldd=='number')&&(top.b.b2.ldd==1)){
    return true;
  } else {
    return false;
  }
}

/* sf mainframe accessible */
function sfdone(){
  if(((top.length!=0)&&(typeof top=='object')&&(typeof top.sfldd=='number')&&(top.sfldd==1))==false){
    // if(usrname==''){ document.write('</head><body class="y">Redirecting...</body></html>'); }
    top.location.href='index.php';
    return false;
  }
}

/* check login form */
function check_login(){
  a=document.fms.name;
  b=document.fms.pass
  if((a.value!='')){
    return true
  } else { 
    return false; 
  }
}

/* add smiley */
function add_smiley(q){
  if(cdone()){
    obj=top.b.b2.document.fms.entry;
    tt=obj.value;obj.value=tt+q;
    set_focus();
  }
  return false;
}

/*preview news*/
function preview_news(){
  crq=document.fms.action;
  dd=window.open('','prv','height=300,width=310,resizable=1');
  document.fms.action='news_preview.php'; document.fms.target='prv';
  document.fms.submit(); dd.focus();
  setTimeout("document.fms.action=crq;document.fms.target='_self'",500);
  return false;
}

/* print email address */
function print_mail(a,b){ document.write('<a href="mailto:'+a+'@'+b+'">'+a+'@'+b+'</a>'); }

/* set random number */
function rand_number(){ if(use_rnd!=0){ rndom=Math.round(99999999*Math.random()); } }

/* refresh chat and history chat frame */
function chat(){ rand_number()
  j=document.fms.last.value;
  x=document.fms.scroll.value;
  o=document.fms.online_check.value;
  e=document.fms.ext.value;

  if(hist==1){
    if(x==0){
      yoffset=parent.b1.b3.document.body.scrollTop;
      parent.b1.b3.document.location.href='history_chat.php?last='+j+'&online_check='+o+'&ext='+e+'&scroll='+x+'&yoffset='+yoffset+'&r='+rndom;
    } else {
      parent.b1.b3.document.location.href='history_chat.php?last='+j+'&online_check='+o+'&ext='+e+'&scroll='+x+'&r='+rndom;
    }
  } else {
    parent.b1.document.location.href='chat.php?last='+j+'&online_check='+o+'&ext='+e+'&r='+rndom;
  }

  return false;
}

/* change refresh rate [edit] */
function change_rate(a,b,c,d){
  refr=a*1000;
  document.im0.src=c;document.im1.src=c;
  document.im2.src=c;document.im3.src=c;
  document.im4.src=c;b.src=d;
  chat();
  set_focus();
  return false;
}

/* onmouseover/onmouseout 'refresh rate' images */
function over_out(a,b,c){
 if(a.src.indexOf(b)==-1){ a.src=c; }
 return true;
}

/* set refresh timeout */
function set_rtime(s){
  self.scrollTo(0,s);
  if(cdone()){
    refr=top.b.b2.refr;
    nn=setTimeout('top.b.b2.chat()',refr);
  } else {
    url=self.location.toString();
    nn=setTimeout('self.location=url',refr);
  }
}

/* clear refresh timeout */
function clear_rtime(){ if(typeof nn=='number'){ clearTimeout(nn); } }

/* force chat load */
function force_chat(){
  if(hist==1){
    top.b.b1.location.href='frameset_hist.php?room'+cr;
  } else {
    top.b.location.href='frameset_chat.php?room='+cr;
  }
}

function reset_ltime(){
  if(typeof fc=='number'){ clearInterval(fc); }
  ltime=refr*2;
  fc=setInterval("force_chat();",ltime);
}

/* check entry */
function entry_ok(){
  e=document.fms.entry;
  if(e.value.length>0&&ctwice==0){
    ctwice=1
    if((typeof top.b.b1=='object')&&(typeof top.b.b1.nn=='number')){ top.b.b1.clear_rtime(); }
    setTimeout('e.value="";e.focus();ctwice=0',500);
    return true;
  } else {
    chat();
    e.focus();
    return false;
  }
}

/* go to url */
function go_url(o,p,r){
rand_number();if(r==1){amp='?'}
if(p<3&&parent.length!=0){
parent.frames[p].location=o+amp+'r='+rndom}
else{self.location=o+amp+'r='+rndom}return false}

/* pop-up member profile */
function ppm(q){
  iq=window.open('secondary.php?view=profile&who='+q,'secondary'+usrname,'width=580,height=400,resizable=0,scrollbars=0');
  if(iq){ iq.focus();iq.closeallowed=1; }
  return false;
}

function ppma(q){
  window.open('profile.php?who='+q+'&viewer=generic','ppma','width=580,height=400,resizable=0,scrollbars=0');
  return false;
}

/* print online user */
function usr(q,r){
  document.write('<a href="terminal.php?reason=link" title="'+r+'" style="text-decoration:none" on'+'click="top.b.b2.document.color=1;changecolor();return spm(\''+q+'\')">'+q+'</a><br>');
}

/* copy/paste/clear username */
function spm(q){
  if(cdone()){
    top.b.b2.document.fms.to.value=q;
    top.b.b2.document.fms.tt.value=q;
    set_focus();
  }
  return false;
}

/* focus entry */
function set_focus(){ if(cdone()){ top.b.b2.document.fms.entry.focus(); } }

/* force focus chat entry */
function force_focus_chat(){
  if(typeof top.b.b2=='object'&&top.b.b2.efocus==0&&top.b.b2.ctwice==0){
    if(event.keyCode!=13&&event.keyCode!=27&&event.keyCode!=32 ){      // filter: enter - esc - space
      e=top.b.b2.document.fms.entry.value;
      top.b.b2.document.fms.entry.focus();
      top.b.b2.document.fms.entry.value=e+'';
    } else if(event.keyCode==13&&ldd!=1){
      top.b.b2.fms.entry.focus();
      top.b.b2.fms.submit();
    }
  }
}

/* general force focus input */
function force_focus(f,i,s){
  if(ifocus==0){
    if(event.keyCode==13){
      f.submit();
    // alphanumeric (zonder esc - enter - space)
    } else if(s==0){
      if(event.keyCode!=13&&event.keyCode!=27&&event.keyCode!=32){
        v=i.value;
        i.focus();
        i.value=v+'';
      }
    // numeric
    } else if(s==1){
      if(event.keyCode>47&&event.keyCode<58){
        v=i.value;
        i.focus();
        i.value=v+'';
      }
    }
  }
} 

/* set the latest message */
function set_last(r){ top.b.b2.document.fms.last.value=r; }

/* set the online user count */
function set_online(r){ top.b.b2.document.fms.online_check.value=r; }

/* set chat extension status */
function set_ext(r){ top.b.b2.document.fms.ext.value=r; }

/* play new message/user online sound */
function snd(s){
  if(top.b.b2.onff==1&&s!='0'){
    if(typeof document.all=='object'){
      document.write('<object type="application/x-shockwave-flash" data="'+s+'" width="1" height="1"><param name="movie" value="'+s+'"></object>')
    } else {
      document.write('<embed type="application/x-shockwave-flash" src="'+s+'" quality="high" width="1" height="1" name="movie" pluginspage="http://www.macromedia.com/go/getflashplayer">')
    }
  }
}

/* check turing number */
function turing_number(){
if(turing==0||(turing==1&&document.fms.turnum.value.length==4&&!isNaN(document.fms.turnum.value))){return true}
else{document.fms.turnum.value='';return false}}

/* flikkerlichtje van to input */
function colorto(c){
  if(top.b.b2.document.color==1){
 // top.b.b2.document.getElementById('inputto').style.backgroundColor=c;  // de achtergrondkleur van de "to" input laten flikkeren
    top.b.b2.document.getElementById('inputto').style.color=c;            // de kleur van de letters in de "to" input laten flikkeren
    currentcolor=c;
    changecolor();
  }
}

currentcolor='';
function changecolor(){
  if(currentcolor=='white'){
    setTimeout("colorto('red')",200);             // red kan vervangen worden door een hexadecimale kleurcode, 200 is de timeout in milliseconden
  } else { setTimeout("colorto('white')",200); }  // white kan vervangen worden door een hexadecimale kleurcode, 200 is de timeout in milliseconden
}

function resetcolor(){
  top.b.b2.document.color=0;
  // top.b.b2.document.getElementById('inputto').style.backgroundColor='#7A7A7A'; // kleur resetten bij flikkerende achtergrond
  top.b.b2.document.getElementById('inputto').style.color='white';                // kleur resetten bij flikkerende letters
}

/* autoscroll on/off */
function autoscroll(){
  if(top.b.b2.document.fms.scroll.value==1){
    top.b.b2.document.fms.scroll.value=0;
    parent.b3.document.getElementById('scrollbutton').innerHTML='Autoscroll off';
  } else {
    top.b.b2.document.fms.scroll.value=1;
    parent.b3.document.getElementById('scrollbutton').innerHTML='Autoscroll on';
  }
}

/* xp sp2/ie 6 workaround voor pm/history save (http://support.microsoft.com/kb/887301/en-us) */
function savenotifier(q){
  if(navigator.userAgent.indexOf("Windows NT 5.1")>-1&&navigator.userAgent.indexOf("SV1")>-1){
    alert(q);
    return false;
  }
}

/* gallery - chat enterpopup */
function enter(q,picturewidth,pictureheight,picpadding) {
  if ((screen.width<=800)&&(screen.height<=600)){ 
    enterwidth=750; enterheight=550; 
  } else { 
    enterwidth=950; enterheight=680; 
  }
  leftpadding = (screen.width-enterwidth)/2;
  toppadding = ((screen.height-enterheight)/2)-24;

  scrolling=0;
  scrolltype='';
  if(picturewidth<enterwidth-(2*picpadding)){
    enterwidth=picturewidth+(2*picpadding);
    if(pictureheight<enterheight-(2*picpadding)){
      enterheight=pictureheight+(2*picpadding);
    } else { scrolltype='right'; scrolling=1; }
  } else if(pictureheight<enterheight-(2*picpadding)){
    enterheight=pictureheight+(2*picpadding);
    if(picturewidth<enterwidth-(2*picpadding)){
      enterwidth=picturewidth+(2*picpadding);
    } else { scrolltype='bottom'; scrolling=1; }
  } else {
    scrolltype='double'; scrolling=1;
  }

  qpe=window.open('gallery_enter.php?disp='+q+'&scrolltype='+scrolltype,'enter','width='+enterwidth+',height='+enterheight+',left='+leftpadding+',top='+toppadding+',resizable=1,scrollbars='+scrolling);qpe.focus();
}


/* select bantype in admin cp */
function selectbantype(q,r){
  if(q!='-'){
    document.fms.banargument.disabled=false;
    document.fms.banargument.value=q;
    document.fms.banargument.focus();
  } else {
    document.fms.banargument.disabled=true;
    document.fms.banargument.value=r;
    // document.getElementById('argumentrow').style.display='none';
  }
}

/* prevent double clicking submit button */
function submitonce(m){
  document.getElementById('error').innerHTML='';
  document.getElementById('error').innerHTML=m;
  document.fms.fsubmit.disabled=true;
}
