
$(document).ready(function() {
    $('.leftnav').hover(function() {
        $(this).addClass('leftnav_hover');
    }, function() {
        $(this).removeClass('leftnav_hover');
    });
});

// updates the counts in the compare and decide tabs
function update_compare_count() {
    //var orig_compare_count = $('.compare_count').html();
    $.post(base_url + 'compare/recalculatecomparenav',
        function(new_count) {
            //alert('added ' + (new_count - orig_compare_count));
            $('.compare_count').each(function(i){$(this).html(new_count);});
        }
    );
}

function reloadcommentcount(css_id, commentable_type, commentable_id) {
    old_val = $('#' + css_id).html();
    $.get(base_url + 'comment/count/' + commentable_type + '/' + commentable_id, 
        function(response){ 
            $('#' + css_id).html(response); 
            new_val = $('#' + css_id).html();
            if (new_val != old_val) {
                $('#' + css_id).effect("highlight", {color:'#E6F8DD'}, 2000);
            }
        });
}

/* check email address format */

function checkEmailFormat(emailAddress) {
	var email = emailAddress;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	}
	
	return true;	
}

/* funtions for showing and clearing default values in textboxes */
function clickclear(thisfield, defaulttext, color) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
        if (color) {
            thisfield.style.color = color;
        }
    }
}
function clickrecall(thisfield, defaulttext, color) {
    if (thisfield.value == "") {
        if (color) {
            thisfield.style.color = color;
        }
        thisfield.value = defaulttext;
    }
}
