//JS scripts for lps_platform page class - php_page.php

//(c)2009 Bruce G. Mills, www.lonepinestudio.com
//all rights reserved.
/***
This script is licensed for use exclusively by authorized customers of Bruce G. Mills for use under a single
designated URL. Unless otherwise stated, the right to use this script is "as is" basis without warranty or 
guarantee, express, implied or otherwise. It may not be copied, moved, sold or passed on by transfer
of ownership without the written permission of Bruce G. Mills, bruce@lonepinestudio.com By accepting the installation 
of this file, the licensee accepts sole responsibility for determining the appropriateness and acceptability of its 
intended use, for insuring compliance with the terms of this notice and for the tems of any additional development or 
site licensing agreements with Bruce G. Mills. 
***/

loginForms = true;

$("login_fields").submit(function () { return false; });

$(function() {
   if ( (f1 = $('input#getFI1')) ) f1.bind('keypress',capsLock);
   if ( (f2 = $('input#getFI2')) ) f2.bind('keypress',capsLock);
   if ( (d1 = $('div#capslock')) ) d1.hide();
 });

function captureKey(event)
{
	var key = event.keyCode;
	if (key == 13)
	{
		//alert("key: "+key);
		chkForm(13);
	}	
}

function chkForm(key)
{
	//alert("checking form");	
	if ( key == 13 && (chk = setLoginFields()) )
	{
		//alert("form validated for submit");		
		document.submit_login.submit();
		return true;
	}
	else return false;
}

function chkLoginFields(field)
{
	fieldNo = null;
	fieldId = null;
	fv=null;
	if (field == 'un') 
	{
		fieldNo = 1;
		fieldId = $('input#getFI1');
	}
	else if (field == 'pw') 
	{
		fieldNo = 2;
		fieldId = $('input#getFI2');		
	}
	if ( (fv = fieldId.attr('value')) )
	{	
		if ( typeof(fv) != 'string' || fv.length < 1 )
		{
			alert("An entry in field "+fieldNo+" is required.");
			fieldId.focus();
			return false;
		}
		else if ( !isSpace(fv) )
		{
			alert("The entry in field "+fieldNo+" cannot contain spaces.");
			fieldId.focus();
			return false;
		}
		else if ( !isAlphaExt(fv) )
		{
			alert("The entry in field "+fieldNo+" may only consist of alphanumeric characters including hyphens and underscores.");
			fieldId.focus();
			return false;
		}
		else if ( fv.length > 16 || fv.length < 6 )
		{
			alert("The entry in field "+fieldNo+" must be between 6 and 16 characters in length.");
			fieldId.focus();
			return false;
		}
		else return true;
	}
	else return false;
}

function setLoginFields()
{	
	var key = $('input#fkey').attr('value');
	var fv1 = $('input#getFI1').attr('value');
	var fv2 = $('input#getFI2').attr('value');
	var len1 = fv1.length;
	var len2 = fv2.length;
	if ( !(chk = chkLoginFields("un")) )
	{
		return false;
	}
	else if ( !(chk = chkLoginFields("pw")) )
	{
		return false;
	}
	else
	{
		//alert("setting login fields");
		$('input#inStr1').attr('value',stringToHex(des(key,fv1,1,0,null,0)));
		$('input#inLen1').attr('value',len1);

		$('input#inStr2').attr('value',stringToHex(des(key,fv2,1,0,null,0)));
		$('input#inLen2').attr('value',len2);
		
		return true;
	}
}

//alert("login forms loaded");



