var mInfoPanelWidth = 320;
var themeCookieName = "growuptheme";
var journalDateCookieName = "growupjournalDate";
var hlightItemsCookieName = "growuphlightitems";
var slideControlCookieName = "growupslidecontrol";
var periodListScrollCookieName = "growupperiodlistscroll";
var itemPageTipDisdplayCookieName = "growupitempagetipdisplay";
var addPeriodTipDisdplayCookieName = "growupaddperiodtipdisplay";
/*
var periodSortMidCookieName = "growupperiodsortmid";
var periodSortRightCookieName = "growupperiodsortright";
*/
/*
var itemlistSortBoxCookieName = "growupitemlistsortbox";
*/
var itemlisDetailInfoCookieName = "growupitemlisDetailInfo";
var timelineDisplay = "growuptimelinedisplay";
var maxpageitemcount = "growupmaxpageitemcount";
var displayitemnum = "growupdisplayitemnum";
var displayiteminfo = "growupdisplayiteminfo";
var leftTabCurrent = "growuplefttabcurrent";
var leftColumnExpand = "growupleftcolumnexpand";
var eventTargets = new Array();
/*
window.onerror = function(msg, err_url, line) {
alert('an error occured on line: ' + line);
}
*/
function dn() {}
function refresh(url) {
  location.href=url;
}
function isEmptyString(s) {
  return (s==null || trim(s).length==0);
}
/*
function isDate(s) {
  return (isEmptyString(trim(s)) || s.length==10); 
}
*/
function isDateTime(s) {
  var msg = 'Format is "mm/dd/yyyy" or "mm/dd/yyyy HH:mm:ss"';
  if (isEmptyString(trim(s))) return true;
  else if (s.length==10) return isDate(s,true);
  else if (s.length!=19) {
    alert(msg);
    return false;
  }
  else {
    var s1 = trim(s.substr(10)).split(":");
    if (s1.length!=3) {
      alert(msg);
      return false;
    }
    else {
      for (var i=0; i<3; i++) {
        if (!isInteger(s1[i])) {
          alert(msg);
          return false;
        }
      }
    }
  }
  return true;
}
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
}
function replaceStr(inStr,oldStr,newStr) {
  // This method is used to match a specifed regular expression(OldStr) against a string(inStr)
  // and replace any match with a new substring(newStr).
  var ret = inStr;
  while (ret.indexOf(oldStr)>-1) {
      ret = ret.replace(oldStr,newStr);
  }
  if (arguments.length>3) {
    for (var i=3; i<arguments.length; i+=2)
      ret = replaceStr(ret, arguments[i], arguments[i+1]);
  }
  return ret;
}

function movie(dir,name) {
  var newWindow;
//    newWindow = window.open("playWmv.jsp?dir="+escape(dir)+"&file="+escape(name),"movie","width=400,height=300,status=no,toolbar=no,menubar=no,location=no")
    newWindow = window.open("playFlv.jsp?dir="+escape(dir)+"&file="+escape(name),"movie","width=346,height=320,status=no,toolbar=no,menubar=no,location=no,resizable=no")
    newWindow.focus();
}

/* This function is used to set cookies */
function setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

/* This function is used to get cookies */
function getCookie(name) {
	var prefix = name + "="
	var start = document.cookie.indexOf(prefix)

	if (start==-1) {
		return null;
	}

	var end = document.cookie.indexOf(";", start+prefix.length)
	if (end==-1) {
		end=document.cookie.length;
	}

	var value=document.cookie.substring(start+prefix.length, end)
	return unescape(value);
}
/* This function is used to delete cookies */
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function rememberUser(v) {
    var expires = new Date();
    expires.setTime(expires.getTime() + 24 * 3 * 60 * 60 * 1000); // sets it for approx 3 days.
    // sets it for entire domain, so freeroller will remember for all users
    setCookie("usitdphotouser",v,expires,"/");
}

function forgetUser() {
    deleteCookie("usitdphotouser","/");
}
function getRandom(size) /* 0-size*/
{return Math.round(Math.random()*(size-1));}

var effectsArray=new Array('Appear','Grow','BlindDown','SlideDown','PhaseIn'); // todo add more effects
var offArray=new Array('Shrink','Fade','SlideUp','PhaseOut','Puff'); // todo add more effects

function slideDown(id) { if ($(id)) new Effect.SlideDown(id, { duration: 0.5});}
function slideUp(id) { if ($(id)) new Effect.SlideUp(id, { duration: 0.5 });}

