﻿var cellsWithAutoText = new Array();

function LoadItinerary(time, title, showType, isEducational, hasAnimalOpenHouse)
{
	var itryObj = document.getElementById("itineraryPanel");
	if(itryObj.style.display != "")
		ToggleDivScroller(itryObj);
	
	var i;
	for (i = 0; i < cellsWithAutoText.length; i++)
		document.getElementById(cellsWithAutoText[i]).innerHTML = '<textarea onblur="this.innerHTML = this.value;" />';
	cellsWithAutoText = new Array();
	
	time = new String(time).replace(/15/, '00').replace(/45/, '30');
	var timeNoColn = time.replace(':', '');
		
	var colObj = document.getElementById("rb_itry_Col_"+timeNoColn);
	cellsWithAutoText[cellsWithAutoText.length] = "rb_itry_Col_"+timeNoColn;
	var itryLabel = document.getElementById("itineraryLabel");

	itryLabel.innerHTML = "<span>"+title.toString().replace(/\s/g,'&nbsp;')+"</span>";
	var timeWSpace = (time.indexOf(':3')!=-1)?time.replace(':30',':30 '):time.replace(':00',':00 ');
	var dateTime = new Date('12/12/2001 '+timeWSpace);//+ time);
	
	var preshowTime = new Date(Number(dateTime) - ((60*1000)*60));
	var openHseTime = new Date(Number(dateTime) - ((60*1000)*90));
	
	preshowTime = FormatTimehmmtt(preshowTime);
	openHseTime = FormatTimehmmtt(openHseTime);    
	var preshowObj = document.getElementById("rb_itry_Col_"+preshowTime);
	var openHouseObj = document.getElementById("rb_itry_Col_"+openHseTime);
	
	if(preshowObj != null && isEducational != 'True')
	{
		preshowObj.innerHTML = "<span style=color:red;font-weight:bold>All-Access Pre-Show</span>"; // 90 prior
		cellsWithAutoText[cellsWithAutoText.length] = "rb_itry_Col_"+preshowTime;
	}
	if(openHouseObj != null && showType != "Go" && hasAnimalOpenHouse == 'True')
	{
		openHouseObj.innerHTML = "<span style=color:red;font-weight:bold>Animal Open House</span>"; // 60 mins prior
		cellsWithAutoText[cellsWithAutoText.length] = "rb_itry_Col_"+openHseTime;
	}
	 
	colObj.innerHTML = "<span style=color:red;font-weight:bold>SHOWTIME!!!</span>";
	 
	var firstTimeObj = document.getElementById("rb_itry_Col_800AM");
	firstTimeObj.focus();
}

function FormatTimehmmtt(time)
{	
	var t = new Date(time);
	var hour = t.getHours() % 12;
	if (hour == 0)
		hour = 12;
	var s = hour.toString();
	s += (t.getMinutes() == 0) ? "00" : t.getMinutes();
	s += (t.getHours() < 12) ? "AM" : "PM";
	return s;
}

function FindShowByZip(obj, action)
{
	action = (action == '' || action == null)?"findshow":action;
	if(obj.value == '' || obj.value == null || obj.value == "Enter zip code")
		alert('Please enter a zip code or select a state');
	else if(isZip(obj.value))
	{   
		window.location = "/TourSchedule.aspx?action="+action+"&zip="+obj.value;
	}
}

function CallOnClickWithEnterKey(obj, e, objClick)
{
	if(e.keyCode)
	{
		if(e.keyCode == 13)
		{
			if(obj.click())
				obj.click();
			else if(objClick.click())
				obj.click();
			return false;
		}
	} 
	else 
		return true;
}

function isZip(s) 
{
	// Check for correct zip code
	reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

	if (!reZip.test(s)) 
	{
		alert("Zip Code Is Not Valid");
		return false;
	}
	return true;
} 

if(document.getElementById("explore-the-shows") != null)
{
	promoHover = function() {
		var li = document.getElementById("explore-the-shows").getElementsByTagName("LI");
		for (var i=0; i<li.length; i++) {
			li[i].onmouseover=function() {
					this.className+=" promo-over";
			}
			li[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" promo-over\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", promoHover);
}
 
if(document.getElementById("find-tour-dd") != null)
{
	findTourDDHover = function() {
		var li = document.getElementById("find-tour-dd").getElementsByTagName("LI");
		for (var i=0; i<li.length; i++) {
				li[i].onmouseover=function() {
						this.className+=" over";
				}
				li[i].onmouseout=function() {
						this.className=this.className.replace(new RegExp(" over\\b"), "");
				}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", findTourDDHover);
}

/* BEGIN LOGO HOVER FUNCTION */
if(document.getElementById("logo") != null)
{
	logoHover = function() {
			var li = document.getElementById("logo").getElementsByTagName("A");
			for (var i=0; i<li.length; i++) {
					li[i].onmouseover=function() {
							this.className+=" over";
					}
					li[i].onmouseout=function() {
							this.className=this.className.replace(new RegExp(" over\\b"), "");
					}
			}
	}
	if (window.attachEvent) window.attachEvent("onload", logoHover);
}
/* END LOGO HOVER FUNCTION */

function ClearText(obj,text)
{
	if(obj.value != null)
		obj.value = (obj.value == '')?text:obj.value.replace(text,"");
}

function ToggleDiv(divObj){
	divObj.style.display = (divObj.style.display == "")? "none":"";
}

function ToggleDivScroller(divObj){
	var scrollDiv = document.getElementById('search-results-scroller');
	divObj.style.display = (divObj.style.display == "")? "none":"";
	if(scrollDiv.scrollUpdate) scrollDiv.scrollUpdate();
}

function OpenDrivingDirections(addressVal){
	document.getElementById('DivDrivingDirections').style.display = 'block';
	document.getElementById('fromAddress').focus();
	var toAddress = (typeof(addressVal) == 'object')?addressVal.value:addressVal;
	document.getElementById('toAddress').value = toAddress;
	
}

function CloseDrivingDirections() {
	document.getElementById('DivDrivingDirections').style.display = 'none';
	document.getElementById('fromAddress').value = '';
	
}

function GetDrivingDirections(objAdd) {

	var fromAdd = document.getElementById('fromAddress').value;
	var toAdd = document.getElementById('toAddress').value;
	window.location="http://maps.google.com/maps?hl=en&daddr="+toAdd+"&saddr="+fromAdd;
}

function printItinerary(base, htmlObj)
 {
	var frm = document.forms[1];
	frm.style.display="";
	var input = frm.hiddenTempInput;
	var links = document.getElementById('itineraryLinks');
	frm.action = base + "NonHtml/ShowItinerary.aspx";
	frm.target = "_blank";
	links.style.display = "none";    
	input.value = htmlObj.innerHTML;
	links.style.display = "";
	frm.submit();
 } 

function showWindow(url, windowName, features) 
{
	var newWin;
	newWin = window.open(url, windowName, features);
	newWin.focus();
}

function CheckEnterZip(code, textboxvalue)
{
	if (code == 13) 
	{ 
		document.location = '/TourSchedule.aspx?action=findshow&zip=' + textboxvalue; 
		return false; 
	}
	return true;
}
