function switchto(q){
      if (q){

          document.getElementById('passwordtext').style.display="none";
          document.getElementById('pwd').style.display="inline";
          document.getElementById('pwd').focus();

      } else {
          document.getElementById('pwd').style.display="none";
          document.getElementById('passwordtext').style.display="inline";
      }

};

function checkEmail(emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]!%";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}

	if (user.match(userPat)==null) {
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false;
			}
		}
		return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
		}
	}

	if (domArr[len-1].length < 2) {
		return false;
	}

	if (len<2) {
		return false;
	}

	var mask=/@(date.com|date.net|matchmaker.com|matchmaker.net|matchmaker.org|matchmaker.biz|mm.org|gay.com|wellsfargo.com|spamhole.com|mailinator.com|klassmaster.com|fakeinformation.com|sogetthis.com|spambob.com|spamgourmet.com|spamex.com)/i;
	if (mask.test(emailStr.toLowerCase())) {
		return false;
	}
	/*mask=/^(root|abuse|webmaster|help|postmaster|sales|resumes|contact|advertising|spam|spamtrap|nospam|noc|admin|support|daemon|listserve|listserver|autoreply)@/i;
	if (mask.test(emailStr.toLowerCase())) {
		return false;
	}*/

	return true;
};

function isEmpty(field) {
	
	//if the field is disabled treat it as an empty field.
	if (field.disabled){return true;}
	
	if (field.type=='checkbox'||(field[0]&&field[0].type == 'checkbox')) {
		return !isCheckBoxChecked(field);
	}
	if (field.type=='radio'||(field[0]&&field[0].type == 'radio')) {
		return !isCheckBoxChecked(field);
	}
	//Try trim - will fail for input type="file".
	try
	{
		field.value = field.value.trim();
	}
	catch(e) {}
	if (field.value.length == 0) {
		return true;
	}
};
/* Trim the whitespace from beginning and the end of the given string. */
function trim(str)
{
	str = new String(str);
	return str.replace(/^\s+/,'').replace(/\s+$/,'');
};

/* Add a trim method to String's. */
function strtrim()
{
	return trim(this);
};
String.prototype.trim = strtrim;

function validateRequiredField(field, name)
{
  return validateRequiredField(field, name, '');
};
/** Validates required field */
function validateRequiredField(field, name, dv)
{
	//Try trim - will fail for input type="file".
	try
	{
		field.value = field.value.trim();
		dv = dv.trim();
	}
	catch(e) {}

	if (field.value.length == 0 || field.value == dv)
	{
		field.focus();
		try{field.focus();}catch(e){}
		return false;
	}
	return true;
};
function validateMaxLength(field, name, maxLength)
{
	var value = field.value;
	var originalVal = value;	//store a copy with the \n's in it
	var newVal = "";	//new value with any extra characters removed from it so as not to go over maxLength
	var character = null;
	value = value.replace(/\n/g,'**'); // bug #4830 when the javascript validates it sees \n's and java validates it sees \r\n's so a string may pass javascript validation but fail java validation, solution validate on a copy of the string with all \n's replaced with 2 characters to simulate the java length
	
	if (value.length > maxLength)
	{
		//loop through the string getting one character at a time.
		//If we encounter a \n we have to count it as 2 characters due to bug #4830
		for(var i=0, count=1; count<=maxLength; i++, count++){
				character = originalVal.charAt(i);
				
				//if this is a new line char make sure we have 2 spaces available in the new string
				if(character == "\n" && count<=maxLength-1){
					newVal = newVal.concat(character);
					count++;
				}else{
					newVal = newVal.concat(character);
				}
		}
		
		var msg = MSG_MAX_LENGTH.replace('%1', name);
		//msg = msg.replace('%2', maxLength);
		//alert(msg);

		try{
			//substitute in the shortened string into the field.
			field.value = newVal;
			field.focus();
		}catch(e){}
		return false;
	}
	return true;
};

/** Validate that a field is greater than or equal to the min length. */
function validateMinLength(field, name, minLength) {
	if (field.value.length < minLength) {
		//var msg = MSG_MIN_LENGTH.replace('%1', name);
		//msg = msg.replace('%2', minLength);
		//alert(msg);
		try{field.focus();}catch(e){}
		return false;
	}
	else {
		return true;
	}
};

