function word_count_init(max_words) {
    setTimeout('calculate_word_count('+max_words+')', 250);
}

function calculate_word_count(max_words) {
    var content_id = document.getElementById('textarea_id').value;
    var content    = document.getElementById(content_id);
    var num_words  = document.getElementById('num_words');
    
    var words_arr  = content.value.split(/\s+/g); // split the sentence into an array of words
    var word_count = words_arr.length;
    if (words_arr[words_arr.length - 1] == '' || words_arr[words_arr.length - 1] == ' ') word_count--;
    
    if (word_count > max_words) {
        var newstr = '';
        for (var i=0; i < max_words; i++) {
            if (i>0) newstr += " ";
            newstr += words_arr[i];
        }
        content.value = newstr+" ";
    }
    
    num_words.value = word_count;  
    
    setTimeout('calculate_word_count('+max_words+')', 250);
}

function dropdownSubmit(select, formName)
{
    selectedIndex = select.options.selectedIndex;
    selectedValue = select.options[selectedIndex].value;
    if (selectedValue != null && selectedValue != '') {
        document.forms[formName].submit();
    }
}

function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
} 


function toggleOnOff ( targetId, onOff ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			var displayType = (onOff===1) ? "" : "none";
			target.style.display = displayType;
  	}
} 

function change_inner_text ( targetId, text1, text2 ) {
	if (document.getElementById) {
		if ( innerTxt =  document.getElementById( targetId )) {
				if (innerTxt.innerHTML==text1) { 
			    innerTxt.innerHTML = text2;
			  } else {
				innerTxt.innerHTML = text1;
			  } 	
		   }
	}	
}

function pageNav(increment) {
  f=document.pageNavForm;
  if (increment == "next") {
    f.page_num.value++;
  } else {
    f.page_num.value--;
  }
  f.submit();
  return false;
}

function gotoPage(pageNo) {
  f=document.pageNavForm;
  f.page_num.value=pageNo;
  f.submit();
  return false;
}

function openWindow(url, width, height, left, top, name, scroll, resize) {
        if (width==null) width = 500;
        if (height==null) height = 400;
        if (left == null) left = 10;
        if (top == null) top = 10;
        if (name == null) name = 'ptd_popup';
        if (scroll == null) scroll = 'no';
        if (resize == null) resize = 'no';

        window.open(url, name, 'toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars='+scroll+',resizable='+resize+',width='+width+',height='+height+',left='+left+',top='+top, 'replace=false');
}
