<!--
// Constants

var pEmail='Please enter your Email Address here.  It is your logon id.';
var pPassword='Please enter your Password. (must be 4 or more characters)\n';
var pReset='Please Press Reset to clear the screen.\n';
var pLogin='Press Login when you have entered your Email and Password.';

// Error Messages
var errPassword='Please enter your password.\n';
var errEmail='Please enter your Email address in the format: EmailId@Isp.Domain.\n';

// whitespace characters
var cWhitespace = " \t\n\r";

// constants
var sLogin = "TemplateLogin";
var sLogout = "TemplateLogout";


function InitForm() {

    var hasLoginTemplate = false;

    for (var i=0; i <= document.form.elements.length; i++) {	
	   if (document.form.element[i].name == "frmLoginTemplate") {
	      hasLoginTemplate = true;	   
	   }		
	}

    if (hasLoginTemplate == true) {
	    var obj = document.forms["frmLoginTemplate"];	
	    //obj.inpEmail.value = sEmail;
	    obj.inpEmail.value = "";
	    obj.inpEmail.focus();	
	    //document.forms.frmLogin.inpEmail.focus();		
     }
}

function TemplateEditAndSubmitForm(obj, btnPressed){

	var bPassedEdits='true';
	var sErrMsg='';

	if (btnPressed == sLogin)
	{
		if (!isEmail(obj.inpEmail.value)){
			sErrMsg += errEmail;
			bPassedEdits=false;
			objFocusObject = obj.inpEmail;
		}
	
		if (!isPassword(obj.inpPassword.value)){
			sErrMsg += errPassword;
			if (bPassedEdits){
				bPassedEdits=false;
				objFocusObject = obj.inpPassword;
			}
		}
	}

	if (bPassedEdits) {
	
        var strFormName;

		if (btnPressed == sLogin)
		{
			strFormName = "frmLoginTemplate";
		}
		else
		{
			strFormName = "frmLogoutTemplate";
		}

       document.forms[strFormName].submit();

	}
	else {
		alert (sErrMsg);
		objFocusObject.focus();
	}
}

// Returns true if string sStr is empty or 
// whitespace characters only.

function isWhitespace (sStr){

	var i;
	var cChar;

    if (isEmpty(sStr)) 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.

    for (i = 0; i < sStr.length; i++)
    {   
        // Check that current character isn't whitespace.
        cChar = sStr.charAt(i);

        if (cWhitespace.indexOf(cChar) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Check whether string sStr is empty.

function isEmpty(sStr){
	return ((sStr == null) || (sStr.length == 0))
}

// Display prompt string sPrompt in status bar.
function Prompt (sPrompt){
   window.status = sPrompt;
}
// Password must be at least 5 characters long.

function isLoginId (sStr) {
   
    if (isWhitespace(sStr)) return false;
    
	if (sStr.length<1) return false;

	return true;
}

// Password must be at least 5 characters long.


function isEmail (sStr) {
   
    // is sStr whitespace?
    if (isWhitespace(sStr)) return false;
    
    // there must be >= 1 character before @, so look at character position 1 (i.e. second character)
    var i = 1;
    var iLength = sStr.length;

    // look for @
    while ((i < iLength) && (sStr.charAt(i) != "@")){
		i++;
    }

    if ((i >= iLength) || (sStr.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < iLength) && (sStr.charAt(i) != ".")){
		i++
    }

    // there must be at least one character after the .
    if ((i >= iLength - 1) || (sStr.charAt(i) != "."))
		return false;
    else
		return true;
}

function isPassword (sStr) {
   
    if (isWhitespace(sStr)) return false;
    
	if (sStr.length<3) return false;

	return true;
}

// Returns true if string sStr is empty or 
// whitespace characters only.

function isWhitespace (sStr){

	var i;
	var cChar;

    if (isEmpty(sStr)) 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.

    for (i = 0; i < sStr.length; i++)
    {   
        // Check that current character isn't whitespace.
        cChar = sStr.charAt(i);

        if (cWhitespace.indexOf(cChar) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Check whether string sStr is empty.

function isEmpty(sStr){
	return ((sStr == null) || (sStr.length == 0))
}

// Display prompt string sPrompt in status bar.
function Prompt (sPrompt){
   window.status = sPrompt;
}

//-->


