var body = document.body;
fontSizing();
addEvent(window,'load',PlaceHolders);
//addEvent(window,'load',fontSizing);
addEvent(window,'resize',fontSizing);
function fontSizing(){
var curWidth = 1024;
var currSize = 0.8;
currSize = body.offsetWidth * currSize / curWidth;
currSize = currSize < 0.8 ? 0.8 : currSize;
currSize = currSize > 1.0 ? 1.0 : currSize;
body.style.fontSize = currSize + 'em';
}
function addEvent(elementPtr, eventType, eventFunc) {
if (elementPtr.addEventListener)
elementPtr.addEventListener(eventType, eventFunc, false);
else
elementPtr.attachEvent('on' + eventType, eventFunc); }
function $(elementId) {
return document.getElementById(elementId);
}
var ph_search, ph_name, ph_mail;
function PlaceHolders(){
if($('search'))
var ph_search = new InputPlaceholder ($('search'), 'поиск', '', 'emptyHolder');
if($('feedback_name'))
var ph_search = new InputPlaceholder ($('feedback_name'), 'представьтесь', '', 'emptyHolder');
if($('feedback_mail'))
var ph_search = new InputPlaceholder ($('feedback_mail'), '@адрес', '', 'emptyHolder');
}
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.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
}
}
