function validate_keyword_search(theform, error_m) {
    var t = theform.and_words.value;
    
    if(t.length == 0) {
        alert(error_m);
    } else {
        theform.submit();
    }
}

function validate_keyword_search_on_submit(theform) {
    var t = theform.and_words.value;
    
    if(t.length == 0) {
        alert("Please enter a search term");
        return false;
    } else {
        return true;
    }
}

function validate_rulenumber_search(theform, error_m) {
    if (theform.rulenumber.value.length == 0) {
        alert(error_m);
    } else {
        theform.submit();
    }
}

function validate_rulenumber_search_on_submit(theform) {
    if (theform.rulenumber.value.length == 0) {
        alert("Please enter a rule number");
        return false;
    } else {
        return true;
    }
}

function changeMonths1(){
	selectedMonth = document.search_form.months1.value;
	selectedMonth = checkMonthLength(selectedMonth);
	
	removeAllOptions(document.search_form.months1);
	if(document.search_form.years1.value != '2007'){
		addOption(document.search_form.months1, "01", "Jan", selectedMonth);
		addOption(document.search_form.months1, "02", "Feb", selectedMonth);
		addOption(document.search_form.months1, "03", "Mar", selectedMonth);
		addOption(document.search_form.months1, "04", "Apr", selectedMonth);
		addOption(document.search_form.months1, "05", "May", selectedMonth);
		addOption(document.search_form.months1, "06", "Jun", selectedMonth);
		addOption(document.search_form.months1, "07", "Jul", selectedMonth);
		addOption(document.search_form.months1, "08", "Aug", selectedMonth);
		addOption(document.search_form.months1, "09", "Sep", selectedMonth);
		addOption(document.search_form.months1, "10", "Oct", selectedMonth);
		addOption(document.search_form.months1, "11", "Nov", selectedMonth);
		addOption(document.search_form.months1, "12", "Dec", selectedMonth);
	}else{
		addOption(document.search_form.months1, "03", "Mar", selectedMonth);
		addOption(document.search_form.months1, "04", "Apr", selectedMonth);
		addOption(document.search_form.months1, "05", "May", selectedMonth);
		addOption(document.search_form.months1, "06", "Jun", selectedMonth);
		addOption(document.search_form.months1, "07", "Jul", selectedMonth);
		addOption(document.search_form.months1, "08", "Aug", selectedMonth);
		addOption(document.search_form.months1, "09", "Sep", selectedMonth);
		addOption(document.search_form.months1, "10", "Oct", selectedMonth);
		addOption(document.search_form.months1, "11", "Nov", selectedMonth);
		addOption(document.search_form.months1, "12", "Dec", selectedMonth);
	}
}

function changeMonths2(){
	selectedMonth = document.search_form.months2.value;
	selectedMonth = checkMonthLength(selectedMonth);
	
	removeAllOptions(document.search_form.months2);
	if(document.search_form.years2.value != '2007'){
		addOption(document.search_form.months2, "01", "Jan", selectedMonth);
		addOption(document.search_form.months2, "02", "Feb", selectedMonth);
		addOption(document.search_form.months2, "03", "Mar", selectedMonth);
		addOption(document.search_form.months2, "04", "Apr", selectedMonth);
		addOption(document.search_form.months2, "05", "May", selectedMonth);
		addOption(document.search_form.months2, "06", "Jun", selectedMonth);
		addOption(document.search_form.months2, "07", "Jul", selectedMonth);
		addOption(document.search_form.months2, "08", "Aug", selectedMonth);
		addOption(document.search_form.months2, "09", "Sep", selectedMonth);
		addOption(document.search_form.months2, "10", "Oct", selectedMonth);
		addOption(document.search_form.months2, "11", "Nov", selectedMonth);
		addOption(document.search_form.months2, "12", "Dec", selectedMonth);
	}else{
		addOption(document.search_form.months2, "03", "Mar", selectedMonth);
		addOption(document.search_form.months2, "04", "Apr", selectedMonth);
		addOption(document.search_form.months2, "05", "May", selectedMonth);
		addOption(document.search_form.months2, "06", "Jun", selectedMonth);
		addOption(document.search_form.months2, "07", "Jul", selectedMonth);
		addOption(document.search_form.months2, "08", "Aug", selectedMonth);
		addOption(document.search_form.months2, "09", "Sep", selectedMonth);
		addOption(document.search_form.months2, "10", "Oct", selectedMonth);
		addOption(document.search_form.months2, "11", "Nov", selectedMonth);
		addOption(document.search_form.months2, "12", "Dec", selectedMonth);
	}
}

