#property copyright "Copyright © 2006, Derk Wehler"
#property link      "http://www.forexfactory.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black

#import "wininet.dll"
   int InternetOpenA(string a0, int a1, string a2, string a3, int a4);
   int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5);
   int InternetReadFile(int a0, string a1, int a2, int& a3[]);
   int InternetCloseHandle(int a0);
#import "kernel32.dll"
   int GetTimeZoneInformation(int& a0[]);
#import

extern bool IncludeHigh = TRUE;
extern bool IncludeMedium = TRUE;
extern bool IncludeLow = FALSE;
extern bool IncludeSpeaks = TRUE;
extern bool IsEA_Call = FALSE;
extern int OffsetHours = 3;
extern bool AllowWebUpdates = TRUE;
extern int Alert1MinsBefore = 0;
extern int Alert2MinsBefore = -1;
extern bool ReportAllForUSD = TRUE;
extern bool ReportAllForEUR = TRUE;
extern bool ReportAllForGBP = TRUE;
extern bool ReportAllForNZD = TRUE;
extern bool ReportAllForJPY = TRUE;
extern bool ReportAllForAUD = TRUE;
extern bool ReportAllForCHF = TRUE;
extern bool ReportAllForCAD = TRUE;
extern bool ReportAllForCNY = FALSE;
extern bool EnableLogging = FALSE;
extern bool ShowNextTwoEvents = TRUE;
extern bool ShowVertNews = FALSE;
extern int TxtSize = 10;
extern color TxtColorTitle = Gold;
extern color TxtColorNews = DeepSkyBlue;
extern color TxtColorImpact = Red;
extern color TxtColorPrevious = Peru;
extern color TxtColorForecast = Lime;
extern int VertTxtShift = 21;
extern int VertLeftLineShift = 900;
extern int VertRightLineShift = 200;
extern color VertLineColor = SlateBlue;
extern color VertTxtColor = Black;
extern int VertTxtSize = 8;
extern int NewsCorner = 1;
extern bool SaveXmlFiles = FALSE;
int Gi_216 = 5;
double G_ibuf_220[];
double G_ibuf_224[];
double G_ibuf_228[];
string Gs_232 = "http://forexfactory.com/ffcal_week_this.xml";
int G_file_240;
int G_file_244 = -1;
int Gi_248;
int Gi_256;
int G_index_260;
int Gi_264;
string Gsa_268[100][7];
int Gi_272;
string Gs_276;
string Gs_dummy_284;
string G_text_292;
int Gi_300;
int Gi_304;
int Gia_308[2];
string Gsa_312[2];
string Gsa_316[2];
string Gsa_320[2];
string Gsa_324[2];
string Gsa_328[2];
string Gsa_332[7] = {"<title>", "<country>", "<date><![CDATA[", "<time><![CDATA[", "<impact><![CDATA[", "<forecast><![CDATA[", "<previous><![CDATA["};
string Gsa_336[7] = {"</title>", "</country>", "]]></date>", "]]></time>", "]]></impact>", "]]></forecast>", "]]></previous>"};
bool Gi_340 = FALSE;
int G_minute_344 = -1;
int Gi_348 = 0;
int Gi_352 = 0;
int G_str2time_356 = 0;
string G_name_360;
bool Gi_368 = FALSE;
int Gi_372;
int Gi_376;
int Gi_380 = 0;
int Gi_384 = 1;
int Gi_unused_388 = 3;
int Gi_392 = 80;
int Gia_396[43];

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   if (Gi_216 > 0) Print("In Init()...\n");
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, G_ibuf_220);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, G_ibuf_224);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(2, G_ibuf_228);
   IndicatorShortName("FFCal");
   MathSrand(TimeLocal());
   Gi_348 = MathRand() % 60;
   Gi_352 = MathRand() % 6;
   if (Gi_216 > 0) {
      Print("RefreshMin  == ", Gi_348);
      Print("RefreshHour == ", Gi_352);
   }
   return (0);
}
                                                                             
