﻿/* Varibales */
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );

var is_gecko = (agt.indexOf('gecko') != -1);
var is_opera = (agt.indexOf("opera") != -1);
var js_addthis = false;


/* Preload Dark Corners */

var c1_img = new Image();
c1_img.src = "http://www.stub.com/com/css/corners/w-ac.png";
var c2_img = new Image();
c2_img.src = "http://www.stub.com/com/css/corners/b-ac.png";
var c3_img = new Image();
c3_img.src = "http://www.stub.com/com/css/corners/lb-ac.png";

/* Search Function */

var focusElements = new Array();
var autocomplete = false;

function sendtosearch(el) {
    var val = el.value;
    if(!autocomplete) {
       if(val == "" || val == el.base) return false;
       document.location.href = "http://www.stub.com/find-tickets/" + cleanInputData(val) + "/";
   }
   return false;
}

function setelementbase(el, base) {el.base = base; el.value = base; el.hasfocus = false;}

function setinputfocus(el, focus, funct) {
    if(focus == true) {
        if(typeof(el.funct) == "undefined") {
            focusElements.push(el.id);
            el.funct = funct;
            el.hasfocus = true;
            el.onblur = function() {setinputfocus(this, false, null)};
        }
        if(el.value.toLowerCase() == el.base.toLowerCase()) el.value = "";
    }else{
        if(el.value == "") el.value = el.base;
        el.hasfocus = false;
    }
}


/* AutoComplete */

function itemSelected(ev){
    autocomplete = true;
    var index=$find("AutoCompleteEx")._selectIndex;
    var aci = $find("AutoCompleteEx").get_completionList().childNodes[index];
    var dd=aci._value;
    $find("AutoCompleteEx").get_element().value = aci._display;
    document.location.href=dd;
    return false;
}

function onClientPopulated(sender,e){
    var comletionList=$find("AutoCompleteEx").get_completionList();
    for(i=0;i<comletionList.childNodes.length;i++){    
        var _v = eval(comletionList.childNodes[i]._value);
        var iname = _v[0];
        var ibname = _v[1];
        var iurl= _v[2];
        comletionList.childNodes[i]._value=iurl;
        comletionList.childNodes[i]._display=iname;
        comletionList.childNodes[i].innerHTML=ibname;
    } 
}

/* Capture Keys */

function captureEvent() {
    if(event.keyCode==13) {
        for(i=0; i<focusElements.length; i++) {
            var elem = document.getElementById(focusElements[i]);
            if(typeof(elem.hasfocus) != "undefined") {
                if(elem.funct != "" && elem.funct != null) {
                    if(elem.hasfocus == true) eval(elem.funct);
                }
            }
        }
        return false;
    } 
}


/* Do OnLoad  ------------------------------------------------- */
/* Menu Fixes  ------------------------------------------------- */

menuHover = function() {     
    var li = document.getElementById("StubMenu").getElementsByTagName("li");     
    for (var i=0; i<li.length; i++) {         
        li[i].onmouseover=function() {
            this.className+=" over";
        }         
        li[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" over\\b"), "");
        }     
    } 
} 


function deferredJS() { 
var element = document.createElement("script"); 
element.src = "//support.stub.com/visitor/index.php?_m=livesupport&_a=htmlcode&departmentid=0"; 
document.body.appendChild(element); 
}


function doOL() {
    if(is_ie6) menuHover(); 
    deferredJS();  
}


if(window.attachEvent) window.attachEvent("onload", doOL);
else if (window.addEventListener) window.addEventListener("load", doOL, false);
else if (window.onload) window.onload = doOL();