﻿var Error_Opening_Placeholder = "<div class=\"error\">";
var Error_Closing_Placeholder = "</div>";
var notification_visible = false;
var acct_info;
var is_cart_page = false;
var in_submit_order_process = false;
var acct_contact_choices = null;
var SubsFixedSeriesOrder = false;
var Phones = [];

var sectionTimers = [];
sectionInfo = function()
{
	this.closetimer = null;
	this.opentimer = null;
	this.viscount = 0;
	this.visible = 0;
}

function hideThis(sID)
{
	$('#children' + sID).slideUp("normal");
	sectionTimers[sID].visible = 0;
	sectionTimers[sID].viscount = 0;
	sectionTimers[sID].closetimer = null;
}

function showThis(sID)
{
	$('#children' + sID).slideDown("normal");
	sectionTimers[sID].opentimer = null;
}

function childnav(sID, sAction)
{
	if (sAction == "show")
	{
		if (sectionTimers[sID] == null)
		{
			sectionTimers[sID] = new sectionInfo();
			//showFeedback("new sectionInfo");
		}
		if (sectionTimers[sID].closetimer != null)
		{
			clearTimeout(sectionTimers[sID].closetimer);
			sectionTimers[sID].closetimer = null;
		}
		sectionTimers[sID].viscount++;
		if (!sectionTimers[sID].visible)
		{
			var child = document.getElementById("children" + sID);
			var childAlinks = child.getElementsByTagName("a");
			if (childAlinks.length > 0)
				sectionTimers[sID].opentimer = setTimeout("showThis('" + sID + "')", 200);
			sectionTimers[sID].visible = 1;
		}
	}
	else if ( sAction == "hide" )
	{
		sectionTimers[sID].viscount--;
		if (sectionTimers[sID].opentimer)
		{
			clearTimeout(sectionTimers[sID].opentimer);
			sectionTimers[sID].opentimer = null;
			sectionTimers[sID].visible = 0;
			sectionTimers[sID].viscount = 0;
		}
		else if (!sectionTimers[sID].closetimer)
			sectionTimers[sID].closetimer = setTimeout("hideThis('" + sID + "')", 1250);
	}
}

function customer_status() {
    var cky = readCookie("wpasuser");
    if (cky)
        $("#login_link_placeholder").html("<a href=\"" + srvr + ROOT + "/account/index.aspx\">Logged in as " + cky + "</a>");
    else
        $("#login_link_placeholder").html("<a id=\"login_link\" href=\"javascript:void(0);\" onclick=\"toggle_login(this);\">My Account</a>");
}

var veil_visible = false;
function toggle_veil() 
{
    if (!veil_visible) 
    {
        var ww = getwindowsize();
        $("#veil").css("width", "" + ww.x + "px");
        $("#veil").css("height", "" + (ww.y + 1000) + "px");
        $('#veil').css("filter", "alpha(opacity=20)");
        $('#veil').fadeIn('slow');
        veil_visible = true;
    }
    else 
    {
        $('#veil').fadeOut('slow');
        veil_visible = false;
    }
}

var login_zoomrect;
var login_mouspos;
var login_panel_visible = false;
function toggle_login(oCallback) 
{
    var login_link = document.getElementById("login_link");
    var login_panel_holder = document.getElementById("login_panel_holder");
    if (login_panel_visible) {
        animate.close("login_panel_holder", function() { $("#login_panel_holder").hide(); login_panel_visible = false; if (oCallback) { oCallback(); } else { in_submit_order_process = false; } }, null, login_mouspos, login_zoomrect);
    }
    else 
    {
        if (login_panel_holder) {
            var loc = getxy(document.getElementById("login_link"));
            var ww = getwindowsize();
            $("#login_panel_holder").css("left", (( ww.x / 2 ) - 100) + "px");
            $("#login_panel_holder").css("top", (( ww.y / 2 ) - 150) + "px");

            var placeholder_width = parseInt(login_panel_holder.style.width);
            var placeholder_height = parseInt(login_panel_holder.style.height);
            
            login_zoomrect =
            {
                left: ((ww.x / 2) - 100),
                top: ((ww.y / 2) - 150),
                width: login_panel_width,
                height: login_panel_height
            };
            login_mouspos = { x: loc.x, y: loc.y };
            animate.open("login_panel_holder", function() { $("#login_panel_holder").show(); login_panel_visible = true; addShadow("login_panel"); }, null, login_mouspos, login_zoomrect);
        }
    }    
}

function do_forgot_login() {
    var req = null;
    var forgotten_login = "";

    handler = function() {
        if (req.readyState == 4) {
            document.body.style.cursor = "default";
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (Error) { /* ignore */ }
                if (rslt.Success)
                    $("#retrieve_msg").html("Your request has been submitted.");
                else {
                    $("#retrieve_msg").html("Sorry, the email address you provided is not associated with any existing account in our system.");
                }
            }
        }
    }

    forgotten_login = document.getElementById("tbx_forgotten_login").value;
    if (forgotten_login.length == 0)
        $("#retrieve_msg").html("Please correct the following:<br/><br/>In order to look up your account, your email address is required.");
    else {
        req = getreq();
        req.open("POST", (srvr + ROOT + WEBSERVICE + "ForgotLogin"), false);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send("{ email:'" + forgotten_login + "'}");
        document.body.style.cursor = "wait";
        $("#retrieve_msg").html("<i>Please wait...</i>");
    }
}

