var jQuery_1_8_2 = $.noConflict();
(function ($, undefined) {
	$(function () {
		var $frmSubscriptionForm = $('#frmSubscriptionForm'),
			tabs = ($.fn.tabs !== undefined),
			$tabs = $("#tabs");
		
		function reDrawCode()
		{
			var group_id = $('#group_id').val(),
				theme = $('#theme').val(),
				clone = $('#install_clone').text();
			if(group_id == '')
			{
				clone = clone.replace(/\{GROUP\}/g, '');
			}else{
				clone = clone.replace(/\{GROUP\}/g, '&group_id=' + group_id);
			}
			if(theme == '')
			{
				clone = clone.replace(/\{THEME\}/g, '');
			}else{
				clone = clone.replace(/\{THEME\}/g, '&theme=' + theme);
			}
			$('#install_code').val(clone);
		}
		
		if ($tabs.length > 0 && tabs) {
			$tabs.tabs();
		}
		
		if($frmSubscriptionForm.length > 0)
		{
			reDrawCode.call(null);
		}
		
		$(".field-int").spinner({
			min: 0
		});
		
		$("#content").on("change", "select[name='value-enum-o_send_email']", function (e) {
			switch ($("option:selected", this).val()) {
			case 'mail|smtp::mail':
				$(".boxSmtp").hide();
				break;
			case 'mail|smtp::smtp':
				$(".boxSmtp").show();
				break;
			}
		}).on("change", "select[name='group_id']", function (e) {
			reDrawCode.call(null);
		}).on("change", "select[name='theme']", function (e) {
			reDrawCode.call(null);
		}).on("click", ".nsPreviewForm", function (e) {
			if (e && e.preventDefault) {
				e.preventDefault();
			}
			var href = 'preview.php',
				group_id = $("select[name='group_id']").val(),
				theme = $("select[name='theme']").val();
			if(theme != '')
			{
				href += '?theme=' + theme;
			} 
			if(group_id != '')
			{
				href += '&group_id=' + group_id;
			}
			window.open(href); 
		});
	});
})(jQuery_1_8_2);