function openWindow(cUrl,cName,cFeatures)
{
	var xWin = window.open(cUrl,cName,cFeatures)
}

function winpopup(url,win,attrib)
{
	var wins=window.open(url,win,attrib);
}

function passfill()
{
  var arrb=new Array("Old Password","New Password","Confirm password");
  for(var b=0;b<document.frm1.elements.length;b++)
  {
    var ques=document.frm1.elements[b].value;
	var queslen=ques.length;
	var sin=0;

	if(queslen==0)
	{
		alert(arrb[b]+" cannot be left blank.");
		document.frm1.elements[b].focus();
		return false;
	}
	for(var k=0;k<queslen;k++)
	{
		if(ques.charAt(k)==" ") sin++;
	}
	
	if(sin==queslen)
	{
		alert(arrb[b]+" cannot be left blank.");
		document.frm1.elements[b].select();
		document.frm1.elements[b].focus();
		return false;
	}
	
	if(b==2)
	{
		if(document.frm1.elements[2].value!=document.frm1.elements[1].value)
		{
			alert("Please Check Your Password and Confirm Password.");
			document.frm1.elements[2].focus();
			document.frm1.elements[2].select();
			return false;
		}
	}	
  }//Outer For Loop
}//Function Closing

function chkunchkall()
{
	var sin=0, cos=0;
	for(var i=0;i<document.frmb.elements.length;i++)
	{
		if(document.frmb.elements[i].name.substr(0,2)=="cb")
		{
			if(document.frmb.cx.checked==false)	document.frmb.elements[i].checked=false;
			else if(document.frmb.cx.checked==true) document.frmb.elements[i].checked=true;
		}
	}
}

<!-- Begin email validation 
function emailCheck (emailStr) {
 
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
 
var checkTLD=1;
 
/* The following is the list of known TLDs that an e-mail address must end with. */
 
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
 
/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */
 
var emailPat=/^(.+)@(.+)$/;
 
/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */
 
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]\\'";
 
/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/
 
var validChars="\[^\\s" + specialChars + "\]";
 
/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
 
var quotedUser="(\"[^\"]*\")";
 
/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
 
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
 
/* The following string represents an atom (basically a series of non-special characters.) */
 
var atom=validChars + '+';
 
/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
 
var word="(" + atom + "|" + quotedUser + ")";
 
// The following pattern describes the structure of the user
 
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
 
/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
 
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
 
/* Finally, let's start trying to figure out if the supplied address is valid. */
 
/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
 
var matchArray=emailStr.match(emailPat);
 
if (matchArray==null) {
 
/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
 
alert("Email address seems incorrect (check @ and .'s)");
return false;

}
var user=matchArray[1];
var domain=matchArray[2];
 
// Start by checking that only basic ASCII characters are in the strings (0-127).
 
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}
 
// See if "user" is valid 
 
if (user.match(userPat)==null) {
 
// user is not valid
 
alert("The username doesn't seem to be valid.");
return false;
}
 
/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
 
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
 
// this is an IP address
 
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
 
// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}
 
/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */
 
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
 
// Make sure there's a host name preceding the domain.
 
if (len<2) {
alert("This address is missing a hostname!");
return false;
}
 
// If we've gotten this far, everything's valid!
return true;
}
 
//  End -->
  
function trim(data)
{

// triming from right

	while(''+data.value.charAt(data.value.length-1)==' ')
	
	data.value=data.value.substring(0,data.value.length-1);
	
	// triming from left
	
	while(''+data.value.charAt(0) == ' ')
	
	data.value=data.value.substring(1,data.value.length);

}  
	
// function check for numeric values
	
function IsNumeric(strString)
//  check for valid numeric strings	
{
var strValidChars = "0123456789";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

//  test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
  {
  strChar = strString.charAt(i);
  if (strValidChars.indexOf(strChar) == -1)
     {
		blnResult = false;
     }
  }
return blnResult;
}
   	
// function check for numeric values
	
