function inputcheck(el){
	var value = $(el).attr("value");
	var isError=false;
	if(! isValidValue(value)) isError=true;
	$(el).parent().children("img").remove();
	var img='true__018565500_1412_15112007.gif';
	if(isError) img='false__021706100_1412_15112007.gif';
	$(el).after("<img class='validation' src='/media/"+img+"' alt=\"\" />");
}
function isValidValue(value){
	if(value=='-1' || value=='' || typeof value=='undefined') return false;
	var regexp=new RegExp(/[\;|\!|\?|\$|%|\(|\)|&|<|>|=|\*\[\]\{\}=\+\/"]/);
	if((value.search(regexp)!=-1)&&(value!="WAGON R+")) return false;
	return true;
}

function selectcheck(el){
	var AllSelect = $(el).parent().children("select");
	var check = "true";
	var day,month,year,field;
	
	AllSelect.each(function(i,val){
		if($(val).attr("disabled")){}else
		{
				if($(val).attr("name").indexOf('Day')!==-1) day=$(val).val();
				if($(val).attr("name").indexOf('Month')!==-1) month=$(val).val();
				if($(val).attr("name").indexOf('Year')!==-1){
					year=$(val).val();
					var tmp=$(val).attr("name").split('_');
					field=tmp[1];
				}
				if($(val).val() == '-1'){
						check = "false";
				}
		}
	});
	if(typeof field!=='undefined'){
		if(month!=-1 && year!=-1){
			if(field==='DateDerniereEcheance') check=isPastDate(day,month,year);
			if(field==='DateEffet') check=isFutureDate(day,month,year);
			if(field==='DatePermisConducteur1') check=checkTestDriveDate('Conducteur1',month,year);
			if(field==='DatePermisConducteur2') check=checkTestDriveDate('Conducteur2',month,year);
		}
	}
	if(check == "true"){
		$(el).parent().children("img").remove();
		$(el).parent().append("<img class='validation' src='/media/true__018565500_1412_15112007.gif' alt='true' />"); 
	}else{
		$(el).parent().children("img").remove();
		$(el).parent().append("<img class='validation' src='/media/false__021706100_1412_15112007.gif' alt='false' />");
	}
}

function isPastDate(day,month,year){
	var now=new Date();
	var today=''+now.getFullYear()+formatDateElmt(now.getMonth()+1)+formatDateElmt(now.getDate());
	var toCheck=year+formatDateElmt(month)+formatDateElmt(day);
	if(toCheck<=today)
		return 'true';
	return 'false';
}
function isFutureDate(day,month,year){
	var now=new Date();
	var today=''+now.getFullYear()+formatDateElmt(now.getMonth()+1)+formatDateElmt(now.getDate());
	var toCheck=year+formatDateElmt(month)+formatDateElmt(day);
	if(toCheck<today) return 'false';
	var nextYear=''+(now.getFullYear()+1)+formatDateElmt(now.getMonth()+1)+formatDateElmt(now.getDate());
	if(toCheck>nextYear) return 'false';
	return 'true';
}
function checkTestDriveDate(field,month,year){
	var testDrive=year+formatDateElmt(month)+'01';
	if(($('#Year_DateNaissance'+field+'Id').val()!=-1) && (year-$('#Year_DateNaissance'+field+'Id').val()>=18)) return 'true';
	return 'false';
}
function checkGTADate(year){
	if(year>=$('#gtaDate').val()) return 'true';
	if(typeof $('#gtaDate').val()=='undefined') return 'true';
	return 'false';
}
function formatDateElmt(elmt){
	if(typeof elmt.length=='undefined') elmt=String(elmt);
	if(elmt.length==1) elmt='0'+elmt;
	return elmt;
}

function multiradiocheck(el){
        var AllRadio = $(el).children("input");
        var check = "false";
        AllRadio.each(function(i,val){
                if($(val).attr("checked")){
                        check= "true";
                }
        });
        if(check == "true"){
                $(el).children("img").remove();
                $(el).append("<img class='validation' src='/media/true__018565500_1412_15112007.gif' alt='true' />"); 
        }else{
                $(el).children("img").remove();
                $(el).append("<img class='validation' src='/media/false__021706100_1412_15112007.gif' alt='false' />");
        }
}
