
  function JSQuote(post, mem_name, date, posturl) {
    theMessage = '[quote]In reference to post [url='+posturl+']#' + post + '[/url] (by ' + mem_name + ' on ' + date + ' ) in this thread[/quote]';
    if (moz) {
     CurOffset = document.messages['message'].selectionStart;
     CurLine = document.messages['message'].scrollTop;
     document.messages['message'].value = (document.messages['message'].value.substring(0, document.messages['message'].selectionStart)) + theMessage + (document.messages['message'].value.substring(document.messages['message'].selectionEnd, document.messages['message'].value.length));
   } else { 
      document.messages['message'].value += theMessage;
   }
       quote_len = theMessage.length;
       returnFocus(quote_len);
  }

<!-- start popup -->


function PopUp(url, name, width,height,center,resize,scroll,posleft,postop) {
    if (posleft != 0) { x = posleft }
    if (postop  != 0) { y = postop  }

    if (!scroll) { scroll = 1 }
    if (!resize) { resize = 1 }

    if ((parseInt (navigator.appVersion) >= 4 ) && (center)) {
      X = (screen.width  - width ) / 2;
      Y = (screen.height - height) / 2;
    }
    if (scroll != 0) { scroll = 1 }

    var Win = window.open( url, name, 'width='+width+',height='+height+',top='+Y+',left='+X+',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}

<!-- end popup -->
 
function doPreview(myForm, theURL) { 
var oldTarget = myForm.target; 
var oldAction = myForm.action; 
myForm.target = 'message'; 
myForm.action = theURL; 
window.open("", "message", 'toolbar=yes,menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=600,height=600');
myForm.submit();
myForm.target = oldTarget; 
myForm.action = oldAction;
}  


function emoticon(theSmilie) {
  var SmilieLen = theSmilie.length;
  if (ie && document.messages['message'].createTextRange && document.messages['message'].caretPos) {
      var caretPos = document.messages['message'].caretPos;
      caretPos.text = theSmilie + ' ';
   } else if (moz) {
     CurOffset = document.messages['message'].selectionStart;
     CurLine = document.messages['message'].scrollTop;
     document.messages['message'].value = (document.messages['message'].value.substring(0, document.messages['message'].selectionStart)) + theSmilie + (document.messages['message'].value.substring(document.messages['message'].selectionEnd, document.messages['message'].value.length));
   } else { 
     document.messages['message'].value += theSmilie; 
   }
   returnFocus(SmilieLen); 
}


var Agent = navigator.userAgent.toLowerCase();
var ie = ((navigator.appName == 'Microsoft Internet Explorer' || FindItemPop('msie')) && BrowserVer >= 4 ) ? 1 : 0;
var moz = (navigator.appName == 'Netscape' && navigator.product == 'Gecko') ? 1 : 0;
var CurOffset;

function emoticon_popup(theSmilie) {
var SmilieLen = theSmilie.length;

if (ie && window.opener.document.messages['message'].createTextRange && window.opener.document.messages['message'].caretPos) {
      var caretPos = window.opener.document.messages['message'].caretPos;
      caretPos.text = theSmilie + ' ';
  } else if (moz) {
     CurOffset = window.opener.document.messages['message'].selectionStart;
     CurLine = window.opener.document.messages['message'].scrollTop;
     window.opener.document.messages['message'].value = (window.opener.document.messages['message'].value.substring(0, window.opener.document.messages['message'].selectionStart)) + theSmilie + (window.opener.document.messages['message'].value.substring(window.opener.document.messages['message'].selectionEnd, window.opener.document.messages['message'].value.length));
   } else { 
      window.opener.document.messages['message'].value += theSmilie; 
   }
   returnFocusPop(SmilieLen); 
}

function returnFocusPop(ItemLen) {
   if (moz) {
     var curFocus = CurOffset+ItemLen;
     window.opener.document.messages['message'].selectionStart = curFocus;
     window.opener.document.messages['message'].selectionEnd = curFocus;
     window.opener.document.messages['message'].scrollTop = CurLine; 
   }
   window.opener.document.messages['message'].focus();
   window.close();
}

function FindItemPop(search_item) {
	item_index = Agent.indexOf(search_item) + 1;
	return item_index;
}



// ******************
// Redirection
// ******************

function ictredirect(search) { 
 self.location.href = '#' + search; 
}

// ******************
// Browser detection
// ******************
// Sources:
// http://www.quirksmode.org/js/detect.html

var Agent = navigator.userAgent.toLowerCase();
var BrowserVer = parseInt(navigator.appVersion);
var CurOffset;
var CurLine;

var ie = ((navigator.appName == 'Microsoft Internet Explorer' || FindItem('msie')) && BrowserVer >= 4 ) ? 1 : 0;
var moz = (navigator.appName == 'Netscape' && navigator.product == 'Gecko' && !(FindItem('safari'))) ? 1 : 0;
var opera  = (navigator.appName == 'Opera' || FindItem('opera')) ? 1 : 0;

var win = (navigator.platform == 'Win32' || FindItem('win')) ? 1 : 0;
var mac = (FindItem('mac')) ? 1 : 0;

function FindItem(search_item)
{
	item_index = Agent.indexOf(search_item) + 1;
	return item_index;
}

// ******************
// Stack functions
// ******************

var TagStack = new Array();

// Find the ToS
function ToS(StackName){
  for (i = 0; i < StackName.length; i++) {
    if (!StackName[i]) { return i; }
  }
  return StackName.length;
}

// Put item on the stack
function PushToS(StackName, Tag) {
  InsertPoint = ToS(StackName);
  StackName[InsertPoint] = Tag;
}

// Return the top item
function GetToS(StackName) {
  TopPoint = ToS(StackName);
  TopItem = StackName[TopPoint -1];
  return TopItem;
}

// Remove the top item
function KillToS (StackName) {
  TopPoint = ToS(StackName);
  delete StackName[TopPoint -1];
}

// Return the top value and remove it
function GetKillToS (StackName) {
  TopPoint = ToS(StackName);
  TopItem = StackName[TopPoint -1];
  delete StackName[TopPoint -1];
  return TopItem;
}

// Related functions

function CloseTags(StackName) {
  for ( i = ToS(StackName);   i > 0;   i--) {
    code =  '[/' + GetToS(StackName) + ']';
    document.messages['message'].value += code;
    delete StackName[i -1];
  } 
  DispUsedCode (TagStack); 
}

function CloseLastTag(StackName) {
  if (ToS(StackName) > 0 ) {
    code =  '[/' + GetKillToS(StackName) + ']';
    ictCode(code);
  }
}

// ******************
// Checking functions
// ******************

function isUrl(text) {
  return ((text.indexOf('.') > 7) &&
         ((text.substring(0,7) == 'http://') || 
        (text.substring(0,8) == 'https://') || 
         (text.substring(0,6) == 'ftp://')));
}

function isEmail(str) {
  if (!reSupport) { return (str.indexOf('.') > 2) && (str.indexOf('@') > 0); }
  var r1 = new RegExp( '(@.*@)|(..)|(@.)|(^.)' );
  var r2 = new RegExp('^.+@([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$ ');
  return (!r1.test(str) && r2.test(str));
}

// ******************
// Textarea functions
// ******************

function DispUsedCode (StackName) {
  if (document.messages.tagsopen != null) {
    document.messages.tagsopen.value = ' '; 
    for (i = ToS(StackName); i > 0; i--) {
      document.messages.tagsopen.value += '['+StackName[i-1]+'] ';
    }
  }
}

function storeCaret(el) { 
  if (ie && el.createTextRange) {
    el.caretPos = document.selection.createRange().duplicate();
  }
}

function returnFocus(ItemLen) {
   if (moz) {
     var curFocus = CurOffset+ItemLen;
     document.messages['message'].selectionStart = curFocus;
     document.messages['message'].selectionEnd = curFocus;
     document.messages['message'].scrollTop = CurLine; 
   }
   DispUsedCode (TagStack); 
   document.messages['message'].focus();
   
}

function getText() {
  if (ie && document.messages['message'].createTextRange && document.messages['message'].caretPos) {
    return (document.messages['message'].caretPos.text);
  } 
  else if (moz) {
    return (document.messages['message'].value.substring(document.messages['message'].selectionStart, document.messages['message'].selectionEnd));
  }
  else if (document.getSelection) {
    return(document.getSelection());
  } 
  else { return '';}
}

// ******************
// Code functions
// ******************
// code = 'the tag'
// is_complex = add the opened tag to the stack

function ictCode(TextItem) {
  var ItemLen = TextItem.length;
  if (ie &&  win && document.messages['message'].createTextRange && document.messages['message'].caretPos) {
    var caretPos = document.messages['message'].caretPos;
    caretPos.text = TextItem;
  } else if (moz) {
     CurOffset = document.messages['message'].selectionStart;
     CurLine = document.messages['message'].scrollTop;
     document.messages['message'].value = (document.messages['message'].value.substring(0, document.messages['message'].selectionStart)) + TextItem + (document.messages['message'].value.substring(document.messages['message'].selectionEnd, document.messages['message'].value.length));
  } else {
     document.messages['message'].value += TextItem; 
  }
  returnFocus(ItemLen); 
}

// Basic tag handler
function ubbBasic(code) {
  var text = getText();
  if (text) {
    code = '[' + code + ']' + text + '[/' + code + ']';
    ictCode(code);
  } else {
    if ( GetToS(TagStack) == code ) {
      var tag = '[/' + code + ']';
      KillToS(TagStack);
    } else {
      var tag = '[' + code + ']';
      PushToS(TagStack, code);
    } ictCode(tag);
  }
}

// URL's
function TPurl() {
  var url = 'http://'; 
  var desc = '';
  var text = getText();
  if (text) {
    if (isUrl(text)) { 
	  url = text; 
      desc = prompt('Enter Description: (or click OK to use the URL)',desc) || url;
    }
    else { 
      desc = text; 
      url = prompt('Enter URL: (must start http://)',url) || '';
    } 
  } else {
    url = prompt('Enter URL: (must start http://)',url) || '';
    desc = prompt('Enter Description: (or click OK to use the URL)',desc) || url;
  }
  if (!isUrl(url) || !desc ) { returnFocus(); return; }
  var code = '[url=' + url + ']' + desc + '[/url]';
  ictCode(code);
}

// Lists
function TPlist() {
    var write = getText();
    if (!write) { write = ''; }
    write = prompt('Enter Text:',write) || '';
    if ( !write ) { returnFocus(); return; }
    var code = (( write ) ? '' : ' ') + '[*]' + write;
    ictCode(code);
  }

// Email
function TPemail() {
  var email = ''; 
  var desc = '';
  var text = getText();
  if (text) {
    if (text) { 
      email = text; 
      desc = prompt('Enter Description: (or click OK to use the address)',desc) || email;
	}
    else { 
      desc = text; 
      email = prompt('Enter Email Address:',email) || '';
    } 
  } else {
    email = prompt('Enter Email Address:',email) || '';
    desc = prompt('Enter Description: (or click OK to use the address)',desc) || email;
  }
  if (!email || !desc) { returnFocus(); return; }
  var code = '[email=' + email + ']' + desc + '[/email]';
  ictCode(code);
}

function TPflash() {
  var url = 'http://';
  var h = '';
  var w = '';
  var wmin = '10';
  var hmin = '10';
  var text = getText();
  if (text && isUrl(text)) { 
     url = text; text = ''; 
  } else {
     url = prompt('Enter Flash URL:',url) || '';
  }
  w = prompt("Enter Flash Width: (max="+100+" min="+wmin+")",w) || '';
  h = prompt("Enter Flash Height: (max="+100+" min="+hmin+")",h) || '';
  if (w > 100) { w = 100; }
  if (h > 100) { h = 100; }
  if (w < wmin) { w = wmin; }
  if (h < hmin) { h = hmin; }
  if (!isUrl(url) || !h || !w) { returnFocus(); return; }
  var code = ((text) ? text + ' ' : '') + '[flash=' + w + ',' + h + ']' + url + '[/flash]';
  ictCode(code);
}

function TPimage() {
  var url = 'http://';
  var text = getText();
  if (text && isUrl(text)) { 
    url = text; text = ''; 
  } else {
    url = prompt('Enter Image URL: (must start http://)',url) || '';
  }
  if (!isUrl(url)) { returnFocus(); return; }
  var code = ((text) ? text + ' ' : '') + '[img]' + url + '[/img]';
  ictCode(code);
}


function TPimageHelp() {
  var text = getText();
  if (text) { 
    url = text; text = ''; 
  } else {
    url = prompt('Enter Image Name: (The images must be stored in the /skins/help_img/ directory)') || '';
  }
  if (!url) { returnFocus(); return; }
  var code = ((text) ? text + ' ' : '') + '[img]' + url + '[/img]';
  ictCode(code);
}

function DropList(OptionVal,OptionSee,UseStyle) {
  var Listitem;
  Listitem = '<option value="' + OptionVal;
  Listitem += ((UseStyle) ? '" style="color:' + OptionSee: '');
  Listitem += '">' + OptionSee + '</option>';
  return Listitem;
}

function TPFont(list) {
  var text = getText();
  var code;
  var attrib = list.name.substring(0,list.name.length);
  var value = list.options[list.selectedIndex].value;
  if (value && attrib && text) {
    code = '[' + attrib + '=' + value + ']' + text + '[/' + attrib + ']';
    ictCode(code);
  } else {
    if (value && attrib && !text) {
      code = '[' + attrib + '=' + value + ']';
      PushToS(TagStack, attrib);
      ictCode(code);
    }
  }
}

function VerifyTags() {
  var TagOpArray = new Array('');
  var TagClArray = new Array('');
  var textArray = new Array('');
  var Errors = 0;
  var AvailTags = new Array('dummy','b','i','u','s','code','me','list','quote');
  text = document.messages['message'].value;
  textArray = text.split('[');
  for(j=0; j < textArray.length; j++){
    textArray[j] = '[' + textArray[j];
    Item = textArray[j].substring(textArray[j].indexOf('[')+1, textArray[j].indexOf(']'));
    Item = Item.toUpperCase();
    if (Item.charAt(0) == '/') {
      ItemArray = Item.split('/');
      if (GetToS(TagOpArray) ==  ItemArray[1]) {
        KillToS(TagOpArray);
      } else {
        for(h=0 ; h<ToS(AvailTags) ; h++) {
          AvailTags[h] = AvailTags[h].toUpperCase();
          if (AvailTags[h] == ItemArray[1]) {
            PushToS(TagClArray, ItemArray[1]);   
          }
        }     
   
      }
    } else {
      for(k=0 ; k<ToS(AvailTags) ; k++) {
        AvailTags[k] = AvailTags[k].toUpperCase();
        if (AvailTags[k] == Item) {
          PushToS(TagOpArray, Item);
        }
      }      
    }
  }

  if (ToS(TagOpArray)) {Errors = 'opening'};
  if (ToS(TagClArray)) {Errors = 'closing'};
  if (ToS(TagClArray) && ToS(TagOpArray)) {Errors = 'the tags are mismatched'};

  Balance = ToS(TagOpArray) - ToS(TagClArray);
  if (Balance == 0) {
    if (Errors == 0 ) {
      Error = 'none';
    } else {

      Error = 'Correct number of open and close tags but they are in the wrong order';
    }
  }
  else if (Balance < 0) {Error = 'more opening tags are needed'}
  else if (Balance > 0) {Error = 'more closing tags are needed'};
  alert('You have ' + Balance + '  ' + Errors + ' tag errors - ' + Error);
}




function CheckLength(NumAllowed) {
  MessLen  = document.messages.message.value.length;
  ArrayWords = document.messages.message.value.split(" ");
  alert( "You have used " + MessLen + " characters. \n The maximum allowed is "+NumAllowed+" so you can use another "+(NumAllowed-MessLen)+" characters.");
}


function CheckDnld(LangMustAgree,LangSelOpt,tot_file) {

  Agree  = document.membercp.agree.checked;
   if( Agree != true ) {
    alert(LangMustAgree);
    document.membercp.agree.focus();
    return false;
  } 

  file_sel = false;
  for (i=0;i<tot_file;i++) {
  if (document.membercp.file_id[i].checked) file_sel = true;
  }
  if (!file_sel) {
    alert(LangSelOpt);
    return false;
  }
}



function CheckReg(LangNameShort,LangPassShort,LangPassMatch,LangEmailMiss,LangEmailInv,LangMustAgree) {

  NameLen  = document.REG.UserName.value.length;
  if( NameLen < 3 ) {
    alert(LangNameShort);
    document.REG.UserName.focus();
    return false;
  }
  Pass1  = document.REG.PassWord.value;
  Pass2  = document.REG.PassWord_Check.value;
  if (Pass1.length < 5 || Pass2 < 5 ) {
    alert(LangPassShort);
    document.REG.PassWord.focus();
    return false;
  }
  if( Pass1 != Pass2 ) {
    alert(LangPassMatch);
    document.REG.PassWord.focus();
    return false;
  }

  Email  = document.REG.EmailAddress.value.length;
  if( Email==null || Email=="" ) {
    alert(LangEmailMiss);
    document.REG.EmailAddress.focus();
    return false;
  } else {
    apos=document.REG.EmailAddress.value.indexOf("@");
    dotpos=document.REG.EmailAddress.value.lastIndexOf(".");
    lastpos=document.REG.EmailAddress.value.length-1;
    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
      alert(LangEmailInv);
      document.REG.EmailAddress.focus();
      return false;
    }
  }
  Agree  = document.REG.agree.checked;
   if( Agree != true ) {
    alert(LangMustAgree);
    document.REG.agree.focus();
    return false;
  }
}