function IsPhone(strString)
//  check for valid numeric strings	
{
var strValidChars = "0123456789-";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

//  test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
  {
  strChar = strString.charAt(i);
  if (strValidChars.indexOf(strChar) == -1)
     {
		blnResult = false;
     }
  }
return blnResult;
}
   
// function check for alpha-numeric values
	
function AlphaNumeric(strString)
//  check for valid numeric strings	
{
	var strValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz,'.-()/#&";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
	     {
			blnResult = false;
	     }
	  }
	return blnResult;
}   

// function check for alphabets only

function isAlpha(strString)
{
	var strValidChars = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ'";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
	     {
			blnResult = false;
	     }
	  }
	return blnResult;
}

// function check for alphabets only

function isAlpha1(strString)
{
	var strValidChars = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ',.";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
	     {
			blnResult = false;
	     }
	  }
	return blnResult;
}

//function for select all 
function selectAll(theElement) 
{
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++)
	 {
     	if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
     	{
	 		theForm[z].checked = theElement.checked;
	  	}
     }
}

// function for delete confirmation
function askforremoval(thetype)
{
	if(confirm("Are you sure you would like to delete this "+thetype+" ?")) 
		return true;
	else 
		return false;
}

// function for Workout Cardio or strength
function askforremovalWorkout()
{
	if(confirm("Are you sure you want to delete this Workout?")) 
		return true;
	else 
		return false;
}
ie = (document.all) ? 1 : 0;
n = !ie;
function Go(){
document.onkeypress = keyDown;

if (n) {
    document.captureEvents(Event.KEYPRESS);
}
}

function keyDown(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode==60 || keycode==62)
    {
        alert("This key is blocked for this application");
    	return false;
    }

}

// function to validate url string

