﻿function MLX_MobilePromo(myID, sourceDivID, targetDivID) {
    this.myID = myID;
    this.load = MLX_LoadMobilePromo;
    this.setup = MLX_SetupMobilePromo;
    this.show = MLX_ShowMobilePromo;
    this.sendSMSLink = MLX_PromoSendSMS;
    this.position = MLX_PositionMobilePromo;

    this.targetDivID = targetDivID;
    this.sourceDivID = sourceDivID;
    this.tabsID = "MLX_MobilePromoTabs";
    this.sendSMSButtonID = "btnSendMobileLink";
    this.sendSMSPhoneID = "txtSendMobileLinkPhone";
    this.sendSMSCarrierListID = "cboSendMobileLinkProvider";
    
    this.promoSourceUrl = "/mobile/promo/promo.aspx?x=" + new Date().getMilliseconds();
}

function MLX_ShowMobilePromo() {
    if (this.targetDivID != null) {
        $("#" + this.targetDivID).dialog('open');
        this.position();
    }
}

function MLX_LoadMobilePromo() {
    if (this.targetDivID == null)
        MLX_MobilePromoCallback();
    else
        $("#" + this.targetDivID).load(this.promoSourceUrl + " #" + this.sourceDivID,
           MLX_MobilePromoCallback).dialog({
               modal: true,
               title: "Search Properties With Your Mobile Phone",
               width: 550,
               zIndex: 99999,
               bgiframe: true 
           });
}

function MLX_SetupMobilePromo() {
    $("#" + this.tabsID).tabs();   
    $("#" + this.sendSMSPhoneID).showDefaultText("Your Phone Number");
    MLX_LoadSMSCarriers(this.sendSMSCarrierListID);
    
    this.position();
    var phoneid = this.sendSMSPhoneID;
    var carrierid = this.sendSMSCarrierListID;
    $("#" + this.sendSMSButtonID).click(function() {
        MLX_PromoSendSMS(phoneid, carrierid);
    });
}

function MLX_PositionMobilePromo() {
    if (this.targetDivID != null) {
        var targetDiv = $("#" + this.targetDivID);
        var left = ($(window).width() - targetDiv.width()) / 2;
        var top = ($(window).height() - targetDiv.height()) / 2;
        targetDiv.dialog('option', 'position', [left, top]);
    }
}

function MLX_PromoSendSMS(sendSMSPhoneID, sendSMSCarrierListID) {
    MLX_SendSMSMessage(sendSMSPhoneID, sendSMSCarrierListID,
        "A message with the link has been sent to your phone",
        "/mobile/promo/promo.aspx?sendsms=yes")
}

