(function($){
 $.fn.extend({
 
 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = $(this).find(':selected');
			
			$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			
			var selectBoxSpan = $(this).next();
			
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			
			selectBoxSpan.css({display:'inline-block'});
			
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
			selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
				// Thanks to Juarez Filho & PaddyMurphy
			});
			
	  });
	  }
	}
 });
})(jQuery);

function checkCheckbox(){
	$("input[type='checkbox']").each(function(){
		if($(this).is(':checked')){
			$(this).parent('.checkboxCustom').addClass('checkboxCustomOn');
		} else {
			$(this).parent('.checkboxCustom').removeClass('checkboxCustomOn');
		}
	});
};


function checkRadio(){
	$("input[type='radio']").each(function(){
		if($(this).is(':checked')){
			$(this).parent('.radioCustom').addClass('radioCustomOn');
		} else {
			$(this).parent('.radioCustom').removeClass('radioCustomOn');
		}
	});
};


$(function(){
	$('select.select').customStyle();

	$("input[type='checkbox']").css('opacity', '0').wrap('<span class="checkboxCustom" />');
	checkCheckbox()
	$("input[type='checkbox']").change(function(){
		checkCheckbox();
	});

	$("input[type='radio']").css('opacity', '0').wrap('<span class="radioCustom" />');
		checkRadio()
	$("input[type='radio']").change(function(){
		checkRadio();
	});
}); 


function fileInput(){
	$('#rcKarta').parent().children('span').text($('#rcKarta').val());
};

$(function(){
	if ($('.fileField').length > 0){
		$('.fileField').find('input').css('opacity','0');
		$('.fileField .fGL').append('<span/>');
		$('#rcKarta').live('change',function(){
			fileInput();
		});
		$('.fileField .fGL span').click(function(){
			$(this).parent().children('input').click();
		});
	}
	
}); 


function customRange(input) {
	var dateDays = 60;
	var dateRange = dateDays * 24 * 60 * 60 * 1000;
	var dateToday = Date.parse(new Date());
	var dateFrom = Date.parse($('#roDF').datepicker("getDate"));
	var dateTo = Date.parse($('#roDT').datepicker("getDate"));
  if (input.id == 'roDT') {
		if (dateToday >= dateFrom || isNaN(dateFrom) == true){
			var dateFrom = dateToday + 86400000;
		}
    return {
      minDate: new Date(dateFrom),
			maxDate: new Date(dateFrom + dateRange)
    };
  } else if (input.id == 'roDF') {
    return {
			minDate: '+1D',
      maxDate: $('#roDT').datepicker("getDate")
    };
  }
}


$(function(){
	$("#roDF, #roDT").datepicker({
		beforeShow: customRange
	});
});

		
























