﻿function highlightTickets(e,bool)
{
    if(bool=="TRUE")
    { 
        e.style.backgroundColor="#fff69d";
    }
    else
    {
         e.style.backgroundColor="#ffffff";
    }  
}

function sortColumn(x)
{
 try
    {
    var strSort = "Up";
    if(returnObj("imgSortUp"+x).style.display!="none")
    {
         strSort = "Down";
    }
    var strImgs = "S,R,Q,P".split(",");
    var n;
    var IMCookie = "IM_" + getPageName().toUpperCase();      
    for(n in strImgs)
    {
        returnObj("imgSortUp"+strImgs[n]).style.display="none";
        returnObj("imgSortDown"+strImgs[n]).style.display="none";
        returnObj("imgSortDown"+strImgs[n]+"x").style.display="inline";
    }
    returnObj("imgSortDown"+x+"x").style.display="none"; 
    returnObj("imgSort"+strSort+x).style.display="inline";
   
    returnObj("divTicketHeaderSection").style.background="url('/Images/Global/tl_column_bgX.png')";
    returnObj("divTicketHeaderRow").style.background="url('/Images/Global/tl_column_bgX.png')";
    returnObj("divTicketHeaderPrice").style.background="url('/Images/Global/tl_column_bgX.png')";
    returnObj("divTicketHeaderQty").style.background="url('/Images/Global/tl_column_bgX.png')";
     
   
    var strSortField = "Price";
    switch(x)
    {
        case "S":
            strSortField = "Section";
            break;
        case "R":
            strSortField = "Row";
            break;
        case "Q":
            strSortField = "Qty";
            break;
        case "P":
            strSortField = "Price";
            break;
    }
    returnObj("divTicketHeader"+strSortField).style.backgroundImage="url('/Images/Global/tl_column_bg.png')";
    
    var strSortDirection = "ASC";
    if(strSort=="Down"){strSortDirection="DESC";}

    returnObj("hidSortField").obj.value=strSortField;
    returnObj("hidSortDirection").obj.value=strSortDirection;

    var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/GetTicketList";
    var nBrokerID = returnObj("hidBrokerId").obj.value;
    var nEventID = returnObj("hidEventId").obj.value;
    var nMinPrice = returnObj("ddMinPrice").obj.options[returnObj("ddMinPrice").obj.selectedIndex].value;
    var nMaxPrice = returnObj("ddMaxPrice").obj.options[returnObj("ddMaxPrice").obj.selectedIndex].value;
    var nQty = returnObj("ddFilterQty").obj.options[returnObj("ddFilterQty").obj.selectedIndex].value;
    var strFilter = returnObj("hidFilter").obj.value;
    var bTransform = "true"
    var strSections = readCookie(IMCookie); 
   var bFilterParking = returnObj("hidFilterParking").obj.value;

    showHide("divTicketListingsLoading","show");
    showHide("divTicketListings","hide");
    showHide("divTicketListingsAjax","hide"); 
    showHide("divTicketFilters","hide");
    showHide("divTicketColumnHeaders","hide"); 
    showHide("divTicketSummary","hide"); 

    var strParams = "BrokerID="+nBrokerID+"&EventID="+nEventID+"&MinPrice="+nMinPrice+"&MaxPrice="+nMaxPrice+"&Qty="+nQty+"&Sort="+strSortField+" "+strSortDirection+"&Filter="+strFilter+"&Transform="+bTransform+"&SectionList="+strSections+"&FilterParking="+bFilterParking;
    ajaxPost(strParams,strServiceURL,"renderTickets");
   }
   catch(ex)
   {
        var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_sortColumn [" + x + "]&bIsHtmlMsg=true";
        ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }
}

