/*
* Resize  all  images on  a  page.
*
*/

function countImgs(maxHeight, maxWidth)
{
   var img = document.images;

   var images_url = /^http:\/\/piccat\.com\/images\//;
   
   for (var i = 0; i < img.length; i++) {
	  var img_src = img[i].src;
      if (img[i].width > maxWidth)
		  if (!img_src.match(images_url))
	         img[i].width = maxWidth;
      else if (img[i].height > maxHeight)
		  if (!img_src.match(images_url))
	         img[i].height = maxHeight;
   }
}


/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 */

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

/*
* BBCode panel + help messages
*
*/

// Helpline messages
b_help = "Bold text: [b]text[/b]";
i_help = "Italic text: [i]text[/i]";
u_help = "Underline text: [u]text[/u]";
p_help = "Insert image: [img]http://image_url[/img]";
w_help = "Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url]";
y_help = "Insert YouTube clip: [youtube]http://youtube_url[/youtube]";
a_help = "Close all open bbCode tags";
_help = "";

//Variables for controlling opening and closing tags (function tag)
var b = 2;
var i = 2;
var u = 2;
var q = 2;
var c = 2;
var url = 2;
var img = 2;
var youtube = 2;

//Function for creating non-font tags
function tag(txtarea, v, tagadd, newbut, tagclose, oldbut, name) {
	txtarea.focus();
    if (eval(v)%2 == 0) {
        eval("window.document.postform."+name+".value = newbut;");
		tagadd = unescape(tagadd);
		if (document.all) {
			WrapIE(tagadd);
		}
		else if (document.getElementById) {
			wrapMoz(txtarea, tagadd);
		}
    } else {
        eval("window.document.postform."+name+".value = oldbut;");
		tagclose = unescape(tagclose);
		if (document.all) {
			WrapIE(tagclose);
		}
		else if (document.getElementById) {
			wrapMoz(txtarea, tagclose);
		}
    }
    eval(v+"++;");
}

// IE only - wraps selected text with lft and rgt
  function WrapIE(lft) {
      document.selection.createRange().text = lft + document.selection.createRange().text;
  }

// Moz only - wraps selected text with lft
  function wrapMoz(txtarea, lft) {
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    if (selEnd==1 || selEnd==2) selEnd=selLength;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd)
    var s3 = (txtarea.value).substring(selEnd, selLength);
    txtarea.value = s1 + lft + s2 + s3;
  }

// Shows the help messages in the helpline window
function helpline(help) {
	// document.post.helpbox.value = eval(help + "_help");
	if ( help.length<5 )
	{
		document.getElementById('helpbox').innerHTML = eval(help + "_help");
	}
	else
	{
		document.getElementById('helpbox').innerHTML = help;
	}
}

// Dropdown menu
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("userNavDropdown");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
 
if (document.all&&document.getElementById) {
navRoot = document.getElementById("mainNavDropdown");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;