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 clearText(thefield){
	if (thefield.defaultValue==thefield.value) {
	 thefield.value = "";
	} else if (thefield.value=='') {
	 thefield.value = thefield.defaultValue;
	} 
}


function redirect_new_portal(vart) {
	var item = document.getElementById(vart);
      	var value_dd = item.options[item.selectedIndex].value;
	temp = '/'+ value_dd + '-portal/news'.toLowerCase();
	temp = temp.toLowerCase();
	temp = temp.replace(/\s/,"_");
	location.href=''+temp+'';
} 
