﻿function popWindow(url, name, intWidth, intHeight) {
	winParameters = "width=" + intWidth + ",height=" + intHeight;	
	popupWin = window.open(url, name, winParameters);
	popupWin.focus();
	return;
}
// *** start: popup window ***

// usage: popuplink(['js-only url',] this[, w[, h[, scroll[, extras]]]])
// basic usage: <a href="popup.html" target="_blank" onclick="return(popuplink(this));">new pop</a>
// advanced usage: <a href="popup_nojs.html" target="_blank" onclick="return(popuplink('popup_yesjs.html', this, 200, 100, false));">new pop</a>
// site-wide defaults:
popup_w = 400;
popup_h = 300;
popup_scroll = true;
popup_extras = 'location=0,statusbar=0,menubar=0';
function popuplink() {
	var undef, i=0, args=popuplink.arguments;
	var url = (typeof(args[i])=='string') ? args[i++] : args[i].getAttribute('href');
	var target = args[i++].getAttribute('target') || '_blank';
	var w = args[i++];
	var h = args[i++];
	var s = (args[i]===undef) ? popup_scroll : args[i++];
	var features = 'width=' + (w || popup_w)
				 + ',height=' + (h || popup_h)
				 + ',scrollbars=' + (s ? 'yes,' : 'no,')
				 + ',resizable=' + (s ? 'yes,' : 'no,')
				 + (args[i] || popup_extras);
	var win = window.open(url, target, features);
	win.focus();
	return false;
}

// *** end: popup window ***

function submitform()
{
	document.googleSearch.submit();
}

var DYO_Selector = Class.create({
    popupOpen: false,
    
    initialize: function() {
        this.prodDropDownList = $("_ctl0_MainContent_uxProductions");
        if (this.prodDropDownList) {
            this.allProdImgs = $$('div.design_your_own div#columnSecondary ul li img');
            for(var i=0; i<this.allProdImgs.length; i++) {
                Event.observe(this.allProdImgs[i].parentNode, 'click', this.showDetailPopup.bindAsEventListener(this));
                var closeLink = this.allProdImgs[i].parentNode.next().firstDescendant();
                Event.observe(closeLink, 'click', this.hideDetailPopup.bindAsEventListener(this));
            }
            this.indicateSelectedProds();
            Event.observe(this.prodDropDownList, 'change', this.indicateSelectedProds.bindAsEventListener(this));
        } else {
            return;
        }
    },
    indicateSelectedProds: function(event) {
         var prodFilterType = this.prodDropDownList.value
         this.allProdImgs.each(function(img) {
            if(prodFilterType == 'ViewAll' || img.hasClassName(prodFilterType)) img.parentNode.className = 'selected';
            else img.parentNode.className = '';
         });
    },
    showDetailPopup: function(event) {
        var element = Event.element(event);
        var posY = element.cumulativeOffset()[1];
        
        if (!this.popupOpen) {
            element.parentNode.next().style.display = 'block';
            // If the browser is IE6, the popup is absolutely positioned so we need to move it next to the imagelink that was clicked
            if (isIE6) element.parentNode.next().style.top = posY+30+'px';
            this.popupOpen = true;
        }
        event.stop();
    },
    hideDetailPopup: function(event) {
        var element = Event.element(event);
        element.parentNode.style.display = 'none';
        this.popupOpen = false;
        event.stop();
    }
});

function detectBrowser() {
    isIE6 = false
    /*@cc_on
        /*@if (@_jscript_version < 5.7)
            isIE6 = true;
        /*@end
    @*/
}

var TabSwitcher = Class.create({
	initialize: function(aTabs, aContents, aOnTab) {
		this.tabs = aTabs;
		this.contents = aContents;
		this.ontab = aOnTab;
		
		// Loop through each and attach a click handler
		for(var i=0; i<this.tabs.length; i++) {
			Event.observe(this.tabs[i], 'click', this.__Click.bindAsEventListener(this));
		}
		// Show the first content item
		if (this.ontab == undefined ) {
			this.show(0);
			$(this.tabs[0].parentNode).addClassName("on"); // turn on first li by default when page loads
		} else {
			this.show(this.ontab);
			$(this.tabs[this.ontab].parentNode).addClassName("on"); // turn on selected li when page loads
		}
	},
	/**
	 * Show a specific content item
	 */
	show: function(iWhich) {
		for (var i=0; i<this.contents.length; i++) {
			if (i == iWhich) {					    
				this.contents[i].style.position = 'static';
				if (this.elementLi) {                          // if an li has been clicked
					this.hideClassName();                      // turn of all other li's first
					this.elementLi.addClassName("on");	       // then turn on specific li					   
				}
			} else {
				this.contents[i].style.position = 'absolute';
				this.contents[i].style.top = '-9001px';
			}
		}
	},
	
	hideClassName: function() {
		var allLi = this.tabs;
		for (var i=0; i<allLi.length; i++) {
			allLi[i].parentNode.removeClassName("on");
		}
	},
	
	/**
	 * Deal with a clicked link
	 */
	__Click: function(e) {
		var e = e || window.event;
		Event.stop(e);
		var element = Event.element(e);
		this.elementLi = Event.findElement(e, "LI");    // storing li relative to event
		for (var i=0; i<this.tabs.length; i++) {
			if (this.tabs[i] == element) {
				this.show(i);											
				break;
			}
		}
	}
});

