/*>====O--------------------O==== :: Archilles Scriptworld :: >\
|         ##### T A L K B O A R D  F O R U M  2 #####          |
|           Copyright (c) by Archilles, 2003-2009              |
|              http://tbforum.sourceforge.net/                 |
| Dieses Programm ist freie Software. Sie können es unter den  |
| Bedingungen der GNU General Public License 2 "only", wie von |
| der Free Software Foundation herausgegeben, weitergeben      |
| und/oder modifizieren. Eine Kopie der Lizenz ist in /docs.   |
\<====O-------------------------------------------------O====<*/

function TBF_Resize_Textarea(strFieldID,intOption){
  if ( intOption < 0 ) intOption = 0;
  if ( intOption > 1 ) intOption = 1;
cur = document.getElementById(strFieldID).rows;
part = Math.floor(0.25*cur);
  if ( intOption == 1 )
  vnew = cur+part;
  else if ( intOption == 0 )
  vnew = cur-part;
  if ( vnew < 4 ) // Kleiner als vier Felder ist nicht sinnig ;)
  vnew = 15;
document.getElementById(strFieldID).rows = vnew;
//window.defaultStatus = 'current '+cur+' / part '+part+' / new '+vnew;
}

// Ein Bild auswechseln bzw. anzeigen
function TBF_Show_Image(strPicID,strPicFile){
//alert(strPicID+' '+strPicFile);
document.images[strPicID].src = strPicFile;
}

// In einem Loginfeld kann die Eingabe mit einem MD5-Hash ersetzt werden...
function TBF_Challenge_Response() {
document.loginform.form_pass_digest.value = hex_md5(document.loginform.form_pass.value);
document.loginform.form_pass.value = "";
}

// Ein Block kann sichtbar geschaltet werden oder nicht...
function TBF_Fold_Controller(strBlockID,intOption){
  if ( document.getElementById(strBlockID).style.display == "" && TBF_VERBOSE_JS == 1 )
  alert('The Block "'+strBlockID+'" seems not to support display settings!');
  else{
    if ( intOption == 1 )
    document.getElementById(strBlockID).style.display = "block";
    else if ( intOption == 0 )
    document.getElementById(strBlockID).style.display = "none";
  }
}

// Input-Checkboxen können in einem Rutsch aktiviert oder deaktiviert werden...
function TBF_Quick_Select(strFormName){
var i = 0;
  for ( i = 0 ; i < document.getElementById(strFormName).elements.length ; i++ ){
    if ( document.getElementById(strFormName).elements[i].type == "checkbox" )
    document.getElementById(strFormName).elements[i].checked = !(document.getElementById(strFormName).elements[i].checked);
  }
}

// Einen Parameter mit Trenner in einem Textfeld hinzufügen...
function TBF_Add_Parameter(strFieldID,strValue,strDelimiter){
var strNew = "";
var strRestore = eval(strFieldID).value;

  if ( strRestore.length == 0 )
  strNew = strValue;
  else{
  strLastChar = strRestore.substr(-1,1);
    if ( strLastChar != strDelimiter )
    strNew = strRestore+strDelimiter+strValue;
    else
    strNew = strRestore+strValue;
  }

  if ( strDelimiter == "~" ) // Nur diese neue Eingabe erlaubt!
  strNew = strValue;

eval(strFieldID).value = strNew;
}

function TBF_Parse_Moderator_RSS_Feed_URI(){
  if ( document.modcp_rss.modcp_rss_range[0].checked == true )
  intRng = document.modcp_rss.modcp_rss_range[0].value;
  else if ( document.modcp_rss.modcp_rss_range[1].checked == true )
  intRng = document.modcp_rss.modcp_rss_range[1].value;
strPwd = document.getElementById('modcp_rss_password').value;
strUrl = TBF_FORUM_ROOT_URI+TBF_MODCP_RSS_URL;
strUrl = strUrl.replace(/&amp;/,"&"); // Hmm, sicherheitshalber doppelt...
strUrl = strUrl.replace(/&amp;/,"&");
strUrl = strUrl.replace(/R1/,parseInt(intRng));
strUrl = strUrl.replace(/R2/,TBF_CURRENT_USERNAME);
strUrl = strUrl.replace(/R3/,hex_md5(strPwd));
  if ( strPwd.length > 4 )
  document.getElementById('modcp_rss_uri').innerHTML = strUrl;
return;
}

// Einen Fortschrittsbalken anzeigen
function TBF_Progress_Bar_Init(intWidth,strTitle){
document.write("<div class=\"prbar_clock\" style=\"width: "+intWidth+"px;\" id=\"TBF_ProgressBar\">");
document.write(strTitle+"<br />");
document.write("<div style=\"width: 0px; text-align: center;\" id=\"TBF_ProgressBar_Block\"><input type=\"text\" class=\"prbar_text\" size=\"3\" id=\"TBF_ProgressBar_Text\" value=\"0%\" /></div>");
document.write("</div>");
TBF_Fold_Controller('TBF_ProgressBar',1);
}

function TBF_Progress_Bar_Set(intPercent,intFactor){
var intRatio_UP = Math.round((intPercent/100)*255);
var intRatio_DN = 255-intRatio_UP;
var strColor_RGB = "rgb("+intRatio_DN+","+intRatio_UP+",0)";
document.getElementById('TBF_ProgressBar_Block').style.width = (intPercent*intFactor)+"px";
document.getElementById('TBF_ProgressBar_Block').style.backgroundColor = strColor_RGB;
document.getElementById('TBF_ProgressBar_Text').value = intPercent+"%";
}

function TBF_Progress_Bar_End(){
TBF_Fold_Controller('TBF_ProgressBar',0);
}

