
#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 = FALSE;
extern bool IncludeLow = FALSE;
extern bool IncludeSpeaks = TRUE;
bool Zi_92 = FALSE;
extern int OffsetHours = 0;
bool Zi_100 = TRUE;
extern int AlertMinsBefore = -1;
extern int AlertMinsBefore2 = -1;
extern bool ReportAllForUSD = TRUE;
bool Zi_116 = FALSE;
extern bool ShowNextTwoEvents = TRUE;
extern bool ShowVertNews = FALSE;
extern int TxtSize = 10;
int Zi_unused_132 = 13882323;
extern color TxtColorNews = DeepSkyBlue;
color Z_color_140 = Red;
extern color TxtColorImpactHigh = Red;
extern color TxtColorImpactMedium = Orange;
extern color TxtColorImpactLow = Yellow;
int Zi_156 = 21;
int Zi_160 = 900;
int Zi_164 = 200;
color Z_color_168 = SlateBlue;
color Z_color_172 = DimGray;
int Z_fontsize_176 = 8;
int Z_corner_180 = 0;
extern bool SaveXmlFiles = FALSE;
int Zi_188 = 2;
double Z_ibuf_192[];
double Z_ibuf_196[];
double Z_ibuf_200[];
string Zs_204 = "http://www.forexfactory.com/ffcal_week_this.xml";
int Z_file_212;
int Z_file_216 = -1;
int Zi_220;
int Zi_228;
int Z_index_232;
int Zi_236;
string Zsa_240[256][7];
int Zi_244;
string Zs_248;
string Zs_dummy_256;
string Zs_unused_264;
int Zi_272;
int Zi_276;
int Zia_280[2];
string Zsa_284[2];
string Zsa_288[2];
string Zsa_292[2];
string Zsa_296[2];
string Zsa_300[2];
string Zsa_304[7] = {"<title>", "<country>", "<date>", "<time>", "<impact>", "<forecast>", "<previous>"};
string Zsa_308[7] = {"</title>", "</country>", "</date>", "</time>", "</impact>", "</forecast>", "</previous>"};
bool Zi_312 = FALSE;
int Z_minute_316 = -1;
int Z_str2time_320 = 0;
string Z_name_324;
int Zi_332 = 0;
bool Zi_336 = TRUE;
int Zi_340;
int Zi_344;
int Zi_348 = 0;
int Zi_352 = 1;
int Zi_unused_356 = 3;
int Zi_360 = 80;
int Zia_364[43];

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   if (!Zi_116) Zi_188 = 0;
   f0_8(StringConcatenate("FFCal", Symbol(), Period()));
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, Z_ibuf_192);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, Z_ibuf_196);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(2, Z_ibuf_200);
   IndicatorShortName("FFCal");
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   ObjectDelete("Sponsor");
   ObjectDelete("Minutes");
   ObjectDelete("Impact");
   ObjectDelete("Previous");
   ObjectDelete("Forecast");
   ObjectDelete("Minutes2");
   ObjectDelete("Impact2");
   ObjectDelete("Previous2");
   ObjectDelete("Forecast2");
   f0_6();
   Z_name_324 = f0_7();
   Z_file_212 = FileOpen(Z_name_324, FILE_BIN|FILE_WRITE|FILE_READ);
   if (Z_file_212 >= 0) {
      FileClose(Z_file_212);
      if (!SaveXmlFiles) FileDelete(Z_name_324);
   }
   if (Z_file_216 > 0) {
      FileClose(Z_file_216);
      Z_file_216 = -1;
   }
   return (0);
}

// B42134010160E2165CCF5D5CA89DEB3F
void f0_6() {
   string name_4;
   string name_12;
   for (int Mi_0 = ObjectsTotal() - 1; Mi_0 >= 0; Mi_0--) {
      name_4 = ObjectName(Mi_0);
      if (StringSubstr(name_4, 0, 5) == "vLine") ObjectDelete(name_4);
   }
   for (Mi_0 = ObjectsTotal() - 1; Mi_0 >= 0; Mi_0--) {
      name_12 = ObjectName(Mi_0);
      if (StringSubstr(name_12, 0, 8) == "Headline") ObjectDelete(name_12);
   }
}

