
//----- Validate Email Addresses -----------//
// checks for valid looking email addy
function checkemail(str){
	var filter=/^.+@.+\..{2,3}$/;	
	return (filter.test(str));
}



//----- Trim White Space -----------//
//trim whitespace for validation
function trim(s){
	if((s==null)||(typeof(s)!='string')||!s.length)return'';return s.replace(/^\s+/,'').replace(/\s+$/,'')
}



//----- Open New Window -----------//
//Open a new window with specific width/height/location 
function openWindow(location, width, height) {		
	newWidth = width + 20;
	newHeight = height + 20;
	widthHeight = "width=" + newWidth + ",height=" + newHeight;
	window.open(location,"",widthHeight);		
}

//----- Open New Window -----------//
//Open a new window with specific width/height/location & scroll bars
function openWindowScroll(location, width, height) {		
	newWidth = width + 20;
	newHeight = height + 20;
	windowParameters = "width=" + newWidth + ",height=" + newHeight + ",scrollbars=yes";
	window.open(location,"",windowParameters);		
}


//----- Contact Form Validation -----------//
function checkContactForm(theForm) {
	var ic = document.getElementById("firstname");			
	var firstName = document.getElementById("middlename");
	firstName.value = trim(firstName.value);
	var lastName = document.getElementById("lastname");
	lastName.value = trim(lastName.value);
	//var organization = document.getElementById("organization");
	//organization.value = trim(organization.value);
	var phoneNum = document.getElementById("phone");
	phoneNum.value = trim(phoneNum.value);
	var emailObject = document.getElementById("email");
	emailObject.value = trim(emailObject.value);
	//var city = document.getElementById("city");
	//city.value = trim(city.value);
	var province = document.getElementById("province");
	var country = document.getElementById("country");
	//var interest = document.getElementById("interest");
	var comments = document.getElementById("comments");
	 
	if (firstName.value.length == 0) {
		alert("Please enter your first name.");
		firstName.focus();
		return false;
	} else if (lastName.value.length == 0) {
		alert("Please enter your last name.");
		lastName.focus();
		return false;
	//} else if (city.value.length == 0) {
	//	alert("Please enter your city.");
	//	city.focus();
	//	return false;
	} else if (emailObject.value.length == 0) {
		alert("Please enter your email address.");
		emailObject.focus();
		return false;
	} else if (!checkemail(emailObject.value)) {
		alert("Please check your email address for errors.");
		emailObject.focus();
		return false;
	//} else if (phoneNum.value.length > 15) {
	//	alert("Please check your phone number - it should not contain more than 15 digits.");
	//	phoneNum.focus();
	//	return false;
	//} else if (organization.value.length > 40) {
	//	alert("Please abbreviate your company name to make it less than 40 characters long.");
	//	organization.focus();
	//	return false;
	} else {
		//alert("Submission CONTACT Good");
		//theForm.submit();
		return true;
	}
}


// Setup for view larger links using fancybox
function setupFancyBox() {
    $("a.fancybox").fancybox();
	$("a.fancygallery").fancybox({
		'hideOnContentClick': false
	}); 
	
    //$("a.fancyboxlink").click(function() {
    //    $("#fancy_title").remove(); //removing the title bar, not needed
    //});     
}
