function VerifyForm() {

	// modify v.msgSeparator to change separator between error messages
	this.msgSeparator = '\n';
	
	// modify v.blankValue to change what is considered a "blank" value in the form
	this.blankValue   = '';
	
	// private array for storage of errors
	// don't access directly, use addError() and showErrors() defined below
	this._gripes      = new Array();
	this._StateUSA = /^(A[AEKLPRSZ]|C[AOT]|DC|DE|FL|FM|GA|GU|HI|I[ADLN]|KS|KY|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|SC|SD|T[NTX]|UT|V[AIT]|W[AIVY])$/i; // 63 states/territories
	this._StateCan = /^(AB|BC|MB|N[BFST]|ON|PE|PQ|QC|SK|YT)$/i;  // 13 provinces/territories
	this._Email    = /^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+[a-z]{2,4}|([0-9]{1,3}\.){3}[0-9]{1,3})$/i;
	this._EmailBad = /^(((postmaster|root|hostmaster|mailer-daemon|webmaster)@(isp|frame)\.com)|.*@(.*\.(isp|frame)\.com|localhost\.com|127\.0\.0\.1))$/i;
    this._Country = {
	    us: /^(u\.?s\.?(a\.?)?|united states(\s+of\s+america)?)$/i,
	    ca: /^(ca\.?|can\.?|canada)$/i
	};
	// import functions defined below as methods of this object
	// see below for usage  
	this.addError      = _VerifyForm_addError;
	this.showErrors    = _VerifyForm_showErrors;
	this.hasValue      = _VerifyForm_hasValue;
	this.getValue      = _VerifyForm_getValue;
	this.validEmail    = _VerifyForm_validEmail;
	this.validState    = _VerifyForm_validState;
	this.getCountry    = _VerifyForm_getCountry;
	this.isUSA         = _VerifyForm_isUSA; // deprecated
	this.isCanada      = _VerifyForm_isCanada; // deprecated
	this.getAllValues  = _VerifyForm_getAllValues;
	this.clearFirst    = _VerifyForm_clearFirst;
	this.clearLast     = _VerifyForm_clearLast;
	this.clearAll      = _VerifyForm_clearAll;
	this.setFirst      = _VerifyForm_setFirst;
	this.setLast       = _VerifyForm_setLast;
	this.setAll        = _VerifyForm_setAll;
	this.checkFirst    = _VerifyForm_checkFirst;
	this.checkLast     = _VerifyForm_checkLast;
	this.checkAll      = _VerifyForm_checkAll;
	this.uncheckFirst  = _VerifyForm_uncheckFirst;
	this.uncheckLast   = _VerifyForm_uncheckLast;
	this.uncheckAll    = _VerifyForm_uncheckAll;
	this.isAFM		   = _VerifyAFM;
	this.valUsername	= _VerifyUserName;
	this.valPswd		= _VerifyUserPswd;
	return this;
}

/*==============================================================================
	Ελέγχει αν το username έχει μόνο λατινικούς χαρακτήρες
===============================================================================*/
function _VerifyUserName(c){
	var nbr = parseInt(c.length);
	var reCheck = true;
	var re = /[A-Za-z0-9]/;
	if(c.length<4 || c.length>10) return false;
	else{
		for(var i=0; i<nbr; i++){
			if( !re.test(c.charAt(i)) ){
				reCheck = false;
				break;
			}
		}
	}
	return reCheck;
}

/*==============================================================================
	Ελέγχει αν το username έχει μόνο λατινικούς χαρακτήρες
===============================================================================*/
function _VerifyUserPswd(c){
	var nbr = parseInt(c.length);
	var reCheck = true;
	var re = /[A-Za-z0-9]/;
	if(c.length!=8) return false;
	else{
		for(var i=0; i<nbr; i++){
			if( !re.test(c.charAt(i)) ){
				reCheck = false;
				break;
			}
		}
	}
	return reCheck;
}
/*==============================================================================
	v.addError() method
	adds an error message to queue, brings keyboard focus to first one
	may be modified someday to put a visual indicator next to fields
	field - the actual form field object
	msg - string of error text to show
	no return value	
===============================================================================*/
function _VerifyForm_addError (field, msg) {
  if ( ! this._gripes.length) {
    // IE 4.x Mac bug workaround: "object.method" produces error
    // instead of returning true when method exists!!!
    // therefore we also test for field.all here
    if (field.all || field.focus)
      field.focus();
    if (/(password|text|textarea)/.test(field.type) && (field.all || field.select))
      field.select();
  }
  this._gripes[this._gripes.length] = msg;
}
/*==============================================================================
	v.showErrors() method
	when done checking for errors, call this to do alert popup
	head - text to put above error msgs
	foot - text to put below error msgs
	returns true (ok) if no errors, false if there were errors
===============================================================================*/
function _VerifyForm_showErrors (head, foot) {
  if (this._gripes.length) {
    alert((head ? head + this.msgSeparator : '') + this._gripes.join(this.msgSeparator) + (foot ? this.msgSeparator + foot : ''));
    return false;
  }
  return true;
}