function changeMonthsFr1(){
	selectedMonth = document.search_form.months1.value;
	selectedMonth = checkMonthLength(selectedMonth);
	
	removeAllOptions(document.search_form.months1);
	if(document.search_form.years1.value != '2007'){
		addOption(document.search_form.months1, "01", "janvier", selectedMonth);
		addOption(document.search_form.months1, "02", "février", selectedMonth);
		addOption(document.search_form.months1, "03", "mars", selectedMonth);
		addOption(document.search_form.months1, "04", "avril", selectedMonth);
		addOption(document.search_form.months1, "05", "mai", selectedMonth);
		addOption(document.search_form.months1, "06", "juin", selectedMonth);
		addOption(document.search_form.months1, "07", "juillet", selectedMonth);
		addOption(document.search_form.months1, "08", "août", selectedMonth);
		addOption(document.search_form.months1, "09", "septembre", selectedMonth);
		addOption(document.search_form.months1, "10", "octobre", selectedMonth);
		addOption(document.search_form.months1, "11", "novembre", selectedMonth);
		addOption(document.search_form.months1, "12", "décembre", selectedMonth);
	}else{
		addOption(document.search_form.months1, "03", "mars", selectedMonth);
		addOption(document.search_form.months1, "04", "avril", selectedMonth);
		addOption(document.search_form.months1, "05", "mai", selectedMonth);
		addOption(document.search_form.months1, "06", "juin", selectedMonth);
		addOption(document.search_form.months1, "07", "juillet", selectedMonth);
		addOption(document.search_form.months1, "08", "août", selectedMonth);
		addOption(document.search_form.months1, "09", "septembre", selectedMonth);
		addOption(document.search_form.months1, "10", "octobre", selectedMonth);
		addOption(document.search_form.months1, "11", "novembre", selectedMonth);
		addOption(document.search_form.months1, "12", "décembre", selectedMonth);
	}
}

function changeMonthsFr2(){
	selectedMonth = document.search_form.months2.value;
	selectedMonth = checkMonthLength(selectedMonth);
	
	removeAllOptions(document.search_form.months2);
	if(document.search_form.years2.value != '2007'){
		addOption(document.search_form.months2, "01", "janvier", selectedMonth);
		addOption(document.search_form.months2, "02", "février", selectedMonth);
		addOption(document.search_form.months2, "03", "mars", selectedMonth);
		addOption(document.search_form.months2, "04", "avril", selectedMonth);
		addOption(document.search_form.months2, "05", "mai", selectedMonth);
		addOption(document.search_form.months2, "06", "juin", selectedMonth);
		addOption(document.search_form.months2, "07", "juillet", selectedMonth);
		addOption(document.search_form.months2, "08", "août", selectedMonth);
		addOption(document.search_form.months2, "09", "septembre", selectedMonth);
		addOption(document.search_form.months2, "10", "octobre", selectedMonth);
		addOption(document.search_form.months2, "11", "novembre", selectedMonth);
		addOption(document.search_form.months2, "12", "décembre", selectedMonth);
	}else{
		addOption(document.search_form.months2, "03", "mars", selectedMonth);
		addOption(document.search_form.months2, "04", "avril", selectedMonth);
		addOption(document.search_form.months2, "05", "mai", selectedMonth);
		addOption(document.search_form.months2, "06", "juin", selectedMonth);
		addOption(document.search_form.months2, "07", "juillet", selectedMonth);
		addOption(document.search_form.months2, "08", "août", selectedMonth);
		addOption(document.search_form.months2, "09", "septembre", selectedMonth);
		addOption(document.search_form.months2, "10", "octobre", selectedMonth);
		addOption(document.search_form.months2, "11", "novembre", selectedMonth);
		addOption(document.search_form.months2, "12", "décembre", selectedMonth);
	}
}

function checkMonthLength(selectedMonth){
	if (selectedMonth.length != 2){
		selectedMonth = "0" + selectedMonth;
	}
	
	return selectedMonth;
}

function removeAllOptions(selectbox){
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text, selectedValue){

	if (value == selectedValue){
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		optn.selected = true;
	}else{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
	}

	selectbox.options.add(optn);
}
