///////////////////////////////////////////////////////////
//	originally used to kill								 //
//	slideshow 											 //
///////////////////////////////////////////////////////////
var iTimerID;

////////////////////////////////////////////////////////////
//	checks login info for valid form field data           //
////////////////////////////////////////////////////////////
function ckLogin() {
	var email = document.forms[0].elements[0].value;
	var password = document.forms[0].elements[1].value;
	
	if(email.indexOf("@") == -1) {
		alert('Please enter a valid email address.');
		document.forms[0].elements[0].select();
		return false;
	}
	else if(	email.indexOf(".com") == -1 &&
				email.indexOf(".net") == -1 &&
				email.indexOf(".org") == -1 &&
				email.indexOf(".gov") == -1	&&
				email.indexOf(".edu") == -1) {
		alert('Please enter a valid email address.');
		document.forms[0].elements[0].select();
		return false;
	}
	else if(password == 0) {
		alert('Please enter a valid password.');
		document.forms[0].elements[1].select();
		return false;
	}
	else {
		return true;
	}
}


////////////////////////////////////////////////////////////
//	used to make sure new user information is valid		  //
////////////////////////////////////////////////////////////
function ckNewUser() {
	var email = document.forms[0].elements[0].value;
	var password = document.forms[0].elements['password'].value;
	
	if(email.indexOf("@") == -1) {
		alert('Please enter a valid email address.');
		document.forms[0].elements[0].select();
		return false;
	}
	else if(	email.indexOf(".com") == -1 &&
				email.indexOf(".net") == -1 &&
				email.indexOf(".org") == -1 &&
				email.indexOf(".gov") == -1	&&
				email.indexOf(".edu") == -1) {
		alert('Please enter a valid email address.');
		document.forms[0].elements[0].select();
		return false;
	}
	else if(password == 0) {
		alert('Please enter a valid password.');
		document.forms[0].elements['password'].select();
		return false;
	}
	else if(password.indexOf(" ") != -1) {
		alert('Password cannot contain  spaces.');
		document.forms[0].elements['passowrd'].select();
		return false;
	}
	else {
		return true;
	}
}

////////////////////////////////////////////////////////////
//	confirm that the user wants to delete their album	  //
////////////////////////////////////////////////////////////
function albDel(url, title) {
	if(confirm("This will permanently delete the album, including all associated images and guest invitations.\n\nAre you sure you want to completely delete " + title + "?")) {
		document.location = url;
	}
}

////////////////////////////////////////////////////////////
//	function for a popup window							  //
////////////////////////////////////////////////////////////
function newWin(url, name, w, h, settings) {
	var winStr = "";
	var top = "";
	var left = "";
	if(screen.width) {
		left = (screen.width - w)/2;
		top = (screen.height - h)/2;
	}
	else {
		top = 0;
		left = 0;
	}
	if(left < 0) { left = 0; }
	if(top < 0) { top = 0; }
	
	winStr += "width=" + w + ",";
	winStr += "height=" + h + ",";
	winStr += "top=" + top + ",";
	winStr += "left=" + left + ",";
	winStr += "scrollbars=yes,location=no,";
	winStr += settings;
	
	winPop = window.open(url, name, winStr);
	winPop.focus();
}

////////////////////////////////////////////////////////////
//	confirm that the user wants to assign a user to album //
////////////////////////////////////////////////////////////
function selUser(url) {
	if(confirm('Are you sure that you want to assign this user to the album?')) {
		document.location = url;
	}
}

////////////////////////////////////////////////////////////
//	confirm that a user wants to remove a user from album //
////////////////////////////////////////////////////////////
function remUser(url) {
	if(confirm('Are you sure that you want to remove this user from the album?')) {
		document.location = url;
	}
}

////////////////////////////////////////////////////////////
//	validate that the user has entered a valid quantity	  //
//	for the number of images to upload					  //
////////////////////////////////////////////////////////////
function numImgForm(frm) {
	var num = frm.elements[0].value;
	
	if(isNaN(num)) {
		alert('Please enter a valid number.');
		return false
	}
	else if(num < 1) {
		alert('Please enter a number greater than zero.');
		return false;
	}
	else if(num > 5) {
		alert('You can only upload a maximum of five (5) images at a time.');
		return false;
	}
	else {
		return true;
	}
}

