﻿function prepUpControls(up, clear) {
    if($(up).val()=="") { $(clear).hide(); }
    $(up).change(function() {
        if($(up).val()=="") {
            $(clear).hide("slow");
        } else {
            $(clear).show("slow");
        }
    });
    $(clear).click(function(e) {
        $(up).val("");
        $(clear).hide("slow");
        return false;
    });
}

function prepLimitChars(textid, limit, infoid) {
	$('#'+textid).keyup(function() { limitChars(textid, limit, infoid); });
	limitChars(textid, limit, infoid);
}

function limitChars(textid, limit, infoid) {
	var text = $('#'+textid).val();
	var textlength = text.length;
	var info = $('#'+infoid);
	if(textlength > limit) {
		info.html('You cannot write more than '+limit+' characters.');
		return false;
	} else {
		info.html('Max. '+limit+' characters. '+(limit-textlength)+' left.');
		return true;
	}
}
$(document).ready(function() {	$(".hover_bo").hover(		function() { $(this).attr('src', $(this).attr('src').replace("_b.gif", "_bo.gif")); },		function() { $(this).attr('src', $(this).attr('src').replace("_bo.gif", "_b.gif")); }		);	$(".charcount").each(function() {		infoid = $(this).attr('id');		textid = $(this).attr('target');		limit = $(this).attr('maxlength');				prepLimitChars(textid, limit, infoid);	});		$(".req").prepend("<span class='reqc'>*</span>");});