function clear(id) { if ($(id)) $(id).innerHTML=""} 
function hide(id) { if ($(id)) $(id).style.display="none"}
function show(id) { if ($(id)) $(id).style.display="block"}
function mhide(id) { if ($(id)) $(id).style.display="none"}
function mshow(id) { if ($(id)) $(id).style.display="block"}
function ishow(id) { if ($(id)) $(id).style.display="inline"}
function nhide(id) { if ($(id)) $(id).style.left="-9000px"}
function ashow(id,opacity,opacity1) {  if (opacity==null) opacity=0.0; if (opacity1==null) opacity1=1.0;if ($(id)) new Effect.Appear(id, { duration: 1.0 , from:opacity, to: opacity1});}
function avshow(id) {
  if ($(id)) {
    var idx = getRandom(effectsArray.length);
    eval('new Effect.'+effectsArray[idx]+'(id, { duration: 1.0 , from:0.0, to: 1.0})');
//    new Effect.Appear(id, { duration: 1.0 , from:0.0, to: 1.0});
  }
}
function ahide(id,opacity,dur) {
  if (opacity==null) opacity=0.0;
  if (dur==null) dur=1.0;
  if ($(id)) {
      new Effect.Fade(id, { duration: dur, from:1.0, to:opacity });
  }
}
function vhide(id) { if ($(id)) $(id).style.visibility="hidden"}
function vshow(id) { if ($(id)) $(id).style.visibility="visible"}
function toggle(id) { if ($(id).style.display=="block") $(id).style.display="none"; else $(id).style.display="block"; }
function toggleBox(id,imgId,cookie,status) { //status:0 closed, 1:opened
  var o = $(imgId);
  var toClose = status==null ? o.src.indexOf("minus")>-1 : status==0;
  if (toClose) {
    o.src="images/plus.gif";
    o.title="expand";
    $(id).style.display = "none";
    if (cookie) setCookie(cookie,0);
  }
  else {
    o.src="images/minus.gif";
    o.title="collapse";
    $(id).style.display = "block";
    if (cookie) setCookie(cookie,1);
  }
}

function ellipsis(s,l) {
  if (s.length>l) return s.substr(0,l)+"...";
  else return s;
}
function gotoUrl(url) {   
  location.href=url;
}
function gotoUrlTop(url) {
  parent.location.href=url;
}

function doAvoidDoubleSubmit() {
  if ($("btnSubmit")) $("btnSubmit").disabled = true;
}
function isValidString(s,ValidChars)
{
  if (ValidChars==null) ValidChars = "0123456789abcdefghijklmnopqrstuvwxyz_- ";
  var isValidString=true;
  var Char;
  for (var i = 0; i < s.length && isValidString; i++)
  {
    Char = s.toLowerCase().charAt(i);
    if (ValidChars.indexOf(Char) == -1)
       isValidString = false;
  }
  return isValidString;

}
function isInValidString(s,inValidChars)
{
  if (inValidChars==null) inValidChars = "_-'\"!@#$%^&*()+|}{[];:,.<>/?~`";
  var Char;
  for (var i = 0; i < s.length; i++)
  {
    Char = s.toLowerCase().charAt(i);
    if (inValidChars.indexOf(Char) > -1)
       return true;
  }
  return false;

}

function setMinHeight(id,h) {
  if ($(id).offsetHeight<h) {
    $(id).style.height=h+"px";
  }

}

function selectAllCheckBox(checkBoxName, flag) {
   var objs=document.getElementsByName(checkBoxName);
   for (var i=0; i<objs.length;i++) {
    objs[i].checked = flag;
   }
}
function selectAllCheckBoxImg(checkBoxName, imgId) {
   var flag=$(imgId).src.indexOf('uncheck')>-1;
   selectAllCheckBox(checkBoxName,flag);
   if (flag) {
     $(imgId).src='images/checkall.gif';
     $(imgId).title="Uncheck All";
   }
   else {
     $(imgId).src='images/uncheckall.gif';
     $(imgId).title="Check All";
   }
}

