String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function () {
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function () {
    return this.replace(/\s+$/, "");
}

RegExp.escape = function (str) {
    var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
    return str.replace(specials, "\\$&");
}

function TNGenerateRandomAlphaNumStr(numChars) {
    var chars = "0123456789abcdefghiklmnopqrstuvwxyz";	
	var retStr = '';

	for (var i=0; i < numChars; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		retStr += chars.substring(rnum,rnum+1);
	}

    return retStr;
}

var previousRandomStrsArr = new Array();

function TNGenerateRandomAlphaNumStrRememberPrior(numChars) {
    var nextStrCandidate = TNGenerateRandomAlphaNumStr(numChars);

    while(previousRandomStrsArr[nextStrCandidate])
    {
        nextStrCandidate = TNGenerateRandomAlphaNumStr(numChars);
    }

    previousRandomStrsArr[nextStrCandidate] = true;

    return nextStrCandidate;
}

function TNR4CreateCookie(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+"; path=/";
}

function TNR4CreateCrossDomainCookie(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 + "; path=/;domain=ticketnetwork.com"
}

function TNR4ReadCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function TNR4EraseCookie(name) {
    TNR4CreateCookie(name,"",-1);
}

function urlEncode(url)
{
    return encodeURIComponent(url);
}

function urlDecode(url)
{
    return decodeURIComponent(url);
}

function CreateBookmarkLink()
{
    title = document.title; 
    url = window.location.href;
  
    if (window.sidebar)
    { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    }
    else if( window.external )
    { // IE Favorite
        window.external.AddFavorite(url, title);
    }
    else if(window.opera && window.print)
    { // Opera Hotlist
        var a = document.createElement("A");
        a.rel = "sidebar";
        a.target = "_search";
        a.title = title;
        a.href = escape(url);
        a.click();
    }
}

function IsArray(obj) {
    if (obj.constructor.toString().indexOf("Array") == -1)
        return false;
    else
        return true;
}

function ToPPUrl(name)
{
    //change - and / to spaces
    //strip all non-digit/non-word/non-space characters and replace all spaces (one or more) with -
    var retStr = name.toLowerCase().trim();
    retStr = retStr.replace(/[\/\-:]+/g, " ");
    retStr = retStr.replace(/[^\w\d\s]+/g, "");
    retStr = retStr.replace(/\s+/g, "-");
    return retStr;
}

function loadXMLDoc(url)
{
    // code for IE7+, Firefox, Chrome, Opera, Safari
    if (window.XMLHttpRequest) 
    {
        xmlhttp = new XMLHttpRequest();
    }
    // code for IE6, IE5
    else 
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", url, false);
    xmlhttp.send(null);
    return xmlhttp.responseXML.documentElement;
}

function checkDate(theDate) {
    var validformat = /^\d{1,2}\/\d{1,2}\/\d{4}$/ //Basic check for format validity
    if (!validformat.test(theDate)) {
        return false;
    }
    else {
        return true;
    }
}

function GetQueryStringObj(queryString) {
    if (queryString === undefined)
        queryString = window.location.search;

    //if there is a query string attached to the URL
    if (queryString.length > 0) {
        // Build an empty URL structure in which we will store
        // the individual query values by key.
        var objURL = new Object();

        // Use the String::replace method to iterate over each
        // name-value pair in the query string. Location.search
        // gives us the query string (if it exists).
        queryString.replace(
			new RegExp("([^?=&]+)(=([^&]*))?", "g"),
        // For each matched query string pair, add that
        // pair to the URL struct using the pre-equals
        // value as the key.
				function ($0, $1, $2, $3) {
				    objURL[$1] = $3;
				}
			);

        return objURL;
    }
    return false;
}

function GetQueryStringValue(key, queryString) {
    if (queryString === undefined)
        queryString = window.location.search;

    //if there is a query string attached to the URL
    if (queryString.length > 0) {
        // Build an empty URL structure in which we will store
        // the individual query values by key.
        var objURL = new Object();

        // Use the String::replace method to iterate over each
        // name-value pair in the query string. Location.search
        // gives us the query string (if it exists).
        queryString.replace(
			new RegExp("([^?=&]+)(=([^&]*))?", "g"),
        // For each matched query string pair, add that
        // pair to the URL struct using the pre-equals
        // value as the key.
				function ($0, $1, $2, $3) {
				    objURL[$1] = $3;
				}
			);

        if (objURL[key]) {
            return objURL[key];
        }
    }
    return false;
}

function getFlashVersion() {
    try
    {
        try
        {
            var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
            try { axo.AllowScriptAccess = 'always'; }
            catch (e) { return '6,0,0'; }
        } catch (e) { }

        return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
        // other browsers
    } catch (e) {
        try {
            if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
                return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
            }
        } catch (e) { }
    }
    return 'Flash Not Installed';
}

