
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;
	});
}

function show_video_file(videofile,previewfile,sizex,sizey,autoplay,fullscr,video_id)
{
	auto_play = false;
	full_screen = false;
	if (autoplay != null){
		auto_play = true;
	}
	if (fullscr != null){
		full_screen = true;
	}
	var vars = {
		width:sizex,
		height:sizey,
		file:videofile,
		image:previewfile,
		fullscreen:full_screen,
		javascriptid:'video_'+video_id,
		enablejs:'true',
		backcolor:'BA0000',
		frontcolor:'FFFFFF',
		lightcolor:'FFFFFF',
		screencolor:'000000',
		autostart:auto_play,
		controlbar:'over'
	};
					
	var params = {
		allowscriptaccess:'always',
		allowfullscreen:full_screen,
		wmode:'transparent'
	};

	swfobject_new.embedSWF("flash/player.swf", "video_"+video_id, sizex, sizey, "9.0.0",'', vars, params);
}

function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	} else {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}

function openwin(uri,title,w,h,scroll,tracking){
	
	if (tracking == undefined) tracking = false;
	
	if (tracking) {
		pageTracker._trackEvent('heaeder', 'Click', 'Radio popup');
	}
	
	if(w){wwidth = w;}else{	wwidth = 380;}
	if(h){wheight = h; }else{ wheight = 380;}
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, title, "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars="+scroll+", status=no, menubar=no, resizable=no, directories=no");
	return false;
}

