// Strictly speaking, I didn't HAVE to do this, but wanted to learn how to include 
// js files and how to use href="javascript:void(0);".
function goToMap() {
	location.href = "/2010_tour/interactive_map/";
	return false;
}


var minYear=1800;
var maxYear=2200;

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function isNonNegInt(s){
	var i;
  for (i = 0; i < s.length; i++){   
    // Check that current character is number.
    var c = s.charAt(i);
    if (((c < "0") || (c > "9"))) 
    	return false;
  }
  return true; // All characters are numbers.
}

function validateDate(dtStr){
	if (dtStr.length != 8) {
		alert("The date must be 8 characters long.");
		return false;
	}
	if (!isNonNegInt(dtStr)) {
		alert("The date must contain only digits.");
		return false;
	}

	var daysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31];

	var strYr=dtStr.substr(0,4);
	var strMonth=dtStr.substr(4,2);
	var strDay=dtStr.substr(6,2);

	// NOTE: have to explicitly indicate radix 10, because discovered this bug
  // http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C85006A6604
  // ...luckily BEFORE I left on my trip!
	var year=parseInt(strYr, 10);
	var month=parseInt(strMonth, 10);
	var day=parseInt(strDay, 10);

	if (year<minYear || year>maxYear){
		alert("Please enter a valid 4-digit year between "+minYear+" and "+maxYear+".");
		return false;
	}
	if (month<1 || month>12){
		alert("Please enter a valid month.");
		return false;
	}
	if (day<1 || day>daysInMonth[month] || (month==2 && day>daysInFebruary(year))){
		alert("Please enter a valid day.");
		return false;
	}
	return true;
}

function simpleValidateURL(url) {
	if ("http://" == url.substr(0, 7))
		return true;
	return false;
}
