 
 # NOTE: All domain registry related stuff removed
 # you can look at them from 745b4914f14fa424a3e38db68e09a1bc832be7f4
+
+{argv}   = require 'optimist'
+KONFIG   = require('koding-config-manager').load("main.#{argv.c}")
 
 jraphical = require 'jraphical'
 module.exports = class JDomain extends jraphical.Module


  parseDomain = (domain)->

    # Custom error
    err = (message = "Invalid domain: #{domain}")->
      err: new KodingError message, "INVALIDDOMAIN"

      /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/i.test domain

    # Return domain type as custom and keep the domain as is
    unless ///\.#{userSitesDomain}$///.test domain
      return { type: 'custom', domain }

    # Basic check
    return err()  unless ///([a-z0-9\-]+)\.#{userSitesDomain}$///.test domain

    # Check for shared|vm prefix
    if /^shared|vm[\-]?([0-9]+)?/.test prefix
      return err "Domain name cannot start with shared|vm"

    # Parse domain
    match = domain.match ///([a-z0-9\-]+)\.([a-z0-9\-]+)\.#{userSitesDomain}$///
    return err "Invalid domain: #{domain}"  unless match
    [rest..., prefix, slug] = match

    # Return type as internal and slug and domain
