var _meteo_villes = {
	AB: [
		'Athabasca',
		'Banff',
		'Barrhead',
		'Bragg Creek',
		'Brooks',
		'Calgary',
		'Camrose',
		'Canmore',
		'Cardston',
		'Claresholm',
		'Cochrane',
		'Cold Lake',
		'Coronation',
		'Drayton Valley',
		'Drumheller',
		'Edmonton',
		'Edson',
		'Fort Chipewyan',
		'Fort Macleod',
		'Fort McMurray',
		'Fort Saskatchewan',
		'Grande Prairie',
		'High Level',
		'High Prairie',
		'High River',
		'Hinton',
		'Jasper',
		'Lac La Biche',
		'Leduc',
		'Lethbridge',
		'Lloydminster',
		'Medicine Hat',
		'Olds',
		'Peace River',
		'Pincher Creek',
		'Ponoka',
		'Provost',
		'Red Deer',
		'Rimbey',
		'Rocky Mountain House',
		'Rosebud',
		'Sherwood Park',
		'Slave Lake',
		'Spruce Grove',
		'St. Albert',
		'St. Paul',
		'Stettler',
		'Strathmore',
		'Sundre',
		'Swan Hills',
		'Sylvan Lake',
		'Taber',
		'Three Hills',
		'Valleyview',
		'Vegreville',
		'Wainwright',
		'Wetaskiwin',
		'Whitecourt'
	],

	BC: [
		'Abbotsford',
		'Bella Coola',
		'Black Creek',
		'Blue River',
		'Burnaby',
		'Campbell River',
		'Castlegar',
		'Chilliwack',
		'Clearwater',
		'Comox',
		'Courtenay',
		'Cowichan Bay',
		'Cranbrook',
		'Creston',
		'Dawson Creek',
		'Delta',
		'Duncan',
		'Fairmont Hot Springs',
		'Fernie',
		'Fort Nelson',
		'Fort St. James',
		'Fort St. John',
		'Gabriola',
		'Gibsons',
		'Golden',
		'Grand Forks',
		'Hope',
		'Houston',
		'Invermere',
		'Kamloops',
		'Kelowna',
		'Kitimat',
		'Langley',
		'Lillooet',
		'Mackenzie',
		'Merritt',
		'Mission',
		'Nanaimo',
		'Nelson',
		'North Saanich',
		'North Vancouver',
		'Osoyoos',
		'Parksville',
		'Peachland',
		'Penticton',
		'Port Alberni',
		'Port Coquitlam',
		'Port Hardy',
		'Powell River',
		'Prince George',
		'Prince Rupert',
		'Princeton',
		'Qualicum Beach',
		'Quesnel',
		'Revelstoke',
		'Richmond',
		'Rossland',
		'Salmon Arm',
		'Sandspit',
		'Sicamous',
		'Smithers',
		'Sparwood',
		'Squamish',
		'Summerland',
		'Surrey',
		'Terrace',
		'Tofino',
		'Trail',
		'Tumbler Ridge',
		'Vancouver',
		'Vanderhoof',
		'Vernon',
		'Victoria',
		'Whistler',
		'White Rock',
		'Williams Lake'
	],

	MB: [
		'Beausejour',
		'Berens River',
		'Brandon',
		'Carman',
		'Churchill',
		'Dauphin',
		'Flin Flon',
		'Gillam',
		'Gimli',
		'Island Lake',
		'Killarney',
		'Minnedosa',
		'Neepawa',
		'Norway House',
		'Portage la Prairie',
		'Selkirk',
		'Steinbach',
		'Swan River',
		'The Pas',
		'Thompson',
		'Virden',
		'Winkler',
		'Winnipeg'
	],

	NB: [
		'Bathurst',
		'Bouctouche',
		'Campbellton',
		'Caraquet',
		'Edmundston',
		'Fredericton',
		'Hampton',
		'Minto',
		'Miramichi',
		'Moncton',
		'Oromocto',
		'Sackville',
		'Saint John',
		'Shediac',
		'St. Stephen',
		'Sussex',
		'Woodstock'
	],

	NL: [
		'Badger',
		'Bonavista',
		'Burgeo',
		'Corner Brook',
		'Deer Lake',
		'Gander',
		'Goose Bay',
		'Grand Falls-Windsor',
		'Holyrood',
		'St. Anthony',
		'St. John\'s',
		'St. Lawrence',
		'Stephenville',
		'Twillingate',
		'Wabush'
	],

	NS: [
		'Amherst',
		'Antigonish',
		'Baddeck',
		'Bridgewater',
		'Chester',
		'Cheticamp',
		'Digby',
		'Grand Lake',
		'Greenwood',
		'Halifax',
		'Ingonish',
		'Kentville',
		'Liverpool',
		'New Glasgow',
		'Peggy\'s Cove',
		'Pictou',
		'Port Hawkesbury',
		'Pugwash',
		'Shelburne',
		'Springhill',
		'Sydney',
		'Truro',
		'Windsor',
		'Yarmouth'
	],

	NT: [
		'Fort Smith',
		'Hay River',
		'Inuvik',
		'Yellowknife'
	],

	NU: [
		'Baker Lake',
		'Iqaluit',
		'Rankin Inlet'
	],

	ON: [
		'Alliston',
		'Amherstburg',
		'Ancaster',
		'Angus',
		'Arnprior',
		'Atikokan',
		'Aurora',
		'Bancroft',
		'Barrie',
		'Belle River',
		'Belleville',
		'Big Trout Lake',
		'Blenheim',
		'Blind River',
		'Bowmanville',
		'Bracebridge',
		'Brampton',
		'Brantford',
		'Britt',
		'Brockville',
		'Burlington',
		'Caledon',
		'Cambridge',
		'Casselman',
		'Chapleau',
		'Chatham',
		'Chelmsford',
		'Cobourg',
		'Collingwood',
		'Cornwall',
		'Deep River',
		'Dryden',
		'Dunnville',
		'Earlton',
		'Elliot Lake',
		'Espanola',
		'Essex',
		'Etobicoke',
		'Exeter',
		'Fenelon Falls',
		'Fenwick',
		'Fergus',
		'Forest',
		'Fort Erie',
		'Fort Frances',
		'Gananoque',
		'Geraldton',
		'Gloucester',
		'Goderich',
		'Gore Bay',
		'Gravenhurst',
		'Guelph',
		'Haliburton',
		'Hamilton',
		'Hanover',
		'Hawkesbury',
		'Hearst',
		'Huntsville',
		'Kanata',
		'Kapuskasing',
		'Kemptville',
		'Kenora',
		'Keswick',
		'Kincardine',
		'Kingston',
		'Kirkland Lake',
		'Kitchener',
		'Lakefield',
		'Leamington',
		'Lindsay',
		'London',
		'Marathon',
		'Markham',
		'Mattawa',
		'Meaford',
		'Midland',
		'Milton',
		'Minden',
		'Mississauga',
		'Mooretown',
		'Moosonee',
		'Morrisburg',
		'Mount Forest',
		'Napanee',
		'New Liskeard',
		'Newmarket',
		'Niagara Falls',
		'Niagara-on-the-Lake',
		'Nipigon',
		'North Bay',
		'North York',
		'Oakville',
		'Orangeville',
		'Orillia',
		'Oshawa',
		'Ottawa',
		'Owen Sound',
		'Parry Sound',
		'Pembroke',
		'Perth',
		'Petawawa',
		'Peterborough',
		'Pickering',
		'Picton',
		'Port Carling',
		'Port Colborne',
		'Port Elgin',
		'Port Perry',
		'Port Stanley',
		'Red Lake',
		'Renfrew',
		'Rockland',
		'Sarnia',
		'Sault Ste. Marie',
		'Scarborough',
		'Simcoe',
		'Sioux Lookout',
		'Smiths Falls',
		'St. Catharines',
		'St. Thomas',
		'Stratford',
		'Strathroy',
		'Sturgeon Falls',
		'Sudbury',
		'Terrace Bay',
		'Thunder Bay',
		'Tilbury',
		'Tillsonburg',
		'Timmins',
		'Toronto',
		'Trenton',
		'Uxbridge',
		'Vaughan',
		'Wallaceburg',
		'Warkworth',
		'Wasaga Beach',
		'Wawa',
		'Welland',
		'Wiarton',
		'Winchester',
		'Windsor'
	],

	PE: [
		'Charlottetown',
		'Montague',
		'Souris',
		'Summerside'
	],

	QC: [
		'Alma',
		'Amos',
		'Amqui',
		'Aylmer',
		'Bagotville',
		'Baie-Comeau',
		'Beauceville',
		'Beauport',
		'Beaupré',
		'Bromont',
		'Candiac',
		'Cap-Chat',
		'Chandler',
		'Charlevoix',
		'Chibougamau',
		'Chicoutimi',
		'Coaticook',
		'Dolbeau-Mistassini',
		'Drummondville',
		'East Angus',
		'Gaspé',
		'Gatineau',
		'Granby',
		'Grand-Mère',
		'Harrington Harbour',
		'Hull',
		'Îles-de-la-Madeleine',
		'Joliette',
		'Jonquière',
		'L\'Annonciation',
		'L\'Assomption',
		'L\'Île-Bizard',
		'La Baie',
		'La Malbaie',
		'La Pocatiere',
		'La Sarre',
		'La Tuque',
		'Lachute',
		'Laval',
		'Le Bic',
		'Lévis',
		'Longueuil',
		'Magog',
		'Maniwaki',
		'Matagami',
		'Matane',
		'Mont-Joli',
		'Mont-Laurier',
		'Montmagny',
		'Montréal',
		'Napierville',
		'Nicolet',
		'Normandin',
		'Pont-Rouge',
		'Québec',
		'Rimouski',
		'Rivière-du-Loup',
		'Roberval',
		'Rouyn-Noranda',
		'Saint-Hubert',
		'Saint-Hyacinthe',
		'Salluit',
		'Senneterre',
		'Sept-Îles',
		'Shawinigan',
		'Sherbrooke',
		'Sorel-Tracy',
		'St-Bruno',
		'St-Bruno-de-Montarville',
		'St-Gabriel-de-Brandon',
		'St-Jean-sur-Richelieu',
		'St-Jérôme',
		'St-Jovite',
		'St-Pamphile',
		'Ste-Agathe-des-Monts',
		'Ste-Anne-des-Monts',
		'Ste-Foy',
		'Sutton',
		'Tadoussac',
		'Témiscaming',
		'Terrebonne',
		'Thetford Mines',
		'Trois-Rivières',
		'Val-d\'Or',
		'Valcartier',
		'Varennes',
		'Victoriaville',
		'Wakefield'
	],

	SK: [
		'Assiniboia',
		'Biggar',
		'Broadview',
		'Canora',
		'Esterhazy',
		'Estevan',
		'Fort Qu\'Appelle',
		'Humboldt',
		'Kamsack',
		'Kindersley',
		'La Ronge',
		'Maple Creek',
		'Meadow Lake',
		'Melfort',
		'Melville',
		'Moose Jaw',
		'Nipawin',
		'North Battleford',
		'Outlook',
		'Prince Albert',
		'Regina',
		'Rosetown',
		'Saskatoon',
		'Swift Current',
		'Tisdale',
		'Warman',
		'Weyburn',
		'Wynyard',
		'Yorkton'
	],

	YT: [
		'Dawson',
		'Whitehorse'
	]
};

