<html><head><title>North52 Formula Manager Timezone</title>
<script src="ClientGlobalContext.js.aspx"></script>

<script type="text/javascript" src="north52_/javascript/jquery"></script>

<script type="text/javascript" src="north52_/javascript/north52.htmlwebresource.helper"></script>

<script type="text/javascript" src="north52_/javascript/north52_dialog_helper"></script>

<script type="text/javascript" src="north52_/javascript/sdk.rest"></script>
<script type="text/javascript" src="north52_/javascript/JSON2"></script>

<script type="text/javascript">

var Timezone = {}; 


Timezone.Init= function() {  

try
{
    $("#ddlTimezone").hide();
    $("select[id$=ddlTimezone] > option").remove();
 
    var options= "$select=UserInterfaceName,TimeZoneCode&$orderby=UserInterfaceName asc";

       SDK.REST.retrieveMultipleRecords("TimeZoneDefinition", options, Timezone.RetrieveEntityData, function (error) { window['n52error'] = error; window['executionContext'] = null; alert("North52 Formula Manager: An error has occurred please contact your system administrator."  ); }, Timezone.RetrieveComplete);

   
 }
 catch(ex)
 {
    alert('North52 Formula Manager: Communication issue, please click Ok & then F5 to refresh the screen. Message: ' + ex.message);

 }

};



Timezone.RetrieveEntityData= function(data) {  

 try
 {

    for (var i = 0; i < data.length; i++)
    {
      N52.HTMLWebResourceHelper.InsertOptionSetItem("ddlTimezone", data[i].UserInterfaceName , data[i].TimeZoneCode );    
    }

        var savedTimezone = parent.Xrm.Page.getAttribute("north52_timezonekey").getValue();
       N52.HTMLWebResourceHelper.InsertOptionSetItemAtTop("ddlTimezone", '' , '' );     

    if (savedTimezone !== null && savedTimezone !=="") 
    {  
            $("#ddlTimezone").val(savedTimezone);
      }
      else
      {
         $("#ddlTimezone").val('');    
         parent.Xrm.Page.data.entity.attributes.get("north52_timezonekey").setValue("");
      }
     
   $('#loading').hide(); 
   $('#ddlTimezone').show(); 

 }
 catch(ex)
 {
   alert('North52 Formula Manager: Communication issue, please click Ok & then F5 to refresh the screen. Message: ' + ex.message);
 }

  };



Timezone.DropDownChanged= function(value) {  
 
  try
  {
    if (value != null && value!="")
    {  
       parent.Xrm.Page.data.entity.attributes.get("north52_timezonekey").setValue(value);
     }
     else
     {
         parent.Xrm.Page.data.entity.attributes.get("north52_timezonekey").setValue("");
     }

   }
   catch(ex)
   {
      alert('North52 Formula Manager: Communication issue, please click Ok & then F5 to refresh the screen. Message: ' + ex.message);
   }
} ; 


Timezone.RetrieveComplete= function(value) {  

         var msg = 'Complete';
  };


</script>

<style type="text\css">
#loading { 
  width: 100%; 
  height: 100%; 
  top: 0px; 
  left: 0px; 
  opacity: 0.7; 
  background-color: #fff; 
  z-index: 99; 
  text-align: center; 
} 
 
#loading-image { 
  top: 0px; 
  left: 0px; 
  z-index: 100; 
}


</style>

<meta charset="utf-8">
</head><body style="margin: 0px; border: 0px currentColor; padding-top: 0px; padding-left: 0px; font-family: Segoe UI, Tahoma, Arial; font-size: 11px; font-weight: normal;" onload="Timezone.Init();" bgColor="transparent">
<div id="container">
<div id="loading"><img id='loading-image"' alt="Loading" src="north52_image_progress"> </div>
<div id="main"><select style="width: 100%; font-family: Segoe UI; font-size: 11px; font-weight: normal;" id="ddlTimezone" onchange="Timezone.DropDownChanged(this.value)" class="ms-crm-SelectBox"></select> </div></div></body></html>