function indexOfArray(ar, e) {
  for (var i=0; i<ar.length; i++) {
    if (ar[i]==e) return i;
  }
  return -1;
}
function callout(left,top,w,title,content,dur,w1) {
  if (dur==null) dur=2;
  if (w1==null) w1=117;
  $('callout').style.left = left + 'px';
  $('callout').style.top = top + 'px';
  $('callout').style.width = w + 'px';
  if (!isEmptyString(content)) {
    $('co_mbox').innerHTML = content;
    $('co_tmt').innerHTML = title;
  }
  $('co_tm').style.width=(w-10)+'px';
  $('co_brb').style.width=w1+'px';
  mshow('co_blb');
  mhide('co_blbn');
  if (isEmptyString(title)) vhide('calloutClose');
  else vshow('calloutClose');
  Element.hide('callout');

  $('callout').style.visibility="visible";
  new Effect.Appear('callout',{from:0.05, to:.9, duration:dur});
}
function isCheckedCheckbox(chkName) {
  var objs = document.getElementsByName(chkName);
  for (var i=0;i<objs.length; i++) {
    if (objs[i].checked) return true;
  }
  return false;
}
function gushow(id,sec) {
  setTimeout(function(){if (di==0) show(id)},sec*1000);
}
function guhide(id,sec) {
  setTimeout(function(){if (di==0) hide(id)},sec*1000);
}
function guvshow(id,sec) {
  setTimeout(function(){if (di==0) vshow(id)},sec*1000);
}
function guvhide(id,sec) {
  setTimeout(function(){if (di==0) vhide(id)},sec*1000);
}
function guap(id,sec) {
  setTimeout(function(){if (di==0) new Effect.Appear(id, { duration: 1.0 , from:0.0, to: 1.0});},sec*1000);
}
function gufa(id,sec) {
  setTimeout(function(){if (di==0) new Effect.Fade(id, { duration: 1.0});},sec*1000);
}
// move list items from "from" list to "to" list.
// "from" and "to" are multiple lists.
function moveList(from,to,disabledClassname) {
  if (disabledClassname==null) disabledClassname="disabled";
  var fromList = $(from);
  var fromLen = fromList.options.length;

  var toList = $(to);
  var toLen = toList.options.length;

  var current = getSelectedIndex(from);
  while (current>-1) {
    var o = fromList.options[current];
    var s = o.selected;
    var t = o.text;
    var v = o.value;
    var className = o.className;
    if (s) {
      if (className!=disabledClassname) {
        // add to selected list
        toList.options[toLen]= new Option(t, v, false, false);
        if (!isEmptyString(className)) toList.options[toLen].className = className;
        toLen++;
        // delete from "from" list
        fromList.options[current]=null;
      }
      else
        fromList.options[current].selected=false;
      current = getSelectedIndex(from);
    }
  }

  setDefaultSelection(from);
  setDefaultSelection(to);
}

// set default selection as the first of the list
function setDefaultSelection(alist) {
  if (!$(alist)) return;
  var lst = $(alist);
  var len = lst.options.length;
  if (len>0)
    lst.options[0].selected=true;
}

// set default selection as specified
function setSelection(alist,index) {
  if (!$(alist)) return;
  setSelectionIndex(alist,index);
}

// set all selection for the list
function setAllSelection(alist) {
  if (!$(alist)) return;
  var lst = $(alist);
  var len = lst.options.length;
  for (var i=0;i<len; i++) {
    lst.options[i].selected=true;
  }
}

// clear a list
function clearList(alist,isDummy) {
  if (!$(alist)) return;
  var lst = $(alist);
  var len = lst.options.length;
  for (var i = (len-1); i >= 0; i--){
    lst.options[i]= null;
  }
  if (isDummy!=null && isDummy) {
    lst.options[0]= new Option("", "", false, false);
  }
}
// get current selected index
function getSelectedIndex(alist) {
  return $(alist).selectedIndex;
}

// get current selected name
function getSelectedName(alist) {
  var i = $(alist).selectedIndex;
  if (i>-1)
    return $(alist).options[i].text;
  else
    return "";
}

// get current selected value
function getSelectedValue(alist) {
  if ($(alist) && isType(alist,"select")) {
    return $(alist).value;
  }
  else return "";
}

function getAllValue(alist) {
  var ret = "";
  var lst = $(alist);
  var len = lst.options.length;
  for (var i=0; i<len; i++) {
    ret += lst.options[i].value+',';
  }
  return ret.substring(0,ret.length-1);
}

// check if the item (which value is v) is in the alist
function lstIndexOf(alist,v) {
  var ret = -1;
  var lst = $(alist);
  var len = lst.options.length;
  for (var i=0; i<len; i++) {
    if (lst.options[i].value==v)
      ret = i;
  }
  return ret;
}

// object holding list element: text and value
function listObj(text,value) {
  this.text = text;
  this.value = value;
}

// =================== SortList ==============
function sortList(listId,startIndex) {
  if (startIndex==null) startIndex=0;
  var aList = new Array();
  var aText = new Array();
  var keepList = new Array();
  var keepText = new Array();
  var lst = $(listId);
  for (var i=0;i<lst.length;i++) {
    if (i<startIndex) {
      keepList[i] = new listObj(lst.options[i].text,lst.options[i].value);
      keepText[i] = lst.options[i].text;
      aList[i]="";
      aText[i]="";
    }
    else {
      aList[i] = new listObj(lst.options[i].text,lst.options[i].value);
      aText[i] = lst.options[i].text;
    }
  }
  aText.sort();
  clearList(listId);
  for (var i=0;i<aText.length;i++) {
    if (i<startIndex)
      lst.options[i]=new Option(keepText[i],getValueByKey(keepList,keepText[i]));
    else
      lst.options[i]=new Option(aText[i],getValueByKey(aList,aText[i]));
  }
}

function getValueByKey(aList,key) {
  for (var i=0; i<aList.length; i++) {
    if (aList[i].text == key) return aList[i].value;
  }
  return "";
}
// =================== end SortList ==============

