
var defaultEmptyOK = false
// VARIABLE DECLARATIONS

var digits = "0123456789";

var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz_"

var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var OtherLetters = " "

// whitespace characters
var whitespace = " \t\n\r";
	
	

	
	
	function isWhitespace (s) // Returns true if string s is empty or whitespace characters only.
	{
	//alert("whitespace start");
	var i;
    // 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.
    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 isEmpty(s) // Check whether string s is empty.
	{
	return ((s == null) || (s.length == 0))
	}

function CheckLenght(a)
	{
	//alert("lenght start");
	if (a.length <= 10)
	   {
	   //SetTopLocation('MapMeResults.asp?')
	   //Message = "Your MapMe code can be only 25 characters long!, please try again";
	   //alert("to long");
	   return false;
	   }
	else
	   {
	   //alert("lengte ok");
	   return true;
	   };
	   
	}	
function CheckIDLenght(a)
	{
	//alert("lenght start");
	if (a.length == 13)
	   {
	   //SetTopLocation('MapMeResults.asp?')
	   //Message = "Your MapMe code can be only 25 characters long!, please try again";
	   //alert("to long");
	   return false;
	   }
	else
	   {
	   //alert("lengte ok");
	   return true;
	   };
	   
	}
// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphanumericWithSpace (s)//(s, true)
{   var i;
//var CharOKVar = "NotOK"
var StringOKVar = "OK"
    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        var CharOKVar = "NotOK"
		var c = s.charAt(i);
/////////////////////////////////////////////////////////////////////
		for (j = 0; j < digits.length; j++)
		  {
		  if (CharOKVar == "NotOK")
		  	 {
		  	 if (c == digits.charAt(j))
		  	 	{CharOKVar = "OK";}else{CharOKVar = "NotOK";};
		  	 };
		  }
////////////////////////////////////////////////////////////////////
		for (j = 0; j < lowercaseLetters.length; j++)
		  {	
		  if (CharOKVar == "NotOK")
		  	 {
			 if (c == lowercaseLetters.charAt(j))
		  	 	{CharOKVar = "OK";}else{CharOKVar = "NotOK";};
			 }		  
		  }
///////////////////////////////////////////////////////////////////
		for (j = 0; j < OtherLetters.length; j++)
		  {
		  if (CharOKVar == "NotOK")
		  	 {
			 if (c == OtherLetters.charAt(j))
		  	 	{CharOKVar = "OK"}else{CharOKVar = "NotOK";};
			 }		  
		  }
//////////////////////////////////////////////////////////////////
		for (j = 0; j < uppercaseLetters.length; j++)
		  {
		  if (CharOKVar == "NotOK")
		  	 {
			 if (c == uppercaseLetters.charAt(j))
		  	 	{CharOKVar = "OK"}else{CharOKVar = "NotOK";};
			 }		  
		  }
///////////////////////////////////////////////////////////////////	  		  
		if (StringOKVar == "OK")
		   {
		   if (CharOKVar!="OK"){StringOKVar = "NotOK";};
		   }
///////////////////////////////////////////////////////////////////
    }
	if (StringOKVar!="OK")
        return false;
    return true;
}	

//var digits = "0123456789";

//var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"

//var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


function isAlphanumeric (s)//(s, true)
{   var i;
//var CharOKVar = "NotOK"
var StringOKVar = "OK"
    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        var CharOKVar = "NotOK"
		var c = s.charAt(i);
/////////////////////////////////////////////////////////////////////
		for (j = 0; j < digits.length; j++)
		  {
		  if (CharOKVar == "NotOK")
		  	 {
		  	 if (c == digits.charAt(j))
		  	 	{CharOKVar = "OK";}else{CharOKVar = "NotOK";};
		  	 };
		  }
////////////////////////////////////////////////////////////////////
		for (j = 0; j < lowercaseLetters.length; j++)
		  {	
		  if (CharOKVar == "NotOK")
		  	 {
			 if (c == lowercaseLetters.charAt(j))
		  	 	{CharOKVar = "OK";}else{CharOKVar = "NotOK";};
			 }		  
		  }
///////////////////////////////////////////////////////////////////
		for (j = 0; j < uppercaseLetters.length; j++)
		  {
		  if (CharOKVar == "NotOK")
		  	 {
			 if (c == uppercaseLetters.charAt(j))
		  	 	{CharOKVar = "OK"}else{CharOKVar = "NotOK";};
			 }		  
		  }
///////////////////////////////////////////////////////////////////	  		  
		if (StringOKVar == "OK")
		   {
		   if (CharOKVar!="OK"){StringOKVar = "NotOK";};
		   }
///////////////////////////////////////////////////////////////////
    }
	if (StringOKVar!="OK")
        return false;
    return true;
}	

//var digits = "0123456789";

//var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"

//var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}	

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function getRandomNum(lbound, ubound) {
return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar(number, lower, upper, other, extra) {
var numberChars = "0123456789";
var lowerChars = "abcdefghijklmnopqrstuvwxyz";
var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
var charSet = extra;
if (number == true)
charSet += numberChars;
if (lower == true)
charSet += lowerChars;
if (upper == true)
charSet += upperChars;
//if (other == true)
//charSet += otherChars;
return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,
latterNumber, latterLower, latterUpper, latterOther) {
var rc = "";
if (length > 0)
rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
for (var idx = 1; idx < length; ++idx) {
rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
}
return rc;
}
function genPassword()
 {
document.SBForm.txtPassword.value = getPassword(8,false,true,true,true,true,true,true,true,false);
}