// B5F2DE57205BF8B0906B68326FE5524D
string f0_7() {
   return (Month() + "-" + Day() + "-" + Year() + "-" + Symbol() + Period() + "-" + "FFCal.xml");
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   int Mi_8;
   string Ms_12;
   bool Mi_20;
   int str2time_24;
   int index_0 = 0;
   int Mi_unused_4 = -1;
   if (!IsConnected()) {
      Print("News Indicator is waiting for a connection to broker!");
      return (0);
   }
   Zs_unused_264 = "FOREX FACTORY CALENDAR";
   Z_name_324 = f0_7();
   Z_file_212 = FileOpen(Z_name_324, FILE_BIN|FILE_READ);
   if (Z_file_212 >= 0) {
      FileClose(Z_file_212);
      Zi_312 = FALSE;
   } else Zi_312 = TRUE;
   if (Zi_100 && Zi_312) {
      if (Zi_188 > 1) f0_9("Grabbing Web, url = " + Zs_204);
      f0_3(Zs_204, Zs_248);
      if (Zi_188 > 1) {
         f0_9("Opening XML file...\n");
         f0_9(StringConcatenate(StringLen(Zs_248), " bytes"));
      }
      Zi_228 = StringFind(Zs_248, "</weeklyevents>", 0);
      if (Zi_228 <= 0) {
         f0_9("Error: web page not complete");
         Alert("FFCal Error - Web page download was not complete!");
         return (0);
      }
      FileDelete(Z_name_324);
      Z_file_212 = FileOpen(Z_name_324, FILE_BIN|FILE_WRITE);
      if (Z_file_212 < 0) {
         Print("Can\'t open xml file: ", Z_name_324, ".  The last error is ", GetLastError());
         f0_9("Error: XML file open failed");
         return (0);
      }
      FileWriteString(Z_file_212, Zs_248, StringLen(Zs_248));
      FileClose(Z_file_212);
      if (Zi_188 > 1) f0_9("Wrote XML file...\n");
      f0_6();
   }
   if ((!Zi_92) && Minute() == Z_minute_316) return (1);
   Z_minute_316 = Minute();
   ArrayInitialize(Z_ibuf_192, 0);
   ArrayInitialize(Z_ibuf_196, 0);
   Z_file_212 = FileOpen(Z_name_324, FILE_BIN|FILE_READ);
   if (Z_file_212 < 0) {
      Print("Can\'t open xml file: ", Z_name_324, ".  The last error is ", GetLastError());
      f0_9("Error: XML file open failed");
      return (0);
   }
   if (Zi_188 > 1) f0_9("XML file opened");
   for (Zs_248 = ""; StringLen(Zs_248) < FileSize(Z_file_212); Zs_248 = StringConcatenate(Zs_248, FileReadString(Z_file_212, FileSize(Z_file_212) - StringLen(Zs_248)))) {
   }
   if (Zi_188 > 1) f0_9(StringConcatenate(StringLen(Zs_248), " bytes read"));
   if (Z_file_212 > 0) FileClose(Z_file_212);
   string Ms_28 = Symbol();
   string Ms_36 = StringSubstr(Ms_28, 0, 3);
   string Ms_44 = StringSubstr(Ms_28, 3, 3);
   if (Zi_188 > 2) f0_9("cntry1 = " + Ms_36 + "    cntry2 = " + Ms_44);
   if (Zi_188 > 1) {
      f0_9("Weekly calendar for " + Ms_28 
      + "\n\n");
   }
   double Md_52 = TimeCurrent() - f0_4();
   int Mi_60 = 3600.0 * MathRound(Md_52 / 3600.0);
   if (Mi_60 != Zi_332) f0_6();
   Zi_332 = Mi_60;
   Zi_272 = 10080;
   Zi_220 = 0;
   while (index_0 < 256) {
      Zi_220 = StringFind(Zs_248, "<event>", Zi_220);
      if (Zi_220 == -1) break;
      Zi_220 += 7;
      Mi_8 = StringFind(Zs_248, "</event>", Zi_220);
      if (Mi_8 == -1) break;
      Ms_12 = StringSubstr(Zs_248, Zi_220, Mi_8 - Zi_220);
      Zi_220 = Mi_8;
      Zi_236 = 0;
      Mi_20 = FALSE;
      for (Z_index_232 = 0; Z_index_232 < 7; Z_index_232++) {
         Zsa_240[index_0][Z_index_232] = "";
         Mi_8 = StringFind(Ms_12, Zsa_304[Z_index_232], Zi_236);
         if (Mi_8 != -1) {
            Zi_236 = Mi_8 + StringLen(Zsa_304[Z_index_232]);
            Zi_228 = StringFind(Ms_12, Zsa_308[Z_index_232], Zi_236);
            if (Zi_228 > Zi_236 && Zi_228 != -1) {
               Zsa_240[index_0][Z_index_232] = StringSubstr(Ms_12, Zi_236, Zi_228 - Zi_236);
               if (StringSubstr(Zsa_240[index_0][Z_index_232], 0, 9) == "<![CDATA[") Zsa_240[index_0][Z_index_232] = StringSubstr(Zsa_240[index_0][Z_index_232], 9, StringLen(Zsa_240[index_0][Z_index_232]) - 12);
            }
         }
      }
      if ((!IncludeHigh) && Zsa_240[index_0][4] == "High") Mi_20 = TRUE;
      if ((!IncludeMedium) && Zsa_240[index_0][4] == "Medium") Mi_20 = TRUE;
      if ((!IncludeLow) && Zsa_240[index_0][4] == "Low") Mi_20 = TRUE;
      if ((!IncludeSpeaks) && StringFind(Zsa_240[index_0][0], "speaks") != -1 || StringFind(Zsa_240[index_0][0], "Speaks") != -1) Mi_20 = TRUE;
      if (Zsa_240[index_0][3] == "All Day" || Zsa_240[index_0][3] == "Tentative" || Zsa_240[index_0][3] == "") Mi_20 = TRUE;
      if (!Mi_20) {
         str2time_24 = StrToTime(f0_5(Zsa_240[index_0][2], Zsa_240[index_0][3]));
         Zi_244 = (str2time_24 - f0_4()) / 60;
         if (Zi_188 > 2) {
            f0_9("FOREX FACTORY\nTitle: " + Zsa_240[index_0][0] 
               + "\n" 
               + Zi_244 
            + "\n\n");
         }
         if (Zi_244 == 0 && Z_str2time_320 != str2time_24) Z_str2time_320 = str2time_24;
         if (ShowVertNews && (!Zi_92)) {
            f0_2(Zsa_240[index_0][0], Zsa_240[index_0][1], 0, StrToTime(f0_5(Zsa_240[index_0][2], Zsa_240[index_0][3])) + Mi_60);
            if (Zsa_240[index_0][3] == Zsa_240[index_0 + 1][3]) f0_2(Zsa_240[index_0 + 1][0], Zsa_240[index_0 + 1][1], 1, StrToTime(f0_5(Zsa_240[index_0 + 1][2], Zsa_240[index_0 + 1][3])) + Mi_60);
         }
         if (Zi_244 < 0 || MathAbs(Zi_272) > Zi_244) {
            Zi_276 = index_0;
            Zi_272 = Zi_244;
         }
         if (Zi_188 > 2) {
            f0_9("FOREX FACTORY\nTitle: " + Zsa_240[index_0][0] 
               + "\nCountry: " + Zsa_240[index_0][1] 
               + "\nDate: " + Zsa_240[index_0][2] 
               + "\nTime: " + Zsa_240[index_0][3] 
               + "\nImpact: " + Zsa_240[index_0][4] 
               + "\nForecast: " + Zsa_240[index_0][5] 
               + "\nPrevious: " + Zsa_240[index_0][6] 
            + "\n\n");
         }
         if (AlertMinsBefore != -1 && Zi_244 == AlertMinsBefore) Alert(AlertMinsBefore, " minutes until news for ", Ms_28, ": ", Zsa_240[index_0][0]);
         if (AlertMinsBefore2 != -1 && Zi_244 == AlertMinsBefore2) Alert(AlertMinsBefore2, " minutes until news for ", Ms_28, ": ", Zsa_240[index_0][0]);
         Z_ibuf_192[index_0] = Zi_244;
         index_0++;
      }
   }
   bool Mi_64 = TRUE;
   Z_ibuf_196[0] = 99999;
   Z_ibuf_196[1] = 99999;
   Z_ibuf_200[0] = 0;
   Z_ibuf_200[1] = 0;
   string Ms_68 = "Minutes until news events for " + Ms_28 + " : ";
   for (Z_index_232 = 0; Z_index_232 < index_0; Z_index_232++) {
      Ms_68 = Ms_68 + Z_ibuf_192[Z_index_232] + ", ";
      if (Z_ibuf_192[Z_index_232] >= 0.0 && Mi_64) {
         Mi_64 = FALSE;
         if (Z_index_232 > 0) {
            Z_ibuf_196[0] = MathAbs(Z_ibuf_192[Z_index_232 - 1]);
            Z_ibuf_200[0] = f0_10(Zsa_240[Z_index_232 - 1][4]);
         }
         if (Z_ibuf_192[Z_index_232] > 0.0 || (Z_ibuf_192[Z_index_232] == 0.0 && Z_ibuf_192[Z_index_232 + 1] > 0.0)) Z_ibuf_196[1] = Z_ibuf_192[Z_index_232];
         Z_ibuf_200[1] = f0_10(Zsa_240[Z_index_232][4]);
      }
      if (Z_index_232 == Zi_276) {
         Zsa_284[0] = Zsa_240[Z_index_232][0];
         Zsa_288[0] = Zsa_240[Z_index_232][1];
         Zsa_292[0] = Zsa_240[Z_index_232][4];
         Zsa_296[0] = Zsa_240[Z_index_232][5];
         Zsa_300[0] = Zsa_240[Z_index_232][6];
         Zia_280[0] = Z_ibuf_192[Z_index_232];
      }
      if (Z_index_232 == Zi_276 + 1) {
         Zsa_284[1] = Zsa_240[Z_index_232][0];
         Zsa_288[1] = Zsa_240[Z_index_232][1];
         Zsa_292[1] = Zsa_240[Z_index_232][4];
         Zsa_296[1] = Zsa_240[Z_index_232][5];
         Zsa_300[1] = Zsa_240[Z_index_232][6];
         Zia_280[1] = Z_ibuf_192[Z_index_232];
      }
   }
   if (Z_ibuf_196[0] == 0.0 && Z_ibuf_196[1] == 0.0) {
      Z_ibuf_196[0] = Z_ibuf_192[Z_index_232 - 1];
      Z_ibuf_196[1] = 999999;
   }
   if (Zi_188 > 2) {
      f0_9(Ms_68);
      f0_9(StringConcatenate("LastMins (ExtMapBuffer1[0]) = ", Z_ibuf_196[0]));
      f0_9(StringConcatenate("NextMins (ExtMapBuffer1[1]) = ", Z_ibuf_196[1]));
   }
   if (!Zi_92) f0_0();
   return (0);
}

