window.addEvent('domready', function() {

	if($('circles')) {
		var Max = $$('#circles img').length;
		function rn1toMax() {
			var zerotoMax = Math.floor(Math.random()*Max);
			var random1toMax = zerotoMax + 1;
			return random1toMax;
		}
		// create an array of three random numbers between 1 and 7 
		var threenumbs = new Array();
		var rn1 = rn1toMax();
		threenumbs.push(rn1);
		var rn2 = rn1toMax();
		while(rn2 == rn1) {
			rn2 = rn1toMax();
		}
		threenumbs.push(rn2);
		var rn3 = rn1toMax();
		while(rn3 == rn2 || rn3 == rn1) {
			rn3 = rn1toMax();
		}
		threenumbs.push(rn3);
		// 

		// make those three of the 7 images fade in 
		var circ_counter = 0, bdur=400; fe = new Array();
		threenumbs.each(function(anum) {
			// original effect 
			var anid = 'circle_'+anum;
			var rightpx = circ_counter*145;
			var zind = circ_counter+10;
			bdur=400;
			rightpx = rightpx+20;
			$(anid).setStyles({
				'opacity':'0',
				'right':'-136px',
				'top':'82px',
				'width':'0',
				'height':'0',
				'z-index':zind
			});

			fe[circ_counter] = new Fx.Morph($(anid), {
				duration:bdur,
				wait:false,
				transition: Fx.Transitions.Sine.easeOut
			});
			// 
			circ_counter++;
		});

		(function() { 
		 	fe[0].start({'opacity':'1', 'right':'20px', 'width':'136px', 'height':'136px', 'top':'28px'}).chain(function() {
				fe[1].start({'opacity':'1', 'right':'165px', 'width':'136px', 'height':'136px', 'top':'28px'}).chain(function() {
					fe[2].start({'opacity':'1', 'right':'310px', 'width':'136px', 'height':'136px', 'top':'28px'});
				});
			});
		}).delay(400);

	}
	
	if($('contactform')) {
		if($('contact_reset')) {
			$('contact_reset').addEvent('click', function(e) {
				e.stop();
				if(confirm('Please confirm that you would like to reset the form')) {
					$('contactform').reset();
				}
			});
		}

		function checkcform() {
			var errstr = '';
			var errmsg = "Error - the following fields are missing:\n";
			if(!$('name').get('value')) { errstr += "\nName"; }
			if(!$('organization').get('value')) { errstr += "\nOrganization/Association"; }
			if(!$('address').get('value')) { errstr += "\nAddress"; }
			if(!$('city').get('value')) { errstr += "\nCity"; }
			if(!$('state').get('value')) { errstr += "\nState"; }
			if(!$('zip').get('value')) { errstr += "\nZip code"; }
			if(!$('phone').get('value')) { errstr += "\nPhone"; }
			if(!$('email').get('value')) { errstr += "\nE-mail address"; }
			if(!$('ttc_1').get('checked') && !$('ttc_2').get('checked') && !$('ttc_3').get('checked')) { errstr += "\nThe best time for HSC to call"; }
			if(!$('cc_yes').get('checked') && !$('cc_no').get('checked')) { errstr += "\nAre you currently an HSC client"; }
			if(!$('location').get('value')) { errstr += "\nLocation"; }
			if(!$('howdidyoufind').get('value')) { errstr += "\nHow did you find HSC"; }
			if(!$('message_sales').get('checked') && !$('message_service').get('checked') && !$('message_comment').get('checked')) { errstr += "\nThe topic of your message"; }
			if(!$('form_comments').get('value')) { errstr += "\nYour message or comments"; }

			if(errstr != '') {
				return errmsg+errstr;
			} else {
				return false;
			}
		}

		$('contactform').addEvent('submit', function(e) {
			e.stop();
			var formerrors = checkcform();
			if(formerrors) {
				alert(formerrors);
			} else {
				$('contactform').submit();
			}
		});

	}
});

