/** 
 * ChangeOne JavaScript Library
 */

function PagePrint() {
	var os = navigator.platform;
	
	
	
	os = os.toLowerCase();
	
	//alert(os);
	
	if (window.print) {
		setTimeout('window.print();',200);
	}
	else if (os.indexOf("mac") != -1){
		alert("Press 'Cmd+p' on your keyboard to print this page.");
	}
	else {
		alert("Press 'Ctrl+p' on your keyboard to print this page.")
	}
}

function submitOrder() {
var bName = navigator.appName;
	
if (bName == "Microsoft Internet Explorer") {
	document.all.item("submitOrder").style.display = "none";
	document.all.item("pleaseWait").style.display = "";
   }
}

/*function popupSurvey(filename, trkid) {
	window.open(filename+"?trkid="+trkid, "","height=575,width=350,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no,directories=no");
	}

function doUnload(trkid) {
	var presented=getCookie("survey_presented");

	// enable or disable the exit survey. disabled for googling. 
	var enabled=false;

	if (enabled==true) {
		if (presented != "true") {
			if (exitMe) {
					popupSurvey("/survey/survey_popup.jsp", trkid);
					document.cookie="survey_presented=true";
					}
			}
		}
	}
*/

function RepeatWeek() {
	
	MM_showHideLayers('pleaseWait','','show');
	
	if (bName == "Microsoft Internet Explorer") {
		document.all.item("submitRepeat").style.display = "none";
		document.all.item("cancelRepeat").style.display = "none";
	}
	
}

//Start Dreamweaver functions (show/hide layers)

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

//End of dreamweaver functions



// howandwhy popup script.
function popHowAndWhy (file,width,height,scrollbars,menubar) {
	open(file,'pop','toolbar=no,left=20,top=20,status=no,width=520,height=500,scrollbars=yes,directories=no,location=no,resizable=no,menubar=' + menubar + '');
		
}

// Dynamic popup script.
function popWinD (file,width,height,scrollbars,menubar) {
	open(file,'pop','toolbar=no,left=20,top=20,status=no,width='+width+',height='+height+',scrollbars='+scrollbars+',directories=no,location=no,resizable=no,menubar=' + menubar + '');
		
}

function popWinName (file,name,width,height,scrollbars,menubar) {
	open(file,name,'toolbar=no,left=20,top=20,status=no,width='+width+',height='+height+',scrollbars='+scrollbars+',directories=no,location=no,resizable=no,menubar=' + menubar + '');
		
}

// Generic popup script.
function popWin (file,width,height,scrollbars,menubar) {
	open(file,'pop','toolbar=no,left=20,top=20,status=no,width=470,height=320,scrollbars=yes,directories=no,location=no,resizable=no,menubar=' + menubar + '');
		
}

// Generic popup script.
function popWinExer (file,width,height,scrollbars,menubar) {
	open(file,'pop','toolbar=no,left=20,top=20,status=no,width=560,height=380,scrollbars=no,directories=no,location=no,resizable=no,menubar=' + menubar + '');
}

// reg popunder script.
function popRegUnder (file,width,height,scrollbars,menubar) {
	regPop=open(file,'pop','toolbar=no,left=20,top=20,status=no,width=300,height=205,scrollbars=no,directories=no,location=no,resizable=no,menubar=' + menubar + '');
	regPop.blur();
	window.focus();
}


// Generic popup script.
function popWinAlt (file,width,height,scrollbars,menubar) {
	open(file,'pop','toolbar=no,left=20,top=20,status=no,width=540,height=490,scrollbars=yes,directories=no,location=no,resizable=no,menubar=' + menubar + '');
}

// Tour popup script.
function popWinTour (file,width,height,scrollbars,menubar) {
	open(file,'pop','toolbar=no,left=20,top=20,status=no,width=640,height=450,scrollbars=yes,directories=no,location=no,resizable=no,menubar=' + menubar + '');
	
}

// Tour popup script.
function closePopOpenURLFromPop (winPop, strURL) {
	winPop.open(strURL,'tour','toolbar=no,left=20,top=20,status=no,width=640,height=450,scrollbars=yes,directories=no,location=no,resizable=no,menubar=no');
	winPop.close();
}