var ItemHider = Class.create({
    initialize: function(aItemName) {
		this.itemName = aItemName;
		$(this.itemName).style.display = "none";
    }
});



Event.observe(window, 'load', function() {
    detectBrowser();
    var dyo_selector = new DYO_Selector();
});
    
	

// ajax popup in performance.aspx
var perfPopup = {
  init: function(exchButton, donButton){
//    if(!exchButton.reduce() || !donButton.reduce()){return;}
    this.exchButton = exchButton;
    this.donButton = donButton;
    perfPopup.exchDonClose();
      
      if(this.donButton != null) {
        for(var i=0; i < this.donButton.length; i++) {
          this.donButton[i].observe("click", function(e) {
              Event.stop(e);
              var topOfDoc = this.offsetTop;
              var leftOfDoc = this.offsetLeft;
              $("donExchaWrapperFly").setStyle({
                top: topOfDoc + -30 + "px",
                left: leftOfDoc + 100 + "px"
              });
              perfPopup.callExchDonAjax(this, "donation");
          })
         
         }
       }
       
       if(this.exchButton != null) {
         for(var i=0; i < this.exchButton.length; i++) {
          this.exchButton[i].observe("click", function(e) {
              Event.stop(e);
              var topOfDoc = this.offsetTop;
              var leftOfDoc = this.offsetLeft;
              $("donExchaWrapperFly").setStyle({
                top: topOfDoc + -30 + "px",
                left: leftOfDoc + 100 + "px"
              });
              perfPopup.callExchDonAjax(this, "exchange");
          })
         
         }
       }
    
    // attach events and get dom references needed
  
  },
   
   callExchDonAjax: function(el, type) {
        $("exchDonflyOutContent").innerHTML = '<img src="/_images/site/ajax-loading-whiteBG.gif" />';
        var perfNo = el.up('li').className; 
        new Ajax.Request('./exchangedonatepopup.aspx?perfno=' + perfNo + '&type=' + type, {
        method: 'get',
        onSuccess: function(response) {
           var donExchText = response.responseText;
           $("exchDonflyOutContent").innerHTML = donExchText;
		   perfPopup.exchDonSelectAll();
		   if (type == "exchange") {
		   	perfPopup.exchangeTicketsEvent();
		   } else if (type == "donation") {
		   	perfPopup.donationTicketsEvent();
		   } else {
		   	return;
		   }
      },
       onFailure: function() { console.log("I'm sorry to say that there is a failure somewhere with the function callExchDonAjax");}
      });

   },
   
	exchDonClose: function() {
	 	$("donExchaFlyClose").observe("click", function() {
        	this.up(1).setStyle({
           	 left: -99999 + 'px'
        	});
        });
	},
	
	exchDonSelectAll: function() {
		$("exchDonSeatsEvent").observe("click", function(){
			var seatInputs = $('exchDonSeats').select("input");
			 for(var l=0; l < seatInputs.length; l++) {
			    seatInputs[l].checked=true;
			 }
		});
	},
	
	exchangeTicketsEvent: function() {
		$('uxExchange').observe("click", function(e) {
			Event.stop(e);
			var seatAttributes = "";
			var selectedSeats = $("uxTickets").select("input:checked");
			for(var k=0; k < selectedSeats.length; k++) {
				seatAttributes += selectedSeats[k].id + ",";
				var seatAttrLength = seatAttributes.length;
				var finalSeatQS = seatAttributes.slice(0, seatAttrLength-1);
				var perfNo = $("uxperfNo").value; 
			}
    		window.location.href="/account/patroncenter/exchangedonatehandler.ashx?type=exchange&tickets=" + finalSeatQS + "&perfNo=" + perfNo;
		})
	},
		
	donationTicketsEvent: function() {
		$('uxDonate').observe("click", function(e) {
			Event.stop(e);
			var seatAttributes = "";
			var selectedSeats = $("uxTickets").select("input:checked");
			for(var k=0; k < selectedSeats.length; k++) {
				seatAttributes += selectedSeats[k].id + ",";
				var seatAttrLength = seatAttributes.length;
				var finalSeatQS = seatAttributes.slice(0, seatAttrLength-1);
				var orderNo = $("uxOrderNo").value; 
			}
			window.location.href="/account/patroncenter/exchangedonatehandler.ashx?type=donation&tickets=" + finalSeatQS + "&orderNo=" + orderNo;
		})
	}
   
} 

Event.observe(window, "load", function() {
if ($$(".exchButton").reduce() && $$(".donButton").reduce()) {
    perfPopup.init( $$(".exchButton"), $$(".donButton"));
    } 
    
    else if (!($$(".exchButton").reduce()) && $$(".donButton").reduce()) {
    perfPopup.init( null, $$(".donButton"));
    } 
    
    else if ($$(".exchButton").reduce() && !($$(".donButton").reduce())) {
    perfPopup.init( $$(".exchButton"), null);
    } 
    
    else if (!($$(".exchButton").reduce()) && !($$(".donButton").reduce())) {return;}
});