﻿// JScript File
var EF = {
	/* Short hand to return object in global */
	$_script: function () {
		return this.Global.ScriptHandler
	},
	$_util: function () {
		return this.Global.Utilities
	},
	/* -- Global */
	Global: {
		Utilities: {
			CookieManager: {
				/* Create cookie */
				Bake: function (name, value, days) {
					var date = new Date();
					days = days || 1
					document.cookie = name + "=" + value + "; Max-Age=" + (60 * 60 * 24 * days) + "; path=/";
				},
				/* Create session cookie */
				Session: function (name, value) {
					document.cookie = name + "=" + value + "; path=/";
				},
				Consume: function (name, key) {
					var arr = this._Check(name);
					var condition = undefined;
					if (arr) {
						arr = unescape(arr).split("&");
						for (var i = 0; i < arr.length; i++) {
							var t = arr[i].split("|");
							for (var g = 0; g < t.length; g++) {
								t[g] = t[g].split("=");
							}
							for (var counter = 0; counter < t.length; counter++) {
								if (unescape(t[counter][0]) == key) {
									condition = t[counter][1];
									break;
								}
							}
						}
						return condition;
					} else {
						return condition;
					}
				},
				/* Checks for key or key/value pair in cookie - hacked together for leadform*/
				Check: function (name, key, value) {
					var arr = this._Check(name);
					var condition = false;
					if (arr) {
						arr = unescape(arr).split("&");
						for (var i = 0; i < arr.length; i++) {
							var t = arr[i].split("|");
							for (var g = 0; g < t.length; g++) {
								t[g] = t[g].split("=");
							}
							for (var counter = 0; counter < t.length; counter++) {
								if (arguments.length == 2) {
									if (unescape(t[counter][0]) == key) {
										condition = true;
										break;
									}
								} else {
									if (unescape(t[counter][0]) == key & unescape(t[counter][1]) == value) {
										condition = true;
										break;
									}
								}
							}
						}
						return condition;
					} else {
						return condition;
					}
				},
				/* Helper - returns value of specified cookie */
				_Check: function (name) {
					var s = document.cookie.split(';');
					for (var i = 0, l = s.length; i < l; i++) {
						var c = s[i].toString(), f, r;
						f = c.substring(0, c.indexOf("="))
						r = c.substring(c.indexOf("=") + 1, c.length)
						while (f.charAt(0) == " ") f = f.substring(1, f.length)
						if (f == name) return r;
					}
				}
			},
			GetDimensions: function (Width_Height_or_Both) {
				Width_Height_or_Both = Width_Height_or_Both.toLowerCase()
				switch (Width_Height_or_Both) {
					case "width":
						return { "width": width() }
						break;
					case "height":
						return { "height": height() }
						break;
					case "both":
						return { "width": width(), "height": height() }
						break;
					// If nothing, just return both...   
					default:
						return { "width": width(), "height": height() }
						break;
						window.location
				}
				function height() {
					return Math.max(
            Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
            Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
            Math.max(document.body.clientHeight, document.documentElement.clientHeight)
          );
				}
				function width() {
					return Math.max(
            Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
            Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
            Math.max(document.body.clientWidth, document.documentElement.clientWidth)
          );
				}
			}
		}
	}
}
	/* -- Teachers 
	Teachers: {
	/* Start - Liveball Marketing 
	LiveBall: {
	Private: function() {
	var playing = new Boolean();
	return function setter(condition) {
	if (arguments.length == 0) return playing;
	playing = condition;
	if (playing == "true") {
	EF.Teachers.LiveBall.killTimer(EF.Teachers.LiveBall.Private._timer);
	return playing;
	} else if (playing == "false") {
	EF.Teachers.LiveBall.setTimer();
	return playing;
	}
	}
	},
	showModal: function() {
	/* Load ColorBox for pop-in -- Will eventually replace nryo and ThickBox 
	$.fn.colorbox({
	href: EF.Teachers.LiveBall.Private._liveball,
	iframe: true,
	overlayClose: false,
	innerWidth: EF.Teachers.LiveBall.Private._width,
	innerHeight: EF.Teachers.LiveBall.Private._height,
	opacity: 0.3,
	onLoad: function() {
	$("select").css("display","none");
	$("html").css("overflow-x", "hidden");
	var dimensions = EF.$_util().GetDimensions('both');
	$("#cboxOverlay").css({
	"height": dimensions['height'],
	"width": dimensions['width']
	})
	},
	onCleanup: function() {
	$("#cboxClose").css("display", "none")
	$("select").css("display","inline");
	$("html").css("overflow-x", "auto");              
	},
	onClosed: function() {
	/* Create EFLD cookie *
	EF.Global.Utilities.CookieManager.Session("EFLD", escape("Viewed=True"));
              
	/* Increment counter *
	var _count = parseInt(EF.Global.Utilities.CookieManager.Consume("EFFEDCK","Count"))+1;
	EF.Global.Utilities.CookieManager.Bake("EFFEDCK","Count="+_count,"180");
	}
	})
	},
	setTimer: function() {
	EF.Teachers.LiveBall.Private._timer = setTimeout('EF.Teachers.LiveBall.showModal()', EF.Teachers.LiveBall.Private._timeout);
	},
	killTimer: function(timer) {
	try {
	clearTimeout(timer)
	} catch (err) { }
	},
	Init: function(url, timeout, width, height, iframe) {
	/* Create counter cookie, if nec. 
	if(!EF.Global.Utilities.CookieManager.Check("EFFEDCK","Count")){
	EF.Global.Utilities.CookieManager.Bake("EFFEDCK","Count=0","180");
	}
        
	if (EF.Global.Utilities.CookieManager.Check("EFLD", "Viewed", "True") || EF.Global.Utilities.CookieManager.Check("EFFEDCK", "Count", "1")) return /*silently;

	EF.Teachers.LiveBall.Private._liveball = url;
	EF.Teachers.LiveBall.Private._timeout = timeout || 15000;
	EF.Teachers.LiveBall.Private._width = width || 400;
	EF.Teachers.LiveBall.Private._height = height || 660;
	this.setTimer()
	},
	FlashInit: function() {
	return EF.Teachers.LiveBall.Private._temp = new this.Private()
	}
	}
	}
	} */

