// Required Fields
$(function() {
	$("label.required")
		.prepend('<img src="images/star.gif" alt="" />');
});

// table row highlight
$(function() {

    $('td').live('mouseover', function(){
        var i = $(this).prevAll('td').length;
        $(this).parent().addClass('hover')

    }).live('mouseout', function(){
        var i = $(this).prevAll('td').length;
        $(this).parent().removeClass('hover');
    })

});

// datepicker with format
$(function(){
// Datepicker
   $('#datepicker').datepicker({
	inline: true,
	// minDate: -0, 
	// maxDate: '1D +6M',
	dateFormat: 'yy-mm-dd',
	onSelect: function(dateText) {
      	// do whatever here    
	window.location = "search-date.php?sel_date=" + dateText;
	}
});		
});		

// Set focus to input field (set form id to focus)

$(function(){
	$("#focus :input:visible:enabled:first").focus();
});


// Back To Top
(function() {

function $(id) {
	return document.getElementById(id);
}

function setStyleDisplay(id, status) {
	$(id).style.display = status;
}

function goTop(acceleration, time) {
	acceleration = acceleration || 0.1;
	time = time || 16;

	var dx = 0;
	var dy = 0;
	var bx = 0;
	var by = 0;
	var wx = 0;
	var wy = 0;

	if (document.documentElement) {
		dx = document.documentElement.scrollLeft || 0;
		dy = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		bx = document.body.scrollLeft || 0;
		by = document.body.scrollTop || 0;
	}
	var wx = window.scrollX || 0;
	var wy = window.scrollY || 0;

	var x = Math.max(wx, Math.max(bx, dx));
	var y = Math.max(wy, Math.max(by, dy));

	var speed = 1 + acceleration;
	window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
	if(x > 0 || y > 0) {
		var invokeFunction = "MGJS.goTop(" + acceleration + ", " + time + ")"
		window.setTimeout(invokeFunction, time);
	}
}

window['MGJS'] = {};
window['MGJS']['$'] = $;
window['MGJS']['setStyleDisplay'] = setStyleDisplay;
window['MGJS']['goTop'] = goTop;

})();