function validateURL(urlStr)
 {
 	urlStr1 = urlStr;
 	urlStr = urlStr.value;
 
 if (urlStr.indexOf(" ")!=-1){
  alert("Spaces are not allowed in a URL");
  urlStr1.focus();
  return false;
 }
 if(urlStr==""||urlStr==null){
  return false;
 }
  urlStr=urlStr.toLowerCase();
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
  var validChars="\[^\\s" + specialChars + "\]";
  var atom=validChars + '+';
  var urlPat=/^(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
  var matchArray=urlStr.match(urlPat);
 if (matchArray==null){
  alert("The URL seems incorrect, check it should be in the format www.yourdomain.extension");
  urlStr1.focus();
  return false;
 }
 var user=matchArray[2];
 var domain=matchArray[3];
 for (i=0; i<user.length; i++) {
 if (user.charCodeAt(i)>127) {
  alert("This domain contains invalid characters.");
  urlStr1.focus();
  return false;
   }
 }
 for (i=0; i<domain.length; i++) 
 {
 if (domain.charCodeAt(i)>127) {
  alert("This domain name contains invalid characters.");
  urlStr1.focus();
  return false;
  }
 }
 var atomPat=new RegExp("^" + atom + "$");
 var domArr=domain.split(".");
 var len=domArr.length;for (i=0;i<len;i++) 
  {
  if (domArr[i].search(atomPat)==-1) 
  {
   alert("The domain name does not seem to be valid.");
   urlStr1.focus();
   return false;
  }
  }

}

// function to validate folat value
function fixFloat(fld,fieldName)
{ 
	// decimal number check/complainer 
	var val= fld.value;
	if(val != "")
	{
		val= parseFloat(fld.value);
		if(isNaN(val))
		{ 
			// parse error 
			status=fieldName+' must contain a decimal value.';
			fld.value = "";
			fld.focus();
			alert(status);
			return false;
		}
	}
}

// function to validate integer value
function fixInt(fld,fieldName)
{ 
	// decimal number check/complainer 
	var val= fld.value;
	if(val != "")
	{
		val= parseInt(fld.value);
		if(isNaN(val))
		{ 
			// parse error 
			status=fieldName+' must contain a decimal value.';
			fld.value = "";
			fld.focus();
			alert(status);
			return false;
		}
	}
}

// function to validate 12 HR time

function fixTime(fld,starthour) 
{ 
	// tenacious time correction 
	if(!fld.value.length||fld.disabled) 
		return true; // blank fields are the domain of requireValue 
	var hour= 0; 
	var mins= 0;
	var ampm= 'am';
	val= fld.value;
	var dt= new Date('1/1/2000 ' + val);
	if(('9'+val) == parseInt('9'+val))
	{ 
		hour= val; 
	}
	else if(dt.valueOf())
	{ 
		hour= dt.getHours(); mins= dt.getMinutes(); 
	}
	else
	{
		val= val.replace(/\D+/g,':');
		hour= parseInt(val);
		mins= parseInt(val.substring(val.indexOf(':')+1,20));
		
		if(val.indexOf('pm') > -1) 
			ampm= 'pm';
		if(isNaN(hour)) 
			hour= 0;
		if(isNaN(mins)) 
			mins= 0;
	}
	
	if(hour < starthour) 
	{ 
		ampm= 'pm'; 
	}
	
	while(hour > 12) 
	{ 
		hour-= 12; 
		ampm= 'pm'; 
	}
	
	while(mins > 60) 
	{ 
		mins-= 60; 
		hour++; 
	}
	
	if(mins < 10) 
		mins= '0' + mins;
		
	if(!hour)
	{ 
		// the date was unparseable 
		status= 'The '+fieldname(fld)+' field has the wrong time.';
		return false;
	}
	fld.value= hour + ':' + mins + ampm;
	return true;
}


// function to validate 24 HR time
function fixTime24(fld) 
{ 
	
	// tenacious time correction 
	if(!fld.value.length||fld.disabled) 
		return true; // blank fields are the domain of requireValue 
	var hour= 0; 
	var mins= 0;
	val= fld.value;
	var dt= new Date('1/1/2000 ' + val);
	
	if(('9'+val) == parseInt('9'+val))
	{ 
		hour= val; 
	}
	else if(dt.valueOf())
	{ 
		hour= dt.getHours(); mins= dt.getMinutes(); 
	}
	else
	{
		val= val.replace(/\D+/g,':');
		hour= parseInt(val);
		mins= parseInt(val.substring(val.indexOf(':')+1,20));
		
		if(isNaN(hour)) 
			hour= 0;
			
		if(isNaN(mins)) 
			mins= 0;
			
		if(val.indexOf('pm') > -1) 
			hour+= 12;
	}
	
	hour%= 24;
	mins%= 60;
	
	if(mins < 10) 
		mins= '0' + mins;
	fld.value= hour + ':' + mins;
	return true;
}

// function for Adding food
function foodPopUp(fType,fDate)
{
	newwindow =	window.open( "addFood.php?fType="+fType+"&fDate="+fDate, "AddFood","status = 1, height = 410, width = 466, resizable = 0" );
    if (window.focus) {newwindow.focus()}
}

 /* function getSelected(opt) {
            var selected = new Array();
            var index = 0;
            for (var intLoop = 0; intLoop < opt.length; intLoop++) {
               if ((opt[intLoop].selected) ||
                   (opt[intLoop].checked)) {
                  index = selected.length;
                  selected[index] = new Object;
                  selected[index].value = opt[intLoop].value;
                  selected[index].index = intLoop;
               }
            }
            return selected;
         }
*/

function submitFood()
{
	lstbox=document.getElementById("lstFood").value;
	dropdown=document.getElementById("amountOfItem").value;
//	serving=document.getElementById("serving").value;
//	alert(dropdown+'AAA'+serving);
	var fDate=document.frmSearch.fDate.value;
	var txtVal=document.frmSearch.numberOfItems.value;
	if(txtVal=="")
			txtVal=1;
		if(document.frmSearch.checkbox.checked == true)
			window.opener.location.href="foodJournal.php?ftype="+document.frmSearch.fType.value+"&foodList="+lstbox+"&dropVal="+dropdown+"&txtVal="+txtVal+"&per="+document.frmSearch.checkbox.value+"&fDate="+fDate;
		else
			window.opener.location.href="foodJournal.php?ftype="+document.frmSearch.fType.value+"&foodList="+lstbox+"&dropVal="+dropdown+"&txtVal="+txtVal+"&fDate="+fDate;
	window.close();
}

function setVisibility(id1,id2,id3) 
{
	document.getElementById(id1).style.display = "block";
	document.getElementById(id2).style.display = "none";
	document.getElementById(id3).style.display = "none";
}
//***************** for increase and decreasing water///////////////////////////////////********************************************
function increaseWater(fDate)
{
	var url = './ounceWater.php?inc=' + document.getElementById('divWater').innerHTML+"&fDate="+fDate;
	req = false;
	if(window.XMLHttpRequest) { // branch for native	XMLHttpRequest object
	try {
	req = new XMLHttpRequest();
	} catch(e) {
	req = false;
	}
	}
	else if(window.ActiveXObject) { // branch for IE/Windows 	ActiveX version
	try {
	req = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
	try {
	req = new
	ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
	req = false;
	}
	}
	}
	if(req){
	req.onreadystatechange = showResult;
	req.open("GET", url, true);
	req.send("");
	}
}

function decreaseWater(fDate)
{
	var url = './ounceWater.php?dec=' + document.getElementById('divWater').innerHTML+"&fDate="+fDate;
	req = false;
	if(window.XMLHttpRequest) { // branch for native	XMLHttpRequest object
	try {
	req = new XMLHttpRequest();
	} catch(e) {
	req = false;
	}
	}
	else if(window.ActiveXObject) { // branch for IE/Windows 	ActiveX version
	try {
	req = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
	try {
	req = new
	ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
	req = false;
	}
	}
	}
	if(req){
	req.onreadystatechange = showResult;
	req.open("GET", url, true);
	req.send("");
	}
}

function showResult() 
{
	if(req.readyState == 4) 
	{
		document.getElementById('divWater').innerHTML="";
		document.getElementById('divWater').innerHTML=req.responseText;
	} 
}


function addFood(fName,cal,carbs,fat,prot,fType,fdate) 
{
	if(fName=='')
	{
		alert("Please enter the new Food Name");
		return false;
	}
	//else if(document.frmSearch.serving.value != "")
	//{
	//	serving_array = document.frmSearch.serving.value;
	//}

//	document.frmSearch.hiddenserving.value = serving_array;
	
//	var hiddenserving = document.frmSearch.serving.value;
	var ndb = document.frmSearch.ndb.value;
	
	//alert(hiddenserving);
	
	window.location.href="addFood.php?fName="+fName+"&cal="+cal+"&carbs="+carbs+"&fat="+fat+"&prot="+prot+"&fType="+fType+"&ndb="+ndb+"&fDate="+fdate;
}


//**********************************For showing Listbox corresponding value in dropdown


function updateDropdown()
{
	var val=document.getElementById("lstFood").value;
	var url = './updateDropdown.php?val=' +val;
	req = false;
	if(window.XMLHttpRequest) 
	{ // branch for native	XMLHttpRequest object
		try 
		{
			req = new XMLHttpRequest();
		} 
		catch(e) 
		{
			req = false;
		}
	}
	else if(window.ActiveXObject) 
	{ // branch for IE/Windows 	ActiveX version
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			try 
			{
				req = new
				ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e) 
			{
				req = false;
			}
		}
	}
	
	if(req)
	{
		req.onreadystatechange = showDropdownResult;
		req.open("GET", url, true);
		req.send("");
	}
}

