$(function (){
	$('.confirm').click(function (){
		var msg = $(this).attr('title');
		if (!msg){msg = 'Are you sure';}
		return confirm(msg+'?');
	});
	$('.popup').popup();
	$('select.autosubmit').change(function (){
		var frm = $(this).parents('form');
		if (frm.length > 0){
			frm[0].submit();
		}
	});
	$('.autofocus').trigger('foucs').trigger('select');
	$('.calendar').each(function (){
		var $this = $(this);
		var settings = {
			dateFormat: 'd/m/yy',
			minDate: null,
			maxDate: null,
			firstDay: 1,
			// gotoCurrent: true,
			showOtherMonths: true,
			changeMonth: true,
			// changeYear: true,
			// yearRange: '1970:2100',
			duration: ''
		};
		if (this.id && $('#button_'+this.id).length){
			settings.buttonImage = $('#button_'+this.id).attr('src');
			settings.showOn = 'button';
			settings.buttonImageOnly = true;
			$('#button_'+this.id).remove();
		}
		$(this).datepicker(settings);
	});
});

/* POPUP Plugin */
/*
* jQuery POPUP Plugin v1.1
*
* easy window.open popups
* @requires metadata plugin
*/
/* POPUP Plugin */
(function($){
	// plugin definition
	$.fn.popup = function (options){
		var options = $.extend({}, $.fn.popup.defaults, options);
		
		return this.each(function (){
			$(this).click(function (){
				$this = $(this);
				var features = $this.metadata() ? $.extend({}, options, $this.metadata()) : options;
				features.url = this.href;
				var win = $.fn.popup.open(features);
				if (win){win.focus();return false;}
				return true;
			});
		});
	}
	// plugin defaults
	$.fn.popup.defaults = {
		status:			1,
		toolbar:		0,
		resizable:		1,
		scrollbars:		1,
		width:			'auto',
		height:			'auto',
		top:			'auto',
		left:			'auto'
	};
	$.fn.popup.open = function (features){
		if (features['width'] == 'auto' || !features['width']){features['width'] = Math.floor(screen.width/2);}
		if (features['height'] == 'auto' || !features['height']){features['height'] = Math.floor(screen.height/2);}
		if (features['left'] == 'auto' || !features['left']){features['left'] = Math.floor((screen.width-features['width'])/2);}
		if (features['top'] == 'auto' || !features['top']){features['top'] = Math.floor((screen.height-features['height'])/2);}
		
		// var url = this.href;
		var target = '_blank';
		var s_features = [];
		for (feature in features){
			if (feature == 'target'){target = features[feature];}
			if (feature == 'url'){url = features[feature];}
			else{s_features[s_features.length] = feature+'='+features[feature];}
		}
		return window.open(url, target, s_features.join(','));
	};
})(jQuery);



