function register() {
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
}

function doRegistration() {
	var email = document.getElementById('email').value;
	var friendCode = document.getElementById('friendcode').value;
	var miiname = document.getElementById('miiname').value;
	var region = document.getElementById('region').value;
	var passwd = document.getElementById('passwd').value;

	if (email == '' || friendCode == '' || miiname == '' || region == '' || passwd == '') {
		alert('All fields are required.');
	} else {
		if (friendCode.length < 12) {
			alert('Friend code must be 12 digits.');
		} else {
			friendCode = friendCode.replace(/\-/g, '');

			if (friendCode.length < 12) {
				alert('Friend code must be 12 digits.');
			} else if (!isNumeric(friendCode)) {
				alert('Friend code must be numeric.');
			} else if (echeck(email) == false){
				// do nothing else
			} else {
				document.getElementById('friendcode').value = friendCode;
				document.forms['registerForm'].submit();
			}
		}
	}
}

function doExchange(fcr) {
	document.getElementById('fcr').value = fcr;
	document.forms['sendExchange'].submit();
}

function loadNextPage() {
	var page = (parseInt(document.getElementById('page').value) + 1);
	var maxpage = parseInt(document.getElementById('maxpage').value);
	
	if (page <= maxpage) {
		document.getElementById('page').value = page;
	}

	document.forms['doSearch'].submit();
}

function loadPreviousPage() {
	var page = (parseInt(document.getElementById('page').value) - 1);

	if (page > 0) {
		document.getElementById('page').value = page;
	}

	document.forms['doSearch'].submit();
}

function loadSelectedPage() {
	var page = document.getElementById('pageselect').value;
	document.getElementById('page').value = page;
	document.forms['doSearch'].submit();
}

function searchFriends() {
	document.getElementById('pageregion').value = document.getElementById('searchregion').value;
	document.getElementById('pageorder').value = document.getElementById('searchorder').value;
	document.getElementById('page').value = '1';
	document.forms['doSearch'].submit();
}

function editInfo() {
	document.getElementById('editing').value = 'true';
	document.forms['getInfo'].submit();
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email address.");
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email address.");
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email address.");
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email address.");
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Please enter a valid email address.");
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email address.");
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email address.");
		    return false
		 }

 		 return true					
	}
	
function forgotPass() {
	var email = document.getElementById('lemail').value;
	
	if (echeck(email) == false) {
		// do nothing
	} else {
		document.getElementById('femail').value = email;
		document.forms['forgotPass'].submit();
	}
}
	
function doInvite() {
	var email = document.getElementById('iemail').value;
	
	if (echeck(email) == false) {
		// do nothing
	} else {
		document.forms['inviteFriend'].submit();
	}
}
	
function isNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}