


// whitespace characters
var whitespace = " \t\n\r";


function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}


// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)
{
	// Is s empty?
	if (isEmpty(s))
		return true;

	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.
	var i;
	for (i = 0; i < s.length; i++) {   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1)
			return false;
	}

	// All characters are whitespace.
	return true;
}


function ValidateEmail(email)
{
	eaddr = email.value;

	if (isEmpty(eaddr)) {
		alert("You must type in an email address");
		return false;
	}
 
	// is s whitespace?
	if (isWhitespace(eaddr)) {
 		alert("Your email address is invalid");
		return false;
	}

	// there must be >= 1 character before @, so we
	// start looking at character position 1 
	// (i.e. second character)
	var i = 1;
	sLength = eaddr.length;

	// look for @
	while ((i < sLength) && (eaddr.charAt(i) != "@")) {
		i++
	}

	if ((i >= sLength) || (eaddr.charAt(i) != "@")) {
 		alert("Your email address is invalid");
		return false;
	}
	i += 2;

	// look for .
	while ((i < sLength) && (eaddr.charAt(i) != ".")) {
		i++
	}

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (eaddr.charAt(i) != ".")) {
 		alert("Your email address is incomplete");
		return false;
	}

	//check for invalid characters
	var invChar = "/,;"
	for(i=0; i < invChar.length; i++) {
		badChar=invChar.charAt(i)
		if(eaddr.indexOf(badChar,0) > -1) {
			alert("Invalid character ' " + badChar + " '");
			return false;
		}
	}

	//the emailAddrs passes the above conditions
	return true;
} 



function AlertThenHighlight(element, str)
{
	if (isWhitespace(str)==false)
		alert(str);
		
	element.focus();
	element.select();
	return false;
}



function AuthenticateAndLoadURL(form)
{
	if (isWhitespace(form.name.value)) {
		return AlertThenHighlight(form.name, "Your user name is invalid");
	}
	if (isWhitespace(form.pswd.value)) {
		return AlertThenHighlight(form.pswd, "Your password is invalid");
	}


	var message = "/clientpages/" + form.name.value + form.pswd.value + ".htm";
//	alert(message);

	document.location.href = message;

	return false;
}



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,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}



function disableRightClick(e)
{
  var message = "Right click disabled";
  
  if(!document.rightClickDisabled) {  // initialize
    if(document.layers) {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all)) {
    if (e.which==2||e.which==3) {
//      alert(message);
      return false;
    }
  }
  else {
//    alert(message);
    return false;
  }
}
disableRightClick();


