var lastupdate = "May 29 2001";
var windowstatus = 0;
var version;
var browserName;
var browserVer;
var browComp;
var docloc = location.hostname;

function onLoad() {

	browserName = navigator.appName;
	browserVer = parseInt(navigator.appVersion);
	userAgent = navigator.userAgent;
	start = userAgent.indexOf("(");
	end = userAgent.indexOf(";");
	platform= userAgent.substring(start +1,end);  
	if (browserName == "Netscape" && browserVer >= 3) version = "n3";
		else version = "n2";
	if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) version = "n3";
	if (browserName == "Netscape") browComp = "N";
		else browComp = "IE";

//	SetCookie("PYTstops"," ");

}
onLoad();

// ***************************************************************************************
//									Cookie functions
// ***************************************************************************************

//
//  Cookie Functions - Second Helping  (21-Jan-96)
//  Written by:  Bill Dortch, hIdaho Design <bdortch@netw.com>
//  The following functions are released to the public domain.
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; 
}
return null;
}

//
//  Function to create or update a cookie.
//    name - String object object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to current date/time)
//    name - String object containing the cookie name
//
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);  // This cookie is history
var cval = GetCookie (name);
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function SaveStop(stopnumber, checked) {

	var stopstring = GetCookie("PYTstops");
	var temp = "";
	var newstopstring = "";
	var foundit = 0;
	var expdate = new Date();

	expdate.setTime (expdate.getTime() + (24*60*60*1000));
	
//	alert("Previous Cookie = '"+stopstring+"'");
//	return;
	if(stopstring == " " && checked) {
		newstopstring = stopnumber + " ";
		DeleteCookie("PYTstops");
		SetCookie("PYTstops",newstopstring,expdate);
		var cstring = GetCookie("PYTstops");
//		alert("Cookie now '"+ cstring+"', added "+newstopstring);
		return;
	}
//	alert("Cookie = " + stopstring);
	for(var i=0; i<stopstring.length; i++) {
		if(stopstring.charAt(i) == ' ' || i==stopstring.length) {
			if(temp == stopnumber) {
				foundit = 1;
//				alert("Found it");
				if(!checked) {
					temp = "";
				}
			} else {
//				alert("Number to be added: "+temp+" Current String: "+newstopstring);
				newstopstring += temp;
				newstopstring += " ";
				temp = "";
			}
		} else {
			temp += stopstring.charAt(i);
//			alert(temp);
		}
	}
	if( foundit==0 && checked) {
		newstopstring += stopnumber + " ";
	}
//	alert("New Cookie = " + newstopstring);
	SetCookie("PYTstops",newstopstring,expdate);
//	alert(newstopstring);
}

function cont_journey(form) {

	var LinkCookie = GetCookie("PYTstops");
//	alert("Cookie = " + LinkCookie);
	if( LinkCookie.length > 1) {
		form.StopText.value = form.StopText.value.substring(0,25)+"                                  $ " + LinkCookie;
	}
//    alert(form.StopText.value);
	if(form.status[0].checked && (form.StopText.value.length == 0 || form.StopText.value.substring(0,1)==" ")) {
		alert("Please enter your next stop");
		form.StopText.value = "";
		form.StopText.focus();
	} else {
		form.submit();
	}

}

function trimText(form) {

		form.StopText.value = form.StopText.value.substring(0,25);

}

// ***************************************************************************************
//									Load Image Objects
// ***************************************************************************************

//if(version == "n3") {
  if( 1==2) {
	var home_off = new Image();
	home_off.src = "ttpgraphics/Buttons/home_off.gif";
	var home_on = new Image();
	home_on.src = "ttpgraphics/Buttons/home_on.gif";

	var advertise_off = new Image();
	advertise_off.src = "ttpgraphics/Buttons/advertise_off.gif";
	var advertise_on = new Image();
	advertise_on.src = "ttpgraphics/Buttons/advertise_on.gif";

	var contact_off = new Image();
	contact_off.src = "ttpgraphics/Buttons/contact_off.gif";
	var contact_on = new Image();
	contact_on.src = "ttpgraphics/Buttons/contact_on.gif";

	var moreinfo_off = new Image();
	moreinfo_off.src = "ttpgraphics/Buttons/moreinfo_off.gif";
	var moreinfo_on = new Image();
	moreinfo_on.src = "ttpgraphics/Buttons/moreinfo_on.gif";

	var otherlinks_off = new Image();
	otherlinks_off.src = "ttpgraphics/Buttons/otherlinks_off.gif";
	var otherlinks_on = new Image();
	otherlinks_on.src = "ttpgraphics/Buttons/otherlinks_on.gif";

}

// ***************************************************************************************
//									activate functions
// ***************************************************************************************

function activategen(imgName) {
	if(version == "n3") {
		if ( eval(imgName + "_on.complete")) {
			document.images[imgName].src = eval(imgName+"_on.src");
		}
	}
} 

function deactivategen(imgName) {
	if(version == "n3") {
		if ( eval(imgName + "_off.complete")) {
			document.images[imgName].src = eval(imgName+"_off.src");
		}
	}
} 

function doNew(picktype,map) {
//	var myWind = window.open("","","Height=0, Width=0");
//	myWind.close();
var newurl = "http://www.plan-your-trip.com/"+map;
var 	myWind = window.open(newurl,picktype,"height=500,width=700,scrollbars");
	myWind.picktype = picktype;
	myWind.creator = window;
}

