function Validate(f)
{
	if(CheckValue(f.firstname,"Enter the firstname")){return false;}
	if(CheckValue(f.lastname,"Enter the lastname")){return false;}
	
	if(CheckValue(f.password,"Enter the password")){return false;}
	if(f.password.value!=f.repassword.value)
	{
		alert("Password & RetypePassword not matched");  
		f.repassword.focus();
		return false;
	}
	if(!ValidEmail(f.emailAddress))
	{ 
		alert("Enter valid email"); 
		f.emailAddress.focus();return false; 
	}
	if(CheckValue(f.zipcode,"Enter the Zip")){return false;}
	processreg1(f.firstname.value,f.lastname.value,f.emailAddress.value,f.password.value,f.yearborn.value,f.aid.value);
return false;
}

function Validateregdiet(f)
{
	
//	if(CheckValue(f.age,"Enter the Age")){return false;}
	if(!(f.gender[0].checked) && !(f.gender[1].checked))
	{
		alert("Please Select the Gender");
			return false;
	}
	if(!(f.gender[0].checked) && !(f.gender[1].checked))
	{
		alert("Please Select the Gender");
			return false;
	}
	if(f.yearborn.value=="select")
	{
		alert("Please Select Born Year")
		return false;
	}
	if(CheckValue(f.height,"Enter the Height")){return false;}
	if(CheckValue(f.weight,"Enter the Weight")){return false;}
	/*if(!(f.goal[0].checked) && !(f.goal[1].checked))
	{
		alert("Please Select Your Goal");
		return false;
	}*/

/*	if(f.goalweight.value=="Select Goal Weight")
	{
		alert("Please Select Goal weight")
		return false;
	}

	if(f.goal[0].checked && !(f.weeklyweightlose[0].checked) && !(f.weeklyweightlose[1].checked) && !(f.weeklyweightlose[2].checked) && !(f.weeklyweightlose[3].checked))
	{
		alert("Please Select Your Weekly weight Loss");
		return false;
	}*/
	if(CheckValue(f.workactivitylevel,"Work Activity Level") || CheckValue(f.liesureactivitylevel,"Leisure Activity Level"))
	{
		alert("Please Select Activity Levels");
		return false;
	}
	if(f.gender[0].checked)
	{
		gendval = "0";
	}
	else
	{
		gendval = "1";
	}
	
	if(f.goal[0].checked)
	{
		goalval = "loseweight"; 
	}
	else
	{
		goalval = "maintainweight"; 
	}
	wwtloseval="";
	if(f.weeklyweightlose[0].checked)
	{
		wwtloseval = "0.5lb";
	}
	else if(f.weeklyweightlose[1].checked)
	{
		wwtloseval = "1lb";
	}
	else if(f.weeklyweightlose[2].checked)
	{
		wwtloseval = "1.5lb";
	}
	else if(f.weeklyweightlose[3].checked)
	{
		wwtloseval = "2lb";
	}
	processdietfun(f.age.value,gendval,f.height.value,f.heightms.value,f.HeightM.value,f.weight.value,f.WeightM.value,goalval,f.goalweight.value,wwtloseval,f.workactivitylevel.value,f.liesureactivitylevel.value);
return false;	
}

function Validatenewsfrm(f)
{
	if(!(f.dietician[0].checked) && !(f.dietician[1].checked))
	{
		alert("Please Select interested in speaking with a dietician or not");
		return false;
	}
	if(!(f.healthymenu[0].checked) && !(f.healthymenu[1].checked))
	{
		alert("Please Select interested in developing a healthy menu for your family or not");
		return false;
	}
	if(!(f.customwork[0].checked) && !(f.customwork[1].checked))
	{
		alert("Please Select interested in a custom work out program or not");
		return false;
	}
	
	if(f.dietician[0].checked)
	{
		dietval = "yes";
	} else	{
		dietval = "no";
	}
	
	if(f.healthymenu[0].checked)
	{
		healthymenuval = "yes";
	} else	{
		healthymenuval = "no";
	}
	
	if(f.customwork[0].checked)
	{
		customworkval = "yes";
	} else {
		customworkval = "no";
	}
	
	processnewsfun(f.newsletteropt.value,dietval,healthymenuval,customworkval,f.aid.value);
return false;
}