function showDropdownResult() 
{
//	alert("Ready State:"+req.readyState+" Text "+req.responseText);
	if(req.readyState == 4) 
	{
		document.getElementById('divDropdown').innerHTML="";
		document.getElementById('divDropdown').innerHTML=req.responseText;
	} 
	else
	{
		document.getElementById('divDropdown').innerHTML="Please Wait...";
	}
}

function changeImage(image1)
{
	document.getElementById('headingImage').src = "./images/"+image1;
}

// function to update display date on select of the date from calendar
function setDisplayDate()
{
	var val=document.getElementById("dateWorkout").value;
	var url = './updateDisplayDate.php?val=' +val;
	req = false;
	if(window.XMLHttpRequest) 
	{ // branch for native	XMLHttpRequest object
		try 
		{
			req = new XMLHttpRequest();
		} 
		catch(e) 
		{
			req = false;
		}
	}
	else if(window.ActiveXObject) 
	{ // branch for IE/Windows 	ActiveX version
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			try 
			{
				req = new
				ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e) 
			{
				req = false;
			}
		}
	}
	
	if(req)
	{
		req.onreadystatechange = returnDisplayDate;
		req.open("GET", url, true);
		req.send("");
	}
}

// function to return display date
function returnDisplayDate()
{
	if(req.readyState == 4) 
	{
		document.getElementById('divDate').innerHTML="";
		document.getElementById('divDate').innerHTML=req.responseText;
	}
}

