function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

//****************************************************************//

function trim(inputString) 
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.

   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user

} // Ends the "trim" function

//Check to validate the email address
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function highlightTextField(field) {
		field.style.borderColor = 'red';
		field.style.borderStyle = 'solid';
		field.style.borderWidth = '1px;';
}

function nohighlightTextField(field) {
		field.style.borderColor = '';
		field.style.borderStyle = '';
		field.style.borderWidth = '';
}

function highlightSelectField(field) {
		field.style.backgroundColor = 'red';
		field.style.color = 'black';
}		

function nohighlightSelectField(field) {
		field.style.backgroundColor = '';
		field.style.color = '';
}	

function check_textfield(field, fieldname, ErrorMsg)
{
	trimmed_string = trim(field.value);
	if (trimmed_string.length == 0) 
	{
		ErrorMsg = ErrorMsg + '- ' + fieldname + '\n';
		highlightTextField(field);
		field.focus();
	}
	else
	{	nohighlightTextField(field);	}
return ErrorMsg;
}

function check_selectfield(field, fieldname, ErrorMsg)
{
	if(field.value == "")
	{
		ErrorMsg = ErrorMsg + '- ' + fieldname + '\n';
		highlightSelectField(field);
		field.focus();
	}
	else
	{	nohighlightSelectField(field);	}

return ErrorMsg;
}

function check_email(field, fieldname, ErrorMsg)
{
	if(!isEmailAddr(field.value))
	{
		ErrorMsg = ErrorMsg + '- ' + fieldname + '\n';
		highlightTextField(field);
		field.focus();
	}
	else
	{	nohighlightTextField(field);	}

return ErrorMsg;
}

//****************************************************************//

function checkStockSearch()
{
	
	var ErrorMsg = '';

	ErrorMsg = check_textfield(document.stocksearch.expr, "Quote Search", ErrorMsg);
	if(ErrorMsg != '') 
	{
		alert('Please complete ALL the following fields to continue:\n' + ErrorMsg);
		return false;
	} 
	else 
	{	
		return true;
	}

}

//Generic Open-Window function
function open_window_ex(url, title, height, width, options) {
    var path = url;
    var opts = '';
	if(options == null || options == "null")
		opts = 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=yes';
    else
		opts = options;
		
	opts += ',width=' + width;
    opts += ',height=' + height;
    mywin=window.open(path,title,opts);
}

//Generic Open-Window function
function open_news(url, title, height, width, options) {
    var path = url;
    var opts = '';
	if(options == null || options == "null")
		opts = 'toolbar=1, location=1, directories=1, status=1, menubar=1, scrollbars=yes, resizable=yes';
    else
		opts = options;
		
	opts += ',width=' + width;
    opts += ',height=' + height;
    mywin=window.open(path,title,opts);
}

function setfocus(field) {
	field.focus();
}


function toggleInterests() {
	var allinterests = document.getElementsByName('allinterests');
	var interests = document.getElementsByName('interests[]');
	for (var i=0; i<interests.length; i++) {
		interests[i].checked = allinterests[0].checked;
	}
}
