function ucFirst(s)
{
	var c = s.charAt(0);

	if (parseInt(s.length)==1){
		return c.toUpperCase();
	}
	else
	{
		return c.toUpperCase() + s.slice(1).toLowerCase();
	}
}
function fromCssToDom(thisLabel)
{
var mySplit = thisLabel.split('-');
// skip the first one
for (i=1;i<mySplit.length;i++)
{
	mySplit[i]=ucFirst(mySplit[i]);
}
thisLabel = mySplit.join('');
return thisLabel;
}
function findInArray(theValue, theArray) {
	var found = false;
	var arrayLength = theArray.length;
	for (var ctr=0; ctr < arrayLength; ctr++){
		if (theValue == theArray[ctr]){
			found=true;
			break;
		}
	}
	return found;
}
function trimString (str) {
  var thisStr = '' + str;
  if (thisStr != '' && (thisStr.search(/^\s+/g) || thisStr.search(/\s+$/g))) {
	  thisStr = thisStr.replace(/^\s+/g, '');
	  thisStr = thisStr.replace(/\s+$/g, '');
  }
  return thisStr;
}
function saidNo(messageString,urlString,setOnCancel,unSetOnCancel) {
	if (confirm(messageString)) {
		document.location.replace(urlString);
		}
	else {
		setOnCancel.checked = 1;
		unSetOnCancel.checked = 0;
		}
	}

/**
 * Throughout, whitespace is defined as one of the characters
 *  "\t" TAB \u0009
 *  "\n" LF  \u000A
 *  "\r" CR  \u000D
 *  " "  SPC \u0020
 *
 * This does not use Javascript's "\s" because that includes non-breaking
 * spaces (and also some other characters).
 */


/**
 * Determine whether a node's text content is entirely whitespace.
 *
 * @param nod  A node implementing the |CharacterData| interface (i.e.,
 *             a |Text|, |Comment|, or |CDATASection| node
 * @return     True if all of the text content of |nod| is whitespace,
 *             otherwise false.
 */
function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}


/**
 * Determine if a node should be ignored by the iterator functions.
 *
 * @param nod  An object implementing the DOM1 |Node| interface.
 * @return     true if the node is:
 *                1) A |Text| node that is all whitespace
 *                2) A |Comment| node
 *             and otherwise false.
 */

function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

/**
 * Version of |previousSibling| that skips nodes that are entirely
 * whitespace or comments.  (Normally |previousSibling| is a property
 * of all DOM nodes that gives the sibling node, the node that is
 * a child of the same parent, that occurs immediately before the
 * reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest previous sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_before( sib )
{
  while ((sib = sib.previousSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |nextSibling| that skips nodes that are entirely
 * whitespace or comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The closest next sibling to |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

/**
 * Version of |lastChild| that skips nodes that are entirely
 * whitespace or comments.  (Normally |lastChild| is a property
 * of all DOM nodes that gives the last of the nodes contained
 * directly in the reference node.)
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The last child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function last_child( par )
{
  var res=par.lastChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.previousSibling;
  }
  return null;
}

/**
 * Version of |firstChild| that skips nodes that are entirely
 * whitespace and comments.
 *
 * @param sib  The reference node.
 * @return     Either:
 *               1) The first child of |sib| that is not
 *                  ignorable according to |is_ignorable|, or
 *               2) null if no such node exists.
 */
function first_child( par )
{
  var res=par.firstChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.nextSibling;
  }
  return null;
}

/**
 * Version of |data| that doesn't include whitespace at the beginning
 * and end and normalizes all whitespace to a single space.  (Normally
 * |data| is a property of text nodes that gives the text of the node.)
 *
 * @param txt  The text node whose data should be returned
 * @return     A string giving the contents of the text node with
 *             whitespace collapsed.
 */
function data_of( txt )
{
  var data = txt.data;
  // Use ECMA-262 Edition 3 String and RegExp features
  data = data.replace(/[\t\n\r ]+/g, " ");
  if (data.charAt(0) == " ")
    data = data.substring(1, data.length);
  if (data.charAt(data.length - 1) == " ")
    data = data.substring(0, data.length - 1);
  return data;
}

/**
 * Adds another method to document to get an array of elements.
 *
 * @param pattern	A RegEx object or string pattern
 * @param flags		Optional only used with string pattern.
 */
document.getElementsByIdRegEx = function() {
	var retVal = false;
	var pattern;
	if (arguments.length > 0) {
		if (typeof(arguments[0]) != 'string') {
			if (arguments[0].exec && arguments[0].test) {
				pattern = arguments[0];
			} else {
				alert('Argument type of object, RegExp object expected.');
			}
		} else {
			if (arguments.length == 2) {
				if (arguments[1].match(/^[igm]$/) || arguments[1] == '') {
					pattern = new RegExp(arguments[0], arguments[1]);
				} else {
					alert('Flags can be one of the following: g, i or m.');
				}
			} else {
				pattern = new RegExp(arguments[0]);
			}
		}

		if (pattern != null) {
			matchedElements = [];
			var elements = document.getElementsByTagName('*');
			for (var i=0; i<elements.length; i++) {
				if (elements[i].id) {
					if (elements[i].id.match(pattern)) { matchedElements.push(elements[i]); }
				}
			}
			
			retVal = matchedElements;
		}
	} 

	return(retVal);
}

function inArray(findThis, inThis) {
	var retval = false;
	for (var i=0;i<inThis.length;i++) {
		if (inThis[i] == findThis) {
			retval = true;
			break;
			}
		}
	return retval;
	}

function hasAncestor(elem, ancestor) {
	var retVal = false;
	if (elem.parentNode) {
		if (elem.parentNode == ancestor) {
			retVal = true;
		} else {
			retVal = hasAncestor(ancestor, elem.parentNode);
		}
	}
	return(retVal)
}

//------------------- for clearing and replacing text in form input fields and textareas -------------------//
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}


//------------------- DATE -------------------//
function date(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write("<p>"+dayarray[day]+" "+montharray[month]+" "+daym+", "+year+"</p>")
}


//------------------- ADD BOOKMARK -------------------//
function addBookmark(title,url) {   
     if (window.sidebar) {   
          window.sidebar.addPanel(title, url,"");   
     } else if( document.all ) {   
          window.external.AddFavorite( url, title);   
     } else if( window.opera && window.print ) {   
          return true;   
     }   
}