function validateEmailField(emailField, name)
{
	emailField.value = emailField.value.trim();
	if (isEmpty(emailField)) return true; 

	if (!checkEmail(emailField.value)) {
		//alert(MSG_INVALID_EMAIL.replace('%1', emailField.value));
		try{emailField.focus();}catch(e){}
		return false;
	}
	return true;
};

/** Checks that a field contains only alphanumeric values */
function validateAlphaNumericWS(field, name)
{
	var mask = /^[_0-9a-zA-Z-\s]*[_0-9a-zA-Z-\s]$/;
	if (!mask.test(field.value)) {
		//alert(MSG_ALPHA_NUMERIC.replace('%1', name));
		try{field.focus();}catch(e){}
		return false;
	}
	return true;
};

function setPreRegistration() {
  var stat = 1;
  var fm = document.RegFrm;
  var fname = document.getElementById("pre_fname");
  var lname = document.getElementById("pre_lname");
  var fullname=document.getElementById("pre_fullname");
  var eml = document.getElementById("pre_mail");
  var gender = "";
  var genderM = document.getElementById("genderMale");
  var genderF = document.getElementById("genderFemale");
  if (genderM.checked) {
    gender = "M";
  } else if (genderF.checked) {
    gender = "F";
  } else {
    gender = "";
  }
  var ctry = document.getElementById("pre_ctry");

  
  if (fullname.value == "") {
	  alert("Please enter your full name.");
	  fullname.focus();
	  return false; 
  }
  else if (!(validateRequiredField(fullname, ''))) {
      alert("Please enter your full name.");
	  fullname.focus();
      return false;
  }
  else if (!(validateMaxLength(fullname, '','40'))) {
      alert("Please enter not more than 40 characters.");
	  fullname.focus();
      return false;
  }
  else if (!(validateAlphaNumericWS(fullname, ''))) {
      alert("Invalid character/s.");
	  fullname.focus();
      return false;
  }
  
  else if (gender == "") {
      alert("Please choose your gender.");
      genderM.focus();
  }
  else if(eml.value==""){
      alert("Please enter your email address");
	  eml.focus();
	  return false;
  }
  else if (!(validateEmailField(eml))) {
	  alert("Please enter a valid email address.");
	  eml.focus();
	  return false;
  }
  else if (ctry == "") {
    alert("Please select your country");
    ctry.focus();
  } else {
     fm.submit();
  }
};

function validateLogin() {
	// check userid
	var fmUserID = document.LoginFrm.loginID.value;

	if (fmUserID == "") {
		alert("Please enter your email address.");
		document.LoginFrm.loginID.focus();
		return false;
	}

	// "Email Address" field validation.
	if (!(validateEmailField(document.LoginFrm.loginID, 'Email Address'))) {
          alert("Invalid username.");
          return false;
        }

	// check password
	var fmpsw = document.LoginFrm.pwd.value;

	if (fmpsw == "") {
		alert("Please enter your password.");
		document.LoginFrm.pwd.focus();
		return false;
	}

	if (fmpsw.length < 6) {
		alert("Please enter at least 6 characters in the password field.");
		document.LoginFrm.pwd.focus();
		return false;
	}
	document.LoginFrm.cmd.value = "login";
	return true;
};
function CreateNewForm(){
	var submitForm=document.createElement('FORM');
	document.body.appendChild(submitForm);
	submitForm.method='POST';
	return submitForm;
};
function CreateNewFormElement(inputForm, elementName, elementType, elementValue){
	var newElement=document.createElement('input');			  
	newElement.setAttribute('name',elementName);			  
	newElement.setAttribute('type',elementType);			  
	newElement.setAttribute('value',elementValue);			  
	inputForm.appendChild(newElement);
	return newElement;
};
function GetDOB(dobString){
	var dobarray = dobString.split('/');
	return dobarray;
};
function GetLocation(locationString){//not using anymore, but only to keep this for memory
	var locationarray=locationString.split(',');
	var locationarray_reverse=locationarray.reverse();
	return locationarray_reverse;
};

			