function WaiveMemberHandlingFee() {
    var req = getreq();

    handler = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (Error) { /* ignore */ }

                if (rslt.Success) {
                    if (rslt.FormattedHTML.length > 0)
                        $("#cartholder").html(rslt.FormattedHTML);
                }
            }
        }
    }

    if (req) {
        req.open("POST", (srvr + ROOT + WEBSERVICE + "WaiveMembershipFee"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send("");
    }
}

function ValidateMembershipConstituency() 
{
    var req = getreq();

    handler = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (Error) { /* ignore */ }

                if (rslt.Success) 
                    WaiveMemberHandlingFee();
            }
        }
    }
    
    if (req) 
    {
        req.open("POST", (srvr + ROOT + WEBSERVICE + "ValidateMembership"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send("");
    }
}

function do_login_username() {
    var req = null;
    handler = function()
    {
    	document.body.style.cursor = "default";
    	if (req.readyState == 4)
    	{
    		if (req.status == 200)
    		{
    			var rslt = JSON.parse(req.responseText);
    			try
    			{
    				rslt = rslt.d;
    			}
    			catch (Error) { /* ignore */ }

    			if (rslt.Success)
    			{
    				$("#login_wait").html("<i style='color:#666;'>Login Successful!</i>");
    				if (rslt.AccountInfo != null)
    				{
    					createCookie("wpasuser", rslt.AccountInfo.NameFirst + " " + rslt.AccountInfo.NameLast, 0);
    					customer_status();
    				}
    				if (location.href.indexOf("register.aspx") > -1 || location.href.indexOf("logout.aspx") > -1)
    					window.location.href = srvr + ROOT + "/account/index.aspx";
    				if (is_cart_page)
    				{
    					toggle_login(login_callback);
    					customer_logged_in = true;
    					document.getElementById("progress_tracker_1").className = "done";
    					acct_info = rslt.AccountInfo;
    					ValidateMembershipConstituency();
    				}
    				else
    					toggle_login();
    				try
    				{
    					login_success_action(rslt);
    				}
    				catch (e) { /* may not exist for current page */ }
    			}
    			else
    			{
    				$("#btn_login").show();
    				$("#login_wait").fadeOut("fast");
    				$("#login_panel_error").html(Error_Opening_Placeholder + rslt.ErrorMessage + Error_Closing_Placeholder);
    				$("#login_panel_error").slideDown(function() { positionShadow("login_panel"); });
    			}
    		}
    	}
    }

    form_validate = function() {
        var retval = {};
        var errmsg = "";
        var username = document.getElementById("tbx_username").value.trim();
        if (username.length == 0)
            errmsg += "Email Address required.<br/>";
        else
            retval.login = username;
        var passwd = document.getElementById("tbx_password").value.trim();
        if (passwd.length == 0)
            errmsg += "Password required.<br/>";
        else
            retval.passwd = passwd;
        retval.promo_code = 0;

        try {
            retval.remember_me = document.getElementById("chk_remember_me").checked;
        }
        catch (err) {
            retval.remember_me = false;
        }
        
        if (errmsg.length > 0) {
            $("#login_panel_error").html(Error_Opening_Placeholder + "Please correct the following:<br/>" + errmsg + Error_Closing_Placeholder);
            $("#login_panel_error").slideDown("slow");
        }
        else
            return retval;
    }

    var sendObj = form_validate();

    if (sendObj) {
        req = getreq();
        req.open("POST", (srvr + ROOT + WEBSERVICE + "Login"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        $("#login_panel_error").hide();
        $("#btn_login").hide();
        $("#login_wait").html("<img src='" + srvr + ROOT + "/lib/images/wait_spinner24x24.gif' align='absmiddle' /> <i>Logging In...</i>");
        $("#login_wait").slideDown("normal");
        try {
            pageTracker._trackPageview("/checkout/log_in");
        } catch (E) { }
    }
}

function do_login_lname() 
{
    var req = getreq();
    handler = function() {
        if (req.readyState == 4) {
            $('#btn_gen_lnlogin').show();
            $('#login_wait_gen_lname').fadeOut("slow");
            if (req.status == 200) {
                var msg = "";
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (err) { alert(err); }

                if (rslt.Success) {
                    $("#login_wait_gen_lname").html("<br/><i style='color:#666;font-size:8pt;'>Login Successful!</i>");
                    if (rslt.AccountInfo != null) {
                        createCookie("wpasuser", rslt.AccountInfo.NameFirst + " " + rslt.AccountInfo.NameLast, 0);
                        customer_status();
                    }
                    if (location.href.indexOf("register.aspx") > -1 || location.href.indexOf("logout.aspx") > -1)
                        window.location.href = srvr + ROOT + "/account/index.aspx";
                        
                    if (is_cart_page) {
                        toggle_login(login_callback);
                        customer_logged_in = true;
                        document.getElementById("progress_tracker_1").className = "done";
                        acct_info = rslt.AccountInfo;
                        ValidateMembershipConstituency();
                    }
                    else
                        toggle_login();
                }
                else
                    msg += "<img src='" + srvr + ROOT + "/lib/images/warning_icon.png' align='absmiddle' /> " + rslt.ErrorMessage;

                if (msg.length > 0) {
                    $("#login_panel_error").html(msg);
                    $("#login_panel_error").slideDown(function() { positionShadow("login_panel"); });
                }
            }
        }
    }

    form_validate = function() {
        var errmsg = "";
        var retval = {};
        retval.renewals = false;
        var lname = document.getElementById('tbx_generic_lname').value;
        if (lname.length == 0)
            errmsg += "Last name required.<br/>"
        else
            retval.lname = lname;

        var customer_no = document.getElementById('tbx_generic_customer_no').value; ;
        if (customer_no.length == 0)
            errmsg += "Customer Number required."
        else
            retval.customer_no = customer_no;

        if (errmsg.length == 0)
            return retval;
        else {
            $("#login_panel_error").html(Error_Opening_Placeholder + "Please correct the following:<br/>" + errmsg + Error_Closing_Placeholder);
            $("#login_panel_error").slideDown("normal");
        }
    }

    var sendObj = form_validate();

    if (sendObj) 
    {
        req.open(HTTP_VERB, (srvr + ROOT + WEBSERVICE + "LoginWithLastName"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        $("#login_panel_error").hide();
        $('#btn_gen_lnlogin').hide();
        $('#login_wait_gen_lname').html("<img src='" + srvr + ROOT + "/lib/images/wait_spinner24x24.gif' align='absmiddle' /> <i>Logging In...</i>");
        $('#login_wait_gen_lname').slideDown("normal");
    }
}

function hide_login_error() {
    if (document.getElementById("login_error").style.display == "block")
        $("#login_error").slideUp("slow");
}


function get_details(target_date) 
{
    var req = getreq();
    handler = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (Error) { /* ignore */ }
                
                if (rslt.Success)
                    $("#calendar_events").html(rslt.FormattedHTML);
                else
                    alert(rslt.Message);
            }
        }
    }

    var sendObj = { "sTargetDate": target_date };

    if (req && sendObj) 
    {
        req.open("POST", (srvr + ROOT + WEBSERVICE + "GetDetails"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
    }    
}

function get_calendar(target_date) 
{
    var req = getreq();
    handler = function() 
    {
        if (req.readyState == 4) 
        {
            if (req.status == 200) 
            {
                var rslt = JSON.parse(req.responseText);
                try 
                {
                    rslt = rslt.d;
                }
                catch (Error) { /* ignore */ }
                //alert(rslt.CalendarTable);
                
                if (rslt.Success) 
                    $("#home_calendar").html(rslt.CalendarTable);
                else
                    handle_error(rslt.Message);
            }
        }        
    }

    var sendObj = {};
    if (target_date == null)
        sendObj = { "sStartDate": "" };
    else
        sendObj = { "sStartDate": target_date };

    if (req && sendObj) 
    {
        req.open("POST", (srvr + ROOT + WEBSERVICE + "GetCalendar"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        $("#calendar_events").html("<p style='background:#F8F0C8;padding:5px 0 5px 0;margin:3px 3px 0 2px;width:250px;'>Roll Over Calendar Dates<br/>for Performance Information</p>");
        $("#home_calendar").html("<img src='"+ srvr + ROOT + "/lib/images/wait_spinner24x24_teal.gif' align='absmiddle' />");
    }
}



function handle_error(msg) 
{
    toggle_veil();
    var ww = getwindowsize();
    $("#err_notification_placeholder").css("top", ((ww.y / 2) - 150) + "px");
    $("#err_notification_placeholder").css("left", ((ww.x / 2) - 100) + "px");
    $("#err_notification_form").html(msg);
    $("#err_notification_placeholder").toggle("slow");
    
}

function hide_error() 
{
    toggle_veil();    
    $("#err_notification_form").html("");
    $("#err_notification_placeholder").toggle("slow");
}

function submit_user_info() 
{
    var sendObj = {};
    var req = null;
    
    handler = function() 
    {
        if (req.readyState == 4) 
        {
            document.body.style.cursor = "default";
            if (req.status == 200) 
            {
                var rslt = JSON.parse(req.responseText);
                try 
                {
                    rslt = rslt.d;
                }
                catch (Error) { /* ignore */ }
                if (rslt.Success)
                    alert("success");
                else
                    handle_error(ajaxresult.Message);
            }   
        }        
    }

    form_validate = function() 
    {
        var errmsg = "";
        var infoarr = [];
        var x = 0;
        var count = 0;

        var tbl_account_create = document.getElementById("tbl_account_create");
        if (tbl_account_create) 
        {
            infoarr = getObjectChildrenInput(tbl_account_create);
            for (var i = 0; i < infoarr.length; i++) 
            {
                if (infoarr[i].V == null || infoarr[i].V == "") 
                {
                    if (infoarr[i].K == "Email")
                        errmsg += ("Email Address is required.<br/>");

                    if (infoarr[i].K == "Password")
                        errmsg += ("Password is required.<br/>");

                    if (infoarr[i].K == "PasswordRepeat")
                        errmsg += ("Password Repeat is required.<br/>");

                    if (infoarr[i].K == "NameFirst")
                        errmsg += ("First name is required.<br/>");

                    if (infoarr[i].K == "NameLast")
                        errmsg += ("Last name is required.<br/>");

                    if (infoarr[i].K == "Street1")
                        errmsg += ("Address is required.<br/>");

                    if (infoarr[i].K == "City")
                        errmsg += ("City is required.<br/>");

                    if (infoarr[i].K == "PostalCode")
                        errmsg += ("Postal Code is required.<br/>");

                    if (infoarr[i].K == "PhoneDay")
                        errmsg += ("Day Phone is required.<br/>");
                }
            }

//            if (document.getElementById("tbx_password").value != document.getElementById("tbx_password_repeat").value)
//                errmsg += ("Password and Password Repeat do not match.<br/>");

            var source_no = get_menu_val(document.getElementById("ddl_source_no"));

            if (source_no <= -1)
                errmsg += ("Please tell us what brought you to our website today.<br/>");

            if (errmsg != "")
                handle_error("Please correct the following:<br/><br/>" + errmsg);
            else
                return { "userinfo": infoarr };
        }
    }

    sendObj = this.form_validate();

    if (sendObj) 
    {   
        req = getreq();
        req.open("POST", (srvr + ROOT + WEBSERVICE + "SubmitUserInfo"), false);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        document.body.style.cursor = "wait";
    }
}

/* ----------------------------------------------------------------------------------------------- */

var priceTypeQty = [];
var priceTypes = [];
var priceTypeToSubmit = "";
var zone_no = 0;
var total_selected_quantity = 0;
var swidth;
var sheight;
var zoomrect;
var mousepos;
var selected_perf_no = -1;
var iFacility_no = 0;

function doReserveTickets() 
{
    var req = null;
    handler = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                } catch (err) { }

                if (rslt.Success)
                    window.location.href = srvr + ROOT + "/cart/index.aspx";
                else {
                    $("#btn_purchase_submit").show(function() { positionShadow("performance_summary_panel"); });
                    if (rslt.ErrorMessage.length > 0)
                        $("#ticket_req_msg").html(Error_Opening_Placeholder + rslt.ErrorMessage + Error_Closing_Placeholder);
                    else
                        $("#ticket_req_msg").html(Error_Opening_Placeholder + rslt.Message + Error_Closing_Placeholder);
                }
            }
        }
    }

    form_validate = function() 
    {
        var retval = {};
        retval.perf_no = selected_perf_no;
        retval.quantity = total_selected_quantity;
        priceTypeToSubmit = "";
        for (x = 0; x < priceTypes.length; x++) {
            var i = priceTypes[x];

            if (i > 0) {
                var ptmenu = document.getElementById("pricetype_" + i);
                if (ptmenu && ptmenu.selectedIndex > 0) {
                    var howmany = parseInt(ptmenu.options[ptmenu.selectedIndex].value);
                    for (y = 0; y < howmany; y++) {
                        if (priceTypeToSubmit.length > 0)
                            priceTypeToSubmit += ",";

                        priceTypeToSubmit = priceTypeToSubmit + i;
                    }
                }
            }
        }

        retval.pricetype = priceTypeToSubmit;
        retval.zone = zone_no;
        retval.specialRequests = "";

        return retval;
    }
    
    var sendObj = form_validate();

    if (sendObj) 
    {
        req = getreq();
        req.open("POST", (srvr + ROOT + WEBSERVICE + "ReserveTickets"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        $("#ticket_req_msg").html("<img src='" + srvr + ROOT + "/lib/images/wait_spinner16x16.gif' align='absmiddle' /> <i style='color:#666;'>Please wait while we reserve your tickets...</i>");
        $("#btn_purchase_submit").hide(function() { positionShadow("performance_summary_panel"); });
        try {
            pageTracker._trackPageview("/checkout/ticketing_price_grid");
            //alert("Google Analytics tracking ran successfully");
        }
        catch (E) { }
    }
}

function doGetPricingGrid(iPerf_no, el) 
{
    var loc = getxy(el);
    selected_perf_no = iPerf_no;
    
    var sendObj = {"perf_no" : iPerf_no }
    var req = getreq();

    handler = function()
    {
    	if (req.readyState == 4)
    	{
    		if (req.status == 200)
    		{
    			document.body.style.cursor = "default";
    			$("#wait_hz").fadeOut("slow");

    			var rslt = JSON.parse(req.responseText);
    			try
    			{
    				rslt = rslt.d;
    			} catch (err) { }

    			if (rslt.Success)
    			{
    				iFacility_no = rslt.VenueID;
    				priceTypes = rslt.PriceTypes;

    				var performance_summary = "";
    				if (rslt.OnSaleIndicator)
    					performance_summary = rslt.PerformanceSummary + rslt.TicketPriceGrid + rslt.ZoneQuantitySelector;
    				else
    					performance_summary = rslt.PerformanceSummary + "<b class='perf_status'>" + rslt.PerformanceStatusDescription + "</b>";

    				$("#performance_summary").html(performance_summary);
    				$("#img_venue_map").attr({ src: srvr + ROOT + "/lib/images/seatmaps/V" + rslt.VenueID + ".gif", alt: rslt.VenueName });
    				var ww = getwindowsize();
    				sheight = ww.y - 250;
    				swidth = (parseInt(ww.x) - 254);
    				var scrtp = getscrolltop();

    				$("#performance_summary_placeholder").css("left", "" + Math.floor((ww.x - ticketing_grid_width) / 2) + "px"); //(((swidth / 2) + 254) - (ticketing_grid_width / 2))
    				var calculated_top = Math.floor((ww.y - ticketing_grid_height) / 2) - 72 + scrtp.y; // ((sheight / 2) - (ticketing_grid_height / 2));
    				// if (page_id == "f2363767-7a8f-47c6-ac0b-fa20a1b8225b")               <--------- no longer necessary with no flash header
    				//    calculated_top = 345;
    				$("#performance_summary_placeholder").css("top", "" + calculated_top + "px");

    				var performance_summary_placeholder = document.getElementById("performance_summary_placeholder");
    				var placeholder_width = parseInt(performance_summary_placeholder.style.width);
    				var placeholder_height = parseInt(performance_summary_placeholder.style.height);
    				zoomrect =
                    {
                    	left: Math.floor((ww.x - ticketing_grid_width) / 2), // (((swidth / 2) + 254) - (ticketing_grid_width / 2)),
                    	top: calculated_top,
                    	width: ticketing_grid_width,
                    	height: ticketing_grid_height
                    };

    				mousepos = { x: loc.x, y: loc.y };
    				animate.open("performance_summary_placeholder", function() { $("#performance_summary_placeholder").show(); addShadow("performance_summary_panel"); }, null, mousepos, zoomrect);
    			}
    		}
    	}
    }
    
    req.open("POST", (srvr + ROOT + WEBSERVICE + "GetPerformancePricing"), true);
    req.setRequestHeader(CONTENT_TYPE, APP_JSON);
    req.onreadystatechange = this.handler;
    req.send(JSON.serialize(sendObj));
    document.body.style.cursor = "wait";            

}

function hideTicketingGrid() 
{
    $("#ticket_req_msg").html("");
    animate.close("performance_summary_placeholder", function() { $("#performance_summary_placeholder").hide(); }, null, mousepos, zoomrect);
}

function checkEnableSubmitPurchase() 
{
    total_selected_quantity = 0;
    $('select.ddlzoneqty').each(
		function(i) {
		    total_selected_quantity += parseInt(this.options[this.selectedIndex].value);
		}
	);
		if (zone_no > -1 && total_selected_quantity > 0)
		    $('#btn_purchase_submit').show(function() { positionShadow("performance_summary_panel"); });
		else
		    $('#btn_purchase_submit').hide(function() { positionShadow("performance_summary_panel"); });

}

function selectZone(iZone_no) 
{
   // $("#zone_map").html("iZone_no: " + iZone_no);
    
    zone_no = iZone_no;
    if (iZone_no > 0)
        document.getElementById("img_venue_map").setAttribute("src", srvr + ROOT + "/lib/images/seatmaps/" + iZone_no + ".gif");    
    else
        document.getElementById("img_venue_map").setAttribute("src", srvr + ROOT + "/lib/images/seatmaps/V" + iFacility_no + ".gif");
}

function selectPriceTypeQty(iPriceType, iQty) 
{
    checkEnableSubmitPurchase();
    $("#ticket_req_msg").html("");
}

function logout_user() {
    alert("log out");
   }

function showPricing(perf_no, prod_season_no, caller)
{
   	doGetPricingGrid(perf_no, caller);
}


function do_password_retrieve() {
    var req = getreq();

    handler = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (E) { }
                if (rslt.Success)
                    $("#retrieve_msg").html("Your request has been submitted. If the login you submitted matches an existing login, it has been emailed to the address associated with that account.");
                else
                    $("#retrieve_msg").html(Error_Opening_Placeholder + rslt.ErrorMessage + Error_Closing_Placeholder);
            }
        }
    }

    form_validate = function() {
        var errmsg = "";
        var retval = null;
        
        var email = document.getElementById('tbx_forgot_email').value;
        if (email.length == 0)
             errmsg += "Email Address required.";

        var e = email_validation(email);
        if (e)
            retval = { "email": email };
        else
            errmsg += "Email format is incorrect.";

        if (errmsg.length > 0)
            $("#retrieve_msg").html("Please correct the following:<br/>" + errmsg);
        else
            return retval;
    }
    
    var sendObj = form_validate();
    if (sendObj) 
    {
        req.open("POST", (srvr + ROOT + WEBSERVICE + "ForgotLogin"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        $("#retrieve_msg").html("<img src='" + srvr + ROOT + "/lib/images/wait_spinner24x24.gif' align='absmiddle' /> <i style='color:#666;'>Please wait...</i>");
        $("#retrieve_msg").fadeIn("fast");
    }

}

function register() {
    var req = getreq();
    var login_source_no = -1;

    handler = function() {
        if (req.readyState == 4) {
            $("#btn_register").show();
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (E) { }
                if (rslt.Success) {
                    createCookie("wpasuser", rslt.AccountInfo.NameFirst + " " + rslt.AccountInfo.NameLast, 0);
                    customer_status();
                    $("#register_msg").html("<i>Redirecting...</i>");
                    if (rslt.RedirectUrl.length > 0)
                        window.location.href = srvr + ROOT + rslt.RedirectUrl;
                    else
                        window.location.href = srvr + ROOT + "/account/index.aspx";
                }
                else
                    $("#register_msg").html(Error_Opening_Placeholder + "The email address you provided is already associated with an existing account." + Error_Closing_Placeholder);
            }
        }
    }

    form_validate = function() {
        var userinputs = [];
        var errmsg = "";
        var customer_register_form = document.getElementById("customer_register_form");

        if (customer_register_form) {
            userinputs = getObjectChildrenInput(customer_register_form);

            var PhoneDay = "";
            var PhoneEve = "";
            for (var x = 0; x < userinputs.length; x++) {
                var K = userinputs[x].K;
                var V = userinputs[x].V;

                if (K == "Email" && V.length == 0)
                    errmsg += "Email Address required.\r\n";

                if (K == "Password" && V.length == 0)
                    errmsg += "Password required.\r\n";

                if (K == "NameFirst" && V.length == 0)
                    errmsg += "First Name required.\r\n";

                if (K == "NameLast" && V.length == 0)
                    errmsg += "Last Name required.\r\n";

                if (K == "Street1" && V.length == 0)
                    errmsg += "Street Address Required.\r\n"

                if (K == "City" && V.length == 0)
                    errmsg += "City Required.\r\n"

                if (K == "PhoneDay")
                    PhoneDay = V;

                if (K == "PhoneEve")
                    PhoneEve = V;

                if (K == "PostalCode" && V.length == 0)
                    errmsg += "Postal Code is required.\r\n";
            }

            if (PhoneDay.length == 0 && PhoneEve.length == 0)
                errmsg += "Day Phone or Evening Phone is required.";
        }
        if (errmsg.length == 0)
            return { userinfo: userinputs };
        else
            alert(errmsg);
    }

    var sendObj = form_validate();

    if (sendObj) {
        req.open("POST", (srvr + ROOT + WEBSERVICE + "SubmitUserInfo"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        $("#btn_register").hide();
        $("#register_msg").html("<img src='" + srvr + ROOT + "/lib/images/wait_spinner24x24.gif' align='absmiddle' /> <i style='color:#666;'>Please wait...</i>");
        $("#register_msg").fadeIn("fast");
    }
}

function show_donor_notes() {
    var chk_donor_notes = document.getElementById("chk_donor_notes");

    if (chk_donor_notes.checked == true)
        $("#donor_notes_holder").slideDown(function() { positionShadow("contrib_panel"); });
    else
        $("#donor_notes_holder").slideUp(function() { positionShadow("contrib_panel"); });    
}

var list_donor = true;
function set_listing_pref(li) {
    if (li == "N")
        list_donor = false;
    else if (li == "Y")
        list_donor = true;
}

var customer_info_panel_visible = false;
function toggle_account_panel() {

    if (customer_info_panel_visible) {
        $("#customer_info_panel").slideUp('slow');
        customer_info_panel_visible = false;
    }
    else {
        $("#customer_info_panel").slideDown('slow');
        customer_info_panel_visible = true;
    }
}

// -------------- contact preferences { email, mail, phone } support methods -------------------------

function GetContactPrefID(desc) 
{
    var id = 0;
    for (var x = 0; x < acct_contact_choices.length; x++) {
        if (acct_contact_choices[x].Description == desc) {
            id = acct_contact_choices[x].id;
            break;
        }
    }
    return id;
}

function AllowEmarket(desc) 
{
    var id = GetContactPrefID(desc);
    if (id == 4)
        return true;
    else
        return false;
}

function AllowMail(desc) {
    var id = GetContactPrefID(desc);
    if (id == 3)
        return true;
    else
        return false;
}

function AllowPhone(desc) 
{
    var id = GetContactPrefID(desc);
    if (id == 3)
        return true;
    else
        return false;
}

// -------------- add contribution support methods -------------------------


function CreateContributionCSI( o ) {

    var req = getreq();
    handler = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (E) { }
                if (rslt.Success)
                    window.location.href = srvr + ROOT + "/cart/index.aspx";
                else
                    $("#contrib_wait").html(Error_Opening_Placeholder + rslt.ErrorMessage + Error_Closing_Placeholder);
            }
        }
    }
    req.open("POST", (srvr + ROOT + WEBSERVICE + "CreateCustomerServiceIssueNotes"), true);
    req.setRequestHeader(CONTENT_TYPE, APP_JSON);
    req.onreadystatechange = this.handler;
    req.send(JSON.serialize({ "userinfo": o }));
}

function AddContribution() 
{
    var req = getreq(); 
    var inputs = [];
    handler = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (E) { }
                if (rslt.Success) 
                {
                    $("#contrib_wait").fadeOut("slow");
                    CreateContributionCSI(inputs);
                } 
                else 
                    $("#contrib_wait").html(Error_Opening_Placeholder + rslt.ErrorMessage + Error_Closing_Placeholder);
            }
        }
    }

    form_validate = function() {
        var retval = {};
        var errmsg = "";
        
        var tbl = document.getElementById("contribution_tbl");
        if (tbl)
            inputs = getObjectChildrenInput(tbl);

        var amt = document.getElementById("tbx_amount").value;
        if (amt <= 0)
            errmsg += "Amount must be greater than zero.";
        else
            retval.amount = amt;
            
        if (errmsg.length == 0)
            return retval;
        else
            alert(errmsg);
    }
    
    var sendObj = form_validate();
    if (sendObj) 
    {
        req.open("POST", (srvr + ROOT + WEBSERVICE + "AddContribution"), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize(sendObj));
        $("#contrib_wait").html("<img src='" + srvr + ROOT + "/lib/images/wait_spinner24x24.gif' align='absmiddle' /> <i style='color:#666;'>Please wait...</i>");
        $("#contrib_wait").fadeIn("slow");
    }
}

