// Common Javascript Functions
var _appPath = '';

document.observe("dom:loaded", function() {
    if (document.images) {
        //GROUP
        groupE = new Image(); groupE.src = _appPath + "images/seatmaps/groupE.gif";
        groupS = new Image(); groupS.src = _appPath + "images/seatmaps/groupS.gif";
        groupW = new Image(); groupW.src = _appPath + "images/seatmaps/groupW.gif";
        groupN = new Image(); groupN.src = _appPath + "images/seatmaps/groupN.gif";

        //SEASON
        season101l = new Image(); season101l.src = _appPath + "images/seatmaps/season101l.png";
        season101u = new Image(); season101u.src = _appPath + "images/seatmaps/season101u.png";
        season103l = new Image(); season103l.src = _appPath + "images/seatmaps/season103l.png";
        season103u = new Image(); season103u.src = _appPath + "images/seatmaps/season103u.png";
        season104l = new Image(); season104l.src = _appPath + "images/seatmaps/season104l.png";
        season104u = new Image(); season104u.src = _appPath + "images/seatmaps/season104u.png";
        season106l = new Image(); season106l.src = _appPath + "images/seatmaps/season106l.png";
        season106m = new Image(); season106m.src = _appPath + "images/seatmaps/season106m.png";
        season106u = new Image(); season106u.src = _appPath + "images/seatmaps/season106u.png";
        season107l = new Image(); season107l.src = _appPath + "images/seatmaps/season107l.png";
        season107u = new Image(); season107u.src = _appPath + "images/seatmaps/season107u.png";
        season108l = new Image(); season108l.src = _appPath + "images/seatmaps/season108l.png";
        season108m = new Image(); season108m.src = _appPath + "images/seatmaps/season108m.png";
        season108u = new Image(); season108u.src = _appPath + "images/seatmaps/season108u.png";
        season110l = new Image(); season110l.src = _appPath + "images/seatmaps/season110l.png";
        season110u = new Image(); season110u.src = _appPath + "images/seatmaps/season110u.png";
        season111l = new Image(); season111l.src = _appPath + "images/seatmaps/season111l.png";
        season111u = new Image(); season111u.src = _appPath + "images/seatmaps/season111u.png";
        season113l = new Image(); season113l.src = _appPath + "images/seatmaps/season113l.png";
        season113u = new Image(); season113u.src = _appPath + "images/seatmaps/season113u.png";
        season114l = new Image(); season114l.src = _appPath + "images/seatmaps/season114l.png";
        season114u = new Image(); season114u.src = _appPath + "images/seatmaps/season114u.png";
        season115l = new Image(); season115l.src = _appPath + "images/seatmaps/season115l.png";
        season115u = new Image(); season115u.src = _appPath + "images/seatmaps/season115u.png";
        season117l = new Image(); season117l.src = _appPath + "images/seatmaps/season117l.png";
        season117u = new Image(); season117u.src = _appPath + "images/seatmaps/season117u.png";
        season118l = new Image(); season118l.src = _appPath + "images/seatmaps/season118l.png";
        season118u = new Image(); season118u.src = _appPath + "images/seatmaps/season118u.png";
        season120l = new Image(); season120l.src = _appPath + "images/seatmaps/season120l.png";
        season120m = new Image(); season120m.src = _appPath + "images/seatmaps/season120m.png";
        season120u = new Image(); season120u.src = _appPath + "images/seatmaps/season120u.png";
        season121l = new Image(); season121l.src = _appPath + "images/seatmaps/season121l.png";
        season121u = new Image(); season121u.src = _appPath + "images/seatmaps/season121u.png";
        season122l = new Image(); season122l.src = _appPath + "images/seatmaps/season122l.png";
        season122m = new Image(); season122m.src = _appPath + "images/seatmaps/season122m.png";
        season122u = new Image(); season122u.src = _appPath + "images/seatmaps/season122u.png";
        season124l = new Image(); season124l.src = _appPath + "images/seatmaps/season124l.png";
        season124u = new Image(); season124u.src = _appPath + "images/seatmaps/season124u.png";
        season125l = new Image(); season125l.src = _appPath + "images/seatmaps/season125l.png";
        season125u = new Image(); season125u.src = _appPath + "images/seatmaps/season125u.png";
        season127l = new Image(); season127l.src = _appPath + "images/seatmaps/season127l.png";
        season127u = new Image(); season127u.src = _appPath + "images/seatmaps/season127u.png";
        season128l = new Image(); season128l.src = _appPath + "images/seatmaps/season128l.png";
        season128u = new Image(); season128u.src = _appPath + "images/seatmaps/season128u.png";
        seasonCSE = new Image(); seasonCSE.src = _appPath + "images/seatmaps/seasonCSE.png";
        seasonCSS = new Image(); seasonCSS.src = _appPath + "images/seatmaps/seasonCSS.png";
        seasonCSW = new Image(); seasonCSW.src = _appPath + "images/seatmaps/seasonCSW.png";
        seasonCSN = new Image(); seasonCSN.src = _appPath + "images/seatmaps/seasonCSN.png";

        mapoff = new Image(); mapoff.src = _appPath + "images/blank.gif";
    }
});