// this function will get all selections value from the list "from" and save it to a hidden-var "to"
// from -- single-select selectList id;
// to -- hidden-var id
function getAllSelectionFromList(from,to) {
  var fromList = $(from);
  var toList = $(to);
  var al = new Array(fromList.options.length);
  for (var i=0; i<al.length; i++) {
    al[i]=fromList.options[i].value;
  }
  toList.value = al.join(",");    
}

// this function will get selected text from the list "from" and save it to a hidden-var "to"
// from -- single-select selectList id;
function getAllSelectedText(listId) {
  var fromList = $(listId);
  var al = new Array();
  var j = 0;
  for (var i=0; i<fromList.options.length; i++) {
    if (fromList.options[i].selected)
    al[j++]=fromList.options[i].text;
  }
  return al;
}

function doTextarea(id,isExpand,expandId,contractId) {
  var row = $(id).rows;             
  if (isExpand && row<10) {
    $(id).rows=row+1;
  }
  else if (!isExpand && row>1){
    $(id).rows=row-1;
  }
}
function uploadCompleted(){}
function  r_getFormData(){}
function getParentAll(parent,parentKey) {
  if (!parent) return;
  var id = parent.id;
  while (isEmptyString(id) || id.indexOf(parentKey)==-1) {
    if (parent.tagName && parent.tagName.toLowerCase()=="body") return "";
    parent = parent.parentNode;
    if (!parent) return "";
    id = parent.id;
  }
  return parent;
}
function changImgSrc(o,src) {
  if (o) {
    o.src=src;
  }
}
function getWindowHeight() {
  var win=window;
  var H;
  if (win.innerWidth) {
    H = win.innerHeight;
  } else if (win.document.documentElement && document.documentElement.clientWidth) {
    H = document.documentElement.clientHeight;
  } else {
    H = document.body.offsetHeight
  }
  return H;
}
function getWindowWidth() {
 var win=window;
 var W;
 if (win.innerWidth) {
    W = win.innerWidth;
  } else if (win.document.documentElement && document.documentElement.clientWidth) {
    W = document.documentElement.clientWidth;
  } else {
    W = document.body.offsetWidth;
  }
  return W;
}
function getWindowScrollHeight() {
  return document.body.scrollHeight<1000 ? 1000 : document.body.scrollHeight;
}
function getWindowScrollWidth() {
  return document.body.scrollWidth<1050 ? 1050 : document.body.scrollWidth;
}

function getCursor(event) {
  var ret = new Array();
  ret[0]=Event.pointerX(event);
  ret[1]=Event.pointerY(event);
  return ret;
}

function contains(a, b) {
 // Return true if node a contains node b.
  while (b.parentNode)
    if ((b = b.parentNode) == a)
      return true;
  return false;
}
/*
function addEventTarget(idStart) {
  eventTargets[eventTargets.length]=idStart;
}
function removedEventTarget(idStart) {
  for (var i=0;i<eventTargets.length;i++) {
    if (eventTargets[i]==idStart) {
      return eventTargets.splice(i,eventTargets.length-i+1);
    }
  }
  return new Array();
}*/
function ajaxError() {
  alert('Sorry,we encountered an error while loading it.');
}

