<?php

$GLOBALS['core_country_list'] = array('AF' => 'Afghanistan', 'AL' => 'Albania', 'DZ' => 'Algeria', 'AD' => 'Andorra', 'AO' => 'Angola', 'AG' => 'Antigua and Barbuda', 'AR' => 'Argentina', 'AM' => 'Armenia', 'AU' => 'Australia', 'AT' => 'Austria', 'AZ' => 'Azerbaijan', 'BS' => 'The Bahamas', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BB' => 'Barbados', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BZ' => 'Belize', 'BJ' => 'Benin', 'BT' => 'Bhutan', 'BO' => 'Bolivia', 'BA' => 'Bosnia and Herzegovina', 'BW' => 'Botswana', 'BR' => 'Brazil', 'BN' => 'Brunei', 'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'KH' => 'Cambodia', 'CM' => 'Cameroon', 'CA' => 'Canada', 'CV' => 'Cape Verde', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'CL' => 'Chile', 'CN' => 'China', 'CO' => 'Colombia', 'KM' => 'Comoros', 'CG' => 'Congo, Republic of the', 'CD' => 'Congo, Democratic Republic of the', 'CR' => 'Costa Rica', 'CI' => 'Cote d\'Ivoire', 'HR' => 'Croatia', 'CU' => 'Cuba', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'DJ' => 'Djibouti', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'TL' => 'Timor-Leste', 'EC' => 'Ecuador', 'EG' => 'Egypt', 'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'EE' => 'Estonia', 'ET' => 'Ethiopia', 'FJ' => 'Fiji', 'FI' => 'Finland', 'FR' => 'France', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GE' => 'Georgia', 'DE' => 'Germany', 'GH' => 'Ghana', 'GR' => 'Greece', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GT' => 'Guatemala', 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HT' => 'Haiti', 'HN' => 'Honduras', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran', 'IQ' => 'Iraq', 'IE' => 'Ireland', 'IL' => 'Israel', 'IT' => 'Italy', 'JM' => 'Jamaica', 'JP' => 'Japan', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', 'KI' => 'Kiribati', 'KP' => 'Korea, North', 'KR' => 'Korea, South', 'ZZ' => 'Kosovo', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Laos', 'LV' => 'Latvia', 'LB' => 'Lebanon', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libya', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MK' => 'Macedonia', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'ML' => 'Mali', 'MT' => 'Malta', 'MH' => 'Marshall Islands', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'MX' => 'Mexico', 'FM' => 'Micronesia, Federated States of', 'MD' => 'Moldova', 'MC' => 'Monaco', 'MN' => 'Mongolia', 'ME' => 'Montenegro', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'MM' => 'Myanmar (Burma)', 'NA' => 'Namibia', 'NR' => 'Nauru', 'NP' => 'Nepal', 'NL' => 'Netherlands', 'NZ' => 'New Zealand', 'NI' => 'Nicaragua', 'NE' => 'Niger', 'NG' => 'Nigeria', 'NO' => 'Norway', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PW' => 'Palau', 'PA' => 'Panama', 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', 'PE' => 'Peru', 'PH' => 'Philippines', 'PL' => 'Poland', 'PT' => 'Portugal', 'QA' => 'Qatar', 'RO' => 'Romania', 'RU' => 'Russia', 'RW' => 'Rwanda', 'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint Lucia', 'VC' => 'Saint Vincent and the Grenadines', 'WS' => 'Samoa', 'SM' => 'San Marino', 'ST' => 'Sao Tome and Principe', 'SA' => 'Saudi Arabia', 'SN' => 'Senegal', 'RS' => 'Serbia', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SG' => 'Singapore', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'SB' => 'Solomon Islands', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'SS' => 'South Sudan', 'ES' => 'Spain', 'LK' => 'Sri Lanka', 'SD' => 'Sudan', 'SR' => 'Suriname', 'SZ' => 'Swaziland', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'SY' => 'Syria', 'TW' => 'Taiwan', 'TJ' => 'Tajikistan', 'TZ' => 'Tanzania', 'TH' => 'Thailand', 'TG' => 'Togo', 'TO' => 'Tonga', 'TT' => 'Trinidad and Tobago', 'TN' => 'Tunisia', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'TV' => 'Tuvalu', 'UG' => 'Uganda', 'UA' => 'Ukraine', 'AE' => 'United Arab Emirates', 'GB' => 'United Kingdom', 'US' => 'United States of America', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VU' => 'Vanuatu', 'VA' => 'Vatican City (Holy See)', 'VE' => 'Venezuela', 'VN' => 'Vietnam', 'YE' => 'Yemen', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe', 'HK' => 'Hong Kong');

