function checkphone(e){
	var goodphone="";
	var phone=String(e.value);
	phone=phone.replace(/[^0-9]/g,'');
	var vlen=phone.length;

	if (phone)
		{

		if (vlen=='10' && !isNaN(phone))
			{
			goodphone="("+phone.slice(0,3)+") "+phone.slice(3,6)+"-"+phone.slice(6);
			e.value=goodphone;
			}
		else
			{
			alert("The phone number you have entered is invalid. Please enter only 10 numbers including the area code.");
			globalvar = e;
			setTimeout("globalvar.focus();", 1);
			setTimeout("globalvar.select();", 1);
			}
		}
	else
		{
		e.value=phone;
		}
}

function checkemail(e){
	var email=String(e.value);
	if (email){
		if(!email.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)) {
			alert("Please enter a valid email address.  Your email address will be used as your login name.");
			globalvar = e;
			setTimeout("globalvar.focus();", 1);
			setTimeout("globalvar.select();", 1);
		}
	}
}

/*Ajax*/

var xmlhttp = false;

//Check if we are using IE.
try 
	{
	//If the Javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
catch (e) 
	{
	//If not, then use the older active x object.
	try 
		{
		//If we are using Internet Explorer.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
	catch (E) 
		{
		//Else we must be using a non-IE browser.
		xmlhttp = false;
		}
	}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
	xmlhttp = new XMLHttpRequest();
	}

function makerequest(serverPage, objID) {
		
	var date = new Date();
	var timestamp = date.getTime();
	url = serverPage + "?time=" +timestamp;

	var obj = document.getElementById(objID);
	xmlhttp.open("GET", url);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(null);
	}

function getdoc(serverPage, id, objID) {
		
	var date = new Date();
	var timestamp = date.getTime();
	url = serverPage + "?timestamp=" + timestamp +"&id=" + id;

	var obj = document.getElementById(objID);
	xmlhttp.open("GET", url);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(null);
	}

function pollvote(serverPage, id, poll_id, objID) {
		
	var date = new Date();
	var timestamp = date.getTime();
	url = serverPage + "?timestamp=" + timestamp +"&id=" + id + "&poll_id=" + poll_id;

	var obj = document.getElementById(objID);
	xmlhttp.open("GET", url);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(null);
	}

function deletephoto(serverPage, gallery, photoid, objID) {
		
	var date = new Date();
	var timestamp = date.getTime();
	url = serverPage + "?timestamp=" + timestamp +"&id=" + gallery + "&photoid=" + photoid;

	var obj = document.getElementById(objID);
	xmlhttp.open("GET", url);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(null);
	}

function viewevent(serverPage, id, objID){

	var date = new Date();
	var timestamp = date.getTime();
	url = serverPage + "?id=" + id + "&timestamp=" + timestamp;

	var obj = document.getElementById(objID);
	obj.style.visibility = "visible";
	xmlhttp.open("GET", url);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(null);
	}

function closeevent(objID){
	
	var obj = document.getElementById(objID);
	obj.style.visibility = "hidden";
	}

/*Form functions must include submitevent, getformvalues, validateevent, trim and process*/
/*getformvalues & trim never change*/

function getformvalues (fobj, valfunc){
	var str = "";
	aok = true;
	var val;
	//Run through a list of all objects contained within the form.
	for(var i = 0; i < fobj.elements.length; i++){
		if(valfunc) {
			if (aok == true){
				val = valfunc (fobj.elements[i].value,fobj.elements[i].name); 
					if (val == false){
						aok = false;
					}
				}
			}
		str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
		}
	//Then return the string values.
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
	}

function trim(inputString){
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces it with one space. If something besides
	// a string is passed in (null, custom object, etc.) then return the input.
	if (typeof inputString != "string") { 
		return inputString; 
		}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") { 
		// Check for spaces at the beginning of the string
	      retValue = retValue.substring(1, retValue.length);
	      ch = retValue.substring(0, 1);
	   	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") { 
		// Check for spaces at the end of the string
	      retValue = retValue.substring(0, retValue.length-1);
	      ch = retValue.substring(retValue.length-1, retValue.length);
	   	}
	while (retValue.indexOf("  ") != -1) { 
		// Note that there are two spaces in the string - look for multiple spaces within the string
	      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
		// Again, there are two spaces in each of the strings
	   	}
	return retValue; 
	// Return the trimmed string back to the user
	} 
	// Ends the "trim" function


var aok;

function submitform (theform, serverPage, objID, valfunc){
	var file = serverPage;
	var str = getformvalues(theform,valfunc);
	//If the validation is ok.
	if (aok == true){
		obj = document.getElementById(objID);
		processform (serverPage, obj, "post", str);
		}
	}

