
// should we complain if the file upload value isn't set?
var check_upload_file = true;

// URL to redirect to if their Zip's invalid
var bad_zip_url = 'furniture_nomatch.html';

var city_zips = new Object;

// each city's property is an array of integers
city_zips['palmsprings'] = new Array(92262, 92263, 92292, 92264, 92234, 92258, 92235, 92240, 92270, 92282, 92276, 92241, 92549, 92255, 92261, 92260, 92230, 92211, 92561, 92210, 92256, 92203, 92253, 92201, 92286, 92220, 92202, 92539, 92544, 92284, 92583, 92236, 92581, 92268, 92546, 92223, 92543, 92582, 92252, 92339, 92545, 92536, 92305, 92320, 92399, 92552, 92386, 92285, 92567, 92596, 92554, 92548, 92314, 92556, 92315, 92359, 92086, 92555, 92277, 92585, 92333, 92274, 92254, 92373, 92571, 92586, 92374, 92592, 92551, 92584, 92572, 92599, 92375, 92591, 92563, 92553, 92278, 92382, 92060, 92341, 92557, 92587, 92518, 92318, 92589, 92593, 92346, 92354, 92564, 92350, 92357, 92570, 92066, 92369, 92061, 92595, 92059, 92508, 92408, 92562, 92385, 92590, 92313, 92532, 92321, 92326, 92404, 92507, 92401, 92531, 92352, 92410, 92324, 92378, 92402, 92406, 92412, 92413, 92414, 92415, 92418, 92420, 92423, 92424, 92427, 92070, 92530, 92403, 92405, 92391, 92506, 92317, 92004, 92411, 92082, 92501, 92356, 92502, 92513, 92514, 92515, 92516, 92517, 92519, 92521, 92522, 92028, 92504, 92325, 92275, 92316, 92376, 92088, 92407, 92503, 92322, 92509, 92377, 92003, 92334, 92883, 92505, 92335, 92337, 92308, 92336, 92027, 92026, 92036, 92881, 92877, 92879, 91752, 92084, 92065, 92860, 92030, 92033, 92046, 92340, 92878, 92025, 91739, 92345, 92085);

city_zips['dallas'] = new Array(75202, 75245, 75262, 75263, 75398, 75270, 75267, 75342, 75370, 75221, 75222, 75250, 75258, 75261, 75264, 75265, 75266, 75275, 75277, 75283, 75284, 75285, 75286, 75301, 75303, 75310, 75312, 75313, 75315, 75320, 75323, 75326, 75336, 75339, 75346, 75353, 75354, 75355, 75356, 75357, 75359, 75363, 75364, 75367, 75368, 75369, 75371, 75372, 75373, 75374, 75376, 75378, 75379, 75380, 75381, 75382, 75387, 75388, 75389, 75390, 75391, 75392, 75393, 75394, 75395, 75396, 75397, 75295, 75242, 75201, 75207, 75260, 75204, 75226, 75246, 75219, 75203, 75215, 75360, 75386, 75208, 75223, 75210, 75206, 75212, 75205, 75235, 75214, 75209, 75216, 75224, 75247, 75211, 75225, 75233, 75239, 75227, 75220, 75231, 75218, 75241, 75228, 75232, 75230, 75217, 75238, 75229, 75014, 75015, 75016, 75017, 75237, 75060, 75236, 75061, 75251, 75243, 75244, 75150, 75039, 75116, 75062, 75138, 75141, 75037, 75240, 75234, 75134, 75053, 75054, 75254, 75149, 75041, 75180, 75137, 75185, 75187, 75042, 75051, 75050, 75038, 75083, 75085, 75001, 75115, 75043, 75081, 75249, 75011, 75248, 75045, 75046, 75047, 75049, 75146, 75006, 75123, 75253, 75063, 75080, 75182, 75040, 75172, 76155, 75052, 75181, 75044, 75252, 75287, 75104, 75106, 76006, 75030, 75007, 76011, 75019, 76010, 75088, 75082, 76039, 75099, 76040, 75075, 76014, 75154, 75093, 75026, 75086, 76003, 76004, 76005, 76007, 76019, 76094, 76096, 75089, 75010, 75048, 76018, 75008, 75074, 75159, 75125, 76099, 76012, 76051, 75023, 75094, 76002, 76021, 76095, 76022, 76015, 75126, 76013, 75067, 75024, 76034, 75056, 75029, 75025, 75057, 76120, 75032, 76053, 76001, 76054, 75098, 76017, 76092, 75028, 75087, 76065, 76016, 75114, 75013, 75027, 76063, 75002, 75022, 76112, 75035, 76118, 76180, 75077, 75034, 75152, 76060, 75165, 75168, 76148, 76103, 75132, 76117, 75065, 75166, 76105, 76119, 76248, 76244, 76061, 75167, 76262, 75068, 76137, 76111, 76299, 75173, 76140, 76084, 75157, 75160, 76104, 76101, 76113, 76121, 76122, 76124, 76129, 76130, 76136, 76147, 76150, 76161, 76162, 76163, 76164, 76178, 76181, 76182, 76185, 76191, 76192, 76193, 76195, 76196, 76197, 76198, 76199, 76102, 75121, 76226, 75070, 75407, 75069, 75189, 76110, 76205, 76115, 76177, 75078, 76106, 75071, 76134, 76131, 75142, 76208, 75158, 75119, 75120, 76028, 76109, 76107, 76097, 76209, 76210, 76133, 76114, 76052, 75164, 76009, 76123, 76064, 76202, 76203, 76204, 76206, 76127, 76247, 76179, 76227, 75101, 75161, 76201, 76132, 76036, 75454, 76041, 76116, 75118, 76135, 75442, 75009, 76207, 75135, 76108, 76623, 76259, 75097, 76059, 76126, 76058, 76050, 76651, 76249, 75458, 76071, 75155, 76258, 75409, 75474, 76098, 76078, 76020, 75424, 75105, 75485, 76033, 75143, 76266, 76031, 75402, 75058, 75169, 75495, 76670, 75403, 75404, 76626, 76055, 75401, 76044, 76271, 76008, 75102, 75423, 76636, 76023, 76641, 76666, 75151, 75453, 76035, 76093, 76628, 75147, 76272, 75459, 75153, 76267, 75110, 75452, 75490, 76233, 76082, 75472, 75489, 76650, 75117, 75491, 76234, 76087, 76645, 75422, 76631, 75103, 76086, 75144, 75124, 75109, 76085, 76627, 76073, 76049, 75475, 75163, 76268, 76246, 75413, 76679, 75496, 76660, 75127, 76238);

