var ActiveBtn = ""

var home_on = new Image(144,26)
var home_off = new Image(144,26)
var compare_on = new Image(144,26)
var compare_off = new Image(144,26)
var build_on = new Image(144,26)
var build_off = new Image(144,26)
var register_on = new Image(144,26)
var register_off = new Image(144,26)
var ebrochures_on = new Image(144,26)
var ebrochures_off = new Image(144,26)
var dealer_on = new Image(144,26)
var dealer_off = new Image(144,26)
var friend_on = new Image(144,26)
var friend_off = new Image(144,26)

home_on.src = "images/btn_home_on.gif"
home_off.src = "images/btn_home_off.gif"
compare_on.src = "images/btn_compare_on.gif"
compare_off.src = "images/btn_compare_off.gif"
build_on.src = "images/btn_build_on.gif"
build_off.src = "images/btn_build_off.gif"
register_on.src = "images/btn_register_on.gif"
register_off.src = "images/btn_register_off.gif"
ebrochures_on.src = "images/btn_ebrochures_on.gif"
ebrochures_off.src = "images/btn_ebrochures_off.gif"
dealer_on.src = "images/btn_dealer_on.gif"
dealer_off.src = "images/btn_dealer_off.gif"
friend_on.src = "images/btn_friend_on.gif"
friend_off.src = "images/btn_friend_off.gif"

function doBtnOver(img)
	{
	document["img_" + img].src = eval(img + "_on.src")
	ActiveBtn = img
	}
	
function doBtnOut(img)
	{
	document["img_" + img].src = eval(img + "_off.src")
	ActiveBtn = ""
	}
	
function displayError(msg, el)
	{
	msg = "You must " + msg + " before continuing. Please try again."
	alert(msg)
	if (el !=  null) el.focus()
	return false
	}

function DayName(DayVal)
	{
	switch (DayVal)
		{
		case 0:
			return "Sunday"
			break
		case 1:
			return "Monday"
			break
		case 2:
			return "Tuesday"
			break
		case 3:
			return "Wednesday"
			break
		case 4:
			return "Thursday"
			break
		case 5:
			return "Friday"
			break
		case 6:
			return "Saturday"
			break
		}
	}
	
function MonthName(MonthVal)
	{
	switch (MonthVal)
		{
		case 0:
			return "January"
			break
		case 1:
			return "February"
			break
		case 2:
			return "March"
			break
		case 3:
			return "April"
			break
		case 4:
			return "May"
			break
		case 5:
			return "June"
			break
		case 6:
			return "July"
			break
		case 7:
			return "August"
			break
		case 8:
			return "September"
			break
		case 9:
			return "October"
			break
		case 10:
			return "November"
			break
		case 11:
			return "December"
			break
		}
	}

function FormatTime(DateVal)
	{
	AP = "AM"
	Hr = DateVal.getHours()
	if (Hr >= 12) 
		{
		Hr -= 12
		AP = "PM"
		}
	if (Hr < 10) Hr = "0" + Hr
	Min = DateVal.getMinutes()
	if (Min < 10) Min = "0" + Min
	return Hr + ":" + Min + " " + AP
	}

