// JavaScript Document
function OpenAdmin(theURL){
	LeftPosition = (screen.width) ? (screen.width)-510 : 0;
	cmsheight = (screen.height) ? (screen.height)*.75 : 550;
	settings = 'height='+cmsheight+',width=500,top=0,left='+LeftPosition+',scrollbars=yes,resizable=yes'
	win = window.open(theURL,'viewit',settings)
}

// -- required form fields for contact form on Help page:
function checkContactFields() {
missinginfo = "";
if (document.formContact.name.value == "") {
missinginfo += "\n     -  name";
}
if ((document.formContact.email.value == "") || 
(document.formContact.email.value.indexOf('@') == -1) || 
(document.formContact.email.value.indexOf('.') == -1)) {
missinginfo += "\n     -  valid email";
}
if (document.formContact.message.value == "") {
missinginfo += "\n     -  message";
}
if (missinginfo != "") {
missinginfo ="Please fill in the following fields:\n" +
missinginfo + "\n\nThanks!";
alert(missinginfo);
return false;
}
else return true;
}

// -- required form fields for Register form:
function checkRegisterFields() {
missinginfo = "";
if (document.regform.username.value == "") {
missinginfo += "\n     -  user name";
}
if ((document.regform.email.value == "") || 
!(validateEmail(document.regform.email.value))) {
missinginfo += "\n     -  valid email";
}
if (document.regform.email.value != document.regform.emailconf.value) {
	missinginfo += "\n     -  email mismatch";
}
if (document.regform.pw_question.value == "") {
missinginfo += "\n     -  password question";
}
if (document.regform.pw_question.value == "") {
missinginfo += "\n     -  password answer";
}
if (document.regform.referral.value == "") {
missinginfo += "\n     -  referral";
}
if(document.regform.news[0].checked == false && document.regform.news[1].checked == false) {
missinginfo += "\n     -  newsletter choice";
}
if(document.regform.tournaments[0].checked == false && document.regform.tournaments[1].checked == false) {
	missinginfo += "\n     -  tournament email choice";
}
if(document.regform.pbe[0].checked == false && document.regform.pbe[1].checked == false && document.regform.pbe[2].checked == false) {
	missinginfo += "\n     -  pbe email choice";
}

if (missinginfo != "") {
missinginfo ="Please fill in the following fields:\n" +
missinginfo + "\n\nThanks!";
alert(missinginfo);
return false;
}

if (document.regform.email.value != document.regform.emailconf.value) {
	alert("The email addresses you entered do not match");
	return false;
}

else return true;
}

/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function validateEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (lat < 1 || lat >= lstr){
	   return false;
	}

	if (ldot < 1 || ldot >= lstr - 1){
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1 || str.indexOf("..")!=-1
			 || str.indexOf("@www.")!=-1){
	    return false;
	 }

	 return true;					
}

// -- required form fields for Profile form:
function checkProfileFields() {
missinginfo = "";
if (document.profileform.username.value == "") {
missinginfo += "\n     -  user name";
}
if (document.profileform.password.value == "") {
missinginfo += "\n     -  password";
}
if(document.profileform.newsletter[0].checked == false && document.profileform.newsletter[1].checked == false) {
missinginfo += "\n     -  newsletter choice";
}
if ((document.profileform.email.value == "") || 
!(validateEmail(document.profileform.email.value))) {
missinginfo += "\n     -  valid email";
}

if (missinginfo != "") {
missinginfo ="Please fill in the following fields:\n" +
missinginfo + "\n\nThanks!";
alert(missinginfo);
return false;
}

if (document.profileform.email.value != document.profileform.emailconf.value) {
	alert("The email addresses you entered do not match");
	return false;
}

else return true;
}

