﻿/// <reference name="MicrosoftAjax.js" />

var BaseUI =
{
    Initialize: function() 
    {
        BaseUI.ShowTripAdvisorPopUp()
    },
    Expand: function(el) 
    {
        if (el) 
        {
            el.style.visibility = 'visible'
            el.style.display    = 'block'
        }
    },
    Collapse: function(el) 
    {
        if (el) 
        {
            el.style.visibility = 'hidden'
            el.style.display    = 'none'
        }
    },
    Show: function(el) 
    {
        if (el) 
        {
            el.style.visibility = 'visible'
        }
    },
    Hide: function(el) 
    {
        if (el) 
        {
            el.style.visibility = 'hidden'
        }
    },
    IsVisible: function(el) 
    {
        if (el) 
        {
            return el.style.visibility.toLowerCase() == 'visible'
        }

        return false
    },
    RemoveAllChildren: function(el) 
    {
        while (el.childNodes.length > 0) el.removeChild(el.childNodes[0])
    },
    SetClass: function(el, className) 
    {
        if (el) 
        {
            if ((Sys.Browser.agent == Sys.Browser.InternetExplorer) && (Sys.Browser.version < 8)) 
            {
                el.className = className
            }
            else 
            {
                el.setAttribute("class", className)
            }
        }
    },
    DaysInMonth: function(date) 
    {
        return 32 - new Date(date.getFullYear(), date.getMonth(), 32).getDate();
    },
    MakeRequest: function(url, verb, data, func, obj) 
    {
        var TheRequest = new Sys.Net.WebRequest()

        TheRequest.set_url(url)
        TheRequest.set_httpVerb(verb)

        if (data) 
        {
            TheRequest.set_body(data)
            TheRequest.get_headers()["Content-Length"] = data.length;
        }

        TheRequest.set_userContext(new RequestParams(func, obj))
        TheRequest.add_completed(BaseUI.MakeRequestComplete)
        TheRequest.invoke()

        return TheRequest
    },
    MakeRequestComplete: function(executer, eventArgs) 
    {
        var TheParams = executer.get_webRequest().get_userContext()

        if (executer.get_responseAvailable()) 
        {
            TheParams.responseData = executer.get_responseData().replace(/\u2028/g, '')
        }
        else 
        {
            TheParams.responseData = null
        }
        if (TheParams.func) TheParams.func(TheParams)
    },
	ShowTripAdvisorPopUp: function()
	{
		$('div.trip-advisor button.ta').click(function(e)
		{
			$(this).siblings('.ta-popup').fadeIn(250);
			e.preventDefault();
		});
		
		$('div.trip-advisor .cancel').click(function()
		{
			$(this).parent().parent('.ta-popup').fadeOut(100);
		});
	}
}

$(document).ready(BaseUI.Initialize);

function RequestParams(afunc, obj) 
{
    this.func         = afunc
    this.responseData = null
    this.obj          = obj
    this.Error        = null
}