var minYear=1000;
var maxYear=3100;
function isDate(dateString,isAlert) {
/* allowed date format
    mm-dd-yyyy,
    mm/dd/yyyy,
    mm.dd.yyyy,
    mm dd yyyy,
    mmm dd yyyy,
    mmddyyyy,
    m-d-yyyy,
    m/d/yyyy,
    m.d.yyyy,
    m d yyyy,
    mmm d yyyy,
    m-d-yy,
    m/d/yy,
    m.d.yy,
    m d yy,
    mmm d yy (yy is 20yy)
    today (any case)
*/
  if (isAlert==null) isAlert = false;
  var strDate;
  var strDateArray;
  var strDay;
  var strMonth;
  var strYear="";
  var intday;
  var intMonth;
  var intYear;
  var booFound = false;
  var strSeparatorArray = new Array("-"," ","/",".");
  var intElementNr;
  var err = 0;

  var strMonthArray = new Array(12);
  strMonthArray[0] = "January";
  strMonthArray[1] = "February";
  strMonthArray[2] = "March";
  strMonthArray[3] = "April";
  strMonthArray[4] = "May";
  strMonthArray[5] = "June";
  strMonthArray[6] = "July";
  strMonthArray[7] = "August";
  strMonthArray[8] = "September";
  strMonthArray[9] = "October";
  strMonthArray[10] = "November";
  strMonthArray[11] = "December";
  strDate = trim(dateString);

  if (strDate.toLowerCase()=="today") return new dateObj().toString();
  if (strDate.length < 1) return true;

  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
    if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);
      if (strDateArray.length != 3) {
        err = 1;
        if (isAlert) alert("Invalid date");
        return false;
      }
      else {
        strDay = strDateArray[0];
        strMonth = strDateArray[1];
        strYear = strDateArray[2];
      }
      booFound = true;
    }
  }
  if (booFound == false) {
    if (strDate.length>5) {
      strDay = strDate.substr(0, 2);
      strMonth = strDate.substr(2, 2);
      strYear = strDate.substr(4);
    }
  }
  if (strYear.length == 2)
    strYear = '20' + strYear;

  strTemp = strDay;
  strDay = strMonth;
  strMonth = strTemp;

  intday = parseInt(strDay, 10);

  if (isNaN(intday)) {
    err = 2;
    if (isAlert) alert("Invalid day");
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i = 0;i<12;i++) {
      if (strMonth.length<=strMonthArray[i].length &&
          strMonthArray[i].toUpperCase().indexOf(strMonth.toUpperCase())==0) {
        intMonth = i+1;
        strMonth = strMonthArray[i];
        i = 12;
      }
    }
    if (isNaN(intMonth)) {
      err = 3;
      if (isAlert) alert("Invalid month");
      return false;
    }
  }

  if (strYear.length>4) {
    if (isAlert) alert("Invalid year");
    return false;
  }
  intYear = parseInt(strYear, 10);
  if (isNaN(intYear) || intYear<minYear || intYear>maxYear) {
    err = 4;
    if (isAlert) alert("Invalid year");
    return false;
  }
  if (intMonth>12 || intMonth<1) {
    err = 5;
    if (isAlert) alert("Invalid month");
    return false;
  }

  if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
    err = 6;
    if (isAlert) alert("Invalid day");
    return false;
  }
  if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
    err = 7;
    if (isAlert) alert("Invalid day");
    return false;
  }

  if (intMonth == 2) {
    if (intday < 1) {
      err = 8;
      if (isAlert) alert("Invalid day");
      return false;
    }
    if (LeapYear(intYear) == true) {
      if (intday > 29) {
        err = 9;
      if (isAlert) alert("Invalid day");
        return false;
      }
    }
    else {
      if (intday > 28) {
        err = 10;
        if (isAlert) alert("Invalid day");
        return false;
      }
    }
  }
  return  formatTwoDigits(intMonth) + "/" + formatTwoDigits(intday)+"/" + strYear;
//  return true;
}
function formatTwoDigits(s) {
  if (s<10) return "0"+s;
  else return s;
}
function LeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) { return true; }
  }
  else {
    if ((intYear % 4) == 0) { return true; }
  }
  return false;
}

function validDate(obj){
  var date=obj.value;
  if (/[^\d/]|(\/\/)/g.test(date))  {obj.value=obj.value.replace(/[^\d/]/g,'');obj.value=obj.value.replace(/\/{2}/g,'/'); return }
  if (/^\d{2}$/.test(date)){obj.value=obj.value+'/'; return }
  if (/^\d{2}\/\d{2}$/.test(date)){obj.value=obj.value+'/'; return }
  if (!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(date)) return

  var test1=(/^\d{1,2}\/?\d{1,2}\/\d{4}$/.test(date))
  date=date.split('/')
  d=new Date(date[2],date[0]-1,date[1])
  var test2=(1*date[1]==d.getDate() && 1*date[0]==(d.getMonth()+1) && 1*date[2]==d.getFullYear())
  if (test1 && test2) return true
  alert("Invalid date")
  obj.select();
  obj.focus()
  return false
}

function trimString(s,ts) {
  if (ts ==null) ts='\'"';
  var isValidString=true;
  var c;
  var ret = '';
  for (var i = 0; i < s.length; i++) {
    c = s.charAt(i);
    if (ts.indexOf(c) == -1) ret+=c;
  }
  return ret;
}
function isInteger(s) {
  for (var i = 0; i < s.length; i++){
      // Check that current character is number.
      var c = s.charAt(i);
      if (((c < "0") || (c > "9"))) return false;
  }
  return true;
}