// Dialogbox, welche auf die gewünschte Seite eines Themas weiterleitet
function TBF_Do_Topic_Page_Jump(intTID,intPagenum){
intStartv = (Number(intPagenum)-1)*TBF_POSTINGS_PER_PAGE;
strUrl = TBF_TOPIC_URL;
strUrl = strUrl.replace(/&amp;/,"&");
strUrl = strUrl.replace(/&amp;/,"&");
strUrl = strUrl.replace(/R1/,intTID);
strUrl = strUrl.replace(/R2/,intStartv);
location.href = strUrl;
}

function TBF_Get_Page(intTID,intMaxpage){
intPagenum = prompt(TBF_STR_SELECT_PAGE_TO_SHOW,'1');
  if ( intPagenum > 0 )
  TBF_Check_Page(intTID,intPagenum,intMaxpage);
exit;
}

function TBF_Check_Page(intTID,intPagenum,intMaxpage){
  if ( isNaN(intPagenum) || intPagenum > intMaxpage )
  TBF_Get_Page(intTID,intMaxpage);
  else
  TBF_Do_Topic_Page_Jump(intTID,intPagenum);
}

// Formulare ausblenden (irgendwie ein doofer Funktionaname :D)
function TBF_Advanced_Forum_Control(strFormName,intValue){
  if ( intValue == 0 )
  TBF_Fold_Controller(strFormName,0);
  else
  TBF_Fold_Controller(strFormName,1);
}

// ACLs von einem Forum auf mehrere kopieren
function TBF_Copy_Access_Control_Entry(){
tc = 0;
use_as_src = 0;
use_as_dst = new Array();
acl_src = document.forms['aclform'].ACLCOPY_SRC;
acl_dst = document.forms['aclform'].ACLCOPY_DST;

  if ( acl_src.length != acl_dst.length )
  return false;

  for ( i = 0 ; i < acl_src.length ; i++ ){
    if ( acl_src[i].checked == true && use_as_src == 0 )
    use_as_src = acl_src[i].value;
    if ( acl_dst[i].checked == true ){
    use_as_dst[tc] = acl_dst[i].value;
    tc++;
    }
  }

  if ( use_as_src != 0 && document.forms['aclform'].eval('form_acl_'+use_as_src) )
  acl_buffer = document.forms['aclform'].eval('form_acl_'+use_as_src).value;
  else
  return false;

  for ( j = 0 ; j < tc ; j++ ){
  current = use_as_dst.shift();
  document.forms['aclform'].eval('form_acl_'+current).value = acl_buffer;
  }

return true;
}

// Bei Favoriten, die regelmäßig abonniert sind, keine Nachricht bei "Neu" oder "Geändert"
function TBF_Check_Favorite_Dependency(value,formid){
  if ( value != 0 ){
  document.getElementById('favform_'+formid).form_onnew.checked = false;
  document.getElementById('favform_'+formid).form_onedit.checked = false;
  }
}

// Einen vorgefertigten Query in das Eingabefeld einfügen
function TBF_MQ_PresetQuery(myinput){
document.getElementById('TBF_MQ_field').value = myinput;
}

// Einen Ladebalken über den Bildschirm legen, entfernen und die Routine für den Fortschrittsbalken
function TBF_Toggle_Loading_Screen(){
  if ( TBF_LS_ENABLE == 0 )
  return;

  if ( window.innerWidth && window.innerHeight ){
  var ieobj = null;
  pos_mid_x = window.pageXOffset+(window.innerWidth/3);
  pos_mid_y = window.pageYOffset+(window.innerHeight/3);
  pos_max_y = ( window.scrollMaxY ) ? window.scrollMaxY : document.body.scrollHeight; // scrollMaxY is Gecko only...
  pos_max_y += window.innerHeight;
  }
  else{
  // http://forum.de.selfhtml.org/archiv/2005/4/t106392/
  // Der IE hat wieder einmal seinen eigenen Affenzirkus ;)
  var ieobj = ( document.compatMode && document.compatMode == 'CSS1Compat' ) ? document.documentElement : document.body || null;
  pos_mid_x = ieobj.scrollLeft+(ieobj.offsetWidth/3);
  pos_mid_y = ieobj.scrollTop+(ieobj.offsetHeight/3);
  pos_max_y = ieobj.scrollHeight;
  }

//alert('mid:'+pos_mid_x+','+pos_mid_y+' maxy:'+pos_max_y+' shade:'+ieobj);
document.getElementById('tbf_loading_screen').style.left = pos_mid_x+'px';
document.getElementById('tbf_loading_screen').style.top = pos_mid_y+'px';
document.getElementById('tbf_loading_screen').style.display = 'block';
  if ( ieobj == null && pos_max_y ){
  document.getElementById('tbf_secure_box').style.height = pos_max_y+'px';
  document.getElementById('tbf_secure_box').style.display = 'block';
  }
TBF_LS_LOCK = 1;
TBF_Cycle_Loading_Screen();
return;
}

function TBF_Untoggle_Loading_Screen(){
document.getElementById('tbf_loading_screen').style.display = 'none';
document.getElementById('tbf_secure_box').style.display = 'none';
TBF_LS_LOCK = 0;
}

function TBF_Cycle_Loading_Screen(){
  if ( TBF_LS_LOCK == 1 ){
    for ( i = 1 ; i <= 10 ; i++ ){
      if ( i == TBF_LS_POINTER )
      document.getElementById('tbf_ls_'+i).className = 'box_ls_bar_v';
      else
      document.getElementById('tbf_ls_'+i).className = 'box_ls_bar_h';
    }
    if ( TBF_LS_POINTER < 10 )
    TBF_LS_POINTER++;
    else
    TBF_LS_POINTER = 1;
  window.setTimeout("TBF_Cycle_Loading_Screen()",200);
  }
}