function processform (serverPage, obj, getOrPost, str){
	//Get an XMLHttpRequest object for use.
	//xmlhttp = getxmlhttp ();
	if (getOrPost == "get"){
			xmlhttp.open("GET", serverPage);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById("wrapper").innerHTML = xmlhttp.responseText;
					}
				}
			xmlhttp.send(null);
			} 
		else {
			xmlhttp.open("POST", serverPage, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					obj.innerHTML = xmlhttp.responseText;
					}
				}
			xmlhttp.send(str);
			}
		}

/*Validates Registration*/
function validateregistration (thevalue, thename){
	var nowcont = true;
	if (thename == "fname"){
		if (trim (thevalue) == ""){
			document.getElementById("regerror").innerHTML = "Please enter your first name";
			document.getElementById("registration").fname.focus();
			nowcont = false;
			}
		}
	if (nowcont == true){
		if (thename == "lname"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please enter your last name.";
				document.getElementById("registration").lname.focus();
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "street"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please enter your street address.";
				document.getElementById("registration").street.focus();
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "city"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please enter your city.";
				document.getElementById("registration").city.focus();
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "state"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please choose a state.";
				document.getElementById("registration").state.focus();
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "zip"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please enter your zipcode.";
				document.getElementById("registration").zip.focus();
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "phone"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please enter a phone number.";
				document.getElementById("registration").phone.focus();
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "emailaddr"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please enter an email address.  This will be your login.";
				document.getElementById("registration").emailaddr.focus();
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "userpass"){
			if (trim (thevalue) == ""){
				document.getElementById("regerror").innerHTML = "Please enter a password.";
				document.getElementById("registration").userpass.focus();
				nowcont = false;
				}
			}
		}
	return nowcont;
	}

/*Validates Contact Form*/
function validatecontact (thevalue, thename){
	var nowcont = true;
	if (thename == "fname"){
		if (trim (thevalue) == ""){
			document.getElementById("error").innerHTML = "Please tell us your first name";
			document.getElementById("form").fname.focus();
			document.getElementById("form").fname.style.background = "#FFFFA4";
			nowcont = false;
			}
		}
	if (nowcont == true){
		if (thename == "webcontact"){
			if (trim (thevalue) == ""){
				document.getElementById("error").innerHTML = "Please select a person or group to contact.";
				document.getElementById("form").webcontact.focus();
				document.getElementById("form").webcontact.style.background = "#FFFFA4";
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "lname"){
			if (trim (thevalue) == ""){
				document.getElementById("error").innerHTML = "Please tell us your last name.";
				document.getElementById("form").lname.focus();
				document.getElementById("form").lname.style.background = "#FFFFA4";
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "dphone"){
			if (trim (thevalue) == ""){
				document.getElementById("error").innerHTML = "Please enter a day time phone number.";
				document.getElementById("form").dphone.focus();
				document.getElementById("form").dphone.style.background = "#FFFFA4";
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "contactemail"){
			if (trim (thevalue) == ""){
				document.getElementById("error").innerHTML = "Please enter an email address.";
				document.getElementById("form").contactemail.focus();
				document.getElementById("form").contactemail.style.background = "#FFFFA4";
				nowcont = false;
				}
			}
		}
	if (nowcont == true){
		if (thename == "comments"){
			if (trim (thevalue) == ""){
				document.getElementById("error").innerHTML = "Please enter some information regarding your request.";
				document.getElementById("form").comments.focus();
				document.getElementById("form").comments.style.background = "#FFFFA4";
				nowcont = false;
				}
			}
		}
	return nowcont;
	}

/*Validates Gallery */
function validategallery (thevalue, thename){
	var nowcont = true;
	if (thename == "title"){
		if (trim (thevalue) == ""){
			document.getElementById("error").innerHTML = "Please enter a title for your gallery.";
			document.getElementById("form").title.focus();
			nowcont = false;
			}
		}
	return nowcont;
	}



/*Validates Login*/
function validatelogin (thevalue, thename){
	var nowcont = true;
	if (thename == "loginname"){
		if (trim (thevalue) == ""){
			document.getElementById("loginerror").innerHTML = "Please enter your email address";
			document.getElementById("reglogin").loginname.focus();
			nowcont = false;
			}
		}
	if (nowcont == true){
		if (thename == "loginpass"){
			if (trim (thevalue) == ""){
				document.getElementById("loginerror").innerHTML = "Please enter your password.";
				document.getElementById("reglogin").loginpass.focus();
				nowcont = false;
				}
			}
		}
	return nowcont;
	}

/*Validates Calendar Information*/
function validateevent (thevalue, thename){
	var nowcont = true;
	if (thename == "title"){
		if (trim (thevalue) == ""){
			document.getElementById("error").innerHTML = "You must enter a title for your event";
			document.getElementById("form").title.focus();
			nowcont = false;
			}
		}
	if (nowcont == true){
		if (thename == "event"){
			if (trim (thevalue) == ""){
				document.getElementById("error").innerHTML = "Please enter some information about your event.";
				document.getElementById("form").event.focus();
				nowcont = false;
				}
			}
		}
	return nowcont;
	}