function getGoogleCampaignSource() {
    var utmz = TNR4ReadCookie('__utmz');
    if (utmz != null) {
        var sourceReg = /utmcsr=(.+?)(?:\||$)/i;
        match = sourceReg.exec(utmz);
        if (match != null) {
            return match[1];
        }
    }
    return null;
}

function getGoogleCampaignMedium() {
    var utmz = TNR4ReadCookie('__utmz');
    if (utmz != null) {
        var sourceReg = /utmcmd=(.+?)(?:\||$)/i;
        match = sourceReg.exec(utmz);
        if (match != null) {
            return match[1];
        }
    }
    return null;
}
	
(function(){
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
        
    special.scrollstart = {
        setup: function() {
 
            var timer,
                handler =  function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
 
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid1, handler);
 
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
    
        
    
    special.scrollstop = {
        latency: 600,
        setup: function() {
 
            var timer,
                    handler = function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    }
 
                    timer = setTimeout( function(){
 
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
 
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid2, handler);
 
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };

  })();

  function mailLink() {
      location.href = "mailto:?subject=Check out this page!&body=Here is a website page I think you will like: \n" + encodeURI(decodeURI(window.location.toString()).replace(/<[^>]*>/g, ''));
  }



  $(document).ready(function () {
      $(this).click(function () {
          $('.popupClass').hide();
      });

      $('.popupOpener').click(function (event) {
          var popupToOpen = $('#' + $(this).attr('popupToOpen'));
          if (popupToOpen.is(":hidden")) {
              event.stopPropagation();
              $('.popupClass').hide();
              popupToOpen.show();
          }
      });

      $('.popupClass').click(function (event) {
          event.stopPropagation(); //don't want the popup to close if you're just clicking on it
      });

      $('.close_me').click(function (event) {
          $('.popupClass').hide();
          event.stopPropagation();
      });



      //alphabetic performer: hide all tabs with no results
      var count = 0;
      var shown = 0;
      $('.alphabet_performer_container .alph_tab').each(function () {
          if ($($(this).attr('href') + ' .performerResults').children().length == 0) {
              $(this).hide();
              count += 1;
          }
      });

      $('.alphabet_performer_container #tabs-all .alpha-headers').each(function () {
          if ($(this).next('.letter_section').children('ul').length == 0) {
              $(this).hide();
              $(this).next('.letter_section').hide();
          }
          else {
              shown++;
              if ((shown + 1) % 2 == 0) {
                  $(this).parents('.column:first').addClass('left_column');
              }
          }
      });

      if (count == 27) {
          $('#no_performers').show();
      }


      //bind click event to 'all of a...' etc.
      $('.tab-click').click(function () {
          var tabToOpen = $(this).attr('tabToOpen');
          $('#alpha-perf-tabs li a').each(function () {
              if (tabToOpen == $(this).attr('href')) {
                  $(this).click();
              }
          });
      });



      //expandable things in a page
      $('.expandable ul').click(function (event) {
          event.stopPropagation();
      });
      $('.expandable').click(function () {
          $(this).toggleClass('opened');
          $(this).children('ul').toggle();
          $(this).children('u').toggle();
          if ($(this).children('span').hasClass('up-arrow')) {
              $(this).children('span').addClass('dn-arrow');
              $(this).children('span').removeClass('up-arrow');

          }
          else {
              $(this).children('span').removeClass('dn-arrow');
              $(this).children('span').addClass('up-arrow');
          }
      });
  });