String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
}

function filterDate(str) {
    if (document.thisform.game.value.trim() == "05/21/2009") {
        show('alertText');
        hide('bestAvailableSeats');
        document.thisform.quantity.disabled = true;
    } else {
        hide('alertText');
        show('bestAvailableSeats');
        document.thisform.quantity.disabled = false;
    }
}

function filterNum(str) {
    fixNum = str.replace(/\D/g, "");
    if (fixNum == "") {
        fixNum.value = fixNum;
    } else {
        fixNum = fixNum.replace(/[^0-9]/g, '');
        fixNum.value = fixNum;
    }
    if (isNaN(fixNum) == true) {
        fixNum = "";
    }
    return fixNum;
}

//GROUP TICKETS
function validate_group() {
    if (document.getElementById('currentLayer')) {
        deleteLayer('currentLayer');
    }

    if (document.thisform.game.value.trim() == "") {
        alert("Please select a game.");
        document.thisform.game.focus();
        return false;
    }
    if (document.thisform.game.value.trim() == "05/21/2009") {
        show('alertText')
        document.thisform.game.focus();
        return false;
    }
    if (document.thisform.quantity.value.trim() == "") {
        alert("Please enter the number of seats you wish to purchase.");
        document.thisform.quantity.focus();
        return false;
    }
    if (document.thisform.quantity.value.trim() < 20) {
        alert("You must enter a minimum of 20 tickets to be eligible for group pricing.");
        document.thisform.quantity.focus();
        return false;
    }

    return true;
}

//SEASON TICKETS
function validate_season() {
    if (document.getElementById('currentLayer')) {
        deleteLayer('currentLayer');
    }

    if (document.thisform.quantity.value.trim() == "") {
        alert("Please enter the number of seats you wish to purchase.");
        document.thisform.quantity.focus();
        return false;
    }
    if (document.thisform.quantity.value.trim() < 1) {
        alert("You must enter a minimum of 1 seat.");
        document.thisform.quantity.focus();
        return false;
    }

    return true;
}

//CORPORATE
function validate_corporate() {
    if (document.getElementById('currentLayer')) {
        deleteLayer('currentLayer');
    }

    if (document.thisform.quantity.value.trim() == "") {
        alert("Please enter the number of seats you wish to purchase.");
        document.thisform.quantity.focus();
        return false;
    }
    if (document.thisform.quantity.value.trim() < 1) {
        alert("You must enter a minimum of 1 seat.");
        document.thisform.quantity.focus();
        return false;
    }

    return true;
}


menu_status = new Array();
function showHide(thisID) {
    if (document.getElementById) {
        var switch_thisID = document.getElementById(thisID);
        if (menu_status[thisID] != 'block') {
            switch_thisID.className = 'block';
            menu_status[thisID] = 'block';
        } else {
            switch_thisID.className = 'hide';
            menu_status[thisID] = 'hide';
        }
    }
}

