
	// make signups scroll
	$(function(){
		var containerElm = $('div.signupList').get();
		var containerHeight = $('div.signupList').height();
		var contentHeight = $('div.signupList table').height();
		var scrollSpeed = (contentHeight - containerHeight) * 100;

		function up(){
			var offset = 0;
			$('div.signupList').animate({scrollTop: offset}, scrollSpeed, 'linear', function(){
				down(); // private method
			});			
		}
		function down(){
			var offset = contentHeight - containerHeight;
			if(offset > 0){
				$('div.signupList').animate({scrollTop: offset}, scrollSpeed, 'linear', function(){
					up(); // private method
				});			
			}
		}

		down();
	});

$(function(){
	// menu hover
	var currentPage;
	var currentPageOn;
	var currentPageOff;
	$('a.menuHover').each(function(index, Element){
		var origSrc = $('img', this).attr('src');
		var onSrc = origSrc.replace('off_', 'on_');
		var offSrc = origSrc.replace('on_', 'off_');
		if(origSrc == onSrc){
			// this is the current page
			currentPage = this;
			currentPageOn = onSrc;
			currentPageOff = offSrc;
		}
		
		$(this).hover(
					  function(){
						  $('img', this).attr('src', onSrc);
						  if(this != currentPage){
							  $('img', currentPage).attr('src', currentPageOff);
						  }
					  },
					  function(){
						  $('img', this).attr('src', origSrc);
						  if(this != currentPage){
							  $('img', currentPage).attr('src', currentPageOn);
						  }
					  }
				);
		
		// preload hover image
		$("<img>").attr("src", onSrc);
		$("<img>").attr("src", offSrc);

	});


});

function checkSignupForm(obj){
	var isError = false;
	var systemMsg = new Array();

	try{
		// make sure the form is complete
		
		var re = new RegExp(/^[^\s]+[\s]+[^\s]+/);
		if(!re.test(trim(obj.fullName.value))){
			isError = true;
			systemMsg.push('You must include your full name. (first and last)');
		}

		var re = new RegExp(/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/);
		obj.phone.value = cleanupPhoneNumber(obj.phone.value);
		if(obj.phone.value == ''){
			isError = true;
			systemMsg.push('Your phone number must be included.');
		}
		else if(obj.country && (obj.country.value == 'USA' || obj.country.value == 'CAN') && !re.test(trim(obj.phone.value))){
			isError = true;
			systemMsg.push('Your phone number must be format like ###-###-####.');
		}
		else if(obj.country && (obj.country.value == 'f03be894-e5a2-4b08-8047-18b7340bca4d' || obj.country.value == '80bd450f-a625-4ee3-97ea-f9a53775d760') && !re.test(trim(obj.phone.value))){
			isError = true;
			systemMsg.push('Your phone number must be format like ###-###-####.');
		}

		if(obj.country && obj.country.value == ''){
			isError = true;
			systemMsg.push('Your country must be included.');
		}


		if(obj.email.value == ''){
			isError = true;
			systemMsg.push('An email address must be included.');
		}
		else if(isEmail(obj.email.value) == false){
			isError = true;
			systemMsg.push('Your email address is invalid.');
		}
		if(obj.country && obj.country.value == ''){
			isError = true;
			systemMsg.push('Your country must be included.');
		}


		// display error message if needed
		if(!isError){
			$('body').append('<div id="pleaseWait" title="Please Wait">Your form is being processed...</div>').find('#pleaseWait').dialog({modal:true});
			return true;
		}
		else if(systemMsg.length > 0){
			alert(systemMsg.join('\n'));
		}
		return false;
	}
	catch(e){
		if(e instanceof TypeError){
			alert("You must fill out the form completely and correctly!");
			alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message);
			return false;
		}
		else if(e instanceof SyntaxError){
			alert("There is an error in the JavaScript code. Please inform the webmaster of this site.");
			return false;
		}
		else if(e instanceof RangeError){
			alert("You must fill out the form completely and correctly!");
			return false;
		}
		else if(e instanceof ReferenceError){
			alert("There is an error in the site code. Please inform the webmaster of this site.");
			return false;
		}
		else{
			alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message);
			return false;
		}
		
	}
	finally{
		//alert("finally");
	}
}


function isEmail(str) {
	var re = new RegExp(/^[\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/);
	return re.test(str);
}

function isRealPhoneNumber(str){
	var prefix = str.substring(0,3);
	if(prefix!='111'&&prefix!='222'&&prefix!='333'&&prefix!='444'&&prefix!='555'&&prefix!='666'&&prefix!='777'&&prefix!='999'){
		var myRegxp = /^([2-9]{1}[0-8]{1}[0-9]{1}[-][2-9]{1}[0-9]{1}[0-9]{1}[-][0-9]{1}[0-9]{1}[0-9]{1}[0-9]{1})$/;
		return myRegxp.test(str);
	}
	else{
		return false;
	}
}

function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}


function cleanupPhoneNumber(phoneNumber){
	var reg = new RegExp("^(1[ .-]*)?[ (]*([2-9][0-9]{2})[) .-]*([0-9]{3})[ .-]*([0-9]{4})$", "i");
	var m = reg.exec(phoneNumber);
	if (m != null) {
		return m[2]+'-'+m[3]+'-'+m[4];
	}
	return phoneNumber;
}


function overlayMessage(title, content){
	var overlayElm = document.getElementById('overlayContainer');
	if(!overlayElm){
		$('body').append('<div id="overlayContainer" title="" style="display:none;"></div>');
		overlayElm = document.getElementById('overlayContainer');
	}
	
	$(overlayElm).attr('title', title);
	$(overlayElm).html(content);
	$(overlayElm).dialog({width: '500px', modal: true, buttons: {'Ok': function() { $(this).dialog("close"); }}});
	$(overlayElm).dialog('open');
}


function encode(str){
	// simple one way encryption (checksum)
	// created: September 30, 2009
	// modified: December 14, 2009
	// author: Jamie Beck <jbeck@terabit.ca>
	
	var l = str.length;
	var i;
	var sum = 0;
	for(i = 0; i < l-1; i++){
		sum = sum + Math.pow(str.charCodeAt(i), i+1);
	}
	return sum;
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name){
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1){
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function popup(pageURL, attr){
	// creates popup window
	// created: December 9, 2009
	// author: Jamie Beck <jbeck@terabit.ca>

	var defaultAttr = {
		height:			400,
		width:			450,
		toolbar:		'no',
		menubar:		'yes',
		scrollbars:		'yes',
		resizable:		'yes',
		location:		'yes',
		directories:	'no',
		status:			'yes'
	};
	
	if(typeof attr == 'undefined'){
		// if not attributes were given create empty attr object
		var attr = {};
	}

	// use default attr for any not explicitly given
	for(i in defaultAttr){
		if(typeof attr[i] == 'undefined'){
			attr[i] = defaultAttr[i];
		}
	}

	// turn attributes into usable string
	var attrStr = '';
	for(i in attr){
		attrStr = attrStr + ',' + i + '=' + attr[i];
	}
	
	// launch the window
	thewindow = window.open(pageURL, "_blank", attrStr);
}