// hide and show divs the YUI way!
function visible(id) 
{
	div = document.getElementById(id);
	if (div) {
		if (YAHOO.util.Dom.hasClass(div,'hidden')) {
			YAHOO.util.Dom.removeClass(div,'hidden')
		}else { 
			YAHOO.util.Dom.addClass(div,'visible')
		}
	}
}

function hidden(id)
{
	div = document.getElementById(id);
	if (div) {
		if (YAHOO.util.Dom.hasClass(div,'visible')) {
			YAHOO.util.Dom.removeClass(div,'visible')
		}else { 
			YAHOO.util.Dom.addClass(div,'hidden')
		}
	}
}

function toggle() {
	 if (document.getElementById("postal-address-opt-in").checked == false) {
	  document.getElementById("postal-address-opt-out").style.display = "block";
	 } else {
	  document.getElementById("postal-address-opt-out").style.display = "none";
	 }
}

function toggleVis(id) 
{
	div = document.getElementById(id);
	if (div) {
		if (YAHOO.util.Dom.hasClass(div,'hidden')) {
			YAHOO.util.Dom.removeClass(div,'hidden')
		} else { 
			YAHOO.util.Dom.addClass(div,'hidden')
		}
	}
}

function buttonToggle(evt) {
	obj = evt.target ? evt.target : evt.srcElement;

	strLayer = obj.id.replace(/Button$/,'') + "HiddenLayer";
	toggleVis(strLayer);
}

function bandwidthToggle() {
	var hasProductInstall = DetectFlashVer(6, 0, 65);
	if (!hasProductInstall) {
		// need to get the proper language
		strLang = window.location.pathname.replace('/disneyparks/', '');
		strLang = strLang.slice(0, strLang.indexOf('/'));
		if (strLang == 'es_US') {
			input_box = confirm("Usted debe instalar el Destello para ver nuestro sitio alto de anchura de banda.");
		} else {
			input_box = confirm("You must install Flash to view our high bandwidth site.");
		}
		if (input_box) {
			return true;	
		} else {
			return false;	
		}
		
	}
}

// must hide quick quote layer because the drop downs show through the login panel
function qqToggle() {
	toggleVis('qq');
}


function loginHide() {
	hidden('loginHiddenLayer');
}

function passwordRecoveryHide() {
	hidden('passwordRecoveryHiddenLayer');
}

function signUpHide() {
	hidden('signupHiddenLayer');
}

function loginToggle(){
	toggleVis('loginHiddenLayer');
}

WDPRO_LOADER.require("event");
WDPRO_LOADER.require("dom");
WDPRO_LOADER.addCallback(
	function() {
		YAHOO.util.Event.addListener("loginButton", "click", buttonToggle); 
		YAHOO.util.Event.addListener("loginButton", "click", passwordRecoveryHide); 
		YAHOO.util.Event.addListener("loginButton", "click", signUpHide); 
		YAHOO.util.Event.addListener("loginButton", "click", qqToggle); 
		YAHOO.util.Event.addListener("loginButton2", "click", loginToggle); 
		YAHOO.util.Event.addListener("loginButton2", "click", passwordRecoveryHide); 
		YAHOO.util.Event.addListener("loginButton2", "click", signUpHide);
		YAHOO.util.Event.addListener("signupButton", "click", buttonToggle);
		YAHOO.util.Event.addListener("signupButton", "click", passwordRecoveryHide);
		YAHOO.util.Event.addListener("signupButton", "click", loginHide);
		YAHOO.util.Event.addListener("bandwidthLink", "click", bandwidthToggle);
	}
);

