window.API = function ( callback ) {

	var api_url			= 'https://api.freegamehosting.eu/cp_api/api.php',
		frm_class		= 'fgh',
		frm_stats		= 'fgh_stats',
		frm_submit		= 'fgh_submit',
		stats_timer		= 0,
		StatsLoop		= '',
		gameinfo 		= {
    "cs": {
        "type": "game",
        "game": "cs",
        "list": true,
        "fullname": "Counter-strike",
        "options": {
            "Hostname": {
                "required": true,
                "type": "text"
            },
            "Maxplayers": {
                "required": true,
                "type": "select",
                "options": {
                    "8": 64642,
                    "20": 44811,
                    "12": 33520,
                    "10": 29776,
                    "2": 27808,
                    "4": 20218,
                    "14": 18493
                }
            },
            "RCON Password": {
                "required": true,
                "type": "text"
            },
            "Password": {
                "type": "text"
            },
            "Map": {
                "required": true,
                "type": "select",
                "options": {
                    "de_dust2": 169173,
                    "aim_map": 15930,
                    "awp_india": 10668,
                    "awp_lego_csgo": 7257,
                    "cs_assault": 5757,
                    "de_mirage": 5685,
                    "de_inferno": 4076,
                    "de_nuke": 2731,
                    "aim_1on1map": 2366,
                    "aim_ak-colt": 1773,
                    "cs_italy": 1758,
                    "de_cache": 1481,
                    "aim_map_usp": 1306,
                    "de_mirage_csgo": 1253,
                    "aim_map2": 1214,
                    "aim_map_esl": 1027,
                    "de_dust": 920,
                    "de_train": 898,
                    "awp_map_esl": 662,
                    "ka_snow": 644,
                    "cs_office": 631,
                    "de_aztec": 526,
                    "de_overpass": 478,
                    "awp_glass2_esl": 476,
                    "de_cbble": 462,
                    "de_tuscan": 330,
                    "aim_dusty": 294,
                    "aim_awp_esl": 257,
                    "cs_estate": 243,
                    "aim_00_awp": 214,
                    "aim_00": 212,
                    "aim_sk_awp": 208,
                    "cs_747": 206,
                    "ka_arena": 198,
                    "cs_militia": 191,
                    "de_survivor": 186,
                    "de_vertigo": 184,
                    "aim_glass2_esl": 175,
                    "aim_famas_x": 149,
                    "aim_fixit": 138,
                    "aim_sk_galil_famas": 136,
                    "ka_matrix": 133,
                    "aim_azze_1": 130,
                    "aim_brucke": 119,
                    "aim_cdp": 116,
                    "de_cpl_strike": 113,
                    "as_oilrig": 112,
                    "de_storm": 111,
                    "de_chateau": 110,
                    "de_cpl_mill": 110,
                    "de_forge": 109,
                    "de_torn": 108,
                    "de_prodigy": 108,
                    "de_piranesi": 108,
                    "ka_longer": 108,
                    "de_cbble_detail": 108,
                    "de_airstrip": 107,
                    "cs_havana": 107,
                    "cs_siege": 107,
                    "cs_backalley": 106
                }
            },
            "Config": {
                "required": true,
                "type": "select",
                "options": {
                    "None": 79655,
                    "Default": 77275,
                    "esl4on4_5on5.cfg": 30727,
                    "esl5on5rl.cfg": 21499,
                    "esl1on1.cfg": 12666,
                    "cpl.cfg": 7379,
                    "esl2on2_3on3.cfg": 5243,
                    "clanbase.cfg": 4648,
                    "esl1on1aml.cfg": 4158
                }
            },
            "VAC": {
                "required": true,
                "type": "checkbox",
                "checked": true
            }
        },
        "gameservers": "none"
    },
    "css": {
        "type": "game",
        "game": "css",
        "list": true,
        "fullname": "Counter-strike: Source",
        "options": {
            "Hostname": {
                "required": true,
                "type": "text"
            },
            "Maxplayers": {
                "required": true,
                "type": "select",
                "options": {
                    "14": 24590,
                    "20": 16838,
                    "2": 13400,
                    "10": 11271,
                    "4": 9570,
                    "8": 4168,
                    "12": 3130
                }
            },
            "RCON Password": {
                "required": true,
                "type": "text"
            },
            "Password": {
                "type": "text"
            },
            "Map": {
                "required": true,
                "type": "select",
                "options": {
                    "de_dust2": 53406,
                    "awp_lego_csgo": 8452,
                    "de_mirage": 4283,
                    "de_nuke": 2681,
                    "cs_assault": 2249,
                    "de_inferno": 1919,
                    "cs_italy": 1618,
                    "cs_office": 1204,
                    "de_dust": 910,
                    "esl_awp_india_mages_v2": 828,
                    "de_tuscan": 573,
                    "awp_garden": 566,
                    "esl_awp_icemap": 489,
                    "de_train": 483,
                    "mg_piratewars_2010": 391,
                    "de_cbble": 369,
                    "de_aztec": 367,
                    "cs_militia": 350,
                    "awp_facti0n_v2": 332,
                    "esl_awp_manor": 262,
                    "cs_compound": 259,
                    "awp_ruins_final": 225,
                    "de_port": 223,
                    "de_season": 209,
                    "esl_awp_pirapira": 193,
                    "awp_niloriver": 192,
                    "awp_deathcanyon_fixed3": 191,
                    "cs_havana": 177,
                    "de_prodigy": 145,
                    "de_piranesi": 138,
                    "de_tides": 130,
                    "de_chateau": 129,
                    "de_tuscan_readme": 97
                }
            },
            "Config": {
                "required": true,
                "type": "select",
                "options": {
                    "Default": 51049,
                    "esl5on5rl.cfg": 13284,
                    "Zblock 4.7 - cb_css.cfg": 8139,
                    "esl1on1.cfg": 4223,
                    "esl4on4_5on5.cfg": 2995,
                    "esl2on2aim.cfg": 1883,
                    "esl1on1aml.cfg": 1770
                }
            },
            "VAC": {
                "required": true,
                "type": "checkbox",
                "checked": true
            }
        },
        "gameservers": "none"
    },
    "csgo": {
        "type": "game",
        "game": "csgo",
        "list": true,
        "fullname": "Counter-strike: Globaloffensive",
        "options": {
            "Hostname": {
                "required": true,
                "type": "text"
            },
            "Maxplayers": {
                "required": true,
                "type": "select",
                "options": {
                    "14": 687777,
                    "10": 367639,
                    "2": 241990,
                    "20": 166975,
                    "4": 140945,
                    "8": 68270,
                    "3": 45478,
                    "5": 39292,
                    "11": 12264,
                    "12": 8447
                }
            },
            "RCON Password": {
                "required": true,
                "type": "text"
            },
            "Password": {
                "type": "text"
            },
            "Map": {
                "required": true,
                "type": "select",
                "options": {
                    "de_mirage": 322008,
                    "aim_map": 231295,
                    "awp_lego_csgo": 145207,
                    "aim_redline": 131174,
                    "de_cache": 72959,
                    "de_dust2": 56681,
                    "de_inferno": 49449,
                    "awp_india_csgo": 26817,
                    "de_overpass": 21062,
                    "aim_deagle": 19801,
                    "aim_ak-colt": 16797,
                    "de_cbble": 16163,
                    "de_train": 15213,
                    "de_nuke": 14506,
                    "aim_p2000": 10210,
                    "awp_pro": 9830,
                    "de_dust2_night": 9628,
                    "aim_map2_go": 9127,
                    "aim_9h_ak": 7921,
                    "cs_office": 7328,
                    "awp_real_lego_go": 7255,
                    "surf_forbidden_ways_ksf": 6782,
                    "de_dust2_original": 6336,
                    "awp_bridge": 4171,
                    "cs_assault": 3943,
                    "cs_italy": 3715,
                    "de_dust2_se": 3469,
                    "aim_crazyjump": 3453,
                    "de_mirage_csgo": 3404,
                    "aim simple": 3372,
                    "de_vertigo": 3231,
                    "aim_dust_go": 3185,
                    "awp_ice_csgo": 3182,
                    "de_dust": 3079,
                    "fy_iceworld_origins": 3032,
                    "de_safehouse": 2882,
                    "de_shortdust": 2692,
                    "aim_glockon": 2572,
                    "seek_hotel_night": 2556,
                    "de_dust2_mirror": 2480,
                    "Seek_Office": 2197,
                    "de_lake": 1926,
                    "de_mirage_mirror": 1923,
                    "de_aztec": 1796,
                    "de_office": 1726,
                    "awp_garden": 1718,
                    "aim_garden": 1636,
                    "awp_map2_origins": 1629,
                    "aim_head2kcss": 1546,
                    "awp_towerzz": 1543,
                    "aim_polar": 1517,
                    "school": 1465,
                    "de_zoo": 1402,
                    "dz_blacksite": 1375,
                    "de_mirage_go": 1372,
                    "de_nuke_se": 1340,
                    "awp_vietnam": 1257,
                    "coop_cementplant": 1246,
                    "aim_bang": 1222,
                    "aim_map_italy": 1179,
                    "awp_bycastor32": 1129,
                    "mg_5v5_football_a4": 1119,
                    "de_mirage_dusk": 1081,
                    "cp_dust2": 1077,
                    "aim_glockon_106_3": 1068,
                    "awp_deathcanyon": 1031,
                    "de_inferno_se": 1027,
                    "de_bank": 958,
                    "cs_militia": 803,
                    "de_shorttrain": 751,
                    "aim_map_nocancer": 742,
                    "de_nuke_ve": 733,
                    "cs_assault_original": 718,
                    "de_747": 678,
                    "de_dust_original": 671,
                    "de_survivor_csgo": 652,
                    "hs_office": 637,
                    "de_inferno_mirror": 596,
                    "ar_shoots": 582,
                    "de_train_2013": 519,
                    "cs_agency": 502,
                    "gd_lake": 482,
                    "gd_cbble": 475,
                    "de_dust_se": 466,
                    "gd_bank": 448,
                    "de_nuke_mirror": 439,
                    "ar_baggage": 434,
                    "de_season": 426,
                    "cs_office_se": 391,
                    "cs_italy_se": 377,
                    "de_inferno_dawn": 364,
                    "de_royal": 352,
                    "de_seaside": 326,
                    "de_santorini": 312,
                    "cs_estate": 303,
                    "de_arcade_v2": 299,
                    "de_aztec_se": 282,
                    "de_cpl_mill": 279,
                    "de_train_se": 275,
                    "de_inferno15_go4pack": 246,
                    "de_infernew_v4": 245,
                    "de_cpl_strike": 244,
                    "cs_insertion": 234,
                    "cs_militia_original": 222,
                    "cp_rooftop": 216,
                    "de_aztec_lg": 213,
                    "de_sugarcane": 200,
                    "de_stmarc": 195,
                    "de_mikla": 194,
                    "de_airstrip_csgo": 194,
                    "de_ali": 194,
                    "de_torntown": 194,
                    "de_empire": 193,
                    "de_tulip": 192,
                    "de_rails": 192,
                    "de_chateau_csgo_b1": 192,
                    "de_winterstorm": 192,
                    "de_corruption_csgo": 192,
                    "ar_monastery": 192,
                    "de_sparity_infinity": 191,
                    "cs_thunder": 191,
                    "gd_crashsite": 191,
                    "de_resort": 191,
                    "de_fasterline_v2": 191,
                    "de_helsing_ver2": 191,
                    "de_mist": 191,
                    "as_oilrig_b1": 191,
                    "de_contra": 191,
                    "de_marquis": 191,
                    "de_capistrano": 191,
                    "de_log": 191,
                    "cs_militia_rc4p": 190,
                    "cs_backalley": 190,
                    "de_dawn": 190,
                    "de_torn_rc1": 190,
                    "de_atrium": 190,
                    "de_storm_sky1": 189,
                    "de_sparity_v37": 189
                }
            },
            "Config": {
                "required": true,
                "type": "select",
                "upload": {
                    "type": ".*",
                    "name": "(.+).cfg",
                    "sizelimit": 60,
                    "location": "csgo\/cfg\/"
                },
                "options": {
                    "esl1on1aim.cfg": 301800,
                    "esl5on5rl.cfg": 121929,
                    "clanbase.cfg": 62274,
                    "esl5on5.cfg": 61400,
                    "esl2on2aim.cfg": 45707,
                    "cevo.cfg": 43474,
                    "esl1on1rl.cfg": 29051,
                    "esl2on2.cfg": 24300,
                    "esl2on2awp.cfg": 20113,
                    "esl3on3.cfg": 16668,
                    "esl2on2hg.cfg": 12590,
                    "esl1on1hg.cfg": 12590
                }
            },
            "Max rounds": {
                "required": true,
                "type": "select",
                "options": {
                    "30": 1385128,
                    "15": 98684,
                    "99": 87006,
                    "10": 49657,
                    "20": 18815,
                    "24": 18789
                }
            },
            "Gametype": {
                "required": true,
                "type": "select",
                "options": {
                    "Classic Competitive": 1303831,
                    "Classic Casual": 177931,
                    "None": 96373,
                    "Deathmatch": 78127,
                    "Arms Race": 12073,
                    "Demolition": 4868,
                    "Danger Zone": 3411
                }
            },
            "VAC": {
                "required": true,
                "type": "checkbox",
                "checked": true
            }
        },
        "gameservers": "none"
    },
    "cod2": {
        "type": "game",
        "game": "cod2",
        "list": true,
        "fullname": "Call of Duty 2",
        "options": {
            "Hostname": {
                "required": true,
                "type": "text"
            },
            "Maxplayers": {
                "required": true,
                "type": "select",
                "options": {
                    "10": 125037,
                    "14": 25952,
                    "4": 12427,
                    "8": 11510,
                    "12": 10155,
                    "2": 8033
                }
            },
            "RCON Password": {
                "required": true,
                "type": "text"
            },
            "Password": {
                "type": "text"
            },
            "Map": {
                "required": true,
                "type": "select",
                "options": {
                    "Toujane": 155388,
                    "Burgundy": 11208,
                    "Carentan": 7664,
                    "Dawnville": 3603,
                    "Leningrad": 2406,
                    "Matmata": 1902,
                    "Farmhouse": 1540,
                    "Downtown": 1321,
                    "Harbor": 1056,
                    "Decoy": 971,
                    "Powcamp": 945,
                    "Tobruk": 912,
                    "Trainstation": 895,
                    "Rhine": 765,
                    "Brecourt": 761,
                    "Vallente": 723,
                    "Breakout": 717,
                    "Toujane Fix": 105,
                    "Burgundy Fix": 39,
                    "Wawa 3dAim": 36,
                    "Carentan Fix": 21,
                    "Trainstation Fix": 11,
                    "Crossroads": 10,
                    "Breakout Tls": 10,
                    "Carentan Bal": 10,
                    "Dawnville Fix": 10,
                    "Vallente Fix": 9,
                    "Leningrad Tls": 9,
                    "Matmata Fix": 6,
                    "Chelm Fix": 4,
                    "Dawnville Sun": 4
                }
            },
            "Mod": {
                "required": true,
                "type": "select",
                "options": {
                    "None": 5804,
                    "ZPAM v3.34 cb": 1118
                }
            },
            "Gametype": {
                "required": true,
                "type": "select",
                "options": {
                    "Search & Destroy": 124767,
                    "Deathmatch": 51218,
                    "Team Deathmatch": 11802,
                    "Capture the Flag": 3696,
                    "Headquaters": 1463
                }
            },
            "Punkbuster": {
                "required": true,
                "type": "checkbox",
                "cmdline_defopt": "+set sv_punkbuster 0",
                "checked": true
            },
            "Version": {
                "required": true,
                "type": "select",
                "options": {
                    "Cracked": 11559,
                    "Original": 1940,
                    "CoD2x": 318,
                    "Reversed": 265
                }
            }
        },
        "gameservers": "none"
    },
    "cod4": {
        "type": "game",
        "game": "cod4",
        "list": true,
        "fullname": "Call of Duty 4",
        "options": {
            "Hostname": {
                "required": true,
                "type": "text"
            },
            "Maxplayers": {
                "required": true,
                "type": "select",
                "options": {
                    "10": 221943,
                    "20": 71099,
                    "4": 44254,
                    "2": 29316,
                    "12": 24002,
                    "8": 20628,
                    "14": 9460
                }
            },
            "RCON Password": {
                "required": true,
                "type": "text"
            },
            "Password": {
                "type": "text"
            },
            "Map": {
                "required": true,
                "type": "select",
                "options": {
                    "Crash": 165001,
                    "Killhouse": 131818,
                    "Shipment": 28332,
                    "Crossfire": 25694,
                    "Backlot": 14850,
                    "Strike": 13243,
                    "Winter crash": 5399,
                    "Vacant": 3019,
                    "Broadcast": 3018,
                    "Showdown": 2989,
                    "Chinatown": 2980,
                    "Bog": 2902,
                    "Creek": 2747,
                    "Overgrown": 2627,
                    "Wet work": 2553,
                    "Bloc": 2550,
                    "District": 2446,
                    "Ambush": 2410,
                    "Pipeline": 2370,
                    "Countdown": 1828,
                    "Downpour": 1643
                }
            },
            "Mod": {
                "required": true,
                "type": "select",
                "options": {
                    "None": 227069,
                    "Promodlive211 Mr12": 70260,
                    "Promodlive220 Mr12": 35937,
                    "modwarfare": 20630,
                    "Promodlive220 Mr10": 15940,
                    "Promodlive211 Public": 13141,
                    "Promodlive217 Mr12": 9774,
                    "Promodlive214 Mr12": 6608,
                    "Promodlive217 Public": 6384,
                    "Promodlive211 Mr10": 4449,
                    "Promodlive214 Public": 3598,
                    "Promodlive214 Mr10": 2192,
                    "Promodlive219 Mr10": 2191,
                    "Promodlive217 Mr10": 2190
                }
            },
            "Gametype": {
                "required": true,
                "type": "select",
                "options": {
                    "Deathmatch": 157337,
                    "Search & Destroy": 152140,
                    "Team Deathmatch": 99690,
                    "Capture the Flag": 6123,
                    "Headquaters": 5029
                }
            },
            "Punkbuster": {
                "required": true,
                "type": "checkbox",
                "cmdline_defopt": "+set sv_punkbuster 0",
                "checked": true
            },
            "Cracked": {
                "required": true,
                "type": "checkbox"
            }
        },
        "gameservers": "none"
    },
    "tf2": {
        "type": "game",
        "game": "tf2",
        "list": true,
        "fullname": "Team Fortress 2",
        "options": {
            "Hostname": {
                "required": true,
                "type": "text"
            },
            "Maxplayers": {
                "required": true,
                "type": "select",
                "options": {
                    "2": 32113,
                    "14": 30270,
                    "4": 21611,
                    "32": 16878,
                    "8": 8937,
                    "10": 4065,
                    "12": 3078
                }
            },
            "RCON Password": {
                "required": true,
                "type": "text"
            },
            "Password": {
                "type": "text"
            },
            "Map": {
                "required": true,
                "type": "select",
                "options": {
                    "ctf_2fort": 47447,
                    "plr_hightower": 14345,
                    "ctf_turbine": 6119,
                    "de_dust2": 4663,
                    "koth_harvest_final": 4407,
                    "pl_upward": 3411,
                    "cp_dustbowl": 2680,
                    "mvm_coaltown": 2621,
                    "ctf_doublecross": 2246,
                    "pl_badwater": 1517,
                    "mvm_ghost_town": 1486,
                    "ctf_sawmill": 1362,
                    "awp_lego_csgo": 1287,
                    "cp_gorge": 1141,
                    "koth_harvest_event": 1136,
                    "itemtest": 1066,
                    "cp_degrootkeep": 1052,
                    "plr_hightower_event": 829,
                    "mvm_mannhattan": 815,
                    "ctf_well": 782,
                    "cp_badlands": 756,
                    "de_mirage": 645,
                    "koth_viaduct": 627,
                    "arena_badlands": 565,
                    "cp_process_final": 562,
                    "pl_goldrush": 551,
                    "koth_nucleus": 507,
                    "koth_sawmill": 499,
                    "mvm_decoy": 460,
                    "arena_sawmill": 385,
                    "mvm_rottenburg": 375,
                    "pl_frontier_final": 374,
                    "cp_5gorge": 367,
                    "koth_badlands": 367,
                    "tr_dustbowl": 360,
                    "koth_king": 331,
                    "cp_egypt_final": 329,
                    "sd_doomsday": 325,
                    "arena_well": 322,
                    "mvm_bigrock": 318,
                    "pl_barnblitz": 312,
                    "de_nuke": 302,
                    "mvm_mannworks": 292,
                    "koth_lakeside_event": 277,
                    "cp_well": 264,
                    "arena_watchtower": 259,
                    "cp_manor_event": 241,
                    "pl_thundermountain": 240,
                    "de_inferno": 231,
                    "tc_hydro": 197,
                    "koth_lakeside_final": 196,
                    "koth_viaduct_event": 196,
                    "arena_nucleus": 188,
                    "cp_cloak": 168,
                    "cp_granary": 165,
                    "pl_hoodoo_final": 164,
                    "cp_foundry": 156,
                    "cp_steel": 152,
                    "cp_snakewater_final1": 151,
                    "cp_coldfront": 145,
                    "koth_pro_viaduct_rc3": 140,
                    "arena_granary": 140,
                    "arena_lumberyard": 137,
                    "tr_target": 137,
                    "cp_mountainlab": 136,
                    "plr_pipeline": 135,
                    "tfdb_catland_v1": 127,
                    "cp_gravelpit": 127,
                    "arena_ravine": 122,
                    "background01": 120,
                    "cp_yukon_final": 116,
                    "arena_offblast_final": 113,
                    "pl_swiftwater_ugc": 111,
                    "plr_nightfall_final": 97,
                    "koth_waste": 94,
                    "pl_barnblitz_pro": 92,
                    "koth_arctic_b3": 91,
                    "cp_gullywash_final1": 90,
                    "koth_ashville_rc1": 88,
                    "maps.sh": 87,
                    "de_overpass": 80,
                    "cp_warmfront": 78,
                    "cp_fastlane": 78,
                    "graphs": 78,
                    "de_cbble": 77,
                    "pl_cashworks_final1": 77,
                    "cp_freight_final1": 76,
                    "pl_beerbowl_b5a": 76,
                    "cp_standin_final": 74,
                    "cp_junction_final": 74,
                    "cp_vanguard_b4a": 74,
                    "cp_edifice_b4": 74,
                    "cp_standin_rc1": 73
                }
            },
            "Config": {
                "required": true,
                "type": "select",
                "options": {
                    "Default": 78031,
                    "esl5on5rl.cfg": 4558,
                    "etf2l_6v6.cfg": 1589,
                    "esl1on1aml.cfg": 1341,
                    "etf2l_9v9.cfg": 993,
                    "wptf2l.cfg": 840,
                    "wpkoth.cfg": 761,
                    "esl4on4_5on5.cfg": 736
                }
            },
            "VAC": {
                "required": true,
                "type": "checkbox",
                "checked": true
            }
        },
        "gameservers": "none"
    },
    "urt": {
        "type": "game",
        "game": "urt",
        "list": true,
        "fullname": "Urban Terror",
        "options": {
            "Hostname": {
                "required": true,
                "type": "text"
            },
            "Maxplayers": {
                "required": true,
                "type": "select",
                "options": {
                    "14": 709,
                    "12": 109,
                    "10": 58,
                    "2": 49,
                    "8": 34,
                    "4": 31
                }
            },
            "Refee Password": {
                "required": true,
                "type": "text"
            },
            "Password": {
                "type": "text"
            },
            "Map": {
                "required": true,
                "type": "select",
                "options": {
                    "ut4_orbital_sl": 733,
                    "ut4_paris_v2": 94,
                    "ut42_jupiter": 58,
                    "ut4_tohunga_b8": 39,
                    "ut42_bstjumps_u2": 35,
                    "ut4_beijing_b3": 31
                }
            },
            "Config": {
                "required": true,
                "type": "select",
                "options": {
                    "uz5v5tdm": 605,
                    "ncts": 94,
                    "uz5v5ts": 53,
                    "uz5v5bomb": 34,
                    "ncbomb": 30,
                    "ncctf": 25,
                    "uz5v5nowave": 16,
                    "uz5v5ctf": 15,
                    "uz5v5ftl": 13,
                    "uz5v5cah": 9
                }
            },
            "Gametype": {
                "required": true,
                "type": "select",
                "options": {
                    "Jump Mode (JUMP)": 481,
                    "Team Survivor (TS)": 163,
                    "Team Deathmatch (TDM)": 94,
                    "Free for All (FFA)": 85,
                    "Bomb &amp; Defuse (BM)": 75,
                    "Capture the Flag (CTF)": 33,
                    "Freeze Tag (FT)": 19,
                    "Capture &amp; Hold (CNH)": 9,
                    "Last Man Standing (LMS)": 7,
                    "Follow the Leader (FTL)": 6
                }
            }
        },
        "gameservers": "none"
    }
},
		current_game	= '',
		http 			= false,
		current_gamearr	= {},
		primary_gs		= {};


	/*
		Prefixes:

		gs 		= Gameserver
		g 		= Game
		f 		= Form

	*/

	this.gChange = function ( game ) {
		gChange( game );
	};

	var gChange = function ( game ) {

    if ( game != '' && gameinfo[game] !== 'undefined' ) {

  		// If there is already a gameservers started, and the required variables have been set.
  		if ( current_game !== 'undefined' && typeof primary_gs.info !== 'undefined' ) {
  			fSetStats( primary_gs.info );
  			gsUpdate();
  			gsLoopStats();
  
  
  		// CHECK if there is already a gameservers started, and set the required variables.
  		} else {
  			for (var gamearr in gameinfo) {
  
  				if ( typeof gameinfo[gamearr].gameservers === 'object' && gameinfo[gamearr].gameservers != 'none' ) {
  
  					current_game 							= gamearr;
  					primary_gs.id							= Object.keys( gameinfo[gamearr].gameservers )[0];
  
  					if ( typeof primary_gs.id !== 'undefined' ) {
  						primary_gs.info 						= gameinfo[gamearr].gameservers[primary_gs.id];
  
  						fSetStats( primary_gs.info );
  						gsUpdate();
  						gsLoopStats();
  						break;
  					} else {
  						primary_gs={};
  					}
  
  				}
  			}
  		}
  
  		// When there is no gameserver started, show the book form.
  		if ( typeof primary_gs.id === 'undefined' ) {
  			current_game 	= game;
  			current_gamearr = gameinfo[game];
  			fSetBook();
  		}

    }

	};

	var fSetStats = function ( ) {

		// Set fgh_stats element on true.
		for ( i=0 ; elem_stats = document.querySelectorAll('[fgh_stats="false"]')[i] ; i++ )
			elem_stats.setAttribute('fgh_stats', 'true');

		// Set fgh_request element on false.
		for ( i=0 ; elem_request = document.querySelectorAll('[fgh_request="true"]')[i] ; i++ )
			elem_request.setAttribute('fgh_request', 'false');

	};
	
	var fSetBook = function ( ) {

	    var elem_notify = document.querySelectorAll('[nice-input="notification"]');
	      for ( i=0 ; i < elem_notify.length ; i++ )
	        elem_notify[i].removeAttribute('fgh_response');

	    var elem_subitem = document.querySelectorAll('[fgh_request] input[fgh_submit]');
	    for ( i=0 ; i < elem_subitem.length ; i++ )
          	elem_subitem[i].closest('.form-item').remove();

        // Create the right elements for all the profiles.
		if ( typeof current_gamearr.profile !== 'undefined' )
		 	fSetElements('profile', '', current_gamearr.profile);

		// Create the right elements for all the options.
		if ( typeof current_gamearr.options !== 'undefined' )
			for (var id in current_gamearr.options)
		  		fSetElements('option', id, current_gamearr.options[id]);

		// Set fgh_stats element on false.
		for ( i=0 ; elem_stats = document.querySelectorAll('[fgh_stats="true"]')[i] ; i++ )
			elem_stats.setAttribute('fgh_stats', 'false');

		// Set fgh_request element on true.
		for ( i=0 ; elem_request = document.querySelectorAll('[fgh_request="false"]')[i] ; i++ )
			elem_request.setAttribute('fgh_request', 'true');

	};

	// Gameserver stats loop.
	var gsLoopStats = function ( ) {

		// Start the gameserver stats loop.
		StatsLoop = setTimeout(function(){
			gsGetStats();
			gsUpdate();
		}, ( stats_timer > 20 )? stats_timer * 1000 : 20000 );

	};

	// Update gameserver info (runn all the functions).
	var gsUpdate = function ( ) {

		if ( typeof primary_gs.info !== 'undefined' )
			fUpdateStats( primary_gs.info );

	};

	// Get the gameserver stats.
	var gsGetStats = function () {

		var request =
		[
			{
		    'type'     		: 'gameserver',
		    'game'      	: current_game,
		    'gameservers'   : true
			}
		];

		APIRequest( request );

	};

	var fUpdateStats = function ( gsInfo ) {

		// Empty fields
		for ( i=0 ; elem = document.querySelectorAll('[fgh_stats="true"] > [fgh_stats]')[i] ; i++ )
			elem.innerHTML='';

		// Set default stats in the correct targets.
		for ( i=0 ; elem = document.querySelectorAll('[fgh_stats="stop"], [fgh_stats="table"], [fgh_stats="map"], [fgh_stats="connect_line"], .fgh_stats')[i] ; i++ ) {

			if ( elem.getAttribute('fgh_stats') == 'map' )
				elem.src = gsInfo.image;
			else if ( elem.getAttribute('fgh_stats') == 'connect_line' )
				elem.innerHTML = gsInfo.connect_line;
			else if ( elem.className == 'fgh_stats' )
				elem.setAttribute('fgh_game', fullgame);

			elem.style.display = '';

		}

		// Go trough the stats, and set them in the correct targets.
		for (var k in gsInfo.stats) {

			if ( k != 'port' ) {

				var stat = k.replace(/^gq_/i, ''),
					elems = document.querySelectorAll('[fgh_stats="true"] > [fgh_stats="' + stat + '"]');

				if ( elems.length > 0 ) {

					for ( i=0 ; i < elems.length ; i++ ) {

						if ( gsInfo.stats[k] != false || !isNaN(gsInfo.stats[k]) === true ) {

							elems[i].style.display 	= '';

							elems[i].innerHTML 		= gsInfo.stats[k];

							//console.log(stat + ' ' + k + ' ' + gsInfo.stats[k]);

						}

					}

				} else {

					console.log('Stats dataset missing: fgh_stats="' + stat + '" (' + gsInfo.stats[k] + ')');

				}

			}

		}

	};

	var fSetElements = function ( type, key, value ) {

		var fgh_request = document.querySelectorAll('[fgh_request]');

		for ( i=0 ; fgh_request[i] ; i++ ) {

			var elem_formitem = document.createElement("DIV");

			elem_formitem.className="form-item";

			if ( type == 'option' ) {

				if ( value.type == 'select' ) {

					var elem_formlabel = document.createElement("LABEL");

					elem_formlabel.setAttribute('nice-input', value.type );

					elem_formlabel.setAttribute('nice-input-placeholder', key );

					elem_formitem.appendChild(elem_formlabel);



					var elem_optionoutp = document.createElement("INPUT");

					elem_optionoutp.placeholder=key;

					elem_optionoutp.name=key;

					elem_optionoutp.type='TEXT';

					elem_optionoutp.setAttribute('fgh_submit', key );

					elem_formlabel.appendChild(elem_optionoutp);



					elem_formoptions = document.createElement("OPTIONS");

					elem_formlabel.appendChild(elem_formoptions);


					var optionoptions=value.options;

					for (var optionname in optionoptions) {

						var elem_formoption  = document.createElement("OPTION");

						elem_formoption.value    = optionname;
						elem_formoption.innerHTML  = optionname;

						if ( elem_formoptions.childNodes.length == 0 ) {

							elem_formoptions.appendChild(elem_formoption);

						} else if ( optionoptions[optionname] > optionoptions[elem_formoptions.firstElementChild.value] ) {

							elem_formoptions.insertBefore(elem_formoption, elem_formoptions.firstElementChild);

						} else {

							elemoptions = elem_formoptions.childNodes;

							for ( oi=0 ; elemoption = elemoptions[oi] ; oi++ ) {

								if ( optionoptions[key] > optionoptions[elemoption.value] ) {
									elem_formoptions.insertBefore(elem_formoption, elemoption);
									return;
								}

							}

							elem_formoptions.appendChild(elem_formoption);

						}

					}

					elem_optionoutp.value=elem_formoptions.firstElementChild.value;

					fgh_request[i].appendChild(elem_formitem);

				} else if ( value.type == 'text' ) {

					var elem_formtext = document.createElement("INPUT");

					elem_formtext.placeholder=key;

					elem_formtext.name=key;

					elem_formtext.type=value.type;

					elem_formtext.setAttribute('fgh_submit', key );

					elem_formtext.setAttribute('nice-input', value.type );

					elem_formitem.appendChild(elem_formtext);

					fgh_request[i].appendChild(elem_formitem);


				} else if ( value.type == 'checkbox' ) {

					var elem_formcheck = document.createElement("INPUT");

					elem_formcheck.placeholder=key;

					elem_formcheck.name=key;

					elem_formcheck.id=key + '-trigger';

					elem_formcheck.type=value.type;

					elem_formcheck.setAttribute('fgh_submit', key );

					elem_formcheck.setAttribute('nice-input', value.type );

					if ( value.type == 'checkbox' && value.checked && value.checked === true )
						elem_formcheck.checked = true;
					else
						elem_formcheck.placeholder = key;

					elem_formitem.appendChild(elem_formcheck);


					var elem_formlabel = document.createElement("LABEL");

					elem_formlabel.innerHTML = key;

					elem_formlabel.htmlFor=key + '-trigger';

					elem_formitem.appendChild(elem_formlabel);


					fgh_request[i].appendChild(elem_formitem);

				}

			} else if ( type == 'profile' ) {

				elem_formitem.style.width="100%";


				var elem_formlabel = document.createElement("LABEL");

				elem_formlabel.setAttribute('nice-input', 'varselect' );

				elem_formitem.appendChild(elem_formlabel);


				var elem_optionoutp = document.createElement("INPUT");

				elem_optionoutp.placeholder='Profile name';

				elem_optionoutp.name='profiles_list';

				elem_optionoutp.type='TEXT';

				elem_optionoutp.setAttribute('fgh_submit', 'profiles_list' );

				elem_formlabel.appendChild(elem_optionoutp);



				elem_formoptions = document.createElement("OPTIONS");

				elem_formlabel.appendChild(elem_formoptions);


				var optionoptions=value.options;

				for (var id in value) {

					var elem_formoption  = document.createElement("OPTION");

					elem_formoption.setAttribute('fgh_profileid', id);
					elem_formoption.innerHTML  = value[id].name;

					elem_formoptions.appendChild(elem_formoption);

				}

				fgh_request[i].appendChild(elem_formitem);

			}

		}

	};

	var fSetProfile = function (id) {

		var profile = current_gamearr.profile[id];

		for ( i=0 ; elem = document.querySelectorAll('[fgh_submit]')[i] ; i++ ) {

			var type = elem.getAttribute('fgh_submit');

			if ( type == 'profiles_list' ) {
				elem.id 			= id;
				elem.value 			= profile.name;
			} else if ( typeof profile.options[type] !== 'undefined' ) {

				if ( elem.type == 'checkbox' || elem.type == 'radio' ) {
					if ( profile.options[type] == '' || profile.options[type] === false )
						elem.checked = false;
					else
						elem.checked = true;
				} else {
					elem.value = profile.options[type];
				}

			}

		}

	};

	var fValuesCollect = function ( tagname = 'fgh_submit' ) {

		elements={};

		for ( i=0 ; elem = document.querySelectorAll('[' + tagname + ']')[i] ; i++ ) {

			var type = elem.getAttribute('fgh_submit');

			if ( type == 'profiles_list' ) {

				elements.profile	= elem.value;

			} else if ( gameinfo[current_game].options[type] ) {

				if ( typeof elements.options === 'undefined' )
					elements.options = {};

				if ( elem.type == 'checkbox' || elem.type == 'radio' ) {
					if ( elem.checked )
						elements.options[type] = true;
					else
						elements.options[type] = false;
				} else {
					elements.options[type] 	= elem.value;
				}

			}

		}

		return elements;

	};

	// API Requests function
	var APIRequest = function ( jsonpost ) {

		var http = ( window.XMLHttpRequest )? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); 
		
		if( ! http )
			return;
		
		http.open('POST', api_url);

		http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

		http.setRequestHeader('API-Request', 'true');

		http.withCredentials = true;

		http.onreadystatechange = function() {

			if ( http.readyState == 4 ) {

				var APIResponse = http.responseText;

		        try {
		          	APIResponse = JSON.parse( http.responseText );
		        } catch (e) {
		        } finally {
		        	APICallback( APIResponse );
		        }

			}

		}

		http.send( JSON.stringify( jsonpost ) );

	};

	// API Requests callback function
	var APICallback = function ( APIResponse ) {

		var APIResponse = APIResponse[0];

		// Run the start function, when the request is a start request.
		if ( typeof APIResponse.start !== 'undefined' && ( APIResponse.start == "missing" || APIResponse.start == "full" ) ) {
			fStart( APIResponse );
		}

		// Run the stop function, when the request is a stop request or when there are no active gameservers anymore.
		else if ( APIResponse.gameservers == 'none' || ( typeof APIResponse.stop !== 'undefined' && APIResponse.stop !== false ) ) {
			fStop( APIResponse );
		}

		// Update info if request is to get new gameserver stats.
		else if ( typeof APIResponse.gameservers !== 'undefined' ) {

			// Update gameservers with the new gameservers list.
			gameinfo[current_game].gameservers 		= APIResponse.gameservers;

			if ( typeof Object.keys( APIResponse.gameservers )[0] !== 'undefined' ) {

				// Set primary gameserver (if there are more then one gameserver has been requested)
				primary_gs.id							= Object.keys( APIResponse.gameservers )[0];

				primary_gs.info 						= APIResponse.gameservers[primary_gs.id];

				// Update the profiles.
				if ( typeof APIResponse.profile !== 'undefined' ) {

					// Update the profile(s).
					gameinfo[APIResponse.game].profile 		= APIResponse.profile;

					// Update profile(s) options.
					for (var profileid in gameinfo[APIResponse.game].profile) {
						gameinfo[APIResponse.game].profile[profileid].options =  JSON.parse( APIResponse.profile[profileid].options );
					}

				}

				fSetStats( primary_gs.info );
				fUpdateStats( primary_gs.info );
				gsLoopStats();

			} else {
				fSetBook( );
			}

		}

	};

	var onclick = window.addEventListener('click', function(e){

		var jsonpost = '';

		if ( e.target.getAttribute('fgh_profileid') !== null ) {

			fSetProfile( e.target.getAttribute('fgh_profileid') );

		}

		if ( e.target.getAttribute('fgh_submit') != null && e.target.getAttribute('fgh_submit') == 'start' ) {

			jsonpost =
			[
			  {
			    'type'      : 'gameserver',
			    'game'      : current_game,
			    'start'     : true,
			    'gameservers' : true,
			    'options'   : {}
			  }
			];

		} else if ( e.target.getAttribute('fgh_stats') != null && e.target.getAttribute('fgh_stats') == 'stop' ) {

			jsonpost =
			[
			  {
			    'type'      : 'gameserver',
			    'game'      : current_game,
			    'stop'      : true,
			    'options'   : {}
			  }
			];

		}

		if ( jsonpost != '' && jsonpost.length > 0 ) {

			var fElements = fValuesCollect();

			for (var name in fElements) {
				jsonpost[0][name] 	= fElements[name];
			}

			APIRequest( jsonpost );

		}

	});

	var fStart = function ( APIResponse ) {

		if ( APIResponse.start == 'missing' ) {

			for ( i=0 ; elem = document.querySelectorAll('[fgh_submit]')[i] ; i++ ) {

				var type = elem.getAttribute('fgh_submit');

				if ( type == 'fail_output' ) {
				  elem.setAttribute( 'fgh_response', 'Missing required input.' );
      			}
				else if ( APIResponse.options[type] === false ) {
					if ( elem.getAttribute( "fgh_required" ) != 'true' )
          				elem.setAttribute( "fgh_required", "true" );
				}
		        else if ( APIResponse.options[type] !== false ) {
		            elem.removeAttribute( "fgh_required" );
				}

			}

		} else if ( APIResponse.start == 'full' ) {

			for ( i=0 ; elem = document.querySelectorAll('[fgh_submit="fail_output"]')[i] ; i++ ) {

				elem.setAttribute( 'fgh_response', 'All our gameserver are in use. Please, try again!' );

			}

		}

	};

	// Function; executed when there are no active gameservers anymore (and/or the gameserver has been forces to stop).
	var fStop = function ( APIResponse ) {

		delete 	gameinfo[APIResponse.game].gameservers[ primary_gs.id ];

		if ( typeof Object.keys( gameinfo[APIResponse.game].gameservers )[0] !== 'undefined' )
			gameinfo[APIResponse.game].gameservers = 'none';
		
		primary_gs={};

		clearTimeout(StatsLoop);

		StatsLoop='';

		// Empty fields
		for ( i=0 ; elem = document.querySelectorAll('[fgh_stats="true"] > [fgh_stats]')[i] ; i++ )
			elem.innerHTML='';

		gChange( current_game );

	};

}

window.API = new API();