city_zips['wichita'] = new Array(67202, 67201, 67251, 67256, 67257, 67259, 67260, 67275, 67277, 67278, 67276, 67214, 67211, 67203, 67213, 67208, 67218, 67217, 67216, 67204, 67210, 67220, 67219, 67212, 67207, 67206, 67221, 67209, 67205, 67215, 67226, 67233, 67067, 67235, 67230, 67060, 67101, 67055, 67037, 67232, 67236, 67228, 67227, 67223, 67147, 67002, 67231, 67030, 67052, 67133, 67026, 67017, 67110, 67120, 67016, 67135, 67001, 67149, 67144, 67010, 67050, 67013, 67108, 67039, 67154, 67146, 67056, 67025, 67123, 67114, 67131, 67031, 67117, 67041, 67042, 67106, 67020, 67543, 67152, 67119, 67151, 67103, 67008, 67062, 67118, 67111, 67074, 67105, 66840, 67156, 66866, 67570, 67107, 67004, 67522, 67053, 67019, 67036, 67585, 67501, 67505, 67051, 67072, 67504, 67128, 67132, 67068, 67140, 67502, 66842, 66851, 67012, 67023, 67546, 67049, 67022, 67566, 67005, 67063, 67058, 67428, 67073, 66843, 67514, 67443, 67038, 66861, 67460, 67142, 67122, 67018, 67561, 74632, 67510, 67003, 67102, 66862, 67346, 74647, 67159, 67491, 67438, 67045, 67568, 66858, 67035, 67579, 67009, 67483, 67476, 66850);