// Reloads the parent of the popup when the user uses the window X to close .
function unloadReload (winPop) {
	winPop.opener.location.reload();
}

// Reloads the parent and closes the popup when link is clicked.
function closeReload (winPop) {
	winPop.opener.location.reload();
	winPop.close();
}

// Close the popup and go to a new URL in the parent.
function closeNewURL (winPop, strURL) {
	winPop.opener.location.href = strURL;
	winPop.close();
}

// Close the popup and go to a new URL in new window.
function closePopOpenURL (winPop, strURL) {
	winPop.open(strURL);
	winPop.close();
}

// Close the popup and go to a new URL in the parent.
function reloadNewURL (winPop, strURL) {
	winPop.opener.location.href = strURL;
	winPop.focus();
}


// Check the URL for the submit flag, close the window, and reload the parent window.
function submitClose (winPop) {
	var strPath = location.href;
	if (strPath.search("submit") > -1) {
		closeReload(winPop);
	}
}

// Check the URL for the submit flag, close the window and reload the parent window.
function submitCloseNewURL (winPop, strURL) {
	var strPath = location.href;
	if (strPath.search("submit") > -1) {
		closeNewURL(winPop, strURL);
	}
}

// Submits the parent's form and closes the popup when link is clicked.
function confirmSubmit (winPop, strAction) {
	if (strAction == "submit") {
		winPop.opener.document.forms.profile.submit();
	} else {
		winPop.opener.document.forms.profile.reset();
	}
	winPop.close();
}


 function popupCalendar(page) {
        window.open(page,'popup','width=365,height=420,toolbar=false,scrollbars=false');
    }

function closeCalendar(url){
        window.opener.location.href=url;
        window.close();
  }
	
	
// Hides default text onclick
function hideText (field, strValue) {
	if (field.value == strValue) {
		field.value = '';
	}
}

// Re-shows default text onblur
function showText (field, strValue) {
	if (field.value == '') {
		field.value = strValue;
	}
}

// Validates the weigh-in form.
function validateEntry() {
	if (document.weighForm.weight.value == "") {
		alert("You did not enter a weight.  Please enter one.");
		document.weighForm.weight.focus();
		return false;
	}
	if (isNaN(document.weighForm.weight.value)) {
		alert("You did not enter a valid weight.  Please enter one.");
		document.weighForm.weight.focus();
		return false;
	}
	if (document.weighForm.weight.value < 75) {
		alert("Please enter a valid weight above 75 pounds.");
		document.weighForm.weight.focus();
		return false;
	}
	if (document.weighForm.weight.value > 999) {
		alert("Please enter a valid weight below 1000 pounds.");
		document.weighForm.weight.focus();
		return false;
	}
	return true;
}

// Displays the date where the user is.
function showDate () {
	var datToday = new Date();
	var strMonth = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
	var strSuffix = new Array ("","st","nd","rd","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","st","nd","rd","th","th","th","th","th","th","th","st");
	document.write(strMonth[datToday.getMonth()] + " ");
	document.write(datToday.getDate() + strSuffix[datToday.getDate()] + ", ");
	document.write(datToday.getFullYear());
}

// Displays the date where the user is for the daily view, also shows future and past dates for dailyview.
function showDateShort (intDay, intCurrentDay) {
	var datToday = new Date();
	datToday.setDate(datToday.getDate() - (intCurrentDay-intDay));
	var strMonth = new Array ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");
	if (intDay == intCurrentDay) {
		document.write("TODAY'S MENU: ");
	} else {
		document.write("MENU FOR: ");
	}
	document.write(strMonth[datToday.getMonth()] + " ");
	document.write(datToday.getDate());
}

// Displays the date for the previous week on the daily page.
function showDatePrev (intDay, intCurrentDay) {
	var datToday = new Date();
	datToday.setDate(datToday.getDate() - ((intCurrentDay-intDay) + 7));
	var strMonth = new Array ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");	
	document.write("MENU FOR: ");
	document.write(strMonth[datToday.getMonth()] + " ");
	document.write(datToday.getDate());
}

// Displays the date for the previous week on the daily page.
function showDateNext (intDay, intCurrentDay) {
	var datToday = new Date();
	datToday.setDate(datToday.getDate() - ((intCurrentDay-intDay) - 7));
	var strMonth = new Array ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");	
	document.write("MENU FOR: ");
	document.write(strMonth[datToday.getMonth()] + " ");
	document.write(datToday.getDate());
}