function show(thisID) {
    if (document.getElementById) {
        var switch_thisID = document.getElementById(thisID);
        switch_thisID.className = 'block';
        menu_status[thisID] = 'block';
    }
}

function hide(thisID) {
    if (document.getElementById) {
        var switch_thisID = document.getElementById(thisID);
        switch_thisID.className = 'hide';
        menu_status[thisID] = 'hide';
    }
}

function rollOn(img1) {
    if (document.images) {
        document.seatmapSpacer.src = eval(img1 + ".src");
    }
}

function rollOff() {
    window.status = "";
    if (document.images) {
        document.seatmapSpacer.src = mapoff.src;
    }
}



if (typeof HTMLElement != "undefined") {
    HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode) {
        switch (where) {
            case 'BeforeBegin':
                this.parentNode.insertBefore(parsedNode, this)
                break;
            case 'AfterBegin':
                this.insertBefore(parsedNode, this.firstChild);
                break;
            case 'BeforeEnd':
                this.appendChild(parsedNode);
                break;
            case 'AfterEnd':
                if (this.nextSibling) this.parentNode.insertBefore(parsedNode, this.nextSibling);
                else this.parentNode.appendChild(parsedNode);
                break;
        }
    }

    HTMLElement.prototype.insertAdjacentHTML = function(where, htmlStr) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var parsedHTML = r.createContextualFragment(htmlStr);
        this.insertAdjacentElement(where, parsedHTML)
    }

    HTMLElement.prototype.insertAdjacentText = function(where, txtStr) {
        var parsedText = document.createTextNode(txtStr)
        this.insertAdjacentElement(where, parsedText)
    }
}

function makeViewLayer(id, L, T, seatsection) {
    if (document.getElementById) {
        if (document.getElementById('currentLayer')) {
            deleteLayer('currentLayer');
        }
		
        var layertitle = seatsection.toUpperCase();
        var layertitle = layertitle.replace('_', ' ');
        var layertitle = layertitle.replace('SECTION', 'SECTION ');
        var layertitle = layertitle.replace('ROWS', 'ROWS ');
		
        var layertitle = layertitle.replace('GROUP EAST', 'Sideline Opposite Storm Bench');
        var layertitle = layertitle.replace('GROUP SOUTH', 'End Zone Near Visitor Bench');
        var layertitle = layertitle.replace('GROUP WEST', 'Sideline Behind Storm Bench');
        var layertitle = layertitle.replace('GROUP NORTH', 'End Zone Near Storm Bench');
		
        var layerStyle = 'position:absolute'
		+ '; left:' + L
		+ '; top:' + T;

        var layerContent = '<div id="currentLayer" class="viewPopup" style="' + layerStyle + '">'
		+ '<div class="closeBar"><a href="#" onclick="deleteLayer(\'currentLayer\')"><img src="' + _appPath + 'images/popup_close.gif" width="16" height="16" alt="" /></a>CLOSE</div><div class="clear"></div>'
		+ '<div class="viewWrapper"><div class="sectionTitle">' + layertitle + '</div>'
		+ '<div class="sectionPic"><img src="' + _appPath + 'images/sectionviews/' + seatsection + '.jpg" /></div>'
		+ '<div class="centerContent"><input type="hidden" name="seat" value="' + seatsection + '"><input type="submit" value="SELECT THESE SEATS" class="controlButton" /></div></div></div>';

        if (document.getElementById("floatView")) {
            if (document.body.insertAdjacentHTML) {
                document.getElementById("floatView").insertAdjacentHTML("BeforeEnd", layerContent);
            } else if (document.createElement && document.getElementById("floatView").appendChild) {
                var newNode = document.createElement('div');
                newNode.setAttribute('id', 'currentLayer');
                newNode.setAttribute('style', layerStyle);
                document.getElementById("floatView").appendChild(newNode);
            }
        }
    }
}

function deleteLayer(id) {
    if (document.getElementById && document.getElementById(id)) {
        var theNode = document.getElementById(id);
        theNode.parentNode.removeChild(theNode);
    } else if (document.all && document.all[id]) {
        document.all[id].innerHTML = '';
        document.all[id].outerHTML = '';
    }
}
