//
// $Id: ContactUs.js,v 1.2 2010/07/10 16:47:58 steve Exp $
//
var ContactUs = function() {

    this.id        = ''
    this.type      = ''
    this.name      = ''
    this.contact   = ''
    this.subject   = ''
    this.email     = ''
    this.phone     = ''    
    this.message   = ''
    this.emailOnly = 0

    this.url = new Url()

    this.submitContactUs = function(type, id, contactId) {

        // type and id optional
        //
        var self = this

        if (type) { self.type      = type      }
        if (id)   { self.id        = id        }
        if (id)   { self.contactId = contactId }

        if ($('#contactName').length > 0)    { self.name      = $('#contactName').val()      }
        if ($('#contactContact').length > 0) { self.contactId = $('#contactContactId').val() }
        if ($('#contactSubject').length > 0) { self.subject   = $('#contactSubject').val()   }
        if ($('#contactPhone').length > 0)   { self.phone     = $('#contactPhone').val()     }
        if ($('#contactEmail').length > 0)   { self.email     = $('#contactEmail').val()     }
        if ($('#contactMessage').length > 0) { self.message   = $('#contactMessage').val()   }

        var page    = self.url.urlPage(location.href)

        if (! self.emailOnly) {
            if (self.email == '' && self.phone == '') {
                alert('Please enter an email or phone number.')
                return
            }
        }

        $.ajax({
                  type:     'POST',
                  url:      AJAXURL,
                  data:     'Action=submitContactUs&Name=' + self.name +
                                                  '&Email=' + self.email +
                                                  '&ContactId=' + self.contactId +
                                                  '&Subject=' + self.subject +
                                                  '&Phone=' + self.phone +
                                                  '&Message=' + self.message +
                                                  '&Page=' + page +
                                                  '&Type=' + self.type +
                                                  '&Id=' + self.id,
                  dataType: 'json',
                  timeout:  40000,
            error:
                function() {
                    return false;
                },
            success:
                function(data) {
                    if (data.Error) {
                        alert(data.Message)
                    } else {
                        alert(data.Message)
                    }
                    tb_remove()
                }
        })
    }
}