// Global Variables

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 = '\
US:AK:Alaska|\
US:AL:Alabama|\
US:AR:Arkansas|\
US:AS:American Samoa|\
US:AZ:Arizona|\
US:CA:California|\
US:CO:Colorado|\
US:CT:Connecticut|\
US:DC:D.C.|\
US:DE:Delaware|\
US:FL:Florida|\
US:GA:Georgia|\
US:GU:Guam|\
US:HI:Hawaii|\
US:IA:Iowa|\
US:ID:Idaho|\
US:IL:Illinois|\
US:IN:Indiana|\
US:KS:Kansas|\
US:KY:Kentucky|\
US:LA:Louisiana|\
US:MA:Massachusetts|\
US:MD:Maryland|\
US:ME:Maine|\
US:MH:Marshall Islands|\
US:MI:Michigan|\
US:FM:Micronesia|\
US:MN:Minnesota|\
US:MO:Missouri|\
US:MP:Marianas|\
US:MS:Mississippi|\
US:MT:Montana|\
US:NC:North Carolina|\
US:ND:North Dakota|\
US:NE:Nebraska|\
US:NH:New Hampshire|\
US:NJ:New Jersey|\
US:NM:New Mexico|\
US:NV:Nevada|\
US:NY:New York|\
US:OH:Ohio|\
US:OK:Oklahoma|\
US:OR:Oregon|\
US:PA:Pennsylvania|\
US:PR:Puerto Rico|\
US:PW:Palau|\
US:RI:Rhode Island|\
US:SC:South Carolina|\
US:SD:South Dakota|\
US:TN:Tennessee|\
US:TX:Texas|\
US:UT:Utah|\
US:VA:Virginia|\
US:VI:Virgin Islands|\
US:VT:Vermont|\
US:WA:Washington|\
US:WI:Wisconsin|\
US:WV:West Virginia|\
US:WY:Wyoming|\
US:AA:Military Americas|\
US:AE:Military Europe/ME/Canada|\
US:AP:Military Pacific|\
CA:AB:Alberta|\
CA:MB:Manitoba|\
CA:AB:Alberta|\
CA:BC:British Columbia|\
CA:MB:Manitoba|\
CA:NB:New Brunswick|\
CA:NL:Newfoundland and Labrador|\
CA:NS:Nova Scotia|\
CA:NT:Northwest Territories|\
CA:NU:Nunavut|\
CA:ON:Ontario|\
CA:PE:Prince Edward Island|\
CA:QC:Quebec|\
CA:SK:Saskatchewan|\
CA:YT:Yukon Territory|\
AU:AAT:Australian Antarctic Territory|\
AU:ACT:Australian Capital Territory|\
AU:NT:Northern Territory|\
AU:NSW:New South Wales|\
AU:QLD:Queensland|\
AU:SA:South Australia|\
AU:TAS:Tasmania|\
AU:VIC:Victoria|\
AU:WA:Western Australia|\
BR:AC:Acre|\
BR:AL:Alagoas|\
BR:AM:Amazonas|\
BR:AP:Amapa|\
BR:BA:Baia|\
BR:CE:Ceara|\
BR:DF:Distrito Federal|\
BR:ES:Espirito Santo|\
BR:FN:Fernando de Noronha|\
BR:GO:Goias|\
BR:MA:Maranhao|\
BR:MG:Minas Gerais|\
BR:MS:Mato Grosso do Sul|\
BR:MT:Mato Grosso|\
BR:PA:Para|\
BR:PB:Paraiba|\
BR:PE:Pernambuco|\
BR:PI:Piaui|\
BR:PR:Parana|\
BR:RJ:Rio de Janeiro|\
BR:RN:Rio Grande do Norte|\
BR:RO:Rondonia|\
BR:RR:Roraima|\
BR:RS:Rio Grande do Sul|\
BR:SC:Santa Catarina|\
BR:SE:Sergipe|\
BR:SP:Sao Paulo|\
BR:TO:Tocatins|\
NL:DR:Drente|\
NL:FL:Flevoland|\
NL:FR:Friesland|\
NL:GL:Gelderland|\
NL:GR:Groningen|\
NL:LB:Limburg|\
NL:NB:Noord Brabant|\
NL:NH:Noord Holland|\
NL:OV:Overijssel|\
NL:UT:Utrecht|\
NL:ZH:Zuid Holland|\
NL:ZL:Zeeland|\
UK:AVON:Avon|\
UK:BEDS:Bedfordshire|\
UK:BERKS:Berkshire|\
UK:BUCKS:Buckinghamshire|\
UK:CAMBS:Cambridgeshire|\
UK:CHESH:Cheshire|\
UK:CLEVE:Cleveland|\
UK:CORN:Cornwall|\
UK:CUMB:Cumbria|\
UK:DERBY:Derbyshire|\
UK:DEVON:Devon|\
UK:DORSET:Dorset|\
UK:DURHAM:Durham|\
UK:ESSEX:Essex|\
UK:GLOUS:Gloucestershire|\
UK:GLONDON:Greater London|\
UK:GMANCH:Greater Manchester|\
UK:HANTS:Hampshire|\
UK:HERWOR:Hereford & Worcestershire|\
UK:HERTS:Hertfordshire|\
UK:HUMBER:Humberside|\
UK:IOM:Isle of Man|\
UK:IOW:Isle of Wight|\
UK:KENT:Kent|\
UK:LANCS:Lancashire|\
UK:LEICS:Leicestershire|\
UK:LINCS:Lincolnshire|\
UK:MERSEY:Merseyside|\
UK:NORF:Norfolk|\
UK:NHANTS:Northamptonshire|\
UK:NTHUMB:Northumberland|\
UK:NOTTS:Nottinghamshire|\
UK:OXON:Oxfordshire|\
UK:SHROPS:Shropshire|\
UK:SOM:Somerset|\
UK:STAFFS:Staffordshire|\
UK:SUFF:Suffolk|\
UK:SURREY:Surrey|\
UK:SUSS:Sussex|\
UK:WARKS:Warwickshire|\
UK:WMID:West Midlands|\
UK:WILTS:Wiltshire|\
UK:YORK:Yorkshire|\
EI:CO ANTRIM:County Antrim|\
EI:CO ARMAGH:County Armagh|\
EI:CO DOWN:County Down|\
EI:CO FERMANAGH:County Fermanagh|\
EI:CO DERRY:County Londonderry|\
EI:CO TYRONE:County Tyrone|\
EI:CO CAVAN:County Cavan|\
EI:CO DONEGAL:County Donegal|\
EI:CO MONAGHAN:County Monaghan|\
EI:CO DUBLIN:County Dublin|\
EI:CO CARLOW:County Carlow|\
EI:CO KILDARE:County Kildare|\
EI:CO KILKENNY:County Kilkenny|\
EI:CO LAOIS:County Laois|\
EI:CO LONGFORD:County Longford|\
EI:CO LOUTH:County Louth|\
EI:CO MEATH:County Meath|\
EI:CO OFFALY:County Offaly|\
EI:CO WESTMEATH:County Westmeath|\
EI:CO WEXFORD:County Wexford|\
EI:CO WICKLOW:County Wicklow|\
EI:CO GALWAY:County Galway|\
EI:CO MAYO:County Mayo|\
EI:CO LEITRIM:County Leitrim|\
EI:CO ROSCOMMON:County Roscommon|\
EI:CO SLIGO:County Sligo|\
EI:CO CLARE:County Clare|\
EI:CO CORK:County Cork|\
EI:CO KERRY:County Kerry|\
EI:CO LIMERICK:County Limerick|\
EI:CO TIPPERARY:County Tipperary|\
EI:CO WATERFORD:County Waterford|\
';