function Validatesmartregdiet(f)
{
	if(CheckValue(f.age_sdp,"Enter the Age")){return false;}
	if(!(f.gender_sdp[0].checked) && !(f.gender_sdp[1].checked))
	{
		alert("Please Select the Gender");
			return false;
	}
	if(CheckValue(f.height_sdp,"Enter the Height")){return false;}
	if(CheckValue(f.weight_sdp,"Enter the Weight")){return false;}
	if(!(f.goal_sdp[0].checked) && !(f.goal_sdp[1].checked))
	{
		alert("Please Select Your Goal");
		return false;
	}

	if(f.goalweight_sdp.value=="Select Goal Weight")
	{
		alert("Please Select Goal weight")
		return false;
	}

	if(f.goal_sdp[0].checked && !(f.weeklyweightlose_sdp[0].checked) && !(f.weeklyweightlose_sdp[1].checked) && !(f.weeklyweightlose_sdp[2].checked) && !(f.weeklyweightlose_sdp[3].checked))
	{
		alert("Please Select Your Weekly weight Loss");
		return false;
	}
	if(CheckValue(f.workactivitylevel_sdp,"Work Activity Level") || CheckValue(f.liesureactivitylevel_sdp,"Leisure Activity Level"))
	{
		alert("Please Select Activity Levels");
		return false;
	}
	if(f.gender_sdp[0].checked)	{
		gendval = "0";
	} else {
		gendval = "1";
	}
	
	if(f.goal_sdp[0].checked) {
		goalval = "loseweight"; 
	} else {
		goalval = "maintainweight"; 
	}
	wwtloseval="";
	if(f.weeklyweightlose_sdp[0].checked)
	{
		wwtloseval = "0.5lb";
	} else if(f.weeklyweightlose_sdp[1].checked) {
		wwtloseval = "1lb";
	} else if(f.weeklyweightlose_sdp[2].checked) {
		wwtloseval = "1.5lb";
	} else if(f.weeklyweightlose_sdp[3].checked) {
		wwtloseval = "2lb";
	}
	processsmartdietfun(f.age_sdp.value,gendval,f.height_sdp.value,f.heightms_sdp.value,f.HeightM_sdp.value,f.weight_sdp.value,f.WeightM_sdp.value,goalval,f.goalweight_sdp.value,wwtloseval,f.workactivitylevel_sdp.value,f.liesureactivitylevel_sdp.value);
return false;	
}



function CheckValue(TxtBox,Msg)
{
	if(TxtBox.value=='')
	{
		alert(Msg);
		TxtBox.focus();
		return true;
	}
	return false;
}


function empty(name,id)
{
  
  field=name.value;
  if(field == "")
  { 
     alert("Please enter " + id);
     name.focus();
     return false;  
  }
  if(field.length<6)
  { 
     alert(id + " must be minimum of 6 characteres");
     name.focus();
     return false;  
  }
  for(i=0;i<=field.length;i++)
  {
   if((field.indexOf(" ")==i)) 
   {
	alert("Enter again here spaces are not allowed");   
	return false;
   }
   if(field.indexOf(" ")==0)
  {
   alert("Enter the valid Password without spaces");
   x.value=""
   x.focus();
   return false;     
  }
 }
   return true;
}


 //function ValidEmail(EmailAddress)
// {
//  if ((EmailAddress.indexOf(' ') >= 0) || (EmailAddress.indexOf(';') >= 0) || (EmailAddress.indexOf(',') >= 0) || (EmailAddress.indexOf('@') < 1))   return false;
//  if (EmailAddress.substr(EmailAddress.indexOf('@')).indexOf('.') < 2)  return false;
//  if (EmailAddress.substr(EmailAddress.indexOf('.',EmailAddress.indexOf('@'))).length < 3)  return false;
//	
//	 var digits=new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','@','.','_')
//  var field=EmailAddress;
//  for(var i=0; i<field.length; i++)
//    {	
//	var cc=field.charAt(i);
//  	if(!(cc==digits[0]|| cc==digits[1]|| cc==digits[2]|| cc==digits[3]||cc==digits[4]|| cc==digits[5]|| cc==digits[6]||cc==digits[7]
//  	    || cc==digits[8]|| cc==digits[9]|| cc==digits[10]|| cc==digits[11]|| cc==digits[12]|| cc==digits[13]|| cc==digits[14]||
//		cc==digits[15]|| cc==digits[16]|| cc==digits[17]|| cc==digits[18]|| cc==digits[19]|| cc==digits[20]|| cc==digits[21]|| cc==
//		digits[22]|| cc==digits[23]|| cc==digits[24]|| cc==digits[25]|| cc==digits[26]|| cc==digits[27]|| cc==digits[28]|| cc==
//		digits[29]|| cc==digits[30]|| cc==digits[31]|| cc==digits[32]|| cc==digits[33]|| cc==digits[34]|| cc==digits[35]|| cc==
//		digits[36]|| cc==digits[37] || cc==digits[38]))
//   {
//   	alert("Invalid Email Address");   	
//   	return false;
//   } 
// }	
//return true;	
// }