// 65FD9F2716FE7C9EF9D6412C8B64075F
void f0_2(string Os_0, string Os_8, int Oi_16, int Oi_20) {
   double price_36 = 0.0;
   int shift_24 = iBarShift(NULL, 0, Oi_20);
   double Md_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] > Md_28) price_36 = Low[iLowest(NULL, 0, MODE_LOW, 5, shift_24)] - Zi_156 * Point;
   else price_36 = High[iHighest(NULL, 0, MODE_HIGH, 5, shift_24)] + Zi_156 * Point;
   if (Oi_20 <= TimeCurrent()) {
      if (Oi_16 == 0) {
         if (ObjectFind("vLine" + Oi_20) == -1) {
            ObjectCreate("vLine" + Oi_20, OBJ_TREND, 0, Oi_20, 0, Oi_20, High[0]);
            ObjectSet("vLine" + Oi_20, OBJPROP_COLOR, Z_color_168);
            ObjectSet("vLine" + Oi_20, OBJPROP_STYLE, STYLE_DOT);
            ObjectSet("vLine" + Oi_20, OBJPROP_BACK, TRUE);
         }
         if (ObjectFind("Headline" + Oi_20) == -1) {
            ObjectCreate("Headline" + Oi_20, OBJ_TEXT, 0, Oi_20 - Zi_160, price_36);
            ObjectSet("Headline" + Oi_20, OBJPROP_ANGLE, 90);
            ObjectSetText("Headline" + Oi_20, "News: " + Os_8 + " " + Os_0, Z_fontsize_176, "Arial", Z_color_172);
         }
      } else {
         if (ObjectFind("Headline" + Oi_20 + "s") == -1) {
            ObjectCreate("Headline" + Oi_20 + "s", OBJ_TEXT, 0, Oi_20 + Zi_164, price_36);
            ObjectSet("Headline" + Oi_20 + "s", OBJPROP_ANGLE, 90);
            ObjectSetText("Headline" + Oi_20 + "s", "News: " + Os_8 + " " + Os_0, Z_fontsize_176, "Arial", Z_color_172);
         }
      }
   }
   WindowRedraw();
}

