
Date.prototype.getTimeDiff = function(unit, dateRef, doNotRound) {
	if(!(dateRef instanceof Date)) {
		return
	}
	
	this.unitValues = this.getUnitsInMilliseconds();

	//offset value always in minutes
	var offset = this.unitValues["mi"] * (this.getTimezoneOffset() - dateRef.getTimezoneOffset());
	
	var oms = dateRef.getTime();
	var mms = this.getTime();

	var diff = mms - oms;
	diff -= offset;
	return (Math.floor(diff / this.unitValues[unit]));
}

Date.prototype.getUnitsInMilliseconds = function() {
	var obj = new Object();
	obj.ms = 1;
	obj.ss = 1000;
	obj.mi = obj.ss * 60;
	obj.hh = obj.mi * 60;
	obj.dd = obj.hh * 24;
	obj.wk = obj.dd * 7;
	obj.mm = obj.dd * 30;
	obj.yyyy = obj.dd * 365;
	return obj;
}

today = new Date();

//Base 64 decryption code starts here
var base64 = [
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' ];

// ***** SWITCH BASE64 CODE ***** 
function switchBase64 () {
  var zz = new Object();
  for (var i = 0; i < 64; i++) {
    zz[base64[i]] = i;
  }
  return zz;
}
var switchedBase64 = switchBase64();

// ***** DECODE THE STRING *****
function decode (B64Str) {
  if (B64Str == "") {
    return ""
  }
  var charIs = new Array();
  var NewStr = "";
  for (var i = 0; i < B64Str.length; i++){
    charIs[i] = switchedBase64[B64Str.charAt(i)];
  }
  for (var i = 0; i < B64Str.length; i += 4) {
    var b24  = (charIs [i] & 0xFF) << 18; 
    b24 |= (charIs[i + 1] & 0xFF) << 12; 
    b24 |= (charIs[i + 2] & 0xFF) << 6;
    b24 |= (charIs[i + 3] & 0xFF) << 0;
    NewStr += String.fromCharCode((b24 & 0xFF0000) >> 16);
    if (B64Str.charAt(i + 2) != '='){
	  NewStr += String.fromCharCode((b24 & 0xFF00) >> 8);
    }
    if (B64Str.charAt(i + 3) != '='){
	  NewStr += String.fromCharCode((b24 & 0xFF) >> 0);
    }
  }
  return NewStr;
}

function RTrim(txt) {
    return txt.replace(/[\s]+$/g, "");
}


// Get cookie info
var userAuthed = iv_getCookie("iv_tkt");
if (!userAuthed || userAuthed == "NA") {
  var userAuthenticated = ""
} else {
  var userAuthenticated = "yes"
}
var iv_spar = iv_getCookie("iv_spar")
if (!iv_spar) { iv_spar = "" };
var childInfo = iv_spar;
if (childInfo != "NA") {
  childInfo = decode(childInfo);
}

// deleting iv_par cookie because as of 1/26/05, parenting info will be saved in session based cookie only
iv_deleteCookie('iv_par','/',".ivillage.com");

// This function will return the age for a given birth date 
// NOTE!!!! birthDate must be in yyyymmdd format - has to be a date in the past
// returns age in this format:  years-months-days so if the age is 2 yrs,4 mths & 15 days, result will be 2-4-15
function getAge(birthDate) {
  var birthDate = birthDate + '';
  var now = new Date();
  var yearNow = now.getFullYear();
  var monthNow = now.getMonth();
  var dateNow = now.getDate();
  var dob = new Date(birthDate.substring(4,6) +'/'+ birthDate.substring(6,8) +'/'+ birthDate.substring(0,4));
  var yearDob = dob.getFullYear();
  var monthDob = dob.getMonth();
  var dateDob = dob.getDate();
  yearAge = yearNow - yearDob;
  if (monthNow >= monthDob)
    var monthAge = monthNow - monthDob;
  else {
    yearAge--;
    var monthAge = 12 + monthNow - monthDob;
  }
  if (dateNow >= dateDob)
    var dayAge = dateNow - dateDob;
  else {
    monthAge--;
    var dayAge = 31 + dateNow - dateDob;
  if (monthAge < 0) {
      monthAge = 11;
      yearAge--; 
    }
  }
  return yearAge + "-" + monthAge + "-" + dayAge;
}

// This function will return the number of DAYS between today and some date in the future 
// NOTE!!!! dueDate must be in yyyymmdd format - should be a date in the future
// if dueDate is in the past, returned number of difference days will be negative
// if dueDate is in the future, returned number of difference days will be positive
function daysBetween(dueDate) {
  var monthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
  var dueDate = dueDate + '';
  var yr = dueDate.substring(0,4)
  var mo = dueDate.substring(4,6)
  var dy = dueDate.substring(6,8)
  var today = new Date()
  var todayYear = today.getFullYear()
  var todayMonth = today.getMonth()
  var todayDay = today.getDate()
  var todayString = monthArray[todayMonth] + " " + todayDay + ", " + todayYear
  var dueDateString = monthArray[mo-1] + " " + dy +", " + yr
  var difference = (Math.round((Date.parse(dueDateString)-Date.parse(todayString)) / (24*60*60*1000)) *1 )
  return difference;
}

// Initialize array called arrChildData
var arrChildData = new Array();
arrChildData["momStatus"] = "";
arrChildData["dueDate"] = "";
arrChildData["defaultStage"] = "";
arrChildData["defaultChildName"] = "";
arrChildData["defaultBirthDate"] = "";

// this uses the cookie info to populate the arrChildData array
// it is called by getRedirectURL and getGreetingTxt
function populateArray(cookieInfo) {
  // pattern is checking for:  starting with any 8 digits
  var datePattern = new RegExp(/^\d{8}/);
  
  // pattern is checking for:  starting with a 'd', followed by any 8 digits
  var defaultDatePattern = new RegExp(/^d+\d{8}/);
  if (defaultDatePattern.test(cookieInfo) != 1) {
    arrChildData["defaultStage"] = "No default setting"
  }
  
  var result = cookieInfo.split('|');
  for (var i = 0; i < result.length; i++) {
    // need to check for this because sometimes cookie could have a trailing pipe
    if (result[i] != "") {    
      var tmp = result[i].split('=')
	  if (tmp[0] == "s") {
	    if (tmp[1] == "0") {
	      arrChildData["momStatus"] = "ttc"
		} else if (tmp[1] == "d0") {
	      arrChildData["momStatus"] = "ttc"
		  arrChildData["defaultStage"] = "ttc"
	    } else {
	      arrChildData["momStatus"] = "No Info"
	    }
	  } else {
	  	  
	    // the following one line will set the b1 thru b5 elements = birthdate and n1 thru n5 elements = name
		// for example: arrChildData["b2"] = 20031028 and arrChildData["n2"] = Sam
	    arrChildData[tmp[0]] = tmp[1]

		
		// if default date is found, remove d at the beginning and set array values
	    if (defaultDatePattern.test(tmp[1]) == 1) {
	      birthDate = tmp[1].substring(1,tmp[1].length)
		  arrChildData["defaultBirthDate"] = birthDate
		  if (daysBetween(birthDate) > 0) {
		    arrChildData["momStatus"] = "pregnant"
			arrChildData["dueDate"] = birthDate
			arrChildData["defaultStage"] = "pregnant"
			arrChildData["unbornChildName"] = arrChildData["n" + tmp[0].substring(1,tmp[0].length)]
		  } else {
		    arrChildData["defaultChildName"] = arrChildData["n" + tmp[0].substring(1,tmp[0].length)]
		    arrChildData["defaultStage"] = getChildStage(birthDate)
		  }		    
	    } else {
	      birthDate = tmp[1]
		  if (daysBetween(birthDate) > 0) {
		    arrChildData["momStatus"] = "pregnant"
		    arrChildData["dueDate"] = birthDate
			arrChildData["unbornChildName"] = arrChildData["n" + tmp[0].substring(1,tmp[0].length)]
		  }
	    }
		
		// pattern is checking for:  starting with 'b', followed by any one digit
	    var bPattern = new RegExp(/^b+\d{1}/);
		
		// if this i is a b1 or b2 type of string, find the n1 or n2 name and set it to the birthdate
		// for example:  this will set arrChildData["Sam"] = 20031028
	    if (bPattern.test(tmp[0]) == 1) {
	      var birthDateIndex = tmp[0].substring(1,tmp[0].length);
		  var childName = arrChildData["n" + birthDateIndex];
	      arrChildData[childName] = birthDate;
	    }
	  }
	}
  }
}

// this function populates the children dropdown box which appears in the custom preg homepage
function getChildrenInfo() {
  if (userAuthenticated != "") {  
    if (childInfo == "") {
	  return;
	} else {
	  populateArray(childInfo);
	  var childrenArray = new Array();
	  var i = 0;
	  	  
	  for (var j=1; j<=5; j++) {
	    var childName = arrChildData["n"+j]
		var birthDate = arrChildData["b"+j]
		
		//alert(childName +" _ "+ birthDate +" _ "+ arrChildData["momStatus"]);
		
		if (birthDate != undefined && birthDate.indexOf('d') == 0) {
		  var birthDate = birthDate.substring(1,birthDate.length)
		} 
		
		//alert(daysBetween(birthDate));
		
		// populate childrenArray only if birthdate is in the past 
		if (daysBetween(birthDate) <= 0 && childName != undefined) {
		  childrenArray[i] = [birthDate,childName];
		  i++;
		
		} else if (daysBetween(birthDate) > 0 && childName != undefined) {
			childrenArray[i] = [birthDate,"pregnant-"+childName];
			i++;  
		 } else {
		 continue;
	  	 }
	   }
	  
	  if (arrChildData["momStatus"] == "ttc" && childrenArray.length != 0) {
	    createOption('',0,'ttc')
	  } 
		
	  if (childrenArray.length == 0) {
	    var selBox = document.getElementById("bleedingSelect");
	    selBox.className=selBox.className+" cat_off";
	  } else if (childrenArray.length == 1 && arrChildData["momStatus"] == "No Info")  {
		var selBox = document.getElementById("bleedingSelect");
	    selBox.className=selBox.className+" cat_off";	  
	  } else {
	    var myInfo = childrenArray.sort(reverseSort);

	    for (k=0; k < myInfo.length; k++) {
	      var bDate = myInfo[k][0];
		  var cName = myInfo[k][1];
		  	if (cName.indexOf("pregnant-") != -1) {	
			 var cNaArr = cName.split('-');
			 displayName = cNaArr[1];
			 
			 var displayYear = bDate.substring(0,4);
			 var displayMonth = bDate.substring(4,6);
			 var displayDay = bDate.substring(6,8);
			 var displayDate = displayMonth +"-"+ displayDay +"-"+ displayYear;
		  	 createOption(displayName +' (due '+displayDate+')',bDate,'pregnancy')
		  } else {	
		  	
		  	createOption(cName,bDate,'')
		  }
		}
	  }	  	  
	}
  }
}

// this is called by getChildrenInfo to dynamically create options for the children dropdown box
// the children dropdown box appears in the custom preg homepage
function createOption(childName, someDate, momStatus) {
  var selBox = document.childForm.selChild;
  var newOption = document.createElement( 'option' );
  if (momStatus == 'ttc') {
    var redirectOID = 'ttc'
	newOption.text = 'You are trying to conceive'
  } else if (momStatus == 'pregnancy') {
    var monthNumber = getPregStage(someDate)
	if (monthNumber == -1) {
	  var redirectOID = getChildStage(someDate)
	  newOption.text = 'Your new baby'
	} else {
      var redirectOID = 'pregnancy_'+getPregStage(someDate)
	  newOption.text = childName
	}
  } else {
    var redirectOID = getChildStage(someDate)
	var tmpvalue = redirectOID.split('_');
	var redirectOIDvalue = tmpvalue[0];
	switch (redirectOIDvalue) 
	 { 
	   case "newborn" : var description = "newborn"; break;
	   case "baby" : var description = "baby"; break;
	   case "tp" : var description = "toddler/preschooler"; break;
	   case "gs" : var description = "gradeschooler"; break;  
       case "tweens" : var description = "tween"; break; 
	   case "teen" : var description = "teen"; break; 
       default : var description = ""; 
	 }
	 
	 	var disYear = someDate.substring(0,4);
		var disMonth = someDate.substring(4,6);
		var disDay = someDate.substring(6,8);
		var disDate = disMonth +"-"+ disDay +"-"+ disYear;
	if (childName != "") {
		newOption.text = childName + " (born " + disDate + ")"
	} else {
	  newOption.text = "Your Child (born " + disDate + ")"
	}
  }
  newOption.value = '/stages/0,,' + redirectOID + ',00.html'
  if (iv_isNS6) {
    selBox.add(newOption, null)
  } else {
    selBox.add(newOption, selBox.length)
  }
}

// this is called by getChildrenInfo to sort the names of the children in 'youngest first' format
function reverseSort(a, b) { 
  if (a > b) {
    return -1;
  } 
  if(a < b) {
    return 1;
  }
  return 0;
} 

// based on due date, returns how many months Mom is currently pregnant
function getPregStage(dueDate) {
  // NOTE!!!! dueDate must be in yyyymmdd format 
  // dueDate should be a date in the future, otherwise -1 will be returned
  // dueDate should also be within 9 months of today, otherwise error will be alerted
  // by Editorial definition:  Pregnancy equals = due date to -(minus) 40 weeks from due date (hence, 40*7=280)
  // for simplicity's sake, we are assuming an average of 30 days in a month - month calculation could be off by 1-2 days depending on the days in the month.
  var numOfDays = daysBetween(dueDate)
  if (numOfDays < 0) {
    return -1;   
  } else if (numOfDays > 280) {
    alert("Due date has to be within 40 weeks from today.")
	return;
  } else {
    // doing +1 here because we need to round down the number of months
	
	var monthsToDueDate = Math.floor(numOfDays / 30)
	if (monthsToDueDate < 9) {
      var monthsPregnant = 9 - monthsToDueDate
	} else {
	  var monthsPregnant = 1
	}
  }
  return monthsPregnant;
}

// this takes a birthdate that occurred in the past and returns the child's stage
function getChildStage(birthDate) {
  // NOTE!!!! birthDate must be in yyyymmdd format
  // birthDate should be a date in the past, otherwise -1 will be returned
  // for simplicity's sake, we are assuming an average of 30 days in a month
  if (birthDate.indexOf('d') == 0) {
    birthDate = birthDate.substring(1,birthDate.length)
  }
  var childAgeResult = getAge(birthDate)
  var childAge = childAgeResult.split('-')
  var childAgeYears = childAge[0]
  var childAgeMonths = childAge[1]
  var childAgeDays = childAge[2]
  
  if (childAgeYears < 0) {
    return -1;
  } else {
     if (childAgeYears == 0 && (childAgeMonths <= 2)) {
	  var i = childAgeMonths
	  var babyStageNbr = ++i;
	  return "newborn_"+ babyStageNbr;
	} else if (childAgeYears == 0 && (childAgeMonths >= 3 && childAgeMonths < 12)) {
	   var babyStageNbr = childAgeMonths - 2
	   return "baby_"+ babyStageNbr;
	} else if (childAgeYears >= 1 && childAgeYears < 5) {
	  return "tp";
	} else if (childAgeYears >= 5 && childAgeYears < 9) {
	  return "gs";
	} else if (childAgeYears >= 9 && childAgeYears < 13) {
	  return "tweens";
	} else if (childAgeYears >= 13 && childAgeYears < 18) {
	  return "teen";
	} else {
	  return "";
	}
  }
}

// This checks the user's cookie info and re-directs the user to the appropriate stage page
function getRedirectURL() {
  if (userAuthenticated == "") {
    return;
  }
  if (childInfo == "") {
    return;
  } else {
   	populateArray(childInfo);
	//alert(arrChildData["defaultStage"])
	
	//no default setting found in cookie
	if (arrChildData["defaultStage"] == "No default setting") {
	  return;
	}
    
	//default = "trying"  - cookie value (s=d0|)
	if (arrChildData["defaultStage"] == "ttc") {
	  document.location.replace('/stages/0,,ttc,00.html');
	  return;
	}
	
	//default not provided - cookie value (s=0|)
	if (arrChildData["defaultStage"] == "" && arrChildData["momStatus"] == "ttc") {
	  document.location.replace('/stages/0,,ttc,00.html');
	  return;
	}
	
	//no info provided - cookie value (s=|)
	if (arrChildData["defaultStage"] == "" && arrChildData["momStatus"] == "No Info") {
	  return;
	}
	    
	//default = "pregnant"
	if (arrChildData["defaultStage"] == "pregnant") {	 
	  var pregStage = getPregStage(arrChildData["dueDate"])
	  //if dueDate is in the past, redirect user to the newborn or baby or toddler etc. page
	  if (pregStage == -1) {
	    var redirectOID = getChildStage(arrChildData["dueDate"])
		document.location.replace('/stages/0,,' + redirectOID + ',00.html');
		return;
	  }  
	  var redirectOID = "pregnancy_" + pregStage
	  document.location.replace('/stages/0,,' + redirectOID + ',00.html');
	  return;	  
    } 
	  
	//default is a child 
	var redirectOID = getChildStage(arrChildData["defaultBirthDate"])
	document.location.replace('/stages/0,,' + redirectOID + ',00.html');
    return;	
  }
}

//checks user's cookie to display "" or "membername!" greeting - the preceding word 'Hi' is in the homepage template
function getGreeting() {
  if (userAuthenticated != "") {
    var userName = iv_getCookie('iv_id')
	if (userName && userName != "") {
      document.write(userName + "!");
	}
  } 
}

// This returns the text that displays the child's name & age i.e., "Sam is 3 years & 2 months old"
function getGreetingTxt () {
  if (userAuthenticated == "") {
    return;
  } else {
      if (childInfo == "" || childInfo == "s=" || childInfo == "NA") {
	  return;
	} else {
	  populateArray(childInfo);
	  //query string will have a name in it if user has selected another child from the children dropdown box
	  var childName = iv_queryString('GCHILD')
	  
	  if (childName == "") {
	    childName = arrChildData["defaultChildName"]
		var birthDate = arrChildData["defaultBirthDate"]
		
		//if default is trying to conceive, childName will be blank
		if (childName == "" && birthDate == "") {
			return;
		}		
	  } else {
	  	var childNameArr = childName.split ('(');
		childName = (childNameArr[0]);
		childName = RTrim(childName);
			
		var qDateString = childNameArr[1];
			
		var qMonth = qDateString.substring(5,7);
		var qDate = qDateString.substring(8,10);
		var qYear = qDateString.substring(11,15);
		var queryDate = qYear+qMonth+qDate;
	  
	    if (childName == 'Your new baby') {
    	  var birthDate = arrChildData["dueDate"];
  		} else {
    	  var birthDate = queryDate;
  		}
		if (birthDate == undefined) {
		  return;
		}
      }
	  var childAgeResult = getAge(birthDate)
	  if (childAgeResult.indexOf('-') == 0) {
	    return;
	  }
	  var childAge = childAgeResult.split('-')
  	  var childAgeYears = childAge[0]
  	  var childAgeMonths = childAge[1]
	  var childAgeDays = childAge[2]	
	  var childAgeWeeks = Math.floor(childAgeDays/7);
	  
	  
	  if (childAgeYears == 0) {
	    var ageText = ""
	  } else if (childAgeYears == 1) {
	    var ageText = " 1 year"
	  } else {
	    var ageText = " " + childAgeYears + " years"
	  }
	  if (childAgeMonths == 0) {
	    var monthText = ""
	  } else if (childAgeMonths == 1) {
	    var monthText = "1 month"
	  } else {
	    var monthText = childAgeMonths + " months"
	  }	  
	  if (childAgeYears >= 1 && monthText != "") {
	    ageText = ageText + " &"
	  }
	  
	  //special case for children under 1
	  if (childAgeYears == 0 && childName == "Your child") {
	  	childName = "Your baby"
	  }
	  
	  //special case for babies between 3 months and 1 year for displaying months and weeks
	  if (childAgeWeeks == 0) {
	  	var weekText = "";
	  } else if (childAgeWeeks == 1) {
	  	var weekText = " & 1 week"
	  } else {
	  	var weekText = " & " + childAgeWeeks + " weeks"
	  }
	  
	  if (childAgeYears == 0 && childAgeMonths >=3 && childAgeWeeks != 0) {
	  	monthText = monthText + weekText;
	  }
	  
	  //special case for 0 & 1 month old newborns - overwrite all above
	  if (childAgeYears == 0 && childAgeMonths == 0) {
	    var monthText = "1 month"
	  }
	 
	  document.write(childName + " is"+ ageText + " " + monthText + " old.")	   
      
	}  
  } 
}


function getGreetingWeeksTxt () {

	if (userAuthenticated == "") {
    	return;
  	} else {
    	if (childInfo == "" || childInfo == "s=" || childInfo == "NA") {
		  	return;
		} else {
		
			populateArray(childInfo);
	 		//query string will have a name in it if user has selected another child from the children dropdown box
	  		var childName = iv_queryString('GCHILD')
			
	 		if (childName == "") {
	   			childName = arrChildData["defaultChildName"]
				var birthDate = arrChildData["defaultBirthDate"]
				
				//if default is trying to conceive, childName will be blank
				if (childName == "" && birthDate == "") {
					return;
				}
							
	  		} else {
				var childNameArr = childName.split ('(');
				childName = (childNameArr[0]);
				childName = RTrim(childName);
				
				var qDateString = childNameArr[1];
				
				var qMonth = qDateString.substring(5,7);
				var qDate = qDateString.substring(8,10);
				var qYear = qDateString.substring(11,15);
				var queryDate = qYear+qMonth+qDate;
				
				
	    		if (childName == 'Your new baby') {
    	  			var birthDate = arrChildData["dueDate"];
  				} else {
    	  			var birthDate = queryDate;
  				}
				if (birthDate == undefined) {
		  			return;
				}
      		}
			
	  		if ( birthDate.indexOf("d") == 0) {	
				birthDate = new Date(birthDate.substr(5,2) +'/'+ birthDate.substr(7,2) +'/'+ birthDate.substr(1,4));
			} else {
				birthDate = new Date(birthDate.substr(4,2)+'/'+ birthDate.substr(6,2) +'/'+ birthDate.substr(0,4));
			}
			var now = new Date();
			
			if(!isBorn(birthDate)) {
				return;
			}
			if (!isUnderOneYears(birthDate)) {
				return;
			}
			
			numOfDays = now.getTimeDiff('dd',birthDate,0);
			numOfWeeks = Math.floor(numOfDays/7);			
			
			if (childName == "Your child") {
			  	childName = "Your baby"
		  	}

			
			week_pl = 'week';
			if (numOfWeeks > 1) { week_pl = 'weeks'; }	
			if (numOfWeeks <= 0) {
				document.write(childName + " has been born");
			} else {
				document.write(childName + " is " + numOfWeeks + " " +week_pl+ " old");
			}			
		}
	}
}

function getPregWeeksTxt () {
	if (userAuthenticated == "") {
    	return;
  	} else {
    	if (childInfo == "" || childInfo == "s=" || childInfo == "NA") {
		  	return;
		} else {
			populateArray(childInfo);
	 		//query string will have a name in it if user has selected another child from the children dropdown box
	  		var childName = iv_queryString('GCHILD')
			
			
			
						
	 		if (childName == "") {
			
			
			
	   			childName = arrChildData["defaultChildName"]
				var birthDate = arrChildData["defaultBirthDate"]		
				
				//if default is trying to conceive, childName will be blank
			
				if (childName == "" && birthDate == "") {
					return;
				}	
	  		} else {
				var childNameArr = childName.split ('(');
				childName = (childNameArr[0]);
				childName = RTrim(childName);
			
				var qDateString = childNameArr[1];
				//alert(tempDString);
				var qMonth = qDateString.substring(4,6);
				var qDate = qDateString.substring(7,9);
				var qYear = qDateString.substring(10,14);
				var queryDate = qYear+qMonth+qDate;
			
	    		if (childName == 'Your new baby') {
    	  			var birthDate = arrChildData["dueDate"];
  				} else {
    	  			var birthDate = queryDate;
  				}
				if (birthDate == undefined) {
		  			return;
				}
      		}
	  		if ( birthDate.indexOf("d") == 0) {	
				birthDate = new Date(birthDate.substr(5,2) +'/'+ birthDate.substr(7,2) +'/'+ birthDate.substr(1,4));
			} else {
				birthDate = new Date(birthDate.substr(4,2) +'/'+ birthDate.substr(6,2) +'/'+ birthDate.substr(0,4));
			}
			
			var now = new Date();
			if (!stillPreg(birthDate)) {
				return;
			}
			
			numOfDays = birthDate.getTimeDiff('dd',now,0);
			
			
			numOfDaysPreg = 278 - numOfDays;
			
			numOfWeeks = Math.floor(numOfDaysPreg/7);
	
			if (numOfWeeks == 0) {
				document.write("You are 1 week pregnant");
			} else if (numOfWeeks >= 39) {
			 	document.write("You are 40 weeks pregnant");
			} else {
				var totalWeeks = Math.floor(numOfWeeks + 1);
				document.write("You are " + totalWeeks + " weeks pregnant");			
			}
		}
	}
}


function getOtherURL(selectId) {
  var theSelect = document.getElementById(selectId)
  var theOption = theSelect.options[theSelect.selectedIndex]
  var childName = theSelect.options[theSelect.selectedIndex].text
  
  var result = childName.indexOf(" (");
  if (result != -1) {
    //var childName = childName.substring(0,result);
  }
  if (theOption != null ){
	location.href = theOption.value + '?GCHILD=' + escape(childName);
  }
  return true;
}

function getCustomText() {
  var sageHost = iv_sageHost;
  
  var redirectURL = iv_channelHomepageURL;
  authAppURL = sageHost + "/familyprofile/restore?rd=" + redirectURL
  if (userAuthenticated != "") {
    document.write("")
  } else {
    var loginURL = sageHost + "/funnels/7?vrt=pp&prd=ppers&dd=" + escape(authAppURL);
	document.write("Already customized your page? <a href=" + loginURL + ">Log in here</a>")
  }
}

//returns bool based on if date passed is a due date; 
function isPregnant(dateObj) {

	daysPreg = dateObj.getTimeDiff('dd',new Date());
	if (daysPreg >= 279) {
		return false;
	}
return true;
}

function stillPreg(dateObj) {
	if (dateObj.getTime() <= today.getTime()) {
		return false;
	}
return true;
}

//returns bool based on dateObj being less <= 1 years old.
function isUnderOneYears(dateObj) {
	yearAgo = new Date((today.getMonth() + 1) +'/'+ today.getDate() +'/'+ (today.getFullYear()-1));
	if (dateObj >= yearAgo) {
		return true;
	} else {
		return false;
	}
}
//returns bool based on dateObj being < today
function isBorn(dateObj) {
	if (dateObj <= today) {
		return true;
	} else {
		return false;
	}
}
