function center_element(parent,child)
{
    $(child).css('position', 'absolute');
    $(child).css('left', ($(parent).width() - $(child).width()) / 2);
    if($(parent).height() != 0){
        if(($(parent).height() - $(child).height()) / 2 < 0)
			$(child).css('top', '0px');
		else
			$(child).css('top', ($(parent).height() - $(child).height()) / 2);
	}
}

function center_horizontal_element(parent,child)
{
    $(child).css('position', 'absolute');
    $(child).css('left', ($(parent).width() - $(child).width()) / 2);
}

function checkDateFormat(date)
{
	var dateRegEx =  /^(((((0?[1-9])|(1\d)|(2[0-8]))-((0?[1-9])|(1[0-2])))|((31-((0[13578])|(1[02])))|((29|30)-((0?[1,3-9])|(1[0-2])))))-((20[0-9][0-9]))|(29-0?2-20(([02468][048])|([13579][26]))))$/;
    if(date.search(dateRegEx) == -1)  return false;
    else return true;
}

function checkEmailFormat(email)
{
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if(email.search(emailRegEx) == -1) return false;
    else return true;
}

function checkPostalFormat(postal)
{
    if(postal.length != 6) return false;
    else if(isNaN(postal[0])) return false;
    else if(isNaN(postal[1])) return false;
    else if(isNaN(postal[2])) return false;
    else if(isNaN(postal[3])) return false;
    else if(Number(postal[4])) return false;
    else if(Number(postal[5])) return false;
    return true;
}

function valueInRange(value,min, max) {
    return (value >= min) && (value <= max);
}

function overlap(x1,y1,w1,h1,x2,y2,w2,h2) {
    var xOverlap = valueInRange(x1, x2, x2 + w2) || valueInRange(x2, x1, x1 + w1);
    var yOverlap = valueInRange(y1, y2, y2 + h2) || valueInRange(y2, y1, y1 + h1);
    return xOverlap && yOverlap;
}

function show_top_message(message, show_time){
    jQuery('#drop_down_message .message_text').text(message);
    jQuery('#drop_down_message').show();
    setTimeout(function(){
        jQuery('#drop_down_message').hide();
    }, show_time);
}

function remove_html_tags(input){
    return input.replace(/<(.|\n)*?>/g,'').replace(/\n/g, '<br/>').replace(/'/, "''");
}

function get_date_time(dbdate){
	var date = new Date();
	date.setTime(Date.parse(dbdate.replace(/-/g,'/')));
		
	var return_value = {
		date: date.getDate() + '-' + (date.getMonth()+1) + '-' + date.getFullYear(),
		time: date.getHours() + ':' + (date.getMinutes() < 10 ? '0' : '') + date.getMinutes()    
	}	
	
	return return_value;
}

function generate_aplhanumeric(size){
	chars = new Array ('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');

	charCount = chars.length;
	stringLength = size;
	var outputString = '';	
	var i = 0;
    while (i<stringLength){
		random = Math.floor(Math.random()*36);		
		random = chars[random];	
		outputString += random;
		i++;
	}
		
	return outputString;
}

function element_flash($element){
	$element.animate({
		backgroundColor: '#FF0000',
		color: '#FFFFFF'
	}, 500, function(){
		$element.animate({
			backgroundColor: '#FFFFFF',
			color: '#666666'
		}, 500);
	});
}

function rick_debug(input){
	if(jQuery.session('user') != null && jQuery.session('user').username == 'rick'){
		alert(input);
	}
}

function is_rick(){
	if(jQuery.session('user') != null && jQuery.session('user').username == 'rick')
		return true;	
	else
		return false;
	
	
}