// 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 = '\
CA:Canada|\
US:United States|\
UK:United Kingdom|\
--:-------------------------------------|\
AF:Afghanistan|\
AL:Albania|\
DZ:Algeria|\
AS:American Samoa|\
AD:Andorra|\
AO:Angola|\
AI:Anguilla|\
AQ:Antarctica|\
AG:Antigua and Barbuda|\
AR:Argentina|\
AM:Armenia|\
AW:Aruba|\
AU:Australia|\
AT:Austria|\
AZ:Azerbaijan|\
AP:Azores|\
BS:Bahamas|\
BH:Bahrain|\
BD:Bangladesh|\
BB:Barbados|\
BY:Belarus|\
BE:Belgium|\
BZ:Belize|\
BJ:Benin|\
BM:Bermuda|\
BT:Bhutan|\
BO:Bolivia|\
BA:Bosnia And Herzegowina|\
XB:Bosnia-Herzegovina|\
BW:Botswana|\
BV:Bouvet Island|\
BR:Brazil|\
IO:British Indian Ocean Territory|\
VG:British Virgin Islands|\
BN:Brunei Darussalam|\
BG:Bulgaria|\
BF:Burkina Faso|\
BI:Burundi|\
KH:Cambodia|\
CM:Cameroon|\
CV:Cape Verde|\
KY:Cayman Islands|\
CF:Central African Republic|\
TD:Chad|\
CL:Chile|\
CN:China|\
CX:Christmas Island|\
CC:Cocos (Keeling) Islands|\
CO:Colombia|\
KM:Comoros|\
CG:Congo|\
CD:Congo, The Democratic Republic O|\
CK:Cook Islands|\
XE:Corsica|\
CR:Costa Rica|\
CI:Cote d` Ivoire (Ivory Coast)|\
HR:Croatia|\
CU:Cuba|\
CY:Cyprus|\
CZ:Czech Republic|\
DK:Denmark|\
DJ:Djibouti|\
DM:Dominica|\
DO:Dominican Republic|\
TP:East Timor|\
EC:Ecuador|\
EG:Egypt|\
SV:El Salvador|\
GQ:Equatorial Guinea|\
ER:Eritrea|\
EE:Estonia|\
ET:Ethiopia|\
FK:Falkland Islands (Malvinas)|\
FO:Faroe Islands|\
FJ:Fiji|\
FI:Finland|\
FR:France (Includes Monaco)|\
FX:France, Metropolitan|\
GF:French Guiana|\
PF:French Polynesia|\
TA:French Polynesia (Tahiti)|\
TF:French Southern Territories|\
GA:Gabon|\
GM:Gambia|\
GE:Georgia|\
DE:Germany|\
GH:Ghana|\
GI:Gibraltar|\
GR:Greece|\
GL:Greenland|\
GD:Grenada|\
GP:Guadeloupe|\
GU:Guam|\
GT:Guatemala|\
GN:Guinea|\
GW:Guinea-Bissau|\
GY:Guyana|\
HT:Haiti|\
HM:Heard And Mc Donald Islands|\
VA:Holy See (Vatican City State)|\
HN:Honduras|\
HK:Hong Kong|\
HU:Hungary|\
IS:Iceland|\
IN:India|\
ID:Indonesia|\
IR:Iran|\
IQ:Iraq|\
IE:Ireland|\
EI:Ireland (Eire)|\
IL:Israel|\
IT:Italy|\
JM:Jamaica|\
JP:Japan|\
JO:Jordan|\
KZ:Kazakhstan|\
KE:Kenya|\
KI:Kiribati|\
KP:Korea, Democratic People\'S Repub|\
KW:Kuwait|\
KG:Kyrgyzstan|\
LA:Laos|\
LV:Latvia|\
LB:Lebanon|\
LS:Lesotho|\
LR:Liberia|\
LY:Libya|\
LI:Liechtenstein|\
LT:Lithuania|\
LU:Luxembourg|\
MO:Macao|\
MK:Macedonia|\
MG:Madagascar|\
ME:Madeira Islands|\
MW:Malawi|\
MY:Malaysia|\
MV:Maldives|\
ML:Mali|\
MT:Malta|\
MH:Marshall Islands|\
MQ:Martinique|\
MR:Mauritania|\
MU:Mauritius|\
YT:Mayotte|\
MX:Mexico|\
FM:Micronesia, Federated States Of|\
MD:Moldova, Republic Of|\
MC:Monaco|\
MN:Mongolia|\
MS:Montserrat|\
MA:Morocco|\
MZ:Mozambique|\
MM:Myanmar (Burma)|\
NA:Namibia|\
NR:Nauru|\
NP:Nepal|\
NL:Netherlands|\
AN:Netherlands Antilles|\
NC:New Caledonia|\
NZ:New Zealand|\
NI:Nicaragua|\
NE:Niger|\
NG:Nigeria|\
NU:Niue|\
NF:Norfolk Island|\
MP:Northern Mariana Islands|\
NO:Norway|\
OM:Oman|\
PK:Pakistan|\
PW:Palau|\
PS:Palestinian Territory, Occupied|\
PA:Panama|\
PG:Papua New Guinea|\
PY:Paraguay|\
PE:Peru|\
PH:Philippines|\
PN:Pitcairn|\
PL:Poland|\
PT:Portugal|\
PR:Puerto Rico|\
QA:Qatar|\
RE:Reunion|\
RO:Romania|\
RU:Russian Federation|\
RW:Rwanda|\
KN:Saint Kitts And Nevis|\
SM:San Marino|\
ST:Sao Tome and Principe|\
SA:Saudi Arabia|\
SN:Senegal|\
XS:Serbia-Montenegro|\
SC:Seychelles|\
SL:Sierra Leone|\
SG:Singapore|\
SK:Slovak Republic|\
SI:Slovenia|\
SB:Solomon Islands|\
SO:Somalia|\
ZA:South Africa|\
GS:South Georgia And The South Sand|\
KR:South Korea|\
ES:Spain|\
LK:Sri Lanka|\
NV:St. Christopher and Nevis|\
SH:St. Helena|\
LC:St. Lucia|\
PM:St. Pierre and Miquelon|\
VC:St. Vincent and the Grenadines|\
SD:Sudan|\
SR:Suriname|\
SJ:Svalbard And Jan Mayen Islands|\
SZ:Swaziland|\
SE:Sweden|\
CH:Switzerland|\
SY:Syrian Arab Republic|\
TW:Taiwan|\
TJ:Tajikistan|\
TZ:Tanzania|\
TH:Thailand|\
TG:Togo|\
TK:Tokelau|\
TO:Tonga|\
TT:Trinidad and Tobago|\
XU:Tristan da Cunha|\
TN:Tunisia|\
TR:Turkey|\
TM:Turkmenistan|\
TC:Turks and Caicos Islands|\
TV:Tuvalu|\
UG:Uganda|\
UA:Ukraine|\
AE:United Arab Emirates|\
GB:Great Britain|\
UM:United States Minor Outlying Isl|\
UY:Uruguay|\
UZ:Uzbekistan|\
VU:Vanuatu|\
XV:Vatican City|\
VE:Venezuela|\
VN:Vietnam|\
VI:Virgin Islands (U.S.)|\
WF:Wallis and Furuna Islands|\
EH:Western Sahara|\
WS:Western Samoa|\
YE:Yemen|\
YU:Yugoslavia|\
ZR:Zaire|\
ZM:Zambia|\
ZW:Zimbabwe|\
';

// General Functions

	function getSelectedText(selectbox) {
		// Gets the text of a selected select option
		var selected = document.getElementById(selectbox).selectedIndex;
		var text = document.getElementById(selectbox)[selected].text;
		return text
	}
	
		function getSelectedValue(selectbox) {
		// Gets the text of a selected select option
		var selected = document.getElementById(selectbox).selectedIndex;
		var value = document.getElementById(selectbox)[selected].value;
		return value
	}
	
	// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked	
	function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

	function getCheckedValue(radioObj) {
		// Gets the value of a selected radio object	
		if(!radioObj)
			return "";
		var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
				return radioObj.value;
			else
				return "";
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
		}
		return "";
	}
	
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

	function setprovince(province, type) {
						
			prefix = "" // used to distinguish person info from billing info
			
			if (type == "acknowledge") {
				prefix = "p"	
			} 
			
			actual = ""
			// actual = province.value;
			
			provincesel = prefix + "provincesel";
			
			//actual = document.getElementById(provincesel).value
			
			actual = province.value

			//alert(type)
			//alert(provincesel)
			//alert(actual)
			
			actualprovinceid = prefix + "actualprovince";
		
			//document.getElementById(actualprovinceid).value = actual;
			
	}
	function setcountry(country) {

	}
	

	
	function formatPostalCode(field, type) {
			var postalcode = "";
			
			//if (type == "acknowledge") {
			///	countryfield = "pcountrysel";
			//} else if (type == "billing") {
				countryfield = "countrysel";
			//}
			//alert(countryfield)
			if (getSelectedText(countryfield) == "Canada") {
				postalcode = removeSpaces(document.getElementById(field).value.toUpperCase());
				if (isPostCode(postalcode)) {
					left = postalcode.substr(0,3);
					if (postalcode.substr(3,1) == " ") {
						right = postalcode.substr(4,3);
					} else {
						right = postalcode.substr(3,3);
					}	
					postalcode = left + " " + right;
					document.getElementById(field).value = postalcode
				} else {
					alert("Please check the value entered for the postal code")	
				}
			}
	}
	
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function isPostCode(entry){ // checks Canadian codes only
	strlen=entry.length; if (strlen!==6){return false;}
	entry=entry.toUpperCase();  // in case of lowercase
	// Check for legal characters in string - note index starts at zero
	if('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0) {return false;}
	if('0123456789'.indexOf(entry.charAt(1))<0) {return false;}
	if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0) {return false;}
	if('0123456789'.indexOf(entry.charAt(3))<0) {return false;}
	if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4))<0) {return false;}
	if('0123456789'.indexOf(entry.charAt(5))<0) {return false;}
return true;}


	function createRef() {
		// Creates the reference number
		var ref = ""
		var cts = document.Formular.centretosupport.value
		var namepart = ((document.Formular.lastname.value).substring(0,3))
		var now = new Date();
		var hour        = now.getHours();
		var minute      = now.getMinutes();
		var monthnumber = now.getMonth();
		var monthday    = now.getDate();
		var year        = (now.getFullYear() + "").substring(2,4);
		ref = cts + namepart + year + monthday + (monthnumber + 1) + hour + minute
		submissiondate = monthday + "/" + (monthnumber + 1) + "/" + year
		document.Formular.date.value = submissiondate
		document.Formular.reference.value = ref
		//alert(document.Formular.reference.value)
		buildconfirm()
	}

	function buildconfirm() {
		// build the confirmation page
var confirmation = ""
		var centre = ""
		var centre = getSelectedText('centretosupport')
		//document.getElementById('centrename').value = centre
		document.Formular.centrename.value = centre
		if (document.Formular.spousefirstname.value != "" || document.Formular.spouselastname.value != "" ) {
			spousename = " and " + document.Formular.spousetitle.value + " " + document.Formular.spousefirstname.value + " " + document.Formular.spouselastname.value
		} else {
			spousename = ""	
		}
		//donation type + name
		
		var donortype = getCheckedValue(document.Formular.donortype)
		
		if (donortype == "D_I") {
			confirmation = "This is an individual donation to " + centre + " made by:\n\n"
			//confirmation += "Issue my receipt to:\n\n"
			donor = document.Formular.title.value + " " + document.Formular.firstname.value + " " + document.Formular.middleinitial.value + " " + document.Formular.lastname.value + spousename + "\n"
			
		}
			if (donortype == "D_C") {
			confirmation = "This is a corporate donation to " + centre + " made by:\n\n"
			//confirmation += "Issue my receipt to:\n\n"	
			donor += "" + document.Formular.company.value + "\n"
		}
		
		
		
		// address info
		
		if (document.Formular.suite.value != "") {
				donor += document.Formular.suite.value + " - "
			}
		donor += document.Formular.street1.value + "\n" 
		if (document.Formular.street2.value != "") {
			donor += document.Formular.street2.value + "\n"
		}
		donor += document.Formular.city.value + ", " + document.Formular.actualprovince.value + "\n" + getSelectedText('countrysel') + "\n" + document.Formular.postalcode.value			

		confirmation += donor

		//alert(getSelectedText('pcountrysel'))
		// public recognition
		var recognition = getCheckedValue(document.Formular.public)
		if (recognition == "yes") {
			confirmation += "\n\nYes, Wellspring can recognize my gift publicly.\n\n"
		}
		if (recognition == "no") {
			confirmation += "\n\nNo, Wellspring cannot recognize my gift publicly.\n\n"
		}
		
		//amount
		
		confirmation += document.Formular.amount.value + " will be charged"
		
		if (document.Formular.donationtype.value == "monthly-donation") {
			confirmation += " monthly"
		}
		
		confirmation += " to my"
		
		var creditcard = getCheckedValue(document.Formular.cardtype)
				
		confirmation += "\n" + creditcard + " account\n"
		confirmation += document.Formular.ccnumber.value + " Expiry " + document.Formular.expirymonth.value + "/" + document.Formular.expiryyear.value + "\n\n"
		confirmation += "Issue my receipt to " + document.Formular.cardholder.value + ", which is the name on the credit card. \n"
		
		corporatecard = getCheckedValue(document.Formular.corporatecard)
		if (corporatecard == "yes") {
			confirmation += "Yes, this is a Corporate Credit Card.\n\n"
			//confirmation += "company:" + document.getElementById('company').value
		}
		if (corporatecard == "no") {
			confirmation += "No, this is not a Corporate Credit Card.\n\n"
		}		
		

		if (document.getElementById('donationtype').value == "sponsor-a-person" || document.getElementById('donationtype').value == "in-memory" || document.getElementById('donationtype').value == "in-honour")  {
			if (document.getElementById('donationtype').value == "sponsor-a-person") {
				// confirmation += "The person you are sponsoring will be notified as follows:\n\n"
			} else if (document.getElementById('donationtype').value == "in-memory" || document.getElementById('donationtype').value == "in-honour") {
				confirmation += "Your donation will be acknowledged as follows:\n\n"
			}
			
			confirmation += "A donation has been made to " + centre + " "
			// centre
			
			if (document.getElementById('donationtype').value == "sponsor-a-person") {
				confirmation += "to sponsor " 
				if (document.Formular.person.value != "") {
					confirmation += document.Formular.person.value + " in "
				}
				
				 eventdropdownvalue = getSelectedText('event')
				 //alert(eventdropdownvalue)
				if (eventdropdownvalue == "Other") {
					confirmation += "the " + document.Formular.actualevent.value
				} else {
					confirmation += "the " + eventdropdownvalue
				}
				
			} else if (document.getElementById('donationtype').value == "in-memory") {
				confirmation += "to honour the memory of " 
				confirmation += document.Formular.person.value 
				
			} else if (document.getElementById('donationtype').value == "in-honour") {
				confirmation += "in celebration of " + document.Formular.person.value + "'s "
				confirmation += document.Formular.actualoccasion.value 
			}
			
		
		

			if (!document.getElementById('pnodisclose').checked) {
				confirmation += " by\n\n"
				//confirmation += document.Formular.madeby.value + ".\n\n"
				//confirmation += document.Formular.madeby.value + "\n"
				//if (document.Formular.suite.value != "") {
				//	confirmation += document.Formular.suite.value + " - "
				//}
				//confirmation += document.Formular.street1.value + "\n" 
				//if (document.Formular.street2.value != "") {
				//	confirmation += document.Formular.street2.value + "\n"
				//}
				//confirmation += document.Formular.city.value + ", " + document.Formular.actualprovince.value + "\n" + getSelectedText('countrysel') + "\n"+ document.Formular.postalcode.value	+ " "
				confirmation += donor
			}
			confirmation += "\n\nYour Personal Message:\n\n"
			confirmation += "" + document.getElementById('personalmessage').value + "\n\n"
		}

	//alert(confirmation)
	//alert(confirmation)
	confirmation += "\n\nPlease scroll to bottom of page and click submit."
	document.getElementById('confirmation').value = confirmation	

	//document.getElementById("confirmation").innerHTML = confirmation

				
	}
	
	
	//Phone Number Formatting
	
function formatPhone(object) {

	country = getSelectedText('countrysel')
	if ((country == 'Canada') || (country == 'United States')) {
		
	num=object.value
	   var _return=false;
	  /*
	   * 7181238748 to 1(718)123-8748
	   */ 
	
	  if(num.length != 10)
	  { 
		if(num.length == 12) {
		/* check to see if it is formatted with dashes */
			//alert(dash1 + dash2)
			if ((dash1 == "-") && (dash2 == "-")) {
				return
			} else {
				alert("'" + num + "' is not a standard phone number format ('416-555-5555'), please verify the number entered");
			}
			
		}
		alert("'" + num + "' is not a standard phone number format ('416-555-5555'), please verify the number entered");
		/* 
		 * if user did not enter 10 digit phone number then simply print whatever user entered 
		 */ 
		return
	  } 
	  else
	  { 
		/* formating phone number here */ 
		_return="";
		var ini = num.substring(0,3);
		_return+=ini+"-";
		var st = num.substring(3,6);
		_return+=st+"-";
		var end = num.substring(6,10);
		_return+=end;
	  }
	  object.value = _return;
	  return  
	}
} 	
 
 
 //end phone number formatting
  			
function writeprovinces(type) {

	var provinces = "" 
	var prefix = "" // used to distinguish person info from billing info
	var	countrysel = "" 
	var	countrydiv = "" 
	var	provincediv = "" 
	var	provincesel = "" 
	var	actualcountryid = "" 
	var	actualprovinceid = "" 
	
	
	if (type == "acknowledge") {
		prefix = "p"	
	} 
	
	countrysel = prefix + "countrysel";
	countrydiv = prefix + "countrydiv";
	provincediv = prefix + "provincediv";
	provincesel = prefix + "provincesel";
	actualcountryid = prefix + "actualcountry";
	actualprovinceid = prefix + "actualprovince";
		
	//alert(countrysel)
	
	countryval = ""
	countryval = document.getElementById(countrysel).value

	// provinceval = document.getElementById(actualprovinceid).value
	
	//countryval = document.getElementById(countrysel).value
	//countryval = document.getElementById(actualcountryid).value
	//alert("1, " + countryval)
	if (countryval == "") { // if undefined, ie first time, then set to Canada
		countryval = "CA"
	} 
		
	
	provinces += populateProvinces(countryval, provincediv, provincesel, '', type);
	//alert(provinces)
		
/*
	}
*/
//alert(actualcountrydiv)
		document.getElementById(provincediv).innerHTML = provinces
		//document.getElementById(actualcountryid).value = countryval;
	}

function populateProvinces(countryval, provincediv, provincesel, provinceval, type) {
	var foundState = false;
	var postCountry = countryval;
	var provinces = "";
	var postState = provinceval;
	//alert(postState);
	
//alert(countryval)
// Populate the drop down with states from the selected country
  var stateLineArray = state.split("|");  // Split into lines
  var optionCntr = 1;

  provinces ='<select name="' + provincesel + '"  id="' + provincesel + '" tabindex="1" onchange="setprovince(this, \'' + type + '\')">';
  
  provinces += '<option value = "">Please Select</option>';
  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 (countryval == countryCode && countryCode != '' ) {

		provinces += '<option value = "' + stateCode + '" ###selected_' + provincediv + '_' + stateCode + '###';
		if ( stateCode == postState ) {
       		
			provinces += ' selected ';
      	}
		provinces += '>'+ stateName + '</option>';
	foundState = true;
	}
	
  }
  provinces += '</select>';
    if ( ! foundState ) {
	//	alert("no")
  
  	//	provinces = '<input type="text" name="other' + provincesel+ '" id="other' + provincesel + '" value="###value_other' + provincesel + '###" onchange="setprovince(this, \'' + type + '\')" tabindex="4" />';
	
	
	provinces = '<input type="text" name="other' + provincesel+ '" id="other' + provincesel + '" value="' + provinceval + '" onchange="setprovince(this, \'' + type + '\')" tabindex="4" />';

  }
  return(provinces);
}
		
function initCountry(type) {

	var prefix = "" // used to distinguish person info from billing info
	
	var countrydiv = "";
	var countrysel = "";
	var provincediv = "";
	var actualcountryid = "";
	
	if (type == "purchased") {
		prefix = "p"
		
	} 
	//countryval = document.getElementById(prefix + "actualcountry").value
	
	//if (countryval == "") { // if undefined, ie first time, then set to Canada
		countryval = "CA"
	//} 
	
	//test

	
	countrydiv = prefix + "countrydiv";
	countrysel = prefix + "countrysel";
	provincediv = prefix + "provincediv";
	//actualcountryid = prefix + "actualcountry";
	
	//alert(countryval + countrydiv + provincediv)
  populateCountry(countryval, countrydiv, countrysel, provincediv, type);
  writeprovinces(type);
}

// Populates the country selected with the counties from the country list
function populateCountry(defaultCountry, countrydiv, countrysel, provincediv, type) {
  if ( postCountry != '' ) {
    defaultCountry = postCountry;
  }

	extra = "onchange=\"writeprovinces(\'' + type + '\')\""
	if (type == "purchased") {
		extra = "class=\"fullwidth\"";
	}
	
	
	
	countries = ''
  	countries = '<select name=\"' + countrysel + '\"  id=\"' + countrysel + '\" tabindex=\"1\"' + extra +'>'
	
	countryLineArray = country.split('|');  // Split into lines

  	for (var loop = 0; loop < countryLineArray.length; loop++) {
    lineArray = countryLineArray[loop].split(':');
    countryCode  = TrimString(lineArray[0]);
    countryName  = TrimString(lineArray[1]);
    if ( countryCode != '' ) {
		countries += '<option value = "' + countryCode + '" ###selected_' + countrydiv + '_' + countryCode + '###';
	if ( defaultCountry == countryCode ) {
      countries += ' selected ';
    } 
		
		countries += '>' + countryName + '</option>';
	
    }
   
  }
  countries += "</select>";
  //alert(countrydiv);
  document.getElementById(countrydiv).innerHTML = countries
}

/* Date Field Functionss */

function populate(inForm) {
	//alert(inForm);
	var temp=0;
	var today= new Date();
	var day= today.getDate();
	var month= today.getMonth();
	var year= today.getFullYear();
	t2= 5;
	
	
	
	for (var i=0; i <31 ; i++)	{
		var x= String(i+1);
		document.getElementById("day").options[i] = new Option(x,x);
		//inForm.day
		}
	
	for (var i=0; i <31 ; i++)	{
		var d=0;
		d=document.getElementById("day").options[i].value;
		if(d=day){
			document.getElementById("day").options[i].selected=true;
			break;
			}
		}
	
	for (var i=0,j=year; i <t2 ; i++, j--)	{
		var y= String(j);
		document.getElementById("year").options[i] = new Option(y,y);
			
		}
	for(var i=0;i<12;i++)	{
		
		if(i=month)
			{document.getElementById("month").options[i].selected=true;
		break;}
		
		}

}

function populate2(inForm2) {
	var t3=0;
	
	if(document.getElementById("month").options[1].selected)
	
	t3=28;
	else if(document.getElementById("month").options[8].selected||document.getElementById("month").options[3].selected||document.getElementById("month").options[5].selected||document.getElementById("month").options[10].selected)
	t3=30;
	else
	t3=31;
	
	
	for(i=0;i<31;i++){
	document.getElementById("day").options[i]=null;
	}
	
	for (var i=0; i <t3 ; i++)
		{
		var x= String(i+1);
		document.getElementById("day").options[i] = new Option(x);
			
		}
}
/* End Date Field Functions */



function initForm () {
	initCountry('personal');
	initCountry('purchased');
	populate('warrantyform')
}
