function useAdmissionIdForStrayer() {
	var useAdmissionIdForStrayer = false; 
	var field = window.document.form1.USE_ADMISSION_ID_STRAYER;
	if(field  && getFieldValueTF(field) == "true") {
		useAdmissionIdForStrayer = true;
	}
	return useAdmissionIdForStrayer;
}

function validate_ADMISSION_ID() {
	var field = window.document.form1.ADMISSION_ID;
    var value = getFieldValueTF(field);

	if (useAdmissionIdForStrayer()) {
		field = window.document.form1.ADMISSION_ID_STRAYER;
		value = getFieldValueLB(field)
	}
    
    if(!validateIsRequired(value)) {
        return alertError(field, "Please enter a valid Name/ID." );
    }
    
    if(!validateIsNumeric(value)){
        return alertError(field, "The Name/ID should be a numeric value.");
    }
    
    return true;
}


function setAgentNameForStrayer() {
	
	var admissionIdField = window.document.form1.ADMISSION_ID_STRAYER;
	var agentNameField = window.document.form1.WARM_TRANSFER_AGENT_NAME_01;
	if(admissionIdField && agentNameField) {
		var index = admissionIdField.selectedIndex;
		var fieldOption = admissionIdField.options[index];
		if(fieldOption) {
			var fieldOptionLabel = fieldOption.text;
			var agentIdIndex = (fieldOptionLabel != null && fieldOptionLabel.length > 0) ? fieldOptionLabel.indexOf("(") : -1;
			if(agentIdIndex > -1) {
				var agentName = fieldOptionLabel.substring(0, agentIdIndex);
				setFieldValue(agentNameField, agentName);
			}
		}
	}
}

function validate_WARM_TRANSFER_AGENT_ID_01() {
    var field = window.document.form1.WARM_TRANSFER_AGENT_ID_01;
    var value = getFieldValueLB(field);
    if(!validateIsRequired(value)) {
        return alertError(field, "Please select a Name/ID." );
    }
    
    if(!validateIsNumeric(value)) {
        return alertError(field, "The Name/ID should be a numeric value.");
    }

    return true;
}

function validate_AGENT_NAME() {
	var agentFirstNameField = form["AGENT_FIRSTNAME_01"];
	var agentLastNameField = form["AGENT_LASTNAME_01"];
	var agentFirstNameValue = getFieldValue(agentFirstNameField);
	var agentLastNameValue = getFieldValue(agentLastNameField);
	
	if (isOther(agentFirstNameValue) && isOther(agentLastNameValue)) {
		var otherAgentFirstNameField = form["AGENT_FIRSTNAME_01"];
		var otherAgentLastNameField = form["AGENT_LASTNAME_01"];
		var otherAgentFirstNameValue = getFieldValue(otherAgentFirstNameField);
		var otherAgentLastNameValue = getFieldValue(otherAgentLastNameField);
	    
		if(!validateIsRequired(otherAgentFirstNameValue) || !validateIsRequired(otherAgentLastNameValue)) {
	        return alertError(field, "Please enter a valid agent name or choose from the list provided." );
	    }
	}
	
	return true;
}

function checkAgentOther() {
	var form = window.document.form1;
	var agentFirstNameField = form["AGENT_FIRSTNAME_01"];
	var agentLastNameField = form["AGENT_LASTNAME_01"];
	var agentFirstNameValue = getFieldValue(agentFirstNameField);
	var agentLastNameValue = getFieldValue(agentLastNameField);
	
	var otherAgentInfoDiv = window.document.getElementById('other-agent-info');
	if (isOther(agentFirstNameValue) && isOther(agentLastNameValue)) {
		otherAgentInfoDiv.style.display = "block";
	} else  {
		otherAgentInfoDiv.style.display = "none";
	}
}

function isOther(agentName) {
	if (isNotBlank(agentName) && agentName == "Other") {
		return true;
	}
	return false;
}


