function InputCheck(debug) {
	this.debug = debug;
}

/**
 * Két dátumot hasonlit össze
 * @param {string} id
 * @return bool
 */
InputCheck.prototype.datumOsszehasonlito = function(elotteEv,elotteHo,elotteNap,utanaEv,utanaHo,utanaNap) {
	try{ 
		var hiba = false;
		var elotteDate = new Date(elotteEv,elotteHo,elotteNap).getTime();
		var utanaDate = new Date(utanaEv,utanaHo,utanaNap).getTime();
		if( utanaDate-elotteDate < 0 ) hiba = true;
		return hiba;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.datumOsszehasonlito()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * visszadja, hogy a parameterkent atadott datum valos datum-e
 * @param integer ev
 * @param integer ho
 * @param integer nap
 * @return 
 */
InputCheck.prototype.datumInputCheck = function(y, m, d) {
	try{ 
		with (new Date(y, m-1, d))
		return (getMonth()==m-1 && getDate()==d); 
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.datumInputCheck()' + ' - ' + exception.message);
		return true;
	}
}

/**
 * visszadja, hogy a parametrekent atadott ertek szam-e
 * @param {Object} ob
 * @return bool true, ha nem szam, egyebkent false
 */
InputCheck.prototype.szamInputCheck = function(ob) {
	try{ 
		if (isNaN(ob)) return true; else return false; 
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.szamInputCheck()' + ' - ' + exception.message);
		return true;
	}
}


/**
 * ellenorzi, hogy csak szám-e
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.szamValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("[^0-9]","g");
		
		if (!bemeno.match(pattern)) {
			return true;
		} else {
			return false;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.checkedSzinez()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * csak számot enged, úgy hogy az első karakter(ek) nem lehet(nek) 0 értékű(ek).
 * @param {mix} ob or string
 * @return string
 */
InputCheck.prototype.csakSzam = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("[^0-9]","g");
		bemeno = bemeno.replace(pattern, "");
		
		var pattern = new RegExp("^([0]+)?([1-9][0-9]*)$","g");
		bemeno = bemeno.replace(pattern, "$2");  
		
		var pattern = new RegExp("^[0]+$","g");
		kimeno = bemeno.replace(pattern, "");  
		
		if (input==true) ob.value = kimeno;
		else return  kimeno;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.csakSzam()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * csak számot enged, úgy hogy az első karakter(ek) lehet(nek) 0 értékű(ek).
 * @param {mix} ob or string
 * @return string
 */
InputCheck.prototype.csakSzamOis = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("[^0-9]","g");
		kimeno = bemeno.replace(pattern, "");  
		
		if (input==true) ob.value = kimeno;
		else return  kimeno;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.csakSzam()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * beformázza a paraméterezett számot ezres kötegekbe szóköz karakterrel elválasztva
 * @param {Object} ob
 * @return string
 */
InputCheck.prototype.ezresCsoport = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		bemeno = this.csakSzam(bemeno);
		
		var pattern = new RegExp("([0-9])(?=([0-9]{3})+(?![0-9]))","g");
		kimeno = bemeno.replace(pattern, "$1 ");
		
		if (input==true) ob.value = kimeno;
		else return  kimeno;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.ezresCsoport()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * csak bankszámlához szükséges számot és kötőjelet enged
 * @param {mix} ob or string
 * @return string
 */
InputCheck.prototype.csakBankszamlaszam = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("[^-0-9]","g");
		kimeno = bemeno.replace(pattern, "");
		
		if (input==true) ob.value = kimeno;
		else return  kimeno;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.csakBankszamlaszam()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * beformázza a karakterszámsort úgy, hogy rendszámformátum beírása lehet csak ABC123
 * @param {mix} ob or string
 * @return string
 */
InputCheck.prototype.rendszamraFormazas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		pattern = new RegExp("[^0-9a-zA-z]","g");
		bemeno = bemeno.replace(pattern, "");
		
		pattern = new RegExp("^[0-9]{1,}","g");
		bemeno = bemeno.replace(pattern, "");
		
		pattern = new RegExp("^([a-zA-Z]{1})[0-9]{1,}","g");
		bemeno = bemeno.replace(pattern, "$1");
		
		pattern = new RegExp("^([a-zA-Z]{2})[0-9]{1,}","g");
		bemeno = bemeno.replace(pattern, "$1");
		
		pattern = new RegExp("^([a-zA-Z]{3})[^0-9]{1,}","g");
		bemeno = bemeno.replace(pattern, "$1");
		
		pattern = new RegExp("^([a-zA-Z]{3}[0-9])[^0-9]{1,}","g");
		bemeno = bemeno.replace(pattern, "$1");
		
		pattern = new RegExp("^([a-zA-Z]{3}[0-9]{2})[^0-9]{1}","g");
		kimeno = bemeno.replace(pattern, "$1");
		  
		if (input==true) ob.value = kimeno;
		else return  kimeno;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.rendszamraFormazas()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * levalidálja hogy a kapott sztring ABC123 formátum-e
 * @param {mix} ob or string
 * @return string
 */
InputCheck.prototype.rendszamValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		pattern = new RegExp("[a-zA-Z]{3}[0-9]{3}","g");
		if (bemeno.match(pattern)) {
			return true;
		} else {
			return false;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.rendszamValidalas()' + ' - ' + exception.message);
		return true;
	}
}

/**
 * beformázza a karakterszámsort úgy, hogy 8asával kötegelve betesz egy kötőjelet kivéve a végére
 * @param {mix} ob or string
 * @return string
 */
InputCheck.prototype.bankszamlaszamraFormazas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		pattern = new RegExp("[^0-9]","g");
		bemeno = bemeno.replace(pattern, "");
		
		var pattern = new RegExp("([0-9]{8})(?=[0-9])","g");
		kimeno = bemeno.replace(pattern, "$1-");
		
		if (input==true) ob.value = kimeno;
		else return  kimeno;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.bankszamlaszamraFormazas()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * levalidálja hogy valós bankszámlászám-e, 8-8[-8]
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.bankszamlaszamValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("^[0-9]{8}-?([0-9]{8}-?)+$","g");
		if (bemeno.match(pattern)) {
			return true;
		} else {
			return false;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.bankszamlaszamraFormazas()' + ' - ' + exception.message);
		return true;
	}
}