$GLOBALS['core_state_list'] = array(

"AF" => "Badakhshan|Badghis|Baghlan|Balkh|Bamian|Farah|Faryab|Ghazni|Ghowr|Helmand|Herat|Jowzjan|Kabol|Kandahar|Kapisa|Konar|Kondoz|Laghman|Lowgar|Nangarhar|Nimruz|Oruzgan|Paktia|Paktika|Parvan|Samangan|Sar-e Pol|Takhar|Vardak|Zabol",
"AL" => "Berat|Bulqize|Delvine|Devoll [Bilisht]|Diber [Peshkopi]|Durres|Elbasan|Fier|Gjirokaster|Gramsh|Has [Krume]|Kavaje|Kolonje [Erseke]|Korce|Kruje|Kucove|Kukes|Kurbin|Lezhe|Librazhd|Lushnje|Malesi e Madhe [Koplik|Mallakaster [Ballsh]|Mat [Burrel]|Mirdite [Rreshen]|Peqin|Permet|Pogradec|Puke|Sarande|Shkoder|Skrapar [Corovode]|Tepelene|Tirane [Tirana]|Tirane [Tirana]|Tropoje [Bajram Curri]|Vlore",
 'DZ' => 'Adrar|Ain Defla|Ain Temouchent|Alger|Annaba|Batna|Bechar|Bejaia|Biskra|Blida|Bordj Bou Arreridj|Bouira|Boumerdes|Chlef|Constantine|Djelfa|El Bayadh|El Oued|El Tarf|Ghardaia|Guelma|Illizi|Jijel|Khenchela|Laghouat|M\'Sila|Mascara|Medea|Mila|Mostaganem|Naama|Oran|Ouargla|Oum el Bouaghi|Relizane|Saida|Setif|Sidi Bel Abbes|Skikda|Souk Ahras|Tamanghasset|Tebessa|Tiaret|Tindouf|Tipaza|Tissemsilt|Tizi Ouzou|Tlemcen', 
 'AD' => 'Andorra', 
 'AO' => 'Andorra la Vella|Bengo|Benguela|Bie|Cabinda|Canillo|Cuando Cubango|Cuanza Norte|Cuanza Sul|Cunene|Encamp|Escaldes-Engordany|Huambo|Huila|La Massana|Luanda|Lunda Norte|Lunda Sul|Malanje|Moxico|Namibe|Ordino|Sant Julia de Loria|Uige|Zaire', 
 'AG' => 'Barbuda|Redonda|Saint George|Saint John|Saint Mary|Saint Paul|Saint Peter|Saint Philip', 
 'AR' => 'Antartica e Islas del Atlantico Sur|Buenos Aires|Buenos Aires Capital Federal|Catamarca|Chaco|Chubut|Cordoba|Corrientes|Entre Rios|Formosa|Jujuy|La Pampa|La Rioja|Mendoza|Misiones|Neuquen|Rio Negro|Salta|San Juan|San Luis|Santa Cruz|Santa Fe|Santiago del Estero|Tierra del Fuego|Tucuman', 
 'AM' => 'Aragatsotn|Ararat|Armavir|Geghark unik|Kotayk|Lorri|Shirak|Syunik|Tavush|Vayots|Dzor|Yerevan', 
 'AU' => 'Australian Capital Territory|New South Wales|Northern Territory|Queensland|South Australia|Tasmania|Victoria|Western Australia', 
 'AT' => 'Burgenland|Kaernten|Niederoesterreich|Oberoesterreich|Salzburg|Steiermark|Tirol|Vorarlberg|Wien',  
 'AZ' => 'Abseron Rayonu|Agcabadi Rayonu|Agdam Rayonu|Agdas Rayonu|Agstafa Rayonu|Agsu Rayonu|Ali Bayramli Sahari|Astara Rayonu|Baki Sahari|Balakan Rayonu|Barda Rayonu|Beylaqan Rayonu|Bilasuvar Rayonu|Cabrayil Rayonu|Calilabad Rayonu|Daskasan Rayonu|Davaci Rayonu|Fuzuli Rayonu|Gadabay Rayonu|Ganca Sahari|Goranboy Rayonu|Goycay Rayonu|Haciqabul Rayonu|Imisli Rayonu|Ismayilli Rayonu|Kalbacar Rayonu|Kurdamir Rayonu|Lacin Rayonu|Lankaran Rayonu|Lankaran Sahari|Lerik Rayonu|Masalli Rayonu|Mingacevir Sahari|Naftalan Sahari|Naxcivan Muxtar Respublikasi|Neftcala Rayonu|Oguz Rayonu|Qabala Rayonu|Qax Rayonu|Qazax Rayonu|Qobustan Rayonu|Quba Rayonu|Qubadli Rayonu|Qusar Rayonu|Saatli Rayonu|Sabirabad Rayonu|Saki Rayonu|Saki Sahari|Salyan Rayonu|Samaxi Rayonu|Samkir Rayonu|Samux Rayonu|Siyazan Rayonu|Sumqayit Sahari|Susa Rayonu|Susa Sahari|Tartar Rayonu|Tovuz Rayonu|Ucar Rayonu|Xacmaz Rayonu|Xankandi Sahari|Xanlar Rayonu|Xizi Rayonu|Xocali Rayonu|Xocavand Rayonu|Yardimli Rayonu|Yevlax Rayonu|Yevlax Sahari|Zangilan Rayonu|Zaqatala Rayonu|Zardab Rayonu', 
 'BS' => 'Acklins and Crooked Islands|Bimini|Cat Island|Exuma|Freeport|Fresh Creek|Governors Harbour|Green Turtle Cay|Harbour Island|High Rock|Inagua|Kemps Bay|Long Island|Marsh Harbour|Mayaguana|New Providence|Nicholls Town and Berry Islands|Ragged Island|Rock Sound|San Salvador and Rum Cay|Sandy Point', 
 'BH' => 'Al Hadd|Al Manamah|Al Mintaqah al Gharbiyah|Al Mintaqah al Wusta|Al Mintaqah ash Shamaliyah|Al Muharraq|Ar Rifa wa al Mintaqah al Janubiyah|Jidd Hafs|Juzur Hawar|Madinat Isa|Madinat Hamad|Sitrah', 
 'BD' => 'Barguna|Barisal|Bhola|Jhalokati|Patuakhali|Pirojpur|Bandarban|Brahmanbaria|Chandpur|Chittagong|Comilla|Coxs Bazar|Feni|Khagrachari|Lakshmipur|Noakhali|Rangamati|Dhaka|Faridpur|Gazipur|Gopalganj|Jamalpur|Kishoreganj|Madaripur|Manikganj|Munshiganj|Mymensingh|Narayanganj|Narsingdi|Netrokona|Rajbari|Shariatpur|Sherpur|Tangail|Bagerhat|Chuadanga|Jessore|Jhenaidah|Khulna|Kushtia|Magura|Meherpur|Narail|Satkhira|Bogra|Dinajpur|Gaibandha|Jaipurhat|Kurigram|Lalmonirhat|Naogaon|Natore|Nawabganj|Nilphamari|Pabna|Panchagarh|Rajshahi|Rangpur|Sirajganj|Thakurgaon|Habiganj|Maulvi bazar|Sunamganj|Sylhet', 
 'BB' => 'Bridgetown|Christ Church|Saint Andrew|Saint George|Saint James|Saint John|Saint Joseph|Saint Lucy|Saint Michael|Saint Peter|Saint Philip|Saint Thomas', 
 'BY' => 'Brestskaya [Brest]|Homyel skaya [Homyel]|Horad Minsk|Hrodzyenskaya [Hrodna]|Mahilyowskaya [Mahilyow]|Minskaya|Vitsyebskaya [Vitsyebsk]', 
 'BE' => 'Antwerpen|Brabant Wallon|Brussels Capitol Region|Hainaut|Liege|Limburg|Luxembourg|Namur|Oost-Vlaanderen|Vlaams Brabant|West-Vlaanderen', 
 
 
  'BZ' => 'Belize|Cayo|Corozal|Orange Walk|Stann Creek|Toledo', 
'BJ' => 'Alibori|Atakora|Atlantique|Borgou|Collines|Couffo|Donga|Littoral|Mono|Oueme|Plateau|Zou', 
 'BM' => 'Devonshire|Hamilton|Hamilton|Paget|Pembroke|Saint George|Saint Georges|Sandys|Smiths|Southampton|Warwick', 
'BT' => 'Bumthang|Chhukha|Chirang|Daga|Geylegphug|Ha|Lhuntshi|Mongar|Paro|Pemagatsel|Punakha|Samchi|Samdrup Jongkhar|Shemgang|Tashigang|Thimphu|Tongsa|Wangdi Phodrang', 
'BO' => 'Beni|Chuquisaca|Cochabamba|La Paz|Oruro|Pando|Potosi|Santa Cruz|Tarija', 
 
'BQ' => 'Bonaire',

'BA' => 'Federation of Bosnia and Herzegovina|Republika Srpska', 
'BW' => 'Central|Chobe|Francistown|Gaborone|Ghanzi|Kgalagadi|Kgatleng|Kweneng|Lobatse|Ngamiland|North-East|Selebi-Pikwe|South-East|Southern', 
'BV' => 'Bouvet Island', 
'BR' => 'Acre|Alagoas|Amapa|Amazonas|Bahia|Ceara|Distrito Federal|Espirito Santo|Goias|Maranhao|Mato Grosso|Mato Grosso do Sul|Minas Gerais|Para|Paraiba|Parana|Pernambuco|Piaui|Rio de Janeiro|Rio Grande do Norte|Rio Grande do Sul|Rondonia|Roraima|Santa Catarina|Sao Paulo|Sergipe|Tocantins', 

 'IO' => 'British Indian Ocean Territory', 
 'BN' => 'Belait|Brunei and Muara|Temburong|Tutong', 
 'BG' => 'Blagoevgrad|Burgas|Dobrich|Gabrovo|Khaskovo|Kurdzhali|Kyustendil|Lovech|Montana|Pazardzhik|Pernik|Pleven|Plovdiv|Razgrad|Ruse|Shumen|Silistra|Sliven|Smolyan|Sofiya|Sofiya-Grad|Stara Zagora|Turgovishte|Varna|Veliko Turnovo|Vidin|Vratsa|Yambol', 

'BF' => 'Bale|Bam|Banwa|Bazega|Bougouriba|Boulgou|Boulkiemde|Comoe|Ganzourgou|Gnagna|Gourma|Houet|Ioba|Kadiogo|Kenedougou|Komandjari|Kompienga|Kossi|Koupelogo|Kouritenga|Kourweogo|Leraba|Loroum|Mouhoun|Nahouri|Namentenga|Naumbiel|Nayala|Oubritenga|Oudalan|Passore|Poni|Samentenga|Sanguie|Seno|Sissili|Soum|Sourou|Tapoa|Tuy|Yagha|Yatenga|Ziro|Zondomo|Zoundweogo',

'BI' => 'Bubanza|Bujumbura|Bururi|Cankuzo|Cibitoke|Gitega|Karuzi|Kayanza|Kirundo|Makamba|Muramvya|Muyinga|Mwaro|Ngozi|Rutana|Ruyigi',
 'KH' => 'Banteay Mean Cheay|Batdambang|Kampong Cham|Kampong Chhnang|Kampong Spoe|Kampong Thum|Kampot|Kandal|Kaoh Kong|Keb|Kracheh|Mondol Kiri|Otdar Mean Cheay|Pailin|Phnum Penh|Pouthisat|Preah Seihanu [Sihanoukville]|Preah Vihear|Prey Veng|Rotanah Kiri|Siem Reab|Stoeng Treng|Svay Rieng|Takev', 
 'CM' => 'Adamaoua|Centre|Est|Extreme-Nord|Littoral|Nord|Nord-Ouest|Ouest|Sud|Sud-Ouest', 
 'CA' => 'Alberta|British Columbia|Manitoba|New Brunswick|Newfoundland|Northwest Territories|Nova Scotia|Nunavut|Ontario|Prince Edward Island|Quebec|Saskatchewan|Yukon', 
'CV' => 'Boa Vista|Brava|Maio|Mosteiros|Paul|Porto Novo|Praia|Ribeira Grande|Sal|Santa Catarina|Santa Cruz|Sao Domingos|Sao Filipe|Sao Nicolau|Sao Vicente|Tarrafal',
'KY' => 'Creek|Eastern|Midland|South Town|Spot Bay|Stake Bay|West End|Western', 
'CF' => 'Bamingui-Bangoran|Bangui|Basse-Kotto|Gribingui|Haut-Mbomou|Haute-Kotto|Haute-Sangha|Kemo-Gribingui|Lobaye|Mbomou|Nana-Mambere|Ombella-Mpoko|Ouaka|Ouham|Ouham-Pende|Sangha|Vakaga',


 
'TD'=> 'Batha|Biltine|Borkou-Ennedi-Tibesti|Chari-Baguirmi|Guera|Kanem|Lac|Logone Occidental|Logone Oriental|Mayo-Kebbi|Moyen-Chari|Ouaddai|Salamat|Tandjile',
'CL'=> "Aisen del General Carlos Ibanez del Campo|Antofagasta|Araucania|Atacama|Bio-Bio|Coquimbo|Libertador General Bernardo O'Higgins|Los Lagos|Magallanes y de la Antartica Chilena|Maule|Region Metropolitana [Santiago]|Tarapaca|Valparaiso", 
'CN'=> 'Anhui|Beijing|Chongqing|Fujian|Gansu|Guangdong|Guangxi|Guizhou|Hainan|Hebei|Heilongjiang|Henan|Hubei|Hunan|Jiangsu|Jiangxi|Jilin|Liaoning|Nei Mongol|Ningxia|Qinghai|Shaanxi|Shandong|Shanghai|Shanxi|Sichuan|Tianjin|Xinjiang|Xizang [Tibet]|Yunnan|Zhejiang', 
 'CX'=> 'Christmas Island', 
'CC'=> 'Direction Island|Home Island|Horsburgh Island|North Keeling Island|South Island|West Island', 
'CO'=> 'Amazonas|Antioquia|Arauca|Atlantico|Bolivar|Boyaca|Caldas|Caqueta|Casanare|Cauca|Cesar|Choco|Cordoba|Cundinamarca|Distrito Capital de Santa Fe de Bogota|Guainia|Guaviare|Huila|La Guajira|Magdalena|Meta|Narino|Norte de Santander|Putumayo|Quindio|Risaralda|San Andres y Providencia|Santander|Sucre|Tolima|Valle del Cauca|Vaupes|Vichada',
'KM'=> 'Anjouan [Nzwani]|Domoni|Fomboni|Grande Comore [Njazidja]|Moheli [Mwali]|Moroni|Moutsamoudou',
'CG'=> 'Bouenza|Brazzaville|Cuvette|Kouilou|Lekoumou|Likouala|Niari|Plateaux|Pool|Sangha',
'CD'=> 'Bandundu|Bas-Congo|Equateur|Kasai-Occidental|Kasai-Oriental|Katanga|Kinshasa|Maniema|Nord-Kivu|Orientale|Sud-Kivu',
'CK'=> 'Aitutaki|Atiu|Avarua|Mangaia|Manihiki|Manuae|Mauke|Mitiaro|Nassau Island|Palmerston|Penrhyn|Pukapuka|Rakahanga|Rarotonga|Suwarrow|Takutea',
'CR'=> 'Alajuela|Cartago|Guanacaste|Heredia|Limon|Puntarenas|San Jose', 
'CI' => "Abengourou|Abidjan|Aboisso|Adiake'|Adzope|Agboville|Agnibilekrou|Ale'pe'|Bangolo|Beoumi|Biankouma|Bocanda|Bondoukou|Bongouanou|Bouafle|Bouake|Bouna|Boundiali|Dabakala|Dabon|Daloa|Danane|Daoukro|Dimbokro|Divo|Duekoue|Ferkessedougou|Gagnoa|Grand Bassam|Grand-Lahou|Guiglo|Issia|Jacqueville|Katiola|Korhogo|Lakota|Man|Mankono|Mbahiakro|Odienne|Oume|Sakassou|San-Pedro|Sassandra|Seguela|Sinfra|Soubre|Tabou|Tanda|Tiassale|Tiebissou|Tingrela|Touba|Toulepleu|Toumodi|Vavoua|Yamoussoukro|Zuenoula", 
'HR'=> 'Bjelovarsko-Bilogorska Zupanija|Brodsko-Posavska Zupanija|Dubrovacko-Neretvanska Zupanija|Istarska Zupanija|Karlovacka Zupanija|Koprivnicko-Krizevacka Zupanija|Krapinsko-Zagorska Zupanija|Licko-Senjska Zupanija|Medimurska Zupanija|Osjecko-Baranjska Zupanija|Pozesko-Slavonska Zupanija|Primorsko-Goranska Zupanija|Sibensko-Kninska Zupanija|Sisacko-Moslavacka Zupanija|Splitsko-Dalmatinska Zupanija|Varazdinska Zupanija|Viroviticko-Podravska Zupanija|Vukovarsko-Srijemska Zupanija|Zadarska Zupanija|Zagreb|Zagrebacka Zupanija', 
'CU'=> 'Camaguey|Ciego de Avila|Cienfuegos|Ciudad de La Habana|Granma|Guantanamo|Holguin|Isla de la Juventud|La Habana|Las Tunas|Matanzas|Pinar del Rio|Sancti Spiritus|Santiago de Cuba|Villa Clara',
'CW'=> 'Curacao',
'CY'=> 'Famagusta|Kyrenia|Larnaca|Limassol|Nicosia|Paphos', 
'CZ'=> 'Brnensky|Budejovicky|Jihlavsky|Karlovarsky|Kralovehradecky|Liberecky|Olomoucky|Ostravsky|Pardubicky|Plzensky|Praha|Stredocesky|Ustecky|Zlinsky', 
'DK'=> 'Arhus|Bornholm|Fredericksberg|Frederiksborg|Greenland|Fyn|Kobenhavn|Kobenhavns|Nordjylland|Ribe|Ringkobing|Roskilde|Sonderjylland|Storstrom|Vejle|Vestsjalland|Viborg',
'DJ'=> "'Ali Sabih|Dikhil|Djibouti|Obock|Tadjoura", 
'DM'=> 'Saint Andrew|Saint David|Saint George|Saint John|Saint Joseph|Saint Luke|Saint Mark|Saint Patrick|Saint Paul|Saint Peter', 
'DO'=> 'Azua|Baoruco|Barahona|Dajabon|Distrito Nacional|Duarte|El Seibo|Elias Pina|Espaillat|Hato Mayor|Independencia|La Altagracia|La Romana|La Vega|Maria Trinidad Sanchez|Monsenor Nouel|Monte Cristi|Monte Plata|Pedernales|Peravia|Puerto Plata|Salcedo|Samana|San Cristobal|San Juan|San Pedro de Macoris|Sanchez Ramirez|Santiago|Santiago Rodriguez|Valverde', 
'EC'=> 'Azuay|Bolivar|Canar|Carchi|Chimborazo|Cotopaxi|El Oro|Esmeraldas|Galapagos|Guayas|Imbabura|Loja|Los Rios|Manabi|Morona-Santiago|Napo|Orellana|Pastaza|Pichincha|Sucumbios|Tungurahua|Zamora-Chinchipe',
'EG'=> "Ad Daqahliyah|Al Bahr al Ahmar|Al Buhayrah|Al Fayyum|Al Gharbiyah|Al Iskandariyah|Al Isma'iliyah|Al Jizah|Al Minufiyah|Al Minya|Al Qahirah|Al Qalyubiyah|Al Wadi al Jadid|As Suways|Ash Sharqiyah|Aswan|Asyut|Bani Suwayf|Bur Sa'id|Dumyat|Janub Sina'|Kafr ash Shaykh|Matruh|Qina|Shamal Sina'|Suhaj",
'SV'=> 'Ahuachapan|Cabanas|Chalatenango|Cuscatlan|La Libertad|La Paz|La Union|Morazan|San Miguel|San Salvador|San Vicente|Santa Ana|Sonsonate|Usulutan',
'GQ'=> 'Annobon|Bioko Norte|Bioko Sur|Centro Sur|Kie-Ntem|Litoral|Wele-Nzas',
'ER'=> 'Akale Guzay|Barka|Denkel|Hamasen|Sahil|Semhar|Senhit|Seraye',
'EE'=> 'Harjumaa [Tallinn]|Hiiumaa [Kardla]|Ida-Virumaa [Johvi]|Jarvamaa [Paide]|Jogevamaa [Jogeva]|Laane-Virumaa [Rakvere]|Laanemaa [Haapsalu]|Parnumaa [Parnu]|Polvamaa [Polva]|Raplamaa [Rapla]|Saaremaa [Kuessaare]|Tartumaa [Tartu]|Valgamaa [Valga]|Viljandimaa [Viljandi]|Vorumaa [Voru]',
 'ET'=> 'Adis Abeba [Addis Ababa]|Afar|Amara|Dire Dawa|Gambela Hizboch|Hareri Hizb|Oromiya|Sumale|Tigray|YeDebub Biheroch Bihereseboch na Hizboch', 
'FK'=> 'Falkland Islands [Islas Malvinas]', 
'FO'=>  'Bordoy|Eysturoy|Mykines|Sandoy|Skuvoy|Streymoy|Suduroy|Tvoroyri|Vagar',
'FJ'=> 'Central|Eastern|Northern|Rotuma|Western',
'FI'=> 'Aland|Etela-Suomen Laani|Ita-Suomen Laani|Lansi-Suomen Laani|Lappi|Oulun Laani', 
'FR'=> "Alsace|Aquitaine|Auvergne|Basse-Normandie|Bourgogne|Bretagne|Centre|Champagne-Ardenne|Corse|Franche-Comte|Haute-Normandie|Ile-de-France|Languedoc-Roussillon|Limousin|Lorraine|Midi-Pyrenees|Nord-Pas-de-Calais|Pays de la Loire|Picardie|Poitou-Charentes|Provence-Alpes-Cote d'Azur|Rhone-Alpes",
'GF'=> 'French Guiana',
'PF'=> 'Archipel des Marquises|Archipel des Tuamotu|Archipel des Tubuai|Iles du Vent|Iles Sous-le-Vent', 
 'TF'=> 'Adelie Land|Ile Crozet|Iles Kerguelen|Iles Saint-Paul et Amsterdam',
'GA'=> 'Estuaire|Haut-Ogooue|Moyen-Ogooue|Ngounie|Nyanga|Ogooue-Ivindo|Ogooue-Lolo|Ogooue-Maritime|Woleu-Ntem',
 'GM'=> 'Banjul|Central River|Lower River|North Bank|Upper River|Western',
'GE'=> "Abashis|Abkhazia or Ap'khazet'is Avtonomiuri Respublika [Sokhumi]|Adigenis|Ajaria or Acharis Avtonomiuri Respublika [Bat'umi]|Akhalgoris|Akhalk'alak'is|Akhalts'ikhis|Akhmetis|Ambrolauris|Aspindzis|Baghdat'is|Bolnisis|Borjomis|Ch'khorotsqus|Ch'okhatauris|Chiat'ura|Dedop'listsqaros|Dmanisis|Dushet'is|Gardabanis|Gori|Goris|Gurjaanis|Javis|K'arelis|K'ut'aisi|Kaspis|Kharagaulis|Khashuris|Khobis|Khonis|Lagodekhis|Lanch'khut'is|Lentekhis|Marneulis|Martvilis|Mestiis|Mts'khet'is|Ninotsmindis|Onis|Ozurget'is|P'ot'i|Qazbegis|Qvarlis|Rust'avi|Sach'kheris|Sagarejos|Samtrediis|Senakis|Sighnaghis|T'bilisi|T'elavis|T'erjolis|T'et'ritsqaros|T'ianet'is|Tqibuli|Ts'ageris|Tsalenjikhis|Tsalkis|Tsqaltubo|Vanis|Zestap'onis|Zugdidi|Zugdidis", 
'DE'=> 'Brandenburg|Berlin|Baden-W\xfcrttemberg|Bayern [Bavaria]|Bremen|Hessen|Hamburg|Mecklenburg-Vorpommern|Niedersachsen [Lower Saxony]|Nordrhein-Westfalen|Rheinland-Pfalz [Palatinate]|Schleswig-Holstein|Saarland|Sachsen [Saxony]|Sachsen-Anhalt [Saxony-Anhalt]|Th\xfcringen [Thuringia]',
 'GH'=> 'Ashanti|Brong-Ahafo|Central|Eastern|Greater Accra|Northern|Upper East|Upper West|Volta|Western',
'GI'=> 'Gibraltar', 
'GR'=> 'Achaea|Aetolia-Acarnania|Arcadia|Argolis|Arta|Athens|Boeotia|Chalcidice|Chania|Chios|Corfu|Corinthia|Cyclades|Dodecanese|Drama|East Attica|Elis|Euboea|Evros|Evrytania|Florina|Grevena|Heraklion|Imathia|Ioannina|Karditsa|Kastoria|Kavala|Kefalonia and Ithaka|Kilkis|Kozani|Laconia|Larissa|Lasithi|Lefkada|Lesbos|Magnesia|Messenia|Pella|Phocis|Phthiotis|Pieria|Piraeus|Preveza|Rethymno|Rhodope|Samos|Serres|Thesprotia|Thessaloniki|Trikala|West Attica|Xanthi|Zakynthos',
'GL'=> 'Avannaa [Nordgronland]|Kitaa [Vestgronland]|Tunu [Ostgronland]', 
'GD'=> 'Carriacou and Petit Martinique|Saint Andrew|Saint David|Saint George|Saint John|Saint Mark|Saint Patrick',
'GP'=> 'Basse-Terre|Grande-Terre|Iles de la Petite Terre|Iles des Saintes|Marie-Galante', 
'GU'=> 'Guam',
'GT'=> 'Alta Verapaz|Baja Verapaz|Chimaltenango|Chiquimula|El Progreso|Escuintla|Guatemala|Huehuetenango|Izabal|Jalapa|Jutiapa|Peten|Quetzaltenango|Quiche|Retalhuleu|Sacatepequez|San Marcos|Santa Rosa|Solola|Suchitepequez|Totonicapan|Zacapa',
 
'GG' => 'Castel|Forest|St. Andrew|St. Martin|St. Peter Port|St. Pierre du Bois|St. Sampson|St. Saviour|Torteval|Vale', 
'GN'	=> 'Beyla|Boffa|Boke|Conakry|Coyah|Dabola|Dalaba|Dinguiraye|Dubreka|Faranah|Forecariah|Fria|Gaoual|Gueckedou|Kankan|Kerouane|Kindia|Kissidougou|Koubia|Koundara|Kouroussa|Labe|Lelouma|Lola|Macenta|Mali|Mamou|Mandiana|Nzerekore|Pita|Siguiri|Telimele|Tougue|Yomou', 
'GW'	=> 'Bafata|Biombo|Bissau|Bolama-Bijagos|Cacheu|Gabu|Oio|Quinara|Tombali',  
'GY'	=> 'Barima-Waini|Cuyuni-Mazaruni|Demerara-Mahaica|East Berbice-Corentyne|Essequibo Islands-West Demerara|Mahaica-Berbice|Pomeroon-Supenaam|Potaro-Siparuni|Upper Demerara-Berbice|Upper Takutu-Upper Essequibo', 
'HT'	=> "Artibonite|Centre|Grand'Anse|Nord|Nord-Est|Nord-Ouest|Ouest|Sud|Sud-Est",  
'HM'	=> 'Heard Island and McDonald Islands',  
'VA' 	=> 'Holy See [Vatican City]', 
'HN'	=> 'Atlantida|Choluteca|Colon|Comayagua|Copan|Cortes|El Paraiso|Francisco Morazan|Gracias a Dios|Intibuca|Islas de la Bahia|La Paz|Lempira|Ocotepeque|Olancho|Santa Barbara|Valle|Yoro',  
'HK'	=> 'Hong Kong', 
'HU'	=> 'Bacs-Kiskun|Baranya|Bekes|Bekescsaba|Borsod-Abauj-Zemplen|Budapest|Csongrad|Debrecen|Dunaujvaros|Eger|Fejer|Gyor|Gyor-Moson-Sopron|Hajdu-Bihar|Heves|Hodmezovasarhely|Jasz-Nagykun-Szolnok|Kaposvar|Kecskemet|Komarom-Esztergom|Miskolc|Nagykanizsa|Nograd|Nyiregyhaza|Pecs|Pest|Somogy|Sopron|Szabolcs-Szatmar-Bereg|Szeged|Szekesfehervar|Szolnok|Szombathely|Tatabanya|Tolna|Vas|Veszprem|Veszprem|Zala|Zalaegerszeg', 
'IS'=> 'Akranes|Akureyri|Arnessysla|Austur-Bardhastrandarsysla|Austur-Hunavatnssysla|Austur-Skaftafellssysla|Borgarfjardharsysla|Dalasysla|Eyjafjardharsysla|Gullbringusysla|Hafnarfjordhur|Husavik|Isafjordhur|Keflavik|Kjosarsysla|Kopavogur|Myrasysla|Neskaupstadhur|Nordhur-Isafjardharsysla|Nordhur-Mulasys-la|Nordhur-Thingeyjarsysla|Olafsfjordhur|Rangarvallasysla|Reykjavik|Saudharkrokur|Seydhisfjordhur|Siglufjordhur|Skagafjardharsysla|Snaefellsnes-og Hnappadalssysla|Strandasysla|Sudhur-Mulasysla|Sudhur-Thingeyjarsysla|Vesttmannaeyjar|Vestur-Bardhastrandarsysla|Vestur-Hunavatnssysla|Vestur-Isafjardharsysla|Vestur-Skaftafellssysla',  
'IN'=> 'Andaman and Nicobar Islands|Andhra Pradesh|Arunachal Pradesh|Assam|Bihar|Chandigarh|Chhattisgarh|Dadra and Nagar Haveli|Daman and Diu|Delhi|Goa|Gujarat|Haryana|Himachal Pradesh|Jammu and Kashmir|Jharkhand|Karnataka|Kerala|Lakshadweep|Madhya Pradesh|Maharashtra|Manipur|Meghalaya|Mizoram|Nagaland|Orissa|Pondicherry|Punjab|Rajasthan|Sikkim|Tamil Nadu|Telangana State|Tripura|Uttar Pradesh|Uttaranchal|West Bengal',  
'ID'=> 'Aceh|Bali|Banten|Bengkulu|East Timor|Gorontalo|Irian Jaya|Jakarta Raya|Jambi|Jawa Barat|Jawa Tengah|Jawa Timur|Kalimantan Barat|Kalimantan Selatan|Kalimantan Tengah|Kalimantan Timur|Kepulauan Bangka Belitung|Lampung|Maluku|Maluku Utara|Nusa Tenggara Barat|Nusa Tenggara Timur|Riau|Sulawesi Selatan|Sulawesi Tengah|Sulawesi Tenggara|Sulawesi Utara|Sumatera Barat|Sumatera Selatan|Sumatera Utara|Yogyakarta',  

'IR'=> 'Ardabil|Azarbayjan-e Gharbi|Azarbayjan-e Sharqi|Bushehr|Chahar Mahall va Bakhtiari|Esfahan|Fars|Gilan|Golestan|Hamadan|Hormozgan|Ilam|Kerman|Kermanshah|Khorasan|Khuzestan|Kohgiluyeh va Buyer Ahmad|Kordestan|Lorestan|Markazi|Mazandaran|Qazvin|Qom|Semnan|Sistan va Baluchestan|Tehran|Yazd|Zanjan',  
'IQ'=> "Al Anbar|Al Basrah|Al Muthanna|Al Qadisiyah|An Najaf|Arbil|As Sulaymaniyah|At Ta'mim|Babil|Baghdad|Dahuk|Dhi Qar|Diyala|Karbala'|Maysan|Ninawa|Salah ad Din|Wasit",  
'IE'=> 'Co. Carlow|Co. Cavan|Co. Clare|Co. Cork|Co. Donegal|Co. Dublin|Co. Galway|Co. Kerry|Co. Kildare|Co. Kilkenny|Co. Laois|Co. Leitrim|Co. Limerick|Co. Longford|Co. Louth|Co. Mayo|Co. Meath|Co. Monaghan|Co. Offaly|Co. Roscommon|Co. Sligo|Co. Tipperary|Co. Waterford|Co. Westmeath|Co. Wexford|Co. Wicklow',  
'IM'=> 'Isle of Man', 
'IL'=> 'Central|Haifa|Jerusalem|Northern|Southern|Tel Aviv',  
'IT'=> "Agrigento|Alessandria|Ancona|Aosta|Ascoli Piceno|L'Aquila|Arezzo|Asti|Avellino|Bari|Bergamo|Biella|Belluno|Benevento|Bologna|Brindisi|Brescia|Barletta-Andria-Trani|Bolzano-Bozen|Cagliari|Campobasso|Caserta|Chieti|Carbonia-Inglesias|Caltanissetta|Cuneo|Como|Cremona|Cosenza|Catania|Catanzaro|Enna|Forl\xec-Cesena|Ferrara|Foggia|Firenze|Fermo|Frosinone|Genova|Gorizia|Grosseto|Imperia|Isernia|Crotone|Lecco|Lecce|Livorno|Lodi|Latina|Lucca|Monza e Brianza|Macerata|Messina|Milano|Mantova|Modena|Massa-Carrara|Matera|Napoli|Novara|Nuoro|Ogliastra|Oristano|Olbia-Tempio|Palermo|Piacenza|Padova|Pescara|Perugia|Pisa|Pordenone|Prato|Parma|Pistoia|Pesaro e Urbino|Pavia|Potenza|Ravenna|Reggio Calabria|Reggio Elilia|Ragusa|Rieti|Roma|Rimini|Rovigo|Salerno|Siena|Sondrio|La Spezia|Siracusa|Sassari|Savona|Taranto|Teramo|Trento|Torino|Trapani|Terni|Trieste|Treviso|Udine|Varese|Verbano-Cusio-Ossola|Vercelli|Venezia|Vicenza|Verona|Medio Campidano|Viterbo|Vibo Valentia",  
'JM'=> 'Clarendon|Hanover|Kingston|Manchester|Portland|Saint Andrew|Saint Ann|Saint Catherine|Saint Elizabeth|Saint James|Saint Mary|Saint Thomas|Trelawny|Westmoreland', 
'JP'=> 'Aichi|Akita|Aomori|Chiba|Ehime|Fukui|Fukuoka|Fukushima|Gifu|Gunma|Hiroshima|Hokkaido|Hyogo|Ibaragi|Ishikawa|Iwate|Kagawa|Kagoshima|Kanagawa|Kochi|Kumamoto|Kyoto|Mie|Miyagi|Miyazaki|Nagano|Nagasaki|Nara|Niigata|Oita|Okayama|Okinawa|Osaka|Saga|Saitama|Shiga|Shimane|Shizuoka|Tochigi|Tokushima|Tokyo|Tottori|Toyama|Wakayama|Yamagata|Yamaguchi|Yamanashi',  
'JE'=> 'Jersey', 
'JO'=> "'Amman|Ajlun|Al 'Aqabah|Al Balqa'|Al Karak|Al Mafraq|At Tafilah|Az Zarqa'|Irbid|Jarash|Ma'an|Madaba",  
'KZ'=> 'Almaty|Aqmola|Aqtobe|Astana|Atyrau|Batys Qazaqstan|Bayqongyr|Mangghystau|Ongtustik Qazaqstan|Pavlodar|Qaraghandy|Qostanay|Qyzylorda|Shyghys Qazaqstan|Soltustik Qazaqstan|Zhambyl', 
'KE'=> 'Central|Coast|Eastern|Nairobi Area|North Eastern|Nyanza|Rift Valley|Western',  
'KI'=> 'Abaiang|Abemama|Aranuka|Arorae|Banaba|Banaba|Beru|Butaritari|Central Gilberts|Gilbert Islands|Kanton|Kiritimati|Kuria|Line Islands|Line Islands|Maiana|Makin|Marakei|Nikunau|Nonouti|Northern Gilberts|Onotoa|Phoenix Islands|Southern Gilberts|Tabiteuea|Tabuaeran|Tamana|Tarawa|Tarawa|Teraina',  

 
 'KP'=> "Chagang-do [Chagang Province]|Hamgyong-bukto [North Hamgyong Province]|Hamgyong-namdo [South Hamgyong Province]|Hwanghae-bukto [North Hwanghae Province]|Hwanghae-namdo [South Hwanghae Province]|Kaesong-si [Kaesong City]|Kangwon-do [Kangwon Province]|Namp'o-si [Namp'o City]|P'yongan-bukto [North P'yongan Province]|P'yongan-namdo [South P'yongan Province]|P'yongyang-si [P'yongyang City]|Yanggang-do [Yanggang Province]",  
'KR'=> "Ch'ungch'ong-bukto|Ch'ungch'ong-namdo|Cheju-do|Cholla-bukto|Cholla-namdo|Inch'on-gwangyoksi|Kangwon-do|Kwangju-gwangyoksi|Kyonggi-do|Kyongsang-bukto|Kyongsang-namdo|Pusan-gwangyoksi|Soul-t'ukpyolsi|Taegu-gwangyoksi|Taejon-gwangyoksi|Ulsan-gwangyoksi",  
'KW'=> "Al 'Asimah|Al Ahmadi|Al Farwaniyah|Al Jahra'|Hawalli",  
'KG'=> 'Batken Oblasty|Bishkek Shaary|Chuy Oblasty [Bishkek]|Jalal-Abad Oblasty|Naryn Oblasty|Osh Oblasty|Talas Oblasty|Ysyk-Kol Oblasty [Karakol]',  
'LA'=> 'Attapu|Bokeo|Bolikhamxai|Champasak|Houaphan|Khammouan|Louangnamtha|Louangphabang|Oudomxai|Phongsali|Salavan|Savannakhet|Viangchan|Viangchan|Xaignabouli|Xaisomboun|Xekong|Xiangkhoang',  
 
'LV'=> 'Aizkraukles Rajons|Aluksnes Rajons|Balvu Rajons|Bauskas Rajons|Cesu Rajons|Daugavpils|Daugavpils Rajons|Dobeles Rajons|Gulbenes Rajons|Jekabpils Rajons|Jelgava|Jelgavas Rajons|Jurmala|Kraslavas Rajons|Kuldigas Rajons|Leipaja|Liepajas Rajons|Limbazu Rajons|Ludzas Rajons|Madonas Rajons|Ogres Rajons|Preilu Rajons|Rezekne|Rezeknes Rajons|Riga|Rigas Rajons|Saldus Rajons|Talsu Rajons|Tukuma Rajons|Valkas Rajons|Valmieras Rajons|Ventspils|Ventspils Rajons',  
'LB'=> 'Beyrouth|Ech Chimal|Ej Jnoub|El Bekaa|Jabal Loubnane',  
'LS'=> "Berea|Butha-Buthe|Leribe|Mafeteng|Maseru|Mohales Hoek|Mokhotlong|Qacha's Nek|Quthing|Thaba-Tseka", 
'LR'=> 'Bomi|Bong|Grand Bassa|Grand Cape Mount|Grand Gedeh|Grand Kru|Lofa|Margibi|Maryland|Montserrado|Nimba|River Cess|Sinoe', 
'LY' => "Ajdabiya|Al 'Aziziyah|Al Fatih|Al Jabal al Akhdar|Al Jufrah|Al Khums|Al Kufrah|An Nuqat al Khams|Ash Shati'|Awbari|Az Zawiyah|Banghazi|Darnah|Ghadamis|Gharyan|Misratah|Murzuq|Sabha|Sawfajjin|Surt|Tarabulus|Tarhunah|Tubruq|Yafran|Zlitan",  
'LI'=> 'Balzers|Eschen|Gamprin|Mauren|Planken|Ruggell|Schaan|Schellenberg|Triesen|Triesenberg|Vaduz',  
'LT'=> 'Akmenes Rajonas|Alytaus Rajonas|Alytus|Anyksciu Rajonas|Birstonas|Birzu Rajonas|Druskininkai|Ignalinos Rajonas|Jonavos Rajonas|Joniskio Rajonas|Jurbarko Rajonas|Kaisiadoriu Rajonas|Kaunas|Kauno Rajonas|Kedainiu Rajonas|Kelmes Rajonas|Klaipeda|Klaipedos Rajonas|Kretingos Rajonas|Kupiskio Rajonas|Lazdiju Rajonas|Marijampole|Marijampoles Rajonas|Mazeikiu Rajonas|Moletu Rajonas|Neringa Pakruojo Rajonas|Palanga|Panevezio Rajonas|Panevezys|Pasvalio Rajonas|Plunges Rajonas|Prienu Rajonas|Radviliskio Rajonas|Raseiniu Rajonas|Rokiskio Rajonas|Sakiu Rajonas|Salcininku Rajonas|Siauliai|Siauliu Rajonas|Silales Rajonas|Silutes Rajonas|Sirvintu Rajonas|Skuodo Rajonas|Svencioniu Rajonas|Taurages Rajonas|Telsiu Rajonas|Traku Rajonas|Ukmerges Rajonas|Utenos Rajonas|Varenos Rajonas|Vilkaviskio Rajonas|Vilniaus Rajonas|Vilnius|Zarasu Rajonas', 

'LU'=> 'Diekirch|Grevenmacher|Luxembourg', 
'MO'=> 'Macao', 
'MK'=> 'Aracinovo|Bac|Belcista|Berovo|Bistrica|Bitola|Blatec|Bogdanci|Bogomila|Bogovinje|Bosilovo|Brvenica|Cair [Skopje]|Capari|Caska|Cegrane|Centar [Skopje]|Centar Zupa|Cesinovo|Cucer-Sandevo|Debar|Delcevo|Delogozdi|Demir Hisar|Demir Kapija|Dobrusevo|Dolna Banjica|Dolneni|Dorce Petrov [Skopje]|Drugovo|Dzepciste|Gazi Baba [Skopje]|Gevgelija|Gostivar|Gradsko|Ilinden|Izvor|Jegunovce|Kamenjane|Karbinci|Karpos [Skopje]|Kavadarci|Kicevo|Kisela Voda [Skopje]|Klecevce|Kocani|Konce|Kondovo|Konopiste|Kosel|Kratovo|Kriva Palanka|Krivogastani|Krusevo|Kuklis|Kukurecani|Kumanovo|Labunista|Lipkovo|Lozovo|Lukovo|Makedonska Kamenica|Makedonski Brod|Mavrovi Anovi|Meseista|Miravci|Mogila|Murtino|Negotino|Negotino-Poloska|Novaci|Novo Selo|Oblesevo|Ohrid|Orasac|Orizari|Oslomej|Pehcevo|Petrovec|Plasnia|Podares|Prilep|Probistip|Radovis|Rankovce|Resen|Rosoman|Rostusa|Samokov|Saraj|Sipkovica|Sopiste|Sopotnika|Srbinovo|Star Dojran|Staravina|Staro Nagoricane|Stip|Struga|Strumica|Studenicani|Suto Orizari [Skopje]|Sveti Nikole|Tearce|Tetovo|Topolcani|Valandovo|Vasilevo|Veles|Velesta|Vevcani|Vinica|Vitoliste|Vranestica|Vrapciste|Vratnica|Vrutok|Zajas|Zelenikovo|Zileno|Zitose|Zletovo|Zrnovci', 
'MG'=> 'Antananarivo|Antsiranana|Fianarantsoa|Mahajanga|Toamasina|Toliara',  
'MW'=> 'Balaka|Blantyre|Chikwawa|Chiradzulu|Chitipa|Dedza|Dowa|Karonga|Kasungu|Likoma|Lilongwe|Machinga [Kasupe]|Mangochi|Mchinji|Mulanje|Mwanza|Mzimba|Nkhata Bay|Nkhotakota|Nsanje|Ntcheu|Ntchisi|Phalombe|Rumphi|Salima|Thyolo|Zomba', 
'MY'=> 'Johor|Kedah|Kelantan|Labuan|Melaka|Negeri Sembilan|Pahang|Perak|Perlis|Pulau Pinang|Sabah|Sarawak|Selangor|Terengganu|Wilayah Persekutuan',  
'MV'=> 'Alifu|Baa|Dhaalu|Faafu|Gaafu Alifu|Gaafu Dhaalu|Gnaviyani|Haa Alifu|Haa Dhaalu|Kaafu|Laamu|Lhaviyani|Maale|Meemu|Noonu|Raa|Seenu|Shaviyani|Thaa|Vaavu',  
'ML'=> 'Gao|Kayes|Kidal|Koulikoro|Mopti|Segou|Sikasso|Tombouctou',  
'MT'=> 'Valletta',  
'MH'=> 'Ailinginae|Ailinglaplap|Ailuk|Arno|Aur|Bikar|Bikini|Bokak|Ebon|Enewetak|Erikub|Jabat|Jaluit|Jemo|Kili|Kwajalein|Lae|Lib|Likiep|Majuro|Maloelap|Mejit|Mili|Namorik|Namu|Rongelap|Rongrik|Toke|Ujae|Ujelang|Utirik|Wotho|Wotje', 
'MQ'=> 'Martinique', 
'MR'=> 'Adrar|Assaba|Brakna|Dakhlet Nouadhibou|Gorgol|Guidimaka|Hodh Ech Chargui|Hodh El Gharbi|Inchiri|Nouakchott|Tagant|Tiris Zemmour|Trarza', 
'MU'=> 'Agalega Islands|Black River|Cargados Carajos Shoals|Flacq|Grand Port|Moka|Pamplemousses|Plaines Wilhems|Port Louis|Riviere du Rempart|Rodrigues|Savanne', 
'YT'=> 'Mayotte', 
'MX'=> 'Aguascalientes|Baja California|Baja California Sur|Campeche|Chiapas|Chihuahua|Coahuila de Zaragoza|Colima|Distrito Federal|Durango|Guanajuato|Guerrero|Hidalgo|Jalisco|Mexico|Michoacan de Ocampo|Morelos|Nayarit|Nuevo Leon|Oaxaca|Puebla|Queretaro de Arteaga|Quintana Roo|San Luis Potosi|Sinaloa|Sonora|Tabasco|Tamaulipas|Tlaxcala|Veracruz-Llave|Yucatan|Zacatecas',  
'FM' => 'Chuuk [Truk]|Kosrae|Pohnpei|Yap',  
'MD'=> 'Balti|Cahul|Chisinau|Chisinau|Dubasari|Edinet|Gagauzia|Lapusna|Orhei|Soroca|Tighina|Ungheni', 
'MC'=> 'Fontvieille|La Condamine|Monaco-Ville|Monte-Carlo', 
'MN'=> 'Arhangay|Bayan-Olgiy|Bayanhongor|Bulgan|Darhan|Dornod|Dornogovi|Dundgovi|Dzavhan|Erdenet|Govi-Altay|Hentiy|Hovd|Hovsgol|Omnogovi|Ovorhangay|Selenge|Suhbaatar|Tov|Ulaanbaatar|Uvs',  
'ME'=> 'Montenegro', 
'MS'=> "Saint Anthony|Saint Georges|Saint Peter's",  
'MA'=> 'Agadir|Al Hoceima|Azilal|Ben Slimane|Beni Mellal|Boulemane|Casablanca|Chaouen|El Jadida|El Kelaa des Srarhna|Er Rachidia|Essaouira|Fes|Figuig|Guelmim|Ifrane|Kenitra|Khemisset|Khenifra|Khouribga|Laayoune|Larache|Marrakech|Meknes|Nador|Ouarzazate|Oujda|Rabat-Sale|Safi|Settat|Sidi Kacem|Tan-Tan|Tanger|Taounate|Taroudannt|Tata|Taza|Tetouan|Tiznit', 
'MZ'=> 'Cabo Delgado|Gaza|Inhambane|Manica|Maputo|Nampula|Niassa|Sofala|Tete|Zambezia',  
'MM'=> 'Ayeyarwady|Bago|Chin State|Kachin State|Kayah State|Kayin State|Magway|Mandalay|Mon State|Rakhine State|Sagaing|Shan State|Tanintharyi|Yangon', 
'NA'=> 'Caprivi|Erongo|Hardap|Karas|Khomas|Kunene|Ohangwena|Okavango|Omaheke|Omusati|Oshana|Oshikoto|Otjozondjupa', 
'NR'=>  'Aiwo|Anabar|Anetan|Anibare|Baiti|Boe|Buada|Denigomodu|Ewa|Ijuw|Meneng|Nibok|Uaboe|Yaren', 
'NP'=> 'Bagmati|Bheri|Dhawalagiri|Gandaki|Janakpur|Karnali|Kosi|Lumbini|Mahakali|Mechi|Narayani|Rapti|Sagarmatha|Seti', 
'NL'=>  'Drenthe|Flevoland|Friesland|Gelderland|Groningen|Limburg|Noord-Brabant|Noord-Holland|Overijssel|Utrecht|Zeeland|Zuid-Holland', 
'NC'=> 'Iles Loyaute|Nord|Sud', 
 


'NZ'   => "Akaroa|Amuri|Ashburton|Bay of Islands|Bruce|Buller|Chatham Islands|Cheviot|Clifton|Clutha|Cook|Dannevirke|Egmont|Eketahuna|Ellesmere|Eltham|Eyre|Featherston|Franklin|Golden Bay|Great Barrier Island|Grey|Hauraki Plains|Hawera|Hawke's Bay|Heathcote|Hikurangi|Hobson|Hokianga|Horowhenua|Hurunui|Hutt|Inangahua|Inglewood|Kaikoura|Kairanga|Kiwitea|Lake|Mackenzie|Malvern|Manaia|Manawatu|Mangonui|Maniototo|Marlborough|Masterton|Matamata|Mount Herbert|Ohinemuri|Opotiki|Oroua|Otamatea|Otorohanga|Oxford|Pahiatua|Paparua|Patea|Piako|Pohangina|Raglan|Rangiora|Rangitikei|Rodney|Rotorua|Runanga|Saint Kilda|Silverpeaks|Southland|Stewart Island|Stratford|Strathallan|Taranaki|Taumarunui|Taupo|Tauranga|Thames-Coromandel|Tuapeka|Vincent|Waiapu|Waiheke|Waihemo|Waikato|Waikohu|Waimairi|Waimarino|Waimate|Waimate West|Waimea|Waipa|Waipawa|Waipukurau|Wairarapa South|Wairewa|Wairoa|Waitaki|Waitomo|Waitotara|Wallace|Wanganui|Waverley|Westland|Whakatane|Whangarei|Whangaroa|Woodville", 
'NI' => 'Atlantico Norte|Atlantico Sur|Boaco|Carazo|Chinandega|Chontales|Esteli|Granada|Jinotega|Leon|Madriz|Managua|Masaya|Matagalpa|Nueva Segovia|Rio San Juan|Rivas', 
'NE' => 'Agadez|Diffa|Dosso|Maradi|Niamey|Tahoua|Tillaberi|Zinder', 
'NG' => 'Abia|Abuja Federal Capital Territory|Adamawa|Akwa Ibom|Anambra|Bauchi|Bayelsa|Benue|Borno|Cross River|Delta|Ebonyi|Edo|Ekiti|Enugu|Gombe|Imo|Jigawa|Kaduna|Kano|Katsina|Kebbi|Kogi|Kwara|Lagos|Nassarawa|Niger|Ogun|Ondo|Osun|Oyo|Plateau|Rivers|Sokoto|Taraba|Yobe|Zamfara', 
'NU' =>  'Niue',  
'NF' => 'Norfolk Island',  
'MP' => 'Northern Islands|Rota|Saipan|Tinian',  
'NO' => 'Akershus|Aust-Agder|Buskerud|Finnmark|Hedmark|Hordaland|More og Romsdal|Nord-Trondelag|Nordland|Oppland|Oslo|Ostfold|Rogaland|Sogn og Fjordane|Sor-Trondelag|Telemark|Troms|Vest-Agder|Vestfold',  
'OM' => 'Ad Dakhiliyah|Al Batinah|Al Wusta|Ash Sharqiyah|Az Zahirah|Masqat|Musandam|Zufar',  
'PK' => 'Balochistan|Federally Administered Tribal Areas|Islamabad Capital Territory|North-West Frontier Province|Punjab|Sindh',  
'PW' => 'Aimeliik|Airai|Angaur|Hatobohei|Kayangel|Koror|Melekeok|Ngaraard|Ngarchelong|Ngardmau|Ngatpang|Ngchesar|Ngeremlengui|Ngiwal|Palau Island|Peleliu|Sonsoral|Tobi',  
'PS' => 'West Bank|Gaza Strip',  
'PA' => 'Bocas del Toro|Chiriqui|Cocle|Colon|Darien|Herrera|Los Santos|Panama|San Blas|Veraguas', 
'PG' => 'Bougainville|Central|Chimbu|East New Britain|East Sepik|Eastern Highlands|Enga|Gulf|Madang|Manus|Milne Bay|Morobe|National Capital|New Ireland|Northern|Sandaun|Southern Highlands|West New Britain|Western|Western Highlands',  
'PY' => 'Alto Paraguay|Alto Parana|Amambay|Asuncion [city]|Boqueron|Caaguazu|Caazapa|Canindeyu|Central|Concepcion|Cordillera|Guaira|Itapua|Misiones|Neembucu|Paraguari|Presidente Hayes|San Pedro',  
'PE' => 'Amazonas|Ancash|Apurimac|Arequipa|Ayacucho|Cajamarca|Callao|Cusco|Huancavelica|Huanuco|Ica|Junin|La Libertad|Lambayeque|Lima|Loreto|Madre de Dios|Moquegua|Pasco|Piura|Puno|San Martin|Tacna|Tumbes|Ucayali',  
'PH' => 'Abra|Agusan del Norte|Agusan del Sur|Aklan|Albay|Angeles|Antique|Aurora|Bacolod|Bago|Baguio|Bais|Basilan|Basilan City|Bataan|Batanes|Batangas|Batangas City|Benguet|Bohol|Bukidnon|Bulacan|Butuan|Cabanatuan|Cadiz|Cagayan|Cagayan de Oro|Calbayog|Caloocan|Camarines Norte|Camarines Sur|Camiguin|Canlaon|Capiz|Catanduanes|Cavite|Cavite City|Cebu|Cebu City|Cotabato|Dagupan|Danao|Dapitan|Davao City Davao|Davao del Sur|Davao Oriental|Dipolog|Dumaguete|Eastern Samar|General Santos|Gingoog|Ifugao|Iligan|Ilocos Norte|Ilocos Sur|Iloilo|Iloilo City|Iriga|Isabela|Kalinga-Apayao|La Carlota|La Union|Laguna|Lanao del Norte|Lanao del Sur|Laoag|Lapu-Lapu|Legaspi|Leyte|Lipa|Lucena|Maguindanao|Mandaue|Manila|Marawi|Marinduque|Masbate|Mindoro Occidental|Mindoro Oriental|Misamis Occidental|Misamis Oriental|Mountain|Naga|Negros Occidental|Negros Oriental|North Cotabato|Northern Samar|Nueva Ecija|Nueva Vizcaya|Olongapo|Ormoc|Oroquieta|Ozamis|Pagadian|Palawan|Palayan|Pampanga|Pangasinan|Pasay|Puerto Princesa|Quezon|Quezon City|Quirino|Rizal|Romblon|Roxas|Samar|San Carlos [in Negros Occidental]|San Carlos [in Pangasinan]|San Jose|San Pablo|Silay|Siquijor|Sorsogon|South Cotabato|Southern Leyte|Sultan Kudarat|Sulu|Surigao|Surigao del Norte|Surigao del Sur|Tacloban|Tagaytay|Tagbilaran|Tangub|Tarlac|Tawitawi|Toledo|Trece Martires|Zambales|Zamboanga|Zamboanga del Norte|Zamboanga del Sur',  
'PN' => 'Pitcarin Islands',  
'PL' => 'Dolnoslaskie|Kujawsko-Pomorskie|Lodzkie|Lubelskie|Lubuskie|Malopolskie|Mazowieckie|Opolskie|Podkarpackie|Podlaskie|Pomorskie|Slaskie|Swietokrzyskie|Warminsko-Mazurskie|Wielkopolskie|Zachodniopomorskie', 
'PT' => 'Acores [Azores]|Aveiro|Beja|Braga|Braganca|Castelo Branco|Coimbra|Evora|Faro|Guarda|Leiria|Lisboa|Madeira|Portalegre|Porto|Santarem|Setubal|Viana do Castelo|Vila Real|Viseu', 
'PR' => 'Adjuntas|Aguada|Aguadilla|Aguas Buenas|Aibonito|Anasco|Arecibo|Arroyo|Barceloneta|Barranquitas|Bayamon|Cabo Rojo|Caguas|Camuy|Canovanas|Carolina|Catano|Cayey|Ceiba|Ciales|Cidra|Coamo|Comerio|Corozal|Culebra|Dorado|Fajardo|Florida|Guanica|Guayama|Guayanilla|Guaynabo|Gurabo|Hatillo|Hormigueros|Humacao|Isabela|Jayuya|Juana Diaz|Juncos|Lajas|Lares|Las Marias|Las Piedras|Loiza|Luquillo|Manati|Maricao|Maunabo|Mayaguez|Moca|Morovis|Naguabo|Naranjito|Orocovis|Patillas|Penuelas|Ponce|Quebradillas|Rincon|Rio Grande|Sabana Grande|Salinas|San German|San Juan|San Lorenzo|San Sebastian|Santa Isabel|Toa Alta|Toa Baja|Trujillo Alto|Utuado|Vega Alta|Vega Baja|Vieques|Villalba|Yabucoa|Yauco', 
'QA' => 'Ad Dawhah|Al Ghuwayriyah|Al Jumayliyah|Al Khawr|Al Wakrah|Ar Rayyan|Jarayan al Batinah|Madinat ash Shamal|Umm Salal', 
'RE' => 'Reunion',  
'RO' => 'Alba|Arad|Arges|Bacau|Bihor|Bistrita-Nasaud|Botosani|Braila|Brasov|Bucuresti|Buzau|Calarasi|Caras-Severin|Cluj|Constanta|Covasna|Dimbovita|Dolj|Galati|Giurgiu|Gorj|Harghita|Hunedoara|Ialomita|Iasi|Maramures|Mehedinti|Mures|Neamt|Olt|Prahova|Salaj|Satu Mare|Sibiu|Suceava|Teleorman|Timis|Tulcea|Vaslui|Vilcea|Vrancea',  
'RU' => 'Moscow|Saint Petersburg|Novosibirsk|Yekaterinburg|Nizhny Novgorod|Samara|Kazan|Omsk|Chelyabinsk|Rostov-on-Don|Ufa|Volgograd|Perm|Krasnoyarsk|Voronezh|Saratov|Tolyatti|Krasnodar|Izhevsk|Yaroslavl',  
'RW' => 'Butare|Byumba|Cyangugu|Gikongoro|Gisenyi|Gitarama|Kibungo|Kibuye|Kigali Rurale|Kigali-ville|Ruhengeri|Umutara', 
'BL' => 'Saint Barthelemy',  
'SH' => 'Ascension|Saint Helena|Tristan da Cunha', 
'KN' => 'Christ Church Nichola Town|Saint Anne Sandy Point|Saint George Basseterre|Saint George Gingerland|Saint James Windward|Saint John Capisterre|Saint John Figtree|Saint Mary Cayon|Saint Paul Capisterre|Saint Paul Charlestown|Saint Peter Basseterre|Saint Thomas Lowland|Saint Thomas Middle Island|Trinity Palmetto Point',  
'LC' => 'Anse-la-Raye|Castries|Choiseul|Dauphin|Dennery|Gros Islet|Laborie|Micoud|Praslin|Soufriere|Vieux Fort', 
'MF' => 'Saint Martin [French part]', 
'PM' => 'Miquelon|Saint Pierre', 
'VC' => 'Charlotte|Grenadines|Saint Andrew|Saint David|Saint George|Saint Patrick',
'WS' => "A'ana|Aiga-i-le-Tai|Atua|Fa'asaleleaga|Gaga'emauga|Gagaifomauga|Palauli|Satupa'itea|Tuamasaga|Va'a-o-Fonoti|Vaisigano",  
'SM' => 'Acquaviva|Borgo Maggiore|Chiesanuova|Domagnano|Faetano|Fiorentino|Monte Giardino|San Marino|Serravalle', 
'ST' => 'Principe|Sao Tome',  
'SA' => "'Asir|Al Bahah|Al Hudud ash Shamaliyah|Al Jawf|Al Madinah|Al Qasim|Ar Riyad|Ash Sharqiyah [Eastern Province]|Ha'il|Jizan|Makkah|Najran|Tabuk",  
'SN' => 'Dakar|Diourbel|Fatick|Kaolack|Kolda|Louga|Saint-Louis|Tambacounda|Thies|Ziguinchor',  
'RS' => 'Serbia', 
'SC' => "Anse aux Pins|Anse Boileau|Anse Etoile|Anse Louis|Anse Royale|Baie Lazare|Baie Sainte Anne|Beau Vallon|Bel Air|Bel Ombre|Cascade|Glacis|Grand' Anse [on Mahe]|Grand' Anse [on Praslin]|La Digue|La Riviere Anglaise|Mont Buxton|Mont Fleuri|Plaisance|Pointe La Rue|Port Glaud|Saint Louis|Takamaka",  
'SL' => 'Eastern|Northern|Southern|Western',  
'SG' => 'Singapore',  
'SX' => 'Sint Maarten [Dutch part]',  
'SK' => 'Banskobystricky|Bratislavsky|Kosicky|Nitriansky|Presovsky|Trenciansky|Trnavsky|Zilinsky',  
'SI' => 'Ajdovscina|Beltinci|Bled|Bohinj|Borovnica|Bovec|Brda|Brezice|Brezovica|Cankova-Tisina|Celje|Cerklje na Gorenjskem|Cerknica|Cerkno|Crensovci|Crna na Koroskem|Crnomelj|Destrnik-Trnovska Vas|Divaca|Dobrepolje|Dobrova-Horjul-Polhov Gradec|Dol pri Ljubljani|Domzale|Dornava|Dravograd|Duplek|Gorenja Vas-Poljane|Gorisnica|Gornja Radgona|Gornji Grad|Gornji Petrovci|Grosuplje|Hodos Salovci|Hrastnik|Hrpelje-Kozina|Idrija|Ig|Ilirska Bistrica|Ivancna Gorica|Izola|Jesenice|Jursinci|Kamnik|Kanal|Kidricevo|Kobarid|Kobilje|Kocevje|Komen|Koper|Kozje|Kranj|Kranjska Gora|Krsko|Kungota|Kuzma|Lasko|Lenart|Lendava|Litija|Ljubljana|Ljubno|Ljutomer|Logatec|Loska Dolina|Loski Potok|Luce|Lukovica|Majsperk|Maribor|Medvode|Menges|Metlika|Mezica|Miren-Kostanjevica|Mislinja|Moravce|Moravske Toplice|Mozirje|Murska Sobota|Muta|Naklo|Nazarje|Nova Gorica|Novo Mesto|Odranci|Ormoz|Osilnica|Pesnica|Piran|Pivka|Podcetrtek|Podvelka-Ribnica|Postojna|Preddvor|Ptuj|Puconci|Race-Fram|Radece|Radenci|Radlje ob Dravi|Radovljica|Ravne-Prevalje|Ribnica|Rogasevci|Rogaska Slatina|Rogatec|Ruse|Semic|Sencur|Sentilj|Sentjernej|Sentjur pri Celju|Sevnica|Sezana|Skocjan|Skofja Loka|Skofljica|Slovenj Gradec|Slovenska Bistrica|Slovenske Konjice|Smarje pri Jelsah|Smartno ob Paki|Sostanj|Starse|Store|Sveti Jurij|Tolmin|Trbovlje|Trebnje|Trzic|Turnisce|Velenje|Velike Lasce|Videm|Vipava|Vitanje|Vodice|Vojnik|Vrhnika|Vuzenica|Zagorje ob Savi|Zalec|Zavrc|Zelezniki|Ziri|Zrece',  
'SB' => 'Bellona|Central|Choiseul [Lauru]|Guadalcanal|Honiara|Isabel|Makira|Malaita|Rennell|Temotu|Western',  
'SO' => 'Awdal|Bakool|Banaadir|Bari|Bay|Galguduud|Gedo|Hiiraan|Jubbada Dhexe|Jubbada Hoose|Mudug|Nugaal|Sanaag|Shabeellaha Dhexe|Shabeellaha Hoose|Sool|Togdheer|Woqooyi Galbeed',  
'ZA' => 'Eastern Cape|Free State|Gauteng|KwaZulu-Natal|Limpopo|Mpumalanga|North West|Northern Cape|Western Cape',  
'GS' => 'Bird Island|Bristol Island|Clerke Rocks|Montagu Island|Saunders Island|South Georgia|Southern Thule|Traversay Islands',  
'SS' => 'South Sudan',  
'ES' => 'Albacete|Alicante|Almer\xeda|Asturias|Badajoz|Balearic Islands|Barcelona|Biscay|Burgos|Cantabria|Castell\xf3n|Ciudad Real|Cuenca|C\xe1ceres|C\xe1diz|C\xf3rdoba|Gerona|Granada|Guadalajara|Guip\xfazcoa|Huelva|Huesca|Ja\xe9n|La Coru\xf1a|La Rioja|Las Palmas|Le\xf3n|Lugo|L\xe9rida|Madrid|Murcia|M\xe1laga|Navarre|Orense|Palencia|Pontevedra|Salamanca|Santa Cruz|Segovia|Sevilla|Soria|Tarragona|Teruel|Toledo|Valencia|Valladolid|Zamora|Zaragoza|\xc1lava|\xc1vila',  
'LK' => 'Central|Eastern|North Central|North Eastern|North Western|Northern|Sabaragamuwa|Southern|Uva|Western',  
'SD' => "A'ali an Nil|Al Bahr al Ahmar|Al Buhayrat|Al Jazirah|Al Khartum|Al Qadarif|Al Wahdah|An Nil al Abyad|An Nil al Azraq|Ash Shamaliyah|Bahr al Jabal|Gharb al Istiwa'iyah|Gharb Bahr al Ghazal|Gharb Darfur|Gharb Kurdufan|Janub Darfur|Janub Kurdufan|Junqali|Kassala|Nahr an Nil|Shamal Bahr al Ghazal|Shamal Darfur|Shamal Kurdufan|Sharq al Istiwa'iyah|Sinnar|Warab",  
'SR' => 'Brokopondo|Commewijne|Coronie|Marowijne|Nickerie|Para|Paramaribo|Saramacca|Sipaliwini|Wanica', 
'SJ' => 'Barentsoya|Bjornoya|Edgeoya|Hopen|Kvitoya|Nordaustandet|Prins Karls Forland|Spitsbergen',  
'SZ' => 'Hhohho|Lubombo|Manzini|Shiselweni',  
'SE' => 'Blekinge|Dalarnas|Gavleborgs|Gotlands|Hallands|Jamtlands|Jonkopings|Kalmar|Kronobergs|Norrbottens|Orebro|Ostergotlands|Skane|Sodermanlands|Stockholms|Uppsala|Varmlands|Vasterbottens|Vasternorrlands|Vastmanlands|Vastra Gotalands', 
'CH' => 'Aargau|Ausser-Rhoden|Basel-Landschaft|Basel-Stadt|Bern|Fribourg|Geneve|Glarus|Graubunden|Inner-Rhoden|Jura|Luzern|Neuchatel|Nidwalden|Obwalden|Sankt Gallen|Schaffhausen|Schwyz|Solothurn|Thurgau|Ticino|Uri|Valais|Vaud|Zug|Zurich',  
'SY' => "Al Hasakah|Al Ladhiqiyah|Al Qunaytirah|Ar Raqqah|As Suwayda'|Dar'a|Dayr az Zawr|Dimashq|Halab|Hamah|Hims|Idlib|Rif Dimashq|Tartus",  
'TW' => "Chang-hua|Chi-lung|Chia-i|Chia-i|Chung-hsing-hsin-ts'un|Hsin-chu|Hsin-chu|Hua-lien|I-lan|Kao-hsiung|Kao-hsiung|Miao-li|Nan-t'ou|P'eng-hu|P'ing-tung|T'ai-chung|T'ai-chung|T'ai-nan|T'ai-nan|T'ai-pei|T'ai-pei|T'ai-tung|T'ao-yuan|Yun-lin", 
'TJ' => 'Viloyati Khatlon|Viloyati Leninobod|Viloyati Mukhtori Kuhistoni Badakhshon',  
'TZ' => 'Arusha|Dar es Salaam|Dodoma|Iringa|Kagera|Kigoma|Kilimanjaro|Lindi|Mara|Mbeya|Morogoro|Mtwara|Mwanza|Pemba North|Pemba South|Pwani|Rukwa|Ruvuma|Shinyanga|Singida|Tabora|Tanga|Zanzibar Central/South|Zanzibar North|Zanzibar Urban/West', 
'TH' => 'Amnat Charoen|Ang Thong|Buriram|Chachoengsao|Chai Nat|Chaiyaphum|Chanthaburi|Chiang Mai|Chiang Rai|Chon Buri|Chumphon|Kalasin|Kamphaeng Phet|Kanchanaburi|Khon Kaen|Krabi|Krung Thep Mahanakhon [Bangkok]|Lampang|Lamphun|Loei|Lop Buri|Mae Hong Son|Maha Sarakham|Mukdahan|Nakhon Nayok|Nakhon Pathom|Nakhon Phanom|Nakhon Ratchasima|Nakhon Sawan|Nakhon Si Thammarat|Nan|Narathiwat|Nong Bua Lamphu|Nong Khai|Nonthaburi|Pathum Thani|Pattani|Phangnga|Phatthalung|Phayao|Phetchabun|Phetchaburi|Phichit|Phitsanulok|Phra Nakhon Si Ayutthaya|Phrae|Phuket|Prachin Buri|Prachuap Khiri Khan|Ranong|Ratchaburi|Rayong|Roi Et|Sa Kaeo|Sakon Nakhon|Samut Prakan|Samut Sakhon|Samut Songkhram|Sara Buri|Satun|Sing Buri|Sisaket|Songkhla|Sukhothai|Suphan Buri|Surat Thani|Surin|Tak|Trang|Trat|Ubon Ratchathani|Udon Thani|Uthai Thani|Uttaradit|Yala|Yasothon',  
'Timor-Leste', 
'TG' => 'De La Kara|Des Plateaux|Des Savanes|Du Centre|Maritime', 
'TK' => 'Atafu|Fakaofo|Nukunonu',  
'TO' => "Ha'apai|Tongatapu|Vava'u", 
'TT' =>  'Arima|Caroni|Mayaro|Nariva|Port-of-Spain|Saint Andrew|Saint David|Saint George|Saint Patrick|San Fernando|Victoria|Tobago', 
'TN' => 'Ariana|Beja|Ben Arous|Bizerte|El Kef|Gabes|Gafsa|Jendouba|Kairouan|Kasserine|Kebili|Mahdia|Medenine|Monastir|Nabeul|Sfax|Sidi Bou Zid|Siliana|Sousse|Tataouine|Tozeur|Tunis|Zaghouan',  
 'TR' => 'Adana|Adiyaman|Afyon|Agri|Aksaray|Amasya|Ankara|Antalya|Ardahan|Artvin|Aydin|Balikesir|Bartin|Batman|Bayburt|Bilecik|Bingol|Bitlis|Bolu|Burdur|Bursa|Canakkale|Cankiri|Corum|Denizli|Diyarbakir|Duzce|Edirne|Elazig|Erzincan|Erzurum|Eskisehir|Gaziantep|Giresun|Gumushane|Hakkari|Hatay|Icel|Igdir|Isparta|Istanbul|Izmir|Kahramanmaras|Karabuk|Karaman|Kars|Kastamonu|Kayseri|Kilis|Kirikkale|Kirklareli|Kirsehir|Kocaeli|Konya|Kutahya|Malatya|Manisa|Mardin|Mugla|Mus|Nevsehir|Nigde|Ordu|Osmaniye|Rize|Sakarya|Samsun|Sanliurfa|Siirt|Sinop|Sirnak|Sivas|Tekirdag|Tokat|Trabzon|Tunceli|Usak|Van|Yalova|Yozgat|Zonguldak',  
'TM' => 'Ahal Welayaty|Balkan Welayaty|Dashhowuz Welayaty|Lebap Welayaty|Mary Welayaty',  
'TC' => 'Turks and Caicos Islands',  
'TV' => 'Tuvalu',  
'UG' => 'Adjumani|Apac|Arua|Bugiri|Bundibugyo|Bushenyi|Busia|Gulu|Hoima|Iganga|Jinja|Kabale|Kabarole|Kalangala|Kampala|Kamuli|Kapchorwa|Kasese|Katakwi|Kibale|Kiboga|Kisoro|Kitgum|Kotido|Kumi|Lira|Luwero|Masaka|Masindi|Mbale|Mbarara|Moroto|Moyo|Mpigi|Mubende|Mukono|Nakasongola|Nebbi|Ntungamo|Pallisa|Rakai|Rukungiri|Sembabule|Soroti|Tororo',  
'UA' => "Avtonomna Respublika Krym [Simferopol']|Cherkas'ka [Cherkasy]|Chernihivs'ka [Chernihiv]|Chernivets'ka [Chernivtsi]|Dnipropetrovs'ka [Dnipropetrovs'k]|Donets'ka [Donets'k]|Ivano-Frankivs'ka [Ivano-Frankivs'k]|Kharkivs'ka [Kharkiv]|Khersons'ka [Kherson]|Khmel'nyts'ka [Khmel'nyts'kyy]|Kirovohrads'ka [Kirovohrad]|Kyyiv|Kyyivs'ka [Kiev]|L'vivs'ka [L'viv]|Luhans'ka [Luhans'k]|Mykolayivs'ka [Mykolayiv]|Odes'ka [Odesa]|Poltavs'ka [Poltava]|Rivnens'ka [Rivne]|Sevastopol'|Sums'ka [Sumy]|Ternopil's'ka [Ternopil']|Vinnyts'ka [Vinnytsya]|Volyns'ka [Luts'k]|Zakarpats'ka [Uzhhorod]|Zaporiz'ka [Zaporizhzhya]|Zhytomyrs'ka [Zhytomyr]",  
'AE' => "'Ajman|Abu Zaby [Abu Dhabi]|Al Fujayrah|Ash Shariqah [Sharjah]|Dubayy [Dubai]|Ra's al Khaymah|Umm al Qaywayn",  

//'GB' => 'England|Northern Ireland|Scotland|Wales',
'GB' => 'Aberdeenshire|Alderney|Angus|Antrim|Argyll|Armagh|Avon|Ayrshire|Banffshire|Bedfordshire|Berkshire|Berwickshire|Blaenau Gwent|Borders|Bridgend|Buckinghamshire|Bute|Caerphilly|Caithness|Cambridgeshire|Cardiff|Carmarthenshire|Central|Ceredigion|Cheshire|Clackmannanshire|Cleveland|Clwyd|Co. Antrim|Co. Armagh|Co. Derry|Co. Down|Co. Fermanagh|Co. Tyrone|Conwy|Cornwall|Cumberland|Cumbria|Denbighshire|Derbyshire|Derry|Devon|Dorset|Down|Dumfries & Galloway|Dumfriesshire|Dunbartonshire|Durham|Dyfed|East Lothian|East Sussex|Essex|Fermanagh|Fife|Flintshire|Gloucestershire|Grampian|Greater London|Greater Manchester|Guernsey|Gwent|Gwynedd|Hampshire|Hereford & Worcester|Herefordshire|Hertfordshire|Highland|Humberside|Huntingdonshire|Inverness|Isle Of Man|Isle of Anglesey|Isle of Wight|Jersey|Kent|Kincardineshire|Kinross-shire|Kirkcudbrightshire|Lanarkshire|Lancashire|Leicestershire|Lincolnshire|Lothian|Merseyside|Merthyr Tydfil|Mid Glamorgan|Middlesex|Midlothian|Monmouthshire|Moray|Nairnshire|Neath Port Talbot|Newport|Norfolk|North Yorkshire|Northamptonshire|Northumberland|Nottinghamshire|Orkney|Oxfordshire|Peebleshire|Pembrokeshire|Perthshire|Powys|Renfrewshire|Rhondda Cynon Taff|Ross & Cromarty|Roxburghshire|Rutland|Scotland|Selkirkshire|Shetland|Shropshire|Somerset|South Glamorgan|South Yorkshire|Staffordshire|Stirlingshire|Strathclyde|Suffolk|Surrey|Sussex|Sutherland|Swansea|Tayside|Torfaen|Tyne & Wear|Tyne and Wear|Tyrone|Vale of Glamorgan|Wales|Warwickshire|West Glamorgan|West Lothian|West Midlands|West Riding|West Sussex|West Yorkshire|Western Isles|Westmoorland|Westmorland|Wigtownshire|Wiltshire|Worcestershire|Wrexham|Yorkshire',
  
'US' => 'Alaska|Alabama|Arkansas|Arizona|California|Colorado|Connecticut|Washington, D.C.|Delaware|Federated States of Micronesia|Florida|Guam|Georgia|Hawaii|Iowa|Idaho|Illinois|Indiana|Kansas|Kentucky|Louisiana|Marshall Islands|Massachusetts|Maryland|Maine|Michigan|Minnesota|Missouri|Mississippi|Montana|North Carolina|Northern Mariana Islands|North Dakota|Nebraska|New Hampshire|New Jersey|New Mexico|Nevada|New York|Ohio|Oklahoma|Oregon|Pennsylvania|Palau|Puerto Rico|Rhode Island|South Carolina|Samoa|South Dakota|Tennessee|Texas|Utah|Virginia|Virgin Islands|Vermont|Washington|Wisconsin|West Virginia|Wyoming', 
'UM' => '', 
'UY' => 'Artigas|Canelones|Cerro Largo|Colonia|Durazno|Flores|Florida|Lavalleja|Maldonado|Montevideo|Paysandu|Rio Negro|Rivera|Rocha|Salto|San Jose|Soriano|Tacuarembo|Treinta y Tres', 
'UZ' => 'Andijon Wiloyati|Bukhoro Wiloyati|Farghona Wiloyati|Jizzakh Wiloyati|Khorazm Wiloyati [Urganch]|Namangan Wiloyati|Nawoiy Wiloyati|Qashqadaryo Wiloyati [Qarshi]|Qoraqalpoghiston [Nukus]|Samarqand Wiloyati|Sirdaryo Wiloyati [Guliston]|Surkhondaryo Wiloyati [Termiz]|Toshkent Shahri|Toshkent Wiloyati', 
'VU' => 'Malampa|Penama|Sanma|Shefa|Tafea|Torba',  
'VE' => 'Amazonas|Anzoategui|Apure|Aragua|Barinas|Bolivar|Carabobo|Cojedes|Delta Amacuro|Dependencias Federales|Distrito Federal|Falcon|Guarico|Lara|Merida|Miranda|Monagas|Nueva Esparta|Portuguesa|Sucre|Tachira|Trujillo|Vargas|Yaracuy|Zulia',  
'VN' => 'An Giang|Ba Ria-Vung Tau|Bac Giang|Bac Kan|Bac Lieu|Bac Ninh|Ben Tre|Binh Dinh|Binh Duong|Binh Phuoc|Binh Thuan|Ca Mau|Can Tho|Cao Bang|Da Nang|Dac Lak|Dong Nai|Dong Thap|Gia Lai|Ha Giang|Ha Nam|Ha Noi|Ha Tay|Ha Tinh|Hai Duong|Hai Phong|Ho Chi Minh|Hoa Binh|Hung Yen|Khanh Hoa|Kien Giang|Kon Tum|Lai Chau|Lam Dong|Lang Son|Lao Cai|Long An|Nam Dinh|Nghe An|Ninh Binh|Ninh Thuan|Phu Tho|Phu Yen|Quang Binh|Quang Nam|Quang Ngai|Quang Ninh|Quang Tri|Soc Trang|Son La|Tay Ninh|Thai Binh|Thai Nguyen|Thanh Hoa|Thua Thien-Hue|Tien Giang|Tra Vinh|Tuyen Quang|Vinh Long|Vinh Phuc|Yen Bai',  
'VG' => 'Anegada|Jost Van Dyke|Tortola|Virgin Gorda',  
'VI' => 'Saint Croix|Saint John|Saint Thomas', 
'WF' => 'Alo|Sigave|Wallis',  
'EH' => 'Western Sahara', 
'YE' => "'Adan|'Ataq|Abyan|Al Bayda'|Al Hudaydah|Al Jawf|Al Mahrah|Al Mahwit|Dhamar|Hadhramawt|Hajjah|Ibb|Lahij|Ma'rib|Sa'dah|San'a'|Ta'izz",  
'ZM' => 'Central|Copperbelt|Eastern|Luapula|Lusaka|North-Western|Northern|Southern|Western',  
'ZW' => 'Bulawayo|Harare|ManicalandMashonaland Central|Mashonaland East|Mashonaland West|Masvingo|Matabeleland North|Matabeleland South|Midlands',  
 
 
 );
 

 
