$().ready(function(){

	$('#OrderForm-1').submit(function(){
		domainName = $('input[name="domain"]', $(this)).val();
		get_domain_details(domainName);
		return false;
	});
	$('#orderAccountResetContacts a').click(resetAccountContacts);
	$('form select[name="user_id"]').bind('change', function(){
		$('#orderAccountResetContacts').fadeIn();
	});
	if ($('div.OrderContactItem').size())
	{
		$.getScript('/js/jquery.fancybox.js', function(){
			$('div.OrderContactItem h4 a.iframe').fancybox({
				'padding': 0,
				'frameWidth': 546,
				'frameHeight': 360,
				'hideOnContentClick': false,
				'callbackOnClose': function(){
					window.location.reload();
				}
			});
		});
	}

});

function resetAccountContacts()
{
	userId = $("FORM SELECT[name='user_id']").val();
	$('#orderAccountResetContacts a').attr('href', '?setAccount=' + userId);
}

function str_repeat(input, multiplier)
{
	return new Array(multiplier + 1).join(input);
}

function get_domain_details(domain,attempt)
{
	if (!attempt)
		attempt = 1;

	$().ready(function(){
		$('#order-domain-loader').html('Zjišťuji informace o doméně..'+str_repeat('.',attempt));
		$("#order-domain-details").css('display','none');
		$("#order-domain-loader").css('display','block');
		$('#order-domain-details').html('');
		$.ajax({
			url: '/system.call/order.domain?domain=' + domain,
			dataType: 'html',
			type: 'GET',
			timeout: 2000,
			cache: true,
			complete: function()
			{
			},
			success: function(src, status)
			{
				$('#order-domain-loader').css('display','none');
				$('#order-domain-details').css('display','block');
				$('#order-domain-details').html(src);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown)
			{
				if (attempt < 4)
				{
					get_domain_details(domain, (attempt + 1));
				}
				else
				{
					$('#order-domain-loader').html('Dlouhá doba odezvy: Zkuste prosím ověřit znova.');
				}
			}
		});
	});
}

function ipt_select_change(o){
 $(document).ready(function(){
  if($("#order-domain-details").val()=='0'){
  }
 });
}

function paypal_submit(){
 $(document).ready(function(){
  $('#pay-paypal').submit();
 });
}

function paypay_submit(){
 $(document).ready(function(){
  $('#pay-paypay').submit();
 });
}