function apply_promo_code() {
    var req = getreq();
    handler = function() {
        if (req.readyState == 4) {
            document.body.style.cursor = "default";
            if (req.status == 200) {
                var rslt = JSON.parse(req.responseText);
                try {
                    rslt = rslt.d;
                }
                catch (Err) { }

                if (rslt.Success) {
                    if (!is_cart_page)
                        doGetPricingGrid(selected_perf_no, document.getElementById("buylink" + selected_perf_no));

                    if (rslt.FormattedHTML.length > 0)
                        $("#cartholder").html(rslt.FormattedHTML);
                }
                else {
                    if (rslt.Message.length > 0)
                        $("#promo_msg").html(rslt.Message);
                    else if (rslt.ErrorMessage.length > 0)
                        $("#promo_msg").html(rslt.ErrorMessage);
                    else
                        $("#promo_msg").html("Invalid promo code.");

                    $("#promo_msg").slideDown(function() { positionShadow("performance_summary_panel") });
                }
            }
        }
    }
    var promo = document.getElementById("tbx_promocode").value;

    if (promo.length > 0) {
        var use_webmethod = "AddPromoCode";
        if (is_cart_page)
            use_webmethod = "SetPromoCode";

        req.open("POST", (srvr + ROOT + WEBSERVICE + use_webmethod), true);
        req.setRequestHeader(CONTENT_TYPE, APP_JSON);
        req.onreadystatechange = this.handler;
        req.send(JSON.serialize({ "promo_code": promo }));
        $("#promo_msg").html("");
        document.body.style.cursor = "wait";
    }

}

