function getPhotoName(inStr) {
	var ins_words = inStr.split(/\s/) // remove leading articles
		var firstword = ins_words[0].toLowerCase()
		if (firstword=="a" || firstword=="an" || firstword=="the") {
			inStr = ins_words.slice(1).join("");
		}
	inStr=removeSpaces(inStr);	// remove spaces
	var ins_array=inStr.split(":"); // stop at a colon
		inStr=ins_array[0];
	inStr=removePunctuation(inStr);	// remove punctuation
	inStr=inStr.toLowerCase(); // lowercase
	inStr = inStr + ".jpg"; // add presumed .jpg
	return inStr;
}

function openEventDetail(objAnchor) {
	var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,resizable=1,scrollbars=1,width=500,height=300';
	var vUrl=objAnchor.getAttribute('href');
	var features = _POPUP_FEATURES
	var theWindow = window.open(vUrl, "ifspop", features);
	theWindow.focus();
	return theWindow;
}

function openSlideshow() {
	var vUrl = "_slideviewer.php";
	var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,resizable=1,scrollbars=1,width=660,height=660';
	var features = _POPUP_FEATURES
	var theWindow = window.open(vUrl, "ifspop", features);
	theWindow.focus();
	return theWindow;
}

function openBrakhage() {
	var vUrl = "brakhage_films.html";
	var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,resizable=1,scrollbars=1,width=550,height=450';
	var features = _POPUP_FEATURES
	var theWindow = window.open(vUrl, "ifspop", features);
	theWindow.focus();
	return theWindow;
}

function removeSpaces(inStr) {
	return inStr.replace(/\s/g,"");
}

function removePunctuation(inStr) {
	return inStr.replace(/\W/g,"");	// \W means NOT(0-9, a-z, or A-Z)
}

function trim (inStr) {
	var whiteSpace = "~ \n\t";
		while (  whiteSpace.indexOf(inStr.substr(0,1)) > 0  ) {
			inStr = inStr.substr(1, inStr.length-1);
		}
		while (  whiteSpace.indexOf(inStr.substr(inStr.length-1,1)) > 0) {
			inStr = inStr.substr(0, inStr.length-1);
		}
	return inStr;
}

// put this part in a separate file ///////////////////////////////////////////////////////

// define regular expressions & errors

// e-mail
	// start with 1 or more characters
	// then @
	// then 1 or more characters
	// and end with . and 2 or more characters
	
	reEmail = /^\w+@\w+(\.\w{2,})$/;
	reEmail = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	errEmail = "E-mail address appears to be the wrong format";

// password
	// 7 or more characters
	rePassword = /\w{7,}/;
	errPassword = "Password must be 7 or more alphanumeric characters";

// address
	// 1 or more characters (e.g., cannot be blank)
	reAddress = /\w+/;	
	errAddress = "Address cannot be blank";
	
// city
	// 1 or more characters (e.g., cannot be blank)
	reCity = /\w+/;	
	errCity = "City cannot be blank";

// Country
	// any number of characters, but not a "-" (which indicates -none-)
	reCountry = /^[^\-]/;
	errCountry = "You must choose a Country";
	
// Credit card
	// 4 characters, then optional space, then 4, opt space, 4, spc, 4
	reCreditCard = /^\d{4}\s*\d{4}\s*\d{4}(\s*\d{4})$/;
	errCreditCard = "Credit card must consist of 16 digits (spaces optional)";
	
// Generic can't be blank
	// 1 or more characters (e.g., cannot be blank)
	reGenericBlank = /\w+/;	

// Generic integer
	// must be numeric
	// i.e., consist only of numbers, not be blank
	reGenericInteger = /^[1234567890]+$/;

// Generic selection
	// any number of characters, but not a "-" (which indicates -none-)
	reGenericSelection = /^[^\-]/;

// Language (for platform/language dropdowns)
	// any number of characters, but not a "-" (which indicates -none-)
	reLanguage = /^[^\-]/;
	errLanguage = "You must select a language";

// name
	// 1 or more characters (e.g., cannot be blank)
	reName = /\w+/;	
	errName = "Name cannot be blank";
	
// password
	// 7 or more characters
	rePassword = /\w{7,}/;
	errPassword = "Password must be 7 or more alphanumeric characters";

// Phone
	// must be 7 or more numeric characters, dots, dashes, and spaces also okay
	rePhoneNumber = /[1234567890\(\)\-\.\s]{7,}/;
	errPhoneNumber = "Phone numbers must include area codes and can only contain numbers, dashes, dots, spaces, and parentheses.";

// Platform
	// any number of characters, but not a "-" (which indicates -none-)
	rePlatform = /^[^\-]/;
	errPlatform = "You must select a platform";

// State/province
	// must be 2 upper case characters
	reStateProvince = /[A-Z]{2}/;
	errStateProvince = "You must choose a state or province";
	
// Zip/postal codes
	// could write rules for us, but what about Canada?
	// instead, for now, just say can't be blank
	// 1 or more characters (e.g., cannot be blank)
	reZipPostal = /\w+/;	
	errZipPostal = "ZIP/postal code cannot be blank";

	


function matchPattern (strText, regExp) {
	if ( regExp.test(strText)==true ) {
		return true;
	} else {
		return false;
	}
}

function validateField (txtField, reTest, objLabel, txtError) {
	if ( !(matchPattern (txtField, reTest)) ) { 
		errMsg += errNum + ". " + txtError + "\n";
		errNum++;
		objLabel.className = "errorHighlight";
	} else {
		objLabel.className = "noError";
	}
}


