// JavaScript Document
function toggle_display(id) {
	var disp = document.getElementById(id).style.display;
	if (disp == 'none') {
		disp = 'block';	
	} else {
		disp = 'none';
	}
}
function validate_required(field)
{
	with (field)
	{
		if (value==null||value=="")
		{
			return false;
		} else {
			field.focus();
			return true;
		}
	}
}
function validate_expression(field, expr)
{
	var ex = '';
	switch (expr) {
		case 'alpha':
			ex = /^[a-zA-Z ]+$/;
			break;
		case 'number':
			ex  = /^[0-9]+$/;
			break;
		case 'alphanum':		
			ex = /^[0-9a-zA-Z ]+$/;
			break;
		case 'email':
			ex = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;	
			break;
		default: // alpha
			ex = /^[a-zA-Z ]+$/;
			break;
	}

	var val = field.value.replace(/ /,'');
	if (val.match(ex)) {
		return true;	
	} else {
		field.focus();
		return false;
	}
}

function compare_values(field_a, field_b) {
	if (field_a.value == field_b.value) {
		return true;
	} else {
		field_a.focus();
		return false;
	}
}


function confirm_delete(obj_name, id, page) {
	if (confirm("Are you sure you want to delete " + obj_name + "?")) {
		window.location.href = page + "?id=" + id + "&action=remove";
	}
}

function detect_ie() {
	var ver = 0;
	var msg = '';
	var ua = navigator.userAgent;
	var av = navigator.appVersion;
	if (ua != null)
	{
		if (ua.indexOf("MSIE") != -1)
		{
			if (av.indexOf("MSIE")!=-1){
				var temp=av.split("MSIE");
				ver=parseFloat(temp[1]);
			}
		}
	}
	return ver;
}
function img_swap(elem, img) {
	document.getElementById(elem).src = img;
}

function open_eclub()
{
	//window.open('./join.php', 'Join', 'width=375,height=200,status=0,toolbar=0,location=0,menubar=0,resizable=0,scrollbars=0');
	window.open('https://invitesystems.e2ma.net/app/view:Join/signupId:41053', 'signup', 'menubar=no, location=no, toolbar=no, scrollbars=yes, height=500'); 
	return false;
}

function validate_contactform()
{
	var retval = true;
	var msg = '';
	var email = document.getElementById('contactemail');
	var name = document.getElementById('contactname');
	if(!validate_required(eml))
	{
		retval = false;
		document.getElementById('contactemail').focus();
		msg = msg + 'Please enter your email address before proceeding.';		
	}
	if(!validate_expression(eml, 'email'))
	{
		retval = false;
		document.getElementById('contactemail').focus();
		msg = msg + 'Please enter a valid email address.';		
	}
	if(!validate_expression(name, 'alphanum'))
	{
		retval = false;
		document.getElementById('contactname').focus();
		msg = msg + 'Invalid entry.  Please re-enter the contents of the Name field.';
	}
	if(msg.length > 1)
	{
		alert(msg);
	}
	
	return retval;
}

function validate_requestform()
{
	var retval = true;
	var msg = '';
	var email = document.getElementById('contactemail');
	var name = document.getElementById('contactname');
	if(!validate_required(eml))
	{
		retval = false;
		document.getElementById('contactemail').focus();
		msg = msg + 'Please enter your email address before proceeding.';		
	}
	if(!validate_expression(eml, 'email'))
	{
		retval = false;
		document.getElementById('contactemail').focus();
		msg = msg + 'Please enter a valid email address.';		
	}
	if(!validate_expression(name, 'alphanum'))
	{
		retval = false;
		document.getElementById('contactname').focus();
		msg = msg + 'Invalid entry.  Please re-enter the contents of the Name field.';
	}
	if(msg.length > 1)
	{
		alert(msg);
	}
	
	return retval;
}

function validate_joinform()
{
	var pass = true;
	var msg = '';
	var eml = document.getElementById('email_address');
	var fnm = document.getElementById('full_name');
	if(!validate_required(eml))
	{
		pass = false;
		document.getElementById('email_address').focus();
		msg = msg + 'Please enter your email address before proceeding.';		
	}
	if(!validate_expression(eml, 'email'))
	{
		pass = false;
		document.getElementById('email_address').focus();
		msg = msg + 'Please enter a valid email address.';		
	}
	if(!validate_expression(fnm, 'alphanum'))
	{
		pass = false;
		document.getElementById('full_name').focus();
		msg = msg + 'Invalid entry.  Please re-enter or remove the contents of the Full Name field.';
	}
	document.getElementById('msg').innerHTML = msg;
	document.getElementById('msg').style.display = 'block';
	
	return pass;
}

/* BEGIN GALLERY FUNCTIONS */
function showPhoto(img, altText) {
	var tmp = document.createElement("img");
	tmp.id = 'galleryPhoto';
	tmp.src = '/photos-page/' + img;
	tmp.alt = altText;
	document.getElementById('photoWindow').appendChild(tmp);
	document.getElementById('photo-wrapper').className = 'photoVis';
	document.getElementById('photo-container').className = 'containerVis';
}
function hidePhoto() {
	oldImg = document.getElementById('galleryPhoto');
	document.getElementById('photoWindow').removeChild(oldImg);
	document.getElementById('photo-wrapper').className = 'photoNoVis';
	document.getElementById('photo-container').className = 'containerNoVis';
}
/* END GALLERY FUNCTIONS */

