function isUserName(username) {
 	var usernameCheck=true;   
	re = /^\w+$/;
	//alert(re.test(username));
	//alert(username.match(/^[A-Za-z0-9]$/));
	if(!re.test(username))
	{
		usernameCheck=false;
	}
	
	return usernameCheck;
}
function trim(str) 
{ 
   if (str == null)
   {
	   return;
   }
	return str.replace(/^\s+|\s+$/g,''); 
}

// Check whether the value of an object is empty/null 
function isEmpty(frm, ctrl, msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (value == null || trim(value) == "")
		{
			alertMSG(msg, ctrl);
			return true;
		}
		return false;
	}
}


// Check whether the value of an object is empty/null 
function isHtmlEditorEmpty(frm, ctrl, msg)
{
	
	var editor = SpawEngine.getEditor(ctrl);
	var page  =  editor.getActivePage();
	var value =  editor.getPageHtml(page).replace(/<\/?[^>]+(>|$)/g, "");
	value = trim(value.replace(/^[\s(&nbsp;)]+/g,'').replace(/[\s(&nbsp;)]+$/g,''));

	if (value == null || trim(value) == "")
	{
		alertMSG(msg, ctrl);
		return true;
	}
	return false;
}


// Check whether the value of an object is numeric
function isNumeric(frm, ctrl, msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (isNaN(trim(value)) == true)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

// Check whether the length of characters entered is equal to specified length
function isOfExactLength(frm, ctrl, num, msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (value.length < num || value.length > num)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

// Check whether the length of characters entered is equal to or greater than specified length.
function isOfMinLength(frm, ctrl, num, msg)
{	
	var obj = levelInDep(frm,ctrl);
	
	with (obj)
	{
		if (value.length < num)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

// Check whether the length of characters entered is equal to or less than specified length
function isOfMaxLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(frm, ctrl);
	with (obj)
	{
		if (value.length > num)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}


// Check whether the value of either of the two control blank or not
function isAtleastOneNotEmpty(frm, ctrl1, ctrl2, msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj1)
	{
		if (trim(value) == "" && trim(obj2.value) == "")
		{
			alertMSG(msg, ctrl1);
			return false;
		}
		return true;
	}
}

// Check whether the value of two control equals or not
function isNotEqual(frm, ctrl1, ctrl2, msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj2)
	{
		if (trim(value) != trim(obj1.value))
		{
			alertMSG(msg, ctrl1);
			return true;
		}
		return false;
	}
}


// Check whether an Email address is valid
function isValidEmail(frm,ctrl,msg)
{	
	var obj = levelInDep(frm, ctrl);
	with (obj)
	{
		var regexp =  /^\w(\.?\w)*@\w(\.?[-\w])*\.[a-z]{2,4}$/i;
		if (regexp.test(trim(value)) != true)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}


// Check whether the something is selected in the list or not
function isSelected(frm, ctrl, msg) 
{ 
	var obj = levelInDep(frm, ctrl);
	with (obj)
	{
		if (selectedIndex != 0)
		{
			return true;
		}
		else 
		{
			alertMSG(msg, ctrl);
			return false;
		}
	}
} 


// Check whether the something is selected in the multi select list or not
function isMultipleSel(level,entered, alertbox) 
{ 
	var obj = levelInDep(frm, ctrl);
	with (obj)
	{
		if (selectedIndex != -1)
		{
			return true;
		}
		else 
		{
			alertMSG(msg, ctrl);
			return false;
		}
	}
} 

function isValidURL(frm,ctrl, msg)
{ 
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
 		var regexp =  /(http|ftp|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/i;
		if (regexp.test(trim(value)) != true)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

function isChecked(frm, ctrl, msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
 		if (checked == true)
		{
			return true;
		}
		else
		{
			alertMSG(msg, ctrl);
			return false;
		}
	}
}

function toggleCheckbox(element)
{
	if(document.getElementById(element).checked==true)
	{
		document.getElementById(element).checked=false;
	}
	else
	{
		document.getElementById(element).checked=true;
	}
}

function selectRadioButton(element)
{
	document.getElementById(element).checked=true;
}

function setFocus(element)
{
	document.getElementById(element).focus();
}

//Level indepenncy
function levelInDep(le,en)
{
	var res = eval('document.'+ le + '.' + en);
	return res;	
}

function alertMSG(message, ctrl)
{
	if (message == null || trim(message) == "") 
	{
		return;
	}
	alert(message);
	setFocus(ctrl);
}
function isAnyChecked(frm, ctrl, msg)
{
	
	obj=levelInDep(frm,ctrl);
	
	var flag=0;
	for(i=0;i<obj.length;i++)
	{
 		if (obj[i].checked == true)
		{
			flag++;
			
		}
		
	}
	if(i==0)
	{
		if (obj[0].checked == true)
		{
			flag++;
			
		}
	}
	if(flag>0)
	{
			return true;
	}
	else
	{
			
			alertMSG(msg, ctrl);
			return false;
		
	}
}
function addCategory()
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n"
	var CategoryName=document.getElementById("Name").value;
	//alert(CategoryName);
	if(CategoryName=='')
	{
		str1 +="- Please enter the category name.\n"
		alert(str1);
	}
	else
	{
		var strSubmit = "action=addBlogCat&catname="+CategoryName;
		var strURL = "ajaxValue.php";
		var strResultFunc="displayCategories";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
		document.getElementById("Name").value='';
		return false;
	}
}
function displayCategories(result)
{
	//alert(result);
	document.getElementById("categoryDiv").innerHTML=result;
}
function uploadImage()
{
		document.form1.blogForm.value="2";
		document.form1.action="blogPost.php";
		document.form1.submit();
}
function addExercise()
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n"
	var exercise=document.getElementById("Name").value;
	if(exercise=='')
	{
		str1 +="- Please enter the exercise type.\n"
		alert(str1);
		
	}
	else
	{
		var strSubmit = "action=addExercise&Name="+exercise;
		var strURL = "ajaxValue.php";
		var strResultFunc="displayExercise";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
		
	}
}
function displayExercise(result)
{
	document.getElementById("exerciseDiv").innerHTML=result;
}
function addNewRow(id)
{
		
		if(id<=10)
		{
			document.getElementById("newRow").innerHTML=document.getElementById("newRow").innerHTML+'<table width="100%"><tr><td align="left" ><select name="Set'+id+'" class="textfield"><option value="">Select One</option><option value="1">Warmup Set </option><option value="2">Exercise Set </option></select></td><td height="25" align="center" valign="middle"><input name="SetNO'+id+'" type="text" class="textfield-invisible" id="SetNO'+id+'" style="width:30px;" value="'+id+'"/></td><td align="center" valign="middle"><input name="Reps'+id+'" type="text" class="textfield" id="Reps'+id+'" style="width:40px;" value=""/></td><td align="left" valign="middle"><input name="Weight'+id+'" type="text" class="textfield" id="Weight'+id+'" style="width:60px;" value=""/></td><td align="right" valign="middle"><input name="Rest'+id+'" type="text" class="textfield" id="Rest'+id+'" style="width:80px;" value=""/></td><td align="right" valign="middle"><input name="Comments'+id+'" type="text" class="textfield" id="Comments'+id+'" style="width:340px;" value=""/></td></tr></table>';
			//alert(document.getElementById("newRow").innerHTML);
			var idd=Number(id)+1;
			document.getElementById("newRowButton").innerHTML='<a href="#" onclick="javascript:addNewRow('+idd+');"><img src="images/addrow.gif" border="0"></a>';
		}
		else
		{
				alert("You can have maximum 10 rows.");
				return false;
		}
}
function selectedExercise()
{
	//document.form1.exerciseForm.value=2;
	//document.form1.submit();
	document.getElementById("exCategory").value="";
	document.getElementById("exerciseListDiv").innerHTML='<select name="exercise" class="dropdown2" size="12" id="exercise" ><option value="">No category is selected</option></select>';
}
function delete_records()
{
	if(confirm('This action will permanently remove the selected data, do you wish to continue?'))
	{
		document.form2.exerciseForm.value=3;
		document.form2.submit();
	}
}
function addCardio()
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n"
	var cardio=document.getElementById("Name").value;
	if(cardio=='')
	{
		str1 +="- Please enter the cardio training name.\n"
		alert(str1);
		
	}
	else
	{
		var strSubmit = "action=addCardioName&Name="+cardio;
		var strURL = "ajaxValue.php";
		var strResultFunc="displayCardio";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
		
	}
}
function displayCardio(result)
{
	document.getElementById("cardioDiv").innerHTML=result;
	document.getElementById("Name").value='';
}
function edit()
{
		var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
		var flag=0;
		
		for(i=0;i<document.form1.chk.length;i++)
		{
			if(document.form1.chk[i].checked==true)
			{
					flag++;
			}
		}
		if(i==0)
		{
				if(document.form1.chk.checked==true)
			{
					flag++;
			}
		}
		if(flag==0)
		{
			str1+=" - Please select a record."
			alert(str1);
		}
		else if(flag>1)
		{
			str1+=" - You can edit one record at a time."
			alert(str1);
		}
		else
		{
				document.form1.cardioForm.value=4;
				document.form1.submit();
		}
}
function massCalculate()
{
	var str='';
	var weight=Number(document.getElementById("Weight").value);
	var bodyFat=Number(document.getElementById("BodyFat").value);
	if(isNaN(weight))
	{
		str += "- Weight must be numeric." + "\r\n";
	}
	if(isNaN(bodyFat))
	{
		str += "- Body Fat must be numeric." + "\r\n";
	}
	if(str!='')
	{
			alert(str);
	}
	else
	{
		var bodyFatMass=weight*bodyFat/100;
		var bodyLeanMass=weight-bodyFatMass;
		document.getElementById("BodyFatMass").value=bodyFatMass;
		document.getElementById("LeanBodyMass").value=bodyLeanMass;
	}
}
function editBodyState()
{
		var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
		var flag=0;
		var id=0;
		for(i=0;i<document.form2.chk.length;i++)
		{
			//alert(document.form2.chk[i].value);
			if(document.form2.chk[i].checked==true)
			{
					id=document.form2.chk[i].value;
					flag++;
			}
		}
		if(i==0)
		{
				if(document.form2.chk.checked==true)
				{
					id=document.form2.chk.value;
					flag++;
				}
		}
		if(flag==0)
		{
			str1+=" - Please select a record."
			alert(str1);
		}
		else if(flag>1)
		{
			str1+=" - You can edit one record at a time."
			alert(str1);
		}
		else
		{
				
				window.open("editBodyState.php?BodyStateID="+id,'mywin','left=100,top=100,width=600,height=500,toolbar=0,resizable=0,scrollbars=yes');
		}
}
function enable(id)
{
	for(i=1;i<5;i++)
	{
		if(document.getElementById(i))
		{
			if(id==i)
			{
				document.getElementById(i).style.display="block";
				document.getElementById("en"+i).bgcolor="#6392E4";
			}
			else
			{
				document.getElementById(i).style.display="none";
				document.getElementById("en"+i).bgcolor="#B6D696";
			}
		}
	}
}
function SearchFood(type)
{
	//alert(type);
	//return false;
	if(type=='bycat')
	{
			
			var categories_id=document.getElementById("foodcategory").value;
			
			window.location.href="diet-nutrition2.php?foodcategory="+categories_id;
	}
	else
	{
			
			

			var itemName=document.getElementById("keyword").value;
			
			if(document.getElementById('tblVal').value=='CUSTOM'){
				var dataTable ='CUSTOM';
			}
			else if(document.form1.dataTable[1].checked==true || document.getElementById('tblVal').value=='USDA' )
			{
				//var dataTable = document.getElementById("dataTable").value;
				var dataTable ='USDA';
				//alert(dataTable);
			}
			
			else if(document.form1.dataTable[0].checked==true || document.getElementById('tblVal').value=='both'){
				var dataTable ='both';
				//alert(dataTable);
			}
			else if(document.form1.dataTable[2].checked==true || document.getElementById('tblVal').value=='CUSTOM'){
				var dataTable ='CUSTOM';
				
			}
			//alert(dataTable);
			//return false;
			window.location.href="diet-nutrition2.php?keyword="+itemName+"&dataTable="+dataTable;
	}
	
}
function addNutritionSummary()
{
	if(validate(document.form1))
	{
		document.form1.action="diet-nutrition1.php";
		document.form1.submit();
	}
}
function addFood()
{
	document.form1.action="diet-nutrition4.php";
	document.form1.submit();
}

function dateDiff() {
	date1 = new Date();
	var one_day=1000*60*60*24;
	date2 = new Date(document.form1.year.value,document.form1.month.value,document.form1.day.value);
	days=(date1.getTime()-date2.getTime())/one_day;
	
	if(days<=13*365)
	{
			alert("We do not accept registrations for users under 13 years of age.");
			return false; // form should never submit, returns false
	}
	else
	{
			return true;
	}

}
function exerciseList()
{
	var CategoriesID=document.getElementById("exCategory").value;
	//alert(CategoriesID);
	var strSubmit = "action=exerciseList&CategoriesID="+CategoriesID;
	var strURL = "ajaxValue.php";
	var strResultFunc="displayExerciseList";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
}
function displayExerciseList(result)
{
	document.getElementById("exerciseListDiv").innerHTML=result;
}
function editExercise(page)
{
	if(page=='cardio')
	{
		var linkPage="editCustomCardioExercise.php?action=Edit";
	}
	else
	{
		var linkPage="editCustomExercise.php";
	}
	window.open(linkPage,'mywin','left=100,top=100,width=600,height=500,toolbar=0,resizable=0,scrollbars=yes');
	return false;
}
function editExPopup()
{
		var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
		var flag=0;
		var id='';
		//alert(document.form2.chk.length);
		for(i=0;i<document.form2.chk.length;i++)
		{
			//alert(document.form2.chk[i].value);
			if(document.form2.chk[i].checked==true)
			{
					if(id!='')
					{
							id+=',';
					}
					id+=document.form2.chk[i].value;
					flag++;
			}
		}
		if(i==0)
		{
				if(document.form2.chk.checked==true)
				{
					id=document.form2.chk.value;
					flag++;
				}
		}
		if(flag==0)
		{
			str1+=" - Please select a record."
			alert(str1);
		}
		else
		{
				
				window.open("editExercise.php?editIds="+id,'mywin','left=100,top=100,width=800,height=500,toolbar=0,resizable=1,scrollbars=yes');
		}
}
function openpopup(page,id)
{
	window.open(page+'?editId='+id,'mywin','left=100,top=100,width=400,height=400,toolbar=0,resizable=1,scrollbars=yes');
	return false;
}
function openpopup2(page,id,type)
{
	window.open(page+'?editId='+id+'&commentType='+type,'mywin3','left=100,top=100,width=400,height=400,toolbar=0,resizable=1,scrollbars=yes');
	return false;
}
function countFriendList(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	var friendList=frm.friendList.value;
	var friendArr=friendList.split(";");
	var total=friendArr.length;
	if(friendList!='')
	{
		if(total>10)
		{
			flag=1;
			str1+=" - You can enter maximum 10 username but you have entered "+total+" username."
			
		}
	}
	else
	{
			flag=1;
			str1+=" - Please enter friend's username."
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function countBackList(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	var backList=frm.backList.value;
	if(backList!='')
	{
		var backListArr=backList.split(";");
		var total=backListArr.length;
		if(total>200)
		{
			flag=1;
			str1+=" - You can enter maximum 200 username but you have entered "+total+" username."
		
		}
	}
	else
	{
			flag=1;
			str1+=" - Please enter backlisted username."
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function reportForm1(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	
	if(frm.butValue.value=='Go1')
	{
		if(frm.bodyStatePeriod.value=='' )
		{
				str1+=" - Please select the time period.";
				flag=1;
		}
	}
	else
	{
			if(frm.bStartDay.value =="" || frm.bStartMonth.value=="" || frm.bStartYear.value=="")
			{
				str1+=" - Please select the time period.";
				flag=1;
			}
			else
			{
				date1 = new Date(frm.bStartYear.value,frm.bStartMonth.value,frm.bStartDay.value);
				var one_day=1000*60*60*24;
				date2 = new Date(frm.bEndYear.value,frm.bEndMonth.value,frm.bEndDay.value);
				days=(date2.getTime()-date1.getTime())/one_day;
				//alert(days);
				if(days<0)
				{
					str1+=" - End date must be greater than start date.";
					flag=1;
				}
				else if(days>365)
				{
					str1+=" - You can select the time period max 1 year.";
					flag=1;
				}
			}
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function reportForm2(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	
	if(frm.butValue.value=='Go1')
	{
		if(frm.nutrition1.value=='' )
		{
				str1+=" - Please select the time period.";
				flag=1;
		}
	}
	else
	{
			if(frm.n1StartDay.value =="" || frm.n1StartMonth.value=="" || frm.n1StartYear.value=="")
			{
				str1+=" - Please select the time period.";
				flag=1;
			}
			else
			{
				date1 = new Date(frm.n1StartYear.value,frm.n1StartMonth.value,frm.n1StartDay.value);
				var one_day=1000*60*60*24;
				date2 = new Date(frm.n1EndYear.value,frm.n1EndMonth.value,frm.n1EndDay.value);
				days=(date2.getTime()-date1.getTime())/one_day;
				//alert(days);
				if(days<0)
				{
					str1+=" - End date must be greater than start date.";
					flag=1;
				}
				else if(days>62)
				{
					str1+=" - You can select the time period max 2 months.";
					flag=1;
				}
			}
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function reportForm3(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	
	if(frm.butValue.value=='Go1')
	{
		if(frm.nutrition2.value=='' )
		{
				str1+=" - Please select the time period.";
				flag=1;
		}
	}
	else
	{
			if(frm.n2StartDay.value =="" || frm.n2StartMonth.value=="" || frm.n2StartYear.value=="")
			{
				str1+=" - Please select the time period.";
				flag=1;
			}
			else
			{
				date1 = new Date(frm.n2StartYear.value,frm.n2StartMonth.value,frm.n2StartDay.value);
				var one_day=1000*60*60*24;
				date2 = new Date(frm.n2EndYear.value,frm.n2EndMonth.value,frm.n2EndDay.value);
				days=(date2.getTime()-date1.getTime())/one_day;
				//alert(days);
				if(days<0)
				{
					str1+=" - End date must be greater than start date.";
					flag=1;
				}
				else if(days>31)
				{
					str1+=" - You can select the time period max 1 months.";
					flag=1;
				}
			}
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function reportForm4(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	/*for(i=0;i<frm.elements.length;i++)
	{
		alert(frm.elements[i].name+" --- "+frm.elements[i].value);
	}
	return false;*/
	if(frm.butValue.value=='Go1')
	{
		if(frm.nutrition3.value=='' )
		{
				str1+=" - Please select the time period.";
				flag=1;
		}
	}
	else
	
	{
			if(frm.n3StartDay.value =="" || frm.n3StartMonth.value=="" || frm.n3StartYear.value=="")
			{
				str1+=" - Please select the time period.";
				flag=1;
			}
			else
			{
				date1 = new Date(frm.n3StartYear.value,frm.n3StartMonth.value,frm.n3StartDay.value);
				var one_day=1000*60*60*24;
				date2 = new Date(frm.n3EndYear.value,frm.n3EndMonth.value,frm.n3EndDay.value);
				days=(date2.getTime()-date1.getTime())/one_day;
				//alert(days);
				if(days<0)
				{
					str1+=" - End date must be greater than start date.";
					flag=1;
				}
				else if(days>31)
				{
					str1+=" - You can select the time period max 1 months.";
					flag=1;
				}
			}
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function reportForm5(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	/*for(i=0;i<frm.elements.length;i++)
	{
		alert(frm.elements[i].name+" --- "+frm.elements[i].value);
	}
	return false;*/
	if(frm.butValue.value=='Go1')
	{
		if(frm.weight1.value=='' )
		{
				str1+=" - Please select the time period.";
				flag=1;
		}
	}
	else
	
	{
			if(frm.w1StartDay.value =="" || frm.w1StartMonth.value=="" || frm.w1StartYear.value=="")
			{
				str1+=" - Please select the time period.";
				flag=1;
			}
			else
			{
				date1 = new Date(frm.w1StartYear.value,frm.w1StartMonth.value,frm.w1StartDay.value);
				var one_day=1000*60*60*24;
				date2 = new Date(frm.w1EndYear.value,frm.w1EndMonth.value,frm.w1EndDay.value);
				days=(date2.getTime()-date1.getTime())/one_day;
				//alert(days);
				if(days<0)
				{
					str1+=" - End date must be greater than start date.";
					flag=1;
				}
				else if(days>183)
				{
					str1+=" - You can select the time period max 6 months.";
					flag=1;
				}
			}
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function reportForm6(frm)
{
	var str1 = "Sorry, we cannot complete your request.\n Kindly provide us missing or incorrect information mentioned below:\n";
	var flag=0;
	if(frm.exercise.value=="")
	{
		str1+=" - Please select an exersice.\n";
				flag=1;
	}
	if(frm.butValue.value=='Go1')
	{
		if(frm.weight2.value=='' )
		{
				str1+=" - Please select the time period.\n";
				flag=1;
		}
	}
	else
	
	{
			if(frm.w2StartDay.value =="" || frm.w2StartMonth.value=="" || frm.w2StartYear.value=="")
			{
				str1+=" - Please select the time period.";
				flag=1;
			}
			else
			{
				date1 = new Date(frm.w2StartYear.value,frm.w2StartMonth.value,frm.w2StartDay.value);
				var one_day=1000*60*60*24;
				date2 = new Date(frm.w2EndYear.value,frm.w2EndMonth.value,frm.w2EndDay.value);
				days=(date2.getTime()-date1.getTime())/one_day;
				//alert(days);
				if(days<0)
				{
					str1+=" - End date must be greater than start date.";
					flag=1;
				}
				else if(days>365)
				{
					str1+=" - You can select the time period max 12 months.";
					flag=1;
				}
			}
	}
	if(flag>0)
	{
			alert(str1);
			return false;
	}
	else
	{
			return true;
	}
}
function backExercise(dt)
{
	//var dt=document.getElementById("exCategory").value;
	
	var strSubmit = "action=profileExercise&date="+dt;
	
	//var strURL = "http://xicom-201/Xicom/fitNRG.com/website/ajaxValue.php";
//	var strURL = "http://216.246.91.52/~fitnrg/ajaxValue.php";
	var strURL = "../ajaxValue.php";//
	//alert(strURL);
//return false;
	var strResultFunc="displayProfileExercise";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
}
function displayProfileExercise(result)
{
	document.getElementById("profileExerciseDiv").innerHTML=result;
}
function profileNutrition(dt)
{
	//var dt=document.getElementById("exCategory").value;
	//alert(CategoriesID);
	var strSubmit = "action=profileNutrition&date="+dt;
	//alert(strSubmit);
	//return false;
	var strURL = "../ajaxValue.php";
	var strResultFunc="displayProfileNutrition";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}
function displayProfileNutrition(result)
{
	
	resultArr = result.split("###########");
	document.getElementById("profileNutritionDiv").innerHTML=resultArr[0];
	document.getElementById("nutritionGraphDiv").innerHTML=resultArr[1];
}
function profileActivity(dt)
{
	//var dt=document.getElementById("exCategory").value;
	//alert(CategoriesID);
	var strSubmit = "action=profileActivity&date="+dt;
	var strURL = "../ajaxValue.php";
	var strResultFunc="displayProfileActivity";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}
function displayProfileActivity(result)
{
	document.getElementById("profileActivityDiv").innerHTML = result;
	
}
function profileWeight(dt)
{
	//var dt=document.getElementById("exCategory").value;
	//alert(CategoriesID);
	var strSubmit = "action=profileWeight&date="+dt;
	var strURL = "../ajaxValue.php";
	var strResultFunc="displayProfileWeight";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}
function displayProfileWeight(result)
{
	document.getElementById("profileWeightDiv").innerHTML = result;
	
}
function weeklyCalories(dt)
{
	//var dt=document.getElementById("exCategory").value;
	//alert(CategoriesID);
	var strSubmit = "action=weeklyCalories&date="+dt;
	var strURL = "ajaxValue.php";
	var strResultFunc="displayWeeklyCalories";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}
function displayWeeklyCalories(result)
{
	document.getElementById("weeklyDiv").innerHTML = result;
	
}
function waterGlass(dt,action)
{
	//var dt=document.getElementById("exCategory").value;
	//alert(CategoriesID);
	var strSubmit = "action=waterGlass&date="+dt+"&glass="+action;
	var strURL = "ajaxValue.php";
	var strResultFunc="displayWaterGlass";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}
function displayWaterGlass(result)
{
	document.getElementById("waterGlass").innerHTML = result;
	
}
function weightLifting(dt)
{
	var hours = document.getElementById("hours").value;
	var mins = document.getElementById("mins").value;
	var time = Number(hours) * 60 + Number(mins);
	if( document.form1.exec[0].checked==true)
	{
		var activityId = document.form1.exec[0].value;
	}
	else
	{
		var activityId = document.form1.exec[1].value;
	}

	
	//return false;
	var strSubmit = "action=weightLifting&date="+dt+"&time="+time+"&activityId="+activityId;
	var strURL = "ajaxValue.php";
	var strResultFunc="displayWeightLifting";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}

function displayWeightLifting(result)
{
	document.getElementById("weightLiftingDiv").innerHTML = result;
	
}
/*function caldatelink(linkurl)
{
	//var dt=document.getElementById("exCategory").value;
	//alert(CategoriesID);
	var strSubmit = linkurl;
	var strURL = "ajaxValue.php";
	var strResultFunc="displaycal2";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}
function displaycal2(result)
{
	document.getElementById("cal2").innerHTML = result;
	
}*/
/*function searchFoods(keyWord,foodtable)
{
	
	alert(keyWord);
	var strSubmit = "action=searchFood&foodTable="+foodtable+"&keyWord="+keyWord;
	var strURL = "ajaxValue.php";
	var strResultFunc="displaySearchReasult";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
}
function displaySearchReasult(result)
{
	alert(result);
	document.getElementById("searchDiv").innerHTML = result;

}*/
function searchFoods(keyWord,foodtable)
{
	//alert (mainFoods);
	//alert(userFoods);
	
		document.getElementById("searchDiv").innerHTML = '<iframe src="foodSearch.php?foodTable='+foodtable+'&keyWord='+keyWord+'"  scrolling="no" frameborder="0" height="630" width="725" id="foodS"></iframe>';
	
	
	
}

function number_format( number, decimals, dec_point, thousands_sep ) {
   
   var i, j, kw, kd, km;
 
    // input sanitation & defaults
    if( isNaN(decimals = Math.abs(decimals)) ){
        decimals = 2;
    }
    if( dec_point == undefined ){
        dec_point = ",";
    }
    if( thousands_sep == undefined ){
        thousands_sep = ".";
    }
 
    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
 
    if( (j = i.length) > 3 ){
        j = j % 3;
    } else{
        j = 0;
    }
 
    km = (j ? i.substr(0, j) + thousands_sep : "");
    kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
    kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
 
 
    return km + kw + kd;
}


function changeState(val){
	document.getElementById('picID').style.display="";
	var strURL = "ajaxCall.php";
	strSubmit = "country="+val+'&action=getState';
	strResultFunc = "showState";
	xmlhttpPost(strURL,strSubmit,strResultFunc);	
}

function showState(str)
{
	document.getElementById('picID').style.display="none";
	document.getElementById('myState').innerHTML=str;
}

//function $(id){return document.getElementById(id);}
function showSearch(){
	document.getElementById('showMe').style.display="";
	document.getElementById('advSearch').style.display="none";
	document.getElementById('firstBut').innerHTML="&nbsp;";
}
function showComments(val1,val2,val3){
	//alert(val1+val2+val3)
	document.getElementById(val1).style.display='';
	document.getElementById(val3).style.display='';
	document.getElementById(val2).style.display='none';
}


function changeUp(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert(" Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbUP';
		strResultFunc = "showUp";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}
function changeUpPro(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert(" Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbUPPro';
		strResultFunc = "showUp";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}

function changeUpStory(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert(" Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbUPStory';
		strResultFunc = "showUp";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}
function changeUpPic(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert(" Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbUPPic';
		strResultFunc = "showUp";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}


function showUp(str)
{
	document.getElementById(chngID).style.display="none";
	document.getElementById(cntID).innerHTML=str;
}

function changeDown(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert("  Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbDN';
		
		strResultFunc = "showDown";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}
function changeDownPro(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert("  Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbDNPro';
		
		strResultFunc = "showDown";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}

function changeDownStory(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert("  Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbDNStory';
		
		strResultFunc = "showDown";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}

function changeDownPic(val,val1,val2,val3){
	chngID=val2;
	cntID=val1;
	if(!sess){
		alert("  Please login to vote...!"); 
		return false;
	}
	else{
		document.getElementById(chngID).style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "commentID="+val+'&action=thmbDNPic';
		
		strResultFunc = "showDown";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	}
}

function showDown(str)
{
	
	document.getElementById(chngID).style.display="none";
	document.getElementById(cntID).innerHTML=str;
}

function callAjaxPaging(val,val1,val3){
		document.getElementById('load1').style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "storyID="+val+'&action=callPageStory&page='+val1;
		
		strResultFunc = "showPging";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	
}
function showPging(str)
{

	document.getElementById('load1').style.display="none";
	document.getElementById('commentsID').innerHTML=str;
}


function callPicComments(val,val1,val3){
		document.getElementById('load1').style.display="";
		var strURL = val3+"ajaxCall.php";
		strSubmit = "picID="+val+'&action=picComment&page='+val1;
		
		strResultFunc = "showPicComment";
		xmlhttpPost(strURL,strSubmit,strResultFunc);	
	
}
function showPicComment(str)
{

	document.getElementById('load1').style.display="none";
	document.getElementById('commentsID').innerHTML=str;
}

function calorieBurn(val,val3){
		var alrt='';
		var wt =document.getElementById('weight').value;
		var unt= document.getElementById('unit').value;
		var hrs=document.getElementById('hours').value;
		var mints=document.getElementById('mints').value;

		if(wt==''){
			alrt +="- Please enter your weight \r\n";
		}
		if(unt==''){
			alrt +="- Please select a unit for weight \r\n";
		}
		
		if(hrs=='' && mints==''){
			alrt +="- Please enter time \r\n";
		}
		if(hrs!='' && mints!=''){
			if(hrs<=0 && mints<=0){
				alrt +="- Please enter time \r\n";
			}
		}
		if(isNaN(wt)==true ||isNaN(hrs)==true ||isNaN(mints)==true ){
			alrt +="- Please enter numeric value in these fields \r\n";
		}

		if(alrt){
			alert(alrt);
			return false;
		}
		else{
		
		document.getElementById('load1').style.display="";
		var strURL = val3+"ajaxCall.php";
		
		strSubmit = "actID="+val+'&action=activityPub&weight='+wt+'&unit='+unt+'&hr='+hrs+'&mins='+mints;
		strResultFunc = "showCalorie";
		xmlhttpPost(strURL,strSubmit,strResultFunc);
	}
	
}
function showCalorie(str)
{

	document.getElementById('load1').style.display="none";
	document.getElementById('brnCal').value =str;
	document.getElementById('showCal').innerHTML=str;
	
	
}

// This function will calculate RMR BMR

function calculateRMR(val3){
	
		var alrt='';
		var age =document.getElementById('age').value;
		var sex =(document.getElementById('sex1').checked==true)?document.getElementById('sex1').value:document.getElementById('sex2').value;

		var wt =document.getElementById('weight').value;
		var unt= document.getElementById('unit').value;
		var fts=document.getElementById('fts').value;
		var inchs=document.getElementById('inchs').value;

		if(age==''){
			alrt +="- Please enter your age \r\n";
		}
		if(wt==''){
			alrt +="- Please enter your weight \r\n";
		}
		if(unt==''){
			alrt +="- Please select a unit for weight \r\n";
		}
		
		if(fts=='' && inchs==''){
			alrt +="- Please enter height \r\n";
		}
		if(fts!='' && inchs!=''){
			if(fts<=0 && inchs<=0){
				alrt +="- Please enter height \r\n";
			}
		}
		if(isNaN(wt)==true ||isNaN(fts)==true ||isNaN(inchs)==true ||isNaN(age)==true){
			alrt +="- Please enter numeric value in these fields \r\n";
		}

		if(alrt){
			alert(alrt);
			return false;
		}
		else{
		
		document.getElementById('load1').style.display="";
		document.getElementById('load2').style.display="";
		var strURL = val3+"ajaxCall.php";
		
		strSubmit = 'action=rmrBmr&weight='+wt+'&unit='+unt+'&fts='+fts+'&inchs='+inchs+"&age="+age+"&sex="+sex;
		strResultFunc = "showRMR";
		xmlhttpPost(strURL,strSubmit,strResultFunc);
	}
	
}
function showRMR(str)
{

	document.getElementById('load1').style.display="none";
	document.getElementById('load2').style.display="none";
	var numRes =parseFloat(1.2)*parseFloat(str.replace(",",""));
	var numVal = numRes.toFixed(3);
	document.getElementById('sadRMR').innerHTML =numVal;
	
	document.getElementById('rmr').innerHTML=str;
	
	
}

// Following function will print exsercise 

function printExsercise(val,exID,exName){

	
	//alert(val);

	var id =val;
	var totExcVal=val;
	// Excersise tabel start here //-->


var genText='<div id="cont'+id+'"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tbody><tr>';
	genText+='<td class="pading-left10" valign="top" width="27%" align="left" height="25"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr>';
	genText+='<td class="bluetext12"><span class="style1"><label id="lblTxt'+id+'">'+exName+' </label></span></td><td valign="middle" align="center">';
	genText+='<img src="images/edit-icon1.gif" border="0" hspace="10"></td></tr>	</tbody></table><input id="totRow'+id+'" name="totRow'+id+'" value="3" type="hidden">';
	genText+='<input id="totExc'+id+'" name="totExc'+id+'" value="'+totExcVal+'" type="hidden"><input id="excID'+id+'" name="excID'+id+'" value="'+exID+'" type="hidden"><input id="totCnt'+id+'" name="totCnt'+id+'" value="" type="hidden">';
	genText+='</td><td id="AppendCel_ex'+id+'" style="padding-top: 3px;" valign="middle" width="73%" align="left">';
			// This table can grow or reduce its element  excID Hold Excercise ID
	genText+='<table id="appndedRow__ex'+id+'1" width="100%" cellpadding="0" cellspacing="0"><tbody><tr><td valign="middle" width="30%" align="left"><table border="0" cellpadding="0" cellspacing="0">';
	genText+='<tbody><tr><td><label><select name="sit__ex'+id+'1" class="inptxt" style="width: 100px;"><option>Select One</option><option value="1">Warmup Set</option>';
	genText+='<option value="2">Exercise Set</option></select></label></td> <td valign="middle" width="20" align="center"><strong><span id="rowVal__ex'+id+'1">1</span></strong><input name="setNo__ex'+id+'1" id="setNo__ex'+id+'1" value="1" type="hidden"></td>';
	genText+='</tr></tbody></table></td><td valign="middle" width="25" align="left" style="padding-right:5px"><input name="set_ex'+id+'1" id="set_ex'+id+'1" class="inptxt" value="" size="5" type="text"></td>';
	genText+='<td valign="middle" width="35" align="center"><input name="weight_ex'+id+'1" id="weight_ex'+id+'1" class="inptxt" value="" size="10" type="text"></td>';
	genText+='<td valign="middle" width="2%" align="left">&nbsp;</td><td valign="middle" width="38%" align="left"><table border="0" cellpadding="0" cellspacing="0">';
	genText+='<tbody><tr><td style="padding-right:5px"><label><input name="rest__ex'+id+'1" id="rest_ex'+id+'1" class="inptxt" value="" size="10" type="text"></label></td><td><label><input name="comment_ex'+id+'1" id="comment_ex'+id+'1" class="inptxt" value="" size="20" type="text"></label></td>';
	genText+='<td valign="middle" width="22" align="right"><img src="images/delete-icon.gif" onclick="deleteMe('+id+'1,'+id+')" width="17" border="0" height="14"></td>';
	genText+='</tr></tbody></table></td></tr></tbody></table> ';
		// This table can grow or reduce its element end here 
	genText+='<table id="appndedRow__ex'+id+'2" style="padding-top: 5px;" width="100%" cellpadding="0" cellspacing="0"><tbody><tr><td valign="middle" align="left"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td><label><select name="sit__ex'+id+'2" class="inptxt" style="width: 100px;"><option>Select One</option><option value="1">Warmup Set</option><option value="2">Exercise Set</option></select></label></td>';
	genText+='<td valign="middle" width="20" align="center"><strong><span id="rowVal__ex'+id+'2">2</span></strong><input name="setNo__ex'+id+'2" id="setNo__ex'+id+'2" value="2" type="hidden"></td></tr></tbody></table></td>';
	genText+='<td valign="middle" width="25" align="left" style="padding-right:5px"><input name="set_ex'+id+'2" id="set_ex'+id+'2" class="inptxt" value="" size="5" type="text"></td><td valign="middle" width="35" align="center">';
	genText+='<input name="weight_ex'+id+'2" id="weight_ex'+id+'2" class="inptxt" value="" size="10" type="text"></td><td valign="middle" width="2%" align="left">&nbsp;</td><td valign="middle" width="38%" align="left"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="padding-right:5px"><label><input name="rest__ex'+id+'2" id="rest_ex'+id+'2" class="inptxt" value="" size="10" type="text"></label></td>';
	genText+='<td><label><input name="comment_ex'+id+'2" id="comment_ex'+id+'2" class="inptxt" value="" size="20" type="text"></label></td><td valign="middle" width="22" align="right"><img src="images/delete-icon.gif" onclick="deleteMe('+id+'2,'+id+')" width="17" border="0" height="14"></td></tr></tbody></table></td></tr></tbody></table> ';
	
	genText+='<table id="appndedRow__ex'+id+'3" style="padding-top: 5px;" width="100%" cellpadding="0" cellspacing="0"><tbody><tr><td valign="middle" align="left"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td><label><select name="sit__ex'+id+'3" class="inptxt" style="width: 100px;"><option>Select One</option><option value="1">Warmup Set</option><option value="2">Exercise Set</option></select></label></td><td valign="middle" width="20" align="center"><strong>';
	genText+='<span id="rowVal__ex'+id+'3">3</span></strong><input name="setNo__ex'+id+'3" id="setNo__ex'+id+'3" value="3" type="hidden"></td></tr></tbody></table></td><td valign="middle" width="25" align="left" style="padding-right:5px"><input name="set_ex'+id+'3" id="set_ex'+id+'3" class="inptxt" value="" size="5" type="text"></td><td valign="middle" width="35" align="center"><input name="weight_ex'+id+'3" id="weight_ex'+id+'3" class="inptxt" value="" size="10" type="text"></td><td valign="middle" width="2%" align="left">&nbsp;</td><td valign="middle" width="38%" align="left">';
	genText+='<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="padding-right:5px"><label><input name="rest__ex'+id+'3" id="rest_ex'+id+'3" class="inptxt" value="" size="10" type="text"></label></td>';
	genText+='<td><label><input name="comment_ex'+id+'3" id="comment_ex'+id+'3" class="inptxt" value="" size="20" type="text"></label></td><td valign="middle" width="22" align="right"><img src="images/delete-icon.gif" onclick="deleteMe('+id+'3,'+id+')" width="17" border="0" height="14"></td></tr></tbody></table></td></tr></tbody></table></td>';
	
	genText+='</tr></tbody></table> </div>';
	genText+='<table width="100%" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td colspan="6" valign="bottom" align="center" height="20"><table width="95%" border="0" cellpadding="0" cellspacing="0">';
	genText+='<tbody><tr><td valign="bottom" width="50%" align="left"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td valign="middle" width="20" align="left"><img src="images/up-arrow.gif" onclick="sendUp('+id+')" width="14" height="15"></td>';
	genText+='<td class="blu11" valign="middle" width="60" align="left"><a href="javascript:void(0)" onclick="sendUp('+id+')">Move Up</a></td><td valign="middle" width="20" align="left"><img src="images/down-arrow.gif" onclick="sendDown('+id+')" width="14" height="15"></td>';
	genText+='<td class="blu11" valign="middle" align="left"><a href="javascript:void(0)" onclick="sendDown('+id+')">Move Down</a></td></tr></tbody></table></td>';
	//Change inner value with updown of above block//-->
	genText+='<td id="opr'+id+'" valign="top" align="right"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td valign="top" width="20" align="left"><img src="images/add-icon.gif" onclick="javascript:addaNewRow('+id+')" align="absmiddle" border="0"></td>';
	genText+='<td valign="top" width="70" align="left"><a href="javascript:void(0)" class="bluelnks-n" onclick="javascript:addaNewRow('+id+')">Add a Set</a></td>';
	genText+='<td valign="top" width="20" align="left"><img src="images/delete-icon.gif" onclick="deleteExsercise('+id+')" align="absmiddle" border="0"></td>';
	genText+='<td valign="top" align="left"><a href="javascript:void(0)" class="bluelnks-n" onclick="deleteExsercise('+id+')">Delete Exercise</a></td></tr></tbody></table></td> </tr>';
	genText+='</tbody></table></td> </tr> <tr><td colspan="6" class="btmbr" valign="middle" align="left"><img src="images/spacer.gif"  width="1" height="10"></td>';
	genText+='</tr><tr><td colspan="6" valign="middle" align="left"><img src="images/spacer.gif"  width="1" height="10"></td> </tr> </tbody></table>';
	//Excersise tabel start here
	var nxtId =parseInt(id)+1;

	window.opener.document.getElementById('compBlock'+id).innerHTML=genText;
	window.opener.document.getElementById('mainID').innerHTML=window.opener.document.getElementById('mainID').innerHTML+'<span id="compBlock'+nxtId+'" style="padding-top: 5px;"></span>';
	
	
	if(window.opener.document.getElementById('totBlockEx')){
		
		window.opener.document.getElementById('totBlockEx').value=nxtId
	}
	else{
		
		window.opener.document.getElementById('totBlock').value=nxtId;
	}
	
	window.close();
	
} 

function openWin(){
	updateAllDOMFields(document.form123);
	window.open('exercise-tracking-pop.php','myWin','width=800,height=550px,menubar=no,resizable=0,toolbar=no,status=no, scrollbars=1');
}

function sendUp(val){
	var nextBlock;
	var curBlock; // used for hold value of current block
	var curNavig ;// used for hold value of current action button block
	var swapBlock ; // used for hold value of to be swap 
	var swapNavig ; // used for hold value of to be swap  action block
	var maxBlock = document.getElementById('totBlock').value;
	var upVal=0;

	// checke prev block 
	for(var i=val-1; i>0;i--){
		if(document.getElementById("cont"+i)){
			upVal =i;
			break;
		}
	}

//alert(upVal);
	if(upVal>0){
		
		updateAllDOMFields(document.form123);
		
		curBlock =$('#cont'+val).html();
		curNavig =$('#opr'+val).html();
		swapBlock =$('#cont'+upVal).html();
		swapNavig =$('#opr'+upVal).html();
		
		$('#cont'+val).html(swapBlock);
		$('#opr'+val).html(swapNavig);
		$('#cont'+upVal).html(curBlock) ;
		$('#opr'+upVal).html(curNavig);
	
	}
}
// This function swap value towards down
function sendDown(val){

	var nextBlock;
	var curBlock; // used for hold value of current block
	var curNavig ;// used for hold value of current action button block
	var swapBlock ; // used for hold value of to be swap 
	var swapNavig ; // used for hold value of to be swap  action block
	if(document.getElementById('totBlockEx')){
		var maxBlock = parseInt(document.getElementById('totBlockEx').value)-1;
	}else{
		var maxBlock = parseInt(document.getElementById('totBlock').value)-1;
	}
//	var downVal =parseInt(val)+1;
	var downVal =0;

	// checke Next block 
	for(var i=parseInt(val)+1; i<=parseInt(maxBlock);i++){
		if(document.getElementById("cont"+i)){
			downVal =i;
			break;
		}
	}
//alert(maxBlock);
//alert(val);


	if(downVal>1){
//alert(downVal);	
		

		updateAllDOMFields(document.form123);

		curBlock = $('#cont' + val).html();
		//alert(curBlock);
		curNavig = $('#opr'+ val).html();
		swapBlock = $('#cont'+ downVal).html();
		swapNavig = $('#opr'+ downVal).html();
		$('#cont'+ val).html(swapBlock);
		$('#opr'+ val).html(swapNavig);
		$('#cont'+ downVal).html(curBlock);
		$('#opr'+ downVal).html(curNavig);

	
	}
}
// This function add new row 
function addaNewRow(apenRow)
{
	//alert(apenRow);
		updateAllDOMFields(document.form123);

		var apenRowVal='AppendCel_ex'+apenRow;
		//alert(document.getElementById('AppendCel_ex1'));

		var id = parseInt(document.getElementById('totRow'+apenRow).value)+1;
		
//alert(id);
		document.getElementById(apenRowVal).innerHTML=document.getElementById(apenRowVal).innerHTML+'<table width="100%" cellpadding="0" cellspacing="0" id="appndedRow__ex'+apenRow+id+'" style="padding-top:5px"><td align="left" valign="middle"><table border="0" cellspacing="0" cellpadding="0"><tr><td><label><select name="sit__ex'+apenRow+id+'"  class="inptxt" style="width:100px;"><option>Select One</option><option value="1">Warmup Set</option><option value="2">Exercise</option></select></label></td><td width="20" align="center" valign="middle"><strong><span id="rowVal__ex'+apenRow+id+'">'+id+'</span></strong><input type="hidden" name="setNo__ex'+apenRow+id+'" id="setNo__ex'+apenRow+id+'" value="'+id+'"/></td></tr></table></td><td align="left" valign="middle" width="25" style="padding-right:5px"><input name="set_ex'+apenRow+id+'" id="set_ex'+apenRow+id+'" type="text" class="inptxt" value="" size="5" /></td><td align="center" valign="middle" width="35"><input name="weight_ex'+apenRow+id+'" id="weight_ex'+apenRow+id+'" type="text" class="inptxt" value="" size="10" /></td><td align="left" valign="middle" width="2%">&nbsp;</td><td align="left" valign="middle" width="38%"><table border="0" cellspacing="0" cellpadding="0"><tr><td style="padding-right:5px"><label><input name="rest__ex'+apenRow+id+'" id="rest_ex'+apenRow+id+'" type="text" class="inptxt" value="" size="10" /></label></td><td><label><input name="comment_ex'+apenRow+id+'" id="comment_ex'+apenRow+id+'" class="inptxt" value="" size="20" type="text"></label></td><td width="22" align="right" valign="middle"><img src="images/delete-icon.gif" width="17" height="14" border="0" onclick="deleteMe('+apenRow+id+','+apenRow+')" /></td></tr></table></td></tr></table> ';
		
		document.getElementById('totRow'+apenRow).value =id;



	var cntVal=$('#totCnt'+apenRow).val();
	
	var k=1;
	if(cntVal){
		for(var i=1; i<=id;i++){
			if($('#rowVal__ex'+apenRow+i).html()){
			
				$('#rowVal__ex'+apenRow+i).html(k);
				$('#setNo__ex'+apenRow+i).val(k);
				k++;
			}
			
		}
	}
}

function deleteMe(id,rid){
	
var flg=confirm("Are you sure you want to delete this Exercise?");
	
	if(flg==true){
		idVal ="appndedRow__ex"+id;
		
				
		$('#'+idVal).remove();
		
		// Update total count value 
		var lastVal =$('#totRow'+rid).val();

		

		var cntVal=0;
		var k =1;
		for(var i=1; i<=lastVal;i++){
			
			
			if($('#rowVal__ex'+rid+i).html()){
				$('#rowVal__ex'+rid+i).html(k);
				$('#setNo__ex'+rid+i).val(k);
				cntVal++;
				k++;
			}
			// Keep new row count 
			$('#totCnt'+rid).val(cntVal);
			//$('#totRow'+rid).val(parseInt(lastVal)-1);

		}
		
	}
	else{
		return false;
	}
}

function deleteExsercise(id){
	
	var flg=confirm("Are you sure you want to delete Exercise?");

		if(flg==true){
		var idVal;
		
		// take ex id to remove 

		var delId =document.getElementById('excID'+id).value;
		
		if(document.getElementById('delExId')){
			var curId =document.getElementById('delExId').value + delId+"#" ;
			document.getElementById('delExId').value=curId; 
		}

		idVal ="compBlock"+id;
		$('#'+idVal).remove();
	}
	else{
		return false;
	}

}

// This function retrun calrory burn value
function weightLiftingNew(dt)
{
	var hours = document.getElementById("hrs").value;
	var mins = document.getElementById("mins").value;
	var time = Number(hours) * 60 + Number(mins);

	if(time==0){
		alert("Please enter time");
		return false;
	}

	if(document.form123.calBrn[0].checked==true){
		var activityId = document.form123.calBrn[0].value;
	}
	else{
		var activityId = document.form123.calBrn[1].value;
	}
	//alert(activityId);
	//return false;
	var strSubmit = "action=weightLifting&date="+dt+"&time="+time+"&activityId="+activityId;
	var strURL = "ajaxValue.php";
	var strResultFunc="displayWeightLifting";
	xmlhttpPost(strURL, strSubmit, strResultFunc);
	return false;
}


function openEdit(action,id,activityId)
{
	window.open( 'add-activity-popup.php?action='+action+'&EditID='+id+'&ActivityID='+activityId+'&todate=<?=$todate?>', 'mywin2', 'width=450,height=500,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0,screenX=0,left=10,screenY=0,top=100' );
	
}

function updateAllDOMFields(theForm){
	var inputNodes = getAllFormFields(theForm);
	for(x=0; x < inputNodes.length; x++){
	var theNode = inputNodes[x];
	updateDOMField(theNode)
	}
}

function getAllFormFields(theForm){
try{
var inputFields = theForm.getElementsByTagName("input");
var selectFields = theForm.getElementsByTagName("select");
var textFields = theForm.getElementsByTagName("textarea");
var array = new Array(inputFields + selectFields + textFields);
for(i=0; i < array.length; i++){
for(x=0; x < inputFields.length; x++){
array[i] = inputFields[x];
i++
}
for(a=0; a < selectFields.length; a++){
array[i] = selectFields[a];
i++
}
for(t=0; t < textFields.length; t++){
debug("Text box Found"+textFields.name);
array[i] = textFields[t];
i++
}
}
}
catch(e){alert("Error when evoking getAllFormFields(): \nSomething is probably wrong with the form you passed in\n\n"+e.message)}
return array;
}

function updateDOMField(inputField) {
    // if the inputField ID string has been passed in, get the inputField object
    if (typeof inputField == "string") {
        inputField = document.getElementById(inputField);
    }

    if (inputField.type == "select-one") {
        for (var i=0; i<inputField.options.length; i++) {
            if (i == inputField.selectedIndex) {
                inputField.options[inputField.selectedIndex].setAttribute("selected","selected");
            }
        }
    } else if (inputField.type == "text") {
        inputField.setAttribute("value",inputField.value);
    } else if (inputField.type == "textarea") {
        inputField.setAttribute("value",inputField.value);
    } else if ((inputField.type == "checkbox") || (inputField.type == "radio")) {
        if (inputField.checked) {
            inputField.setAttribute("checked","checked");
        } else {
            inputField.removeAttribute("checked");
        }
    }
}