// 52D46093050F38C27267BCE42543EF60
int deinit() {
   string name_4;
   string name_12;
   ObjectDelete("Sponsor");
   ObjectDelete("Minutes");
   ObjectDelete("Impact");
   ObjectDelete("Previous");
   ObjectDelete("Forecast");
   ObjectDelete("Minutes2");
   ObjectDelete("Impact2");
   ObjectDelete("Previous2");
   ObjectDelete("Forecast2");
   for (int Li_0 = ObjectsTotal() - 1; Li_0 >= 0; Li_0--) {
      name_4 = ObjectName(Li_0);
      if (StringSubstr(name_4, 0, 5) == "vLine") ObjectDelete(name_4);
   }
   for (Li_0 = ObjectsTotal() - 1; Li_0 >= 0; Li_0--) {
      name_12 = ObjectName(Li_0);
      if (StringSubstr(name_12, 0, 8) == "Headline") ObjectDelete(name_12);
   }
   G_name_360 = f0_7();
   G_file_240 = FileOpen(G_name_360, FILE_BIN|FILE_WRITE|FILE_READ);
   if (G_file_240 >= 0) {
      FileClose(G_file_240);
      if (!SaveXmlFiles) FileDelete(G_name_360);
   }
   return (0);
}
                                                                       
// B5F2DE57205BF8B0906B68326FE5524D
string f0_7() {
   return (Month() + "-" + Day() + "-" + Year() + "-" + Symbol() + Period() + "-" + "FFCal.xml");
}
                                                                       
// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   int Li_8;
   string Ls_12;
   bool Li_20;
   int str2time_24;
   int index_0 = 0;
   int Li_unused_4 = -1;
   if (!IsConnected()) {
      Print("News Indicator is disabled because NO CONNECTION to Broker!");
      return (0);
   }
   if (!EnableLogging) Gi_216 = 0;
   G_text_292 = "FOREX FACTORY CALENDAR";
   G_name_360 = f0_7();
   G_file_240 = FileOpen(G_name_360, FILE_BIN|FILE_READ);
   if (G_file_240 >= 0) {
      FileClose(G_file_240);
      Gi_340 = FALSE;
   } else Gi_340 = TRUE;
   if (AllowWebUpdates) {
      if (Gi_216 > 1) Print(GlobalVariableGet("LastUpdateTime") + " " + ((TimeCurrent() - GlobalVariableGet("LastUpdateTime"))));
      if (Gi_340 || GlobalVariableCheck("LastUpdateTime") == FALSE || TimeCurrent() - GlobalVariableGet("LastUpdateTime") > 14400.0) {
         if (Gi_216 > 1) Print("sUrl == ", Gs_232);
         if (Gi_216 > 0) Print("Grabbing Web, url = ", Gs_232);
         f0_3(Gs_232, Gs_276);
         if (Gi_216 > 0) {
            Print("Opening XML file...\n");
            Print(Gs_276);
         }
         FileDelete(G_name_360);
         G_file_240 = FileOpen(G_name_360, FILE_BIN|FILE_WRITE);
         if (G_file_240 < 0) {
            if (Gi_216 <= 0) return (0);
            Print("Can\'t open new xml file, the last error is ", GetLastError());
            return (0);
         }
         FileWriteString(G_file_240, Gs_276, StringLen(Gs_276));
         FileClose(G_file_240);
         if (Gi_216 > 0) Print("Wrote XML file...\n");
         Gi_256 = StringFind(Gs_276, "</weeklyevents>", 0);
         if (Gi_256 <= 0) {
            Alert("FFCal Error - Web page download was not complete!");
            return (0);
         }
         GlobalVariableSet("LastUpdateTime", TimeCurrent());
      }
   }
   if (!IsEA_Call && Minute() == G_minute_344) return (1);
   G_minute_344 = Minute();
   f0_8("FFCal");
   ArrayInitialize(G_ibuf_220, 0);
   ArrayInitialize(G_ibuf_224, 0);
   G_file_240 = FileOpen(G_name_360, FILE_BIN|FILE_READ);
   if (G_file_240 < 0) {
      Print("Can\'t open xml file: ", G_name_360, ".  The last error is ", GetLastError());
      return (0);
   }
   if (Gi_216 > 0) Print("XML file open must be okay");
   Gs_276 = FileReadString(G_file_240, 65536);
   if (StringLen(Gs_276) < FileSize(G_file_240)) Gs_276 = Gs_276 + FileReadString(G_file_240, FileSize(G_file_240));
   if (G_file_240 > 0) FileClose(G_file_240);
   string Ls_28 = Symbol();
   string Ls_36 = StringSubstr(Ls_28, 0, 3);
   string Ls_44 = StringSubstr(Ls_28, 3, 3);
   if (Gi_216 > 0) Print("cntry1 = ", Ls_36, "    cntry2 = ", Ls_44);
   if (Gi_216 > 0) {
      f0_9("Weekly calendar for " + Ls_28 
      + "\n\n");
   }
   Gi_300 = 10080;
   Gi_248 = 0;
   while (true) {
      Gi_248 = StringFind(Gs_276, "<event>", Gi_248);
      if (Gi_248 == -1) break;
      Gi_248 += 7;
      Li_8 = StringFind(Gs_276, "</event>", Gi_248);
      if (Li_8 == -1) break;
      Ls_12 = StringSubstr(Gs_276, Gi_248, Li_8 - Gi_248);
      Gi_248 = Li_8;
      Gi_264 = 0;
      Li_20 = FALSE;
      for (G_index_260 = 0; G_index_260 < 7; G_index_260++) {
         Gsa_268[index_0][G_index_260] = "";
         Li_8 = StringFind(Ls_12, Gsa_332[G_index_260], Gi_264);
         if (Li_8 != -1) {
            Gi_264 = Li_8 + StringLen(Gsa_332[G_index_260]);
            Gi_256 = StringFind(Ls_12, Gsa_336[G_index_260], Gi_264);
            if (Gi_256 > Gi_264 && Gi_256 != -1) Gsa_268[index_0][G_index_260] = StringSubstr(Ls_12, Gi_264, Gi_256 - Gi_264);
         }
      }
      if (Ls_36 != Gsa_268[index_0][1] && Ls_44 != Gsa_268[index_0][1] && (!ReportAllForUSD || Gsa_268[index_0][1] != "USD" && !ReportAllForEUR || Gsa_268[index_0][1] != "EUR" &&
         !ReportAllForGBP || Gsa_268[index_0][1] != "GBP" && !ReportAllForNZD || Gsa_268[index_0][1] != "NZD" && !ReportAllForJPY || Gsa_268[index_0][1] != "JPY" && !ReportAllForAUD ||
         Gsa_268[index_0][1] != "AUD" && !ReportAllForCAD || Gsa_268[index_0][1] != "CAD" && !ReportAllForCHF || Gsa_268[index_0][1] != "CHF" && !ReportAllForCNY || Gsa_268[index_0][1] != "CNY")) Li_20 = TRUE;
      if (!IncludeHigh && Gsa_268[index_0][4] == "High") Li_20 = TRUE;
      if (!IncludeMedium && Gsa_268[index_0][4] == "Medium") Li_20 = TRUE;
      if (!IncludeLow && Gsa_268[index_0][4] == "Low") Li_20 = TRUE;
      if (!IncludeSpeaks && StringFind(Gsa_268[index_0][0], "speaks") != -1 || StringFind(Gsa_268[index_0][0], "Speaks") != -1) Li_20 = TRUE;
      if (Gsa_268[index_0][3] == "All Day" || Gsa_268[index_0][3] == "Tentative" || Gsa_268[index_0][3] == "") Li_20 = TRUE;
      if (!(!Li_20)) continue;
      str2time_24 = StrToTime(f0_6(Gsa_268[index_0][2], Gsa_268[index_0][3]));
      Gi_272 = (str2time_24 - f0_4()) / 60;
      if (Gi_216 > 0) {
         f0_9("FOREX FACTORY\nTitle: " + Gsa_268[index_0][0] 
            + "\n" 
            + Gi_272 
         + "\n\n");
      }
      if (Gi_272 == 0 && G_str2time_356 != str2time_24) {
         f0_5(Gsa_312[0], Gsa_316[0], 0);
         if (Gia_308[0] == Gia_308[1]) f0_5(Gsa_312[1], Gsa_316[1], 1);
         G_str2time_356 = str2time_24;
      }
      if (ShowVertNews && (!IsEA_Call)) {
         f0_2(Gsa_268[index_0][0], Gsa_268[index_0][1], 0, StrToTime(f0_6(Gsa_268[index_0][2], Gsa_268[index_0][3])));
         if (Gsa_268[index_0][3] == Gsa_268[index_0 + 1][3]) f0_2(Gsa_268[index_0 + 1][0], Gsa_268[index_0 + 1][1], 1, StrToTime(f0_6(Gsa_268[index_0 + 1][2], Gsa_268[index_0 + 1][3])));
      }
      if (Gi_272 < 0 || MathAbs(Gi_300) > Gi_272) {
         Gi_304 = index_0;
         Gi_300 = Gi_272;
      }
      f0_9("Weekly calendar for " + Ls_28 
      + "\n\n");
      if (Gi_216 > 0) {
         f0_9("FOREX FACTORY\nTitle: " + Gsa_268[index_0][0] 
            + "\nCountry: " + Gsa_268[index_0][1] 
            + "\nDate: " + Gsa_268[index_0][2] 
            + "\nTime: " + Gsa_268[index_0][3] 
            + "\nImpact: " + Gsa_268[index_0][4] 
            + "\nForecast: " + Gsa_268[index_0][5] 
            + "\nPrevious: " + Gsa_268[index_0][6] 
         + "\n\n");
      }
      if (Alert1MinsBefore != -1 && Gi_272 == Alert1MinsBefore) Alert(Alert1MinsBefore, " minutes until news for ", Ls_28, ": ", Gsa_268[index_0][0]);
      if (Alert2MinsBefore != -1 && Gi_272 == Alert2MinsBefore) Alert(Alert2MinsBefore, " minutes until news for ", Ls_28, ": ", Gsa_268[index_0][0]);
      G_ibuf_220[index_0] = Gi_272;
      index_0++;
   }
   bool Li_52 = TRUE;
   G_ibuf_224[0] = 99999;
   G_ibuf_224[1] = 99999;
   G_ibuf_228[0] = 0;
   G_ibuf_228[1] = 0;
   string Ls_56 = "Minutes until news events for " + Ls_28 + " : ";
   for (G_index_260 = 0; G_index_260 < index_0; G_index_260++) {
      Ls_56 = Ls_56 + G_ibuf_220[G_index_260] + ", ";
      if (G_ibuf_220[G_index_260] >= 0.0 && Li_52) {
         Li_52 = FALSE;
         if (G_index_260 > 0) {
            G_ibuf_224[0] = MathAbs(G_ibuf_220[G_index_260 - 1]);
            G_ibuf_228[0] = f0_10(Gsa_268[G_index_260 - 1][4]);
         }
         if (G_ibuf_220[G_index_260] > 0.0 || (G_ibuf_220[G_index_260] == 0.0 && G_ibuf_220[G_index_260 + 1] > 0.0)) G_ibuf_224[1] = G_ibuf_220[G_index_260];
         G_ibuf_228[1] = f0_10(Gsa_268[G_index_260][4]);
      }
      if (G_index_260 == Gi_304) {
         Gsa_312[0] = Gsa_268[G_index_260][0];
         Gsa_316[0] = Gsa_268[G_index_260][1];
         Gsa_320[0] = Gsa_268[G_index_260][4];
         Gsa_324[0] = Gsa_268[G_index_260][5];
         Gsa_328[0] = Gsa_268[G_index_260][6];
         Gia_308[0] = G_ibuf_220[G_index_260];
      }
      if (G_index_260 == Gi_304 + 1) {
         Gsa_312[1] = Gsa_268[G_index_260][0];
         Gsa_316[1] = Gsa_268[G_index_260][1];
         Gsa_320[1] = Gsa_268[G_index_260][4];
         Gsa_324[1] = Gsa_268[G_index_260][5];
         Gsa_328[1] = Gsa_268[G_index_260][6];
         Gia_308[1] = G_ibuf_220[G_index_260];
      }
   }
   if (G_ibuf_224[0] == 0.0 && G_ibuf_224[1] == 0.0) {
      G_ibuf_224[0] = G_ibuf_220[G_index_260 - 1];
      G_ibuf_224[1] = 999999;
      ObjectDelete("Impact");
      ObjectDelete("Previous");
      ObjectDelete("Forecast");
      ObjectDelete("Impact2");
      ObjectDelete("Previous2");
      ObjectDelete("Forecast2");
   }
   if (Gi_216 > 0) {
      Print(Ls_56);
      Print("LastMins (ExtMapBuffer1[0]) = ", G_ibuf_224[0]);
      Print("NextMins (ExtMapBuffer1[1]) = ", G_ibuf_224[1]);
   }
   if (!IsEA_Call) f0_0();
   if (G_file_244 > 0) {
      FileClose(G_file_244);
      G_file_244 = -1;
   }
   return (0);
}
                                                               