class Core_Advanced_Search {

    private static $_instance;
 
    function __construct() {
 
        add_action( 'wp_ajax_asw_save_options', array($this, 'save_options') );
		if ( isset( $_GET['advanced_search'] ) ) {
        add_filter( 'pre_get_posts', array($this, 'pre_get_posts') );
 		}
    }

    public static function instance() {
        if ( !self::$_instance ) {
            self::$_instance = new Core_Advanced_Search();
        }

        return self::$_instance;
    }

    /**
     * Filter the query for search
     *
     * @global object $wpdb
     * @param object $query
     * @return object
     */
    function pre_get_posts( $query ) {
        global $wpdb;

        if ( $query->is_main_query() ) {
            if ( isset( $_GET['advanced_search'] ) ) {
                $query->is_search = true;
            }

            if ( $query->is_search ) {

                $GLOBALS['taxonomies'] = array();
                $GLOBALS['custom'] = array();

                //$fields = get_site_transient( 'asw_fields' );

                //if ( false == $fields ) {
                    $fields = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."core_search" );
                 //   set_site_transient( 'asw_fields', $fields, 60 * 60 );
                //}
				 
                if ( $fields ) {
				
				// PREPARE GET DATA
				$GET_VALUES_ARRAY = array();
				foreach($_GET as $key=>$val){
					$new_key = explode("--",$key);
					 
					// CHECK IF IT EXISTS, IF SO ADD 1
					if (array_key_exists($new_key[0], $GET_VALUES_ARRAY)) {
						$GET_VALUES_ARRAY[$new_key[0]."-1"] = $val; 
					}else{
						$GET_VALUES_ARRAY[$new_key[0]] = $val; 
					} 
				}
				 
				  
                    foreach ($fields as $field) {
					
						// BUILD SEARCH FOR KEY
						$SearchKey = $field->key; 
						 
                        switch ($field->type) {
                            case 'taxonomy':
							
										
								// ADD-ON FOR CUSTOM CHECKBOXES 
								if(isset($_GET['ct'.$field->id]) && is_array($_GET['ct'.$field->id]) ){
									 
									$GLOBALS['taxonomies'][] = array(
											'taxonomy' => $field->key,											 
											'terms' => $_GET['ct'.$field->id],
											'operator' => 'IN'											 
									);							 			
								}

                                if ( $field->key == 'category' ) {
								 
                                    if ( isset( $GET_VALUES_ARRAY[$SearchKey] ) && $GET_VALUES_ARRAY[$SearchKey] != 0 ) {
                                        $GLOBALS['taxonomies'][] = array(
                                            'taxonomy' => 'category',
                                            'field' => 'term_id',
                                            'terms' => $GET_VALUES_ARRAY[$SearchKey],
                                            'operator' => $field->compare
                                        );
                                        continue;
                                    }
                                }
 								
								
								
								// CHECK IF ITS AN ARRAY
								if(isset($_GET['tx_' . $SearchKey]) && is_array($_GET['tx_' . $SearchKey])){
								
								foreach($_GET['tx_' . $SearchKey] as $taxMyBigJuicy){
								
									if ( $taxMyBigJuicy != '0' && $taxMyBigJuicy !="" ) {
										$GLOBALS['taxonomies'][] = array(
											'taxonomy' => $SearchKey,
											'field' => 'slug',
											'terms' => $taxMyBigJuicy,
											'operator' => $field->compare
										);
									}// end if
								} // end foreach
								
								
								}else{								
								
									if ( isset( $_GET['tx_' . $SearchKey] ) && $_GET['tx_' . $SearchKey] != '0' ) {
										$GLOBALS['taxonomies'][] = array(
											'taxonomy' => $SearchKey,
											'field' => 'slug',
											'terms' => $_GET['tx_' . $SearchKey],
											'operator' => $field->compare
										);
									}
								
								}
								
                                break;

                            case 'custom':
							
                                $key = ($field->alias != '') ? $field->alias : $SearchKey;							 	

                                if ( isset( $GET_VALUES_ARRAY[$SearchKey] ) && !empty( $GET_VALUES_ARRAY[$SearchKey] ) ) {
								 	
									
									if($SearchKey == "wlt_tags"){
									
										$GLOBALS['taxonomies'][] = array(
											'taxonomy' => 'post_tag',
											'field' => 'slug',
											'terms' => array($GET_VALUES_ARRAY[$SearchKey]),																													 
										);
										 
									
									}elseif($SearchKey == "author"){
										$GLOBALS['post_author'] = $GET_VALUES_ARRAY[$SearchKey];									 
									}elseif($field->field_type == "multi-select"){
										if(is_array($GET_VALUES_ARRAY[$SearchKey]) && !empty($GET_VALUES_ARRAY[$SearchKey]) ){
											$GLOBALS['custom_or'] = array( 'relation' => 'OR' ); 
											foreach($GET_VALUES_ARRAY[$SearchKey] as $value){
											 			
												array_push($GLOBALS['custom_or'], array( 
													'key' => $SearchKey,
													'value' => $value,
													'type' => $field->operator,
													'compare' => "LIKE"
												) ) ;
												$i++;										
											}	 								 
											 
											 //DIE(PRINT_R($GLOBALS['custom_or']));
										}// end if
									
									}else{
                                    $GLOBALS['custom'][] = array(
                                        'key' => str_replace("map-state1","map-state",str_replace("map-city1","map-city",str_replace("map-country1","map-country",$SearchKey))),
                                        'value' => $GET_VALUES_ARRAY[$SearchKey],
                                        'type' => $field->operator,
                                        'compare' => $field->compare
                                    ); 
									}
                                }
                                break;

                            default:
                                break;
                        }
						
						// ADD-ON FOR RATING SEARCH
						if(isset($_GET['rate']) && is_array($_GET['rate'])  ){
						
						if(defined('WLT_MICROJOB')){
				 
								
								$GLOBALS['orderby'] = "meta_value_num";
							$GLOBALS['custom'][] = array(
                                        'key' => "rating_total",
                                        'value' => $_GET['rate'],
                                        'compare' => 'IN',
                            );	
						
						}else{
						$GLOBALS['orderby'] = "meta_value_num";
							$GLOBALS['custom'][] = array(
                                        'key' => "starrating",
                                        'value' => $_GET['rate'],
                                        'compare' => 'IN',
                            );	
						}
						  					
						} 
					 
						
						// UNSET KEY SO WE DONT FIND IT AGAIN
						if($SearchKey != ""){
						unset($GET_VALUES_ARRAY[$SearchKey]); 						
							// NOW CHECK IF THIS KEY HAS A SECOND AND MAKE IT THE FIRST
							if(isset($GET_VALUES_ARRAY[$SearchKey."-1"])){
								$this_key_val = $GET_VALUES_ARRAY[$SearchKey."-1"];
								unset($GET_VALUES_ARRAY[$SearchKey."-1"]);
								$GET_VALUES_ARRAY[$SearchKey] = $this_key_val;
							}						
						}
                    }

     
                    //die(print_r($query));
                }
            }
        }
    }
 
    function print_r( $param ) {
        echo '<pre>';
        print_r( $param );
        echo '</pre>';
    }
 
    /**
     * Handles the plugin admin page
     *
     * @global object $wpdb
     */
    function plugin_page() {
	
        global $wpdb, $CORE, $CORE_ADMIN;
		
		$core_admin_values = get_option("core_admin_values");

        $fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}core_search ORDER BY `order` ASC" );
        ?>
        <input type="hidden" name="searchform" value="1" />
    <div class="row-fluid">

    <div class="box gradient span8">
    <div class="title">
            <div class="row-fluid">
          
          
