function validateForm(){
	if(document.ItemList.s.selectedIndex==0)
	{
		alert('Select City/ Choisir la ville');
		return false;
	}
	return true;
}

/* This script and many more are available free online at
 The JavaScript Source :: http://javascript.internet.com
 Created by: Down Home Consulting :: http://downhomeconsulting.com */

/*
 Country State Drop Downs v1.0.
 (c) Copyright 2005 Down Home Consulting, Inc.
 www.DownHomeConsulting.com
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, itness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
 
 */

// If you have PHP you can set the post values like this
//var postState = '<?= $_POST["state"] ?>';
//var postCountry = '<?= $_POST["country"] ?>';
var postState = '';
var postCountry = '';

// State table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var state = '\
AL:Brooks:Brooks|\
AL:Calgary:Calgary|\
AL:Edmonton:Edmonton|\
BC:Vancouver:Vancouver|\
BC:Victoria:Victoria|\
NS:Halifax:Halifax|\
NS:Dartmouth:Dartmouth|\
ONEAST:Belleville:Belleville|\
ONEAST:Brockville:Brockville|\
ONEAST:Cornwall:Cornwall|\
ONEAST:Cobourg:Cobourg|\
ONEAST:Kingston:Kingston|\
ONEAST:Ottawa:Ottawa|\
ONEAST:Peterborough:Peterborough|\
ONEAST:Port Hope:Port Hope|\
ONG:Acton:Acton|\
ONG:Bolton:Bolton|\
ONG:Bradford:Bradford|\
ONG:Burlington:Burlington|\
ONG:Etobicoke:Etobicoke|\
ONG:Georgetown:Georgetown|\
ONG:Milton:Milton|\
ONG:Mississauga:Mississauga|\
ONG:Newmarket:Newmarket|\
ONG:North York:North York|\
ONG:Oshawa:Oshawa|\
ONG:Richmond Hill:Richmond Hill|\
ONG:Scarborough:Scarborough|\
ONG:Toronto:Toronto|\
ONG:Uxbridge:Uxbridge|\
ONG:Whitby:Whitby|\
ONN:Fort Erie:Fort Erie|\
ONN:Hamilton:Hamilton|\
ONN:Niagara Falls:Niagara Falls|\
ONN:St Catharines:St Catharines|\
ONN:Welland:Welland|\
ONNO:Barrie:Barrie|\
ONNO:Collingwood:Collingwood|\
ONNO:Owen Sound:Owen Sound|\
ONW:Amherstburg:Amherstburg|\
ONW:Cambridge:Cambridge|\
ONW:Guelph:Guelph|\
ONW:Kitchener:Kitchener|\
ONW:Leamington:Leamington|\
ONW:London:London|\
ONW:Sarnia:Sarnia|\
ONW:St Thomas:St Thomas|\
ONW:Windsor:Windsor|\
ONW:Woodstock:Woodstock|\
QUE:Montreal:Montreal|\
QUE:Gatineau:Gatineau|\
SAS:Saskatoon:Saskatoon|\
';

// Country data table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var country = '\
AL:Alberta:Alberta|\
BC:British Columbia:British Columbia|\
NS:Nova Scotia:Nova Scotia|\
ONEAST:Ontario East:Ontario East|\
ONG:Ontario GTA:Ontario GTA|\
ONN:Ontario Niagara:Ontario Niagara|\
ONNO:Ontario North:Ontario North|\
ONW:Ontario West:Ontario West|\
QUE:Quebec:Quebec|\
SAS:Saskatchewan:Saskatchewan\
';

function TrimString(sInString) {
	if ( sInString ) {
		sInString = sInString.replace( /^\s+/g, "" );// strip leading
		return sInString.replace( /\s+$/g, "" );// strip trailing
	}
}

// Populates the country selected with the counties from the country list
function populateCountry(defaultCountry) {
	if ( postCountry != '' ) {
		defaultCountry = postCountry;
	}
	var countryLineArray = country.split('|');  // Split into lines
	var selObj = document.getElementById('countrySelect');
	selObj.options[0] = new Option('Select Province / Choisir la Province ','');
	selObj.selectedIndex = 0;
	for (var loop = 0; loop < countryLineArray.length; loop++) {
		lineArray = countryLineArray[loop].split(':');
		countryCode  = TrimString(lineArray[0]);
		countryName  = TrimString(lineArray[1]);
		if ( countryCode != '' ) {
			selObj.options[loop + 1] = new Option(countryName, countryCode);
		}
		if ( defaultCountry == countryCode ) {
			selObj.selectedIndex = loop + 1;
		}
	}
}

function populateState() {
	var selObj = document.getElementById('stateSelect');
	var foundState = true;
	// Empty options just in case new drop down is shorter
	if ( selObj.type == 'select-one' ) {
		for (var i = 0; i < selObj.options.length; i++) {
			selObj.options[i] = null;
		}
		selObj.options.length=null;
		selObj.options[0] = new Option('Select City / Choisir la ville','');
		selObj.selectedIndex = 0;
	}
	// Populate the drop down with states from the selected country
	var stateLineArray = state.split("|");  // Split into lines
	var optionCntr = 1;
	for (var loop = 0; loop < stateLineArray.length; loop++) {
		lineArray = stateLineArray[loop].split(":");
		countryCode  = TrimString(lineArray[0]);
		stateCode    = TrimString(lineArray[1]);
		stateName    = TrimString(lineArray[2]);
		if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
			// If it's a input element, change it to a select
			if ( selObj.type == 'text' ) {
				parentObj = document.getElementById('stateSelect').parentNode;
				parentObj.removeChild(selObj);
				var inputSel = document.createElement("SELECT");
				inputSel.setAttribute("name","s");
				inputSel.setAttribute("id","stateSelect");
				parentObj.appendChild(inputSel) ;
				selObj = document.getElementById('stateSelect');
				selObj.options[0] = new Option('Select City','');
				selObj.selectedIndex = 0;
			}
			if ( stateCode != '' ) {
				selObj.options[optionCntr] = new Option(stateName, stateCode);
			}
			// See if it's selected from a previous post
			if ( stateCode == postState && countryCode == postCountry ) {
				selObj.selectedIndex = optionCntr;
			}
			foundState = true;
			optionCntr++
		}
	}
	// If the country has no states, change the select to a text box
	if ( ! foundState ) {
		parentObj = document.getElementById('stateSelect').parentNode;
		parentObj.removeChild(selObj);
		// Create the Input Field
		var inputEl = document.createElement("INPUT");
		inputEl.setAttribute("id", "stateSelect");
		inputEl.setAttribute("type", "text");
		inputEl.setAttribute("name", "location");
		inputEl.setAttribute("size", 8);
		inputEl.setAttribute("value", postState);
		parentObj.appendChild(inputEl) ;
	}
}

function initCountry(country) {
	populateCountry(country);
	populateState();
}

