/*
function hashLoginPassword(doForm, cur_session_id)
{
	// Compatibility.
	if (cur_session_id == null)
		cur_session_id = smf_session_id;

	if (typeof(hex_sha1) == "undefined")
		return;
	// Are they using an email address?
	if (doForm.user.value.indexOf("@") != -1)
		return;

	// Unless the browser is Opera, the password will not save properly.
	if (typeof(window.opera) == "undefined")
		doForm.passwrd.autocomplete = "off";

	doForm.hash_passwrd.value = hex_sha1(hex_sha1(doForm.user.value.php_to8bit().php_strtolower() + doForm.passwrd.value.php_to8bit()) + cur_session_id);

	// It looks nicer to fill it with asterisks, but Firefox will try to save that.
	if (navigator.userAgent.indexOf("Firefox/") != -1)
		doForm.passwrd.value = "";
	else
		doForm.passwrd.value = doForm.passwrd.value.replace(/./g, "*");
}

function hashAdminPassword(doForm, username, cur_session_id)
{
	// Compatibility.
	if (cur_session_id == null)
		cur_session_id = smf_session_id;

	if (typeof(hex_sha1) == "undefined")
		return;

	doForm.admin_hash_pass.value = hex_sha1(hex_sha1(username.toLowerCase() + doForm.admin_pass.value) + cur_session_id);
	doForm.admin_pass.value = doForm.admin_pass.value.replace(/./g, "*");
}

 */


//details: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(), // Get client info
	clientVer = parseInt(navigator.appVersion), // Get browser version
	is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1)),
	is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));


//http://xavisys.com/2007/03/using-prototype-javascript-to-get-the-value-of-a-radio-group/
function getRadioValue(formName, radioGroup) {
	if($(formName).type && $(formName).type.toLowerCase() == 'radio'){
		var radioGroup = $(formName).name,
			formName = $(el).form;
	}
	else if ($(formName).tagName.toLowerCase() != 'form'){
		return false;
	}
	var checked = $(formName).getInputs('radio', radioGroup).find(
		function(re){
			return re.checked;
		}
	);
	return(checked) ? $F(checked) : null;
}
	

//http://corpocrat.com/2008/08/10/how-to-get-selected-value-in-textarea-using-javascript/
// --> to prototype
function addTags(tag,textarea,extra){
	textarea = $(textarea);
	extra = (!extra) ? '' : extra ;
	var openTag='[' + tag + extra + ']', closeTag='[/' + tag + ']';
	if((clientVer >= 4) && is_ie && is_win){
		if(document.selection){
			textarea.focus();
			var sel = document.selection.createRange();
			sel.text = openTag + sel.text + closeTag;
		}
	}
	else{
		var len = textarea.value.length, start = textarea.selectionStart, end = textarea.selectionEnd, sel = textarea.value.substring(start, end), replace = openTag + sel + closeTag;
		textarea.value =  textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
	}
}

//--> to prototype
function addText(text,textarea){
	textarea = $(textarea);
	if((clientVer >= 4) && is_ie && is_win){
		if(document.selection){
			textarea.focus();
			var sel = document.selection.createRange();
			sel.text = text;
		}
	}
	else if(!isNaN(textarea.selectionStart)){
		var start = textarea.selectionStart, end = textarea.selectionEnd;
		textarea.value = textarea.value.substring(0, start) + text + textarea.value.substring(end, textarea.value.length);
	}
	else{
		textarea.value += text;			
	}
}

function inputSlider(slider,target,disp,handle,min,max,start) {
	new Control.Slider($(slider).down(handle), $(slider), {
		range: $R(min, max),
		sliderValue: start,
		onSlide: function(value) {
			$(target).value = Math.round(value);
			$(disp).update(Math.round(value));
		},
		onChange: function(value) { 
			$(target).value = Math.round(value);
			$(disp).update(Math.round(value));
		}
	});
}

function showOverlay(content){
	$('overlay-inner').update(content);
	Effect.BlindDown('overlay');
	$('overlay-inner').appear();
}

function hideOverlay(){
	$('overlay-inner').fade();
	$('overlay').fade();
	$('overlay-inner').update('');
} 

function formFocus(id,text){
	if($(id).value==text){
		$(id).value='';
	}
}

function formBlur(id,text){
	if($(id).value==''){
		$(id).value=text;
	}
}


// --> port to prototype

