+// Checks whether the given sub id is fused by current member
+function isMemberSubIdFree ($subId) {
+ // Check it
+ $isFree = (countSumTotalData(getMemberId(), 'user_subids', 'id', 'userid', true, sprintf(" AND `subid`='%s'", $subId)) == 0);
+
+ // Return result
+ return $isFree;
+}
+
+// Prepares given sub id for storage in database
+function prepareSubId ($subId) {
+ // First convert any spaces/dashes to underscores
+ $subId = str_replace(' ', '_', str_replace('-', '_', $subId));
+
+ // Then filter out any unwanted characters
+ $subId = preg_replace('/([^a-zA-Z0-9_])/', '', $subId);
+
+ // Then Check if it is available
+ if (!isMemberSubIdFree($subId)) {
+ // Is not free
+ $subId = false;
+ } // END - if
+
+ // Return prepared sub id
+ return $subId;
+}
+