If Then Function Javascript Definition