

	function is_email(string) {
		if(string == "mano@pastas.lt") { return false; }

		rez = string.match(/.*@pastas.*/ig);
		if(rez != null) { return false; }

		rez = string.match(/^[\w-\.]+@[\w-\.]+\.\w{2,4}$/ig);
		return (rez == null) ? false : true;
	}

	var SEARCH = false;
	function is_empty(string){
		string = remSpaces(string);
		if(string == "")	{ return true;	}
		expression = /[\w\dąįāćäåøęēčéźėģķīļšńņóōõö÷ųłśūüżž˙]+/ig;
		if(SEARCH == true) {
			expression = /\w+|\d+|\*+/ig;
		}
		rez = string.match(expression);
		SEARCH = false;
		return (rez == null) ? true : false;
	}

	function remSpaces(string) {
		return string.replace(/^\s*/ig,"").replace(/\s*$/ig,"");
	}
	

	function smartCheck(form){ 
	/***********************
		This function checks all inputs, selects and textareas in the given form 
		witch will have	isEmpty or isEmail properties or both.
	***********************/
		var inputs = form.getElementsByTagName("INPUT");
		var selects = form.getElementsByTagName("SELECT");
		var texareas = form.getElementsByTagName("TEXTAREA");
		for (i = 0; i < inputs.length; i++) {
			if(inputs[i].isEmpty) { /*  check if field is empty or there is no a-z,0-9,_ simbols  */
				inputs[i].value = remSpaces(inputs[i].value);
				if(inputs[i].searchField) {
					SEARCH = true;
				}
				
				if(is_empty(inputs[i].value)) {
					alert(inputs[i].isEmpty);
					inputs[i].select();
					return false;
				}
			}
			if(inputs[i].isEmail) {
				inputs[i].value = remSpaces(inputs[i].value);
				if(!is_empty(inputs[i].value)) {
					if(!is_email(inputs[i].value)) {
						alert(inputs[i].isEmail);
						inputs[i].select();
						return false;
					}
				}
			}
			if(inputs[i].isFileEmpty) { 
				if(inputs[i].fName) { if(!is_empty(inputs[i].fName)) { continue; } }
				inputs[i].value = remSpaces(inputs[i].value);

				if(is_empty(inputs[i].value)) {
					alert(inputs[i].isEmpty);
					inputs[i].select();
					return false;
				}
			}
		}
		for (i = 0; i < texareas.length; i++) {
			if(texareas[i].isEmpty) {
				texareas[i].value = remSpaces(texareas[i].value);
				if(is_empty(texareas[i].value)) {
					alert(texareas[i].isEmpty);
					texareas[i].select();
					return false;
				}
			}
		}
		for (i = 0; i < selects.length; i++) {
			if(selects[i].isEmpty) { /*  check if field is empty or there is no a-z,0-9,_ simbols  */
				if(is_empty(selects[i].options(selects[i].options.selectedIndex).value)) {
					alert(selects[i].isEmpty);
					selects[i].focus();
					return false;
				}
			}
			continue;
		}
		return true;
	}/*  smartCheck() end */

	function initSubmit(form) {
		return smartCheck(form);
	}

	function validatePass(form) {
		pass1 = document.getElementById("pass_1");
		pass2 = document.getElementById("pass_2");
		if(!is_empty(pass1.value) || !is_empty(pass2.value)) {
			if(pass1.value != pass2.value) {
				pass1.value = "";
				pass2.value = "";
				pass1.focus();
				alert("Slaptažodžiai nesutampa!");return false;
			}
		}
		return true;
	}