﻿
if ($(".pd_photos_tab_photos img").length > 0) {
    var link = document.createElement("LINK");
    link.rel = "image_src"
    link.href = $(".pd_photos_tab_photos img")[0].src;
    $("head").add(link);
}

$(document).ready(function() {

    $("#pd_actions_sms_opendialog").click(OpenSMSDialog);
    $("#pd_actions_sms_cancel").click(function() { $("#mobileDialog").dialog('close'); });
    $("#pd_actions_sms_send").click(SendMessage);

    function OpenSMSDialog() {
        MLX_LoadSMSCarriers("pd_SMS_cboSMSCarriers");
        $("#mobileDialog").dialog(
        { modal: true,
            title: "Send Listing To Phone"
        }
        ).dialog('open');
    }

    function SendMessage() {
        var phone = SE_StripNonDigit($("#pd_SMS_txtPhone").val());

        var carrier = $("#pd_SMS_cboSMSCarriers").val();

        if (!SE_IsPossiblePhoneNumber_Accurate(phone)) {
            alert("Please enter a valid phone number.")
            $("#pd_SMS_txtPhone").focus();
        }
        else if (carrier == "") {
            alert("Please select your mobile carrier from the list.");
            $("#pd_SMS_cboSMSCarriers").focus();
        }
        else {
            $.post(location.href, {
                phone: phone,
                domain: carrier,
                listingid: SE_PD_Current_ListingID,
                postaction: 'sendsms'
            },
                function(data) {
                    if (data == "Success") {
                        alert("Your message was sent.");
                        $("#mobileDialog").dialog('close');
                    }
                    else {
                        if (data.length < 500)
                            alert(data);
                        else
                            alert("We had a problem sending your message.");
                    }
                });


        }
    }
})