city_zips['chattanooga'] = new Array(37401, 37422, 37450, 37424, 37414, 37402, 37403, 37408, 37404, 37405, 37410, 37409, 37407, 37406, 37419, 37350, 37411, 37351, 37415, 37412, 30741, 30750, 30742, 37416, 37377, 30725, 37421, 30757, 37343, 30726, 37396, 37340, 30736, 37363, 37315, 30707, 37397, 37341, 30752, 37384, 37302, 37347, 37379, 30739, 37353, 30755, 35958, 30738, 37374, 30756, 30710, 35979, 37304, 37380, 30728, 30740, 37327, 35740, 37311, 37320, 37364, 37373, 30720, 37365, 30719, 30722, 35966, 37323, 30721, 37312, 37308, 37336, 37338, 37339, 37387, 35981, 37313, 30711, 37356, 37362, 35772, 37316, 30751, 30753, 37310, 30708, 37372, 37376, 37361, 30724, 30731, 37321, 37375, 37366, 37305, 30746, 30705, 37309, 35984, 35978, 35765, 35989, 37301, 30735, 30747, 37307, 37318, 35746, 37370, 37367, 35752, 30105, 37322, 30703, 37332, 37324, 35988, 37325, 30701, 37342, 38585, 35744, 37394, 30730, 30733, 37369, 30732, 37303, 37383, 37398, 35968, 37331, 35986, 35967, 37330, 37371, 35768, 30734, 37111, 37395, 30541, 37378, 37306, 30172, 35973, 37357, 35745, 35771, 30103, 30555, 37110, 37381, 38581, 37317, 37382, 37349, 37326, 35769, 30165, 38550, 37329, 35971, 37826, 37391, 30540, 37355, 30539, 30149, 35766, 37345, 30139, 30129, 30162, 30164, 38579, 30522, 37388, 30161, 37389, 38559, 35774, 37337, 37333, 37880, 35751, 30513, 30175, 30163, 35959, 30171, 30559, 35776, 30145, 35963, 35755, 38587, 37328, 37314, 37360);

city_zips['grandrapids'] = new Array(49503, 49501, 49502, 49510, 49514, 49516, 49518, 49523, 49530, 49550, 49555, 49560, 49588, 49515, 49599, 49504, 49507, 49506, 49505, 49509, 49525, 49544, 49508, 49546, 49468, 49548, 49321, 49512, 49418, 49429, 49306, 49355, 49356, 49357, 49301, 49428, 49435, 49315, 49351, 49341, 49426, 49430, 49316, 49427, 49317, 49345, 49401, 49403, 49302, 49335, 49331, 49404, 49323, 49314, 49319, 49330, 49464, 49348, 49318, 49333, 48815, 49325, 49451, 48809, 49448, 48881, 49311, 49303, 49328, 48887, 49343, 49460, 48838, 49326, 49424, 49419, 49422, 49344, 49423, 49415, 49339, 49327, 49417, 49456, 48865, 49347, 49058, 48849, 49070, 49409, 48846, 49035, 49434, 49322, 48885, 49329, 49010, 48897, 49337, 49442, 49444, 48834, 49453, 49046, 49080, 49441, 49078, 49443, 49440, 48884, 49406, 48870, 49408, 48851, 48888, 48890, 48860, 49073, 49412, 49413, 49445, 49050, 49457, 49336, 48875, 48850, 49450, 49060, 49096, 49425, 48861, 48886, 48852, 48873, 49083, 49055, 48845, 49416, 49349, 49062, 48818, 48894, 48811, 49026, 48829, 49004, 49056, 49020, 49063, 49461, 49346, 49012, 48812, 49007, 48835, 48822, 49006, 49048, 49003, 49005, 49019, 49016, 49041, 49021, 49463, 49001, 49027, 49009, 48891, 49017, 49053, 49008, 48837, 49437, 49421, 49077, 49074, 49090, 48889, 49310, 49452, 48856, 48853, 48830, 49332, 48813, 49018, 49071, 49015, 49312, 49013, 48871, 48877, 49307, 49024, 48876, 49002, 49014, 49079, 49076, 49034, 49081, 49340, 49342, 48832, 48896, 48917, 48879, 48820, 49088, 49309, 49446, 49064, 48874, 49338, 49043, 48821, 49320, 49455, 48906, 48915, 49065, 49033, 48801, 48847, 49459, 49051, 48802, 48924, 48951, 48901, 48909, 48913, 48916, 48918, 48919, 48921, 48922, 48929, 48930, 48937, 48950, 48956, 48980, 48933, 48908, 49087, 48833, 48911, 49057, 48910, 48893, 49097, 49069, 49305, 48912, 49068, 48827, 48806);