function renderTickets(xml)
{
    /*alert(xml);*/
    try
    {
        returnObj("divTicketListingsAjax").obj.innerHTML=xml;
        showHide("divTicketListingsAjax","show");
        showHide("divTicketFilters","show");
        showHide("divTicketColumnHeaders","show");
        showHide("divTicketSummary","show");  
        showHide("divTicketListingsLoading","hide");
    }
   catch(ex)
   {
        var strException = getDebugInfo()+getExceptionInfo(ex)+"<textarea rows=\"10\" cols=\"100\">"+xml.toString()+"</textarea>";
        var strParams = "strErrorMsg="+strException+"&strSubject=JS_Exception_renderTickets&bIsHtmlMsg=true";  
        ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }    
}

function filterTickets(type)
{
    try
    {
        showHide("divTicketListingsLoading","show");
        showHide("divTicketListings","hide");
        showHide("divTicketListingsAjax","hide");
        showHide("divTicketFilters","hide");
        showHide("divTicketColumnHeaders","hide");
        showHide("divTicketSummary","hide"); 
     
        var IMCookie = "IM_" + getPageName().toUpperCase();      
        var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/GetTicketList";
        var nBrokerID = returnObj("hidBrokerId").obj.value;
        var nEventID = returnObj("hidEventId").obj.value;
        var strSections = readCookie(IMCookie); 
        
        var nMinPrice = 0;
        var nMaxPrice = 0;
       
        switch(type)
        {
            case "MIN":
                if(returnObj("ddMinPrice").obj.selectedIndex>returnObj("ddMaxPrice").obj.selectedIndex)
                {
                    returnObj("ddMaxPrice").obj.selectedIndex=returnObj("ddMinPrice").obj.selectedIndex
                }
                break;
            case "MAX":
                if(returnObj("ddMinPrice").obj.selectedIndex>returnObj("ddMaxPrice").obj.selectedIndex)
                {
                    returnObj("ddMinPrice").obj.selectedIndex=returnObj("ddMaxPrice").obj.selectedIndex
                }
                break;
        } 

        nMinPrice = returnObj("ddMinPrice").obj.options[returnObj("ddMinPrice").obj.selectedIndex].value; 
        nMaxPrice = returnObj("ddMaxPrice").obj.options[returnObj("ddMaxPrice").obj.selectedIndex].value;
        
        var nQty = returnObj("ddFilterQty").obj.options[returnObj("ddFilterQty").obj.selectedIndex].value;
        var strSortField = returnObj("hidSortField").obj.value;
        var strSortDirection = returnObj("hidSortDirection").obj.value;
        var strFilter = returnObj("hidFilter").obj.value;
        var bTransform = "true";
        
        returnObj("hidFilterParking").obj.value = returnObj("chkFilterParking").obj.checked;
        var bFilterParking = returnObj("hidFilterParking").obj.value;

        var strParams = "BrokerID="+nBrokerID+"&EventID="+nEventID+"&MinPrice="+nMinPrice+"&MaxPrice="+nMaxPrice+"&Qty="+nQty+"&Sort="+strSortField+" "+strSortDirection+"&Filter="+strFilter+"&Transform="+bTransform+"&SectionList="+strSections+"&FilterParking="+bFilterParking;
        ajaxPost(strParams,strServiceURL,"renderTickets");
   }
   catch(ex)
   {
        var strException = getDebugInfo()+getExceptionInfo(ex);
        var strParams = "strErrorMsg="+strException+"&strSubject=JS_Exception_filterTickets [" + type + "]&bIsHtmlMsg=true";  
        ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }
}

function initSortColumn()
{
    try
    {
        var strSortD;
        if(returnObj("hidDefaultSortDirection").obj.value=="ASC")
        {
            strSortD="Up";
        }
        else
        {
            strSortD="Down";
        }
        var x = returnObj("hidDefaultSortField").obj.value.substring(0,1);
        returnObj("imgSort"+strSortD+x).style.display="inline";
        returnObj("imgSortDown"+x+"x").style.display="none";

        var strSortField = "Price";
        switch(x)
        {
            case "S":
                strSortField = "Section";
                break;
            case "R":
                strSortField = "Row";
                break;
            case "Q":
                strSortField = "Qty";
                break;
            case "P":
                strSortField = "Price";
                break;
        } 
        returnObj("divTicketHeader"+strSortField).style.backgroundImage="url('/Images/Global/tl_column_bg.png')";
   }
   catch(ex)
   {
        var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_initSortColumn&bIsHtmlMsg=true";  
        ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }    
}

