// JavaScript Document
function yearChange(thisForm,firstYear,firstMonth,firstDay,lastYear,lastMonth,lastDay,lang) {
	thisForm.optLimit[1].checked = 1;
	var monthText = new Array();
	if (lang == 1) {
		monthText[1] = 'January';
		monthText[2] = 'February';
		monthText[3] = 'March';
		monthText[4] = 'April';
		monthText[5] = 'May';
		monthText[6] = 'June';
		monthText[7] = 'July';
		monthText[8] = 'August';
		monthText[9] = 'September';
		monthText[10] = 'October';
		monthText[11] = 'November';
		monthText[12] = 'December';
	} else {
		monthText[1] = 'janvier';
		monthText[2] = 'f\u00E9vrier';
		monthText[3] = 'mars';
		monthText[4] = 'avril';
		monthText[5] = 'mai';
		monthText[6] = 'juin';
		monthText[7] = 'juillet';
		monthText[8] = 'ao\u00FBt';
		monthText[9] = 'septembre';
		monthText[10] = 'octobre';
		monthText[11] = 'novembre';
		monthText[12] = 'd\u00E9cembre';
	}

	selectedMonth = thisForm.Month[thisForm.Month.selectedIndex].value;
	selectedDay = thisForm.Day[thisForm.Day.selectedIndex].value;

	if (thisForm.Year.value == firstYear) {
		thisForm.Month.length = 13 - firstMonth;
		for (i=0; i<thisForm.Month.length; i++) {
			if (i + firstMonth == selectedMonth) {
				thisForm.Month.options[i] = new Option(monthText[i+parseInt(firstMonth)],i+parseInt(firstMonth));
				thisForm.Month.options[i].selected = true;
			} else {
				thisForm.Month.options[i] = new Option(monthText[i+parseInt(firstMonth)],i+parseInt(firstMonth));
				thisForm.Month.options[i].selected = false;
			}
		}
	} else if (thisForm.Year.value == lastYear) {
		thisForm.Month.length = lastMonth;
		for (i=0; i<thisForm.Month.length; i++) {
			if (i + 1 == selectedMonth) {
				thisForm.Month.options[i] = new Option(monthText[i+1],i+1);
				thisForm.Month.options[i].selected = true;
			} else {
				thisForm.Month.options[i] = new Option(monthText[i+1],i+1);
				thisForm.Month.options[i].selected = false;
			}
		}
	} else {
		thisForm.Month.length = 12;
		for (i=0; i<thisForm.Month.length; i++) {
			if (i + 1 == selectedMonth) {
				thisForm.Month.options[i] = new Option(monthText[i+1],i+1);
				thisForm.Month.options[i].selected = true;
			} else {
				thisForm.Month.options[i] = new Option(monthText[i+1],i+1);
				thisForm.Month.options[i].selected = false;
			}
		}
	}
	updateDays(thisForm,firstYear,firstMonth,firstDay,lastYear,lastMonth,lastDay);
}

function updateDays(thisForm,firstYear,firstMonth,firstDay,lastYear,lastMonth,lastDay) {
	daySelected = thisForm.Day.options[thisForm.Day.selectedIndex].value;
	startDay = 1;
	if (thisForm.Month.options[thisForm.Month.selectedIndex].value == 1 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 3 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 5 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 7 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 8 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 10 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 12) {
		if (thisForm.Year.options[thisForm.Year.selectedIndex].value == firstYear &&
			 thisForm.Month.options[thisForm.Month.selectedIndex].value == firstMonth) {
			thisForm.Day.length = 32 - firstDay;
			startDay = firstDay;
		} else if (thisForm.Year.options[thisForm.Year.selectedIndex].value == lastYear &&
					  thisForm.Month.options[thisForm.Month.selectedIndex].value == lastMonth) {
			thisForm.Day.length = lastDay;
		} else {
			thisForm.Day.length = 31;
		}
	} else if (thisForm.Month.options[thisForm.Month.selectedIndex].value == 4 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 6 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 9 |
		 thisForm.Month.options[thisForm.Month.selectedIndex].value == 11) {
		if (thisForm.Year.options[thisForm.Year.selectedIndex].value == firstYear &&
			 thisForm.Month.options[thisForm.Month.selectedIndex].value == firstMonth) {
			thisForm.Day.length = 31 - firstDay;
			startDay = firstDay;
		} else if (thisForm.Year.options[thisForm.Year.selectedIndex].value == lastYear &&
					  thisForm.Month.options[thisForm.Month.selectedIndex].value == lastMonth) {
			thisForm.Day.length = lastDay;
		} else {
			thisForm.Day.length = 30;
		}
	} else {
		thisYear = thisForm.Year.options[thisForm.Year.selectedIndex].value;
		thisDate = new Date(thisYear,'1','29');
		if (thisDate.getDate() == 29) {
			if (thisForm.Year.options[thisForm.Year.selectedIndex].value == firstYear &&
				 thisForm.Month.options[thisForm.Month.selectedIndex].value == firstMonth) {
				thisForm.Day.length = 30 - firstDay;
				startDay = firstDay;
			} else if (thisForm.Year.options[thisForm.Year.selectedIndex].value == lastYear &&
						  thisForm.Month.options[thisForm.Month.selectedIndex].value == lastMonth) {
				thisForm.Day.length = lastDay;
			} else {
				thisForm.Day.length = 29;
			}
		} else {
			if (thisForm.Year.options[thisForm.Year.selectedIndex].value == firstYear &&
				 thisForm.Month.options[thisForm.Month.selectedIndex].value == firstMonth) {
				thisForm.Day.length = 29 - firstDay;
				startDay = firstDay;
			} else if (thisForm.Year.options[thisForm.Year.selectedIndex].value == lastYear &&
						  thisForm.Month.options[thisForm.Month.selectedIndex].value == lastMonth) {
				thisForm.Day.length = lastDay;
			} else {
				thisForm.Day.length = 28;
			}
		}
	}

	for (i = startDay; i < thisForm.Day.length + 1; i++) {
		if (i == daySelected || (daySelected < startDay && i == startDay) ||
			(daySelected > thisForm.Day.length && i == thisForm.Day.length)) {
			thisForm.Day.options[i-startDay] = new Option(i,i);
			thisForm.Day.options[i-startDay].selected = true;
		} else {
			thisForm.Day.options[i-startDay] = new Option(i,i);
			thisForm.Day.options[i-startDay].selected = false;
		}
	}
}

