
/*
###############################################################################
###############################################################################
# WebAPP - Automated Perl Portal                                              #
#-----------------------------------------------------------------------------#
# webapp.js                                                                   #
# Last Modified: v0.9.9.8                                                     #
#                                                                             #
#   ###  WebAPP Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007              #
#   ###  M. Carter Brown                                                      #
#   ###  Jocelyn Brown                                                        #
#   ###  www.web-app.org                                                      #
#                                                                             #
#   ### See individual file headers for more details on copyrights by         #
#   ### contributing developers, per file and per subroutine as noted.        #
#                                                                             #
# This file is part of WebAPP.                                                #
#                                                                             #
# WebAPP is free software; you can redistribute it and/or modify              #
# it under the terms of the GNU General Public License as published by        #
# the Free Software Foundation; either version 2 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# WebAPP is distributed in the hope that it will be useful,                   #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with WebAPP; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.               #
#                                                                             #
# File: Modified: 2004 by Jos ("bantychick") for WebAPP v0.9.9.2              #
# Modified: 2006 by Jos for WebAPP v0.9.9.3.4NE                               #
# Modified: 2006 by Lee ("leenanall") and Jos for WebAPP v0.9.9.4             #
# Modified: 2007 by Jos for WebAPP v0.9.9.5                                   #
# Modified: 2007 by Jos for WebAPP v0.9.9.8                                   #
###############################################################################
###############################################################################
*/

/** caret positioning by Lee added 4 Nov 2006 **/
/*** css dropdown - added by bantychick ***/
/*** Fixed UBBC - by Jeff (W. Jeff Crawford) ***/
/** Fixed UBBC fix for firefox browser by Lee **/

/** caret positioning **/
function addCode(anystr) {
if (document.creator.message.createTextRange && document.creator.message.caretPos) { 
  var caretPos = document.creator.message.caretPos; 
  caretPos.text = anystr; 
} 
else if (document.creator.message.setSelectionRange) { 
  var selectionStart = document.creator.message.selectionStart; 
  var selectionEnd =   document.creator.message.selectionEnd; 
  document.creator.message.value = document.creator.message.value.substring(0, selectionStart) + anystr + document.creator.message.value.substring(selectionEnd); 
} 
else { 
  document.creator.message.value+=anystr; 
} 
document.creator.message.focus(); 
}

function showColor(color) {
document.creator.message.value+="[color="+color+"][/color]";
}

/*** click only once for forms ***/
function oneclick(theform){
if (document.all||document.getElementById){
  for (i=0;i<theform.length;i++){
  var tempobj=theform.elements[i]
    if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
    tempobj.disabled=true
  }
} else
return false
}

/*** broadcast message ***/
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

/*** drag drop function for NS 4 ***/
var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

/*** drag drop function for ie4+ and NS6 ***/
function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")

/*** drag drop functions end here ***/

function hidebox(){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}

/*** css dropdown ***/
function toggle( targetId ){
   if (document.getElementById){
         target = document.getElementById( targetId );
            if (target.style.display == "none"){
               target.style.display = "";
            } else {
               target.style.display = "none";
            }
      }
      return false;
}

/*** show hide block ***/
/* by Jos Brown (bantychick) using part of cookie code from post by RonPK,
 Webmaster World thread www.webmasterworld.com/forum91/4917.htm */
function SetBlock(targetId) {
// write the cookie 
var oneyear = new Date(); oneyear.setFullYear(oneyear.getFullYear() + 1); 
document.cookie = targetId + '=' + (getCurrentState(targetId) == 1? 2 : 1) + '; expires=' + oneyear.toGMTString() + '; path=/'; 
MakeBlock(targetId);
return false;
}
function MakeBlock(targetId) { 
var currentState = getCurrentState(targetId);
target = document.getElementById(targetId);
target.style.display = currentState == 1? 'none' : 'block'; 
} 
function getCurrentState(targetId) { 
// returnvalues: 1 (closed), 2 (opened) 
return document.cookie.substr(document.cookie.indexOf(targetId+'=') + targetId.length +1, 1); 
} 
/*** end show hide block ***/

/*** UBBC ***/
function AddText(NewCode) {
if (document.creator.message.createTextRange && document.creator.message.caretPos) {
  var caretPos = document.creator.message.caretPos;
  caretPos.text = NewCode;
} 
else if (document.creator.message.setSelectionRange) {
  var selectionStart = document.creator.message.selectionStart;
  var selectionEnd =   document.creator.message.selectionEnd;
  document.creator.message.value = document.creator.message.value.substring(0, selectionStart) + NewCode + document.creator.message.value.substring(selectionEnd);
}
else {
  document.creator.message.value+=NewCode;
}
document.creator.message.focus();
}

function addCodeA(bCode1,bCode2) { 
var text = getText();
AddTxt = bCode1 + text + bCode2;
AddText(AddTxt);	
}

function getText() {
if (document.creator.message.createTextRange && document.creator.message.caretPos) {
  return document.creator.message.caretPos.text;
} 
else if(document.creator.message.setSelectionRange) {
  var selectionStart = document.creator.message.selectionStart;
  var selectionEnd =   document.creator.message.selectionEnd;
  return document.creator.message.value.substring(selectionStart, selectionEnd);
}
else {
  return '';
}
}

function storeCaret(ftext) {
if (ftext.createTextRange) {
  ftext.caretPos = document.selection.createRange().duplicate();
}
}
/*** End UBBC ***/

function textCounter(field,cntfield,maxlimit) {
cntfield.value = maxlimit - field.value.length;
}

// reload shout box for Firefox
function ReloadShoutBox() { 
 var f = document.getElementById('chatout'); 
 f.src = f.src; 
} 

