

function openWindow(href) {
/*  var width = parseInt(screen.availWidth * .8);
  var height = parseInt(screen.availHeight * .7);
  var x = parseInt((screen.availWidth/2) - (width/2));
  var y = parseInt((screen.availHeight/2) - (height/2));
  var windowFeatures = "width=" + width + ",height=" + height + ",left=" + x +",screenX=" + x +",top=" + y + ",screenY=" + y;
  windowFeatures += ",toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=yes";*/
  windowFeatures = "";
  var openWindow = this.open(href, "", windowFeatures);
}

function openAudio(href) {
  var width = 500;
  var height = 200;
  var x = parseInt((screen.availWidth/2) - (width/2));
  var y = parseInt((screen.availHeight/2) - (height/2));
  var windowFeatures = "width=" + width + ",height=" + height + ",left=" + x +",screenX=" + x +",top=" + y + ",screenY=" + y;
  windowFeatures += ",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes";
  var openPicWindow = this.open(href, "pic", windowFeatures);
  openPicWindow.focus();
}

var NEW_WIN_MSG = " (opens in new window)";

function setOnClick() {
  //set google map
  if (document.getElementById("map")) {
	loadMap()
  }
  
  if(!document.getElementsByTagName) {
    return;
  }
  var anchors = document.getElementsByTagName("a");
  for (var i=anchors.length; i !=0; i--) {
    var a=anchors[i-1];
	if (a.rel.indexOf("external") != -1) {
		a.title += NEW_WIN_MSG;
		a.onclick = function(){openWindow(this.href);return false;}
	}
	if (a.rel.indexOf("audio") != -1) {
		a.title += NEW_WIN_MSG;
		a.onclick = function(){openAudio(this.href);return false;}
	}
  }
}

//google map
//load function
function loadMap() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(42.321485, -83.224581), 10);
		
		//add controls
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		
		//add marker
		var point = new GLatLng(42.321485, -83.224581);
		map.addOverlay(new GMarker(point));
		
		//display window
		map.addOverlay(createMarker(point));
	}
}

//function to display window
function createMarker(point) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("<span style='font-size:.9em'>University of Michigan-Dearborn<br />School of Business<br />South Building, Room 102<br />19000 Hubbard Drive<br />Dearborn, MI 48126</span>");
	}
);
	return marker;
}

//Mailing List form validation
function validateMailingList() {
	var f_ue = document.getElementById("email");
	if (!validEmail(f_ue.value)) {
		alert("Please enter a valid email address.");
		f_ue.focus();
		f_ue.select();
		return false;
	}
}

//Mailer form validation
function validateMailer() {
	var f_s = document.getElementById("subject");
	if (f_s.value.length<3) {
		alert("Please enter a subject.");
		f_s.focus();
		f_s.select();
		return false;
	}
	var f_m = document.getElementById("message");
	if (f_m.value.length<15) {
		alert("Please enter a message.");
		f_m.focus();
		f_m.select();
		return false;
	}
}

//Contact form validation
function validateFormJoin() {
	var f_n = document.getElementById("Name");
	if (f_n.value.length<2) {
		alert('Please enter your name.');
		f_n.focus();
		f_n.select();
		return false
	}
	var f_bn = document.getElementById("BusinessName");
	if (f_bn.value.length<2) {
		alert('Please enter your business name.');
		f_bn.focus();
		f_bn.select();
		return false
	}
	/*var f_ue = document.getElementById("userEmail");
	if (!validEmail(f_ue.value)) {
		alert("Please enter a valid email address.");
		f_ue.focus();
		f_ue.select();
		return false
	}*/
	var f_phone = document.getElementById("Phone");
	if (f_phone.value.length<10) {
		alert('Please enter your phone number including the area code.');
		f_phone.focus();
		f_phone.select();
		return false
	}
	var f_pw = document.getElementById("password");
	if (f_pw.value.length<3) {
		alert('Please enter the characters show in the image.');
		f_pw.focus();
		f_pw.select();
		return false
	}
return true
}

//email validation
function validEmail(email) {
	invalidChars = " /:,;"
	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) != -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}



