function checkAll(obj) {
	var arrInput = document.getElementsByTagName("input");
	for (i=0; i<arrInput.length; i++) {
		if (arrInput[i].type == 'checkbox') {
			arrInput[i].checked = obj.checked;
		} 
	}
}

function checkForm(form){
	re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	if (form.s_date.value != '' && !form.s_date.value.match(re)) {
		alert("Invalid date format: " + form.s_date.value + ". Please use mm/dd/yyyy format.");
		form.s_date.focus();
		return false;
	}
	if (form.e_date.value != '' && !form.e_date.value.match(re)) {
		alert("Invalid date format: " + form.e_date.value + ". Please use mm/dd/yyyy format.");
		form.e_date.focus();
		return false;
	}
}

function populate(objForm,selectIndex) {
	timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text, objForm.month.options[objForm.month.selectedIndex].value,1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	for (var i = 0; i < objForm.day.length; i++) {
		objForm.day.options[0] = null;
	}
	for (var i = 0; i < daysInMonth; i++) {
		objForm.day.options[i] = new Option(i+1);
	}
	document.f1.day.options[0].selected = true;
}

function getYears() {
	// You can easily customize what years can be used
	var years = new Array(2009,2010,2011)
	for (var i = 0; i < document.f1.year.length; i++) {
		document.f1.year.options[0] = null;
	}
	timeC = new Date();
	currYear = timeC.getFullYear();
	for (var i = 0; i < years.length; i++) {
		document.f1.year.options[i] = new Option(years[i]);
	}
	document.f1.year.options[2].selected=true;
}

window.onLoad = getYears;

function RunIndex() {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="175" height="100">\n');
	document.write('<param name="movie" value="images/rotator.swf">\n');
	document.write('<param name="wmode" value="transparent">\n');
	document.write('<param name=menu value="false">\n');
	document.write('<param name="quality" value="high">\n');
	document.write('<embed src="images/rotator.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="175 height="100" wmode="transparent"></embed>\n');
	document.write('</object>\n');
}

function RunCat() {
	document.write('<a href="http://www.mthoodterritory.com/Submit.html" target="_blank"><img src="http://www.mthoodterritory.com/images/enews_button.gif" alt="Subscribe to our E-Newsletter" width="130" height="38" border="0"></a><br>\n');
	document.write('<a href="http://www.mthoodterritory.com/Submit.html" target="_blank">Click here</a> to receive our<br>monthly newsletter. <br><br>\n');
}

function RunBtmNav() {
	document.write('<p><center><p><a href="http://www.mthoodterritory.com/partners/" class="nav2"><img src="http://www.mthoodterritory.com/images/mini.gif" width="127" height="74" border="0"><br> \n');
	document.write('CCTCA Partners</a><p>1-800-424-3002 (toll-free information)<br> \n');
	document.write('<a href="http://www.mthoodterritory.com/contact.jsp" class="nav2">Contact Us</a> | <a href="http://www.mthoodterritory.com/disclaimer.htm" class="nav2">Privacy/Disclaimer Policy</a> | <a href="http://www.mthoodterritory.com/sitemap.jsp" class="nav2">Site Map</a></p> \n');
	document.write('<a href="http://www.mthoodterritory.com/" class="nav2">Home</a> | <a href="http://www.mthoodterritory.com/lodging.jsp" class="nav2">Lodging</a> | <a href="http://www.mthoodterritory.com/dining.jsp" class="nav2">Dining</a> | <a href="http://www.mthoodterritory.com/greatoutdoors.jsp" class="nav2">Recreation</a> | <a href="http://www.mthoodterritory.com/heritage.jsp" class="nav2">Heritage & Culture</a><br> \n');
	document.write('<a href="http://www.mthoodterritory.com/countrypleasures.jsp" class="nav2">Agritourism</a> | <a href="http://www.mthoodterritory.com/shopping.jsp" class="nav2">Shopping</a> | <a href="http://www.mthoodterritory.com/events.jsp" class="nav2">Events</a> | <a href="http://www.mthoodterritory.com/territory.htm" class="nav2">Territory Overview</a><br> \n');
	document.write('<a href="http://www.mthoodterritory.com/meetings.jsp" class="nav2">Meeting Planning</a> | <a href="http://www.mthoodterritory.com/group.jsp" class="nav2">Group Travel</a> | <a href="http://www.mthoodterritory.com/press.htm" class="nav2">Press Room</a> | <a href="http://www.mthoodterritory.com/info.jsp" class="nav2">More Info</a></p></center></p> \n');
}

function submitdaform() {
	document.forms[0].submit();
}

function toggleMe(a){
	var e=document.getElementById(a);
	if(!e)return true;
	if(e.style.display=="none"){
		e.style.display="block"
	} else {
		e.style.display="none"
	}
	return true;
}

function Del(Word) {
	a = Word.indexOf("<");
	b = Word.indexOf(">");
	len = Word.length;
	c = Word.substring(0, a);
	if(b == -1)
	b = a;
	d = Word.substring((b + 1), len);
	Word = c + d;
	tagCheck = Word.indexOf("<");
	if(tagCheck != -1)
	Word = Del(Word);
	return Word;
}

function Check() {
	ToCheck = document.TDC.message.value;
	Checked = Del(ToCheck);
	document.TDC.message.value = Checked;
	return true;
}

var FormName = "TDC";
var RequiredFields = "to,from,toEmail,fromEmail";
function ValidateRequiredFields() {
	var FieldList = RequiredFields.split(",")
	var BadList = new Array();
	for(var i = 0; i < FieldList.length; i++) {
		var s = eval('document.' + FormName + '.' + FieldList[i] + '.value');
		s = StripSpacesFromEnds(s);
		if(s.length < 1) { BadList.push(FieldList[i]); }
	}
	if(BadList.length < 1) { return true; }
	var ess = new String();
	if(BadList.length > 1) { ess = 's'; }
	var message = new String('\n\nThe following field' + ess + ' are required:\n');
	for(var i = 0; i < BadList.length; i++) { message += '\n' + BadList[i]; }
	alert(message);
	return false;
}

function StripSpacesFromEnds(s) {
	while((s.indexOf(' ',0) == 0) && (s.length> 1)) {
		s = s.substring(1,s.length);
	}
	while((s.lastIndexOf(' ') == (s.length - 1)) && (s.length> 1)) {
	 s = s.substring(0,(s.length - 1));
	}
	if((s.indexOf(' ',0) == 0) && (s.length == 1)) { s = ''; }
	return s;
}

function close_other_box(box){
	if(box.id.value="box1"){
	 document.getElementById("box2").disabled=true;
 } else{
	 document.getElementById("box2").disabled=false;
 }
}

function close_box(box){
	if(box.id.value="box2"){
	 document.getElementById("box1").disabled=true;
 } else {
	 document.getElementById("box1").disabled=false;
 }
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}