////////////////////////////////////////////////////////////
//	alerts the user to wait while images upload			  //
////////////////////////////////////////////////////////////
function imgUploadForm(frm) {
	alert('Please be patient while your images upload.\n\nDo not click the upload button more than once!');
	return true;
}

////////////////////////////////////////////////////////////
//	confirm that user wants to delete an image from album //
////////////////////////////////////////////////////////////
function delImage(url) {
	if(confirm('Are you sure you want to delete this image?')) {
		document.location = url;
	}
}

////////////////////////////////////////////////////////////
//	form to validate data in user info update form		  //
////////////////////////////////////////////////////////////
function userForm(frm) {
	var email = frm.elements['email'].value;
	var first = frm.elements['firstname'].value;
	var last = frm.elements['lastname'].value;
	var uPass = frm.elements['uPass'].checked;
	var pass1 = frm.elements['password1'].value;
	var pass2 = frm.elements['password2'].value;
	
	if(email.indexOf("@") == -1) {
		alert('Please enter a valid email address.');
		frm.elements['email'].select();
		return false;
	}
	else if(	email.indexOf(".com") == -1 &&
				email.indexOf(".net") == -1 &&
				email.indexOf(".org") == -1 &&
				email.indexOf(".gov") == -1	&&
				email.indexOf(".edu") == -1) {
		alert('Please enter a valid email address.');
		frm.elements['email'].select();
		return false;
	}
	else if(first==0) {
		alert('Please enter a first name.');
		frm.elements['firstname'].select();
		return false;
	}
	else if(last==0) {
		alert('Please enter a last name.');
		frm.elements['lastname'].select();
		return false;
	}
	else if(uPass) {
		if(pass1==0) {
			alert('Please enter a valid password.');
			frm.elements['password1'].select();
			return false;
		}
		else if(pass2==0) {
			alert('Please enter a valid password.');
			frm.elements['password2'].select();
			return false;
		}
		else if(pass1 != pass2) {
			alert('The passwords you have entered do not match.');
			frm.elements['password1'].select();
			return false;
		}
	}
	else {
		return true;
	}
}

////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
function passField() {
	var uPass = document.forms[0].elements['uPass'].checked;
	if(uPass) {
		document.forms[0].elements['password1'].disabled = false;
		document.forms[0].elements['password2'].disabled = false;
		document.forms[0].elements['password1'].select();
	}
	else {
		document.forms[0].elements['password1'].disabled = true;
		document.forms[0].elements['password2'].disabled = true;
	}
}

////////////////////////////////////////////////////////////
//	validate form that sends email to user				  //
////////////////////////////////////////////////////////////
function ckEmailForm(frm) {
	var subject = frm.elements['subject'].value;
	var msg = frm.elements['message'].value;
	
	if(subject == 0) {
		if(confirm('You have not entered a subject.  Do you wish to enter one now?')) {
			frm.elements['subject'].select();
		}
		else {
			frm.elements['subject'].value = "(No Subject)";
			frm.elements['message'].focus();
		}
	}
	
	else if(msg == 0) {
		alert('Please enter an email message to send.');
		frm.elements['message'].focus();
		return false;
	}
	
	else if(confirm('Are you sure you want to send this email?')) {
		return true;
	}
	
	return false;
}

////////////////////////////////////////////////////////////
//	confirm that user wants to make an image a cover img  //
////////////////////////////////////////////////////////////
function makeCover(url, img) {
	if(confirm('Are you sure that you want to use ' + img + ' as the cover image for this album?')) {
		document.location = url;
	}
}

////////////////////////////////////////////////////////////
//	handles the slide show auto navigation				  //
////////////////////////////////////////////////////////////
function slideShow(dir, currRow, alb, currentMode) {
	if(dir == "next") {
		var newRow = eval(currRow + 1);
	}
	else {
		var newRow = eval(currRow - 1);
	}
	
	var url = "goToURL('popSlideShow.cfm?alb_id=" + alb + "&row=" + newRow + "&currentMode=" + currentMode + "')";
	//setTimeout("alert('hello')", 2000);
	iTimerID = setTimeout(url, 3000);
}

////////////////////////////////////////////////////////////
//	this function is no longer valid					  //
////////////////////////////////////////////////////////////
function killSlideShow() {
	clearTimeout(iTimerID);
}

