function InputPlaceholder (input, value, cssFilled, cssEmpty){
	var thisCopy = this
	
	this.Input = input
	this.Value = value
	this.SaveOriginal = (input.value == value)
	this.CssFilled = cssFilled
	this.CssEmpty = cssEmpty
	this.Type = input.type;

	this.setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()})
	this.setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()})
	this.setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()})

	if (input.value == '') this.onBlur();

	return this
}

InputPlaceholder.prototype.setupEvent = function (elem, eventType, handler){
	if (elem.attachEvent){
		elem.attachEvent ('on' + eventType, handler)
	}
	if (elem.addEventListener){
		elem.addEventListener (eventType, handler, false)
	}
}

InputPlaceholder.prototype.onFocus = function(){
	if (!this.SaveOriginal &&  this.Input.value == this.Value){
		this.Input.value = ''
	}else{
		this.Input.className = ''
	}
}

InputPlaceholder.prototype.onKeyDown = function(){
	this.Input.className = ''
}

InputPlaceholder.prototype.onBlur = function(){
	if (this.Input.value == '' || this.Input.value == this.Value){
		this.Input.value = this.Value;
		this.Input.className = this.CssEmpty;
	}else{
		this.Input.className = this.CssFilled;
//		if((this.Type != null) && (this.Type.search(/^password$/i) == 0)) this.Input.type = "password";
	}
}























function FormVerification (form){
	var thisCopy = this;
	this.Form = form;
	this.setupEvent (this.Form, 'submit', function() {return thisCopy.onSubmit()})
	return this;
}

FormVerification.prototype.setupEvent = function (elem, eventType, handler){
	if (elem.attachEvent){
		elem.attachEvent ('on' + eventType, handler);
	}
	if (elem.addEventListener){
		elem.addEventListener (eventType, handler, false);
	}
}

FormVerification.prototype.onSubmit = function(){
	var inputs = this.Form.getElementsByTagName("input");
	for(i = 0; i < inputs.length; i++){
		if((inputs[i].getAttribute("rules") != null) && (inputs[i].getAttribute("rules") != '')){
			if(!this.verify(inputs[i])) return false;
		}
	}
	var textareas = this.Form.getElementsByTagName("textarea");
	for(i = 0; i < textareas.length; i++){
		if((textareas[i].getAttribute("rules") != null)&&(textareas[i].getAttribute("rules") != '')){
			if(!this.verify(textareas[i])) return false;
		}
	}
	this.Form.submit();
	return true;
}
FormVerification.prototype.verify = function(obj){
	var rules = obj.getAttribute("rules").split(new RegExp('\\s')); 
	for(var i = 0; i < rules.length; i++){
		switch (rules[i]) {
			case "filled":
				if(!this.verifyFilled(obj)) return false;
			break;
		}
	}
	return true;
}
FormVerification.prototype.verifyFilled = function(obj){
	if((obj.value != "") && (obj.value != obj.getAttribute("placeholder"))){
		return true;
	}else{
		this.showMessage("Не заполнено обязательное поле \"" + obj.getAttribute("title") + "\"", obj);
		return false;
	};
}
FormVerification.prototype.showMessage = function(msg, focusTarget){
	alert(msg);
	focusTarget.focus();
}






window.onload = function(){
	var inputs = document.getElementsByTagName("input");
	for(i = 0; i < inputs.length; i++){
		if((inputs[i].getAttribute("placeholder") != null) && (inputs[i].getAttribute("placeholder") != "")){
			new InputPlaceholder (inputs[i], inputs[i].getAttribute("placeholder"), "", "placeholder")
		}
	}
		var textareas = document.getElementsByTagName("textarea");
	for(i = 0; i < textareas.length; i++){
		if((textareas[i].getAttribute("placeholder") != null) && (textareas[i].getAttribute("placeholder") != "")){
			new InputPlaceholder (textareas[i], textareas[i].getAttribute("placeholder"), "", "placeholder")
		}
	}

	var forms = document.getElementsByTagName("form");
	for(i = 0; i < forms.length; i++){
		if((forms[i].getAttribute("verification") != null) && (forms[i].getAttribute("verification") != "")){
			new FormVerification (forms[i]);
		}
	}

}









