﻿<html>
<head>
    <meta charset="utf-8" />
    <script type="text/javascript">

        function updateFacilityLocation() {

            // saves the entered data and refreshes the form without refreshing the page
            Xrm.Page.data.refresh(save).then(successCallback, errorCallback);

        }

        function resetToSource() {

            //sets variables from Source Form
            var srcName = window.parent.Xrm.Page.getAttribute("btsss_src_name").getValue();
            //var srcName = $('#btsss_src').val();
            var srcLine1 = window.parent.Xrm.Page.getAttribute("btsss_src_addr_line1").getValue();
            var srcLine2 = window.parent.Xrm.Page.getAttribute("btsss_src_addr_line2").getValue();
            var srcCity = window.parent.Xrm.Page.getAttribute("btsss_src_city").getValue();
            var srcState = window.parent.Xrm.Page.getAttribute("btsss_src_state").getValue();
            var srcZipCode = window.parent.Xrm.Page.getAttribute("btsss_src_zipcode").getValue();
            var srcStationNumber = window.parent.Xrm.Page.getAttribute("btsss_src_stationnumber").getValue();
            var srcClass = window.parent.Xrm.Page.getAttribute("btsss_src_class").getValue();
            var srcType = window.parent.Xrm.Page.getAttribute("btsss_src_facilitytype").getValue();
            var srcRegion = window.parent.Xrm.Page.getAttribute("btsss_src_regionid").getValue();
            var srcVISN = window.parent.Xrm.Page.getAttribute("btsss_src_visnid").getValue();

            //changes values in Facility Information Form
            window.parent.Xrm.Page.getAttribute("btsss_name").setValue(srcName);
           // $('#btsss_name').append(srcName);
            window.parent.Xrm.Page.getAttribute("btsss_addr_line1").setValue(srcLine1);
            window.parent.Xrm.Page.getAttribute("btsss_addr_line2").setValue(srcLine2);
            window.parent.Xrm.Page.getAttribute("btsss_city").setValue(srcCity);
            window.parent.Xrm.Page.getAttribute("btsss_state").setValue(srcState);
            window.parent.Xrm.Page.getAttribute("btsss_zipcode").setValue(srcZipCode);
            window.parent.Xrm.Page.getAttribute("btsss_stationnumber").setValue(srcStationNumber);
            window.parent.Xrm.Page.getAttribute("btsss_class").setValue(srcClass);
            window.parent.Xrm.Page.getAttribute("btsss_facilitytype").setValue(srcType);
            window.parent.Xrm.Page.getAttribute("btsss_regionid").setValue(srcRegion);
            window.parent.Xrm.Page.getAttribute("btsss_visnid").setValue(srcVISN);
            alert("The location information has been reset.");

            //saves the form
            window.parent.Xrm.Page.data.entity.save();

        }

    </script>
</head>
<body style="border-width: 0px; padding-left: 0px; padding-top: 0px; margin-left: 0px; margin-top: 0px; margin-bottom: 0px">

    <button type="button" onclick="resetToSource()" title="Reset Facility Information to Default" style="padding-bottom: 2px; padding-top: 2px;">
         Reset to Source Values 
    </button>

</body>
</html>