// JavaScript Document
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function validRequired(formField,fieldLabel)
{
  var result = true;
  
  if (formField.value == "")
  {
    alert('Please enter a value for the "' + fieldLabel +'" field.');
    formField.focus();
    result = false;
  }
  
  return result;
}
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
  result = true;
  }

  return result;
}
function validEmail(formField,fieldLabel,required)
{
  var result = true;
  
  if (required && !validRequired(formField,fieldLabel))
    result = false;

  if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
  {
    alert("Please enter a complete email address in the form: name@domain.com");
    formField.focus();
    result = false;
  }
   
  return result;

}
function validLengthof(formField,fieldLabel,minwidth,maxwidth)
{
	var result = true;
	
	if((formField.value.length < minwidth) || (formField.value.length > maxwidth))
	{
		alert('Length of "' + fieldLabel + '" must be between ' + minwidth + ' and ' + maxwidth + ' characters.');
    	formField.focus();
    	result = false;
	}
	
	return result;
}
function validOnlyLengthof(formField,fieldLabel,minwidth,maxwidth)
{
	var result = true;
	
	if((formField.value.length < minwidth) || (formField.value.length > maxwidth))
	{
		alert('Length of "' + fieldLabel + '" must be ' + minwidth + ' characters.');
    	formField.focus();
    	result = false;
	}
	
	return result;
}
function validRequirednospace(formField,fieldLabel)
{
  var result = true;
  
  if (formField.value == "")
  {
    alert('Please enter a value for the "' + fieldLabel +'" field.');
    formField.focus();
    result = false;
  }
  re = /\s/;
  if ( re.test(formField.value) ) {
    alert('Spaces not allowed in "' + fieldLabel + '" field.\nUse underscore \"_\" or dash \"-\" instead.');
	formField.focus();
    result = false;
  }
  return result;
}
function validCheckBoxes(formField,fieldLabel) {
	if (
	formField.checked == false) 
	{
		alert ('You must check "' + fieldLabel +'".');
		return false;
	} else { 	
		return true;
	}
}
function validPasswords(formField1,formField2){
    p1 = formField1.value;
    p2 = formField2.value;    
	if (p1 != p2){      
		alert('Passwords don\'t seem to match. Try again.');      
		return false;    
	} else { 	
		return true;
	}      
}
function validateRegisterForm(theForm)
{
  if (!validRequired(theForm.j_username,"Username"))
    return false;
  if (!validEmail(theForm.email,"Email",true))
    return false;
  if (!validRequired(theForm.j_password,"Password"))
   	return false;
  if (!validRequired(theForm.j_password2,"Second Password"))
   	return false;
  if (!validLengthof(theForm.j_password,"Password",6,16))
   	return false;
  if (!validPasswords(theForm.j_password,theForm.j_password2))
   	return false;
  if (!validCheckBoxes(theForm.uagree,"User Agreement"))
   	return false;
  
  return true;
}
function validateReminderForm(theForm)
{
  if (!validEmail(theForm.email,"Email",true))
    return false;
  
  return true;
}
function validateLoginForm(theForm)
{
  if (!validRequired(theForm.username,"Username"))
    return false;
  if (!validRequired(theForm.password,"Password"))
   	return false;
  
  return true;
}
function validateMemberInfoChangeForm(theForm)
{
  if (!validLengthof(theForm.password,"Password",6,16))
   	return false;
  if (!validOnlyLengthof(theForm.callerid,"Phone",10,10))
   	return false;
  if (!validEmail(theForm.email,"Email",true))
    return false;
  
  return true;
}
function popUpWindowSpec(URLStr, left, top, width, height)
{
  if(popUpWinSpec)
  {
    if(!popUpWinSpec.closed) popUpWinSpec.close();
  }
  popUpWinSpec = open(URLStr, 'popUpWinSpec', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=0,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  window.location.href = '/myaccount/index.cfm';
}