//
// $Id: ThickBoxGeneric.js,v 1.2 2010/07/10 16:47:59 steve Exp $
//
var ThickBoxGeneric = function() {
    
    this.url = new Url()

    this.init = function() {
    
        var self = this
        
        $('.thickBoxCancel').click( function() { tb_remove() })
        $('.mandatory').keyup( function() { self.checkValid($(this)) })
    }

    this.applyThickBox = function(nodes) {

        var self = this

        $(nodes).unbind('click')
        $(nodes).click(
            function() {
                var login = new Login()
                var href = $(this).attr('href')
                if ($(this).hasClass('needLogin') && ! login.isLoggedIn()) {
                    href = href + '&NotLoggedIn=1'
                }
                if ($(this).hasClass('formLink')) {
                    var id = self.url.urlArg(location.href, 'Id')
                    href   = self.url.addIdToHref(href, id) 
                    $(this).attr('href', href)
                }
                $('#clickedURL').val(href)
            })
        tb_init(nodes)
    }
    
    this.applyThickBoxNoLogin = function(nodes) {

        $(nodes).unbind('click')
        $(nodes).click(
            function() {
                var href = $(this).attr('href')
                $('#clickedURL').val(href)
            })
        tb_init(nodes)
    }

    this.checkValid = function(elem) {

        if ($(elem).val()) {
            $(elem).removeClass('invalid')
        }
    }
}


