$(function(){
	$('#searchform').submit(function(){
		var domain = $('#domain_search').val();
		// Don't submit if it's empty
		if (!domain) {
			return false;
		}

		// Get the parts of the submited domain
		// and set the sld and tld hidden input fields
		var parts = domain.split('.');
		$('#searchform').find('input[name="sld"]').val(parts[0]);

		if (parts.length > 1) {
			$('#searchform').find('input[name="tld"]').val(domain.substring(domain.indexOf('.') + 1));
		}

		// Construct the action url for the domain search form
		var href = $(this).attr('action')+'?sld='+$(this).find('input[name=sld]').val()+
			'&tld='+$(this).find('input[name=tld]').val()+
			$(this).find('input[name=order_link]').val();
		$.colorbox({iframe:true, width: '1100px', height: '100%', href: href, fixed: true});
		
		return false;
	});

	// Attach colorbox to all order links (these are the plan specific ones)
	$('.order_link').colorbox({iframe:true, width:'1100px', height:'100%', fixed: true});

	// Placeholder fix
	// Using this instead of the standart html5 attribute, because of the styling
	$('#domain_search').focus(function() {
		var placeholder = "Search for Domains";
		var input = $(this);
		if (input.val() == placeholder) {
			input.val('');
			input.removeClass('placeholder');
	}}).blur(function() {
		var input = $(this);
		var placeholder = "Search for Domains";
		if (input.val() == '' || input.val() == placeholder) {
			input.addClass('placeholder');
			input.val(placeholder);
		}
	}).blur();

});


