function updatePurchaseWhere(form)
{
	if( ! form )
		form = document.forms.theForm;

	var regionCd = form.regionCd[form.regionCd.selectedIndex].value;
	var purchaseWhere = form.purchaseWhere;
	var options;

	switch (regionCd) {
	case 'ON':

		options = [
			new Option('1.	SHOPPERS DRUG MART', 'SHOPPERS DRUG MART'),
			new Option('2.	WALMART', 'WALMART'),
			new Option('3.	LOBLAW/ZEHRS/FORTINOS', 'LOBLAW/ZEHRS/FORTINOS'),
			new Option('4.	PHARMAPLUS', 'PHARMAPLUS'),
			new Option('5.	ZELLERS', 'ZELLERS'),
			new Option('6.	GUARDIAN/IDA', 'GUARDIAN/IDA'),
			new Option('7.	METRO', 'METRO'),
			new Option('8.	PHARMX/REXALL', 'PHARMX/REXALL'),
			new Option('9.	FOOD/DRUG BASICS', 'FOOD/DRUG BASICS'),
			new Option('10. OTHER', 'OTHER')
		];

		break;
	case 'AB':
	case 'BC':
	case 'MB':
	case 'NT':
	case 'NU':
	case 'SK':
	case 'YT':

		options = [
			new Option('1.	WALMART', 'WALMART'),
			new Option('2.	REAL CANADIAN SUPERSTORE', 'REAL CANADIAN SUPERSTORE'),
			new Option('3.	SHOPPERS DRUG MART', 'SHOPPERS DRUG MART'),
			new Option('4.	SAFEWAY', 'SAFEWAY'),
			new Option('5.	LONDON DRUGS', 'LONDON DRUGS'),
			new Option('6.	ZELLERS', 'ZELLERS'),
			new Option('7.	OVERWAITEA', 'OVERWAITEA'),
			new Option('8.	PHARMX/REXALL', 'PHARMX/REXALL'),
			new Option('9.	PHARMASAVE', 'PHARMASAVE'),
			new Option('10. OTHER', 'OTHER'),
		];

		break;
	case 'PE':
	case 'QC':
	case 'NS':
	case 'NB':
	case 'NF':

		options = [
			new Option('1.	JEAN COUTU', 'JEAN COUTU'),
			new Option('2.	WALMART', 'WALMART'),
			new Option('3.	LOBLAW/MAXI/PROVIGO', 'LOBLAW/MAXI/PROVIGO'),
			new Option('4.	UNIPRIX', 'UNIPRIX'),
			new Option('5.	LAWTONS', 'LAWTONS'),
			new Option('6.	PHARMAPRIX', 'PHARMAPRIX'),
			new Option('7.	FAMILIPRIX', 'FAMILIPRIX'),
			new Option('8.	BRUNET', 'BRUNET'),
			new Option('9.	PROXIM', 'PROXIM'),
			new Option('10. OTHER', 'OTHER')
		];

		break;

	default:

		options = [];

		break;
	}

	if( options.length == 0 || purchaseWhere.options.length < 2 || purchaseWhere[1].value != options[0].value ) {
		purchaseWhere.options.length = 0;

		purchaseWhere.options[0] = new Option('', '__blank__');
		for(var i = 0; i < options.length; ++i) {
			purchaseWhere.options[purchaseWhere.options.length] = options[i];
		}
	}
}


function chk_phone(validator, field, name)
{
	var phoneNum
		= field.form.phoneNumA.value
		+ field.form.phoneNumB.value
		+ field.form.phoneNumC.value
		;
		
	if( phoneNum.length < 10 ) {
		validator.alert(field, name, 'free' , 'Please supply a value for "Telephone" in the following format: 123-555-9876');
		return false;
	}

	return true;
}

function a_radioset(validator, field, name)
{
   var group = field.form[field.name];
   var i;
   for(i = 0; i < group.length; ++i)
      if( group[i].checked )
         return true;

   validator.alert(field, name, 'free' , 'Please specify if you would like to receive future communications');

   return false;
}

function chk_captchasupplied(validator, field, name)
{
	if( field.value.length < 1 ) {
		validator.alert(field, name, 'free' , 'Please specify the value of the character graphic');
		return false;
	}

	return true;
}

function resetCaptcha(offset)
{
	var conn = getXmlHttpObject();	
	if( conn == null ) {
		return;
	}

	if( ! offset )
		offset = '';

	var url = offset + "../cgi-bin/render_captcha?format=js";

	conn.open("GET", url, false);
	conn.send(null);
	
	var resp = eval('(' + conn.responseText + ')'); 
	document.getElementById("captcha_gif").src = offset + "../gifs/" + resp.frmctl_m + ".gif";
	document.getElementById("frmctl_m").value = resp.frmctl_m;
	document.getElementById("frmctl_h").value = "";
	
}
function howOld(field)
{
   var prov = field.form.regionCode.options[field.form.regionCode.selectedIndex].value;

   if( prov == 'AB'
    || prov == 'MB'
    || prov == 'SK'
    || prov == 'ON'
    || prov == 'QC'
    || prov == 'PE' )
      return 18;
   else if( prov == 'BC'
    || prov == 'NB'
    || prov == 'NU'
    || prov == 'NT'
    || prov == 'NS'
    || prov == 'YT'
    || prov == 'NF' )
      return 19;
   else
      return 0;
}

// NOTA BETA: don't call a function "consent", one of the browers doesn't like it.  Perhaps it overrides an internal function
function consentChecked(validator, field, name)
{
	if( field.checked )
		return true;

    validator.alert(field, name, 'free' , "Please indicate that you agree with the rules of this contest");
	return false;
}

function privacyChecked(validator, field, name)
{
	if( field.checked )
		return true;

    validator.alert(field, name, 'free' , "Please indicate that you have read and understood the Privacy Policy");
	return false;
}

function getXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				return null;
			}
		}
	}
	return xmlHttp;
}
