////////////////////////////////////////////////////////////////////////////////
//
//  µµ¸ÞÀÎ µî·Ï°¡´É °Ë»ç Å¬·¡½º
//
//  required file : prototype.js, cookie.js
//
//  µµ¸ÞÀÎ Ã¼Å©¹Ú½º id°ªÀ» domain_¼ýÀÚ
//  ÈÄÀÌÁî ¾ÆÀÌÄÜ id°ªÀ» whois_¼ýÀÚ
//  Àç½Ãµµ ¾ÆÀÌÄÜ id°ªÀ» retry_¼ýÀÚ
//  °Ë»ö ÁøÇà»óÈ² Ãâ·Â¹Ù ¾ÆÀÌÄÜ id°ªÀ» pgbar_¼ýÀÚ
//
////////////////////////////////////////////////////////////////////////////////
function DomainChecker(ajax_url)
{
  this.ajax_url = ajax_url; // (/ajax/check_domain.ajax.php)
}

/**
 * ¼¼¼Ç ¾ÆÀÌµð °ªÀ» ÄíÅ°·ÎºÎÅÍ ¹ÝÈ¯ÇÑ´Ù.
 *
 * @return String ¼¼¼Ç¾ÆÀÌµð
 */
DomainChecker.prototype.get_sid = function()
{
  return getCookie("SID");
}

/**
 * µµ¸ÞÀÎ µî·Ï °¡´É °Ë»ç¸¦ ÇÑ´Ù.
 *
 * @param no ÆäÀÌÁö³»ÀÇ µµ¸ÞÀÎ ¼ø¹ø (domain_xxxxx)
 */
DomainChecker.prototype.check = function(no)
{
  var domain = $("domain_"+no).value;
  var myAjax = new Ajax.Request(this.ajax_url,
    {
      method: "get",
      parameters: "&no=" + no + "&domain=" + domain + "&sid=" + this.get_sid(),
      onComplete: this.response
    });
}

/**
 * µµ¸ÞÀÎ µî·Ï °¡´É °Ë»ç¸¦ Àç½ÃµµÇÑ´Ù.
 *
 * @param no ÆäÀÌÁö³»ÀÇ µµ¸ÞÀÎ ¼ø¹ø (domain_xxxxx)
 */
DomainChecker.prototype.recheck = function(no)
{
  $("pgbar_"+no).style.display = "inline";
  $("retry_"+no).style.display = "none";
  this.check(no);
}

/**
 * AJAX Åë½Å °á°ú¸¦ ÀÌ¿ëÇÏ¿© µµ¸ÞÀÎ °Ë»ç °á°ú¸¦ µ¿ÀûÀ¸·Î º¯È­½ÃÅ²´Ù.
 *
 * @param res AJAX °á°ú °´Ã¼
 */
DomainChecker.prototype.response = function(res)
{
  var response = res.responseText;
//  alert(response);
  var code = response.substring(0, 1);
  var no = response.substring(1);

  $("pgbar_"+no).style.display = "none";
  if (code == "A") //µî·Ï°¡´É
  {
    $("domain_"+no).style.display = "inline";
    $("domain_"+no).checked = true;
  }
  else if (code == "D") //µî·ÏºÒ°¡
  {
    $("whois_"+no).style.display = "inline";
  }
  else if (code == "R") // ±ÝÀÏ »èÁ¦ µµ¸ÞÀÎ (Àçµî·Ï°¡´É)
  {
	$("rreg_"+no).style.display = "inline";
  }
  else // if (response == "E") //°Ë»ö¿¡·¯
  {
    $("retry_"+no).style.display = "inline";
  }
}

/**
 * ±×·ìº°·Î ±¸ºÐµÈ TLD¸¦ ´ÙÁß ¼±ÅÃÇÑ´Ù.
 *
 * @param tld_group_name TLD ±×·ì¸í (gtld_xxx ÇüÅÂ·Î ³ª¿­µÉ °æ¿ì ±×·ì¸íÀº gtld)
 */
DomainChecker.prototype.select_multi_tld = function(tld_group_name)
{
  var checked = $(tld_group_name).checked;
  for (var i = 1;; i++)
  {
    var el = $(tld_group_name+"_"+i);
    if (el == null)
    {
      break;
    }
    el.checked = checked;
  }
}

DomainChecker.prototype.validate = function(domain)
{
  if (domain.charAt(0) == '.')
  {
		alert ("µµ¸ÞÀÎ ¸íÀº '.'·Î ½ÃÀÛÇÒ ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}

	if (domain.charAt(0) == '-')
  {
		alert ("µµ¸ÞÀÎ ¸íÀº '-'·Î ½ÃÀÛÇÒ ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}
	
	if (domain.charAt(domain.length-1) == '-')
  {
		alert ("µµ¸ÞÀÎ ¸íÀº '-'·Î ³¡³¯ ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}

	if (domain.indexOf('.') > 0)
  {
		alert("µµ¸ÞÀÎ ¸íÀº '.' µé¾î°¥¼ö ¾ø½À´Ï´Ù.");	
		return false;
	}

  return true;
}

