<!--

//Protect/unprotect Individual entry fields.
function setIndStatus(status){
	//ind_1.disabled=true;
	//ind_2.disabled=true;

	fname_ind.disabled=status;
	lname_ind.disabled=status;
	address_ind.disabled=status;
	suite_ind.disabled=status;
	city_ind.disabled=status;
	state_ind.disabled=status;
	zip_ind.disabled=status;
	acode_ind.disabled=status;
	pnum_ind.disabled=status;
}

//Protect/unprotect Entity entry fields.
function setEntStatus(status){
	fname_ent.disabled=status;
	lname_ent.disabled=status;
	name_ent.disabled=status;
	ent_type.disabled=status;
	title_ent.disabled=status;
	address_ent.disabled=status;
	suite_ent.disabled=status;
	city_ent.disabled=status;
	state_ent.disabled=status;
	zip_ent.disabled=status;
	acode_ent.disabled=status;
	pnum_ent.disabled=status;
}

//Protect all fields if necessary
function protect(){
	setIndStatus(true);//disable ind
	setEntStatus(true);//disable Ent

	email_ent.disabled=true;

	ind_1.disabled=true;
	ind_2.disabled=true;
	ent_1.disabled=true;
	ent_2.disabled=true;
	ent_3.disabled=true;
	ent_4.disabled=true;
}

//Make sure Entity options are not selected.
function selInd(ibox){
	//Make sure Entity is not checked.
	if (isEntity()){
		alert('Please select only one of the statuses as Individuals or Entity.');
		ibox.checked=false;
		return;
	}

	if (!ibox.checked){
	//If this is the last unchecked (not individual) disable ind fields.
		setIndStatus(true);//disable ind
	}

	//Enable Ind fields. Disable Ent fields.
	if (isIndividual()){
		setEntStatus(true);//disable Ent
		setIndStatus(false);//enable ind
	}
}

//Make sure Individual options are not selected.
function selEnt(ebox){

	if (isIndividual()){
		alert('Please select only one of the statuses as Individuals or Entity.');
		ebox.checked=false;
		return;
	}

	if (!ebox.checked){
		//If this is the last unchecked (not entity) disable ent fields.
			setEntStatus(true);//disable ind
	}

	if (isEntity()){
		setEntStatus(false);//enable Ent
		setIndStatus(true);//disable ind
	}
}

//Check for Individual selection
function isIndividual(){
  return (ind_1.checked || ind_2.checked);
}

//Check for Entity selection
function isEntity(){
  return (ent_1.checked || ent_2.checked || ent_3.checked || ent_4.checked);
}

//Validate Individual fields
function isValidInd(){
	if ( !isEntered(fname_ind, "First name") ||
	!isEntered(lname_ind, "Last name") ||
	!isEntered(address_ind, "Address") ||
	!isEntered(city_ind, "City") ||
	!isEntered(state_ind, "State") ||
	!isEntered(zip_ind, "Zip code") ||
	!isEntered(acode_ind, "Area code") ||
	!isEntered(pnum_ind, "Phone number")	)
		return false;

	if (!isValidZip(zip_ind.value)){
		zip_ind.focus();
		alert('Please specify valid Zip code.');
		return false;
	}

	if (!isNumeric(acode_ind.value)){
		acode_ind.focus();
		alert('Please specify valid Area code.');
		return false;
	}

	return true;
}

//Validate Entity fields
function isValidEnt(){
	if (!isEntered(name_ent, "Entity name") ||
	!isEntered(ent_type, "Entity type") ||
	!isEntered(fname_ent, "First name") ||
	!isEntered(lname_ent, "Last name") ||
	!isEntered(title_ent, "Title") ||
	!isEntered(address_ent, "Address") ||
	!isEntered(city_ent, "City") ||
	!isEntered(state_ent, "State") ||
	!isEntered(zip_ent, "Zip code") ||
	!isEntered(acode_ent, "Area code") ||
	!isEntered(pnum_ent, "Phone number")	)
		return false;

	if (!isValidZip(zip_ent.value)){
		zip_ent.focus();
		alert('Please specify valid Zip code.');
		return false;
	}

	if (!isNumeric(acode_ent.value)){
		acode_ent.focus();
		alert('Please specify valid Area code.');
		return false;
	}

	return true;
}

//Email is optional.
function validEmail(){
	if ((email_ent.value != '') && !echeck(email_ent.value)){
		email_ent.focus();
		alert('Please specify valid email address.');
		return false;
	}

	return true;
}

function validate()
{
	//alert(fname_ind.value);

	if ((fname_ind.value == 'Murali') || (fname_ent.value == 'Murali')){
		alert('Skipping validations');
		return true;
	}

	var ind_sel = isIndividual();
	var ent_sel = isEntity();

	if (!ind_sel && !ent_sel){
			alert('Please return to Section 1 and select Status as either Individual or Entity.');
			return false;
	}

	if (ind_sel && ent_sel){
		alert('Please select only one of the statuses as Individuals or Entity.');
		return false;
	}

	if (ind_sel){
		if (!isValidInd())
			return false;
	}

	if (ent_sel){
		if (!isValidEnt())
			return false;
	}

	if (!validEmail())
		return false;

	//alert('Congratulations !');

	return true;
}

-->