city_zips['hartford'] = new Array('06103', '06115', '06183', '06152', '06123', '06126', '06127', '06129', '06131', '06132', '06134', '06140', '06141', '06142', '06143', '06144', '06145', '06146', '06147', '06150', '06151', '06153', '06154', '06155', '06156', '06160', '06161', '06167', '06176', '06180', '06102', '06120', '06101', '06105', '06106', '06114', '06133', '06199', '06104', '06112', '06108', '06138', '06119', '06128', '06118', '06110', '06117', '06107', '06109', '06002', '06006', '06111', '06095', '06033', '06028', '06067', '06074', '06040', '06041', '06045', '06053', '06051', '06032', '06025', '06030', '06034', '06089', '06050', '06073', '06064', '06001', '06052', '06088', '06070', '06416', '06081', '06023', '06087', '06096', '06085', '06037', '06092', '06062', '06066', '06016', '06026', '06019', '06043', '06480', '06022', '06020', '06013', '06447', '06049', '06459', '06010', '06489', '06457', '06035', '06083', '06029', '06080', '06248', '06078', '06414', '06011', '06232', '06090', '06424', '06481', '06456', '06082', '06137', '06061', '06450', '06454', '06059', '06084', '06479', '06455', '06451', '06238', '06781', '06072', '06093', '06467', '06057', '06786', '06231', '06063', '06474', '06060', '06251', '06444', '06071', '06716', '06237', '06027', '06265', '01106', '01077', '06791', '06782', '01030', '06422', '01001', '06441', '06268', '06469', '06410', '06408', '06411', '06269', '01116', '06065', '06787', '06495', '01028', '06279', '06415', '06705', '06492', '01108', '06494', '06704', '06091', '06778', '06098', '06790', '06493', '01105', '06438', '06710', '01101', '01102', '01111', '01114', '01115', '01133', '01138', '01139', '01199', '01152', '01144', '01103', '01090', '01118', '01089', '06702', '06712', '06706', '06226', '06701', '06703', '06720', '06721', '06722', '06723', '06724', '06725', '06726', '06749', '06779', '06250', '01036', '06249', '01128', '01107', '06423', '06075', '01109', '06708', '01086', '06076', '06094', '06795', '01085', '01104', '06472', '01034', '01129', '01119', '06077', '01014', '01021', '06412', '06278', '06770', '06419', '06518', '06266', '01013', '01095', '06256', '06280', '06439', '06336', '06759', '06762', '01151', '06763', '06473', '01020', '01057', '06751', '01071', '01097', '06235', '06021', '06420', '06417', '06758', '06254', '06524', '06750', '06756', '06334', '01056', '06264', '01040', '01022', '01041', '06471', '01081', '06403', '06058', '06798', '06517', '06437', '06514', '06242', '01008', '06442', '06409', '06247', '01073', '06389', '06426', '01255', '06370', '06443', '06350', '01075', '01080', '06330', '06513', '01521', '06793', '06478', '06282', '01069', '06525', '06483', '06511', '01079', '06413', '06515', '01029', '06353', '06753', '06501', '06502', '06503', '06505', '06506', '06507', '06508', '06509', '06520', '06521', '06530', '06531', '06532', '06533', '06534', '06535', '06536', '06537', '06538', '06540', '06510', '06405', '01010', '06794', '01033', '06504', '06488', '06383', '06498', '06777', '06024', '06796', '01027', '06331', '06230', '06380', '06371', '01009', '06754', '06519', '06512', '06360', '06783', '06333', '06401', '01259', '06382', '06031', '06487', '06475', '06259', '06234', '01253', '06018', '06418', '06516', '01244', '06491', '06281', '01518', '01050', '06258', '06351', '01007', '01092', '01566', '06477', '06375', '01062', '06482', '01060', '01061', '01063', '06267', '01083', '01222', '01550', '06335', '06244', '01011', '06357', '06376', '06752', '06374', '06387', '06484', '01245', '06332', '06385', '06785', '06263', '06776', '06757', '01053', '06365', '01082', '06386', '06404', '01035', '06468', '06320', '06239', '06069', '06079', '06039', '06262', '06245', '06354', '01264', '06470', '06260', '01585', '06339', '06755', '01506', '01038', '06068', '06349', '06440', '06246', '01257', '06241', '01039', '06233', '01004', '01059', '06460', '01003', '06255', '06804', '01088', '01002', '06337', '01223', '01571', '06340', '01084', '01243', '01508', '01012', '06384', '06377', '01507', '01515', '06784', '01066', '06243', '06614', '06611', '06372', '01096', '06277', '01509', '01230', '06497', '06373', '12546', '12592', '01098', '06355', '12501', '01570', '06801', '01535', '01031', '06650', '06388', '01258', '01093', '12594', '01238', '06610', '06359', '06876', '01260', '06812', '12522', '11957', '06615', '11939', '06606', '01531', '06811', '01375', '06612', '06608', '06813', '06814', '06816', '06817', '06810', '06607', '01540', '02827', '01562', '01032', '01262', '11944', '01037', '06378', '06875', '01094', '01373', '06604', '01263', '01537', '01242', '06390', '06602', '02825', '01252', '01542', '06432', '06896', '01236', '01229', '12564', '06601', '06673', '06699', '01026', '02873', '01054', '06605', '12503', '12563', '12517', '11965', '06379', '11971', '02833', '01524', '12593', '02814', '01235', '02859', '01341', '01072', '01240', '12516', '02824', '01068', '06430', '02804', '11958', '02815', '12545', '11964', '02832', '01074', '01501', '06883', '01266', '01611', '01330', '01355', '01516', '01526', '02817', '12570', '06829', '12506', '01586', '06431', '11935', '01070', '02891', '06877', '01005', '12581', '12567', '10509', '01351', '01342', '01590', '06490', '12585', '01612', '11952', '02898', '01603', '01226', '12529', '02808', '02857', '06879', '12531', '01366', '01270', '11956', '02858', '02830', '02839', '01254', '01227', '01602', '01347', '02894', '01607', '01527', '12017', '12502', '02826', '01379', '01202', '01203', '01610', '06897', '06436', '06880', '12540', '01338', '06881', '06888', '06889', '01543', '01201', '11948', '02829', '02812', '01609', '01608', '01601', '01613', '01614', '01615', '01653', '01654', '01655', '01349', '12582', '11963', '12510', '02831', '10512', '12514', '01588', '01302', '11792', '11931', '02822', '02816', '10590', '12578', '11947', '01604', '10560', '11970', '01569', '01538', '12521', '01525', '11786', '12165', '10597', '11778', '11933', '06851', '01560', '01370', '02875', '01605', '01224', '01301', '02823', '11901', '01520', '02828', '11789', '12569', '12029', '02813', '02876', '01522', '01376', '02836', '01606', '10519', '06852', '06856', '06857', '06858', '06859', '06860', '01519', '01534', '11764', '11937', '10518', '02892', '01536', '12533', '01380', '01529', '06850', '06855', '01344', '01256', '02896', '02893', '01225', '10578', '02921', '12565');








