$(document).ready(function(){
	$('.clicknclear').click(function() {
		$(this).attr('rel', $(this).val());
		$(this).val('');
	}).blur(function() {
		if ($(this).val().length < 1)
			$(this).val($(this).attr('rel'));
	});

	if (typeof jQuery.fn.datepicker == 'function')
		$('input.selectdate').datepicker({dateFormat: 'dd/mm/yy', showOn: 'both', buttonImage: '/skin/images/icon-calendar.gif', buttonImageOnly: true});

    $('.object-selector').click(function() {
      var obj = eval('(' + $(this).attr("rel") + ')');
      window.opener.selectObj(obj);
      window.close();
      return false;
    });

	// Hide all records except the first
	$(".record").not(':first').hide();

	// Setup handler to fade in each record when the recordlink is clicked.
	$(".recordlink").click(
		function(e){
			var idField = $(this).attr('id');
			var idNum = 0;
			if (idField.match(/(\d+)$/))
			{
				idNum = RegExp.$1;
			}
				
			$('.record').hide();
			$('#record_'+idNum).fadeIn("slow");
			e.stopPropagation();
			return false;
		}
	);

	$(".printme").click(function () {
		window.print();
		return false;
	});
	
	$(".closeme").click(function () {
		window.close();
		return false;
	});
	$(".submit").change(function () {
		$(this).parents('form:first').submit();
	});

	$(".confirm").click(function() {
		var message = $(this).attr("rel");
		if (!message)
			message = "Are you sure? Press OK to confirm.";

		return confirm(message);
	});

	if (typeof jQuery.fn.popupwindow == 'function') {
		$('.popupwindow').attr('rel', 'popupwindow').popupwindow({popupwindow: {height: 600, width:750, createnew:0, scrollbars:1, center:1}});
	}
	
	
	/* TABS */
	//When page loads...
	/*
	$(".tab_content").hide(); //Hide all content
	if (location.hash && location.hash.match(/^#tab/)) {
		// Activate selected tab 
		var selectedTab = location.hash;
		// Selected tab link (add active to surrounding li) - <ul class="tabs"><li><a href="#tabX">My Tab</a></li></ul>
		$("ul.tabs li a[href='" + selectedTab + "']").parent().addClass("active").show();
		// Selected tab content
		$(selectedTab).addClass('active').show();
	} else {
		// Activate first tab
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
	}

	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class from other <li>
		$(this).addClass("active"); //Add "active" class to selected tab <li>
		$(".tab_content").hide(); //Hide all tab content 

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show().fadeIn('slow'); //Fade in the active ID content
		return false;
	});
	*/

	if (typeof jQuery.fn.ckeditor == 'function')
	{
		$('textarea.editor').ckeditor(function() { }, {
			format_tags: 'p;h2;h3;h4;h5;h6;pre;div',
            contentsCss: '/skin/css/ckeditor.css',
			toolbar: [
			  ['Format', 'Bold','Italic','Underline','StrikeThrough', 'BulletedList', 'NumberedList', 'Undo', 'Redo'],
			  ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
			  ['Link','Unlink','Table']
			]
		});
	}
});

function RunBanner(uid, width, height)
{
	var datapath = encodeURIComponent('/service/xmlbanners.php?uid=' + uid + '&data=1');
	var configpath = encodeURIComponent('/service/xmlbanners.php?uid=' + uid + '&config=1');
	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	if(!InternetExplorer){
		document.write('<embed src="/skin/flash/rotator.swf" wmode="opaque" FlashVars="datapath=' + datapath + '&configpath=' + configpath + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>\n');
	}
	else{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" style="padding: 0;" width="' + width + '" height="' + height + '">\n');
		document.write('<param name="wmode" value="opaque">');
		document.write('<param name="movie" value="/skin/flash/rotator.swf">\n');
		document.write('<param name="quality" value="high">\n');
		document.write('<param name="FlashVars" value="datapath=' + datapath + '&configpath=' + configpath + '">\n');
		document.write('</object>\n');
	}
}