// 0160EC6BBBF4C3343C4F101D5EDE5E31
void f0_0() {
   int Mi_4;
   int Mi_8;
   int Mi_12;
   string text_16;
   int y_0 = 12;
   ObjectDelete("Impact");
   ObjectDelete("Previous");
   ObjectDelete("Forecast");
   ObjectDelete("Impact2");
   ObjectDelete("Previous2");
   ObjectDelete("Forecast2");
   string Ms_24 = "until ";
   int Mi_32 = Zia_280[0];
   if (Zia_280[0] <= 0) {
      Ms_24 = "since ";
      Mi_32 = -1 * Mi_32;
   }
   y_0 = y_0 + TxtSize + 4;
   if (Mi_32 == 999999) text_16 = " (No more events this week)";
   else {
      if (Mi_32 < 60) text_16 = Mi_32 + " mins ";
      else {
         Mi_8 = MathRound(Mi_32 / 60);
         Mi_12 = Mi_32 % 60;
         if (Mi_8 < 24) text_16 = Mi_8 + " hrs " + Mi_12 + " mins ";
         else {
            Mi_4 = MathRound(Mi_8 / 24);
            Mi_8 %= 24;
            text_16 = Mi_4 + " days " + Mi_8 + " hrs " + Mi_12 + " mins ";
         }
      }
   }
   if (ObjectFind("Minutes") == -1) ObjectCreate("Minutes", OBJ_LABEL, 0, 0, 0);
   if (Mi_32 == 999999) ObjectSetText("Minutes", text_16, TxtSize, "Arial Bold", TxtColorNews);
   else ObjectSetText("Minutes", text_16 + Ms_24 + Zsa_288[0] + ": " + Zsa_284[0], TxtSize, "Arial Bold", TxtColorNews);
   ObjectSet("Minutes", OBJPROP_CORNER, Z_corner_180);
   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);
   if (Zsa_292[0] == "Low") Z_color_140 = TxtColorImpactLow;
   else {
      if (Zsa_292[0] == "Medium") Z_color_140 = TxtColorImpactMedium;
      else {
         if (Zsa_292[0] == "High") Z_color_140 = TxtColorImpactHigh;
         else Z_color_140 = Red;
      }
   }
   ObjectSetText("Impact", "Impact: " + Zsa_292[0], TxtSize, "Arial Bold", Z_color_140);
   ObjectSet("Impact", OBJPROP_CORNER, Z_corner_180);
   ObjectSet("Impact", OBJPROP_XDISTANCE, 10);
   ObjectSet("Impact", OBJPROP_YDISTANCE, y_0);
   if (ShowNextTwoEvents && Zsa_284[1] != "") {
      Ms_24 = "until ";
      Mi_32 = Zia_280[1];
      if (Zia_280[1] <= 0) {
         Ms_24 = "since ";
         Mi_32 = -1 * Mi_32;
      }
      y_0 = y_0 + TxtSize + 20;
      if (Mi_32 == 999999) text_16 = " (No more events this week)";
      else {
         if (Mi_32 < 60) text_16 = Mi_32 + " mins ";
         else {
            Mi_8 = MathRound(Mi_32 / 60);
            Mi_12 = Mi_32 % 60;
            if (Mi_8 < 24) text_16 = Mi_8 + " hrs " + Mi_12 + " mins ";
            else {
               Mi_4 = MathRound(Mi_8 / 24);
               Mi_8 %= 24;
               text_16 = Mi_4 + " days " + Mi_8 + " hrs " + Mi_12 + " mins ";
            }
         }
      }
      if (ObjectFind("Minutes2") == -1) ObjectCreate("Minutes2", OBJ_LABEL, 0, 0, 0);
      if (Mi_32 == 999999) ObjectSetText("Minutes", text_16, TxtSize, "Arial Bold", TxtColorNews);
      else ObjectSetText("Minutes2", text_16 + "until " + Zsa_288[1] + ": " + Zsa_284[1], TxtSize, "Arial Bold", TxtColorNews);
      ObjectSet("Minutes2", OBJPROP_CORNER, Z_corner_180);
      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);
      if (Zsa_292[1] == "Low") Z_color_140 = TxtColorImpactLow;
      else {
         if (Zsa_292[1] == "Medium") Z_color_140 = TxtColorImpactMedium;
         else {
            if (Zsa_292[1] == "High") Z_color_140 = TxtColorImpactHigh;
            else Z_color_140 = Red;
         }
      }
      ObjectSetText("Impact2", "Impact: " + Zsa_292[1], TxtSize, "Arial Bold", Z_color_140);
      ObjectSet("Impact2", OBJPROP_CORNER, Z_corner_180);
      ObjectSet("Impact2", OBJPROP_XDISTANCE, 10);
      ObjectSet("Impact2", OBJPROP_YDISTANCE, y_0);
   }
}