////////////////////////////////////////////////////////////
//	used to relocate to another page					  //
////////////////////////////////////////////////////////////
function goToURL(url) {
	document.location = url;
}

////////////////////////////////////////////////////
//	FUNCTION TO VALIDATE THE CREATION OF AN ALBUM //
////////////////////////////////////////////////////
function ckCAlbum(f) {
	//var dirName = f.elements['name'].value;
	var dirTitle = f.elements['title'].value;
	
	/* automating album directory naming
	if (dirName == 0) {
		alert('Please enter an album short name.');
		f.elements['name'].focus();
		return false;
	}
	
	for(var i=0;i<dirName.length;i++) {
		code = dirName.charCodeAt(i);
		if (
				!(code >= 65 && code <= 90) && 
				!(code >= 48 && code <= 57) &&
				!(code == 95)
			) {
			alert('The album short name can only contain letters (A-Z), numbers (0-9), and underscores (_).');
			return false;
		}
	}
	
	if(dirName.charCodeAt(0) == 95 || dirName.charCodeAt(dirName.length-1) == 95) {
		alert('The album short name cannot begin or end with an underscore (_).');
		return false;
	}
	*/
	
	if(dirTitle == 0) {
		alert('Please enter an album title.');
		f.elements['title'].focus();
		return false;
	}
	
	return true;
}


/////////////////////////////////////////////////
//  MAKE CONTROL ALL UPPER CASE
/////////////////////////////////////////////////
function makeUpper(what) {
	what.value = what.value.toUpperCase();
	what.focus();
}

////////////////////////////////////////////////////
//	FUNCTION TO VALIDATE USER SEARCHING			  //
////////////////////////////////////////////////////
function userSearchForm(f) {
	var fname = f.elements['firstname'].value;
	var lname = f.elements['lastname'].value;
	var email = f.elements['email'].value;
	
	if(fname==0 && lname==0 && email==0) {
		alert('Please enter either a first name, last name, or an email address.');
		f.elements['firstname'].select();
		return false;
	}
	
	return true;
}

////////////////////////////////////////////////
//	FUNCTION TO MAKE THE SLIDESHOW FULLSCREEN
//	OR COMPACT
////////////////////////////////////////////////

function fullScreen(currentMode, alb_id, row, play) {
	window.moveTo(0,0);
	var w = screen.availWidth;
	var h = screen.availHeight;
	
	if(document.all) {
		if(currentMode == 'FULL') {
			window.resizeTo(w,h);
		}
		else {
			window.resizeTo(500,650);
			window.moveTo((w/2)-250,(h/2)-250);
		}
	}
	else{
		if(currentMode == 'FULL') {
			window.innerWidth = w;
			window.innerHeight = h;
		}
		else {
			window.innerWidth = 450;
			window.innerHeight = 650;
			window.moveTo((w/2)-250,(h/2)-250);
		}
	}
	
	if(currentMode == 'FULL') {
		document.location = "popSlideShow.cfm?alb_id=" + alb_id + "&row=" + row + "&play=" + play + "&currentMode=FULL";
	}
	else {
		document.location = "popSlideShow.cfm?alb_id=" + alb_id + "&row=" + row + "&play=" + play + "&currentMode=";
	}
}

//////////////////////////////////////////////////
//	SET BACKGROUND
//////////////////////////////////////////////////
function checkDim() {
	if(document.all) {
		var body_el = document.all.item("body1");
		var brow_w = window.document.body.clientWidth;
		var brow_h = window.document.body.clientHeight;
	}
	else {
		var body_el = document.getElementById("body1");
		var brow_w = window.innerWidth;
		var brow_h = window.innerHeight;
	}
	
	var img = "images/bg2_800x600.gif";
	var w = brow_w;
	var h = brow_h;
	var dim = "";
	//	1600x1200
	//	1280x1024
	//	1152x864
	//	1024x768
	//	800x600
	//alert(w);
	if(w<=1600) {
		dim = "1600x1200";
	}
	if(w<=1280) {
		dim = "1280x1024";
	}	
	if(w<=1152) {
		dim = "1152x864";
	}
	if(w<=1024) {
		dim = "1024x768";
	}
	if(w<=800) {
		dim = "800x600";
	}
	if(dim!=0) {
		img = "images/bg2_" + dim + ".gif";
	}
	//alert(img + "\n\n" + w + "x" + h);
	body_el.background = img;
}

