$(document).ready(function() {
	$.ajax({
  		url: "/services/ajaxGetDomainZones",
  		success: function(data) {
  			for (var key in data) {
  				if(typeof firstKey == "undefined")  {
  					firstKey = key;
  				}
  				$('#zonesSelect').append('<option value="'+key+'">'+data[key]+'</option>');
  			}
  			$('#zonesSelect').attr('name', 'data[Domain][zones]['+data[firstKey]+']');
  		},
  		dataType: "json"
	});
	
});

$(document).change('#zonesSelect', function() {
	$("#zonesSelect option:selected").each(function () {
		$('#zonesSelect').attr('name', 'data[Domain][zones]['+$('#zonesSelect option:selected').val()+']');
	});
});

$('#check_domain').submit(function() {
  var data = $('#check_domain').serialize();
  
  $.ajax({type: "POST",
  	url: '/domains/ajaxCheckDomain',
  	async: true,
  	data: data,
  	dataType: "json",
  	success: function(data) {
  		for (var zone in data) {
			if(data[zone]) {
				$('#checkResult').html('<strong style="color: green;">Свободен.</strong> <a href="https://cp.firehost.com.ua/domains/register">Пройтиде, чтобы зарегистрировать</a>');
			} else {
				$('#checkResult').html('<strong  style="color: red;">Занят</strong>');
			}
  		}
  	}});
  
  return false;
});

//$(document).bind("ajaxError", function(){
//   alert('AjaxError');
// });

$(document).bind("ajaxSend", function(){
   $("#div_check_domain").hide(0);
   $("#div_ajax_load_gif").show(0);
 });
 
 $(document).bind("ajaxComplete", function(){
   $("#div_ajax_load_gif").hide(0);
   $("#div_check_domain").show(0);
 });
 