// To check the Email ID for correctness
/**	 FUNCTION EMAILVALIDATION(element) 	 **/

  function ValidEmail(Element)
  {
		Flag  = 1;
		count = 0;
	
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-";
		
		if(Element.value.length > 0)
		{
			for (var i=0; i<Element.value.length; i++)
			{
				temp = Element.value.substring(i, i+1);
	
				if (alp.indexOf(temp) == -1)
				{
					Flag = 0;
				}
			} // closing the for loop
		}
		else
		{
			Flag = 0;
		}
	
		for(var i=0; i <= Element.value.length; i++)
		{
			if(Element.value.charAt(0)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(Element.value.length-1)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(i)=='@') 
			{
				count = count + 1;

				if(count>1)
				{
					Flag = 0;
					break;
				}
			  
				if((Element.value.charAt(i-1)=='.') || (Element.value.charAt(i+1)=='.'))
				{
					Flag = 0;
					break;
				}
			}
			if(Element.value.indexOf('@')==-1)
			{
				Flag = 0;		    	
				break;
			}
			if(Element.value.charAt(0)=='.')
			{
				Flag = 0;
				break;
			}
			if(Element.value.indexOf('.')==-1)
			{
				Flag = 0;		    	
				break;
			}
		  } //closing the for loop
		
		if(Element.value.charAt(Element.value.length-1) == '.')
			Flag = 0;
			
		if(Flag != 1)
		{
			alert("Invalid Email Address.\nValid Characters are [a-z][A-Z][0-9][ _ @ . - ].");
			Element.focus();
			return 0;
		}	
		else
			return 1;
	}

/**	 END OF FUNCTION EMAILVALIDATION(element) 	 **/
 
 
 
 function JSLogout()
 {
	document.frmlogout.submit(); 
 }
 
 function JSValid(frmObj)
 {	
	 if(!ValidEmail(frmObj.email))
	 { 
	 	frmObj.email.focus();return false;
	 }
	 if(frmObj.password.value=='')
	 {
		 	alert("Please enter password");
			frmObj.password.focus();
			return false;
	 }

 }

function Creditinfofun(f)
{
	if(CheckValue(f.firstname,"Enter the First Name")){return false;}
	else if(CheckValue(f.lastname,"Enter the Last Name")){return false;}	
	else if(!checkCreditCard(f.ccardnumber.value,f.user_cardtype.value)){ alert (ccErrors[ccErrorNo]);return false;}
	else if(CheckValue(f.ccexpmonth,"Enter Expire Month")){return false;}
	else if(CheckValue(f.ccexpyear,"Enter Expire Year")){return false;}
	else if(CheckValue(f.cvv2Number,"Enter Card verification Number")){return false;}
	else if(CheckValue(f.address,"Enter the Address")){return false;}
	else if(CheckValue(f.city,"Enter the City")){return false;}
	else if(CheckValue(f.state,"Enter the State")){return false;}
	else if(CheckValue(f.zip,"Enter the Zip")){return false;}
	else if(CheckValue(f.mobilenumber,"Enter Mobile Number")){return false;}
	else if(!CheckNum(f.mobilenumber,"Enter Proper Mobile Number")){return false;}
	else if(CheckValue(f.mobilebrand,"Enter Mobile Brand")){return false;}
	else if(CheckValue(f.mobilecarrier,"Enter Mobile Carrier")){return false;}
	
	
	processcreditinfo(f.firstname.value, f.lastname.value,f.ccardnumber.value,f.user_cardtype.value,f.ccardnumber.value,f.ccexpmonth.value,f.ccexpyear.value,f.cvv2Number.value,f.address.value,f.city.value,f.state.value,f.zip.value,f.country.value,f.mobilenumber.value,f.mobilebrand.value,f.mobilecarrier.value,f.aid.value);

return false;

}

function CheckNum(frmObj,Msg)
{
	var str="0123456789";
	var Numchar;
	for(i=0;i<frmObj.value.length;i++)
	{
		NumChar=frmObj.value.charAt(i);
		if(str.indexOf(NumChar)<0){
			alert(Msg);
			frmObj.focus();
			return false;
			break;
		}
	}
	return true;
}

function height_change()
{
	if(document.forms['regdietinfo'].elements['height'].value == "0")
	{
		document.forms['regdietinfo'].elements['height'].value = '';
	}
}

function heightms_change()
{
	if(document.forms['regdietinfo'].elements['heightms'].value == "0")
	{
		document.forms['regdietinfo'].elements['heightms'].value = '';
	}
}

function weight_change()
{
	if(document.forms['regdietinfo'].elements['weight'].value == "0")
	{
		document.forms['regdietinfo'].elements['weight'].value = '';
	}
}