// -------------- minicalendar support methods -------------------------

      var minicalendar_display_guid = "5B21569F-1DAE-4338-8AB4-957287F6F9CB";

      function parseDate(sDate)
      {
      	var start_pt = sDate.indexOf("(");
      	var end_pt = sDate.indexOf(")");
      	var dateno = parseInt(sDate.substr(start_pt + 1, end_pt - 1));
      	return new Date(dateno);
      }

      function ajaxminicalendar(sMonthYear)
      {
      	var req = getreq();

      	var cachedPastMonths = document.getElementById("cachedPastMonths");
      	var minicalendar_div = document.getElementById("minicalendar_div");

      	this.handler = function()
      	{
      		if (req.readyState == 4)
      		{
      			document.body.style.cursor = "default";
      			if (req.status == 200)
      			{
      				var result = JSON.parse(req.responseText);
      				try
      				{
      					result = result.d;
      				}
      				catch (E) { }

      				if (result.Success)
      				{
      					var currentDisplayCalendar = minicalendar_div.getElementsByTagName("table");
      					if (currentDisplayCalendar && currentDisplayCalendar.length)
      					{
      						var nodeToMove = currentDisplayCalendar[0];
      						minicalendar_div.removeChild(nodeToMove);
      						cachedPastMonths.appendChild(nodeToMove);
      					}
      					$(minicalendar_div).html(result.FormattedHTML);
      					if (result.CalendarItems != null)
      					{
      						for (var x = 0; x < result.CalendarItems.length; x++)
      						{
      							var currcalitem = result.CalendarItems[x];
      							currcalitem.EventWhen = parseDate(result.CalendarItems[x].EventWhen);
      							caldisplayitems[caldisplayitems.length] = currcalitem;
      						}
      					}
      					eval(result.JS);
      				}
      			}
      		}
      	}

      	var exists = document.getElementById("minical" + sMonthYear);
      	if (exists)
      	{
      		var currentDisplayCalendar = minicalendar_div.getElementsByTagName("table");
      		if (currentDisplayCalendar && currentDisplayCalendar.length)
      		{
      			var nodeToMove = currentDisplayCalendar[0];
      			nodeToMove.parentNode.removeChild(nodeToMove);
      			cachedPastMonths.appendChild(nodeToMove);
      			exists.parentNode.removeChild(exists);
      			minicalendar_div.appendChild(exists);
      			return;
      		}
      	}

      	var sendObj = { display_id: minicalendar_display_guid, month: sMonthYear };

      	if (req)
      	{
      		$('#dayresults').html("");
      		document.body.style.cursor = "wait";
      		req.open(HTTP_VERB, srvr + WEBSERVICE + "get_minicalendar", true)
      		req.setRequestHeader(CONTENT_TYPE, APP_JSON);
      		req.onreadystatechange = this.handler;
      		req.send(JSON.serialize(sendObj));
      	}

      }


      var firstEventURLThisDay;
      function day_details(sDate)
      {
      	$('#dayresults').html("");
      	var s = "";
      	var dt = new Date(sDate);
      	var setFirstEvent = false;
      	var lastPerfNo = -1;
      	for (var x = 0; x < caldisplayitems.length; x++)
      	{
      		if (dt.getDate() == caldisplayitems[x].EventWhen.getDate() && dt.getMonth() == caldisplayitems[x].EventWhen.getMonth())
      		{
      			// on calendar/genre pages, there may be duplicate instances of calendar items, so
      			// hopefully this'll filter out obvious adjacent duplicates.
      			if ( lastPerfNo == caldisplayitems[x].perf_no )
      				continue;
      			s += "<div class='minicalitem'><b><a href='" + caldisplayitems[x].DetailsUrl;
      			s += ( ( caldisplayitems[x].DetailsUrl.indexOf("?") > -1 ) ? "&" : "?" );
      			s += "location=minicalendar'>";
      			s += caldisplayitems[x].Title + "</a></b><br/>"
      			s += caldisplayitems[x].Venue;
      			if (!setFirstEvent)
      			{
      				setFirstEvent = true;
      				firstEventURLThisDay = caldisplayitems[x].DetailsUrl;
      			}
      			if (caldisplayitems[x].BuyLink && caldisplayitems[x].BuyLink.length > 0)
      			{
      				s += "<span class='action' onclick='" + caldisplayitems[x].BuyLink + "'>";
      				s += "<img class='minibuy' src='/lib/images/hp_buy3.gif' alt='' /></span>"
      			}
      			s += "</div>";
      			lastPerfNo = caldisplayitems[x].perf_no;
      		}
      	}
      	if (s.length > 0)
      		$('#dayresults').html(s);
      }

      function jumpevt()
      {
      	var lhref = firstEventURLThisDay;
      	lhref += ((firstEventURLThisDay.indexOf("?") > -1) ? "&" : "?");
      	lhref += "location=minicalendar";
      	location.href = lhref;
      }

      // ------------------ search -----------------------------------
      function handleReturn(e)
      {
      	if (search_results_visible)
      	{
      		toggle_searchresults_box();
      	}
      	if (!e)
      		e = window.event;
      	var k = (window.event ? e.keyCode : e.which);
      	if (k == 13)
      		doSearch();
      	return k != 13;
      }

      var search_results_visible = false;
      var search_results_zoompoint;
      var search_results_zoomrect;
      function toggle_searchresults_box()
      {
      	var search_results_holder = document.getElementById("search_results_holder");
      	if (search_results_visible)
      	{
      		var curwid = search_results_holder.clientWidth;
      		var curheight = search_results_holder.clientHeight;

      		var xy = getxy(search_results_holder);
      		search_results_zoomrect = { left: xy.x, top: xy.y, width: curwid, height: curheight };
      		search_results_visible = false;
      		$(search_results_holder).hide();
      		animate.close(search_results_holder, null, null, search_results_zoompoint, search_results_zoomrect);
      	}
      	else
      	{
      		search_results_zoompoint = getxy("img_search_go");
      		search_results_zoomrect = { left: search_results_zoompoint.x - 300, top: search_results_zoompoint.y + 20, width: 300, height: 200 };
      		search_results_visible = true;
      		if (search_results_holder.parentNode != document.body)
      		{
      			search_results_holder.parentNode.removeChild(search_results_holder);
      			document.body.appendChild(search_results_holder);
      		}
      		search_results_holder.style.left = "" + search_results_zoomrect.left + "px";
      		search_results_holder.style.top = "" + search_results_zoomrect.top + "px";
      		animate.open(search_results_holder, function() { $(search_results_holder).show(); addShadow("search_results"); }, null, search_results_zoompoint, search_results_zoomrect);
      	}

      }

      function displaySearchResults(oRslt)
      {
      	var tbl_search_rslts = document.getElementById("tbl_search_rslts");
      	var numchildren = tbl_search_rslts.childNodes.length;
      	for (var x = 0; x < numchildren; x++) // remove existing children;
      		tbl_search_rslts.removeChild(tbl_search_rslts.childNodes[numchildren - x - 1]);

      	for (var x = 0; x < oRslt.SearchResultItems.length; x++)
      	{
      		var tr = document.createElement("tr");
      		var td = document.createElement("td");
      		var alink = document.createElement("a");
      		alink.href = oRslt.SearchResultItems[x].URL;
      		alink.appendChild(document.createTextNode(oRslt.SearchResultItems[x].Title));
      		td.appendChild(alink);
      		tr.appendChild(td);
      		tbl_search_rslts.appendChild(tr);
      	}
      	if (isIE)
      	{
      		var str = $(tbl_search_rslts).html();
      		$('#tbl_search_rslts').html(str);
      	}
      	$("#p_searchresults_label").html(oRslt.FormattedHTML);
      }

      function doSearch()
      {
      	var req = getreq();

      	this.handler = function()
      	{
      		if (req.readyState == 4)
      		{
      			document.body.style.cursor = "default";
      			if (req.status == 200)
      			{
      				rslt = JSON.parse(req.responseText);
      				try
      				{
      					rslt = rslt.d;
      				}
      				catch (err) { }
      				if (rslt.Success)
      				{
      					toggle_searchresults_box();
      					displaySearchResults(rslt);
      				}
      				else
      					alert(rslt.ErrorMessage);
      			}
      			else
      				alert(req.responseText);
      			document.body.style.cursor = "default";
      		}
      	}

      	this.validate = function()
      	{
      		var tbx_search = document.getElementById("tbx_search");
      		var retval = { search: tbx_search.value.trim() };
      		if (retval.search.length > 0)
      			return retval;
      	}

      	var sendObj = this.validate();

      	if (sendObj && req)
      	{
      		document.body.style.cursor = "wait";
      		req.open(HTTP_VERB, (WEBSERVICE + "ftsearch"), true);
      		req.setRequestHeader(CONTENT_TYPE, APP_JSON);
      		req.onreadystatechange = this.handler;
      		req.send(JSON.serialize(sendObj));
      	}
      }
