function setText(a, b)	{
	x = document.getElementById(a);
	if (x) {
		x.innerHTML = b.options[b.selectedIndex].innerHTML;
		setTextColor(a);
	}
}

function setTextColor(a){
	$("#" + a).css('color', '#202020');
}

// Adds a ".selected" function
(function ($) {
    $.fn.selected = function (fn) {
        return this.each(function () {
            var clicknum = 0;
            $(this).click(function () {
                clicknum++;
                if (clicknum == 2) {
                    clicknum = 0;
//                    fn();
                }
            });
        });
    }
})(jQuery);

// On load
$(function () {
    $('.mainNav ul li:has(div)').mouseover(function () {
        $(".subNav").hide();
        $(this).find(".subNav").show();
    }).mouseout(function () {
        $(this).find(".subNav").hide();
    });


    cleanerErrors();

    $('input').blur(function () {
        cleanerErrors();
    });

    $('input').keypress(function (e) {
        if (e.which == 13) {
            cleanerErrors();
        }
    });
	
    $('form').submit(function () {
        cleanerErrors();
		return validCareerCommentLength();
    });

    $('#file1').change(cleanerErrors());
    $('#file2').change(cleanerErrors());
    $('#file3').change(cleanerErrors());
    $('#ddlType1').selected(cleanerErrors());
    $('#ddlType2').selected(cleanerErrors());
    $('#ddlType3').selected(cleanerErrors());

});

function cleanerErrors(){
    $('.msg_erreur').each(function () {
        var current_style = "";
        current_style = $(this).attr('style');
        if (current_style != undefined) {
            if (current_style.indexOf('inline') != -1) {
                $(this).attr('style', 'display: block;');
            }

            if (current_style.indexOf('hidden') != -1) {
                $(this).attr('style', 'display: none;');
            }
        }
    });
}

function validCareerCommentLength(){
    var comment = "";
  // comment = $('textarea[name="ctl00$ctl00$ctl00$ctl00$ContentPlaceHolderDefault$cp_main$cp_main$postuler_3$txtComment"]').val();
  comment = $('#txtComment').val();
    if (comment != undefined) {
        if (comment.length > 500) {
            $('.CustomValidator_txtComment_Error').attr('style', 'display:block;');
            return false;
        }
    }
    return true;
}
