﻿function getOffset(element)
{
	valueT = 0;
	valueL = 0;
	do
	{
		valueT += element.offsetTop  || 0;
		valueL += element.offsetLeft || 0;
		element = element.offsetParent;
	} while (element);
};

function getElementPosition(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ScrollToElement(element){

  var posX = 0;
  var posY = 0;
			  
  while(element != null){
	posX += element.offsetLeft;
	posY += element.offsetTop;
	element = element.offsetParent;
  }
									  
 window.scrollTo(posX, posY);

}


//Used to support rollover images
function rollImg(btnID, img) 
{
	if(document.images) 
	{
		
		var btn = document.getElementById(btnID);
		if(btn)
			btn.src = img;
	}
}

//Used to catch the enter key in a textbox and click a button
function fireDefaultButton(event, target) {

	if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) 
	{
		var defaultButton = document.getElementById(target);

		if (defaultButton && typeof (defaultButton.click) != "undefined") 
		{
			defaultButton.click();
			event.cancelBubble = true;
			if (event.stopPropagation)
				event.stopPropagation();
			return false;
		}
	} 
	
	return true;
}

//Used to open up new windows for descriptions
function newWin(contentURL, windowName)
{
	var inWindow = window.open(contentURL, windowName, 'scrollbars=yes,toolbar=no,location=yes,resizable=yes,width=640,height=480');
	inWindow.focus();
}

function showEDItem(element, order, orderlog, isMobile)
{
    var winFeat = "scrollbars=yes,toolbar=no,location=yes,resizable,width=480,height=480";
    var gotoURL = "PrintAtHome.aspx?GUID=" + order + "&ol=" + orderlog + "&";
    if (isMobile == true)
        gotoURL = "EDeliveryTicket.aspx?GUID=" + order + "&ol=" + orderlog + "&";

    try { myWindow.close(); } catch (e) { }
    myWindow = window.open(gotoURL, "EDelivery", winFeat);
    myWindow.focus();
}

function clickLinkById(ele)
{
	var linkElement = document.getElementById(ele);
	if(linkElement)
	{
		document.location.href=linkElement.href;
	}
}

function disableItem(itemID)
{
	var item = document.getElementById(itemID);
	alert(item);
	if(item)
		item.disabled = true;
}

function getYScroll() {

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
	return arrayPageSize;
}

function centerWin(url, windowName, width, height)
{
	var bw, bh, bl, bt;
	
	if (document.all)
	{
		alert('document.all');
		bw = document.body.clientWidth;
		bh = document.body.clientHeight;
		bl = window.screenLeft;
		bt = window.screenTop;
	}
	else if (document.layers)
	{
		bw = window.outerWidth;
		bh = window.outerHeight;
		bl = window.screenX;
		bt = window.screenY;
	}

	var leftPos = Math.floor((bw-width)/2) + bl;
	var topPos = Math.floor((bh-height)/2) + bt;
	
	//<!-- window.open(url, windowName, 'height=' + height + ', width=' + width + ', top=' + topPos + ', left=' + leftPos + 'resizable=no, toolbar=no, menubar=no, titlebar=no, alwaysraised=yes, dependent=yes'); -->
	
	//alert(bw + ' ' + bh + ' ' + bl + ' ' + bt + ' ' + leftPos + ' ' + topPos);
}

var inputPrompt;
var inputCover;
var waitSender;
function EnterPromotionCode(message, inputBlockID, focusID, sender, doingPost) {

	if (waitSender) {//alert('herea');
		waitSender = null;
		return true;
	}
	else {//alert('herec');
		inputPrompt = document.getElementById(inputBlockID);
		if (sender && inputPrompt) {
			var pageinfo = getPageSize();
			var pos = getElementPosition(sender);
			pos[0] = (pageinfo[2] / 2) - (inputPrompt.style.width.replace("px", "") / 2);
			pos[1] = (pageinfo[3] / 2) - (inputPrompt.style.height.replace("px", "") / 2) + getYScroll();
			inputPrompt.style.position = 'absolute';
			inputPrompt.style.display = 'block';
			inputPrompt.style.zIndex = '50';
			inputPrompt.style.posLeft = pos[0] + 'px';
			inputPrompt.style.posTop = pos[1] + 'px';
			inputPrompt.style.left = pos[0] + 'px';
			inputPrompt.style.top = pos[1] + 'px';

			inputCover = document.getElementById('inputCover');
			if (inputCover) {
				inputCover.style.width = pageinfo[0] + 'px';
				inputCover.style.height = pageinfo[1] + 'px';
				inputCover.style.display = 'block';
			}

			if (document.getElementById(focusID))
				document.getElementById(focusID).focus();
		}

		if (doingPost)
			waitSender = sender;
			
		return false;
	}
}

function submitInput() {
	if (inputPrompt) {
		if (inputCover)
			inputCover.style.display = 'none';
		inputPrompt.style.display = 'none';

		if (waitSender != null) {//alert('hereb');
			waitSender.click();
		}
		else {
			var url = '' + document.location;
			var txtBoxes = inputPrompt.getElementsByTagName('input');
			var inputVals = '';
			for (i = 0; txtBoxes[i]; i++) {
				if (txtBoxes[i].getAttribute('type') == 'text') {
					if (url.indexOf(txtBoxes[i].getAttribute('id') + '=') > -1) {
						var subTemp = url.substring(url.indexOf(txtBoxes[i].getAttribute('id') + '='));
						subTemp = subTemp.substring(0, subTemp.indexOf('&') + 1);
						url = url.replace(subTemp, '');
					}
					url = url + txtBoxes[i].getAttribute('id') + '=' + txtBoxes[i].value + '&';
				}
			}
			document.location.href = url;
		}
	}
}

