// JavaScript Document

//Navigation
function Nav() {
	document.write('<table border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFCC" width="140"><tr><td align="left"> \n');
	document.write('<a href="http://www.mthoodterritory.com/">Home</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/lodging.jsp">Lodging</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/dining.jsp">Dining</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/greatoutdoors.jsp">Recreation</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/heritage.jsp">Heritage &amp; Culture</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/countrypleasures.jsp">Agritourism</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/shopping.jsp">Shopping</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/event.jsp">Events</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/weddings/">Wedding Guide</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/cities.htm">Communities</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/territory.htm">Territory Overview</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/meetings.jsp">Meeting Planning</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/group.jsp">Group Travel</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/press.htm">Press Room</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/vid/">Video Gallery </a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/info.jsp">More Info</a><br /> \n');
	document.write('<a href="http://www.mthoodterritory.com/contact.jsp">Contact Us</a><br /> \n');
	document.write('</td></tr></table><br /> \n');
	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('<div style="font-size:11px"><a href="http://www.mthoodterritory.com/Submit.html" target="_blank" class="nav2">Click here</a> to receive our<br>monthly newsletter.</div><br />\n');
	document.write('<a href="http://www.mthoodterritory.com/wander/"><img src="http://www.mthoodterritory.com/images/banner_wander.gif" width="148" height="133" border="0" /></a><br />\n');
}

//Bottom Navigation
function RunBtmNav() {
	document.write('<p align="center"><a href="http://www.mthoodterritory.com/partners/"><img src="http://www.mthoodterritory.com/images/mini.png" width="127" height="74" border="0"></a>\n');
	document.write('<br><a href="http://www.mthoodterritory.com/partners/" class="nav2">CCTCA Partners</a><br><br>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><br><br> \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/event.jsp" class="nav2">Events</a> | <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/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');
}
//Bottom Navigation Option 2
function RunBtmNav3() {
	document.write('<p align="center"><a href="http://www.mthoodterritory.com/partners/" class="nav2"><img src="http://www.mthoodterritory.com/images/mini.png" width="127" height="74" border="0"></a>\n');
	document.write('<br><a href="http://www.mthoodterritory.com/partners/" class="nav2">CCTCA Partners</a><br><br>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><br><br> \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/event.jsp" class="nav2">Events</a> | <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/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');
}

// Wander contest checkbox combine  Note: Needs to be standardized
function checkboxes() {
	fld=document.TDC2.fCat;
	str=''
	for (i=0;i<fld.length;i++){
		if (fld[i].checked) str+=fld[i].value;
	}
	document.TDC2.fCatValue.value=str;
}

//form validation
function checkForm(form){
	var name = form.fName.value;
	var email = form.fEmail.value;
	var zip = form.fZip.value;
	var news = form.fNews.value;
	var checked = false;
	if(name.length==0 && name != null){
		alert("Please enter your name in the form");
		form.fName.focus();  
		return false;
	}
	if(zip.length > 0 && zip != null){
		var valid = "0123456789-";
		var hyphencount = 0;
		for (var i=0; i < zip.length; i++) {
			temp = "" + zip.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {
				alert("Invalid characters in your zip code.  Please try again.");
				return false;
			}
			if ((hyphencount > 1) || ((zip.length==10) && ""+zip.charAt(5)!="-")) {
				alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
				return false;
			}
		}
	} else {
		alert("Please enter your 5 digit or 5 digit+4 zip code.");
		form.fZip.focus();  
		return false;
	}
	if (email.length==0){
		alert("Please fill out the email field before submitting this form.");
		form.fEmail.focus();
		return false;
	} else {
		if (!isEmailAddr(email)) {
			alert("Please enter a complete email address in the form: yourname@yourdomain.com");		
			form.fEmail.focus();  
			return false;
		}
	}
}
function isEmailAddr(email){
	var result = false;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
	if (index > 0){
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
}

function submitdaform() {
	document.forms[0].submit();
}

function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

Date.prototype.getWeek = function(){
	var onejan = new Date(this.getFullYear(),0,1);
	return Math.ceil((((this - onejan)/86400000)+onejan.getDay()+1)/7);
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* Partners Navigation Scripting */
var persistmenu="yes"
var persisttype="sitewide"
if (document.getElementById){ 
	document.write('<style type="text/css">\n')
	document.write('.submenu{display: none;}\n')
	document.write('</style>\n')
}
function SwitchMenu(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") 
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
function get_cookie(Name) { 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}
function onloadfunction(){
	if (persistmenu=="yes"){
		var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
		var cookievalue=get_cookie(cookiename)
		if (cookievalue!="")
		document.getElementById(cookievalue).style.display="block"
	}
}
function savemenustate(){
	var inc=1, blockid=""
	while (document.getElementById("sub"+inc)){
		if (document.getElementById("sub"+inc).style.display=="block"){
			blockid="sub"+inc
			break
		}
		inc++
	}
	var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
	var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
	document.cookie=cookiename+"="+cookievalue
}
if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction
if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate
