﻿/* 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);


/* Set Focuses and Searches */

var topSB = null;
var msf = "EVENT, ARTIST OR TEAM";
var focusElements = new Array();

function setHFI(t, tfoc, funct, css) {
    if(typeof(t.hasFocus) == "undefined") {
        t.tfoc = tfoc;
        t.funct = funct;
        t.css = css;
        if (typeof(t.vfoc) == "undefined") t.vfoc = 0;
        t.onblur = function(){setHFB(t)};
        focusElements.push(t.id);
    }
    t.hasFocus = true;
    t.className= t.css + "_o";
    if(t.value.toLowerCase() == tfoc[t.vfoc].toLowerCase()) t.value = "";
}

function setHFB(t) {
    if (t.value == "") {
        t.value = t.tfoc[t.vfoc];
        t.className=t.css;
    }
    t.hasFocus = false;
}

/* Main Search */

var autocomplete = false;

function doSearch() {
   if(!autocomplete) {
       var a = topSB;
       if(a.value == "" || a.value == msf) return false;
       document.location.href = "/find-tickets/" + cleanInputData(a.value) + "/";
   }
   return false;   
}



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 != "") {
                    if(elem.hasFocus == 1) eval(elem.funct)();
                }
            }
        }
        return false;
    } 
}

/* Do OnLoad  ------------------------------------------------- */
/* Menu Fixes  ------------------------------------------------- */

var muitems = "/com/img/mu/"
var reg_btn = /(\-o)*\.(?:(jpg)|(gif)|(png))/;

gsHover = function() {     
    var gsME = document.getElementById("GSMenu").getElementsByTagName("li");     
    for (var i=0; i<gsME.length; i++) {         
        gsME[i].onmouseover=function() {
            this.className+=" over";
            this.el = getElementsByClass("cho", this, "img");
            if(this.el.length > 0) {
                for(this.j=0;this.j<this.el.length;this.j++) {
                    this.el[0].src = this.el[0].src.replace(reg_btn, "-o.$2");
                }
            }
        }         
        gsME[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" over\\b"), "");
            for(this.j=0;this.j<this.el.length;this.j++) {
                this.el[0].src = this.el[0].src.replace(reg_btn, ".$2");
            }
        }     
    } 
} 

function deferredJS() { 
var element = document.createElement("script"); 
element.src = "//support.gamestub.com/visitor/index.php?_m=livesupport&_a=htmlcode&departmentid=0"; 
document.body.appendChild(element); 
}

function doOL() {gsHover(); deferredJS();}
if(window.attachEvent) window.attachEvent("onload", doOL);
else if (window.addEventListener) window.addEventListener("load", doOL, false);
else if (window.onload) window.onload = doOL();