function checkStnNameValidity (thisForm,txtMessage) {
	if (thisForm.txtStationName.value.length < 3) {
		alert(txtMessage);
		thisForm.txtStationName.focus();
		return false;
	}
	return true;
}

function checkStnProxValidity (thisForm,txtMessage,latDegMsg,latMinMsg,longDegMsg,longMinMsg) {
	var radioGrp = thisForm.optProxType;
	for (var i = 0; i < radioGrp.length; i++) {
		if(radioGrp[i].checked) {
			var radioChecked = radioGrp[i].value;
		}
	}
	switch (radioChecked) {
		case "city":
			if(thisForm.selCity.selectedIndex == 0) {
				alert(txtMessage);
				thisForm.selCity.focus();
				return false;
			}
			break;
		case "park":
			if(thisForm.selPark.selectedIndex == 0) {
				alert(txtMessage);
				thisForm.selPark.focus();
				return false;
			}
			break;
		case "custom":
			if(thisForm.txtCentralLatDeg.value.length == 0 || thisForm.txtCentralLongDeg.value.length == 0) {
				alert(txtMessage);
				thisForm.txtCentralLatDeg.focus();
				return false;
			} else if (!checknumber(thisForm.txtCentralLatDeg.value) || !numberrange(thisForm.txtCentralLatDeg.value,0,90)) {
				alert(latDegMsg);
				thisForm.txtCentralLatDeg.select();
				return false;
			} else if (!checknumber(thisForm.txtCentralLongDeg.value) || !numberrange(thisForm.txtCentralLongDeg.value,0,180)) {
				alert(longDegMsg);
				thisForm.txtCentralLongDeg.select();
				return false;
			} else if (!checknumber(thisForm.txtCentralLatMin.value) || !numberrange(thisForm.txtCentralLatMin.value,0,59)) {
				alert(latMinMsg);
				thisForm.txtCentralLatMin.select();
				return false;
			} else if (!checknumber(thisForm.txtCentralLongMin.value) || !numberrange(thisForm.txtCentralLongMin.value,0,59)) {
				alert(longMinMsg);
				thisForm.txtCentralLongMin.select();
				return false;
			}
			break;
		default:
			return false;
	}
	return true;
}

function checknumber (object_value) {
	if (object_value.length == 0) return true;

	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	check_char = start_format.indexOf(object_value.charAt(0));

	if (check_char == 1) decimal = true;
	else if (check_char < 1) return false;

	for (var i = 1; i < object_value.length; i++) {
		check_char = number_format.indexOf(object_value.charAt(i));
		if (check_char < 0) return false;
		else if (check_char == 1) {
			if (decimal) return false;
			else decimal = true;
		} else if (check_char == 0) {
			if (decimal || digits) trailing_blank = true;
		} else if (trailing_blank) return false;
		else digits = true;
	}	
	return true
}

function numberrange(object_value, min_value, max_value) {
	if (min_value != null) {
		if (object_value < min_value) return false;
	}
	if (max_value != null) {
		if (object_value > max_value) return false;
	}
	return true;
}
//function that will make sure that the reset is working
function setDayMonthValues(thisForm,daySelected,monthSelected,firstYear,firstMonth,firstDay,lastYear,lastMonth,lastDay, lang)
{
	yearChange(thisForm,firstYear,firstMonth,firstDay,lastYear,lastMonth,lastDay, lang);
	
	thisForm.reset();
	
	if (thisForm.Month.options[thisForm.Month.selectedIndex].value != parseInt(monthSelected)){
		thisForm.Month.options[parseInt(monthSelected)-1].selected=true;
	}

	if (thisForm.Day.options[thisForm.Day.selectedIndex].value != parseInt(daySelected)){
		thisForm.Day.options[parseInt(daySelected)-1].selected = true;	
	}
	
	yearChange(thisForm,firstYear,firstMonth,firstDay,lastYear,lastMonth,lastDay, lang);
}
/***********************************************************************************************************************************/
/* This function takes in a string and looks for special characters that match the ones found in stringArrayF. 
/* If/when there is a match the character will be replaced with a character from the stringArrayE array at the equivalent location.
/* The fucntion will then return a accent-free string*/
/********************************************************************************************************************************Ang
function parseString (a){
	var stringArrayF = ['À','Â','Ä','Á','È','É','Ê','Ë','Î','Ï','Ô','Œ','Ù','Û','Ü','Ÿ','à','â','ä','è','é','ê','ë','î','ï','ô','œ','ù','û','ü','ÿ','Ç','ç','«','»'];
	var stringArrayE = ['A','A','A','A','E','E','E','E','I','I','O','OE','U','U','U','Y','a','a','a','e','e','e','e','i','i','o','oe','u','u','u','y','c','c','"','"'];
	var temp = new Array();
	temp = a.split('');

	for (i=0; i < a.length; i++){
		for (j=0; j < stringArrayF.length; j++){
			if(temp[i] == stringArrayF[j]){
				a = a.replace(temp[i], stringArrayE[j]);
			}
		}
	}
	return a;
}*/