<div class="btn-group pull-right" style="margin-top: 5px;    margin-right: 15px;">
  <a class="btn dropdown-toggle btn-success" data-toggle="dropdown" href="#">
   Add New Field
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu asw-elements">
      <li style="margin:0px;"><a href="#" onclick="window.scrollTo(0,document.body.scrollHeight);" id="asw-search-add-btn">Search Field</a></li>
      <li style="margin:0px;"><a href="#" onclick="window.scrollTo(0,document.body.scrollHeight);" id="asw-custom-add-btn">Custom Field</a></li>
      <li style="margin:0px;"><a href="#" onclick="window.scrollTo(0,document.body.scrollHeight);" id="asw-tax-add-btn">Taxonomy Field</a></li>        
      <li style="margin:0px;"><a href="#" onclick="window.scrollTo(0,document.body.scrollHeight);" id="asw-head-add-btn">Heading Separator</a></li> 
  </ul>
</div>
          
          
          
            
            <h3><i class="gicon-search"></i>Advanced Search Fields</h3></div>
    </div>
    <div class="content">
    
     <div id="asw-ajax-response"></div>
	
    	<ul class="asw-form-elements">
                            <?php
                            if ( $fields ) {
                                echo $this->build_builder_form( $fields );
                            } else {
                                $this->search_field();
                            }
                            ?>
         </ul>
        <?php //submit_button(); ?>
            <?php do_action('hook_admin_1_tab4_left'); ?>            
    
    </div> 
 
    
    </div>            
	 

    <div class="span4">
    
      <a data-toggle="modal" href="#VideoModelBox" class="btn btn-warning youtube" onclick="PlayPPTVideo('oh1UP9fpYDw','videoboxplayer','479','350');" style="width:100%; margin-bottom:10px; ">Watch Video Tutorial</a>
 
    
    
     <div class="box gradient">
     <div class="title"><div class="row-fluid"><h3><i class="gicon-retweet"></i> Search Data</h3></div></div>
     <div class="content">
     
    
     <p>Select the content you wish to include in search results.</p>
 
     
     <div class="checkbox"> <input name="admin_values[dstypes][]" type="checkbox" value="<?php echo THEME_TAXONOMY; ?>_type" checked="checked" /> Listings (on by default) </div>
     <div class="checkbox"> <input name="admin_values[dstypes][]" type="checkbox" value="page" <?php if(isset($core_admin_values['dstypes']) && is_array($core_admin_values['dstypes']) && in_array("page",$core_admin_values['dstypes'])){ echo "checked=checked"; } ?> /> Pages </div>
     <div class="checkbox"> <input name="admin_values[dstypes][]" type="checkbox" value="post" <?php if(isset($core_admin_values['dstypes']) && is_array($core_admin_values['dstypes']) && in_array("post",$core_admin_values['dstypes'])){ echo "checked=checked"; } ?> /> Blog Posts </div>
     
     
     
     
  
    
    
     </div></div> 
       
    
   </div>
             
  </div><!-- end fluid -->

    <div class="clear"></div>
	<script type="text/html" id="asw-search-template">
    <?php $this->search_field(); ?>
    </script>
            
            <script type="text/html" id="asw-custom-template">
        <?php $this->custom_field(); ?>
            </script>

            <script type="text/html" id="asw-tax-template">
        <?php $this->taxonomy_field(); ?>
            </script>
            
            
            <script type="text/html" id="asw-head-template">
        <?php $this->head_field(); ?>
            </script>
 
        <?php
    }

    /**
     * Save admin page options with ajax
     *
     * @global object $wpdb
     */
    function save_options() {
	
        global $wpdb;
     
        $posted = $_POST;
    
        //delete all fields when saving
        $wpdb->query( "DELETE FROM {$wpdb->prefix}core_search" );
		if(!is_array($posted['csw_field_type'])){ return; }
        foreach ($posted['csw_field_type'] as $index => $action) {
            $data = array();

            switch ($action) {
                case 'search':
                    $data = array(
                        'type' => 'search',
                        'label' => $posted['asw_label'][$index],
						'alias' => $posted['asw_key_alias'][$index],
                        'order' => $index
                    );
                 break;
					
				case 'head':
                    $data = array(
                        'type' => 'head',
                        'label' => $posted['asw_label'][$index],
                        'order' => $index,
						'alias' => trim( $posted['asw_key_alias'][$index] ),
                    );
                break;

                case 'custom': {
				
					if(strlen($posted['asw_label'][$index]) > 0){
                    $data = array(
                        'type' => 'custom',
                        'label' => $posted['asw_label'][$index],
                        'order' => $index,
                        'operator' => $posted['asw_operator'][$index],
                        'compare' => $posted['asw_compare'][$index],
                        'values' => $posted['asw_cs_values'][$index],
                        'key' => trim( $posted['asw_key'][$index] ),
                        'alias' => trim( $posted['asw_key_alias'][$index] ),
                        'field_type' => $posted['asw_cs_type'][$index],
                        'description' => $posted['asw_help'][$index]
                    );
                    }
				} break;

                case 'taxonomy': {
                    $data = array(
                        'type' => 'taxonomy',
                        'label' => $posted['asw_label'][$index],
                        'order' => $index,
                        'compare' => $posted['asw_compare'][$index],
						'link' => $posted['asw_link'][$index],
                        'key' => $posted['asw_key'][$index],
                        'description' => $posted['asw_help'][$index],
						'alias' => trim( $posted['asw_key_alias'][$index] ),
                    );
 
                    if ( $posted['asw_cs_type'][$index] == 'yes' ) {
                        $data['field_type'] = 'multi';
						
                    }elseif ( $posted['asw_cs_type'][$index] == 'link' ) {
                        $data['field_type'] = 'link';
                    }
				} break;
                default:
                    break;
            }
  
            $wpdb->insert( $wpdb->prefix . 'core_search', $data );
        }

        //delete transient
        delete_site_transient( 'asw_fields' );
 
    }

    /**
     * Builds an custom field area for search form builder
     *
     * @param null|object $data
     */
    function custom_field( $data = null ) {
	
	global $CORE;
	
        $label = '';
        $meta_key = '';
		$link_key = '';
        $field_type = '';
        $values = '';
        $data_type = '';
        $compare = '';
        $operator = '';
        $help = '';
        $alias = '';
		 

        if ( !is_null( $data ) ) {
            $label = $data->label;
            $meta_key = $data->key;
            $field_type = $data->field_type;
			$link_key = $data->link;
            $values = $data->values;
            $operator = $data->operator;
            $compare = $data->compare;
            $help = $data->description;
            $alias = $data->alias;
        }

        $style = ($field_type == 'select') ? 'block' : 'none';
        ?>
        <li class="postbox adsearchbox closed">
            <div title="Click to toggle" class="handlediv"></div>
            <h3 class="hndle">
                &nbsp;&nbsp; <span class="label label-important"><a href="#" class="asw-remove-el" style="color:#fff;">Remove Field</a></span> // <span class="label label-success">Custom Field</span><span>
                    <?php
                    if ( !empty( $label ) ) {
                        echo ' - ' . stripslashes($label);
                    }
                    ?></span>
            </h3>
            <div class="inside">
            
            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
                Display Caption
                </label>
                <div class="controls span7">
                  
                  <input type="text" class="row-fluid required" 
                  placeholder="Enter your display caption here" name="asw_label[]" value="<?php echo esc_attr( stripslashes($label) ); ?>" />
                    <input type="hidden" name="csw_field_type[]" value="custom" />
                </div>
            </div>
            <!-------------------- FIELD ---------------------->
            
            
          <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
                Search Field
                </label>
                <div class="controls span7">
                  
                  <select data-placeholder="Choose a value..." class="chzn-select" name="asw_key[]" style="width:300px; font-size:12px;">
                    <option value=""></option>
                    
                    <?php if(defined('WLT_DEALER')){ ?>
                     <option value="ctype" <?php if( $meta_key == "ctype"){echo "selected=selected"; } ?> >Car Types (*Recommended*)</option>
                     <option value="cstatus" <?php if( $meta_key == "cstatus"){echo "selected=selected"; } ?> >Car Status (*Recommended*)</option>
                      <?php } ?>
                      
                      
                      <?php if(defined('WLT_DATING')){ ?>
                     <option value="daseeking" <?php if( $meta_key == "daseeking"){echo "selected=selected"; } ?> >I'm a(*Recommended*)</option>
                     <option value="dagender" <?php if( $meta_key == "dagender"){echo "selected=selected"; } ?> >Looking for (*Recommended*)</option>
                     <option value="daage" <?php if( $meta_key == "daage"){echo "selected=selected"; } ?> >Age (*Recommended*)</option>
                     
                     
                      <?php } ?>
                      
                      <option value="map-country1" <?php if( $meta_key == "map-country1"){echo "selected=selected"; } ?> >Country Search &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (USER LIST)&nbsp;&nbsp; (*Recommended*)</option>
                       <option value="map-country" <?php if( $meta_key == "map-country"){echo "selected=selected"; } ?> >Country Search  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (FULL LIST)</option>
                     
                     <option value="">---------------</option>
                      <option value="map-state" <?php if( $meta_key == "map-state"){echo "selected=selected"; } ?>>State Search &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LINKED)&nbsp;&nbsp; (*Recommended*)</option>
                      <option value="map-state1" <?php if( $meta_key == "map-state1"){echo "selected=selected"; } ?>>State Search &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (NOT LINKED)</option>
                     
                     <option value="">---------------</option>
                      <option value="map-city" <?php if( $meta_key == "map-city"){echo "selected=selected"; } ?>>City Search &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LINKED)&nbsp;&nbsp; (*Recommended*)</option>
                      <option value="map-city1" <?php if( $meta_key == "map-city1"){echo "selected=selected"; } ?>>City Search &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (NOT LINKED)</option>
                     
                     <option value="">---------------</option>
                      <option value="map-zip" <?php if( $meta_key == "map-zip"){echo "selected=selected"; } ?>>Zip/Postcode Search</option>
                      
                      
                      <option value="">---------------</option>
                      <option value="wlt_tags" <?php if( $meta_key == "wlt_tags"){echo "selected=selected"; } ?>>Listing Tag</option>
                       <option value="">---------------</option>
                      
                      
                    <?php
					echo $CORE->CUSTOMFIELDLIST(esc_attr( $meta_key ));
					?> 
                    </select>
                </div>
            </div>
            
            <input type="hidden" name="asw_link[]" value="" />
            
           
            <!-------------------- FIELD ---------------------->          
            
            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
                Help Text (Sub Caption)
                </label>
                <div class="controls span7">
                  
                  <input type="text" class="row-fluid" 
                  placeholder="Enter a sub caption if required" name="asw_help[]" value="<?php echo esc_attr( $help ); ?>" />
                 
                </div>
            </div>
            <!-------------------- FIELD ---------------------->
            
            
             <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
               Field Type
                </label>
                <div class="controls span7">
                  
                  <select name="asw_cs_type[]" class="row-fluid" >
                        <option value="text"<?php selected( $field_type, 'text' ); ?>>Text</option>
                        <option value="select"<?php selected( $field_type, 'select' ); ?>>Select</option>
                        <option value="multi-select"<?php selected( $field_type, 'multi-select' ); ?>>Multiple Selection</option>                        
                        
                        <option value="radio"<?php selected( $field_type, 'radio' ); ?>>Radio</option>
                        <option value="date"<?php selected( $field_type, 'date' ); ?>>Date</option>
                        <!--<option value="date-range"<?php selected( $field_type, 'date-range' ); ?>>Date (range)</option>-->
                    </select>
                </div>
            </div>
         
            <!-------------------- FIELD ---------------------->  
               
         <div class="form-row control-group row-fluid show-if-select" id="extrafieldvalues" style="display: <?php echo $style; ?>;">
                
                    
                    
             <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
            
                </label>
                <div class="controls span7">
                
                 <label><b>Selection Box Values</b></label>
                    <textarea name="asw_cs_values[]" class="row-fluid" placeholder="1 value per row" rows="2" cols="20" style="height:200px;"><?php echo esc_textarea( $values ); ?></textarea>
                    <p> <small>(1 value per row/line, use syntax for custom displays <span class="label label-ok">value[text]</span> )</small></p>
                 
                </div>
            </div>                    
           
           
           </div>
                
               <!-------------------- FIELD ---------------------->  
             
              <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
               Data Stored As
                </label>
                <div class="controls span7">
                  
                     <select name="asw_operator[]">
                        <option value="CHAR"<?php selected( $operator, 'CHAR' ); ?>>Text</option>
                        <option value="NUMERIC"<?php selected( $operator, 'NUMERIC' ); ?>>Numeric</option>
                        <option value="BINARY"<?php selected( $operator, 'BINARY' ); ?>>Binary</option>
                        <option value="DATE"<?php selected( $operator, 'DATE' ); ?>>Date</option>
                        <option value="DATETIME"<?php selected( $operator, 'DATETIME' ); ?>>Datetime</option>
                        <option value="DECIMAL"<?php selected( $operator, 'DECIMAL' ); ?>>Decimal</option>
                        <option value="SIGNED"<?php selected( $operator, 'SIGNED' ); ?>>Signed</option>
                        <option value="TIME"<?php selected( $operator, 'TIME' ); ?>>TIME</option>
                        <option value="UNSIGNED"<?php selected( $operator, 'UNSIGNED' ); ?>>Unsigned</option>
                         
                    </select>
                    <br /><span class="description">How is the data stored in your WordPress database.</span>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->  
                 
                
               <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
              Returned Values Must
                </label>
                <div class="controls span7">
                  
                  <select name="asw_compare[]">
                        <option value="="<?php selected( $compare, '=' ); ?>>Equal Search Query</option>
                        <option value="!="<?php selected( $compare, '!=' ); ?>>Not Equal Search Query</option>
                        <option value=">"<?php selected( $compare, '>' ); ?>>Greater Than Search Query</option>
                        <option value=">="<?php selected( $compare, '>=' ); ?>>Greater than or eaual Search Query</option>
                        <option value="<"<?php selected( $compare, '<' ); ?>>Less than Search Query</option>
                        <option value="<="<?php selected( $compare, '<=' ); ?>>Less than or eaual Search Query</option>
                        <option value="LIKE"<?php selected( $compare, 'LIKE' ); ?>>(Like) Search Query</option>
                        <option value="IN"<?php selected( $compare, 'IN' ); ?>>(In) Search Query</option>
                        <option value="NOT IN"<?php selected( $compare, 'NOT IN' ); ?>>(Not In) Search Query</option>
                        <!-- <option value="BETWEEN"<?php selected( $compare, 'BETWEEN' ); ?>>Between</option> -->
                        
                        <!-- <option value="NOT BETWEEN"<?php selected( $compare, 'NOT BETWEEN' ); ?>>Not Between</option> -->
                    </select>
                    <br /><span class="description">how to compare the input value with post custom field?</span>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->                
                  
               <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
              Display Home Page?
                </label>
                 <div class="controls span7">
                  
                  <select name="asw_key_alias[]" class="row-fluid ">
                        <option value="yes"<?php selected( $alias, 'yes' ); ?>>Yes</option>
                        <option value="no"<?php selected( $alias, 'no' ); ?>>No</option>
                    </select>
              
                    <br /><span class="description">Here you can choose to hide fields from displaying on your home page.</span>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->                
           
                 
            </div>
        </li>
         
       
        <?php
    }
	
	
	function head_field( $data = null ){
	
	global  $CORE;
	
	  $label = '';
	  $alias = '';
	   if ( !is_null( $data ) ) {
            $label = stripslashes($data->label);
            $alias = $alias = $data->alias;
        }
	
	?>
    
    <li class="postbox adsearchbox closed">
    
            <div title="Click to toggle" class="handlediv"></div> 
            <h3 class="hndle">
                &nbsp;&nbsp; <span class="label label-important"><a href="#" class="asw-remove-el" style="color:#fff;">Remove Field</a></span> // <span class="label label-inverse">Heading</span> <span>
                    <?php
                    if ( !empty( $label ) ) {
                        echo '- ' . $label;
                    }
                    ?></span>
            </h3>
            
              <div class="inside">
            
              <input type="hidden" name="csw_field_type[]" value="head" /> 
              <input type="hidden" name="asw_operator[]" value="" />
              <input type="hidden" name="asw_cs_values[]" value="" />
              <input type="hidden" name="asw_cs_type[]" value="" />
              <input type="hidden" name="asw_compare[]" value="" />
              <input type="hidden" name="asw_key[]" value="" />
              <input type="hidden" name="asw_help[]" value="" />
              
              <input type="hidden" name="asw_link[]" value="" />
                    
                    
            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
                Display Caption
                </label>
                <div class="controls span7">
                  
                  <input type="text" class="row-fluid required" 
                  placeholder="Enter your display caption here" name="asw_label[]" value="<?php echo esc_attr( $label ); ?>" />
                     
                </div>
            </div>
            <!-------------------- FIELD ---------------------->
             <div class="form-row control-group row-fluid">
                <label class="control-label span4">
              Display Home Page?
                </label>
                 <div class="controls span7">
                  
                  <select name="asw_key_alias[]" class="row-fluid ">
                        <option value="yes"<?php selected( $alias, 'yes' ); ?>>Yes</option>
                        <option value="no"<?php selected( $alias, 'no' ); ?>>No</option>
                    </select>
              
                    <br /><span class="description">Here you can choose to hide fields from displaying on your home page.</span>
                </div>
            </div>
            
          
            
            
    </li>   
    
    
    <?php 	
	
	}

    /**
     * Builds an taxonomy field area for search form builder
     *
     * @param null|object $data
     */
    function taxonomy_field( $data = null ) {
	
	global  $CORE;
	
        $label = '';
        $taxonomy = '';
        $compare = '';
        $help = '';
        $field_type = 'no';
		$alias = '';
		$link_field = "";

        if ( !is_null( $data ) ) {
            $label = $data->label;
            $taxonomy = $data->key;
			$link_field = $data->link;
            $compare = $data->compare;
            $help = $data->description;
            $field_type = $data->field_type;
			$alias = $data->alias;
        }

        $taxs = get_taxonomies();
        $exclude = array('nav_menu', 'link_category', 'post_format','post_tag');
        foreach ($exclude as $ex) {
            if ( in_array( $ex, $taxs ) ) {
                unset( $taxs[$ex] );
            }
        }
        ?>
        <li class="postbox adsearchbox closed">
            <div title="Click to toggle" class="handlediv"></div> 
            <h3 class="hndle">
                &nbsp;&nbsp; <span class="label label-important"><a href="#" class="asw-remove-el" style="color:#fff;">Remove Field</a></span> // <span class="label label-info">Taxonomy</span> <span>
                    <?php
                    if ( !empty( $label ) ) {
                        echo '- ' . $label;
                    }
                    ?></span>
            </h3>
            
            <div class="inside">
            
              <input type="hidden" name="csw_field_type[]" value="taxonomy" /> 
                    <input type="hidden" name="asw_operator[]" value="" />
                    <input type="hidden" name="asw_cs_values[]" value="" />
                     
            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
                Display Caption
                </label>
                <div class="controls span7">
                  
                  <input type="text" class="row-fluid required" 
                  placeholder="Enter your display caption here" name="asw_label[]" value="<?php echo esc_attr( $label ); ?>" />
                     
                </div>
            </div>
            <!-------------------- FIELD ---------------------->
            
            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
                Help Text (Sub Caption)
                </label>
                <div class="controls span7">
                  
                  <input type="text" class="row-fluid" 
                  placeholder="Enter a sub caption if required" name="asw_help[]" value="<?php echo esc_attr( $help ); ?>" />
                 
                </div>
            </div>
            <!-------------------- FIELD ---------------------->
            
            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
               Taxonomy
                </label>
                <div class="controls span7">
                  
                 <select name="asw_key[]" class="row-fluid">
                        <?php
						$not_wanted = array('nav_menu','post_tag','post_format');									
                        foreach ($taxs as $tax) {
							if(in_array($tax,$not_wanted)){ continue; }
							if($tax == "category"){ $display_text = "Blog Category"; }elseif($tax == "listing"){ $display_text = "Listing Categories"; }else{ $display_text = $tax; }
							
                            printf( '<option value="%1$s"%2$s>%3$s</option>', $tax, selected( $taxonomy, $tax, false ), $display_text );
                        }
                        ?>
                    </select>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->

            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
               Display Type
                </label>
                <div class="controls span7">
                  
                 <select name="asw_cs_type[]" class="row-fluid">
                        <option value="no"<?php selected( $field_type, '' ); ?>>Listbox</option>
                        <option value="yes"<?php selected( $field_type, 'multi' ); ?>>Multi Select Listbox</option>
                        <option value="link"<?php selected( $field_type, 'link' ); ?>>List of Checkboxes</option>
                    </select>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->
            
            <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
               Linked Taxonomy
                </label>
                <div class="controls span7">
                  
                  <select data-placeholder="Choose a value..." class="chzn-select" name="asw_link[]">
                    <option value="">This field is not linked.</option>
                    <option value="disabled" <?php if($link_field == "disabled"){ echo "selected=selected"; } ?>>This field is already linked. (disable me)</option>
                    <?php
                        foreach ($taxs as $tax) {
							
							if($tax == "category"){ $display_text = "Blog Category"; }elseif($tax == "listing"){ $display_text = "Listing Categories"; }else{ $display_text = $tax; }
							
                            printf( '<option value="%1$s"%2$s>%3$s</option>', $tax, selected( $link_field, $tax, false ), $display_text );
                        }
                        ?>
                    </select>
                    
                    <span class="description">If the result selected within this field will populate another, select the linked field above.</span>
                    
                </div>
            </div>            
   
                   
                            
          <!-------------------- FIELD ---------------------->
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
               Compare
                </label>
                <div class="controls span7">
                  
               
                    <select name="asw_compare[]" class="row-fluid">
                        <option value="IN"<?php selected( $compare, 'IN' ); ?>>In</option>
                        <option value="NOT IN"<?php selected( $compare, 'NOT IN' ); ?>>Not In</option>
                        <option value="AND"<?php selected( $compare, 'AND' ); ?>>And</option>
                    </select>
                    <span class="description">how to compare the input value with the taxonomy? Default is <b>IN</b></span>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->                
               
                
                
                
            <div class="form-row control-group row-fluid">
                <label class="control-label span4">
              Display Home Page?
                </label>
                 <div class="controls span7">
                  
                  <select name="asw_key_alias[]" class="row-fluid ">
                        <option value="yes"<?php selected( $alias, 'yes' ); ?>>Yes</option>
                        <option value="no"<?php selected( $alias, 'no' ); ?>>No</option>
                    </select>
              
                    <br /><span class="description">Here you can choose to hide fields from displaying on your home page.</span>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->   

               
            </div>
        </li>
        <?php
    }

    /**
     * Builds an search field area for search form builder
     *
     * @param null|object $data
     */
    function search_field( $data = null ) {
        $label = '';

        if ( !is_null( $data ) ) {
            $label = $data->label;
			$alias = $data->alias;
        }
        ?>
        <li class="postbox adsearchbox">
            <div title="Click to toggle" class="handlediv"></div>
            <h3 class="hndle">&nbsp;&nbsp;<span class="label label-important"><a href="#" class="asw-remove-el" style="color:#fff;">Remove Field</a></span> // <span class="label label-warning">Keyword Search</span> - <?php echo esc_attr( $label ); ?> </h3>
            <div class="inside">
                <p>
                    <label>Label</label>
                    <input type="text" class="row-fluid" placeholder="Enter field label" name="asw_label[]" value="<?php echo esc_attr( $label ); ?>" />
                    <input type="hidden" name="csw_field_type[]" value="search" />
                    <input type="hidden" name="asw_operator[]" value="" />
                    <input type="hidden" name="asw_cs_values[]" value="" />
                    <input type="hidden" name="asw_cs_type[]" value="" />
                    <input type="hidden" name="asw_compare[]" value="" />
                    <input type="hidden" name="asw_key[]" value="" />
                    <input type="hidden" name="asw_help[]" value="" />
                   
                    <input type="hidden" name="asw_link[]" value="" />
                </p>
                
                
                <div class="form-row control-group row-fluid">
                <label class="control-label span4">
              Display Home Page?
                </label>
                 <div class="controls span7">
                  <?php if(!isset($alias)){ $alias = "no"; } ?>
                  <select name="asw_key_alias[]" class="row-fluid ">
                        <option value="yes"<?php selected( $alias, 'yes' ); ?>>Yes</option>
                        <option value="no"<?php selected( $alias, 'no' ); ?>>No</option>
                    </select>
              
                    <br /><span class="description">Here you can choose to hide fields from displaying on your home page.</span>
                </div>
            </div>
            <!-------------------- FIELD ---------------------->   

                
            </div>
        </li>
        <?php
}
 