// Show the right nav links.
function getWeekLinkOne () {
	// Read in the URL.
	var strPath = location.pathname;
	// Look for file names containing...
	if (strPath.search("prev.jhtml") > -1) {
		document.write('<a href="/mpl/mpl-weeklydefault.jhtml" class="navContent">This week\'s menu</a>');
	} else {
		document.write('<a href="/mpl/mpl-weeklyprev.jhtml" class="navContent">Last week\'s menu</a>');
	}
}

function getWeekLinkTwo () {
	// Read in the URL.
	var strPath = location.pathname;
	// Look for file names containing...
	if (strPath.search("next.jhtml") > -1) {
		document.write('<a href="/mpl/mpl-weeklydefault.jhtml" class="navContent">This week\'s menu</a>');
	} else {
		document.write('<a href="/mpl/mpl-weeklynext.jhtml" class="navContent">Next week\'s menu</a>');
	}
}

// Alerts the user that his BMI is too high on registration.
function alertBMI (intBMI) {
	if (parseInt(intBMI) > 26) {
		open('/reg/reg-highbmi.jhtml',
			 '',
			 'toolbar=no,left=20,top=20,status=no,width=450,height=150,scrollbars=no,directories=no,location=no,resizable=no,menubar=no');
	}
}

// Insert a function fired onChange when the user updates his profile with any
// items that affect BMI.
function alertChangeBMI (strForm) {
	if (strForm.feet.value != strForm.testFeet.value ||
		strForm.inches.value != strForm.testInches.value ||
		strForm.weight.value != strForm.testWeight.value ||
		strForm.gender.value != strForm.testGender.value) {
		open('/mbr/mbr-pop-bmi.jhtml',
	 	'bmi',
	 	'toolbar=no,left=20,top=20,status=no,width=470,height=320,scrollbars=yes,directories=no,location=yes,resizable=no,menubar=no');
		return false;
	}	
}

// Check for password synch.
function matchPassword (strForm) {
	if (strForm.pass1.value != strForm.pass2.value) {
		alert('The passwords do not match');
		return false;
	}
}

// Prompts the user as to whether he really wants to log out.
function confirmLogout () {
	if (!confirm('Are you sure you want to logout?')) {
		return false;
	}
}

// Confirm that a user wants to leave in the middle of registration
 function confirmNoReg () {
	if (!confirm('You are about to cancel registration.  Is this OK?')) {
		return false;
	}
	else
	{
	
	
		popRegUnder('/pop/changeonebook.jhtml');
	
	}
} 

// Set a flag if the value of a checkbox array has changed.
function updateHidden (objForm) {
	 objForm.testDiet.value = true;
}

// Set a flag if the value of the weigh in has changed.
function updateHiddenWeight (objForm) {
	 objForm.testWeight.value = objForm.weight.value;
}

// Takes any given character and changes it to the mask character.
function replaceChar (chrPassed, chrMask) {
	return chrPassed = chrMask;
}

// Replace all but the last 4 letters of a credit card number.
function scrambleCard (strCC) {
	var intLength = strCC.length;
 	var strX = "";
	for (var i = 0; i < (intLength - 4); i++) { 
		strX += replaceChar(strCC.charAt(i), 'X');
	}
	return strX + "-" + strCC.substring(intLength - 4, intLength);
}

// Scramble the password.
function scramblePass (strPass) {
 	var strX = ""; 
	for (var i = 0; i < strPass.length; i++) {
		strX += replaceChar(strPass.charAt(i), '*');
	}
	return strX;
}

