function fixnewlines_textarea(val) {             
  if (val.indexOf('\r\n')!=-1)
    ; // this is IE on windows. Puts both characters for a newline, just what MySQL does. No need to alter
  else if (val.indexOf('\r')!=-1)
    val = val.replace ( /\r/g, "\r\n" );        // this is IE on a Mac. Need to add the line feed
  else if (val.indexOf('\n')!=-1)
    val = val.replace ( /\n/g, "\r\n" );        // this is Firefox on any platform. Need to add carriage return
  else 
    ;                                           // no newlines in the textarea  
  return val;
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
var text = fixnewlines_textarea(obj.value);
if (obj.getAttribute && text.length>mlength) {
obj.value=text.substring(0,mlength);
alert("Please limit the text to " + mlength + " characters.");
}
}

function forwardToSelected(elementid) {
 
   window.location.href = $F(elementid);
   
}

function CheckAll(abc, count, elementid)
{		
		for (i = 0; i < count; i++) {
			document.getElementById (elementid + "_" + i).checked = abc.checked;	
		}
}

function selectOrUnselect(checkBoxName, value)
{
	var check = document.getElementsByName(checkBoxName);
	for (i =0; i < check.length; i++)
	{
		check[i].checked = value;	
	}
}

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo, ignoreLimit)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  

  if (!ignoreLimit && ( Form.Element.getValue(theSelFrom).length + theSelTo.length) > 25) {
	alert('Sorry, you can only select up to 25 fave friends.');
	return;
  }

  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }


  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);
}

function selectAllOptions(selStr)
{
  var selObj = document.getElementById(selStr);
  for (var i=0; i<selObj.options.length; i++) {
    selObj.options[i].selected = true;
  }
}