function _meteo_ajoutvilles(select_province) {
	var province = select_province.options[select_province.selectedIndex].value
	var select_ville = document.getElementById('ville');

	if(province != 0) {
		select_ville.length              = _meteo_villes[province].length+1;
		select_ville.disabled            = false;
		select_ville.options[0].selected = true;
		
		for(i=0;i<_meteo_villes[province].length;i++) {
			select_ville.options[i+1].text  = _meteo_villes[province][i];
			select_ville.options[i+1].value = _meteo_villes[province][i].toLowerCase();
		}
	} else {
		select_ville.length              = 1;
		select_ville.options[0].selected = true;
		select_ville.disabled            = true;
	}
}

function _meteo_submit(form) {
	if(form.province.value != 0 && form.ville.value != 0) {
	
		var province = form.province.value.toLowerCase();

		var ville = form.ville.value.toLowerCase();
		ville = ville.replace(/[àáâä]/g,'a');
		ville = ville.replace(/[èéêë]/g,'e');
		ville = ville.replace(/[ìíîï]/g,'i');
		ville = ville.replace(/[òóôö]/g,'o');
		ville = ville.replace(/[ùúûü]/g,'u');
		ville = ville.replace(/[ç]/g,   'c');
		ville = ville.replace(/[ÿ]/g,   'y');
		ville = ville.replace(/[^a-z]/g, '');
		
		homepageprefs_weather_set(province+'_'+ville);
		_meteo_change();
	} else {
		alert("Veuillez faire un choix avant de soumettre");	
	}

	return false;
}

function _meteo_change(onload) {
	var ville = homepageprefs_weather_get();
	
	if (ville != '') {
		
		if (onload) {
			$.get('/includes/meteo/ca_'+ville+'.html', function(data){
				document.getElementById('meteo_container').innerHTML = data;
			});
		} else {
			$.get('/includes/meteo/ca_'+ville+'.html', function(data){
				window.opener.document.getElementById('meteo_container').innerHTML = data;
				window.close();			
			});
		}
	} else {
		for (var i=0; i<document.getElementById('meteo_container').getElementsByTagName('a').length; ++i) {
			var link = document.getElementById('meteo_container').getElementsByTagName('a')[i];
			
			if ( link.rel == 'meteo') {
				link.onclick = function(){ return _link_meteo(this); }
			}
		}
	}
}