function validEmail(val)
	{
	RE = /^[A-Z0-9\.\_\-\'\’]+@([A-Z0-9\.\-]+\.)+[A-Z0-9\.\-]{2,4}$/i
	return RE.test(val)
	}
	
function validInteger(val)
	{
	RE = /^\-?\d+$/
	return RE.test(val)
	}
	
function validNumber(val)
	{
	RE = /^(\d{1,3}\,?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.\d{1,2}?)$/
	return RE.test(val)
	}
	
function validZipCode(val)
	{
	RE = /^[0-9]{5}(\-[0-9]{4})?$/
	return RE.test(val)
	}
	
function validDate(el)
	{
	Val = new Date(el.value)
	if (isNaN(Val))
		return false
	else
		{
		if (Val.getFullYear() < 1950)
			Val.setFullYear(Val.getFullYear() + 100)
		el.value = (Val.getMonth() + 1) + "/" + Val.getDate() + "/" + Val.getFullYear()
		return true
		}
	}
	
function validYear(val)
	{
	Now = new Date()
	if (! validInteger(val))
		return false
	else if (val < 2004 || val > Now.getFullYear() + 1)
		return false
	else
		return true
	}
	
function Trim(Str)
	{
	Str = LeftTrim(Str)
	return RightTrim(Str)
	}

function LeftTrim(Str)
	{
	var i = 0
	for (i = 0; i < Str.length; i++)
		{
		if (Str.charAt(i) != " ")
			break
		}
	return Str.substring(i, Str.length)
	}
	
function RightTrim(Str)
	{
	var i = 0
	for (i = Str.length - 1; i >= 0; i--)
		{
		if (Str.charAt(i) != " ")
			break
		}
	return Str.substring(0, i + 1)
	}
	
function testLength(el, len)
	{
	val = el.value
	if (val.length > len)
		{
		msg = "Your input exceeds the " + len + " character limit for this field. "
			+ "Please adjust your input and try again."
		alert(msg)
		el.focus()
		return false
		}
	return true
	}

/*-------------------------------------------------
SHOW PROMPT

Shows a Prompt box containing the specified message
and returns the user's input. RetVal will either be
a string or a null (if Cancel was clicked).
-------------------------------------------------*/
function showPrompt(msg, deflt, maxLen)
	{
	retVal = prompt(msg, deflt)
	if (retVal == "")
		{
		mMsg = "You must enter a value and then click the OK button. To exit without "
			+ "entering a value, click the Cancel button."
		alert(mMsg)
		showPrompt(msg, deflt)
		}
	else if (retVal != null && retVal.length > maxLen)
		{
		tmpVal = retVal.substring(0, maxLen)
		mMsg = "The maximum length for this value is " + maxLen + " characters. Your "
			+ "input exceeds this limit. To automatically truncate your input to the "
			+ "proper length, i.e. \"" + tmpVal + "\", click OK. To return and shorten "
			+ "your input, click Cancel."
		if (confirm(mMsg))
			retVal = tmpVal
		else
			showPrompt(msg, retVal, maxLen)
		}
	return(retVal)
	}
	
var nWin = null

/*-------------------------------------------------
SHOW POP UP

This function generates a new pop-up window based
on the referenced arguments. If any pop-up window
is currently open, it closes that window and opens
the requested window.
-------------------------------------------------*/
function showPopUp(URL, Name, Height, Width, Top, Left, Status, Toolbar, Menubar, Location, Resizable, Scrollbars)
	{
	if (nWin == null)
		{
		nWin = window.open(URL, Name, "height=" + Height + ",width=" + Width 
			+ ",top=" + Top + ",left=" + Left + ",status=" + Status 
			+ ",toolbar=" + Toolbar + ",menubar=" + Menubar
			+ ",location=" + Location + ",resizable=" + Resizable + ",scrollbars=" + Scrollbars)
		if (nWin != null)
			nWin.opener = window
		}
	else
		{
		CloseNWin()
		showPopUp(URL, Name, Height, Width, Top, Left, Status, Toolbar, Menubar, Location, Resizable, Scrollbars)
		}	
	}
	
/*-------------------------------------------------
CENTER HORIZONTAL/VERTICAL

These functions return the Left and Top values,
respectively, for centering a pop-up window on the
current screen.
-------------------------------------------------*/
function CenterHorz(width)
	{
	return(window.screenLeft + ((document.body.offsetWidth - width) / 2))
	}
	
function CenterVert(height)
	{
	//25 is the apprx. size of the title bar which is not part of the pop-up height
	return(window.screenTop + ((document.body.offsetHeight - (height + 25)) / 2))
	}
	
function CloseNWin()
   {
   if (nWin != "" && nWin != null)
      {
      nWin.close()
      nWin = null
      }
   }
   
function CloseWindow(v)
	{	
		if (v=="Register")
		{
			opener.nWin = null
			window.close() 
		}
		else
		{
			parent.HideFrameDiv()
		}
	
	}
	
function showRegistration()
	{
	width = 500
	height = 550
	topVal = CenterVert(height)
	leftVal = CenterHorz(width)
	showPopUp("http://www.toyotashow.com/PopUps/Register.asp",
				 "Register",
				 height,
				 width,
				 topVal,
				 leftVal,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "yes")
	}

function showPrivacy()
	{
	width = 450
	height = 550
	leftVal = CenterHorz(width)
	topVal = CenterVert(height)
	showPopUp("http://www.toyotashow.com/popups/PrivacyStatement.asp",
				 "PrivacyStatement",
				 height,
				 width,
				 topVal,
				 leftVal,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "yes")
	}	
	
	
function showEventDetails(EventID)
	{
	width = 500
	height = 400
	topVal = CenterVert(height)
	leftVal = CenterHorz(width)
	showPopUp("http://www.toyotashow.com/PopUps/EventDetails.asp?WebEventID=" + EventID,
				 "Details",
				 height,
				 width,
				 topVal,
				 leftVal,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "yes")
	}
	function showEventNewsDetails(EventNewsID)
	{
	width = 500
	height = 400
	topVal = CenterVert(height)
	leftVal = CenterHorz(width)
	showPopUp("http://www.toyotashow.com/PopUps/NewsDetails.asp?WebEventNewsID=" + EventNewsID,
				 "Details",
				 height,
				 width,
				 topVal,
				 leftVal,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "yes")
	}
	
function showSnapshot(SnapshotID)
	{
	width = 500
	height = 550
	topVal = CenterVert(height)
	leftVal = CenterHorz(width)
	showPopUp("http://www.toyotashow.com/PopUps/Snapshot.asp?WebEventSnapshotID=" + SnapshotID,
				 "Snapshot",
				 height,
				 width,
				 topVal,
				 leftVal,
				 "no",
				 "no",
				 "no",
				 "no",
				 "no",
				 "no")
	}
	
function showLogin(EventID, RegistrantID)
	{
	if (RegistrantID > 0)
		document.location = "Snapshot.asp?WebEventID=" + EventID
	else
		{
		width = 450
		height = 350
		topVal = CenterVert(height)
		leftVal = CenterHorz(width)
		showPopUp("http://www.toyotashow.com/PopUps/Login.asp?WebEventID=" + EventID,
					 "Login",
					 height,
					 width,
					 topVal,
					 leftVal,
					 "no",
					 "no",
					 "no",
					 "no",
					 "no",
					 "yes")
		}
	}
	
function showRegMsg()
	{
	msg = "Be sure to register for the Toyota Show giveaway. For more information, click on the Register To Win! Link in the left menu.";
	alert(msg);
	}
	
var theList = null

function addItemToList(Value, Text)
	{
	Opt = document.createElement("OPTION")
	Opt.value = Value
	Opt.text = Text
	theList.add(Opt)
	theList.selectedIndex = theList.options.length - 1
	}
	
function showCalendar(DateBox)
	{
	window.dateField = DateBox
	calendar = window.open('http://www.toyotashow.com/calendar.htm', 'cal', 'WIDTH=200,HEIGHT=250')
	}

function DateAdd(Interval, Offset, DateVal)
	{
	tmpDate = new Date(DateVal)
	if (isNaN(tmpDate))
		{
		msg = "Type mismatch: GLOBAL.JS: DateAdd."
		alert(msg)
		return null
		}
	else
		{
		switch (Interval.toLowerCase())
			{
			case "y" || "yy" || "yyyy":
				tmpDate.setFullYear(tmpDate.getFullYear() + Offset)
				break
			case "m" || "mm":
				tmpDate.setMonth(tmpDate.getMonth() + Offset)
				break
			case "w" || "wk":
				tmpDate.setDay(tmpDate.getDay() + Offset)
				break
			case "d" || "dd":
				tmpDate.setDate(tmpDate.getDate() + Offset)
				break
			case "h" || "hh":
				tmpDate.setHours(tmpDate.getHours() + Offset)
				break
			case "n" || "mi":
				tmpDate.setMinutes(tmpDate.getMinutes() + Offset)
				break
			case "s" || "ss":
				tmpDate.setSeconds(tmpDate.getSeconds() + Offset)
				break
			default:
				msg = "Invalid Interval: GLOBAL.JS: DateAdd."
				alert(msg)
				return null
			}
		return tmpDate
		}
	}
	
function formatShortDate(DateVal)
	{
	tmpDate = new Date(DateVal)
	if (isNaN(tmpDate))
		{
		msg = "Type mismatch: GLOBAL.JS: formatShortDate."
		alert(msg)
		return null
		}
	else
		{
		MM = tmpDate.getMonth() + 1
		DD = tmpDate.getDate()
		YY = tmpDate.getFullYear()
		return MM + "/" + DD + "/" + YY
		}
	}

function doShopAt()
	{
	window.open('http://www.shopatgst.com/shopatgst/shopatgst.asp',null,'height=560,width=825,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes')
	}
	
function OpenWindow(URL)
	{
	window.open(URL, "", "width=800,height=500,menubar=yes,toolbar=yes,scrollbars=yes,status=yes,location=yes,resizable=yes,titlebar=yes")
	}