InputCheck.prototype.bankszamlaszamEllenorzo = function( ba ) {
	try {
		var numbers = "0123456789", tmp;
		var multipliers = "9731";
	
		var pattern = new RegExp("[^0-9]","g");
		tmp = ba.replace(pattern, "");

		for ( i = 0; i < tmp.length; i++ ) {
			nextchar = tmp.charAt(tmp.length-1-i);
			if (numbers.indexOf(nextchar) == -1) {
				alert('Hibás bankszámlaszám formátum!');
				return false;
			}
		}
		
		if ( tmp.length != 0 ) {
			i = 0;
			sum = 0;
			checksum = 	0;
			for (groups = 0; groups <= 1;  groups++) {			
				if ( groups == 0 ) {
					group_length = 8;
				} else {
					group_length = tmp.length-8;
				}
				group_start = groups*8;
				for ( i = group_start; i < (group_start + group_length); i++ ) {
					sum += parseInt(tmp.charAt(i)) * parseInt(multipliers.charAt((i % 4)));
				}
				checksum = sum % 10;
			}
			if ( checksum != 0 ) {
				alert("Hibás a bankszámlaszám ellenőrző összege!");
				return false;
			}
		}
		return true;
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.bankszamlaszamEllenorzoSzamosValidalas()' + ' - ' + exception.message);
		return true;
	}
}   

