var currentImage = 0;
var imageMax = 6;
function closeWindow() {
	window.open('','_parent','');
	window.close();
}
function searchFocus(bool) {
	var searchField = document.getElementById('searchField');
	if (bool == true && searchField.value == 'username') {
		searchField.style.color = '#000000';
		searchField.value = '';
	} else if (searchField.value == '') {
		searchField.style.color = '#000000';
		searchField.value = 'username';
	}
}
function searchFocus2(bool) {
	var searchField2 = document.getElementById('searchField2');
	if (bool == true && searchField2.value == 'password') {
		searchField2.style.color = '#000000';
		searchField2.value = '';
	} else if (searchField2.value == '') {
		searchField2.style.color = '#000000';
		searchField2.value = 'password';
	}
}
function changeImage(direction) {
	currentImage += direction;
	//
	prevB = document.getElementById( 'prevButton' );
	nextB = document.getElementById( 'nextButton' );
	if (currentImage == 0) {
		prevB.className = 'invisible';
	} else if (currentImage == imageMax) {
		nextB.className = 'invisible';
	} else {
		prevB.className = 'visible';
		nextB.className = 'visible';
	}
	target = document.getElementById( 'mainContent' );
	target.className = 'introPage'+currentImage;
}
function submitLogin() {
	var error = "";
	error += checkEmail(document.loginForm.email.value);
	if (error != "") {
		alert(error);
		return false;
	}
	if (document.loginForm.email.value != 'Investor') {
		//document.loginForm.password.value = hex_md5('aber'+document.loginForm.password.value);
	}
	return true;
}
function submitLoginInv() {
	var error = "";
	error += checkEmail(document.attachBusinessForm.email.value);
	if (error != "") {
		alert(error);
		return false;
	}
	if (document.attachBusinessForm.confirmpw.value != 'x' && document.attachBusinessForm.password.value != document.attachBusinessForm.confirmpw.value) {
		error += 'Password confirmation does not match.';
		document.attachBusinessForm.confirmpw.value = '';
		alert(error);
		return false;
	}
	document.attachBusinessForm.password.value = hex_md5('aber'+document.attachBusinessForm.password.value);
	if (document.attachBusinessForm.confirmpw.value != '') {
		document.attachBusinessForm.confirmpw.value = hex_md5('aber'+document.attachBusinessForm.confirmpw.value);
	}
	return true;
}
function submitRegister() {
	var error = "";
	error += checkEmail(document.createProfileForm.email.value);
	if (document.createProfileForm.password.value != document.createProfileForm.confirmpw.value) {
		error += "Password confirmation did not match. \n\r";
	}
	if (document.createProfileForm.password.value == '') {
		error += "Password cannot be blank. \n\r";
	}
	if (document.createProfileForm.reason.value == '0') {
		error += "Please choose the option that best describes you. \n\r";
	}
	if (error != "") {
		alert(error);
		return false;
	}
	//document.createProfileForm.password.value = hex_md5('aber'+document.createProfileForm.password.value);
	//document.createProfileForm.confirmpw.value = hex_md5('aber'+document.createProfileForm.confirmpw.value);
	return true;
}
function submitInvestor() {
	var error = "";
	error += checkEmail(document.createProfileForm.email.value);
	if (document.createProfileForm.password.value != document.createProfileForm.confirmpw.value) {
		error += "Password confirmation did not match. \n\r";
	}
	if (document.createProfileForm.password.value == '') {
		error += "Password cannot be blank. \n\r";
	}
	if (document.createProfileForm.reason.value == '0') {
		error += "Please choose the option that best describes you. \n\r";
	}
	if (error != "") {
		alert(error);
		return false;
	}
	document.createProfileForm.password.value = hex_md5('aber'+document.createProfileForm.password.value);
	document.createProfileForm.confirmpw.value = hex_md5('aber'+document.createProfileForm.confirmpw.value);
	return true;
}
function checkMemberRequired() {
	var error = "";
	//error += checkEmail(document.adminForm.adminEmail.value);
	/*if (document.adminForm.password.value == '') {
		error += 'Password cannot be blank \n';
	}*/
	if (document.adminForm.name.value == '') {
		error += 'Member Name cannot be blank \n';
	}
	if (document.adminForm.category.selectedIndex < 0) {
		error += 'Must choose at least one Category \n';
	}
	if (error != "") {
		alert(error);
	} else {
		toggle('newMember0', false); 
		toggle('newMember1', true);
	}
}
function showCommercial(version) {
	window.open('http://www.absolutelyaberdeen.com/commercials/'+version,'','scrollbars=no,menubar=no,height=300,width=340,resizable=yes,toolbar=no,location=no,status=no,top=175,left=150');
}
function showRules() {
	window.open('http://www.absolutelyaberdeen.com/2007Hunt/rules/','','scrollbars=no,menubar=no,height=300,width=550,resizable=yes,toolbar=no,location=no,status=no,top=175,left=150');
}
function showMRules() {
	window.open('http://www.absolutelyaberdeen.com/missing/rules/','','scrollbars=no,menubar=no,height=300,width=550,resizable=yes,toolbar=no,location=no,status=no,top=175,left=150');
}
function submitHolidays() {
	var error = "";
	if (document.pageForm.name.value == '') {
		error += "Your name cannot be left blank. \n";
	}
	if (document.pageForm.address.value == '') {
		error += "Address cannot be left blank. \n";
	}
	if (document.pageForm.city.value == '') {
		error += "City cannot be left blank. \n";
	}
	error += checkZip(document.pageForm.zip.value);
	error += checkEmail(document.pageForm.email.value);
	//
	if (document.pageForm.nameM.value == '') {
		error += "Your family member's name cannot be left blank. \n";
	}
	if (document.pageForm.addressM.value == '') {
		error += "Your family member's address cannot be left blank. \n";
	}
	if (document.pageForm.cityM.value == '') {
		error += "Your family member's city cannot be left blank. \n";
	}
	error += checkZip(document.pageForm.zipM.value);
	error += checkEmail(document.pageForm.emailM.value);
	if (document.pageForm.ageM.value == '') {
		error += "Your family member's age cannot be left blank. \n";
	}
	//
	if (error != "") {
		error = "All information is required to be eligible for the drawing. \n\n"+error;
		alert(error);
		return false;
	}
	return true;
}
function submitHunting() {
	var error = "";
	if (document.hunterForm.name.value == '') {
		error += "Your name cannot be left blank. \n";
	}
	if (document.hunterForm.address.value == '') {
		error += "Address cannot be left blank. \n";
	}
	if (document.hunterForm.city.value == '') {
		error += "City cannot be left blank. \n";
	}
	error += checkZip(document.hunterForm.zip.value);
	error += checkEmail(document.hunterForm.email.value);
	//
	if (document.hunterForm.occupation.value == '') {
		error += "Occupation cannot be left blank. \n";
	}
	error += checkAge(document.hunterForm.age.value);
	if (!document.hunterForm.staying[0].checked && !document.hunterForm.staying[1].checked &&!document.hunterForm.staying[2].checked && !document.hunterForm.staying[3].checked) {
		error += "Check the button of where you will be staying when hunting in Aberdeen this year. \n";
	}
	if (!document.hunterForm.livedHere[0].checked && !document.hunterForm.livedHere[1].checked) {
		error += "Check the button if you have lived in the Aberdeen area before. \n";
	}
	var selected = false;
	for (i=0; i<10; i++) {
		if (document.hunterForm.moveBack[i].checked) {
			selected = true;
			break;
		}
	}
	if (selected == false) {
		error += "Rate your likeliness to move to the Aberdeen area. \n";
	}
	//
	if (error != "") {
		error = "All information is required to be eligible for the drawing. \n\n"+error;
		alert(error);
		return false;
	}
	return true;
}
function submitInterest() {
	var error = "";
	if (document.pageForm.name.value == '') {
		error += "Name must be filled in. \n";
	}
	if (document.pageForm.address.value == '') {
		error += "Address must be filled in. \n";
	}
	if (document.pageForm.city.value == '') {
		error += "City must be filled in. \n";
	}
	error += checkZip(document.pageForm.zip.value);
	error += checkEmail(document.pageForm.email.value);
	if (error != "") {
		error = "The fields with (*) after them are required. \n\n"+error;
		alert(error);
		return false;
	}
	return true;
}
function submitReferral() {
	var error = "";
	if (document.pageForm.referrerName.value == '') {
		error += "Your name must be filled in. \n";
	}
	if (document.pageForm.referrerAddress.value == '') {
		error += "Address must be filled in. \n";
	}
	if (document.pageForm.referrerCity.value == '') {
		error += "City must be filled in. \n";
	}
	error += checkZip(document.pageForm.referrerZip.value);
	error += checkEmail(document.pageForm.referrerEmail.value);
	if (document.pageForm.referrerRelation.value == '') {
		error += "Relation must be filled in. \n";
	}
	//
	if (document.pageForm.name.value == '') {
		error += "Name must be filled in. \n";
	}
	if (document.pageForm.address.value == '') {
		error += "Address must be filled in. \n";
	}
	if (document.pageForm.city.value == '') {
		error += "City must be filled in. \n";
	}
	error += checkZip(document.pageForm.zip.value);
	error += checkEmail(document.pageForm.email.value);
	if (error != "") {
		error = "The fields with (*) after them are required. \n\n"+error;
		alert(error);
		return false;
	}
	return true;
}
function checkZip(zip) {
	if (zip == '') {
		return 'Zip Code cannot be left blank \n';
	}
	var ok = "1234567890-";
	//
	for(i=0; i < zip.length ;i++){
		if(ok.indexOf(zip.charAt(i))<0){ 
			return 'Zip code contains invalid characters, use only numbers and dashes, spaces are not allowed. \n';
		}
	}
	return '';
}
function checkAge(age) {
	if (age == '') {
		return 'Age cannot be left blank \n';
	}
	var ok = "1234567890";
	//
	if (age > 125) {
		return age+' years old? Yeah, right. Try again.';
	}
	for(i=0; i < age.length ;i++){
		if(ok.indexOf(age.charAt(i))<0){ 
			return 'Age contains invalid characters, use only numbers. \n';
		}
	}
	return '';
}
function checkEmail(address) {
	if (address == 'Investor') {
		return '';
	}
	var ok = "@1234567890qwertyuiop[]asdfghjklzxcvbnm.-_QWERTYUIOPASDFGHJKLZXCVBNM";
	//
	for(i=0; i < address.length ;i++){
		if(ok.indexOf(address.charAt(i))<0){ 
			return 'Email contains invalid characters \n';
		}
	}
	var email_array=address.split("@");
	if (email_array.length != 2) {
		return 'Email should contain 1 @ symbol \n';
	}
	var siteCheck = email_array[1].split(".");
	if (siteCheck.length > 1) {
		if (siteCheck[(siteCheck.length-1)].length > 4) {
			return 'Email address invalid \n';
		}
	} else {
		return 'Incomplete email address \n';
	}
	return '';
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}