function doSelect(picktype,form,prov) {

	if(picktype == 'Start') {
		if(prov == 'BC') {
			form.StartText.value = form.StartCityBC.options[form.StartCityBC.selectedIndex].text + ","+prov;
		}
		if(prov == 'AB') {
			form.StartText.value = form.StartCityAB.options[form.StartCityAB.selectedIndex].text + ","+prov;
		}
		if(prov == 'SK') {
			form.StartText.value = form.StartCitySK.options[form.StartCitySK.selectedIndex].text + ","+prov;
		}
		if(prov == 'YK') {
			form.StartText.value = form.StartCityYK.options[form.StartCityYK.selectedIndex].text + ","+prov;
		}
		if(prov == 'WA') {
			form.StartText.value = form.StartCityWA.options[form.StartCityWA.selectedIndex].text + ","+prov;
		}
		if(prov == 'ID') {
			form.StartText.value = form.StartCityID.options[form.StartCityID.selectedIndex].text + ","+prov;
		}
		if(prov == 'MT') {
			form.StartText.value = form.StartCityMT.options[form.StartCityMT.selectedIndex].text + ","+prov;
		}
		if(prov == 'OR') {
			form.StartText.value = form.StartCityOR.options[form.StartCityOR.selectedIndex].text + ","+prov;
		}
		if(prov == 'UT') {
			form.StartText.value = form.StartCityUT.options[form.StartCityUT.selectedIndex].text + ","+prov;
		}
	} else {
		if(prov == 'BC') {
			form.StopText.value = form.EndCityBC.options[form.EndCityBC.selectedIndex].text + ","+prov;
		}
		if(prov == 'AB') {
			form.StopText.value = form.EndCityAB.options[form.EndCityAB.selectedIndex].text + ","+prov;
		}
		if(prov == 'SK') {
			form.StopText.value = form.EndCitySK.options[form.EndCitySK.selectedIndex].text + ","+prov;
		}
		if(prov == 'YK') {
			form.StopText.value = form.EndCityYK.options[form.EndCityYK.selectedIndex].text + ","+prov;
		}
		if(prov == 'WA') {
			form.StopText.value = form.EndCityWA.options[form.EndCityWA.selectedIndex].text + ","+prov;
		}
		if(prov == 'ID') {
			form.StopText.value = form.EndCityID.options[form.EndCityID.selectedIndex].text + ","+prov;
		}
		if(prov == 'MT') {
			form.StopText.value = form.EndCityMT.options[form.EndCityMT.selectedIndex].text + ","+prov;
		}
		if(prov == 'OR') {
			form.StopText.value = form.EndCityOR.options[form.EndCityOR.selectedIndex].text + ","+prov;
		}
		if(prov == 'UT') {
			form.StopText.value = form.EndCityUT.options[form.EndCityUT.selectedIndex].text + ","+prov;
		}
	}
}

function doNewProvince(map) {
var 	myWind = window.open(map,"","height=500,width=700,scrollbars");
	myWind.picktype = self.picktype;
	myWind.creator = self.creator;
	self.close();
}

function doNewListWindow(listurl) {
	var newurl = "http://www.plan-your-trip.com/"+listurl;
	var myWind = window.open(newurl,"","Height=600, Width=600");
	myWind.creator = window;
//	self.close();
}

function TransferText(textToTransfer) {
	if(self.creator) {
		if(self.picktype == "Start") {
			self.creator.document.next.StartText.value = textToTransfer;
		} else {
			self.creator.document.next.StopText.value = textToTransfer;
		}
	}
	self.close();
}

function doNewWindow(content) {
	var windowContent = "<HTML>\n<HEAD>\n<TITLE>\nDetailed Window 2\n</TITLE>\n</HEAD>\n"
	windowContent += "<BODY> Hello"
//	windowContent += content
	windowContent += "\n</BODY></HTML>"
	var	myWindow = window.open("","","height=300, width=300")
	if( myWindow != null) {
		myWindow.document.write(windowContent)
	}
}

function doNewJumpWindow(url,urlname,num) {
	var windowContent = "<HTML>\n<HEAD>\n<TITLE>\n"+urlname+"\n</TITLE>\n";
	windowContent += "<META HTTP-EQUIV=\"refresh\" CONTENT=\"5, URL=http://"+url+"\">\n";

	windowContent += "</HEAD>\n";
	windowContent += "<BODY>\n";
	windowContent += "<img src =\"/cgi-bin/Count.cgi?df="+num+"-c.dat&ft=0&dd=B&sh=N\" width=\"1\" height=\"1\">\n";
	windowContent += "<A HREF=\"http://"+url+"\"> Please wait... Loading "+urlname+"....</A>\n";
	windowContent += "<SCRIPT> window.location=\"http://"+url+"\" </SCRIPT>";
	windowContent += "\n</BODY>\n</HTML>";
	
	var	myWindow = window.open("","","height=400,width=800,scrollbars,toolbar,location,menubar,status");
	if( myWindow != null) {
		myWindow.document.write(windowContent);
		myWindow.document.close();
	}
}

function doMapWind(roadnum) {
	var newurl = "http://www.plan-your-trip.com/ttpgraphics/roads/"+roadnum+".gif";
	var myWind = window.open(newurl,"","height=220,width=220");
	myWind.creator = window;
//	self.close();
}
