<!--
// Begin Form Validation Functions
function isBlankElement(s)
// This function read each of the fields that are in the form and returns true if the form element contatins only whitespace characters.
{
	for (i=0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ' ) && (c != '\n') && (c !='\t')) return false;
	}
	 return true;
}
	
function isNumeric(s)
{
	for (i=0; i < s.length; i++)
	{
		var c = s.charAt(i);	
		if (  (  !( (c >= '0' ) && (c <= '9') ) )   &&   ((c !='.') && (c !=',')) 	)
		{
		 	return false;
		}
	}
	return true;
}	
		// This if the function that perfroms from validation. It will be invoked from the from onSubmit event handler. The handler should return whatever value this function returns
function verifyToolkitForm(f)
{
	var OverallWarning = "";//"Sorry this page could not be processed.\n\n";
	var AlphaWarning = "";
	var MissingWarning = "";
	var EmptyMessage = "";
	var WarningMessage = "";
	var WarnAtAll = false;
				
		// Loop throught the elements of the form, looking for all text and textarea elements that don't have an "optional" properety defined Then check for fields taht are empty and make a list of them Also, if any of these elements have a min or max poreperty defined then veriy that they are and that they are in the right range put toghter error esaged based on the problems found
		
		for( var i=0; i<f.length; i++)
		{
			var e = f.elements[i];
			
			if ((e.type == "text") || (e.type == "textarea"))
			{
				// fisrt check to see if the field is empty
				if (((e.value == null) || (e.value == "" ) || isBlankElement(e.value)) && !e.optional)
				{
					MissingWarning += e.username + " is a mandatory field, please supply a numeric value to proceed.";//\n";
					//EmptyMessage = "This may be because you haven't filled in all the required boxes: please check again.\n\n"
					WarnAtAll = true;					
					myForm.Height.focus();
					myForm.Height.select();
					continue;
				}
				
				// now check for field that are supposed to be numeric
				if ((e.numeric != null) && (e.numeric))
				{
					//alert(e.value);
					if (isNumeric(e.value))
					{
						var v = parseFloat(e.value);
						if ((( e.min != null) && (v < e.min)) ||
							(( e.max != null) && (v > e.max)))
						{
							MissingWarning += "For " + e.username + " ensure you enter a number between " + e.min + " and " +e.max +".\n";
							WarnAtAll = true;
							myForm.Height.focus();
							myForm.Height.select();
						}	
					}
					else
					{
						AlphaWarning = "For " + e.username + " ensure you enter numbers only, with no letters of the alphabet.";//\n\n";
						WarnAtAll = true;
						myForm.Height.focus();
						myForm.Height.select();
					}
				}							
			}// if type is of text
			 
		} // for each element loop
						
	// now. if there was any errors, display the messages and return false otherwise return true and submit the form
	
	if(WarnAtAll) 
	{	
		WarningMessage = OverallWarning + EmptyMessage + AlphaWarning + MissingWarning;  
		alert(WarningMessage);
		return false;
	}
	else
	{
		return true;
	}
	
}// End Form Validation Functions

//if (document.images) {

//	still_scale = new Image(96,60)
	
//	still_scale.src = "Assets/Images/scales_animated.gif";	
//}

function calulate(formdata)
{
var weight1;
var weight2;
var height1;

	if (verifyToolkitForm(formdata))
	{
		height1 = document.myForm.Height.value/100;
		weight1 = Math.round((height1 * height1)*20);
		weight2 = Math.round((height1 * height1)*25);
		document.myForm.weight1.value=weight1 + " kg.";
		document.myForm.weight2.value=weight2 + " kg.";
		//document["animated_scales"].src = still_scale.src;
		return true;
	}
	else
	{
		document.myForm.weight1.value="";
		document.myForm.weight2.value="";
		//document["animated_scales"].src = still_scale.src;	
	}
}

function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