// form reference is sole parameter
function validate(f) {

	// validate zip as soon as possible -- if they're out of range,
	// don't frustrate them with unnecessary details
	var event_city_index = f.event_city.selectedIndex;
	var event_city_value = f.event_city[event_city_index].value;
	if (event_city_value == null || event_city_value == '') {
		alert("You must let us know which city's event you wish to attend");
		return false;
	}

	var zip = f.zip.value;
	if (zip.search(/^\d\d\d\d\d$/) < 0) {
		alert("Please enter your 5-digit zip code");
		f.zip.focus();
		f.zip.select();
		return false;
	}


	// look for user's zip in city's list
	var zips = city_zips[event_city_value];
	var zip_ok = false;
	for (var j=0; j<zips.length; j++) {
		if (zip == zips[j]) {
			zip_ok = true;
			break;
		}
	}
	if (! zip_ok) {
		//var city_name = f.event_city[event_city_index].text;
		//alert("Sorry.  Your zip code doesn't fall within 50 miles of " + city_name);
		// send them to the sorry page
		location.href = bad_zip_url;
		return false;
	}


	var required = new Array('first_name','last_name','address',
		'city','state','zip','phone','email','confirm_email','description');
	var empty_fields = new Array();
	for (var i=0; i<required.length; i++) {
		if (f[required[i]].value.length < 1) {
			empty_fields[empty_fields.length] = required[i].replace(/_/g, " ");
		}
	}
	if (empty_fields.length > 0) {
		alert("You must fill out these required fields:\n * " +
			empty_fields.join("\n * "));
		return false;
	}


	// make sure we get at least 10 digits
	var phone_temp = f.phone.value.replace(/\D/g,"");
	if (phone_temp.search(/\d\d\d\d\d\d\d\d\d\d/) < 0) {
		alert("A valid phone number with area code is required to enter.");
		f.phone.focus();
		f.phone.select();
		return false;
	}


	if ((f.email.value.search(/@/) < 0) || 
		(f.email.value.search(/@.*@/) >= 0) ||
		(f.email.value.search(/.@.+\.\w+/) < 0)
		){
		alert("Your e-mail address is invalid");
		f.email.focus();
		f.email.select();
		return false;
	}

	if (f.email.value != f.confirm_email.value) {
		alert("Your two e-mail addresses don't match.\nPlease double-check them.");
		f.email.focus();
		f.email.select();
		return false;
	}

	if (check_upload_file && (f.pic1.value == null || f.pic1.value == '')) {
		// don't ask twice;  this might be undefined because of browser security
		check_upload_file = false;
		alert("Did you choose the first photograph to upload?");
		f.pic1.focus();
		f.pic1.select();
		return false;
	}

	// if we make it here, things look ok
//	alert("Everything checks out");return false;
	return true;
}



