<!--
/************************************************************************
 * Ryneezy PhoSheezy                                                    *
 * preprocess.js                                                        *
 *                                                                      *
 * (c) 2003 Ryan Samiley                                                *
 * http://www.ryneezy.net                                               *
 *                                                                      *
 * This file is part of PhoSheezy.                                      *
 *                                                                      *
 * PhoSheezy is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by *
 * the Free Software Foundation; either version 2 of the License, or    *
 * (at your option) any later version.                                  *
 *                                                                      *
 * Phosheezy is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 * GNU General Public License for more details.                         *
 *                                                                      *
 * You should have received a copy of the GNU General Public License    *
 * along with PhoSheezy; if not, write to the Free Software Foundation, *
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA       *
 ************************************************************************/

// Calculates the SHA-1 message digest of the password entered by the user.
function processLogin(form)
{
		var password = form.password.value; // Get the user input
		
		// Display an error message when the user does not enter anything
		if(password == '')
		{
			alert("You must enter a password to login.\n\nPlease try again.");
			
			return false;
		}
		
		form.password.value = hex_sha1(password); // Calculate the message digest on valid input
		
		return true;
}

// Makes sure search field is not empty
function preprocessSearch(form)
{
	var query = form.query.value;
	
	// Search field is empty so display an error message
	if(query == '')
	{
		alert("You did not enter a search query.\nPlease try agian.");
		
		return false;
	}
	if(query == 0)
	{
		alert("You did not enter a search query.\nPlease try agian.");
		
		return false;
	}
	
	return true;
}

function preprocessEditCaption(form)
{
	var caption = form.caption.value;
	var caption2 = form.caption.value.length;
	
	if(caption == '')
	{
		alert("You did not enter a caption name.\nPlease enter a name");
		return false;
	}
	
	
	return true;
}

function preprocessEditLayout(form)
{
	// Extract the user input from the form
	var header = form.header.value;
	var footer = form.footer.value;
	
	// Check for valid header input. Display an error message on invalid input.
	if(header == '')
	{
		alert("You left the Header blank. Please try again.");
		
		return false;
	}
	
	// Check for valid footer input. Display an error message on invalid input.
	if(footer == '')
	{
		alert("You left the Footer blank. Please try again.");
		
		return false;
	}
	
	return true;	// Everything passes.
}

// Helper method determines the extension. Returns true with valid JPG extension and false otherwise
function isValidFile(file)
{
	var strlen = file.length;
	var extension = file.substring(strlen - 3, strlen);
	
	if(extension.toLowerCase() == "jpg")
		return true;
	
	return false;
}

// Makes sure all picture file in with  JPG extension
function preprocessAddPictures(form)
{
	var pictures = new Array(10);
	
	// Put all file names in an array so they can be processed easier in a for loop
	pictures[0] = form.picture1.value;
	pictures[1] = form.picture2.value;
	pictures[2] = form.picture3.value;
	pictures[3] = form.picture4.value;
	pictures[4] = form.picture5.value;
	pictures[5] = form.picture6.value;
	pictures[6] = form.picture7.value;
	pictures[7] = form.picture8.value;
	pictures[8] = form.picture9.value;
	pictures[9] = form.picture10.value;
	
	// Process each filename
	for(var i = 0; i < 10; i++)
	{
		if(pictures[i] != '')
		{
			// File name is invalid so display an error message
			if(!isValidFile(pictures[i]))
			{
				alert("Picture " + (i + 1) + " is not a JPEG file. Uploaded files must end in .jpg\n\nPlease try again.");
				return false;
			}
		}
	}
	
	return true;
}