// 854443ECF7476D06304FEA1DB268F015
void f0_5(string As_0, string As_8, int Ai_16) {
   double price_28 = 0.0;
   double Ld_20 = (iHigh(NULL, PERIOD_D1, 1) + iLow(NULL, PERIOD_D1, 1) + iClose(NULL, PERIOD_D1, 1)) / 3.0;
   if (Open[0] > Ld_20) price_28 = Low[iLowest(NULL, 0, MODE_LOW, 5, 0)] - VertTxtShift * Point;
   else price_28 = High[iHighest(NULL, 0, MODE_HIGH, 5, 0)] + VertTxtShift * Point;
   if (Ai_16 == 0) {
      if (ObjectFind("vLine" + Time[0]) == -1) {
         ObjectCreate("vLine" + Time[0], OBJ_TREND, 0, Time[0], 0, Time[0], High[0]);
         ObjectSet("vLine" + Time[0], OBJPROP_COLOR, VertLineColor);
         ObjectSet("vLine" + Time[0], OBJPROP_STYLE, STYLE_DOT);
         ObjectSet("vLine" + Time[0], OBJPROP_BACK, TRUE);
      }
      if (ObjectFind("Headline" + Time[0]) == -1) {
         ObjectCreate("Headline" + Time[0], OBJ_TEXT, 0, Time[0] - VertLeftLineShift, price_28);
         ObjectSet("Headline" + Time[0], OBJPROP_ANGLE, 90);
         ObjectSetText("Headline" + Time[0], "News: " + As_8 + " " + As_0, VertTxtSize, "Arial", VertTxtColor);
      }
   } else {
      if (ObjectFind("Headline" + Time[0] + "s") == -1) {
         ObjectCreate("Headline" + Time[0] + "s", OBJ_TEXT, 0, Time[0] + VertRightLineShift, price_28);
         ObjectSet("Headline" + Time[0] + "s", OBJPROP_ANGLE, 90);
         ObjectSetText("Headline" + Time[0] + "s", "News: " + As_8 + " " + As_0, VertTxtSize, "Arial", VertTxtColor);
      }
   }
   WindowRedraw();
}
                                                                               