function cancelInput() {
	if (inputPrompt) {
		inputPrompt.style.display = 'none';
		if (inputCover)
			inputCover.style.display = 'none';
	}
	waitSender = false;
}
function GetInput(message)
{
	return prompt(message, '');
}


try
{
	if(document.location.href.toLowerCase().indexOf('/payment.aspx') > 0)
		checkForFrame();
}
catch(e)
{
}

function checkForFrame()
{
	try
	{
		if (top.location != location)
		{
			top.location.href = document.location.href ;
		}
	}
	catch(ex){}
}

function toggleElementDisplay(eleID)
{
	try {
		var eleDisp = document.getElementById(eleID);
		if (eleDisp) {
			if (eleDisp.style.display == 'none' || eleDisp.style.display == '') {
				eleDisp.style.display = 'block';
			}
			else {
				eleDisp.style.display = 'none';
			}
		}
	}
	catch (e) { }
}

function ADAAttestation()
{
    return confirm(
        "Wheelchair, sign‐interpreted and captioned seating is reserved for the exclusive use of patrons with disabilities and their guests. The purchase or use of these seating locations by non‐disabled individuals is strictly prohibited and can result in relocation or ejection. By clicking OK you are attesting that, you or one of your guests require(s) the accessibility features of the seats that you have selected."
        );
}

String.prototype.atsTrim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }

var GiftNum = '';
var CardTrack1 = '';
var TempDeets = '';
var readingGift = false;
var readingCard = false;
function KeyCapture(e)
{
    var KeyCode = (window.event) ? event.keyCode : e.keyCode;

    var input = String.fromCharCode(KeyCode);

    if (input == "%")
    {
        CardTrack1 = '';
        GiftNum = '';
        readingCard = false;
        readingGift = false;
        TempDeets = input;
    }
    else if (TempDeets == "%" || TempDeets == "%R" || TempDeets == "%RT")
    {
        TempDeets += input;
    }

    if (readingCard)
    {
        if (input == "?")
        {
            CardTrack1 += input;
            readingCard = false;
            document.getElementById(payTypeDDClientID).value = "Swipe";
            PaymentChange(payTypeClientID, payTypeDDClientID);
            document.getElementById(hidCNID).value = CardTrack1;
            if(typeof(document.getElementById('ucimgbtnSearch_regularBtn')) != 'undefined')
                __doPostBack("ucimgbtnSearch$regularBtn", "");
            else if (typeof (document.getElementById('ucimgbtnSearch_imgButton')) != 'undefined')
                __doPostBack("ucimgbtnSearch$imgBtn", "");
        }
        else
        {
            CardTrack1 += input;
        }
    }

    if (readingGift)
    {
        if (input == "?")
        {
            readingGift = false;
            document.getElementById(gcNumID).value = GiftNum;
        }
        else
        {
            GiftNum += input;
        }
    }

    if (TempDeets == "%B")
    {
        CardTrack1 = TempDeets;
        TempDeets = '';
        readingCard = true;
    }
    else if (TempDeets == "%RTS" || TempDeets == "%Z")
    {
        TempDeets = '';
        readingGift = true;
    }
}

function textareaMaxLength(e, object, maxLen) 
{
    if (object.value.length > maxLen) 
        object.value = object.value.substring(0, maxLen);

    if (typeof textareaChanged == 'function') 
        textareaChanged(object, object.value.length, maxLen); 

    if (object.value.length == maxLen)
    {
        var keyCode = (window.event) ? event.keyCode : e.keyCode;

        if (keyCode > 46 && keyCode < 112 || keyCode > 123)
            return false;
    }
}

function GetQueryValue(qsName, inputQuery)
{
    try
    {
        var querystring = location.search.replace('?', '').split('&');

        if (inputQuery.length > 0)
        {
            querystring = inputQuery.replace('?', '').split('&');
        }

        for (idx = 0; idx < querystring.length; idx++)
        {
            var qNameVal = querystring[idx].split('=');
            if (qNameVal.length > 1)
            {
                if (qsName.toUpperCase() == qNameVal[0].toUpperCase())
                {
                    return qNameVal[1];
                }
            }
        }
        //alert(decodeURIComponent(querystring[0]));
    }
    catch (e)
    {
    }

    return '';
}

function RemoveQueryValue(qsName, inputQuery)
{
    try
    {
        var querystring = location.search.replace('?', '').split('&');

        if (inputQuery.length > 0)
        {
            querystring = inputQuery.replace('?', '').split('&');
        }

        var newQuery = '';
        for (idx = 0; idx < querystring.length; idx++)
        {
            var qNameVal = querystring[idx].split('=');
            if (qNameVal.length > 1)
            {
                if (qsName.toUpperCase() != qNameVal[0].toUpperCase())
                {
                    newQuery = newQuery + qNameVal[0] + '=' + qNameVal[1] + '&';
                }
            }
        }
        return (newQuery);
    }
    catch (e)
    {
    }

    return '';
}
