﻿var DomainReg = {
	IsDomainAvailable: function(DomainName, DomainType, ResponseNodeID)
	{
		var Check = DomainReg.ValidateDomainName(DomainName);
		if (Check.length <= 0)
		{
			$(ResponseNodeID).update("<center style=\"margin-top:12px;\"><img border=\"0\" alt=\"Busy\" src=\"images/blank.gif\" class=\"WA_AjaxBusy_29\" /></center>");
			var ToURL = "domainchecker.ashx?d=" + DomainName + "&t=" + DomainType + "&ds=" + Number(new Date().getTime());
			DomainReg.__Ajax = new Ajax.Request(ToURL, {
				method: 'post',
				onFailure: function(){
					var Img = "<img border=\"0\" alt=\"\" src=\"images/blank.gif\" class=\"cross_16\" />&nbsp;"
					$(ResponseNodeID).update("<span class=\"Fail\">" + Img + "We were unable to contact our server. Please check your connectivity and retry.</span>");				
				},
				onSuccess: function(transport) {
					$(ResponseNodeID).update(transport.responseText);
				}
			});
		}
		else
		{
			$(ResponseNodeID).update(Check);
		}
	},
	ValidateDomainName: function(DomainName)
	{
		if (DomainName.length <= 0)
		{
			return "Domain name cannot be blank!";
		}
		else
		{
			Chars = "., !, @, #, $, %, ^, &, *, (, ), ,, :, ', /, \\, =, +, _, {, }, |, `, ~, >, <,  ".split(", ");
			for (cIdx = 0; cIdx < Chars.length; cIdx++)
			{
				if (DomainName.indexOf(Chars[cIdx]) != -1)
				{
					theChar = Chars[cIdx];
					if (theChar == " ")
					{
						theChar = "&lt;space&gt;";
					}
					return "Domain contains invalid character: " + theChar;
				}
			}
		}
		return "";
	}

};