// 65FD9F2716FE7C9EF9D6412C8B64075F
void f0_2(string As_0, string As_8, int Ai_16, int Ai_20) {
   double price_36 = 0.0;
   int shift_24 = iBarShift(NULL, 0, Ai_20);
   double Ld_28 = (iHigh(NULL, PERIOD_D1, shift_24) + iLow(NULL, PERIOD_D1, shift_24) + iClose(NULL, PERIOD_D1, shift_24)) / 3.0;
   if (Open[shift_24] > Ld_28) price_36 = Low[iLowest(NULL, 0, MODE_LOW, 5, shift_24)] - VertTxtShift * Point;
   else price_36 = High[iHighest(NULL, 0, MODE_HIGH, 5, shift_24)] + VertTxtShift * Point;
   if (Ai_20 < Time[0]) {
      if (Ai_16 == 0) {
         if (ObjectFind("vLine" + Ai_20) == -1) {
            ObjectCreate("vLine" + Ai_20, OBJ_TREND, 0, Ai_20, 0, Ai_20, High[0]);
            ObjectSet("vLine" + Ai_20, OBJPROP_COLOR, VertLineColor);
            ObjectSet("vLine" + Ai_20, OBJPROP_STYLE, STYLE_DOT);
            ObjectSet("vLine" + Ai_20, OBJPROP_BACK, TRUE);
         }
         if (ObjectFind("Headline" + Ai_20) == -1) {
            ObjectCreate("Headline" + Ai_20, OBJ_TEXT, 0, Ai_20 - VertLeftLineShift, price_36);
            ObjectSet("Headline" + Ai_20, OBJPROP_ANGLE, 90);
            ObjectSetText("Headline" + Ai_20, "News: " + As_8 + " " + As_0, VertTxtSize, "Arial", VertTxtColor);
         }
      } else {
         if (ObjectFind("Headline" + Ai_20 + "s") == -1) {
            ObjectCreate("Headline" + Ai_20 + "s", OBJ_TEXT, 0, Ai_20 + VertRightLineShift, price_36);
            ObjectSet("Headline" + Ai_20 + "s", OBJPROP_ANGLE, 90);
            ObjectSetText("Headline" + Ai_20 + "s", "News: " + As_8 + " " + As_0, VertTxtSize, "Arial", VertTxtColor);
         }
      }
   }
   WindowRedraw();
}
                                                                         
