function Validate(strKeyCode)
{
	if (LTrim(RTrim(document.theForm.weight.value)) == '')
	{
		alert("Please enter your weight so we can provide your personalized profile.");
		document.theForm.weight.focus();
		return false;
	}
	if (isNaN(LTrim(RTrim(document.theForm.weight.value))))
	{
		alert("Please only enter numbers in the weight box.");
		document.theForm.weight.focus();
		return false;
	}

	if ((parseInt(LTrim(RTrim(document.theForm.weight.value))) < 50) || (parseInt(LTrim(RTrim(document.theForm.weight.value))) > 700))
	{
		alert("Please re-check the weight you entered.");
		document.theForm.weight.focus();
		return false;
	}

	if (LTrim(RTrim(document.theForm.age.value)) == '')
	{
		alert("Please enter your age so we can provide your personalized profile.");
		document.theForm.age.focus();
		return false;
	}
	if (isNaN(LTrim(RTrim(document.theForm.age.value))))
	{
		alert("Please only enter numbers in the age box.");
		document.theForm.age.focus();
		return false;
	}
	if (parseInt(LTrim(RTrim(document.theForm.age.value))) < 18)
	{
		alert("You must be at least 18 years old to use this site.");
		document.theForm.age.focus();
		return false;
	}

	var checked = false;
	for (i=0; i<document.theForm.gender.length; i++) 
	{
		if (document.theForm.gender[i].checked) 
		{
			checked = true;
			break;
		}
	}
	if (!checked)
	{
		alert("Please select your gender so we can provide your personalized profile.");
		document.theForm.gender.focus();
		return false;
	}

	var strEmail;
	strEmail = LTrim(RTrim(document.theForm.email.value));
	if (strEmail == '')
	{
		alert("Please enter your e-mail address so we can provide your personalized profile.");
		document.theForm.email.focus();
		return false;
	}

	if (strEmail.indexOf("@") == -1)
	{
		alert("Your email address must contain an \"@\" symbol. Please enter a new value for the \"Email Address\" field.");
		document.theForm.email.focus();
		return false;
	}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(strEmail) == false)
	{
		alert("Your email address does not appear to be valid. Please enter a new value for the \"Email Address\" field.");
		document.theForm.email.focus();
		return false;
	}

	if (LTrim(RTrim(strKeyCode)) != "")
	{
		document.theForm.txtKeyCode.value = strKeyCode;
	}
	document.theForm.action="http://www.sugarsolutiononline.com/landing_profile.asp?cm_re=1-_-top-_-landing_profile.asp";
	document.theForm.submit();
	return false;
}

function GetQStringValue(strQVar)
{
	var strQString = window.location.search.substring(1);
	var strReturnString;
	strReturnString = "";
	var aKeyVal;
	aKeyVal = strQString.split('&');
	for (var i=0; i < aKeyVal.length; i++)
	{
		if(aKeyVal[i].substr(0,strQVar.length) == strQVar)
		{
			if(aKeyVal[i].substr(strQVar.length,1) == '=')
			{
				var iPosQVar;
				iPosQVar = aKeyVal[i].indexOf(strQVar);
				
				var iOffset;
				iOffset =aKeyVal[i].indexOf('=') + 1;
				strReturnString = aKeyVal[i].substring(iOffset);
			}
		}
	}
	return strReturnString;
}

function LTrim(orgString)
{
	return orgString.replace(/^\s+/,'');
}

function RTrim(orgString)
{
	return orgString.replace(/\s+$/,'');
}

var strQSKeyCode = escape(GetQStringValue('keycode'));

if (LTrim(RTrim(strQSKeyCode)) != "")
{
	document.cookie = 'keycode=' + LTrim(RTrim(strQSKeyCode)) + ';domain=sugarsolutionsonline.com';
}

function ValidateLogin()
{
//this is if enter is hit...  run from the onSubmit of the form
	if (document.theLoginForm.strUserName.value == "")
	{
		document.theLoginForm.strUserName.focus();
		return (false);
	}

	if (document.theLoginForm.strPassword.value == "")
	{
		document.theLoginForm.strPassword.focus();
		return (false);
	}

	//theForm1.action=whereFrom;
	
	
	document.theLoginForm.submit();
	
	return (false);
}

function ValidateLogin2()
{
//this actually uses alerts, it is run from clicking the button
	if (document.theLoginForm.strUserName.value == "")
	{
		alert("Please enter your User Name.");
		document.theLoginForm.strUserName.focus();
		return (false);
	}

	if (document.theLoginForm.strPassword.value == "")
	{
		alert("Please enter your Password.");
		document.theLoginForm.strPassword.focus();
		return (false);
	}
	
	document.theLoginForm.submit();
	return (false);
}

function popUpWindow(url)
{
	window.open(url,'','width=670,height=340,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no');
}