/*==============================================================================
	v.hasValue() method
	check if field has a value
	field - the actual form field object
	returns true/false
===============================================================================*/
function _VerifyForm_hasValue (field) {
  if ( ! field.type && field.length ) {
    for (var i = 0; i < field.length; i++)
      if (field[i].type && this.hasValue(field[i]))
        return true;
    return false;
  }
  if (/select/.test(field.type))
    return (field.selectedIndex != -1 && (field.options[field.selectedIndex].value != this.blankValue));
  if (/(checkbox|radio)/.test(field.type))
    return ( field.checked && (field.value != this.blankValue) );
  if (/(button|reset|submit)/.test(field.type))
    return false;
  return (field.value != this.blankValue)
}

/*==============================================================================
	v.getValue() method
	get value of field if there is a value
	field - the actual form field object
	returns value or null
	note: on multi-valued fields, returns only the first value encountered
===============================================================================*/
function _VerifyForm_getValue (field) {
  if ( ! field.type && field.length ) {
    for (var i = 0; i < field.length; i++) {
      if (field[i].type) {
        var value = this.getValue(field[i]);
        if (value) return value;
      }
    }
    return null;
  }
  if (/select/.test(field.type))
    return ( (field.selectedIndex != -1 && (field.options[field.selectedIndex].value != this.blankValue))
      ? field.options[field.selectedIndex].value : null );
  if (/(checkbox|radio)/.test(field.type))
    return ( (field.checked && (field.value != this.blankValue)) ? field.value : null );
  return ( ( ! /(button|reset|submit)/.test(field.type) && (field.value != this.blankValue)) ? field.value : null )
}

/*==============================================================================
	v.getAllValues() method
	get values of field if there are values, designed for multi-valued fields
	field - the actual form field object
	returns array of values or empty array
===============================================================================*/
function _VerifyForm_getAllValues (field) {
  var arr = new Array();
  if ( ! field.type && field.length ) {
    var temparr;
    for (var i = 0; i < field.length; i++) {
      if (field[i].type) {
        temparr = this.getAllValues(field[i]);
        for (var j = 0; j < temparr.length; j++)
          arr[arr.length] = temparr[j];
      }
    }
  }
  else if (/select/.test(field.type)) {
    for (var i = 0; i < field.length; i++)
      if (field.options[i].selected && (field.options[i].value != this.blankValue))
        arr[arr.length] = field.options[i].value;
  }
  else if (/(checkbox|radio)/.test(field.type) && field.checked && (field.value != this.blankValue))
    arr[arr.length] = field.value;
  else if ( ! /(button|reset|submit)/.test(field.type) && (field.value != this.blankValue))
    arr[arr.length] = field.value;
  return arr;
}
/*==============================================================================
	v.validEmail() method
	check if email looks valid
===============================================================================*/
function _VerifyForm_validEmail (e) { return ( this._Email.test(e) && ! this._EmailBad.test(e) ) }

/*==============================================================================
	v.validState() method
	check if state/province abbreviation looks valid for supplied country
===============================================================================*/
function _VerifyForm_validState (s, c) { return ( this.isUSA(c) ? this._StateUSA.test(s) : (this.isCanada(c) ? this._StateCan.test(s) : true) ) }

/*==============================================================================
	v.isUSA() method
	check if country looks like USA
	this is now deprecated, use v.getCountry(c, 'us') instead
===============================================================================*/
function _VerifyForm_isUSA (c) { return ( this._Country.us.test(c) ) } // deprecated

/*==============================================================================
	v.isCanada() method
	check if country looks like Canada
	this is now deprecated, use v.getCountry(c, 'ca') instead
===============================================================================*/
function _VerifyForm_isCanada (c) { return ( this._Country.ca.test(c) ) } // deprecated

