﻿// JScript File

if (typeof String.prototype.startsWith != 'function') {
  String.prototype.startsWith = function (str){
    return this.indexOf(str) == 0;
  };
}

var MAX_DUMP_DEPTH = 10;
function dumpObj(obj, name, indent, depth) {
  if (depth > MAX_DUMP_DEPTH) {
         return indent + name + ": <Maximum Depth Reached>\n";
  }
  if (typeof obj == "object") {
         var child = null;
         var output = indent + name + "\n";
         indent += "\t";
         for (var item in obj)
         {
               try {
                      child = obj[item];
               } catch (e) {
                      child = "<Unable to Evaluate>";
               }
               if (typeof child == "object") {
                      output += dumpObj(child, item, indent, depth + 1);
               } else {
                      output += indent + item + ": " + child + "\n";
               }
         }
         return output;
  } else {
         return obj;
  }
}

function mergeObj(dest, source)
{
  if (typeof source == "object") {
         var child = null;
         for (var item in source)
         {
               try {
                      child = source[item];
               } catch (e) {
                      child = "<Unable to Evaluate>";
               }
               if (typeof child == "object") {
                      dest[item] += mergeObj( dest[item], child );
               } else {
                      dest[item] = child;
               }
         }
         return;
  } else {
         return;
  }
}
       

function arrayPopup3(pElem, pTitle, pContent, pStyle)
{

    if (pElem == null || pElem.id == null || pElem.id == "")
    {
        var now = new Date();
        pElem.id = 'rand_'+ now.getTime();
//        arrayPopup2(pTitle, pContent, null);
//        return;
    }
    
    var themeName = 'azure';
    if (window.R3D_Theme != null && typeof(R3D_Theme.getThemeName) == 'function')
        themeName = R3D_Theme.getThemeName();
        
    var options = { selectable: true,
                   innerHtmlStyle: {'text-align' : 'left', 'max-width' : '300' },
                   manageMouseOverEvents: false,
                   themeName: themeName
                 };
                 
    if (pStyle != null && typeof(pStyle) == 'object' && pStyle.constructor != Array)
        mergeObj(options, pStyle);

    var item = $('#'+pElem.id);
    if (pTitle != '')
        pTitle = "<div class=\"jq_popupTitle\" style=\"width:100%\">"+pTitle+"</div>";
    if ( item.HasBubblePopup())
        return; //item.RemoveBubblePopup();
        
    if (pContent.indexOf('<table') == -1)  
        pContent = "<div class=\"jq_popupContent\" style=\"max-width:300px\">" + pContent + "</div>";
    else
        pContent = "<div class=\"jq_popupContent\" >" + pContent + "</div>";
        
    options.innerHtml =  pTitle + pContent;       
    item.CreateBubblePopup(options);
}

function closePopup3(pElem)
{
    if (pElem == null || pElem.id == null || pElem.id == "")
    {
        closePopup();
        return;
    }

    var item = $('#'+pElem.id);
    if ( item.HasBubblePopup())
       item.RemoveBubblePopup();
    else
        closePopup();
}

$(function () {

$('input[class*="value-hide"], textarea[class*="value-hide"]').each(function() {
    this.value = '';
    $(this).removeClass().addClass('default-value');
});

// Initialsie all pop up bubble help
$('input[class*="content-popup"]').each(function() {
    $(this).CreateBubblePopup({innerHtml: $(this).attr('popup-content')})
});

// comment field call to action for customer/presenters 
$('textarea[class*="field-call-to-action"]').each(function(obj) {
    var id = $(this).attr('id') + "_CallToActionCopy";
    var default_value = $('#'+id).val();
    if(this.value == '' || this.value == default_value)
    {
       this.value = default_value;
       this.setAttribute('class', 'default-value');
    }
    
    $(this).focus(function(obj) {
        if(this.value == default_value) {
            this.value = '';
            this.setAttribute('class', this.className.replace('default-value', ''));
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
            this.setAttribute('class', 'default-value');
        }
    });
});

$('input[class*="promo-field"]').CreateBubblePopup({innerHtml: 'You need to enter the promo code for this price'});
$('input[class*="required-ticket-qty"]').CreateBubblePopup({innerHtml: 'You need to select 1 or more <br>tickets from this price category'});
$('input[class*="required-ticket-qty-1"]').CreateBubblePopup({innerHtml: 'You need to select 1 ticket from this price category'});

$('input[class*="default-value"]').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
        }
    });
});

})