// F3CCAF12B086C5AAC123E3F7DB870E06
double f0_10(string Os_0) {
   if (Os_0 == "High") return (3);
   if (Os_0 == "Medium") return (2);
   if (Os_0 == "Low") return (1);
   return (0);
}

// 8E314AF1224715F50B4B50AFD86BF84B
string f0_5(string Os_0, string Os_8) {
   int Mi_16 = StringFind(Os_0, "-");
   int Mi_20 = StringFind(Os_0, "-", Mi_16 + 1);
   string Ms_24 = StringSubstr(Os_0, 0, 2);
   string Ms_32 = StringSubstr(Os_0, 3, 2);
   string Ms_40 = StringSubstr(Os_0, 6, 4);
   int Mi_48 = StringFind(Os_8, ":");
   string Ms_52 = StringSubstr(Os_8, 0, Mi_48);
   string Ms_60 = StringSubstr(Os_8, Mi_48 + 1, 2);
   string Ms_68 = StringSubstr(Os_8, StringLen(Os_8) - 2);
   int Mi_76 = StrToInteger(Ms_52);
   if (Ms_68 == "pm" || Ms_68 == "PM" && Mi_76 != 12) Mi_76 += 12;
   if (Ms_68 == "am" || Ms_68 == "AM" && Mi_76 == 12) Mi_76 = 0;
   string Ms_80 = "";
   if (Mi_76 < 10) Ms_80 = "0";
   return (StringConcatenate(Ms_40, ".", Ms_24, ".", Ms_32, " ", Ms_80, Mi_76, ":", Ms_60));
}