function getStringByint(intValue, len) {
  var s = intValue;
  if (s.length<len)
    for (var i=s.length; i<len; i++) s="0"+s;
  return s.substring(s.length-len);
}
function getMygrowupPathByUid(uid) {
  var sUserId = getStringByint(uid,gFILE_SERVER_USER_ID_LEN);
  return sUserId.substring(0,4) + "/" +
                sUserId.substring(4,7) + "/" +
                sUserId.substring(7);

}
function math_round(v,dec) {
  return Math.round(v*Math.pow(10,dec))/Math.pow(10,dec);
}
function writeMonthList(userId, periodId) {
  var aLine = '';
  aLine +='<select id="lstMonth" onchange="editJournal_validateDate(false,'+userId+','+periodId+');">';
  for (var i=1;i<13;i++) {
    aLine +='<option value="'+i+'">'+i+'</option>';
  }
  aLine +='</select>';
  document.write(aLine);
}
function writeDayList(userId,periodId) {
  var aLine = '';
  aLine +='<select id="lstDay" onchange="editJournal_validateDate(false,'+userId+','+periodId+');">';
  for (var i=1;i<32;i++) {
    aLine +='<option value="'+i+'">'+i+'</option>';
  }
  aLine +='</select>';
  document.write(aLine);
}
function getYear(d) { //d ='mm/dd/yyyy'
  return parseInt(d.substr(6),10);
}
function getMonth(d) { //d ='mm/dd/yyyy'
  return parseInt(d.substr(0,2),10);
}
function getDay(d) { //d ='mm/dd/yyyy'
  return parseInt(d.substr(3,2),10);
}
function replace160(s) { // replace &nbsp; to space
  var ret = '';
  for (var i=0;i<s.length;i++) {
    var c = s.charCodeAt(i);
    if (c==160) {
      ret+=' ';
    }
    else {
      ret+=s.charAt(i);
    }
  }
  return ret;
}
function changeBrokenImg(name, newImg, elementType) { 
  var objs ;
  if (elementType=="className")
   objs = $$('.'+name);
  else if (elementType=="tagName")
    objs = document.getElementsByTagName(name);
  else if (elementType=="objs")
    objs = name;
  else {  //  elementId
    objs = new Array();
    objs[objs.length] = document.getElementById(name);
  }
  for (var i=0;i<objs.length;i++) {
    if (objs[i].offsetHeight<40) {
     objs[i].src=newImg;
    }
  }
}


function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

function validateDateLength()  {
  var bd = $('birthday').value;
  if (trim(bd).length!=10) {
    alert('Invalid date. Date format is "mm/dd/yyyy".');
    return false;
  }
  else return true;
}
function showAjaxInfo(id)  {
  mshow(id);
  $(id).style.backgroundColor='lightyellow';
  if ($(id).innerHTML.indexOf('fail')>-1)
    $(id).style.color='red';
  else
    $(id).style.color='green';
  setTimeout(function(){
    $(id).innerHTML='';
    mhide(id);
  },3000)

}

function orderManager(listName,param,delTo) {
  var l = $(listName);

  var len = l.options.length;
  if (len==0) return false;

  var curIndex = l.selectedIndex;
  if (curIndex==-1) {
//        alert("Please select ...");
    return false;
  }

  var text = l.options[curIndex].text;
  var value = l.options[curIndex].value;

  var moveIndex = -1;
  if (param=="up") moveIndex = (curIndex>0) ? curIndex-1 : 0;
  if (param=="down") moveIndex = (curIndex<len-1) ? curIndex+1 : len-1;
  if (param=="top") moveIndex=0;
  if (param=="bottom") moveIndex=len-1;
  if (param=="up" || param=="down" || param=="top" || param=="bottom" ) {
    l.options[curIndex].text = l.options[moveIndex].text;
    l.options[curIndex].value = l.options[moveIndex].value;
    l.options[moveIndex].text = text;
    l.options[moveIndex].value = value;
    l.selectedIndex = moveIndex;
  }
  if (param=="del") {
//        if (confirm("Delete?"))
    if (delTo!=null) {
      $(delTo).options[$(delTo).length]=new Option(l.options[curIndex].text, l.options[curIndex].value, false, false);;
    }
    l.options[curIndex] = null;
    if (curIndex==0)  {
        if (l.length>0) l.selectedIndex = 0;
    }
    else if (curIndex>0) {
        l.selectedIndex=curIndex-1;
    }
  }
}
function getHelp(id, e) {
  setTimeout(function(){
    var url="ajaxHelp.htm?helpId="+id;
    if (_debug) {_debug.message('url',url);}
    new Ajax.Updater('dummy',url,{asynchronous:false, evalScripts:true,onComplete: function(){
      if (_debug) {_debug.message('callout content',$('dummy').innerHTML);}
      var c = getCursor(e);
      var dur=2;
      var cLength = 1000;
      var tLength = $('hContent').innerHTML.length>cLength?70:50;
      var w = $('hContent').innerHTML.length>cLength? 500:400;
      var w1=$('hContent').innerHTML.length>cLength? 467:367;
      $('callout').style.width = w + 'px';
      $('co_mbox').innerHTML = $('hContent').innerHTML;
      $('co_tmt').innerHTML = $('hTitle').innerHTML.length>tLength?$('hTitle').innerHTML.substr(0,tLength)+'...':$('hTitle').innerHTML;
      $('co_tmt').title = $('hTitle').innerHTML;
      $('co_tm').style.width=(w-10)+'px';
      $('co_brb').style.width=w1+'px';
      $('callout').style.left = (c[0]-10) + 'px';
      $('callout').style.top = (c[1]-$('callout').offsetHeight<0?0:c[1]-$('callout').offsetHeight-4) + 'px';
      var outerWidth = $('.outer') ? $$('.outer')[0].offsetWidth : document.body.offsetWidth;
      if (_debug) {
        _debug.message('outerWidth',outerWidth);
      }
      if (c[1]-$('callout').offsetHeight<0 || c[0]-10+$('callout').offsetWidth>outerWidth) {
        mshow('co_blbn');
        mhide('co_blb');
      }
      else {
        mhide('co_blbn');
        mshow('co_blb');
      }
      if (c[0]-10+$('callout').offsetWidth>outerWidth) {
        $('callout').style.left = (outerWidth-$('callout').offsetWidth)+'px';
      }
      Element.hide('callout');
      $('callout').style.visibility="visible";
      new Effect.Appear('callout',{from:0.05, to:.9, duration:dur});
    }});
  },100);
}