/*==============================================================================
	v.getCountry() method
	check if country matches given list of 2-letter country abbreviations
	returns matching abbreviation (also true) or null (also false)
===============================================================================*/
function _VerifyForm_getCountry (c) {
  for (var i = 1; i < arguments.length; i++)
    if (this._Country[arguments[i]] && this._Country[arguments[i]].test(c))
      return arguments[i];
  return null;
}

/*==============================================================================
	v.clear/set/check/uncheckFirst/Last/All() methods
	modify the value or checked/selected status of a field
	giving 'val' clrs/sets/checks/unchks first/last/all values that match val
	if no val is given, clrs/sets/checks/unchks first/last/all item(s) period
===============================================================================*/
function _VerifyForm_clearFirst (field, val) { return this._setField(field,  1, val, this.blankValue, true) }
function _VerifyForm_clearLast  (field, val) { return this._setField(field, -1, val, this.blankValue, true) }
function _VerifyForm_clearAll   (field, val) { return this._setField(field,  0, val, this.blankValue, true) }
function _VerifyForm_setFirst     (field, toval, val) { return this._setField(field,  1, val, toval,  true) }
function _VerifyForm_setLast      (field, toval, val) { return this._setField(field, -1, val, toval,  true) }
function _VerifyForm_setAll       (field, toval, val) { return this._setField(field,  0, val, toval,  true) }
function _VerifyForm_checkFirst   (field, val)        { return this._setField(field,  1, val,  true, false) }
function _VerifyForm_checkLast    (field, val)        { return this._setField(field, -1, val,  true, false) }
function _VerifyForm_checkAll     (field, val)        { return this._setField(field,  0, val,  true, false) }
function _VerifyForm_uncheckFirst (field, val)        { return this._setField(field,  1, val, false, false) }
function _VerifyForm_uncheckLast  (field, val)        { return this._setField(field, -1, val, false, false) }
function _VerifyForm_uncheckAll   (field, val)        { return this._setField(field,  0, val, false, false) }

/*==============================================================================
	internal method used above, do not call directly, use above methods instead
===============================================================================*/
function _VerifyForm__setField    (field, whichway, val, toval, valueorcheck) {
  var retval = false;
  if ( ! field.type && field.length ) {
    for (var i = (whichway == 1 ? 0 : field.length - 1); i < field.length && i >= 0; i += (whichway || -1))
      if (field[i].type && this._setField(field[i], whichway, val, toval, valueorcheck))
        if (whichway) return true;
        else retval = true;
    return retval;
  }
  if (valueorcheck) {
    if (/(file|password|text)/.test(field.type) && (typeof val != 'string' || field.value == val)) {
      field.value = toval;
      return true;
    }
  }
  else if (/select/.test(field.type)) {
    for (var i = (whichway == 1 ? 0 : field.length - 1); i < field.length && i >= 0; i += (whichway || -1)) {
      if ( typeof val != 'string' || field.options[i].value == val) {
        field.options[i].selected = toval;
        if (whichway) return true;
        else retval = true;
      }
    }
    return retval;
  }
  else if (/(checkbox|radio)/.test(field.type) && (typeof val != 'string' || field.value == val)) {
    field.checked = toval;
    return true;
  }
  return false
}

/*==============================================================================
	ΑΦΜ 
	Author: Sotiris,	Created: Τετάρτη, 27 Απριλίου 2005 11:53:57 μμ
===============================================================================*/

function _VerifyAFM(formElmObj){
	
	var afm = new String(formElmObj.value);
	var afmLen = afm.length
	var iCheckDigit = 0;
	
	if ((afmLen < 8) || afmLen >9){
		return false;
	}
			
	if (afmLen == 8){
		afm = "0"+afm;
		afmLen = afm.length
	}	
			
	var tot = 0;
	
	for (var i=0; i<afmLen-1; i++){
		if( isNaN(afm.charAt(i)) ){
			return false;
		}
		tot +=  parseInt(afm.charAt(i)) * Math.pow(2, (9-(i+1)));
	}

	iCheckDigit = (tot%11);
	
	if( iCheckDigit==10 ){
		iCheckDigit = 0
	}
	
	if ( iCheckDigit == parseInt(afm.charAt(8)) ){
		return true;
	}else{
		return false;
	}
	return true;
}

