/*
	dom.functions.js
	Misc. DOM Functionality
	
	Creator: Matt Kircher
	Created: 7.29.07
	
*/

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.isEmail = function() { return (this.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)?true:false; }

function initGalleryThumbEffects(){
	var gallery = document.getElementById('portfolio-gallery');
	if(!gallery) return;
	
	var thumbs = gallery.getElementsByTagName('img');
	for(var x=0; x<thumbs.length; x++){
		thumbs[x].onmouseover = function(){
			Element.setOpacity(this, 0.75);
		}
		thumbs[x].onmouseout = function(){
			Element.setOpacity(this, 1);
		}
	}
}

function validateForm(){

	var form = document.contact_form;
	var valid = true;
	
	if(form.name.value.trim() == ""){
		alert("Please fill in your name!");
		form.elements['name'].focus();
		valid = false;
	}
	else if(form.email.value.trim() == ""){
		alert("Please supply a valid email!")
		form.elements['email'].focus();
		valid = false;
	}
	else if(form.comments.value.trim() == ""){
		if(!confirm("You have not left any comments! Do you still want to send your name and email address?")){
			form.elements['comments'].focus();
			valid = false;
		}
	}	
	return valid;
}

function init(){
	initGalleryThumbEffects();	
}

window.onload = init;
