/*
 * What it is:
 * Javascript functions for the website
 *
 * Author:
 * Jason Stechschulte <jasons@wcoil.com>
 *
 * Description:
 * This page is mainly for javascript functions that are to be used throughout
 * the website.  There could be some page specific stuff here as well.  Mainly
 * this exists because I like things as modular as possible, so separating this
 * from the main page makes me happy.
 *
 */


/*
 * This function confirms that the user actually wants to go to the url passed
 * to this function.
 */

function confirmdelete(message, url) {
	if(confirm(message)) location.href = url;
}


/*
 * The next three function work together to swap classes and status messages
 * for links.  With all three, links can look like buttons if you use the
 * correct styles to go with them.
 */

function over(field, link, myclass) {
	field.className = myclass + "2";
	if(link != '') {
		if(document.getElementById) {
			document.getElementById(link).className = myclass + "link2";
			window.status = document.getElementById(link).href;
		}
		else {
			document.all(link).className = myclass + "link2";
			window.status = document.all(link).href;
		}
	}
	return true;
}

function out(field, link, myclass) {
	field.className = myclass;
	if(link != '') {
		if(document.getElementById) {
			document.getElementById(link).className = myclass + "link";
		}
		else {
			document.all(link).className = myclass + "link";
		}
	}
	window.status = '';
	return true;
}

function down(field, link, myclass) {
	field.className = myclass + "3";
	if(link != '') {
		if(document.getElementById) {
			document.getElementById(link).className = myclass + "link3";
		}
		else {
			document.all(link).className = myclass + "link3";
		}
	}
	return true;
}


/*
 * This function checks to see if a message has been typed, if not, it is
 * assumed that the user accidentally hit the enter key, so rather than
 * submitting the form, we simply tab them to the first empty field that
 * follows a filled in field.  This in effect makes the enter key work somewhat
 * like the tab key for them.
 */

function contactFormSubmit() {
	if(document.contact.message.value == '') {
		var keepGoing = true;
		document.contact.message.focus();
		if(document.contact.phone.value == '') {
			document.contact.phone.focus();
		}
		else {
			keepGoing = false;
		}
		if(keepGoing && document.contact.email.value == '') {
			document.contact.email.focus();
		}
		else {
			keepGoing = false;
		}
		if(keepGoing && document.contact.name.value == '') {
			document.contact.name.focus();
		}
		return false;
	}
	return true;
}


/*
 * This function is used for making a thumbnail larger.  You send it the image,
 * image width, and image height.  It then opens a new window just large enough
 * for the full size image to be displayed in, and displays the image.
 */

function viewImage(image, w, h) {
	var winl;
	var wint;
	if(screen.width){
		winl = (screen.width - w) / 2;
		wint = (screen.height - h) / 2;
		if(winl < 0) winl = 0;
		if(wint < 0) wint = 0;
	}
	else{
		winl = 0;
		wint = 0;
	}
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += 'toolbar=no,scrollbars=yes';
	win = window.open(image, "Picture", settings);
	win.window.focus();
}


function viewphoto(img, cw, ch) {
   day = new Date();
   id = day.getTime();
   var top = (screen.height - ch) / 2 - 55;
   var left = (screen.width - cw) / 2 - 55;
   ch = ch + 55;
   cw = cw + 55;
   URL = "viewphoto.php?img=" + img + "&w=" + cw + "&h=" + ch;

	newpage = "page" + id + " = window.open(URL, '" + id + "','top=" + top + ", left=" + left 
			  + ",titlebar=0,toolbar=0,scrollbars=1, location=0,statusbar=1, menubar=0, resizable=1,width="
			  + cw + ",height=" + ch + "');";
	eval(newpage);
}