/**
 * levalidálja, hogy valós emailcím-e
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.emailValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("^[a-z0-9][-a-z0-9_.]*[a-z0-9]@[a-z0-9][-a-z0-9.]*[a-z0-9][.][a-z0-9]{2,10}$","ig");
		var pattern2 = new RegExp("[-._][-._]","g");
		if (bemeno.match(pattern) && !bemeno.match(pattern2)) {
			return true;
		} else {
			return false;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.emailValidalas()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * levalidálja, hogy valós telefonszám-e
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.telValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		// EK = engedett karakterek [-/ ] több menyiségben
		
		//+1[2] EK (1[2]) EK 123[4] EK 123
		var pattern = new RegExp("^([+]?[0-9]{1,2}[ -/]*)?[(][0-9]{1,2}[)][ -/]*[0-9]{3,4}[ -/]*[0-9]{3}$","ig");
		//+1[2] EK 1[2] EK 123[4] EK 123
		var pattern2 = new RegExp("^([+]?[0-9]{1,2}[ -/]*)?[0-9]{1,2}[ -/]*[0-9]{3,4}[ -/]*[0-9]{3}$","ig");
		
		//+1[2] EK (1[2]) EK 123 EK 12 EK 12
		var pattern3 = new RegExp("^([+]?[0-9]{1,2}[ -/]*)?[(][0-9]{1,2}[)][ -/]*[0-9]{3}[ -/]*[0-9]{2}[ -/]*[0-9]{2}$","ig");
		//+1[2] EK 1[2] EK 123 EK 12 EK 12
		var pattern4 = new RegExp("^([+]?[0-9]{1,2}[ -/]*)?[0-9]{1,2}[ -/]*[0-9]{3}[ -/]*[0-9]{2}[ -/]*[0-9]{2}$","ig");
		
		if (bemeno.match(pattern) || bemeno.match(pattern2) || bemeno.match(pattern3) || bemeno.match(pattern4)) {
			return true;
		} else {
			return false;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.telValidalas()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * levalidálja, hogy valós telefonszám-e, de előre engedett formátumra
 * @example +12-12-123-567 v. 12-12-123-456a v. 12-123-456 v. 12-1234-567 v. 1-1234-567 v. 1-123-467
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.szigoruTelValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		// EK = engedett karakterek [-] egy menyiségben
		//+1[2] EK 1[2] EK 123[4] EK 123 
		//pl.: +12-11-123-567 v. 12-12-123-567 v. 12-123-456 v. 12-1234-567 v. 1-1234-567 v. 1-123-467
		var pattern = new RegExp("^([+]?[0-9]{2}[-])?[0-9]{1,2}[-][0-9]{3,4}[-][0-9]{3}$","ig");
		
		if (bemeno.match(pattern)) {
			return true;
		} else {
			return false;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.szigoruTelValidalas()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * levágja jobbról és balról az egyszerű whitespace karaktereket [ \f\n\r\t\v] 
 * \  space karakter
 * \f lapemelés
 * \n soremelés
 * \r kocsi-vissza 
 * \t tabulátor
 * \v függőleges tabulátor
 * @param {mix} ob or string
 * @return str
 */
InputCheck.prototype.trim = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("^\\s+$","g");
		bemeno = bemeno.replace(pattern, "");
		
		var pattern = new RegExp("^\\s*((\\s*\\S+)+)\\s*$","g");
		kimeno = bemeno.replace(pattern, "$1");
		
		if (input==true) ob.value = kimeno;
		else return  kimeno;
		
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.trim()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * ellenorzi, hogy ket tagu e a szó
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.ketTag = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("\\S+ +\\S+","g");
		
		if (bemeno.match(pattern)) {
			return true;
		} else {
			return false;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.ketTag()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * levalidálja, hogy valós személyi igazolványszám-e
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.szemigValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		//AB123456
		var pattern = new RegExp("^[a-z]{2}[0-9]{6}$","ig");
		//123456AB
		var pattern2 = new RegExp("^[0-9]{6}[a-z]{2}$","ig");
		//AA-VIII.123456
		var pattern3 = new RegExp("^[a-z]{2}[- ]*(I|II|III|IV|V|VI|VII|VIII|IX|X)[. ]*[0-9]{6}$","ig");
		if (bemeno.match(pattern) || bemeno.match(pattern2) || bemeno.match(pattern3)) {
			return true;
		} else {
			return false;
		}
		
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.szemigValidalas()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * levalidálja, hogy valós személyi igazolványszám-e
 * @param {mix} ob or string
 * @return bool
 */
InputCheck.prototype.adoszamValidalas = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		//12345678-1-12
		var pattern = new RegExp("^[0-9]{8}-?[0-9]{1}-?[0-9]{2}$","ig");
		if (bemeno.match(pattern)) {
			return true;
		} else {
			return false;
		}
		
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.adoszamValidalas()' + ' - ' + exception.message);
		return true;
	}
}

