﻿function ajax_tickets(){
    this.callbackid = 'tfunct';
    this.id = null;
    this.groups = null;
    this.pagesize = null;
    this.results = document.getElementById("rw_set");
    this.display = document.getElementById("rw_ft");	
    this.loader = document.getElementById("rw_loader");
    this.minprice = 0;
    this.split = '';
    this.maxprice  = 9999999;
    this.current = 1;
    this.whereclause = '';
    this.sort = '';
}

ajax_tickets.prototype = {
    btns:function() {
        return document.getElementById("rw_btns");
    },
    paging:function(p){
        this.current = this.current + p;
        return this.calltickets();
    },
    sorting:function(s){
        this.current = 1;
        this.sort = s;
        return this.calltickets();
    },
    where:function(w){
        this.current = 1;
        this.whereclause = w;
        
        document.getElementById("minp").value = "0";
        document.getElementById("maxp").value = "9999999";
        document.getElementById("quant").value = "";
        
        return this.calltickets();
    },
    calltickets:function() {
    
        this.minprice = document.getElementById("minp").value;
        this.maxprice = document.getElementById("maxp").value;
        this.split = document.getElementById("quant").value;
        
        this.showloader();
        GameStub.TicketService.TicketResults(this.id, this.current, this.groups, this.pagesize, this.sort, this.minprice, this.maxprice, this.split, this.whereclause, this.oncomplete, this.onfailure);
        return false;
    },
    
    oncomplete:function(ReturnValue){
        var xmlDoc = null;
        if (window.DOMParser){
            parser=new DOMParser();
            xmlDoc=parser.parseFromString(ReturnValue,"text/xml");
        }else{
          xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
          xmlDoc.async="false";
          xmlDoc.loadXML(ReturnValue); 
        } 
    
        tfunct.results.innerHTML = xmlDoc.getElementsByTagName("results")[0].childNodes[0].nodeValue;
        tfunct.display.innerHTML = xmlDoc.getElementsByTagName("paging")[0].childNodes[0].nodeValue;
        tfunct.showresults();
    },
    
    onfailure:function(ReturnValue){
        tfunct.results.innerHTML = "Failed To Gather Results";
        tfunct.display.innerHTML = "";
        tfunct.showresults();
    },

    showloader:function() {
        this.results.style.display = "none";
        this.btns().style.display = "none";
        this.loader.style.display = "block";
    },
    
    showresults:function() {
        this.loader.style.display = "none";
        this.results.scrollTop = 0;
        this.results.style.display = "block";  
    }
}


function flipImages(a) {
    if(a == 0) {
    
        document.getElementById("stickets").src = "/com/img/tp/show-tickets.jpg";
        document.getElementById("sparking").src = "/com/img/tp/showing-parking.jpg";
        
        tfunct.results.style.display = "none";
        tfunct.results = document.getElementById("pw_set");
        tfunct.showresults();
       
    }else if(a == 1) {
    
        document.getElementById("stickets").src = "/com/img/tp/showing-tickets.jpg";
        document.getElementById("sparking").src = "/com/img/tp/show-parking.jpg";
        
        tfunct.results.style.display = "none";
        tfunct.results = document.getElementById("rw_set");
        
        if(typeof(ssc) == "function") {
            ssc.setMapOptions("clearSectionSelect=*");
            ssc.criteriaChanged("MinPrice=0&MaxPrice=0&ReqQty=0");
            $("#quant").attr("selectedIndex", 0);
            $("#minp").attr("selectedIndex", 0);
            $("#maxp").attr("selectedIndex", 0);
        }else{
            tfunct.whereclause='';
        }
                
        tfunct.showresults();
    }
}

function makeGuid(){
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
	var guid_length = 5;
	var guid = '';
	for (var i=0; i<guid_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		guid += chars.substring(rnum,rnum+1);
	}
	return guid;
}

function gc(id, price) {
    var spsource = getCookie("gs-source");
    var adsource = "";
    if (spsource != null) adsource = "&GSSourceID=" + spsource

    var split = document.getElementById("qu" + id).value;
    var oURL = "https://secure.gamestub.com/checkout/checkout.aspx?brokerid=3214&sitenumber=2&tgid=" + id + "&treq=" + split + "&evtID=" + eventID + "&price=" + price + "&SessionId=" + makeGuid() + adsource;
    window.location.href = oURL;
    return false;
}