////////////////////////////////////////////////////////////
//	used to handle roll-over effects on menu items		  //
////////////////////////////////////////////////////////////
function swapImg(img, show) {
	if(document.all) {
		var imgObj = document.all.item(img);
	}
	
	if(document.getElementById) {
		var imgObj = document.getElementById(img);
	}
	
	var newSrc = eval(img + show + ".src");
	imgObj.src = newSrc;
}

/*
var text = new Array();
text[0] = "do it";
text[1] = "come on";
text[2] = "log in already";
text[3] = "you know you want to";
text[4] = "please log in?";
text[5] = "just log in already";
text[6] = "i promise i won't bite";
text[8] = "you're not scared are you?";
text[9] = "you are scared, aren't you?";
text[10] = "i think i might cry";
text[11] = "why must you torture me?";

var randomnumber = Math.floor(Math.random()*11);

function doRandText() {
	randomnumber = Math.floor(Math.random()*11);	
	
	if(document.all) {
		randText.innerHTML = text[randomnumber];
	}
	else {
		document.getElementById("randText").innerHTML = text[randomnumber];
	}
	
	setInterval("doRandText()", 5000);
}*/

////////////////////////////////////////////////////////////
//	used to show/hide album users in album edit mode	  //
////////////////////////////////////////////////////////////
function albumUsers() {
	if(document.all) {
		var el = document.all.item("usersDisp");
	}
	else {
		var el = document.getElementById("usersDisp");
	}
	if(el.style.display=="none") {
		el.style.display = "";
	}
	else {
		el.style.display = "none";
	}
}

////////////////////////////////////////////////////////////
//	used to show/hide album images in album edit mode	  //
////////////////////////////////////////////////////////////
function albumImages() {
	if(document.all) {
		var el = document.all.item("albumImages");
	}
	else {
		var el = document.getElementById("albumImages");
	}
	if(el.style.display=="none") {
		el.style.display = "";
	}
	else {
		el.style.display = "none";
	}
}

////////////////////////////////////////////////////////////
//	used to show hide any object						  //
////////////////////////////////////////////////////////////
function showHide(what) {
	if(document.all) {
		var el = document.all.item(what);
	}
	else{
		var el = document.getElementById(what);
	}
	if(el.style.display=="none") {
		el.style.display = "";
	}
	else {
		el.style.display = "none";
	}
}

//////////////////////////////
// site access form validation
//////////////////////////////
function siteAccess(f) {
	var fname = f.elements['firstname'].value;
	var lname = f.elements['lastname'].value;
	var email1 = f.elements['email1'].value;
	var email2 = f.elements['email2'].value;
	var how = f.elements['how'].value;
	
	if(email1!=email2) {
		alert('The email addresses do not match.');
		document.forms[0].elements[0].select();
		return false;
	}
	else if(email1.indexOf("@") == -1) {
		alert('Please enter a valid email address.');
		document.forms[0].elements[0].select();
		return false;
	}
	else if(	email1.indexOf(".com") == -1 &&
				email1.indexOf(".net") == -1 &&
				email1.indexOf(".org") == -1 &&
				email1.indexOf(".gov") == -1	&&
				email1.indexOf(".edu") == -1) {
		alert('Please enter a valid email address.');
		document.forms[0].elements[0].select();
		return false;
	}
	else if(fname==0) {
		alert('Please enter a valid first name.');
		f.elements['firstname'].select();
		return false;
	}
	else if(lname==0) {
		alert('Please enter a valid last name.');
		f.elements['lastname'].select();
		return false;
	}
	else if(how==0) {
		alert('Please tell us how you heard about gpuds.com and why you would like access to this site');
		f.elements['how'].select();
		return false;
	}
	else {
		return true;
	}
}

function confAction(url,msg){
	if(confirm(msg)){
		document.location = url;
	}
}

function whichUploader(url,alb_id){
	document.location = url;
	return;
	//if(confirm('Do you want to try the new GPUDS drag-n-drop image uploader?')){
	if(confirm('Do you want to use the GPUDS flash uploader?')) {
		//document.location = 'content.cfm?target=EDETAIL&alb_id='+alb_id+'&action=IMAGES&dnd=y';
		document.location = url;
	} else {
		newWin('popUpload.cfm?alb_id='+alb_id,'upWin',500,500,'');
	}
}