function validate() {
	j = 0;
	data = new Array();
	data[j++] = document.forms['theForm'].elements[0].name;
	
	for (i=1;i<document.forms['theForm'].elements.length-1;i++) {
		if (document.forms['theForm'].elements[i].name != data[j-1]) {
			data[j++] = document.forms['theForm'].elements[i].name;
		}
	}
	
	
	for (i=0;i<data.length;i++) {
		if (document.forms['theForm'].elements[data[i]].type=="text") {
			if (isNaN(document.forms['theForm'].elements[data[i]].value)||document.forms['theForm'].elements[data[i]].value=="") {
				document.forms['theForm'].elements[data[i]].focus();
				alert ("Please answer this question properly or the evaluation will not be complete.");
				return false;
			} else { continue; }
		}
		if	(document.forms['theForm'].elements[data[i]][0].type=="radio") {
			valid=0;
			for(j=0;j<document.forms['theForm'].elements[data[i]].length;j++) {
				valid+=document.forms['theForm'].elements[data[i]][j].checked;
			}
			if (valid==0) {
				if (( document.forms['theForm'].elements['pregnancy'][0].checked) && ( data[i] == 'pregnancies' )) { continue; }
				if (( document.forms['theForm'].elements['children'].value == "1") && ( data[i] == 'feed' )) { continue; }
				if (( document.forms['theForm'].elements['intercourse'][0].checked) && (( data[i] == 'regular' ) || ( data[i] == 'circumcised' ) || ( data[i] == 'partners' ) || ( data[i] == 'barrier' ))) { continue; }
				if (( document.forms['theForm'].elements['pregnancy'][0].checked) && ( data[i] == 'pregnancies' )) { continue; }
				if (( document.forms['theForm'].elements['sex'][0].checked != true ) && (( data[i] == 'estrogen' ) || ( data[i] == 'oral' ))) { continue; }
				
				document.forms['theForm'].elements[data[i]][0].focus();
				alert ("Please answer this question or the evaluation will not be complete.");
				return false;
			} else { continue ; }
		}
		if (document.forms['theForm'].elements[data[i]].type=="select-one") {
			valid=0;
			if (document.forms['theForm'].elements[data[i]].value!="select") { valid = 1; }
			if ( valid == 0 ) {
				if ((document.forms['theForm'].elements['cancer'][1].checked) && ( data[i] == "type" )) { continue; }
		
				document.forms['theForm'].elements[data[i]].focus();
				alert ("Please answer this question properly or the evaluation will not be complete.");
				return false;
			} else { continue; }
		}
	}
	document.forms['theForm'].submit();	
	return true;
}
function mail() {
	if (isEmail(document.forms['theForm'].elements['frommail'].value)) {
	document.forms['theForm'].elements['str'].value = document.forms['theForm'].elements['msg'].value;
	while( document.forms['theForm'].elements['str'].value.indexOf(String.fromCharCode(13)+String.fromCharCode(10)) != -1 ) {
		document.forms['theForm'].elements['str'].value = document.forms['theForm'].elements['str'].value.replace(String.fromCharCode(13)+String.fromCharCode(10),'<br />');
	}
	document.forms['theForm'].submit();	 
	return true;
	} else { alert("Incomplete Information.");return false; }
}
function convertpounds() 
{
	convertfactor=0.45359237;
	pounds=prompt("How many pounds do you weight?","numbers only");

	if ((pounds=="") || (isNaN(pounds)))
	{
		alert("Only enter numbers please.");
		convertpounds(form_name);
	}
	else {
		kilos=pounds*convertfactor;
		document.forms['theForm'].elements["weight"].value=kilos;
	}
}

function convertinches() 
{
	convertfactor=2.54;
	inches=prompt("How tall are you in inches?","numbers only");

	if ((inches=="") || (isNaN(inches)))
	{
		alert("Only enter numbers please.");
		convertinches();
	}
	else {
		cm=inches*convertfactor;
		document.forms['theForm'].elements["height"].value=cm;
	}
}
function isEmail (s) { 
	var whitespace = " \t\n\r";
	if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")) { i++; }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")) { i++; }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function isEmpty(s) { return ((s == null) || (s.length == 0)) }
function isWhitespace (s) {
	var whitespace = " \t\n\r";
	var i;
    if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
	    if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}
