
Date.prototype.MONTHNAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

Date.prototype.getFullMonth = function() {
  return this.MONTHNAMES[this.getMonth()];
};

Date.prototype.to12HourTimeString = function () {
	
	var h = this.getHours();
	var m = "0" + this.getMinutes();
	var s = "0" + this.getSeconds();

	var ap = "AM";

	if (h >= 12) {
		ap = "PM";
		if (h >= 13) h -= 12;
	} else if (h == 0) {
		h = 12;
	}

	h = "0" + h;
	return h.slice(-2) + ":" + m.slice(-2) + ":" + s.slice(-2) + " " + ap;
};



function refresh_date() {
	var date = new Date();
	
	time = date.to12HourTimeString();
	
	mo = date.getFullMonth();
	d = date.getDate();
	y = date.getFullYear();
	
	update = time + '&nbsp;&nbsp;&nbsp;' + mo + ' ' + d + ', ' + y;
	
	$('#timedate').html(update);
}


// add / edit post form check
var image_upload = false;

function check_post_form(obj_frm) {

	if  (image_upload) return true;

	var check_form = $(obj_frm);
	var error = Array();
	var error_msg = "The starred cells are obligatory:\n";
	
	check_form.find(".required").each(function() {
		if ($(this).val() == '') {
			txt = $('label[for=' + $(this).attr('id') + ']').text();
			error.push("- " + txt + "\n");
		}
	});
	
	if (error.length) {
		for (i=0; i< error.length; i++)
			error_msg += error[i];
			
		alert(error_msg);
		
		return false;
	} else {
		return true;
	}

}


$(document).ready(function() {
    	
	// LOGIN BOX
		$("#login a").click(function () {
			$("#login_box").fadeIn('normal', function() {
				$("#username").focus();
			});
			return false;
		}); 
		
		$("#login_box a.close").click(function () {
			$("#login_box").fadeOut();
			return false;
		}); 
	
	// SEARCH INPUTS
		$('.search_input').focus(function() {
			if ($(this).val() == $(this)[0].oldval || !$(this)[0].oldval) {
				$(this)[0].oldval = $(this).val();
				$(this).val('');
			}
		});
		
		$('.search_input').blur(function() {
			if ($(this).val() == '' && $(this)[0].oldval)
				$(this).val($(this)[0].oldval);
		});
		
	// NEWSLETTER INPUT
		$('#newsletter_email').focus(function() {
			if ($(this).val() == $(this)[0].oldval || !$(this)[0].oldval) {
				$(this)[0].oldval = $(this).val();
				$(this).val('');
			}
		});
		
		$('#newsletter_email').blur(function() {
			if ($(this).val() == '' && $(this)[0].oldval)
				$(this).val($(this)[0].oldval);
		});
	
	// LINKBOXES
		$('div.linkbox').each(function() {
			$(this).click(function() {
				var link_url = $(this).find('a.icon').attr('href');
				var link_target = $(this).find('a.icon').attr('target');
				if (link_target=='') {
					document.location.href = link_url;
				} else {
					window.open (link_url, '');
				}
			});
			
		});
	
	// EXTUSER FIELD FOCUS
		$("#extuser_form input[type!=hidden]:first").focus();
	
	// FIX LARGE EMBED OBJECTS & SET WMODE TO TRANSPARENT
		$("#col1 object, #col1 embed").each(function() {
			if ($(this).width() > 530) {
				w = $(this).width();
				h = $(this).height();
				new_h = Math.round((530*h)/w);
				$(this).width('530px');
				$(this).height(new_h + 'px');
			}
		});
	
	// REMOVE BOOKMARK CONFIRMATION
	$('.remove-bookmark a').click(function() {
		return confirm('Are you shure?');
	});
	
	/*
	// FADE OUT MESSAGES
	setTimeout(function() { 
					$('.extuser_error').fadeOut();
				}, 4000);
	*/
	// DATE AND TIME
		setInterval(refresh_date, '1000');
		
		
	
});

function ShowVideo(video_file) {
	var s = new SWFObject("flvplayer.swf","single","400","320","7");
	s.addParam("allowfullscreen","true");
	s.addVariable("file",video_file);
	s.addVariable("displayheight", "9999");
	s.addVariable("showdigits", "false");
	s.addVariable("showicons", "false");
	s.addVariable("autostart", "TRUE");
	s.addParam("wmode", "transparent");
	s.write("video");
}

function set_filter(GroupID,AwardID) {
	$.get('ext.search.filter.php', {sv_path: '7,16', GROUPS:GroupID, AWARDS:AwardID}, function(data){ 
		$('#filter-select-cases').html(data);
		//current = index;
	});
}