InputCheck.prototype.strRepeat = function( str, hossz ) {
	try{ 
		if ( hossz == 0 ) {
			return '';
		}
		for ( i=1; i<hossz; i++ ) {
			str += str;
		}
		return str;	
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.strRepeat()' + ' - ' + exception.message);
		return true;
	}
}

InputCheck.prototype.strPad = function( ob, pad_length, pad_string, pad_type, input ) {
	try{ 
	
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		pad_length = Number(pad_length);
		pad_string = String(pad_string);
		pad_type = String(pad_type);
		
		var karakterHossz = bemeno.length;
		var ismetlesHossz = pad_length - karakterHossz;
		
		if ( pad_length <= 0 || ismetlesHossz <= 0 || this.trim(bemeno).length == 0 ) {
			return;
		}
		
		switch ( pad_type ) {
			case 'STR_PAD_LEFT':
				var kimeno = this.strRepeat(pad_string, ismetlesHossz) + bemeno;
			break;
			case 'STR_PAD_RIGHT':
				var kimeno = bemeno + this.strRepeat(pad_string, ismetlesHossz);
			break;
			case 'STR_PAD_BOTH':
				var kimeno = this.strRepeat(pad_string, Math.floor(ismetlesHossz/2)) + bemeno + this.strRepeat(pad_string, Math.ceil(ismetlesHossz/2));
			break;
		}
		
		if (input==true) ob.value = kimeno;
		else return  kimeno;
		
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.strPad()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * törlés gombra belép a target mezőbe
 * @param {obj} evt 
 * @param {obj} obj 
 * @param {string} targetId 
 * @return bool
 */
InputCheck.prototype.forwardInput = function(evt,obj,targetId) {
	try{ 
		var charCode = (evt.which) ? evt.which : event.keyCode;
		if (this.trim(obj.value) == '' && charCode == 8) {
			document.getElementById(targetId).focus();
			document.getElementById(targetId).value = document.getElementById(targetId).value;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.forwardInput()' + ' - ' + exception.message);
		return true;
	}
}
/**
 * megadott hosszra belép a target mezőbe
 * @param {int} valueLength 
 * @param {obj} obj 
 * @param {string} targetId 
 * @return bool
 */
InputCheck.prototype.nextInput = function(valueLength,obj,targetId) {
	try{ 
		if (obj.value.length == valueLength) {
			document.getElementById(targetId).focus();
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.nextInput()' + ' - ' + exception.message);
		return true;
	}
}

/**
 * eltávolítja a védett karaktereket
 * @param {mix} ob or string
 * @return str
 */
InputCheck.prototype.vedettKarakterek = function(ob , input) {
	try{ 
		if (input==true) var bemeno = String(ob.value);
		else var bemeno = String(ob);
		
		var pattern = new RegExp("\\s|'|\"|[%]|\\x5c","g");
		kimeno = bemeno.replace(pattern, "");
		
		if (input==true) {
			if (talalat = bemeno.match(pattern)) {
				alert('Tiltott karakter lett megadva (' + talalat[0] + '), törlésre kerül!');
			}
			ob.value = kimeno;	  
		} else {
			return  kimeno;
		}
	} catch ( exception ) {
		if ( this.debug ) alert('InputCheck.vedettKarakterek()' + ' - ' + exception.message);
		return true;
	}
}