// 1BBC94D06E1F0D3B9CFC87C094EBA75D
int f0_1(bool Oi_0) {
   string Ms_4;
   if (Zi_340 == 0) {
      Ms_4 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)";
      Zi_340 = InternetOpenA(Ms_4, Zi_348, "0", "0", 0);
      Zi_344 = InternetOpenA(Ms_4, Zi_352, "0", "0", 0);
   }
   if (Zi_336) f0_9("hsession_ietype: " + Zi_340);
   if (Zi_336) f0_9("hsession_direct: " + Zi_344);
   if (Oi_0) return (Zi_344);
   return (Zi_340);
}

// 67B5F51F6CCDE3F6F9D86EE70C3F4037
int f0_3(string Os_0, string &Os_8) {
   int Mia_24[] = {1};
   string Ms_28 = "                                                                                                                                                                                                                                                               ";
   Zi_336 = Zi_116;
   int Mi_16 = InternetOpenUrlA(f0_1(0), Os_0, "0", 0, -2080374528, 0);
   if (Zi_336) f0_9("hInternet: " + Mi_16);
   if (Mi_16 == 0) return (0);
   if (Zi_188 > 1) f0_9("Reading URL: " + Os_0);
   int Mi_20 = InternetReadFile(Mi_16, Ms_28, Zi_360, Mia_24);
   if (Zi_336) f0_9("iResult: " + Mi_20);
   if (Zi_336) f0_9("lReturn: " + Mia_24[0]);
   if (Zi_336) f0_9("iResult: " + Mi_20);
   if (Zi_336) f0_9("sBuffer: " + Ms_28);
   if (Mi_20 == 0) return (0);
   int Mi_36 = Mia_24[0];
   for (Os_8 = StringSubstr(Ms_28, 0, Mia_24[0]); Mia_24[0] != 0; Os_8 = Os_8 + StringSubstr(Ms_28, 0, Mia_24[0])) {
      Mi_20 = InternetReadFile(Mi_16, Ms_28, Zi_360, Mia_24);
      if (Mia_24[0] == 0) break;
      Mi_36 += Mia_24[0];
   }
   if (Zi_188 > 1) f0_9("Closing URL web connection");
   Mi_20 = InternetCloseHandle(Mi_16);
   if (Mi_20 == 0) return (0);
   return (1);
}

