function submitForm( formObj )
{
	// loop through all form elements, check for image1_# and image2_#
	
	for ( var i = 0; i < formObj.elements.length; i++ )
	{
		var elementName = formObj.elements[i].name;
		var elementValue = formObj.elements[i].value;
		
		if ( elementName.indexOf( "image1" ) != -1 && elementValue != "" )
		{
			// split elementValue to get the ID value
			var objParts = elementName.split( "_" );
		
			var pathObj = "imagePath1_" + objParts[1];
			
			formObj[ pathObj ].value = elementValue;
		}
	}

	formObj.submit();
}

function submitContactForm( formObj )
{
	// email, telephone, name are required fields
	if ( formObj.name.value == "" )
	{
		alert( "Name is Required." );
		return false;
	}
	if ( formObj.email.value == "" )
	{
		alert( "E-Mail is Required." );
		return false;
	}
	
	if ( !validEmail( formObj.email.value ) )
	{
		alert( "There is invalid syntax in the e-mail address that you entered." );
		return false;
	}

	formObj.submitContact.value = 1;
	formObj.submit();
}

// a very primitive email checker
function validEmail( email )
{
	var arr = email.split("@");
	
	if (arr.length != 2) {
		return false;
	}
	var last = email.lastIndexOf(".");
	var len1 = email.length;
	var abc1 = len1 - last -1;
	
	if (abc1 < 2 || abc1 > 7 || email.indexOf(" ") != -1 ) {
		return false;
	}

	return true;
}

function submitUser( formObj )
{
	formObj.submit();
}

function submitPage( formObj )
{	
	formObj.submit();
}	

function confirmDeleteUser( formObj, userID )
{
	if ( confirm( "Are you sure? This will permanently delete this user's information!" ) )
	{
		formObj.deleteUser.value = userID;
		formObj.submit();
	}
}

function confirmDeletePage( formObj, pageID )
{
	if ( confirm( "Are you sure? This will permanently delete the page and all information!" ) )
	{	
		formObj.deletePageID.value = pageID;
		formObj.submit();
	}
}

function validateChoice( formObj )
{
	if ( formObj.pageID.selectedIndex == 0 )
	{
		alert( "Please choose a page to edit." );
		return false;
	}
	
	formObj.projectChoosePage.value = 1;  // indicates that we are leaving the "project chooser" page
	formObj.submit();
}


function submitProject( formObj )
{
	formObj.path1.value = formObj.image1.value;
	formObj.path2.value = formObj.image2.value;
	formObj.path3.value = formObj.image3.value;
	formObj.path4.value = formObj.image4.value;
	formObj.path5.value = formObj.image5.value;
	formObj.path6.value = formObj.image6.value;
	
	formObj.masterSubmitPage.value = 1;
	
	formObj.submit();
}

function launch(url, options) {
   self.name = "opener2";
   remote = open(url, "remote2", options);
}

// launch a centered popup
function showProjectImage( imgWidth, imgHeight, path )
{
	var popupWidth = imgWidth + 50;
	var popupHeight = imgHeight + 100;	//larger for "close" links at top and bottom
	var leftOffset = ( screen.width - popupWidth ) / 2;
	var topOffset = ( screen.height - popupHeight ) / 2;


	var options = "scrollbars,resizable,width=" + popupWidth + ",height=" + popupHeight + ",top=" + topOffset + ",left=" + leftOffset;

	launch( "../pages/showProjectImage.php?path=" + path, options );
}

