var $ = jQuery.noConflict();

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


$(document).ready(function() {

//check all
	$("input[name=check_all]").click(function(){
	var checked_status = this.checked;
		$("input[id^=check]").each(function(){
			this.checked = checked_status;
		});
	});	
	
	tooltip();
});

function gotoPageLink(pageLink){
	if(pageLink!=""){
		$target = $("a[name='"+ pageLink +"']");
		if ($target.length) {
			var targetOffset = $target.offset().top;
			$('html,body').animate({scrollTop: targetOffset}, 1000);
			return false;
		}
	}
}

function decision(message, url){
	if(confirm(message)) location.href = url;
}

function displayLoader(show_hide){
	if(show_hide==1){
		$("#loading_image").slideDown();
	}else{
		$("#loading_image").slideUp();
	}
}

function displayErrorMessage(){
	$("#loading_image").slideUp();
	alert("Requested data could not be loaded, please try again.\n\nIf the problem continues, please contact us with details of what you were attempting to do.");
}

function validateDate(form_value) {
    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    if (form_value.match(RegExPattern)== null) {
        return true; 
    } else {
        return false; 
    } 
}

function isNumeric(form_value){ 
    if(form_value.match(/^\d+$/) == null){
        return true; 
    }else{
		return false; 
	}
}

$.fn.disableOnSubmit = function(disableList){
	if(disableList == null){
		var $list = 'input[type=submit],input[type=button],input[type=reset],button';
	}else{
		var $list = disableList;
	}
	// Makes sure button is enabled at start
	$(this).find($list).removeAttr('disabled');
	
	$(this).submit(function(){
		$(this).find($list).val('Please wait...').attr('disabled','disabled');		
	});
	return this;
};