// C4F1D323FF392507E56B0FB3E05D9A07
void f0_8(string Os_0) {
   string Ms_8;
   string Ms_16;
   string str_concat_24;
   if (Zi_116) {
      if (Z_file_216 > 0) FileClose(Z_file_216);
      Ms_8 = "";
      Ms_16 = "";
      if (Month() < 10) Ms_8 = "0";
      if (Day() < 10) Ms_16 = "0";
      str_concat_24 = StringConcatenate(Os_0, "_", Year(), Ms_8, Month(), Ms_16, Day(), "_log.txt");
      Z_file_216 = FileOpen(str_concat_24, FILE_CSV|FILE_WRITE|FILE_READ);
      if (Z_file_216 > 0) {
         FileFlush(Z_file_216);
         FileSeek(Z_file_216, 0, SEEK_END);
      }
   }
}

// CE0BE71E33226E4C1DB2BCEA5959F16B
void f0_9(string Os_0) {
   if (Zi_116) {
      if (Z_file_216 > 0) {
         Os_0 = TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES|TIME_SECONDS) + " " + Os_0;
         FileWrite(Z_file_216, Os_0);
         FileFlush(Z_file_216);
      }
   }
}

// 7BB4737772D59D76D97170BEEB73BEFE
int f0_4() {
   int Mi_0 = GetTimeZoneInformation(Zia_364);
   int Mi_4 = Zia_364[0];
   if (Mi_0 == 1) Mi_4 += Zia_364[21];
   if (Mi_0 == 2) Mi_4 += Zia_364[42];
   return (TimeLocal() + 60 * Mi_4);
}