function NameValueObj(name,value) {
  this.name = name;
  this.value = value;
}
function getRandomByDate() {
  var d = new Date();
  return d.getFullYear().toString()+
         d.getMonth().toString()+
         d.getDate().toString()+
         d.getHours().toString()+
         d.getMinutes().toString()+
         d.getSeconds();
}

function getRdmStr(len) {
  var str= "abcdefghijklmnopqrstuvwxyz";
  var ret= new Array();
  for(var i=0;i<len;i++){
    ret[i]=str.substr(getRandom(26),1);
  }
  return ret.join('');
}
function getRdmDigitStr(len) {
  var str= "1234567890";
  var ret= new Array();
  for(var i=0;i<len;i++){
    ret[i]=str.substr(getRandom(9),1);
  }
  return ret.join('');
}
function trimHash(a,trimKey) {
  if (a.get(trimKey)) a.unset(trimKey);
}

function copyListAll(from,to,isSelectAll) {
  if (isSelectAll==null) isSelectAll=false;
  clearList(to);

  var fromList = $(from);
  var fromLen = fromList.options.length;

  var toList = $(to);
  var toLen = toList.options.length;

  for (var i=0; i<fromLen; i++) {
    var o = fromList.options[i];
    var s = o.selected;
    var t = o.text;
    var v = o.value;
    var optionName = new Option(t, v, false, false);
    toList.options[i]= optionName;
    if (s || isSelectAll)
      toList.options[i].selected=true;
  }
}