function resetListings()
{
    try
    {
        var IMCookie = "IM_" + getPageName().toUpperCase();
        if (readCookie(IMCookie))
        {
            reloadFlashMap(); 
        }
        if (returnObj("divDetailedIMapInstructionsWrapper").style.display=="")
        {
            showHideMapInstructions('hide');                              
        }        
        returnObj("ddMinPrice").obj.selectedIndex=0;
        returnObj("ddMaxPrice").obj.selectedIndex=returnObj("ddMaxPrice").obj.options.length-1;
        returnObj("ddFilterQty").obj.selectedIndex=0;
        sortColumn(returnObj("hidDefaultSortField").obj.value.substring(0,1));
   }
   catch(ex)
   {
        var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_resetListings&bIsHtmlMsg=true";  
        ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }        
}

function TicketSignup (emailID, email, brokerID, rttID)
{

    if(validateField(emailID,'show','divBlankEmail2','divBadEmail2', '') && validateEmail(emailID,'divBlankEmail2','divBadEmail2'))
    {
		args = new Array();
		for(n=0; n<arguments.length; n++)
		{
			args[n] = arguments[n];
		}

		var strParams = "RemoteIP="+readCookie("IPAddress")+"&Challenge="+returnObj("recaptcha_challenge_field").obj.value+"&Response="+returnObj("recaptcha_response_field").obj.value;
		var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/ReCaptcha";
		ajaxPost(strParams,strServiceURL,"SignupForTix_ReCaptcha",args);
    }
}

function SignupForTix_ReCaptcha()
{
	xml = arguments[0];
	txtEmail = arguments[1][0];
	strEmail = arguments[1][1];
	nBrokerID = arguments[1][2];
	nRTTID = arguments[1][3];

	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}

    switch(xmlDoc.getElementsByTagName("ReCaptcha")[0].getAttribute("StatusCode"))
    {
        case "0":

			SignupForTix(strEmail,nBrokerID,nRTTID);
			returnObj("divSuccess").style.display="";

			// reset the form
			bEmailSignupExpanded=false;
			returnObj("txtSignupAlerts").obj.value="";
			returnObj('divReCaptcha').style.display='none';
			returnObj('btnCancelEmailSignUp').style.display='none';

            break;
        default:
			alert("The words entered into the verification box were incorrect!\n\nPlease try again or call 1-800-521-9616 to speak with a representative.");
            break;
    }
	Recaptcha.reload(); 
}

function SignupForTix(email, brokerID, rttID)
{
    var strParams = "strCB="+rttID+"&nBrokerID="+brokerID+"&EmailAddress="+email;
    var strServiceURL =  "http://"+location.hostname+"/ws/tcws.asmx/LogNewsLetter";
    ajaxPost(strParams,strServiceURL,"fnNada");
}

function iPhoneAlert()
{
	if((navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i))&&(readCookie("bIPhoneAlert")!="true"))
	{
		createCookie("bIPhoneAlert","true",365);
		showHideModalBG("show");
		showHide("divIPhoneAlertWindowWrapper","show");
		returnObj("divIPhoneAlertWindow").style.left=(returnObj("divMain").obj.offsetLeft+(returnObj("divMain").obj.offsetWidth/2))-(returnObj("divIPhoneAlertWindow").obj.offsetWidth/2)+"px";
		returnObj("aIPhoneAlertHeader").obj.focus(); /*ff,safari*/
	}
}
