

var digits = "0123456789";
var digitstel = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var lowercaseLettersGr = "αβγδεζηθικλμνξοπρστυφχψωάέήίόύώϊϋς"
var uppercaseLettersGr = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ’ΈΌΉΎΏΊ"
var whitespace = " \t\n\r ";
var decimalPointDelimiter = ",";

var defaultEmptyOK = false;

var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;


function	UncheckGR()
{
	
}

function	UncheckEU()
{
	
}

function	CheckOnly3Sports()
{
counter=0;

for (i=1;i<37;i++)
{
eval("if (document.forms[0].af_sport"+i+".checked==true)	counter++;");
}
if (counter>3)	
	{
	alert(Lang ? "  Please fill up to three sport categories\n " : "  Παρακαλώ υποδείξτε έως τρία αθλήματα\n ")
	for (i=1;i<37;i++)
		{
		eval("document.forms[0].af_sport"+i+".checked=false");
		}
	}
}

function	CheckOnly1DayGroup()
{
counter=0;

for (i=1;i<4;i++)
{
eval("if (document.forms[0].af_nod"+i+".checked==true)	counter++;");
}
if (counter>1)	
	{
	alert(Lang ? "  Please choose one selection.\n " : "  Παρακαλώ επιλέξτε μία επιλογή.\n ")
	for (i=1;i<4;i++)
		{
		eval("document.forms[0].af_nod"+i+".checked=false");
		}
	}
}

function	CheckOnly3Jap()
{
counter=0;

for (i=1;i<18;i++)
{
eval("if (document.forms[0].af_jap"+i+".checked==true)	counter++;");
}
if (counter>3)	
	{
	alert(Lang ? "  Please mark up to three (3) areas\n " : "  Παρακαλώ υποδείξτε μέχρι τρεις (3) τομείς\n ")
	for (i=1;i<18;i++)
		{
		eval("document.forms[0].af_jap"+i+".checked=false");
		}
	}
}


function FullCheck(sIn, sDispName,  bNumbers, nLetters, nMinimum) 
{
	sIn = trim(sIn);
	if (isEmpty(sIn) && nMinimum>0) {
		return sDispName + (Lang ? ": The field is mandatory.\n" : ": Το πεδίο πρέπει να συμπληρωθεί.\n");
	}
	else {
		var nLen = sIn.length, i, c;
	
		if (nLen < nMinimum) return sDispName + (Lang ? ":  The field must have at least " + nMinimum + " characters.\n" : ": Το πεδίο πρέπει να έχει τουλάχιστον " + nMinimum + " χαρακτήρες.\n");

		bOK = false;
		for (i = 0; i < nLen; i++) {   
			c = sIn.charAt(i);
			bOK = false;
			if (c != ' ') {
			if (bNumbers == 1 && c >= "0" && c <= "9") bOK = true;
			if (bNumbers == 0 && nLetters == 0) if (uppercaseLetters.indexOf(c) >= 0 || lowercaseLetters.indexOf(c) >= 0) bOK = true;
			if (bNumbers == 0 && nLetters == 1) if (uppercaseLettersGr.indexOf(c) >= 0 || lowercaseLettersGr.indexOf(c) >= 0) bOK = true;
			if (bNumbers == 0 && nLetters == 2) if (uppercaseLettersGr.indexOf(c) >= 0 || lowercaseLettersGr.indexOf(c) >= 0 || uppercaseLetters.indexOf(c) >= 0 || lowercaseLetters.indexOf(c) >= 0) bOK = true;
			if (bNumbers == 1 && nLetters == 2) bOK = true;
			if (!bOK) return sDispName + (Lang ? ": The field is not valid.\n" : ": Το πεδίο δεν είναι έγκυρο.\n");
			}
		}
	}
	return true;
}

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or whitespace characters only.
function isWhitespace (s)
{   var i;

    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}

// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Removes all whitespace characters from s.
function stripWhitespace (s) {   
   return stripCharsInBag (s, whitespace)
}

// Returns true if character c is a letter 
function isLetter (c, flag) {   
	if (flag & 1) if (uppercaseLetters.indexOf(c) >= 0) return true;
	if (flag & 2) if (lowercaseLetters.indexOf(c) >= 0) return true;
	if (flag & 4) if (uppercaseLettersGr.indexOf(c) >= 0) return true;
	if (flag & 8) if (lowercaseLettersGr.indexOf(c) >= 0) return true;
}

// Returns true if character c is a digit 
function isDigit (c) {
   return ((c >= "0") && (c <= "9"))
}

// isInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if all characters in string s are numbers.
function isInteger (s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// Returns true if all characters are numbers.  First character is allowed to be + or - as well.
function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

// isFloat (STRING s [, BOOLEAN emptyOK])
// True if string s is an unsigned floating point (real) number. 
function isFloat (s)
{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    return true;
}

// isAlphabetic (STRING s, allowWhite, letterFlag [, BOOLEAN emptyOK])
function isAlphabetic (s, allowWhite, letterFlag)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 3) return defaultEmptyOK;
       else return (isAlphabetic.arguments[3] == true);


    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isLetter(c, letterFlag)) {
	     if (allowWhite) {
              if (!isWhitespace(c)) return false;
           } else
              return false;
        }
    }

    return true;
}

// isAlphanumeric (STRING s, allowWhite, letterFlag [, BOOLEAN emptyOK])
function isAlphanumeric (s, allowWhite, letterFlag)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 3) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[3] == 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++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c, letterFlag) || isDigit(c) ) )
        {
	     if (allowWhite) {
              if (!isWhitespace(c)) return false;
           } else
              return false;
        }
    }

    // All characters are numbers or letters.
    return true;
}

// isTelephone (STRING s, allowWhite [, BOOLEAN emptyOK])
function isTelephone (s)
{   var i;

    if (isEmpty(s)) 
       if (isTelephone.arguments.length == 3) return defaultEmptyOK;
       else return (isTelephone.arguments[3] == true);


    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (digitstel.indexOf(c)==-1)
              return false;
    }

    return true;
}


// isEmail (STRING s [, BOOLEAN emptyOK])
function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    if (isWhitespace(s)) return false;
    
    var splitted = s.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
      }
}

// isYear (STRING s [, BOOLEAN emptyOK])
function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 3) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[3] == true);

    if (!isInteger(s, false)) return false;

    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

// isDay (STRING s [, BOOLEAN emptyOK])
function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

// daysInFebruary (INTEGER year)
function daysInFebruary (year)
{
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// isDate (STRING year, STRING month, STRING day)
function isDate (year, month, day)
{ 
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}
function trim(str) {
i=0;
while(i<=str.length && str.charAt(i)==" "){
i++;
}
return str.substr(i,str.length);
}
function integerTrim(n) {
s = n.toString(2);
var ret = s;
if(s.length==2) {
if(s.substr(0,1)=='0') {
ret=s.substr(1,2)
}
}
return ret;
}