function getRadio(formId,radioName) {
  f = $(formId);
  c = document.getElementsByName(radioName);
  l = c.length;
  for (var i=0; i<l; i++) {
    if (c.item(i).checked) return c.item(i).value;
  }
  return "";
}
function setRadio(formId,radioName,v) {
  var f = $(formId);
  var c = document.getElementsByName(radioName);
  var l = c.length;
  for (var i=0; i<l; i++) {
    c.item(i).checked=(c.item(i).value==v);
  }
}
function setChecked(checkboxName,checkedArray) {
  var objs = document.getElementsByName(checkboxName);
  for (var i=0; i<objs.length; i++)
    if (indexOfArray(checkedArray,objs[i].id)>-1) objs[i].checked=true;
}
function getChecked(checkboxName,checkedArray) {
  checkedArray = new Array();
  var objs = document.getElementsByName(checkboxName);
  for (var i=0; i<objs.length; i++)
    if (objs[i].checked) checkedArray[checkedArray.length]=objs[i].id;
}
function getRadioId(formId,radioName) {
  var f = $(formId);
  var c = document.getElementsByName(radioName);
  var l = c.length;
  for (var i=0; i<l; i++) {
    if (c.item(i).checked) return c.item(i).id;
  }
  return "";
}
Element.addMethods({
   descendantOfAnd: function(element,ancestor) {
     element = $(element), ancestor = $(ancestor);
     return (element.descendantOf(ancestor) || element.id == ancestor.id || element==ancestor);
  }
});
var PopWin = {
  width:800,
  height:500,
  _debug : false,
  sizeLevel:'large',
  init: function(sizeLevel) {   // small:small,middle:middle,large:large
    if (sizeLevel=='small') {
      this.width=400;
      this.height=300;
    }
    else if (sizeLevel=='middle') {
      this.width=600;
      this.height=400;
    }
    else  {//(sizeLevel=='large')
      this.width=800;
      this.height=500;
    }
    this.sizeLevel=sizeLevel;
  },
  open:function(url,left,top) {
    if ($('popWindowBase')) $('popWindowBase').remove();
    Element.insert(document.body.firstChild,{'before':'<div id="popWindowBase" style="display:none"></div><div id="popWindow" style="display:none"></div>'});
    $('popWindowBase').style.height=Element.getDocumentHeight()+'px';
    new Ajax.Updater('popWindow',url,{method:'get',evalScripts:true,onComplete:function(){
      if (MyGrowupError.ajaxError('popWindow')) {
        alert($('popWindow').innerHTML);
        MyGrowupError.ajaxErrorAction('popWindow');
        $('popWindowBase').show();
        $('popWindow').show();
      }
      else {
        var w = $('popWindow');
        w.style.width=PopWin.width+'px';
        w.style.height=PopWin.height+'px';
        if (left==null) left= 0.5*(Element.getViewportWidth()-PopWin.width);
        if (top==null) top= 0.5*(Element.getViewportHeight()-PopWin.height);
        w.style.left = left+'px';
        w.style.top = top+'px';
        $('popWindowBase').show();
        $('popWindow').show();
        if ($('popHeaderIn')) {
          $('popHeaderIn').style.width=(PopWin.width-11)+'px';
          $('popContentIn').style.height=(PopWin.height-36)+'px';
          $('popFooterIn').style.width=(PopWin.width-11)+'px';
          $('editBox').style.height=($('popContentIn').offsetHeight-18)+'px';
          new Draggable('popWindow', {handle:'popHeader',scroll:window,zindex:20009});
        }
        PopWin._popInit();
      }
    }});
  },
  innerOpen:function(hiddenDivId,left,top) {
    if ($('popWindowBase')) $('popWindowBase').remove();
    Element.insert(document.body.firstChild,{'before':'<div id="popWindowBase" style="display:none"></div><div id="popWindow" style="display:none"></div>'});
    $('popWindowBase').style.height=Element.getDocumentHeight()+'px';
    $('popWindow').update($(hiddenDivId).innerHTML);
    var w = $('popWindow');
    w.style.width=PopWin.width+'px';
    w.style.height=PopWin.height+'px';
    if (left==null) left=0.5*(Element.getViewportWidth()-PopWin.width);
    if (top==null) top=0.5*(Element.getViewportHeight()-PopWin.height);
    w.style.left = left;
    w.style.top = top;
    $('popWindowBase').show();
    $('popWindow').show();
    $('popHeaderIn').style.width=(PopWin.width-11)+'px';
    $('popContentIn').style.height=(PopWin.height-36)+'px';
    $('popFooterIn').style.width=(PopWin.width-11)+'px';
    $('editBox').style.height=($('popContentIn').offsetHeight-18)+'px';
    new Draggable('popWindow', {handle:'popHeader',scroll:window,zindex:20009});
    if (Prototype.Browser.IE) {
      $$('#popFooterIn .btn').each(function(item){
        item.style.width=(item.down('input').offsetWidth+10)+'px';
      });
    }
    PopWin._popInit();
  },
  _popInit:function(){},
  close:function(){
    $('popWindowBase').hide();
    $('popWindow').hide();
    $('popWindowBase').remove();
    $('popWindow').remove();
  }
};
Element.addMethods({
   vhide: function(element) {
    element = $(element);
    element.style.visibility = 'hidden';
    return element;
  },

  vshow: function(element) {
    element = $(element);
    element.style.visibility = 'visible';
    return element;
  }     ,
  getViewWidth : function(full){
      return full ? this.getDocumentWidth() : this.getViewportWidth();
  },

  getViewHeight : function(full){
      return full ? this.getDocumentHeight() : this.getViewportHeight();
  },

  getDocumentHeight: function() { // missing from prototype?
      var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
      return Math.max(scrollHeight, this.getViewportHeight());
  },

  getDocumentWidth: function() { // missing from prototype?
      var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
      return Math.max(scrollWidth, this.getViewportWidth());
  },

  getViewportHeight: function() { // missing from prototype?
      var height = self.innerHeight;
      var mode = document.compatMode;

      if ( (mode || Prototype.Browser.IE) && !Prototype.Browser.Opera) {
          height = (mode == "CSS1Compat") ?
                  document.documentElement.clientHeight : // Standards
                  document.body.clientHeight; // Quirks
      }

      return height;
  },

  getViewportWidth: function() { // missing from prototype?
      var width = self.innerWidth;  // Safari
      var mode = document.compatMode;

      if (mode || Prototype.Browser.IE) { // IE, Gecko, Opera
          width = (mode == "CSS1Compat") ?
                  document.documentElement.clientWidth : // Standards
                  document.body.clientWidth; // Quirks
      }
      return width;
  },
 descendantOfAnd: function(element,ancestor) {
   element = $(element), ancestor = $(ancestor);
   return (element.descendantOf(ancestor) || element.id == ancestor.id || element==ancestor);
}
});
var MyGrowupError = {
  errorPageId:'errorPage',
  ajaxError: function(id) {
    return $(id).innerHTML.indexOf(MyGrowupError.errorPageId)>-1;
  },
  ajaxErrorAction:function(id,msg) {
    if (msg==null) msg = '<div class="error">System error. Please try it again.</div>';
    $(id).update(msg);
  }
} ;

function rootUrl2007() {
  setTimeout(function(){
    $$('img').each(function(item){ 
      if (item.src.indexOf('2007/')>-1 || item.src.indexOf('2008/')>-1)
          item.src = (item.src).gsub(rootUrl,'http://www.warminglove.com/mygrowup');
    });
  },2000);
}