﻿BenefulMap.ModalSendToPhone = BenefulMap.ModalForm.extend({
	init: function(modalTitle, modalElements, modalOptions, snippetPath, params, formElements, context) {
		this._super( modalTitle, modalElements, modalOptions, snippetPath, params, formElements);
	},
	showThankYou: function() {
		this.setTitle("Thank You");
		var params = {};
		params.ph = 2;
		params.id = jQuery.url.attr("file").replace(".aspx", "");
		this.setParams(params);
		this.populate();
	},
	redisplayFormWithMessage: function(message) {
		var params = {};
		params.ph = 1;
		params.id = jQuery.url.attr("file").replace(".aspx", "");
        params.message = message;
        this.setParams(params);
        this.populate();
	},
	submitFormData: function() {
		this._super();
		var self = this;
		var businessId = parseInt(jQuery.url.attr("file").replace(".aspx", ""));
		var smsId = parseInt(this.getIndividualFormData("Carrier"));
		var mobileNumber = this.getIndividualFormData("PhoneAreaCode") + this.getIndividualFormData("PhonePrefix") + this.getIndividualFormData("PhoneSuffix");
		WagWorld.Web.AjaxUtility.SendToMobile(businessId, smsId, mobileNumber, function(result) {
			self.checkResult(result.value.Pass, result.value.Reason);
		});
	},
	checkResult: function(pass, msg) {
        if (pass == true) {
            this.showThankYou();
        } else {
            this.redisplayFormWithMessage(msg);
        }
	}
});

