$(function() {
	$('a#getReport').click(getReport1);
	$('a#close').click(closeReport);
	$('form#contact1').submit(validateAndSubmit);
});

function getReport1() {
	var contactWindow = document.getElementById("contact");
	contactWindow.style.display = "block";
	return false;
}

function closeReport() {
	var contactWindow = document.getElementById("contact");
	var close = document.getElementById("close");
	contactWindow.style.display = "none";
	return false;
}

function validateAndSubmit() {
	return validate();
	$('form#contact1').submit();
}

function validate() {
	if (document.contact1.name.value=="") {
		alert ("Please provide your Name.");
		document.contact1.name.select(); 
		return false;
	}  

	if (document.contact1.title.value=="") {
		alert ("Please provide your Title.");
		document.contact1.title.select(); 
		return false;
	} 
	
	if (document.contact1.company.value=="") {
		alert ("Please provide your Company Name.");
		document.contact1.company.select(); 
		return false;
	} 

	if (document.contact1.email.value=="") {
		alert ("Please provide your Email address.");
		document.contact1.email.select(); 
		return false;
	}

	if (document.contact1.email.value.indexOf("@",1) == -1) {
		alert("Invalid E-Mail address");
		document.contact1.email.focus();
		document.contact1.email.select();
		return(false);
	}

	if (document.contact1.email.value.indexOf("@") == 0) {
		alert("Invalid E-Mail address");
		document.contact1.email.focus();
		document.contact1.email.select();
		return(false);
	}

	if (document.contact1.email.value.indexOf(".",5) == -1) {
		alert("Invalid E-Mail address");
		document.contact1.email.focus();
		document.contact1.email.select();
		return(false);
	}

	if (document.contact1.email.value.indexOf(".") == 0) {
		alert("Invalid E-Mail address");
		document.contact1.email.focus();
		document.contact1.email.select();
		return(false);
	}

	if ((document.contact1.email.value.lastIndexOf(".")) -(document.contact1.email.value.indexOf("@"))<4 ) {		
		alert("Invalid E-Mail address");
		document.contact1.email.focus();
		document.contact1.email.select();
		return(false);
	}

	if (document.contact1.format[0].checked == false && document.contact1.format[1].checked == false) {
		alert("Please select the format you prefer.");
		return(false);
	}
}