function preprocessChangePassword(form)
{
	// Extract user input
	var oldPassword = form.old_password.value;
	var newPassword1 = form.new_password1.value;
	var newPassword3 = form.new_password1.value.length;
	var newPassword2 = form.new_password2.value;
	var newPassword4 = form.new_password2.value.length;
	
	// The user must enter the old password. Display an error message when the user does not enter one.
	if(oldPassword == '')
	{
		alert("You must enter the old password.\n\nPlease try again.");
		
		return false;
	}
	
	// The user must enter a new password. Display an error message when the user does not enter one.
	if(newPassword1 == '')
	{
		alert("You did not enter a new password.\n\nPlease try again.");
		
		return false;
	}
	// if new password has been entered with a space
	if(newPassword1 == 0)
	{
		alert("You can't just fill with a space.\n\nPlease try again.");
		
		return false;
	}
	//password must at least 6 char
	if(newPassword3 != 6)
	{
		alert("Your password must at least 6 char.\n\nPlease try again.");
		
		return false;
	}
	
	// The user must retype the new password. Display an error message when the user does not enter one.
	if(newPassword2 == '')
	{
		alert("You did not retype your new password.\n\nPlease try again.");
		
		return false;
	}
	// if new password has been entered with a space
	if(newPassword2 == 0)
	{
		alert("You can't just fill with a space.\n\nPlease try again.");
		
		return false;
	}
	//password must at least 6 char
	if(newPassword4 != 6)
	{
		alert("Your retype password must at least 6 char too and same.\n\nPlease try again.");
		
		return false;
	}
	
	// New passwords 1 and 2 must match. Display an error messag when they do not match.
	if(newPassword1 != newPassword2)
	{
		alert("The password you retyped does not match the new password.\n\nPlease try again.");
		
		return false;
	}
	
	if(oldPassword == newPassword1 && newPassword1 == newPassword2)
	{
		alert("You did not enter a new password because the new password matches the old password.\n\n" +
			"Please try again.");
		
		return false;
	}
	
	// Everything passes so compute the SHA-1 message digests for the old and new passwords.
	form.old_password.value = hex_sha1(oldPassword);
	form.new_password1.value = hex_sha1(newPassword1);
	
	return true;
}

// Makes sure the album name field is not blank and all uploaded files end with a JPG extension
function preprocessAddAlbum(form)
{
	
	var name = form.name.value;
	var name2 = form.name.value.length;
	
	// Album name is blank display error message
	if(name == '')
	{
		alert("You did not enter an album name.\nPlease enter an album name and try again.");
		
		return false;
	}
	if(name == 0)
	{
		alert("You did not enter an album name.\nPlease enter an album name and try again.");
		
		return false;
	}
	
	
	var pictures = new Array(10);
	
	// Put picture names in an array so they can be processed easier in a for loop
	pictures[0] = form.picture1.value;
	pictures[1] = form.picture2.value;
	pictures[2] = form.picture3.value;
	pictures[3] = form.picture4.value;
	pictures[4] = form.picture5.value;
	pictures[5] = form.picture6.value;
	pictures[6] = form.picture7.value;
	pictures[7] = form.picture8.value;
	pictures[8] = form.picture9.value;
	pictures[9] = form.picture10.value;
	
	// Process each picture name
	for(var i = 0; i < 10; i++)
	{
		if(pictures[i] != '')
		{
			// Not a valid file so display an error message
			if(!isValidFile(pictures[i]))
			{
				alert("Picture " + (i + 1) + " is not a JPEG file. Uploaded files must end in .jpg\n\nPlease try again.");
				return false;
			}
		}
	}
	
	return true;
}

// Makes sure the album name field is not blank
function preprocessEditAlbumName(form)
{
	var name = form.name.value;
	var name2 = form.name.value.length;
	
	// Album name is blank so show error message
	if(name == '')
	{
		alert("You must enter an album name.\nPlease try again.");
		
		return false;
	}
	if(name == 0)
	{
		alert("You must enter an album name.\nPlease try again.");
		
		return false;
	}
	
	
	return true;
}
function setImage(what)
				{
				var obj = parent.document.getElementById('imghold').contentWindow;
				var pic = obj.document.getElementById('theimg');
				pic.setAttribute('src',what);
				}
				
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// -->