// 0160EC6BBBF4C3343C4F101D5EDE5E31
void f0_0() {
   int Li_4;
   int Li_8;
   int Li_12;
   string text_16;
   int y_0 = 12;
   if (ObjectFind("Sponsor") == -1) ObjectCreate("Sponsor", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Sponsor", G_text_292, TxtSize, "Arial Bold", TxtColorTitle);
   ObjectSet("Sponsor", OBJPROP_CORNER, NewsCorner);
   ObjectSet("Sponsor", OBJPROP_XDISTANCE, 10);
   ObjectSet("Sponsor", OBJPROP_YDISTANCE, y_0);
   string Ls_24 = "until ";
   int Li_32 = Gia_308[0];
   if (Gia_308[0] <= 0) {
      Ls_24 = "since ";
      Li_32 = -1 * Li_32;
   }
   y_0 = y_0 + TxtSize + 4;
   if (Li_32 == 999999) text_16 = " (No more events this week)";
   else {
      if (Li_32 < 60) text_16 = Li_32 + " mins ";
      else {
         Li_8 = MathRound(Li_32 / 60);
         Li_12 = Li_32 % 60;
         if (Li_8 < 24) text_16 = Li_8 + " hrs " + Li_12 + " mins ";
         else {
            Li_4 = MathRound(Li_8 / 24);
            Li_8 %= 24;
            text_16 = Li_4 + " days " + Li_8 + " hrs " + Li_12 + " mins ";
         }
      }
   }
   if (ObjectFind("Minutes") == -1) ObjectCreate("Minutes", OBJ_LABEL, 0, 0, 0);
   if (Li_32 == 999999) ObjectSetText("Minutes", text_16, TxtSize, "Arial Bold", TxtColorNews);
   else ObjectSetText("Minutes", text_16 + Ls_24 + Gsa_316[0] + ": " + Gsa_312[0], TxtSize, "Arial Bold", TxtColorNews);
   ObjectSet("Minutes", OBJPROP_CORNER, NewsCorner);
   ObjectSet("Minutes", OBJPROP_XDISTANCE, 10);
   ObjectSet("Minutes", OBJPROP_YDISTANCE, y_0);
   y_0 = y_0 + TxtSize + 4;
   if (ObjectFind("Impact") == -1) ObjectCreate("Impact", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Impact", "Impact: " + Gsa_320[0], TxtSize, "Arial Bold", TxtColorImpact);
   ObjectSet("Impact", OBJPROP_CORNER, NewsCorner);
   ObjectSet("Impact", OBJPROP_XDISTANCE, 10);
   ObjectSet("Impact", OBJPROP_YDISTANCE, y_0);
   if (Gsa_328[0] != "") {
      y_0 = y_0 + TxtSize + 4;
      if (ObjectFind("Previous") == -1) ObjectCreate("Previous", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("Previous", "Previous: " + Gsa_328[0], TxtSize, "Arial Bold", TxtColorPrevious);
      ObjectSet("Previous", OBJPROP_CORNER, NewsCorner);
      ObjectSet("Previous", OBJPROP_XDISTANCE, 10);
      ObjectSet("Previous", OBJPROP_YDISTANCE, y_0);
   }
   if (Gsa_324[0] != "") {
      y_0 = y_0 + TxtSize + 4;
      if (ObjectFind("Forecast") == -1) ObjectCreate("Forecast", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("Forecast", "Forecast: " + Gsa_324[0], TxtSize, "Arial Bold", TxtColorForecast);
      ObjectSet("Forecast", OBJPROP_CORNER, NewsCorner);
      ObjectSet("Forecast", OBJPROP_XDISTANCE, 10);
      ObjectSet("Forecast", OBJPROP_YDISTANCE, y_0);
   }
   if (ShowNextTwoEvents && Gsa_312[1] != "") {
      Ls_24 = "until ";
      Li_32 = Gia_308[1];
      if (Gia_308[1] <= 0) {
         Ls_24 = "since ";
         Li_32 = -1 * Li_32;
      }
      y_0 = y_0 + TxtSize + 20;
      if (Li_32 == 999999) text_16 = " (No more events this week)";
      else {
         if (Li_32 < 60) text_16 = Li_32 + " mins ";
         else {
            Li_8 = MathRound(Li_32 / 60);
            Li_12 = Li_32 % 60;
            if (Li_8 < 24) text_16 = Li_8 + " hrs " + Li_12 + " mins ";
            else {
               Li_4 = MathRound(Li_8 / 24);
               Li_8 %= 24;
               text_16 = Li_4 + " days " + Li_8 + " hrs " + Li_12 + " mins ";
            }
         }
      }
      if (ObjectFind("Minutes2") == -1) ObjectCreate("Minutes2", OBJ_LABEL, 0, 0, 0);
      if (Li_32 == 999999) ObjectSetText("Minutes", text_16, TxtSize, "Arial Bold", TxtColorNews);
      else ObjectSetText("Minutes2", text_16 + "until " + Gsa_316[1] + ": " + Gsa_312[1], TxtSize, "Arial Bold", TxtColorNews);
      ObjectSet("Minutes2", OBJPROP_CORNER, NewsCorner);
      ObjectSet("Minutes2", OBJPROP_XDISTANCE, 10);
      ObjectSet("Minutes2", OBJPROP_YDISTANCE, y_0);
      y_0 = y_0 + TxtSize + 4;
      if (ObjectFind("Impact2") == -1) ObjectCreate("Impact2", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("Impact2", "Impact: " + Gsa_320[1], TxtSize, "Arial Bold", TxtColorImpact);
      ObjectSet("Impact2", OBJPROP_CORNER, NewsCorner);
      ObjectSet("Impact2", OBJPROP_XDISTANCE, 10);
      ObjectSet("Impact2", OBJPROP_YDISTANCE, y_0);
      if (Gsa_328[1] != "") {
         y_0 = y_0 + TxtSize + 4;
         if (ObjectFind("Previous2") == -1) ObjectCreate("Previous2", OBJ_LABEL, 0, 0, 0);
         ObjectSetText("Previous2", "Previous: " + Gsa_328[1], TxtSize, "Arial Bold", TxtColorPrevious);
         ObjectSet("Previous2", OBJPROP_CORNER, NewsCorner);
         ObjectSet("Previous2", OBJPROP_XDISTANCE, 10);
         ObjectSet("Previous2", OBJPROP_YDISTANCE, y_0);
      }
      if (Gsa_324[1] != "") {
         y_0 = y_0 + TxtSize + 4;
         if (ObjectFind("Forecast2") == -1) ObjectCreate("Forecast2", OBJ_LABEL, 0, 0, 0);
         ObjectSetText("Forecast2", "Forecast: " + Gsa_324[1], TxtSize, "Arial Bold", TxtColorForecast);
         ObjectSet("Forecast2", OBJPROP_CORNER, NewsCorner);
         ObjectSet("Forecast2", OBJPROP_XDISTANCE, 10);
         ObjectSet("Forecast2", OBJPROP_YDISTANCE, y_0);
      }
   }
}
                                                                           
// F3CCAF12B086C5AAC123E3F7DB870E06
double f0_10(string As_0) {
   if (As_0 == "High") return (3);
   if (As_0 == "Medium") return (2);
   if (As_0 == "Low") return (1);
   return (0);
}
                                                                     
// 8E314AF1224715F50B4B50AFD86BF84B
string f0_6(string As_0, string As_8) {
   int Li_16 = StringFind(As_0, "-");
   int Li_20 = StringFind(As_0, "-", Li_16 + 1);
   string Ls_24 = StringSubstr(As_0, 0, 2);
   string Ls_32 = StringSubstr(As_0, 3, 2);
   string Ls_40 = StringSubstr(As_0, 6, 4);
   int Li_48 = StringFind(As_8, ":");
   string Ls_52 = StringSubstr(As_8, 0, Li_48);
   string Ls_60 = StringSubstr(As_8, Li_48 + 1, 2);
   string Ls_68 = StringSubstr(As_8, StringLen(As_8) - 2);
   int Li_76 = StrToInteger(Ls_52);
   if (Ls_68 == "pm" || Ls_68 == "PM" && Li_76 != 12) Li_76 += 12;
   if (Ls_68 == "am" || Ls_68 == "AM" && Li_76 == 12) Li_76 = 0;
   string Ls_80 = "";
   if (Li_76 < 10) Ls_80 = "0";
   return (StringConcatenate(Ls_40, ".", Ls_24, ".", Ls_32, " ", Ls_80, Li_76, ":", Ls_60));
}
                                                                     
// 1BBC94D06E1F0D3B9CFC87C094EBA75D
int f0_1(bool Ai_0) {
   string Ls_4;
   if (Gi_372 == 0) {
      Ls_4 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)";
      Gi_372 = InternetOpenA(Ls_4, Gi_380, "0", "0", 0);
      Gi_376 = InternetOpenA(Ls_4, Gi_384, "0", "0", 0);
   }
   if (Ai_0) return (Gi_376);
   return (Gi_372);
}
                                                                     
// 67B5F51F6CCDE3F6F9D86EE70C3F4037
int f0_3(string As_0, string &As_8) {
   int Lia_24[] = {1};
   string Ls_28 = "                                                                                                                                                                                                                                                               ";
   int Li_16 = InternetOpenUrlA(f0_1(0), As_0, "0", 0, -2080374528, 0);
   if (Gi_368) f0_9("hInternet: " + Li_16);
   if (Li_16 == 0) return (0);
   Print("Reading URL: " + As_0);
   int Li_20 = InternetReadFile(Li_16, Ls_28, Gi_392, Lia_24);
   if (Gi_368) f0_9("iResult: " + Li_20);
   if (Gi_368) f0_9("lReturn: " + Lia_24[0]);
   if (Gi_368) f0_9("iResult: " + Li_20);
   if (Gi_368) f0_9("sBuffer: " + Ls_28);
   if (Li_20 == 0) return (0);
   int Li_36 = Lia_24[0];
   for (As_8 = StringSubstr(Ls_28, 0, Lia_24[0]); Lia_24[0] != 0; As_8 = As_8 + StringSubstr(Ls_28, 0, Lia_24[0])) {
      Li_20 = InternetReadFile(Li_16, Ls_28, Gi_392, Lia_24);
      if (Lia_24[0] == 0) break;
      Li_36 += Lia_24[0];
   }
   Print("Closing URL web connection");
   Li_20 = InternetCloseHandle(Li_16);
   if (Li_20 == 0) return (0);
   return (1);
}
                                                                             
// C4F1D323FF392507E56B0FB3E05D9A07
void f0_8(string As_0) {
   string Ls_8;
   string Ls_16;
   string str_concat_24;
   if (EnableLogging) {
      if (G_file_244 <= 0) {
         Ls_8 = "";
         Ls_16 = "";
         if (Month() < 10) Ls_8 = "0";
         if (Day() < 10) Ls_16 = "0";
         str_concat_24 = StringConcatenate(As_0, "_", Year(), Ls_8, Month(), Ls_16, Day(), "_log.txt");
         G_file_244 = FileOpen(str_concat_24, FILE_CSV|FILE_WRITE|FILE_READ);
         Print("logHandle =================================== ", G_file_244);
      }
      if (G_file_244 > 0) {
         FileFlush(G_file_244);
         FileSeek(G_file_244, 0, SEEK_END);
      }
   }
}
                                                                           
// CE0BE71E33226E4C1DB2BCEA5959F16B
void f0_9(string As_0) {
   if (EnableLogging) {
      if (G_file_244 > 0) {
         As_0 = TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES|TIME_SECONDS) + " " + As_0;
         FileWrite(G_file_244, As_0);
      }
   }
}
                                                                           
// 7BB4737772D59D76D97170BEEB73BEFE
int f0_4() {
   int Li_0 = GetTimeZoneInformation(Gia_396);
   if (Li_0 == 1) Li_0 = 3600;
   else Li_0 = 2;
   return (TimeLocal() + Li_0 + 3600 * OffsetHours + 60 * (Gia_396[0] + Gia_396[42]));
}