function surveyLauncher(){
	if(window.launchSurveyWindow){
		launchSurveyWindow();
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; domain=go.com; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function openLetterHeadWindow(){
	popup=window.open('http://disneyparks.disney.go.com/disneyparks/en_US/index?name=LetterheadAppPage','new','width=500,height=645,toolbar=no,scrollbars=no,menubar=no,status=false,location=no,resizable=no,top=150,left=150');
}

function popupProfiler(url){
var win = window.open(url,'new','width=800,height=600,toolbar=false,scrollbars=no,menubar=no,status=false,location=no,resizable=no,top=180,left=180');
	if (window.focus) {
		win.focus();
		}
}

WDPRO_LOADER.addCallback(makeLinks);

function makeLinks(){
if (document.getElementById("contentHolder")){
		var contentHolder	= document.getElementById("contentHolder");
		var links = contentHolder.getElementsByTagName("a");
		for (i=0; i< links.length; i++){
			var thisLink = links.item(i);
			if (thisLink.className == "navToggle"){
					thisLink.onclick = function(){
					var idNum = parseInt(this.id.replace(/[a-z]/gi,''));
					var textBoxes = contentHolder.getElementsByTagName("dd");
					var thisText = textBoxes.item(idNum);
					for (j=0; j< textBoxes.length; j++){
						var currentText	= textBoxes.item(j);
						if(currentText.getAttribute("id") == thisText.getAttribute("id")) {
							currentText.className = "visible";
						} else {
							currentText.className = "hidden";
						}
					}
				}
			}
		}
	} else {
		return false;
	}
}


WDPRO_LOADER.addCallback(closeWindow);

function closeWindow(){
	if ( !document.getElementsByTagName ) return false;
	var closeLinks = document.getElementsByTagName("a");
	for (var i = 0; i < closeLinks.length; i++ ) {
		if ( closeLinks[i].className.match("closeWindow") ) {
			closeLinks[i].onclick = function () {
				window.close();
				return false;
			}
		}
	
	}
}


function wopenSendFriend() {
	w = 970;
	h = 700;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open( 'http://disneyparks.disney.go.com/disneyparks/en_US/sendtofriend/sendToFriendLoginGate',
		'popup',
		'width=' + w + ', height=' + h + ', ' +
		'left=' + wleft + ', top=' + wtop + ', ' +
		'location=no, menubar=no, ' +
		'status=no, toolbar=no, scrollbars=yes, resizable=yes' );
	win.resizeTo(w, h);			// if width and height are ignored
	win.moveTo(wleft, wtop);	// if left and top are ignored
	win.focus();
}

function createPopupAndCenter(strLocation, strWindowName, intWidth, intHeight, strResizable, strScrollbars, strStatus, strToolbar, strLocationBar, strMenuBar){
	var strParams = "";
	var strDelimiter = "";
	xPosition = (screen.width - intWidth ) / 2;
	yPosition = (screen.height - intHeight ) / 2;
	// build param list
	
	// popup width param
	if(intWidth != null && intWidth != ""){
		strParams = strParams + "width=" + intWidth;
	}
	
	// popup height param
	if(intHeight != null && intHeight != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "height=" + intHeight;
	}
	
	// popup top (y-position) param
	if(yPosition != null && yPosition != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "top=" + yPosition;
	}
	
	// popup left (x-position) param
	if(xPosition != null && xPosition != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "left=" + xPosition;
	}
	
	// popup resizable param
	if(strResizable != null && strResizable != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "resizable=" + strResizable;
	}
	
	// popup scrollbars param
	if(strScrollbars != null && strScrollbars != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "scrollbars=" + strScrollbars;
	}
	
	// popup status param
	if(strStatus != null && strStatus != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "status=" + strStatus;
	}
	
	// popup toolbar param
	if(strToolbar != null && strToolbar != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "toolbar=" + strToolbar;
	}
	
	// popup location bar param
	if(strLocationBar!= null && strLocationBar != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "location=" + strLocationBar;
	}
	
	// popup menu bar param
	if(strMenuBar != null && strMenuBar != ""){
		if(strParams.length > 0){
			strDelimiter = ", ";
		}else{
			strDelimiter = "";
		}
		strParams = strParams + strDelimiter + "menubar=" + strMenuBar;
	}
	
	var objPopup = window.open(strLocation, strWindowName, strParams);
	
	if ((document.window != null) && (!objPopup.opener)){
		objPopup.opener = document.window;
	}
}

WDPRO_LOADER.require("connection");

DisneyParks = {
		
	/* Static Properties */
	contentData: null, 
	flashVersionRequired: 8, 
	hbxData: null,
	hbxMlcFilter: new RegExp('hbx.mlc=[^&]*'), 
	hbxPageNameFilter: new RegExp('hbx.pn=[^&]*'),
	nameFilter: new RegExp('name=[^&]*'),  
	videoFilter: new RegExp('video=[^&]*'),
	rootFilter: new RegExp('cRoot=[^&]*'),
			
	//adding function for video Ajax call 
	getVideo: function(strLink) {
		if ( DisneyParks.VideoFeed && 
			( window.location.toString().indexOf('Printable') != -1 && strLink.indexOf('Printable') != -1 ) ||
			( window.location.toString().indexOf('Printable') == -1 && strLink.indexOf('Printable') == -1 ) ) {
			var strPageName = strLink.match(this.nameFilter).toString().replace('name=', '');
			var strVideoName = strLink.match(this.videoFilter).toString().replace('video=', '');
			var strRootName = strLink.match(this.rootFilter).toString().replace('cRoot=', '');

			var VideoObject = {
				//We got a good response
				handleSuccess:function(o){
					//Load the Video
					var objVideoPlayerContainer = document.getElementById('videoPlayerContainer');
					if ( objVideoPlayerContainer ) {
						objVideoPlayerContainer.innerHTML  = o.responseText.replace(/writeContent\(\'/g, '</script>').replace(/\'\)\;\<\/script\>/g, '');
					}
					//Register the Hitbox Call
					var strHbxName = hbx.pn;
					var strHbxMlc = hbx.mlc;
					if(strLink.match(DisneyParks.hbxPageNameFilter)){
						strHbxName = strLink.match(DisneyParks.hbxPageNameFilter).toString().replace('hbx.pn=', '');
					}
					if(strLink.match(DisneyParks.hbxMlcFilter)){
						strHbxMlc = strLink.match(DisneyParks.hbxMlcFilter).toString().replace('hbx.mlc=', '');
					}
					_hbPageView(strHbxName, strHbxMlc);

				},
				// The Call failed
				handleFailure:function(o){
				},
				// This is the call we'll make
				startRequest:function() {
					YAHOO.util.Connect.asyncRequest('GET',DisneyParks.VideoFeed + '?name=' + strPageName + '&video=' + strVideoName + '&cRoot=' + strRootName, callback, null);
				}
			};
			
			var callback = { 
			    success:VideoObject.handleSuccess, 
			    failure:VideoObject.handleFailure, 
			    scope: VideoObject 
			};
			
			VideoObject.startRequest(); 
			
		} 
		else {
			window.location = strLink;
		}
	}
	
};



function writeContent(strContent) {
	document.write(strContent);
}

//**********************************************************************
// Function to alert users before redirecting to another site/locale
//**********************************************************************
popup = window.self;
function confirmRedirect(url, text, popupProps) {
	var bAnswer = confirm(text);
	if (bAnswer) {
		// remove width and height values, if null
		popupProps = popupProps.replace("width=null,","");
		popupProps = popupProps.replace("height=null,","");
		popup = window.open(url,'popup',popupProps);
		
	}
}