// JavaScript Document created by Bluewire Media //

//
// Opens up new email window. Attemps to hide email address from spammers | Must Pass in user (left of @) and domain (right of @)
//
function hideEmail(user,domain) {
	  locationstring = "mailto:" + user + "@" + domain;
	  window.location = locationstring;
	}
		
//
// Openup new window in middle of screen | Must Pass in URL of new window.
//
function openWindow(url) {
	
	var width = 600;
	var height = 570;
	
	var leftPos = 0;
	var topPos = 0;
	
	//alert("Width: " + width + " | Height: " + height);
	
	if (screen) {
		leftPos = (screen.width / 2) - (width/2);
		topPos = (screen.height / 2) - (height/2);
	}
	var newWindow = window.open(url, "" , "width="+width+", height="+height+", left="+leftPos+", top="+topPos+", toolbar=No, location=No, scrollbars=Yes, resizable=Yes, fullscreen=No");
	newWindow.focus();
}

//
// Form Validation
//

function checkEmail(str){
	
	var errorString = "";	
	
	var emailFilter = /^.+@.+\..{2,3}$/;
	
	if (!(emailFilter.test(str))) { 
		errorString = "\n - Email address is INVALID.";
	}
	
	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	
	if (str.match(illegalChars)) {
		errorString = "\n - Email address contains ILLEGAL characters.";			
	}
	
	return errorString;
}

function checkForNumbers(str){
	var numberFilter = /^[a-z A-Z]+$/;
	if(!(numberFilter.test(str))){
		return true;
	}
	else{
		return false;	
	}
}
	
function checkForLetters(str){
	var letterFilter = 	/^[0-9\ ]+$/;
	if(!(letterFilter.test(str))){
		return true;
	}
	else{
		return false;	
	}
}

function checkForIllegalChars(str){
	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if(str.match(illegalChars)){
		return true;
	}
	else{
		return false;	
	}
}

function validateForm(form){
	
	var errorString = "";				
	
	if(form.name.value == ""){
		errorString += "\n - Name is empty.";
	}
	else{
		//if(checkForNumbers(form.name.value)){
		//	errorString += "\n - Name contains NUMBERS.";
		//}
		if(checkForIllegalChars(form.name.value)){
			errorString += "\n - Name contains ILLEGAL characters.";	
		}
	}
	
	if(form.email.value == ""){
		errorString += "\n - Please provide an Email Address.";
	}
	else{
		if(checkForLetters(form.phone.value)){
			errorString += "\n - Phone Number contains LETTERS.";
		}
		if(checkForIllegalChars(form.phone.value)){
			errorString += "\n - Phone contains ILLEGAL characters.";	
		}
		if((form.phone.value).length < 8){
			errorString += "\n - Phone Number is to short. (Phone Numbers are usually 8 digits or longer)";
		}	
	}
	
	if(form.phone.value == ""){
		errorString += "\n - Please provide a Phone Number";
	}
	else{
		errorString += checkEmail(form.email.value);
	}
	
	//Control Statement
	if(errorString == ""){
		return true;
	}
	else{
		alert("The following errors occurred...\n" + errorString + "\n\n...Please make corrections and re-submit the form");
		return false;
	}
}