// Create the navigation preload and rollover scripts here.
function newImage (arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
	
function changeImages () {
	if (document.images && (preloadFlag == true)) {
		for (var i = 0; i < changeImages.arguments.length; i += 2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
		}
	}
}
	
var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		var cnvg_nav_health_off = 	newImage('/img/cnvg_nav_health_off.gif');
		var cnvg_nav_health_on = 	newImage('/img/cnvg_nav_health_on.gif');
		var cnvg_nav_food_off = 	newImage('/img/cnvg_nav_food_off.gif');
		var cnvg_nav_food_on = 		newImage('/img/cnvg_nav_food_on.gif');
		var cnvg_nav_comm_on = 		newImage('/img/cnvg_nav_comm_on.gif');
		var cnvg_nav_plan_off = 	newImage('/img/cnvg_nav_plan_off.gif');
		var cnvg_nav_plan_on = 		newImage('/img/cnvg_nav_plan_on.gif');
		var cnvg_nav_home_off = 	newImage('/img/cnvg_nav_home_off.gif');
		var cnvg_nav_home_on = 		newImage('/img/cnvg_nav_home_on.gif');
		var cnvg_nav_diacomm =          newImage('/img/diabetescenter/cnvg_nav_diacomm_on.gif');   
		var cnvg_nav_diahome =          newImage('/img/diabetescenter/cnvg_nav_diahome_on.gif');
		var cnvg_nav_diaplan =          newImage('/img/diabetescenter/cnvg_nav_diaplan_on.gif');
		var cnvg_nav_diafood =          newImage('/img/diabetescenter/cnvg_nav_diafood_on.gif'); 
		var cnvg_nav_diahealth =        newImage('/img/diabetescenter/cnvg_nav_diahealth_on.gif');
		var cnvg_nav_diafun =           newImage('/img/diabetescenter/cnvg_nav_diafun_on.gif');
		var cnvg_nav_diacenter =        newImage('/img/diabetescenter/cnvg_nav_diacntr_on.gif');
		preloadFlag = true;
	}
}

function windowTimeout() {
	setTimeout("window.location.href='/mbr/mbr-pop_timedout.jhtml'",600000);
}

//cookie for splash page
function deleteCookie (name) { 
	alert("deleting cookie " + name);
	var exp = new Date();  
	alert("cookie time " + exp);
	exp.setTime (0);  
	alert("cookie time 2 " + exp);
	var cval = getCookie (name);  
	alert("cookie cval " + cval);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
	
		i = document.cookie.indexOf(" ", i) + 1;    
	
		if (i == 0) break;   
	}  

	return null;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
	var count = getCookie('splash');
	if (count == "false"){
		window.location.href="/gen-con/home.jhtml";
   	}
}
// Take the selected value of the passed dropdown object and redirect the user to this page.
function goto_URL(object) {
	if(object.options[object.selectedIndex].value != "") {
	    window.location.href = object.options[object.selectedIndex].value;
	}
}

//Script for rotating images on spash page

	adImages = new Array("/img/cspl_img_meal1.jpg","/img/cspl_img_meal2.jpg","/img/cspl_img_meal3.jpg","/img/cspl_img_meal4.jpg","/img/cspl_img_meal5.jpg","/img/cspl_img_meal6.jpg","/img/cspl_img_meal7.jpg")
	
	thisAd = 0
	imgCt = adImages.length

	function rotate() {
		if (document.images) {
			if (document.adBanner.complete) {
				thisAd++
				if (thisAd == imgCt) {
					thisAd = 0
				}
				document.adBanner.src=adImages[thisAd]
			}
		  	setTimeout("rotate()", 5 * 1000)
	  	}
	}
	
	

		// Journal User guide popup script.
		<!--
		function popJrnl (file,width,height,scrollbars,menubar) {
			open(file,'pop','toolbar=no,left=20,top=20,status=no,width=' + width + ',height=' + height + ',scrollbars=' + scrollbars + ',directories=no,location=no,resizable=no,menubar=' + menubar);
		}
		
		//offer terms popup
		function popUp (file,width,height,scrollbars,menubar) {
	open(file,
		 'pop',
		 'toolbar=no,left=20,top=20,status=no,width=450,height=500,scrollbars=yes,directories=no,location=no,resizable=no,menubar=' + menubar + '');
		
}
		//-->
		
		//bmi popup
		function popBMI (file,width,height,scrollbars,menubar) {
	open(file,
		 'pop',
		 'toolbar=no,left=20,top=20,status=no,width=350,height=300,scrollbars=yes,directories=no,location=no,resizable=no,menubar=' + menubar + '');
		
}
		//-->


/*
not being used
function setCount() {
	var count = GetCookie('splash');
	if (count == null) {
		count=1;
		SetCookie('splash', count, exp);
	} else {
		count++;
		SetCookie('splash', count, exp);
	}
}
*/