$(document).ready(function () {
	/* Begin Variable Declaration */
	var thisSrc;
	var linkClicked = false;
	var whichLinkClicked;
	var cmRunOnce = false;


	/* Sets Image in Navigation */
	var currentPath = location.pathname;
	var pageIdValue = $("input[name*='PageID']").val();

	switch (pageIdValue) {
		case "GlobalRewards":
			$("a:contains('For Faculty')").addClass("selected tk-ff-din-web-condensed");
			break;
		case "BrowseOurTours":
			$("a:contains('Browse Tours')").addClass("selected tk-ff-din-web-condensed");
			break;
		case "AboutEF":
			$("a:contains('About Us')").addClass("selected tk-ff-din-web-condensed");
			break;
		case "ContactUs":
			$("a:contains('Contact Us')").addClass("selected tk-ff-din-web-condensed");
			break;
		case "GlobalRewardsLogin":
			$('#LoginBrickWrap').hide();
		default: break;
	};

	/* Events for Navigation */
	$(".headerWrapper .headerLinks ul.headerNav li a img").click(function () {
		if ($(this).parent().attr('rel') != "external") {
			linkClicked = true;
			whichLinkClicked = $(this).parent().attr('id');
			$(".headerWrapper").css('cursor', 'wait');
			$(".cstLegacy").css('cursor', 'wait');
		}
	});
	$(".headerWrapper .headerLinks ul.headerNav li a").hover(function () {
		thisSrc = $(this).children().attr('src');
		var onThisSrc = thisSrc.replace("_off", "_on");
		$(this).children().attr('src', onThisSrc);
	}, function () {
		if (linkClicked != true) {
			$(this).children().attr('src', thisSrc);
		} else {
			if (whichLinkClicked != $(this).attr('id')) $(this).children().attr('src', thisSrc);
		}
	});

	/* Double Arrow - apply hover effects */
	$(".aboutEFCallOuts a, .headerText a, .QuoteDetailLinks a").hover(function () {
		$(this).next().removeClass("doubleArrowForLinks");
		$(this).next().css('font-weight', 'normal').css('color', '#1BA0DA')
	}, function () {
		$(this).next().addClass("doubleArrowForLinks");
	});
	// Mouse over effect for images.
	$(".bottomCallOutRowButtons img").click(function () {
		return false;
	})

	// Adobe link
	$(".DownloadAdobeImg img").bind("click", function () {
		var adobeLink = "http://www.adobe.com/products/reader/"
		window.open(adobeLink);
		$(this).blur();
		return false;
	});
	$(".DownloadAdobeImg img").css('cursor', 'pointer');


	/* Catch disabled arrows and NOT show pointer */

	$("input[src$='disabled.gif']").hover(function () {
		$(this).css('cursor', 'move');
	}, function () {
		$(this).css('cursor', 'default');

	});



	/* Hover Fn */
	var imageToSwap;
	var imageToSwapDown;
	$(".hoverFn").bind("mousedown", function () {
		imageToSwapDown = $(this).attr('src');
		e = imageToSwapDown;
		e = e.split("_over.gif");
		e[0] += "_down.gif";
		$(this).attr('src', e[0]);
		return false;
	});
	$(".hoverFn").bind("mouseup", function () {
		$(this).attr('src', imageToSwapDown);
		return false;
	});
	$(".hoverFn").hover(function () {
		imageToSwap = $(this).attr('src');
		e = $(this).attr('src');
		e = e.split(".gif");
		e[0] += "_over.gif";
		$(this).attr('src', e[0]);
	}, function () {
		$(this).attr('src', imageToSwap);
	});

	/* Rollover for Start Planning Now */
	$("img[name='startPlanningNowRollOver']").hover(function () {
		imageToSwap = $(this).attr('src');
		e = $(this).attr('src');
		e = e.split(".jpg");
		e[0] += "_roll.jpg";
		$(this).attr('src', e[0]);
	}, function () {
		$(this).attr('src', imageToSwap);
	});



	$(".middleCallOutRowRightText a img").hover(function () {
		imageToSwap = $(this).attr('src');
		e = $(this).attr('src');
		e = e.split(".jpg");
		e[0] += "_roll.jpg";
		$(this).attr('src', e[0]);
	}, function () {
		$(this).attr('src', imageToSwap);
	});

	// Adjust width for Header anchor area (on browse.aspx)
	$(".tourItineraryText span.header a").each(function () {
		var el = $(this).text();
		el = el.length * 9;
		if (el < 600) {
			$(this).css('width', el);
		} else {
			$(this).css('width', '600px');
		};
	});


	// Questions/Comments form (Characters remaining)
	var priorComment;
	var thisScroll;
	$(".questionsAndCommentsTextArea").keyup(function (f) {
		var z = parseInt($(".totalNumb").text())
		var e = $(this).val();
		e = parseInt(e.length)
		var charRemaining = (4000 - e);
		if (f.keyCode == 8) {
			if (z >= 4000) {
				$(".totalNumb").text(4000)
			} else {
				$(".totalNumb").text(z += 1)
			}
		}
		$(".totalNumb").text(charRemaining)
	});
	$(".questionsAndCommentsTextArea").keypress(function (f) {
		var e = $(this).val();
		e = parseInt(e.length + 1)
		var charRemaining = (4000 - e);
		if (charRemaining <= -1) {
			$(".totalNumb").css('color', 'red');
			$(".totalNumb").text("0");
			$(this).val(priorComment);
		} else {
			$(".totalNumb").css('color', '#666');
			$(".totalNumb").text(charRemaining)
		}
		priorComment = $(this).val();
	});

	// Fix width
//	$("#emailUsForm p select").each(function () {
//		$(this).css('width', '198px')
//	});
//	if (($.support.cssFloat != true) || ($.browser.opera)) {
//		$("#emailUsForm p select").css("width", "181px")
//		$("p.zipcode input:eq(1)").css('width', '74px');
//		$("p.phone input:eq(2)").css('width', '63px');
//	}
//	// Catch links that are required to open in a new window
	$("a[rel='external']").bind("click", function () {
		window.open($(this).attr('href'));
		$(this).blur();
		return false;
	});
	// Catches links that use an image (that opens in a new window)
	$("a[rel='external'] img").bind("click", function () {
		window.open($(this).parent().attr('href'));
		$(this).blur();
		return false;
	});

	// Disabled Inputs should not hover
	$(".browseSortByRegionNav input[src$='disabled.gif']").each(function () {
		$(this).attr("style", "cursor:default");
	});


	// Fix Footer Navigation
	//$(".footerWrapper p span:first").each(function () { $(this).css('margin', '0px 5px 0px 0px'); });

	// Fix PNG issues
	//$(document).pngFix();


	// Pop up windows & Lightbox

	// Catch tab change
	$("a[rel='lightWindow']").live("click", function () {
		var link = $(this).attr('href');
		switch (link) {
			case "tourFeesContainer":
				$("img[src$='TourFees.gif']").removeClass("nyroSwitcherOff").addClass("nyroSwitcher")
				$("img[src$='Insurance.gif']").removeClass("nyroSwitcher").addClass("nyroSwitcherOff")
				$("#tourFeesContainer").show();
				$("#insuranceContainer").hide();
				$("a[href='insuranceContainer']").removeClass("nyroLinkOn").addClass("nyroLinkOff");
				$("a[href='tourFeesContainer']").removeClass("nyroLinkOff").addClass("nyroLinkOn").blur();
				break;
			case "insuranceContainer":
				$("img[src$='TourFees.gif']").removeClass("nyroSwitcher").addClass("nyroSwitcherOff")
				$("img[src$='Insurance.gif']").removeClass("nyroSwitcherOff").addClass("nyroSwitcher")
				$("#tourFeesContainer").hide();
				$("#insuranceContainer").show();
				$("a[href='tourFeesContainer']").removeClass("nyroLinkOn").addClass("nyroLinkOff");
				$("a[href='insuranceContainer']").removeClass("nyroLinkOff").addClass("nyroLinkOn").blur();
				break;
			default: break;
		}
		return false;
	});
	$("#menuContainer a").live("mouseover", function () {
		$(this).css('text-decoration', 'underline');
	});
	$("#menuContainer a").live("mouseout", function () {
		$(this).css('text-decoration', 'none');
	});

	// Mouseover effect for Explore
	$(".middleCallOutRowRightText a").hover(function () {
		$(this).parent().parent().css("background-position", "0px 202px");
	}, function () {
		$(this).parent().parent().css("background-position", "0px 0px");
	});

	// Define your pop up settings
	var popWindows = {
		"QuoteDetail": [{
			"focus": "true", "name": "printWin", "directories": "yes", "height": "620", "left": "10", "location": "no",
			"menubar": "no", "resizable": "yes", "scrollbars": "no", "status": "yes", "titlebar": "no", "toolbar": "no",
			"top": "10", "width": "670"
		}]
	};
	// Function to catch those popups
	$("a[rel='popup']").bind("click", function () {
		var href = $(this).attr("href");
		var winname = $(this).attr("name");
		// Initial our options
		var popFocus = eval("popWindows." + winname + "[0].focus");
		var popName = eval("popWindows." + winname + "[0].name");
		var popChannelMode = eval("popWindows." + winname + "[0].channelmode");
		var popDirectories = eval("popWindows." + winname + "[0].directories");
		var popFullscreen = eval("popWindows." + winname + "[0].fullscreen");
		var popHeight = eval("popWindows." + winname + "[0].height");
		var popLeft = eval("popWindows." + winname + "[0].left");
		var popLocation = eval("popWindows." + winname + "[0].location");
		var popMenubar = eval("popWindows." + winname + "[0].menubar");
		var popResizable = eval("popWindows." + winname + "[0].resizable");
		var popScrollbars = eval("popWindows." + winname + "[0].scrollbars");
		var popStatus = eval("popWindows." + winname + "[0].status");
		var popTitlebar = eval("popWindows." + winname + "[0].titlebar");
		var popToolbar = eval("popWindows." + winname + "[0].toolbar");
		var popTop = eval("popWindows." + winname + "[0].top");
		var popWidth = eval("popWindows." + winname + "[0].width");
		window.open(href, popName, "directories=" + popDirectories + ",height=" + popHeight + ",left=" + popLeft + ",location=" + popLocation + ",menubar=" + popMenubar + ",resizable=" + popResizable + ",scrollbars=" + popScrollbars + ",status=" + popStatus + ",titlebar=" + popTitlebar + ",toolbar=" + popToolbar + ",top=" + popTop + ",width=" + popWidth + "");
		return false;
	});

	/*GR Redeem Buttons Equal Div height */
	var numberofdivs = $(".GiftIndvContainer").length;
	var giftdiv = $(".GiftIndvContainer")
	var giftdivonetwo = $(".GiftOneTwoPrice")


	for (count = 0; count <= numberofdivs; count = count + 3) {

		var tallest = Math.max($(".GiftIndvContainer").eq(count).height(),
		giftdiv.eq(count + 1).height(), giftdiv.eq(count + 2).height());

		giftdiv.eq(count).height(tallest);
		giftdiv.eq(count + 1).height(tallest);
		giftdiv.eq(count + 2).height(tallest);


		var tallest2 = Math.max($(".GiftOneTwoPrice").eq(count).height(),
		giftdivonetwo.eq(count + 1).height(), giftdivonetwo.eq(count + 2).height());

		giftdivonetwo.eq(count).height(tallest2);
		giftdivonetwo.eq(count + 1).height(tallest2);
		giftdivonetwo.eq(count + 2).height(tallest2);

	}

	/* Catching Contact Us Dropdown list changes */
	$(".leadingATourProfessionList").bind("change", function () {
		if ($(this).val() == 101583) {
			$("#leadingATourHiddenStudent").show()
			$("#leadingATourHiddenGrade").hide()
			$("#leadingATourHiddenGradeSubject").hide()
		} else if (($(this).val() == 101630) || ($(this).val() == 101608) || ($(this).val() == 101587) || ($(this).val() == 101622)) {
			$("#leadingATourHiddenStudent").hide()
			$("#leadingATourHiddenGrade").show()
			$("#leadingATourHiddenGradeSubject").show()
		} else {
			$("#leadingATourHiddenStudent").hide()
			$("#leadingATourHiddenGrade").hide()
			$("#leadingATourHiddenGradeSubject").hide()
		}
	})
});

    window.onload = function wininit(){
        $(".validatorFn").each(function() {
            var e = $(this).parent().offset();
            $(this).css('position', 'absolute').css('top', e.top).css('left', e.left);
        })
        // Position dropdown on resize
        $(window).resize(function() {
            $(".validatorFn").each(function() {
                var e = $(this).parent().offset();
                $(this).css('position', 'absolute').css('top', e.top).css('left', e.left);
            })
        });
    };

    // iItems
    function GlossaryTooltip(divID, spanID, vis, shortDesc) {
    var docElement;
    docElement = document.getElementById(divID);

    if (docElement) {
        docElement.style.display = vis ? "inline" : "none";
        docElement.style.visibility = vis ? "visible" : "hidden";
    }

    if (shortDesc != 'Nothing') document.getElementById(spanID).innerHTML = shortDesc;
    return false;
   };

   //FAQ popup in GR

   function OpenPopup(url, width, height, left, top, resizeable, scrollbar, status) {
   	var mywindow = window.open(url, "FAQ", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",resizable=" + resizeable + ",scrollbars=" + scrollbar + ",status=" + status + "");
   	mywindow.focus();
   }  

    // This is for Coremetric tagging in pages with multiple tags.
    function callCoremetrics(code) {
    
    
        var _code;
        
        // Verify we're not in QA or Staging
        if (($("input[name$='DevEnv']").val() != "QA") || (($("input[name$='DevEnv']").val() == "Prod") && (location.hostname != "192.168.193.126"))) {
        
        // If not in QA, check for HREF
            switch (code) {
                case "#moreTourFees":
                    cmCreatePageviewTag("CST-Browse-Tourfees", "30000", null, null);
                    break;
                default: break;
            }
        }
    };


    //printer friendly function
    function PrintPage() {
        window.print();
    }

