
// Fields input control

// Patterns
var inpptr = new Object();

inpptr.DATE=/^\d{1,4}-\d{1,2}-\d{1,2}$/;
//inpptr.ANY=/.*/;
//inpptr.PSW=/^[A-Za-z0-9]{6,40}$/;
//inpptr.NUMB=/^\d+$/;
//inpptr.HOUR=/^\d{1,2}$/;
//inpptr.MINUTE=/^\d{1,2}$/;
//inpptr.FNAME=/^([A-ZÀÈÆËÁÐØÛÞ]|[a-zàèæëáðøûþ]| |-)+$/;
//inpptr.LNAME=/^([A-ZÀÈÆËÁÐØÛÞ]|[a-zàèæëáðøûþ]| |-)+$/;
//inpptr.EMAIL=/^.+$/;
//inpptr.FLOAT3=/^\d+(\.\d{1,3})?$/;
//inpptr.FLOAT2=/^\d+(\.\d{1,2})?$/;
//inpptr.IMID=/^(\d{7}|\d{9})$/;
//inpptr.PVM=/^(\d{9}|\d{12})$/;
//inpptr.PHONE=/^[0-9()\-\[\]\+ ]+$/;
//inpptr.FAX=/^[0-9()\-\[\]\+ ]+$/;
//inpptr.DESC=/^([^$@#+><|`~?!*])+$/;
//inpptr.UNAME=/^[A-Za-z0-9]{6,30}$/;
//inpptr.IP=/^\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}$/;
//inpptr.PCODE=/^(\d{11})$/;
//inpptr.PCODEPART=/^(\d{7,11})$/;
//inpptr.DZNR=/^(\d{2})-(\d{6})$/;
//inpptr.UIN=/^([A-ZÀÈÆËÁÐØÛÞ]|[a-zàèæëáðøûþ]|[0-9]){1,10}$/;
//inpptr.UIN5=/^([A-ZÀÈÆËÁÐØÛÞ]|[a-zàèæëáðøûþ]|[0-9]){5}$/;
//inpptr.UNIKALUSNR=/^\d{1,16}$/;




function testgram(value, type)
{
    var pattern = inpptr[type];
    var patres = pattern.exec(value);

    if(!patres){
      return false;
    } else return true;
}

function check_date(source, arguments)
{
    if (arguments == null || !arguments)
    {
        arguments.IsValid=false;
        return;
    }
    var value = arguments.Value;
    var ret;
    gramres = testgram(value, "DATE");
    if( !gramres ){
        arguments.IsValid=false;
        return;
    }
    eval(ret=chk_date(value)); 
    if(!ret){
        arguments.IsValid=false;
        return;
    }
    else{
        arguments.IsValid=true;
        return true;
    }
}

function check_lt_jak(source, arguments)
{
    if (arguments == null || !arguments)
    {
        arguments.IsValid = false;
        return;
    }
    var value = new String(arguments.Value);
    // shitas algoritmas 7-niu simboliu ilgio kodo netikrina
    if (value.length == 7)
    {
        arguments.IsValid = true;
        return;
    }
    // kitas variantas gali buti tik 9-iu simboliu ilgio kodas
    if (value.length != 9)
    {
        arguments.IsValid = false;
        return;
    }
    var sum = 0;
    for(i=0; i<8; i++)
        sum = sum + value.charAt(i) * (i+1);

    if (sum % 11 == value.charAt(8))
    {
        arguments.IsValid = true;
        return;
    }
    else
    {
        arguments.IsValid = false;
        return;
    }   
}

