var xmlHttp; // used for ajax
var sbVal; // used for specials boxes

//---- Setup AJAX -----------------------//
function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


//----- 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;
	}
}