//

function build_form( $fields = null, $form_id = '' ) {
        
		global $wpdb, $CORE; $existing_key_array = array(); $system_extra = "";
 

        $is_admin = is_admin(); $counter = 0;

        ob_start();

        if ( is_null( $fields ) ) {
		
			if( isset($GLOBALS['flag-home']) ){
			
			$fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}core_search WHERE  alias='yes' ORDER BY `order` ASC" );
			}else{ 
			
			$fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}core_search ORDER BY `order` ASC" );
			
			}
            
        }

        if ( !$is_admin ) {
			if($form_id == ""){ $form_id = "core_advanced_search_form"; }
            echo '<form method="get" class="'.$form_id.' list-group" action="' . esc_url( home_url( '/' ) ) . '"><input type="hidden" name="s" value=""> ';
        }

        if ( $fields ) {
		
		// CREATE A UNIQUE TIMESTAMP
		$extraID = str_replace(".","",str_replace("+","",round(microtime(true) * 1000)));
		
		$flagHeading = false; $headingCount  = 0; $fieldsCounter = 0;
            //var_dump($fields);
            foreach ($fields as $field) {
			$fieldsCounter++;
			
			// HEADING SETUP
			if($field->type == "head"){
			
			// CLOSE LAST TAG
			if(isset($flagHeading) && $flagHeading){ echo "</div> </div> </div> "; }
			
			$flagHeading = true; $headingCount ++;
			
			if(isset($_GET['advanced_search'])){ $status = " in"; }else{  $status = "collapse";  }
			
			// PANEL CSS
			if($fieldsCounter == 1){ 
			$cssextra = " firstpanel";
	 		 
			}else{ 
			$cssextra = "";
			}
			
			echo '<div class="clearfix"></div>
			
			<label class="col-md-12"> 
			<a data-toggle="collapse" data-parent="#accordion" href="#head_group_'.$headingCount.'"><i class="glyphicon glyphicon-chevron-down pull-right"></i> </a> 
			
			'.stripslashes($field->label).'</label>
			
			<div class="'.$cssextra.'"> 
				
			<div id="head_group_'.$headingCount.'" class="panel-collapse '.$status.'"> <div class="panel-body"> ';
  
  			continue; // continue to stop showing the label as well
			
			}  
			 	
				// CHANGE SIZE DEPENDNG ON COLUMNS
				if(isset($GLOBALS['CORE_THEME']['layout_columns']['3columns']) && $GLOBALS['CORE_THEME']['layout_columns']['3columns'] == "1"){ $col1 = "col-md-12"; $col2 = "col-md-12"; }else{ $col1 = "col-md-12"; $col2 = "col-md-12";  }
			 
		 		if(!isset($GLOBALS['advanced_search_submenu'])){
				 echo '<div class="form-group fg-'.$field->key.'">'; $counter++; // class="span'.$listtype.' box'.$counter.'"
				}else{
				 echo '<div class="'.$col1.' box'.$counter.'">'; $counter++;
				}
                 
				if($field->field_type != 'link'){
				if(!isset($GLOBALS['advanced_search_submenu'])){ 
				 if ( !empty( $field->label ) ) { printf( '<label class="col-md-12">%s</label>', stripslashes($field->label) );}
					echo "<div class='".$col2."'>"; 				
				}else{				
				 if ( !empty( $field->label ) ) { printf( '<label class="col-md-12">%s</label>', stripslashes($field->label) );}
				}
				}else{ echo "<div>";  }
				
				
				
				
				
				
				if($field->key == "ctype" || $field->key  == "cstatus" ){
				
				$field_name =  $field->key;
				$selected = isset( $_GET[$field_name] ) ? $_GET[$field_name] : '';
				echo '<select name="'.$field_name.'" class="form-control  "><option value="">&nbsp;&nbsp;</option>';
				
				if($field->key == "ctype"){
				$cars_array =  array("2" => $CORE->_e(array('dealer','t2')), "3" => $CORE->_e(array('dealer','t3')), "4" => $CORE->_e(array('dealer','t4')), "5" => $CORE->_e(array('dealer','t5')), "6" => $CORE->_e(array('dealer','t6')), "7" => $CORE->_e(array('dealer','t7')) , "8" => $CORE->_e(array('dealer','t8')) , "9" => $CORE->_e(array('dealer','t9')) , "10" => $CORE->_e(array('dealer','t10')),  "12" => $CORE->_e(array('dealer','t12'))  );
				}else{
				$cars_array = array("1" => $CORE->_e(array('dealer','24')), "2" => $CORE->_e(array('dealer','25')), "3" => $CORE->_e(array('dealer','26'))  ); 
				}
				
				foreach($cars_array as $k => $t){
				
					if(strlen($t) < 2){ continue; }
				
					if($k == $selected){
					echo '<option value="'.$k.'" selected=selected>'.$t.'</option>';
					}else{
					echo '<option value="'.$k.'">'.$t.'</option>';
					}
				
				}
				
				echo '</select>';
				
				
				}elseif($field->key == "dagender" || $field->key  == "daseeking" || $field->key  == "daage" ){
				
				$field_name =  $field->key."--".$counter;
				$selected = isset( $_GET[$field_name] ) ? $_GET[$field_name] : '';
				echo '<select name="'.$field_name.'" class="form-control  "><option value="">&nbsp;&nbsp;</option>';
				
				if($field->key != "daage"){
					$cars_array =  array(					
					"1" => $CORE->_e(array('dating','25')), 
					"2" => $CORE->_e(array('dating','26')), 
					"3" => $CORE->_e(array('dating','27')), 
					"4" => $CORE->_e(array('dating','28')),
					"5" => $CORE->_e(array('dating','31')),
					"6" => $CORE->_e(array('dating','32')),
					"7" => $CORE->_e(array('dating','33')),
					"8" => $CORE->_e(array('dating','34')),
					"9" => $CORE->_e(array('dating','35')),					
					);
				}else{				
					$ageArray = array(); $i = 18;
					while($i < 101){
					$ageArray[$i] = $i;
					$i++;
					}				
					$cars_array = $ageArray;
				}
				
				foreach($cars_array as $k => $t){
				
					// HIDE IF BLANK
					$t = trim($t);
					if($t == ""){ continue; }
						
					if($k == $selected){
					echo '<option value="'.$k.'" selected=selected>'.$t.'</option>';
					}else{
					echo '<option value="'.$k.'">'.$t.'</option>';
					}
				
				}
				
				echo '</select>';
				
				
				}elseif($field->key == "map-country"){
				
				// SELECT AND STRING
				$field_name =  $field->key."--".$counter;
                $selected = isset( $_GET[$field_name] ) ? $_GET[$field_name] : '';
				 printf( '<select name="%s" class="form-control  " id="core_country_dropdown'.$extraID.'"><option value="">&nbsp;&nbsp;</option> ', $field_name );
                 foreach ($GLOBALS['core_country_list'] as $key=>$option) {				 				
                 	printf( '<option value="%1$s"%3$s>%2$s</option>', trim( $key  ), $option, selected( $selected, $key, false ) );
                 }
                 echo '</select>';			 
			 
				 
				}elseif($field->key == "map-state"){
				
				// SELECT AND STRING
				$field_name =  $field->key."--".$counter;
                $selected = isset( $_GET[$field_name] ) ? $_GET[$field_name] : '';				 
				
					printf( '<select name="%s" class="form-control  " id="core_state_dropdown'.$extraID.'"><option value="">&nbsp;&nbsp;</option>', $field_name );                 
                	echo "</select><script> 
					jQuery('#core_country_dropdown".$extraID."').change(function() {
					WLTChangeState('".str_replace("http://","",get_home_url())."',this.value,'core_state_dropdown".$extraID."');				 
					} );";
					
					if($selected != ""){
					// NEED TO FIND THE VALUE FOR MAP-LOCATION
					$cvalue = "";
					foreach($_GET as $key=>$val){ 
						if(substr($key,0,11) == "map-country"){
							$cvalue = $val;
						}
					}
					echo "jQuery(window).load(function () {					
					WLTChangeState('".str_replace("http://","",get_home_url())."','".$cvalue."','core_state_dropdown".$extraID."','".$selected."');
					}); ";
					}
					
					echo "</script>";	
					
				}elseif($field->key == "map-city"){
				
				
				// SELECT AND STRING
				$field_name =  $field->key."--".$counter;
                $selected = isset( $_GET[$field_name] ) ? $_GET[$field_name] : '';				 
				
					printf('<select name="%s" class="form-control  " id="core_city_dropdown'.$extraID.'"><option value="">&nbsp;&nbsp;</option>', $field_name );				
                 
                	echo "</select><script> 
					jQuery('#core_state_dropdown".$extraID."').change(function() {
					WLTChangeState('".str_replace("http://","",get_home_url())."',this.value,'core_city_dropdown".$extraID."');
					} );";
					
					if($selected != ""){
					$cvalue = "";
					// NEED TO FIND THE VALUE FOR MAP-LOCATION
					foreach($_GET as $key=>$val){ 
						if(substr($key,0,9) == "map-state"){
							$cvalue = $val;
						}
					}
					echo "jQuery(window).load(function () {					
					WLTChangeState('".str_replace("http://","",get_home_url())."','".$cvalue."','core_city_dropdown".$extraID."','".$selected."');
					}); ";
					}
					
					echo "</script>";	
					
				}elseif($field->key == "map-country1" || $field->key == "map-state1" || $field->key == "map-city1"){
				 	
					// SELECTED VALUE 
					$selected = isset( $_GET[$field->key."--".$counter] ) ? $_GET[$field->key."--".$counter] : '';	
					 
					// SELECT AND STRING
					$CSTR = "";
					$SQL = "SELECT distinct ".$wpdb->postmeta.".meta_value FROM ".$wpdb->postmeta." 
					INNER JOIN ".$wpdb->posts." ON ( ".$wpdb->postmeta.".post_id = ".$wpdb->posts.".ID AND ".$wpdb->posts.".post_status='publish')
					WHERE ".$wpdb->postmeta.".meta_key = ('".str_replace("1","",$field->key)."') ORDER BY ".$wpdb->postmeta.".meta_value ASC LIMIT 0,500";
		 			  
					$county_list = $wpdb->get_col($SQL); $gh = array();
					if(is_array($county_list)){
						foreach($county_list AS $cc){ 
						
						$cc = trim($cc);
						
						// REMOVE BLANK VALUES
						if($cc == ""){ continue; }							
						
						//if($field->key == "map-country1" && strlen($cc) > 2){ continue; }
						if(in_array($cc,$gh)){ continue; }
						$gh[] = $cc;
						
							if($selected == $cc){ $sel = " selected=selected"; }else{ $sel = ""; }
						
							if(isset($GLOBALS['core_country_list'][$cc])){
								$CSTR .= "<option value='".$cc."' ".$sel.">".$GLOBALS['core_country_list'][$cc]."</option>";
							}else{
								$CSTR .= "<option value='".$cc."'".$sel.">".$cc."</option>";
							}						
						} // foreach
					}// end if
					
					$field_name =  $field->key."--".$counter;
				
					printf( '<select name="%s" class="form-control  " id="core_'.$field->key.'_dropdown'.$extraID.'"><option value="">&nbsp;&nbsp;</option> ', $field_name );
					echo $CSTR;
					echo '</select>';
					
					echo "<script>";
					if($field->key == "map-country1"){
					 
					echo "jQuery('#core_map-country1_dropdown".$extraID."').change(function() {					
						var has_state = jQuery('#core_map-country1_dropdown".$extraID."').val();
						 					
						if(typeof has_state != 'undefined'){
							var has_state_menu = jQuery('#core_map-state1_dropdown".$extraID."').val();	
							 				
							if(typeof has_state_menu != 'undefined'){
								WLTChangeState('".str_replace("http://","",get_home_url())."',this.value,'core_map-state1_dropdown".$extraID."');
							}else{							 
								WLTChangeState('".str_replace("http://","",get_home_url())."',this.value,'core_state_dropdown".$extraID."');
							}
						}
						
						
					} );";
					}
					if($field->key == "map-state1" ){
					echo "jQuery('#core_map-state1_dropdown".$extraID."').change(function() {					
						var has_city = jQuery('#core_map-city1_dropdown".$extraID."').val();
					 
						if(typeof has_city != 'undefined'){							
							var has_city_menu = jQuery('#core_map-city1_dropdown".$extraID."').val();
							if(typeof has_city_menu != 'undefined'){
								WLTChangeState('".str_replace("http://","",get_home_url())."',this.value,'core_map-city1_dropdown".$extraID."');
							}else{
								WLTChangeState('".str_replace("http://","",get_home_url())."',this.value,'core_city_dropdown".$extraID."');
							}						
						}
						var has_city = jQuery('#core_city_dropdown".$extraID."').val();
						 
						if(typeof has_city != 'undefined'){
							WLTChangeState('".str_replace("http://","",get_home_url())."',this.value,'core_city_dropdown".$extraID."');							 						
						}
						
					} );";
					}
					
					echo "</script>";	
					
					
				}elseif($field->key == "map-zip"){
				    if(!isset($_GET['zipcode'])){ $_GET['zipcode'] = ""; }
					printf( '<input type="text" name="zipcode" value="%s"  class="form-control " />', strip_tags($_GET['zipcode']), '' );
				
					if($field->description != "off"){
					
					if( $GLOBALS['CORE_THEME']['geolocation_unit'] == "K"){ $lid = 13; }else{ $lid = 15; }
					
					
					echo "<br /><small>".$CORE->_e(array('widgets','2')).":</small>					
					<select name='radius' class='form-control  '>
					<option value='0' selected='selected'>".$CORE->_e(array('widgets','3'))."</option>
					<option value='1'";
					if(isset($_GET['radius']) && $_GET['radius'] == "1"){ echo "selected=selected "; }
					echo ">1 ".$CORE->_e(array('widgets',$lid))."</option>
					<option value='5'";
					if(isset($_GET['radius']) && $_GET['radius'] == "5"){ echo "selected=selected "; }
					echo ">5 ".$CORE->_e(array('widgets',$lid))."</option>
					<option value='10'";
					if(isset($_GET['radius']) && $_GET['radius'] == "10"){ echo "selected=selected "; }
					echo ">10 ".$CORE->_e(array('widgets',$lid))."</option>
					<option value='50'";
					if(isset($_GET['radius']) && $_GET['radius'] == "50"){ echo "selected=selected "; }
					echo ">50 ".$CORE->_e(array('widgets',$lid))."</option>
					<option value='100'";
					if(isset($_GET['radius']) && $_GET['radius'] == "100"){ echo "selected=selected "; }
					echo ">100 ".$CORE->_e(array('widgets',$lid))."</option>
			 
				</select>";			
					}
					
				}else{
 
                switch ($field->type) {
				
                    case 'custom':
                        //var_dump($field);
                        $field_name =  $field->key."--".$counter;
                        $selected = isset( $_GET[$field_name] ) ? $_GET[$field_name] : '';

 
						if ( $field->field_type == 'date' ) {
						
						$v1 = strip_tags($_GET[$field_name]); 
						if($v1 == ""){ $v1 = date('Y-m-d'); }
						
						echo '<script>jQuery(function(){ jQuery(\'#search_id_'.$field_name.'_div\').datetimepicker({ format: \'yyyy-MM-dd\', pickTime: false,   icons: {
                    time: "fa fa-clock-o",
                    date: "fa fa-calendar",
                    up: "fa fa-arrow-up",
                    down: "fa fa-arrow-down"
                } }); }); </script>
						<div class="input-group date" id="search_id_'.$field_name.'_div" data-date="'.$v1.'" data-date-format="yyyy-MM-dd hh:mm:ss">';
						printf( '<input type="text" id="search_id_'.$field_name.'" name="%s" value="%s"  class="form-control" />', $field_name, $selected );
						  
						 echo '<span class="add-on input-group-addon" style="cursor:pointer;"><i class="glyphicon glyphicon-calendar"></i></span></div>';
						
						
						}elseif ( $field->field_type == 'date-range' ) {
						
						 
						printf( '<input type="text" id="search_id_'.$field_name.'" name="%s" value="%s"  class="span8" />', $field_name, $selected );
						
						$v1 = strip_tags($_GET['dpd1']); 
						if($v1 == ""){ $v1 = date('Y-m-d'); }
						$v2 = strip_tags($_GET['dpd2']); 
						if($v2 == ""){ $v2 = date(date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")+2, date("Y")))); }
						
						echo '<input type="text" class="span2" value="'.$v1.'" id="dpd1" name="dpd1" style="width:100%; min-width:60px;" data-date-format="yyyy-mm-dd"><br />';
						echo '<input type="text" class="span2" value="'.$v2.'" id="dpd2" name="dpd2" style="width:100%; min-width:60px;" data-date-format="yyyy-mm-dd">';
						
						
						  
						 echo ' 
						<script> 
						
						 
						var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
 
var checkin = jQuery(\'#dpd1\').datetimepicker({
  onRender: function(date) {
    return date.valueOf() < now.valueOf() ? \'disabled\' : \'\';
  }
}).on(\'changeDate\', function(ev) {
  if (ev.date.valueOf() > checkout.date.valueOf()) {
    var newDate = new Date(ev.date)
    newDate.setDate(newDate.getDate() + 1);
    checkout.setValue(newDate);
	
	document.getElementById(\'search_id_'.$field_name.'\').value = document.getElementById(\'dpd1\').value;
	//+\'--\'+document.getElementById(\'dpd2\').value
	 
  }
  checkin.hide();
  jQuery(\'#dpd2\')[0].focus();
}).data(\'datetimepicker\');
var checkout = jQuery(\'#dpd2\').datetimepicker({
  onRender: function(date) {
    return date.valueOf() <= checkin.date.valueOf() ? \'disabled\' : \'\';
  }
}).on(\'changeDate\', function(ev) { checkout.hide();}).data(\'datetimepicker\');  </script>';
						
						
						
						
						
                        }elseif ( $field->field_type == 'text' ) {
						
						// BEFORE						 
						$es = "";	
						if($field->operator == "NUMERIC"){ echo '<div class="input-group">';  }
						
						
                        printf( '<input type="text" id="search_id_'.$field_name.'" name="%s" value="%s"  class="form-control " />', $field_name, $selected );
						
						// AFTER
							
						if($field->operator == "NUMERIC"){ echo '<span class="input-group-addon">'.$GLOBALS['CORE_THEME']['currency']['symbol'].'</span></div>'; } // && strpos($field_name,"price") !== false 
						
						
						
						} else if ( $field->field_type == 'radio' ) {
						  
							
							 $fields = $wpdb->get_results( "SELECT DISTINCT ".$wpdb->postmeta.".meta_value FROM ".$wpdb->postmeta." WHERE ".$wpdb->postmeta.".meta_key = '".$field->key."'");
							  
							 if(is_array($fields)){
								 foreach ($fields as $field) {
								 
								 echo "<div class='radio'><input type='radio' name='".$field_name."' value='".$field->meta_value."' />". $field->meta_value."</div>";
								 
								 }
							 }
							 
						} else if ( $field->field_type == 'multi-select' ) {



							if($field->values == ""){
							
								printf( '<select name="%s[]" class="form-control " multiple=multiple>', $field_name );
								echo $CORE->CUSTOMFIELD_LIST($field->key,$selected);
								echo '</select>';
							
							}else{
							
								$options = explode( PHP_EOL, $field->values );
								
								printf( '<select name="%s[]" class="form-control " multiple=multiple>', $field_name );
								foreach ($options as $option) {
								
									// CHECK IF WE HAVE A CUSTOM TEXT OPTION
									$v = explode("[",$option);
									if(isset($v[1]) && strlen($v[1]) > 1){ $display_text = str_replace("]","",$v[1]); }else{ $display_text = $v[0]; }
									
									if(is_array($selected) && !empty($selected)){								 								 
										if(in_array($v[0],$selected) ){ $sel = "selected=selected"; }else{ $sel = ""; } 
									}
									printf( '<option value="%1$s"%3$s>%2$s</option>', trim( $v[0] ), $display_text, $sel );
								}
								echo '</select>';
							
							}
                        	
                        } else if ( $field->field_type == 'select' ) {
							
							
							if($field->values == ""){
							
							printf( '<select name="%s" class="form-control ">', $field_name );
							echo '<option value="">&nbsp;&nbsp;</option>';
							echo $CORE->CUSTOMFIELD_LIST($field->key,$selected);
							echo '</select>';
							
							}else{
                            $options = explode( PHP_EOL, $field->values );
							
                            printf( '<select name="%s" class="form-control ">', $field_name );
                            foreach ($options as $option) {
							
								// CHECK IF WE HAVE A CUSTOM TEXT OPTION
								$v = explode("[",$option);
								if(isset($v[1]) && strlen($v[1]) > 1){ $display_text = str_replace("]","",$v[1]); }else{ $display_text = $v[0]; }
								
                                printf( '<option value="%1$s"%3$s>%2$s</option>', trim( $v[0] ), $display_text, selected( $selected, $v[0], false ) );
                            }
                            echo '</select>';
							
							}
                        }
 						
						if($field->description != "off"){
                        printf( '<span class="description">%s</span>', $field->description );
						}
						
                        break;

                    case 'taxonomy':
                        $taxo = get_taxonomy( $field->key );
                        $field_name = $field->key;
						if(isset($taxo->label)){  $ll = $taxo->label; }else{ $ll = ""; }
						
						 
                        $args = array(
                            'taxonomy' => $field->key,
                            'name' => $field_name,
                            'orderby' => 'name',
                            'hide_empty' => false,
                            'hierarchical' => true,
							'class' => 'form-control ',
                            'echo' => false,						 
                            'show_option_all' => sprintf( ' ', $ll ), //'-- All %s --' 
                            'selected' => (isset( $GET_VALUES_ARRAY[$field->key] )) ? $GET_VALUES_ARRAY[$field->key] : ''
                        );
						
						 
						 
                        if ( $field->key != 'category' ) {
                            $walker = new ASW_Category_Dropdown();
                            $field_name = 'tx_' . $field->key;
						 
                            $args['name'] = $field_name;
                            //$args['id'] = "core_ads_".$field->key;
                            $args['walker'] = $walker;
                            $args['selected'] = (isset( $_GET[$field_name] )) ? esc_attr($_GET[$field_name]) : '';
							
							if($args['selected'] != "" && $field->link != "disabled" && $field->link != '' ){
							echo "<script type='text/javascript'>
							(function($){
							jQuery(document).ready(function() {
							ChangeSearchValues('".str_replace("http://","",get_home_url())."','".esc_attr($_GET[$field_name][0])."','".$field->link."','tx_".$field->link."[]','".esc_attr($_GET["tx_".$field->link][0])."','0', 'core_ads_wrapper_".$field->link."');	
							});})(jQuery);
							</script>";
							}
                        }

                        
                        if ( isset($taxo->hierarchical) && $taxo->hierarchical ) {
                            $dropdown = wp_dropdown_categories( $args );
							// REMOVE THE ID AS ITS NOT NEEDED
							$dropdown = preg_replace('/id=".*?"/', '', $dropdown);

                            if ( $field->field_type == 'multi' ) {
                                
								$dropdown = str_replace(sprintf("<select name='%s'", $field_name), sprintf("<select name='%s[]' multiple='multiple' class='form-control '", $field_name), $dropdown);
                            
							
							}elseif( $field->field_type == 'link' ){
							
							 
							echo '<div class="clearfix"></div>
							
							<label class="col-md-12">'.$field->label.'</label>
							 
								
							<div id="head_group_cat"> ';
							
							
							$terms = get_terms($field->key,"orderby=count&order=desc&pad_counts=1");							 
							 $count = count($terms);
							 if ( $count > 0 ){
								 $system_extra .= "<ul class='wlt_taxonomy_catlist'>";
								 foreach ( $terms as $term ) {								 
								   if($term->parent != "0"){ continue; } // HIDE CHILD	
								   
								   
								   $checkedm = "";
									if(isset($_GET['ct'.$field->id]) && in_array($term->term_id, $_GET['ct'.$field->id]) ){
									$checkedm = "checked=checked";	
									}
								    
						 
						 			if(isset($GLOBALS['CORE_THEME']['layout_columns']['3columns']) && $GLOBALS['CORE_THEME']['layout_columns']['3columns'] == "1"){ $ss = "col-md-9 col-sm-9"; }else{ $ss = "col-md-10 col-sm-10"; }
									
								   echo '<div class="row">
								   
										<div class="col-md-1 col-sm-1">
										<input type="checkbox" name="ct'.$field->id.'[]" value="'.$term->term_id.'" '.$checkedm.'>
										</div>
										
										<div class="'.$ss.'">'.$term->name.'';
										
										if(isset($GLOBALS['CORE_THEME']['layout_columns']['search']) && $GLOBALS['CORE_THEME']['layout_columns']['search'] != 4){ 
										echo ' <span>('.$term->count.')</span> <a href="'.get_term_link($term). '"><i class="fa fa-angle-double-right pull-right"></i></a>';
										}
										
										echo '</div>
										
										</div>';
								   						 
								  			
								 }
								 
							 } 
							
							echo '</div> '; 
							
							
							$dropdown ="";
							 
													
							
							 
							 
							}
						
							
							if ( $field->link != '' ) {
								
								if( $field->link == "disabled"){
								
								$dropdown = str_replace(sprintf("<select name='%s' ", $field_name), sprintf("<select name='%s[]' class='form-control ' disabled=disabled ", $field_name), $dropdown);
								
								}else{		
								
								 if(isset($_GET['tx_'.$field->key][0]) && strlen($_GET['tx_'.$field->key][0]) > 2){
								 $dropdown = str_replace($_GET['tx_'.$field->key][0].'"', $_GET['tx_'.$field->key][0].'" selected=selected',$dropdown);
								 }
							 
								$dropdown = "".str_replace(sprintf("<select name='%s' ", $field_name), sprintf("<select name='%s[]' class='form-control ' onChange=\"jQuery('#core_ads_wrapper_".$field->link."').html('<img src=".FRAMREWORK_URI."img/loading1.gif>');ChangeSearchValues('".str_replace("http://","",get_home_url())."',this.value,'".$field->link."','tx_".$field->link."[]','','','core_ads_wrapper_".$field->link."')\" ", $field_name), $dropdown);
								
								}
                                
                            } 
							
							if ( $field->key != 'category' ) {
							
							}else{
							$dropdown = preg_replace("/id='.*?'/", '', $dropdown);
							}
							
							// DISPLAY DROP DOWN
                            echo  "<span id='core_ads_wrapper_".$field->key."'>".$dropdown."</span>";
							
                        } else {
                            printf( '<input type="text" name="%s" value="" class="form-control " />', $field->key );
                        }

                        printf( '<span class="description">%s</span>', $field->description );

                        break;

                    case 'search':
                        printf( '<input type="text" name="s"  value="%s" class="form-control " />', get_search_query() );
                        break;

                    default:
                        break;
                }// end switch
				
				}// end for loop 
				
				 
				if(!isset($GLOBALS['advanced_search_submenu'])){ echo '</div>'; }
                
				
				if(!isset($GLOBALS['advanced_search_submenu'])){
				 echo '<div class="clearfix"></div></div>';
				}else{
				 echo '</div>';
				}
            }
        } else { 
		
		
            printf( '<input type="text" name="s" value="%s" class="form-control " />', get_search_query() );
        } 
		

		// CHECK FOR HEADING TO CLOSE THE BOX
		if($flagHeading){ echo '</div> </div> </div> '; }	
		
				
				

        if ( !$is_admin ) {
		
		if(isset($GLOBALS['CORE_THEME']['layout_columns']['3columns']) && $GLOBALS['CORE_THEME']['layout_columns']['3columns'] == "1"){ $ss = "col-md-9 col-sm-9"; }else{ $ss = "col-md-5 col-sm-5"; }
		
		// STAR RATING SYSTEM
			if(isset($GLOBALS['CORE_THEME']['rating_as']) && $GLOBALS['CORE_THEME']['rating_as'] == 1 && !isset($GLOBALS['rating_blox_set']) ){
			
			$GLOBALS['rating_blox_set'] = true;
			
			echo '<div class="clearfix"></div><div class="panel1 panel-default1 starratingpanel ">
			
				<div class="panel-heading1">
					<div class="panel-title">
					<a data-toggle="collapse" data-parent="#accordion" href="#"> '.$CORE->_e(array('widgets','28')).' </a>
					</div>	  
				</div>
				
			<div id="head_group_rating"> <div class="panel-body">
			
			';
			
			$i=1; $g = 0; while($g < 5){
	
			$checkedm = "";
			if(isset($_GET['rate']) && in_array($i, $_GET['rate']) ){
			$checkedm = "checked=checked";	
			}
		
			
			echo '<div class="row">
							<div class="col-md-1 col-sm-1">
							<input type="checkbox" name="rate[]" value="'.$i.'" '.$checkedm. '>
							</div>
							<div class="'.$ss.'"> 
							
							
						<div class="wlt_search_starrating">';
						
						switch($g){
						case 0: {
						echo '<span class="fa fa-star size16 readonlytrue" data-score="1" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="2" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="3" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="4" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="5" title="very good"></span>';						
						} break;
						case 1: {						
						echo '<span class="fa fa-star size16 readonlytrue" data-score="1" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="2" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="3" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="4" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="5" title="very good"></span>';						
						} break;
						case 2: {						
						echo '<span class="fa fa-star size16 readonlytrue" data-score="1" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="2" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="3" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="4" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="5" title="very good"></span>';						
						} break;
						case 3: {						
						echo '<span class="fa fa-star size16 readonlytrue" data-score="1" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="2" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="3" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="4" title="very good"></span>
						<span class="fa fa-star-o size16 readonlytrue" data-score="5" title="very good"></span>';						
						} break;
						case 4: {						
						echo '<span class="fa fa-star size16 readonlytrue" data-score="1" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="2" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="3" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="4" title="very good"></span>
						<span class="fa fa-star size16 readonlytrue" data-score="5" title="very good"></span>';						
						} break;
						
						}
						
						
											
				echo '</div></div>';
							
				if($GLOBALS['CORE_THEME']['layout_columns']['3columns'] != "1"){ 
					echo '<div class="col-md-4 col-sm-4">'.$i.' '.$CORE->_e(array('widgets','29')).'</div>';
				}
							
			echo '</div>';
			$i++; $g++;
			}			
			
			echo '</div></div></div> ';
			
			}
		
		
		
		
		
		
            echo '<input type="hidden" name="advanced_search" value="yes" />';
            echo '  <div class="clearfix"></div>
			<div class="col-md-12 btnarea">
			<button type="submit"  class="btn btn-primary col-md-12 text-center">' . $CORE->_e(array('button','11')) . '</button>';
            echo '</div> <div class="clearfix"></div></form> ';
        }
		
		echo $system_extra;

        return ob_get_clean();
    }

    /**
     * Builds the drag-n-drop field area for admin form builder
     *
     * @global object $wpdb
     * @param null|object $fields
     * @return string
     */
    function build_builder_form( $fields = null ) {
        global $wpdb;

        if ( is_null( $fields ) ) {
            $fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}core_search ORDER BY `order` ASC" );
        }

        ob_start();
        foreach ($fields as $field) {

            switch ($field->type) {
                case 'custom':
                    $this->custom_field( $field );
                    break;

                case 'taxonomy':
                    $this->taxonomy_field( $field );
                    break;

                case 'search':
                    $this->search_field( $field );
                    break;
					
				case 'head':
                    $this->head_field( $field );
                    break;

                default:
                    break;
            }
        }

        return ob_get_clean();
    } 

}

$advance_search = Core_Advanced_Search::instance();

/**
 * Create HTML dropdown list of Categories.
 *
 * It's a customized walker. Used only on custom taxonomies printing slug
 * instead of term_id
 *
 * @uses Walker
 */
class ASW_Category_Dropdown extends Walker_CategoryDropdown {

    function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
        $pad = str_repeat( '&nbsp;', $depth * 3 );

        //var_dump($category);
        $cat_name = apply_filters( 'list_cats', $category->name, $category );
        $output .= "\t<option class=\"level-$depth\" id=\"{$category->taxonomy}-{$category->term_id}\" value=\"" . $category->slug . "\"";
        if ( $category->slug == $args['selected'] )
            $output .= ' selected="selected"';
        $output .= '>';
        $output .= $pad . $cat_name;
        if ( $args['show_count'] )
            $output .= '&nbsp;&nbsp;(' . $category->count . ')';
        $output .= "</option>\n";
    }

}

/**
 * Utility function for displaying the search field
 * in theme area
 *
 */
function core_search_form($a="",$b="") {
    $advance_search = Core_Advanced_Search::instance();
    return $advance_search->build_form($a,$b);
}