function check_slaptazodis(source, arguments)
{
    if (arguments == null || !arguments)
    {
        arguments.IsValid = false;
        return;
    }
    var passwd = new String(arguments.Value);
   	if (passwd.match(/^[0-9a-z]{32}$/))
	{
        arguments.IsValid = true;
        return;
	}
	else
	{
	    if (!passwd.match(/.{8,}/))
	    {
            arguments.IsValid = false;
            return;
	    }
	    if (!passwd.match(/.[a-zA-Z]/))
	    {
            arguments.IsValid = false;
            return;
	    }
	    if (!passwd.match(/.*\d.*\d/))
	    {
            arguments.IsValid = false;
            return;
	    }
	    if (!passwd.match(/.*[!,?,#,$,&,*]/))
	    {
            arguments.IsValid = false;
            return;
	    }
	}
}

function check_email(source, arguments)
{
    if (arguments == null || !arguments)
    {
        arguments.IsValid=false;
        return;
    }
    var ret;
    eval(ret=emailCheck(arguments.Value)); 
    if(!ret){
        arguments.IsValid=false;
        return;
    }
    else{
        arguments.IsValid=true;
        return true;
    }
}


function chk_date ( date_str )
{
  var system_start_year = 1900;
  var system_start_month = 01;
  
  var month_days = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
  if( date_str.length > 0 )
  {
    if( ( date_str.charAt(4) != '-' )||( date_str.charAt(7) != '-' ) )
    {
       return false;
    }
    var year = Number(date_str.substr( 0, 4 ));
    var month = Number(date_str.substr( 5, 2 ));
    var day = Number(date_str.substr( 8, 2 ));
    if( ( year<1900 ) || ( year>2200 ) || isNaN(year) )
    {
       return false;
    }
    if( ( month<1 ) || ( month>12 ) || isNaN(month) )
    {
       return false;
    }
    /*
    if( (year == system_start_year) && (month < system_start_month) )
    {
       alert( system_start_day_help );
       return false;
    }
    */
    if( !is_leap( year ) ) month_days[ 1 ] = 28; else month_days[ 1 ] = 29;

    if( ( day < 1 ) || ( day > month_days[ month-1 ] ) || isNaN(day) )
    {
       return false;
    }
  }
  return true;
}

function is_leap( year )
{
   /* Determine if the year is a leap year with the algorithm: */
   /* 1.Years evenly divisible by four are normally leap years (e.g. 1996) */
   /* 2.Years also evenly divisible by 100 are not leap years (e.g. 1900)  */
   /* 3.Years also evenly divisible by 400 are leap years (e.g. 2000) */
   return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}
/*
function chk_control(element, type, notreq)
{
    if (element == null || !element)
    {
        return false;
    }
    var value = trim(element.value);
    var ret;
    element.value = value;
    if (((notreq != null) && (value == "")) || (element.disabled == 1)) return true;
    if( (notreq == null) && (value == "") )
    {
       return false;
    }
    gramres = testgram(value, type);
    if( !gramres ){
        return false;
    }
    switch(type)
    {
        case "DATE": eval(ret=chk_date(value)); break;
        case "HOUR": eval(ret=chk_range( 0, 23, value, type )); break;
        case "MINUTE": eval(ret=chk_range( 0, 59, value, type )); break;
        case "EMAIL": eval(ret=chk_email(value)); break;
        case "ANY":
        case "PSW":
        case "NUMB":
        case "FNAME":
        case "LNAME":

        case "IMID":
        case "PHONE":
        case "FAX":
        case "DESC":
        default: ret=true;
    }
    if(!ret){
      try{ element.focus();} catch(evt){}
      return false;
    }
    else return true;
}
*/
/*
function chk_email (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) {
        alert(getLabel("lbl_input_control_email"));
        return false
  }
  var user=matchArray[1]
  var domain=matchArray[2]
  if (user.match(userPat)==null) {
    alert(getLabel("lbl_input_control_email_username"));
    return false
  }
  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null) {
          for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                alert(getLabel("lbl_input_control_email_ip"));
                    return false
            }
      }
      return true
  }
  var domainArray=domain.match(domainPat)
  if (domainArray==null) {
        alert(getLabel("lbl_input_control_email_subnet_name"));
    return false
  }
  var atomPat=new RegExp(atom,"g")
  var domArr=domain.match(atomPat)
  var len=domArr.length
  if (domArr[domArr.length-1].length<2 ||
      domArr[domArr.length-1].length>3) {
    alert(getLabel("lbl_input_control_email_end"));
    return false
  }
  if (len<2) {
     var errStr=getLabel("lbl_input_control_email_computer_name");
     alert(errStr)
     return false
  }
  return true;
}*/

//function is_empty(field)
//{
//    if ( field.disabled == 1 ) return false;
//    if( field.value.length < 1 )
//    {
//        alert(msg_text.EMPTY);
//        try{ field.focus();} catch(evt){}
//        return true;
//    } else return false;
//}


//function trim(inputString) {
//   // Removes leading and trailing spaces from the passed string. Also removes
//   // consecutive spaces and replaces it with one space. If something besides
//   // a string is passed in (null, custom object, etc.) then return the input.
//   if (typeof inputString != "string") { return inputString; }
//   var retValue = inputString;
//   var ch = retValue.substring(0, 1);
//   while (ch == " ") { // Check for spaces at the beginning of the string
//      retValue = retValue.substring(1, retValue.length);
//      ch = retValue.substring(0, 1);
//   }
//   ch = retValue.substring(retValue.length-1, retValue.length);
//   while (ch == " ") { // Check for spaces at the end of the string
//      retValue = retValue.substring(0, retValue.length-1);
//      ch = retValue.substring(retValue.length-1, retValue.length);
//   }
//   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
//      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
//   }
//   return retValue; // Return the trimmed string back to the user
//} // Ends the "trim" function

//function upper( field )
//{
//        return chk_upper(field);
//}

/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us>
Description: This is a quick and dirty password quality meter 
		 written in JavaScript so that the password does 
		 not pass over the network
Revision Author: Dick Ervasti (dick dot ervasti at quty dot com)
Revision Description: Exchanged text based prompts for a graphic thermometer

Password Strength Factors and Weightings

password length:
level 0 (3 point): less than 4 characters
level 1 (6 points): between 5 and 7 characters
level 2 (12 points): between 8 and 15 characters
level 3 (18 points): 16 or more characters

letters:
level 0 (0 points): no letters
level 1 (5 points): all letters are lower case
level 2 (7 points): letters are mixed case

numbers:
level 0 (0 points): no numbers exist
level 1 (5 points): one number exists
level 1 (7 points): 3 or more numbers exists

special characters:
level 0 (0 points): no special characters
level 1 (5 points): one special character exists
level 2 (10 points): more than one special character exists

combinatons:
level 0 (1 points): letters and numbers exist
level 1 (1 points): mixed case letters
level 1 (2 points): letters, numbers and special characters 
					exist
level 1 (2 points): mixed case letters, numbers and special 
					characters exist


NOTE: Because I suck at regex the code below is incomplete and 
	  does not accurately assess the strength of passwords 
	  according to the above factors and weightings
	  
NOTE: Instead of putting out all the logging information,
	  the score, and the verdict it would be nicer to stretch
	  a graphic as a method of presenting a visual strength
	  guage.

************************************************************ */
function testPassword(passwd)
{
        var description = new Array();
        description[0] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=4 width=30 bgcolor=#ff0000></td><td height=4 width=120 bgcolor=tan></td></tr></table></td><td> &nbsp;&nbsp;<b>Labai silpnas</b></td></tr></table>";
        description[1] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=4 width=60 bgcolor=#990000></td><td height=4 width=90 bgcolor=tan></td></tr></table></td><td> &nbsp;&nbsp;<b>Silpnas</b></td></tr></table>";
        description[2] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=4 width=90 bgcolor=#990099></td><td height=4 width=60 bgcolor=tan></td></tr></table></td><td> &nbsp;&nbsp;<b>Pakankamas</b></td></tr></table>";
        description[3] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=4 width=120 bgcolor=#000099></td><td height=4 width=30 bgcolor=tan></td></tr></table></td><td> &nbsp;&nbsp;<b>Stiprus</b></td></tr></table>";
        description[4] = "<table><tr><td><table><tr><td height=4 width=150 bgcolor=#0000ff></td></tr></table></td><td> &nbsp;&nbsp;<b>Labai stiprus</b></td></tr></table>";
        description[5] = "<table><tr><td><table><tr><td height=4 width=150 bgcolor=tan></td></tr></table></td><td> &nbsp;&nbsp;<b></b></td></tr></table>";

		var intScore   = 0
		var strVerdict = 0
		
		// PASSWORD LENGTH
		if (passwd.length==0 || !passwd.length)                         // length 0
		{
			intScore = -1
		}
		else if (passwd.length>0 && passwd.length<5) // length between 1 and 4
		{
			intScore = (intScore+3)
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6)
		}
		else if (passwd.length>7 && passwd.length<12)// length between 8 and 15
		{
			intScore = (intScore+12)
		}
		else if (passwd.length>11)                    // length 16 or more
		{
			intScore = (intScore+18)
		}
		
		
		// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
		if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		{
			intScore = (intScore+1)
		}
		
		if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		{
			intScore = (intScore+5)
		}
		
		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
		}
		
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5)
		}
		
		
		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5)
		}
		
																 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5)
		}
	
		
		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2)
		}

		if (passwd.match(/(\d.*\D)|(\D.*\d)/))                    // [FAILED] both letters and numbers, almost works because an additional character is required
		{
			intScore = (intScore+2)
		}
 
																  // [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2)
		}
	
	
		if(intScore == -1)
		{
		   strVerdict = description[5];
		}
		else if(intScore > -1 && intScore < 16)
		{
		   strVerdict = description[0];
		}
		else if (intScore > 15 && intScore < 25)
		{
		   strVerdict = description[1];
		}
		else if (intScore > 24 && intScore < 35)
		{
		   strVerdict = description[2];
		}
		else if (intScore > 34 && intScore < 45)
		{
		   strVerdict = description[3];
		}
		else
		{
		   strVerdict = description[4];
		}
	
	    document.getElementById("Words").innerHTML= (strVerdict);	
}
// End-->


/*
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Changes:
1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original  */
// -->

function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
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) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//  End -->