/*------------------------------------------------------------------------------
Function:       footnoteLinks()
Author:         Aaron Gustafson (aaron at easy-designs dot net)
Creation Date:  8 May 2005
Version:        1.3
Homepage:       http://www.easy-designs.net/code/footnoteLinks/
License:        Creative Commons Attribution-ShareAlike 2.0 License
                http://creativecommons.org/licenses/by-sa/2.0/
Note:           This version has reduced functionality as it is a demo of 
                the script's development
                
                window.onload = function() {
  					footnoteLinks('content','content');
				}
------------------------------------------------------------------------------*/
function footnoteLinks(containerID,targetID) {
  if (!document.getElementById || !document.getElementsByTagName || !document.createElement) return false;
  if (!document.getElementById(containerID) || !document.getElementById(targetID)) return false;
  var container = document.getElementById(containerID);
  var target    = document.getElementById(targetID);
  var h2        = document.createElement('h2');
  addClass.apply(h2,['printOnly']);
  var h2_txt    = document.createTextNode('Links');
  h2.appendChild(h2_txt);
  var coll = container.getElementsByTagName('*');
  var ol   = document.createElement('ol');
  addClass.apply(ol,['printOnly']);
  var myArr = [];
  var thisLink;
  var num = 1;
  for (var i=0; i<coll.length; i++) {
    var thisClass = coll[i].className;
    if ( coll[i].getAttribute('href') || coll[i].getAttribute('cite') ) { 
      thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
      var note = document.createElement('sup');
      addClass.apply(note,['printOnly']);
      var note_txt;
      var j = inArray.apply(myArr,[thisLink]);
      if ( j || j===0 ) {
          note_txt = document.createTextNode('[' + (j+1) + '] ');
      }
      else {
        var li     = document.createElement('li');
        var li_txt = document.createTextNode('[' + num + '] ' + thisLink);
        li.appendChild(li_txt);
        ol.appendChild(li);
        myArr.push(thisLink);
        note_txt = document.createTextNode('[' + num + '] ');
        num++;
      }
      note.appendChild(note_txt);
      if (coll[i].tagName.toLowerCase() == 'blockquote') {
        var lastChild = lastChildContainingText.apply(coll[i]);
        lastChild.appendChild(note);
      }
      else {
        coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
      }
    }
  }
  target.appendChild(h2);
  target.appendChild(ol);
  addClass.apply(document.getElementsByTagName('html')[0],['noted']);
  return true;
}


/*------------------------------------------------------------------------------
Excerpts from the jsUtilities Library
Version:        2.1
Homepage:       http://www.easy-designs.net/code/jsUtilities/
License:        Creative Commons Attribution-ShareAlike 2.0 License
                http://creativecommons.org/licenses/by-sa/2.0/
Note:           If you change or improve on this script, please let us know.
------------------------------------------------------------------------------*/
if(Array.prototype.push == null) {
  Array.prototype.push = function(item) {
    this[this.length] = item;
    return this.length;
  };
};

// ---------------------------------------------------------------------
//                  function.apply (if unsupported)
//           Courtesy of Aaron Boodman - http://youngpup.net
// ---------------------------------------------------------------------
if (!Function.prototype.apply) {
  Function.prototype.apply = function(oScope, args) {
    var sarg = [];
    var rtrn, call;
    if (!oScope) oScope = window;
    if (!args) args = [];
    for (var i = 0; i < args.length; i++) {
      sarg[i] = "args["+i+"]";
    };
    call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
    oScope.__applyTemp__ = this;
    rtrn = eval(call);
    oScope.__applyTemp__ = null;
	return rtrn;
  };
};

function inArray(needle) {
  for (var i=0; i < this.length; i++) {
    if (this[i] === needle) {
      return i;
    }
  }
  return false;
}

function addClass(theClass) {
  if (this.className != '') {
    this.className += ' ' + theClass;
  } else {
    this.className = theClass;
  }
}

function lastChildContainingText() {
  var testChild = this.lastChild;
  var contentCntnr = ['p','li','dd'];
  while (testChild.nodeType != 1) {
    testChild = testChild.previousSibling;
  } 
  var tag = testChild.tagName.toLowerCase();
  var tagInArr = inArray.apply(contentCntnr, [tag]);
  if (!tagInArr && tagInArr!==0) {
    testChild = lastChildContainingText.apply(testChild);
  }
  return testChild;
}