// function to fill intensity on the basis of exercise selected

function fillIntensity(dVal,pVal)
 {
	
	var val=document.getElementById("exercise").value;
	if(val=="")
		val=dVal;
		var strSubmit ='1' ;
	//alert("HELLO");	 
		var strURL = "./fillIntensity.php?val="+val+"&pVal="+pVal;
		
		var strResultFunc = "displayResult";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
		
 }

 function filluserWorkoutIntensity(dVal,pVal)
 {
	
	var val=document.getElementById("exercise").value;
	if(val=="")
		val=dVal;
		var strSubmit ='1' ;
	//alert("HELLO");	 
		var strURL = "./fillIntensity.php?wEid="+val+"&wSid="+pVal;
		
		var strResultFunc = "displayUserResult";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
		
 }

// *****************************for workount excerise and intensity******************************

 function fillWorkoutIntensity(dVal,pVal)
 {
	
	var val=document.getElementById("exeID").value;
	if(val=="")
		val=dVal;
		var strSubmit ='1' ;
		 
		var strURL = "./fillIntensity.php?val="+val+"&pVal="+pVal;
		
		var strResultFunc = "displayResult";
		xmlhttpPost(strURL, strSubmit, strResultFunc);
		
 }

function displayResult(result){
	var sel_flag;
	var str1='';
	var i = 0;
	var comb;
//alert(result);
	comb2=result.split("@");
	comb=comb2[1].split("::");
	
	document.frmWorkOut.intensity.options.length=0;
	var sel_flag = false;
	document.frmWorkOut.intensity.options.add(new Option('Select Intensity','',sel_flag));
		for(i=0; i < comb.length-1; i++){
			comb1=comb[i].split(",");
			if(comb2[0] == comb1[0]){
				sel_flag = true;
			}
		 	  document.frmWorkOut.intensity.options.add(new Option(comb1[1],comb1[0],sel_flag));
		}
		document.getElementById("intensity").value=comb2[0];
}

function displayUserResult(result){
	var sel_flag;
	var str1='';
	var i = 0;
	var comb;
	
	if(result.length !=1){

	comb2=result.split("@");
	comb=comb2[1].split("::");
	
	document.frmWorkOut.subcategory.options.length=0;
	var sel_flag = false;
	document.frmWorkOut.subcategory.options.add(new Option('Select Subcategory','',sel_flag));
		for(i=0; i < comb.length-1; i++){
			comb1=comb[i].split(" ");
	
			if(comb2[0] == comb1[0]){
				sel_flag = true;
			}
		 	  document.frmWorkOut.subcategory.options.add(new Option(comb1[1],comb1[0],sel_flag));
		}
		document.getElementById("subcategory").value=comb2[0];
	
	
 }

}

	