// JavaScript Document

// used in imageSwap
var prev_image = 0;
var j = 1;


function confirmSubmit(msg)
{
	var agree=confirm(msg);
	if (agree)
		return true ;
	else
		return false ;
}

function memberAction(option, formFrame) 
{
	var set = 0;
	var url;
	
	// get the option
	if(option == 0)
	{
		alert("Please select an action!");
		return false;
	}
	else if(option == -1)
		url = "../scripts/action.php?app=m_invite";
	else if(option == -2)
		url = "../scripts/action.php?app=m_message";
	else if(option == -3)
		url = "../scripts/action.php?app=m_promote";
	else if(option == -4)
		url = "../scripts/action.php?app=l_create";
	else if(option == -5)
		url = "../scripts/action.php?app=b_attend";
	else if(option == -6)
		url = "../scripts/action.php?app=m_certify";
	else
		url = "../scripts/action.php?app=l_add&lid=" + option;

	if(option == -6)
		url = "../scripts/action.php?app=m_certify";
		
	
	// build the link
	for(var i = 0; i < formFrame.length; i++)
	{
		if(formFrame.elements[i].checked == true)
		{
				set = 1;
				url += "&uid"+ i + "=" + formFrame.elements[i].value;
		}
	}

	// make sure at least one member was checked
	if(set == 0)
	{
		alert("Please select at least 1 member!");
		return false;
	}
	
	window.location.href = url;
	
	return;

}

function brainstormAttendance(option) 
{
	// get the option
	if(option == 0)
	{
		alert("Please select an action!");
		return false;
	}
	else
		return true;
}

function listModify(lid) 
{	
	if(lid == 0)
		alert("Please select a list!");
	else
		window.location.href = "lists.php?opt=2&lid=" + lid;
		
	return false;
}


function filterList(option) 
{
	document.l_table.location.href = "_lists_table.php?lid=" + option;
	return;
}

function filterLocation(option) 
{
	document.location.href = "locations.php?locid=" + option;
	return;
}

function filterBrainstormType(option) 
{
	document.b_table.location.href = "table.php?type=" + option;
	return;
}
function filterBrainstormLocation(option) 
{
	document.b_table.location.href = "table.php?location=" + option;
	return;
}

function filterMemberType(option) 
{
	document.m_table.location.href = "table.php?type=" + option;
	return;
}

function filterMemberLocation(option) 
{
	document.m_table.location.href = "table.php?location=" + option;
	return;
}

function validateStep1(form)
{
	if(form.password.value == "")
	{
		alert("The password field is blank.  Please enter a password.");
		form.password.focus();
		return false;
	}
	if(form.password.value != form.password2.value)
	{
		alert("The passwords do not match. Please re-enter your password.");
		form.password.value = "";
		form.password2.value = "";
		form.password.focus();
		return false;
	}
	
	return true;
}

function frmActivate(form)
{
	form.email.focus();
	return;
}

function verifyNDA(form, name)
{
	
	if(form.signature.value == "" || form.signature.value =="Sign your full name here")
	{
		alert("Please sign your full name!");
		form.signature.focus();
		return false;
	}

	return true;
}

function verifyBrainstorm(form)
{
	if(form.type.value == 0)
	{
		alert("You must select a brainstorm type!");
		form.type.focus();
		return false;
	}
	if(form.quota.value == "")
	{
		alert("You must specify the maximum attendance!");
		form.quota.focus();
		return false;
	}
	if(form.topic.value == "")
	{
		alert("You must specify a topic!");
		form.topic.focus();
		return false;
	}
	if(form.client.value == "")
	{
		alert("You must specify a client!");
		form.client.focus();
		return false;
	}
	if(form.month.value == "")
	{
		alert("You must specify a valid 2-digit month!");
		form.month.focus();
		return false;
	}
	if(form.day.value == "")
	{
		alert("You must specify a valid 2-digit day!");
		form.day.focus();
		return false;
	}
	if(form.year.value == "")
	{
		alert("You must specify a valid 2-digit year!");
		form.year.focus();
		return false;
	}
	if(form.hour.value == "")
	{
		alert("You must specify a valid 2-digit hour!");
		form.hour.focus();
		return false;
	}
	if(form.minute.value == "")
	{
		alert("You must specify a valid 2-digit minute!");
		form.minute.focus();
		return false;
	}
	if(form.location.value == "")
	{
		alert("You must specify a location!");
		form.location.focus();
		return false;
	}
	return true;
}

function verifyMember(form)
{
	if(form.type.value == 0)
	{
		alert("You must select a member type!");
		form.type.focus();
		return false;
	}
	if(form.first.value == "")
	{
		alert("You must specify a user first name!");
		form.first.focus();
		return false;
	}
	if(form.last.value == "")
	{
		alert("You must specify a user last name!");
		form.last.focus();
		return false;
	}
	if(form.email.value == "")
	{
		alert("You must specify a user email!");
		form.email.focus();
		return false;
	}
	
	return true;
}

function verifyPassword(form)
{
	if(form.pass1.value == "")
	{
		alert("Please enter a password!");
		form.pass1.value = "";
		form.pass2.value = "";
		form.pass1.focus();
		return false;
	}
	
	if(form.pass1.value != form.pass2.value)
	{
		alert("The passwords do not match. Please re-enter your password");
		form.pass1.value = "";
		form.pass2.value = "";
		form.pass1.focus();
		return false;
	}
	
	return true;
}


function emailerSelect(eid) {
	if(eid == 0)
		window.location = "messages.php?opt=2";
	else
		window.location = "messages.php?opt=2&eid=" + eid;
}

function emailerSelectModify(eid) {
	if(eid == 0)
		window.location = "messages.php?opt=4";
	else
		window.location = "messages.php?opt=4&eid=" + eid;
	
}

function imageSwap(image, number)
{
	for(i = 0; i < number; i++)
	{
		var column = "col" + i;
		document.images[column].src = '../images/blank.gif';
	}
	
	for(i = 0; i < number; i++)
	{
		var column = "col" + i;
		document.images[column].src = '../images/blank.gif';
		
		if(image == i)
		{
			if(prev_image == i && j)
			{
				document.images[column].src = '../images/arrow_up.gif';
				j = 0;
			}
			else
			{
				document.images[column].src = '../images/arrow_down.gif';
				j = 1;
			}
		}
	}
	
	prev_image = image;
}



