function _CF_onError(form_object, input_object, object_value, error_message){
	alert(error_message);
       	return false;	
    }

function _CF_hasValue(obj, obj_type){
    if (obj_type == "TEXT" || obj_type == "PASSWORD"){
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    }
    else if (obj_type == "SELECT"){
        for (i=0; i < obj.length; i++){
			if (obj.options[i].selected)
				return true;
		}
       	return false;	
	}
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX"){
		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX"){
        for (i=0; i < obj.length; i++){
			if (obj[i].checked)
				return true;
		}
       	return false;	
	}
}

function isUnsignedInteger(s) {
	return (s.toString().search(/^[0-9]+$/) == 0);
}

function  _CF_checkCFForm_1(_CF_this){
    if  (!_CF_hasValue(_CF_this.age, "TEXT" )){
        if  (!_CF_onError(_CF_this, _CF_this.age, _CF_this.age.value, "Please indicate your age")){
            return false; 
        }
    }
		if (!isUnsignedInteger(_CF_this.age.value)){
        if  (!_CF_onError(_CF_this, _CF_this.age, _CF_this.age.value, "Please enter a valid age")){
            return false; 
        }
		}
		
    if  (!_CF_hasValue(_CF_this.gender, "RADIO" )){
        if  (!_CF_onError(_CF_this, _CF_this.gender, _CF_this.gender.value, "Please indicate your gender")){
            return false; 
        }
    }
    if  (!_CF_hasValue(_CF_this.weight, "TEXT" )){
        if  (!_CF_onError(_CF_this, _CF_this.weight, _CF_this.weight.value, "Please indicate your weight")){
            return false; 
        }
    }
		if (!isUnsignedInteger(_CF_this.weight.value)){
        if  (!_CF_onError(_CF_this, _CF_this.weight, _CF_this.weight.value, "Please enter a valid weight")){
            return false; 
        }
		}

    if  (!_CF_hasValue(_CF_this.Q1, "RADIO" )){
        if  (!_CF_onError(_CF_this, _CF_this.Q1, _CF_this.Q1.value, "Please indicate how long you have been overweight")){
            return false; 
        }
    }
    if  (!_CF_hasValue(_CF_this.Q4, "RADIO" )){
        if  (!_CF_onError(_CF_this, _CF_this.Q4, _CF_this.Q4.value, "Please indicate how many stairs you can climb before resting")){
            return false; 
        }
    }

    return true;
}

function  _CF_checkCFForm_2(_CF_this){
    if  (!_CF_hasValue(_CF_this.fname, "TEXT" )){
        if  (!_CF_onError(_CF_this, _CF_this.fname, _CF_this.fname.value, "Please enter your first name.")){
            return false; 
        }
    }
    if  (!_CF_hasValue(_CF_this.lname, "TEXT" )){
        if  (!_CF_onError(_CF_this, _CF_this.lname, _CF_this.lname.value, "Please enter your Last Name")){
            return false; 
        }
    }
    if  (!_CF_hasValue(_CF_this.emailAddress, "TEXT" )){
        if  (!_CF_onError(_CF_this, _CF_this.emailAddress, _CF_this.emailAddress.value, "Please enter your E-mail address")){
            return false; 
        }
    }

    if  (!_CF_hasValue(_CF_this.hphone, "TEXT" )){
        if  (!_CF_onError(_CF_this, _CF_this.hphone, _CF_this.hphone.value, "Please enter your phone number")){
            return false; 
        }
    }
	
    if  (!_CF_hasValue(_CF_this.city, "TEXT" )){
       if  (!_CF_onError(_CF_this, _CF_this.city, _CF_this.city.value, "Please enter your City of residence")){
            return false; 
       }
    }
		if( document.CFForm_2.country.options[document.CFForm_2.country.selectedIndex].value == 'United States' ){
	    if  (document.CFForm_2.state.selectedIndex == 0){
					alert("Please enter your State of residence");
 	        return false; 
	    }
		}
		else{
	    if  (!_CF_hasValue(_CF_this.province, "TEXT" )){
  	      if  (!_CF_onError(_CF_this, _CF_this.province, _CF_this.province.value, "Please enter your Province")){
    	        return false; 
      	  }
	    }
		}
		if  (!_CF_hasValue(_CF_this.zip, "TEXT" )){
        if  (!_CF_onError(_CF_this, _CF_this.zip, _CF_this.zip.value, "Please enter your Zip Code")){
            return false; 
        }
    }
    return true;
}

function countryChange(obj){
	var sel = document.CFForm_2.country.options[document.CFForm_2.country.selectedIndex].value;
	if( sel == "United States"){
		document.getElementById("stateRow").style.display = "";
		document.getElementById("provinceRow").style.display = "none";			
	}
	else{
		document.getElementById("stateRow").style.display = "none";
		document.getElementById("provinceRow").style.display = "";			
	}
}

/***********************************************
* Limit number of checked checkboxes script- by JavaScript Kit (www.javascriptkit.com)
* This notice must stay intact for usage
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more
***********************************************/

function checkboxlimit(checkgroup, limit){
	var checkgroup=checkgroup
	var limit=limit
	for (var i=0; i<checkgroup.length; i++){
		checkgroup[i].onclick=function(){
		var checkedcount=0
		for (var i=0; i<checkgroup.length; i++)
			checkedcount+=(checkgroup[i].checked)? 1 : 0
		if (checkedcount>limit){
			alert("Please select only 3 goals")
			this.checked=false
			}
		}
	}
}

