/**
* Обработка поля ввода
*/

function inputController()
{

}

inputController.object = null;
inputController.button = null;
inputController.classActive = '';
inputController.classInactive = '';
inputController.defaultValue = '';
inputController.isSubmitable = '';

inputController.prototype.init = function(inputId, buttonId)
{
    // настройки
    this.classActive = 'active';
    this.classInactive = 'inactive';

    if (arguments[2]) {
        this.defaultValue = arguments[2];
    } else {
        this.defaultValue = 'Поиск';
    }

    this.isSubmitable = false;

    if (this.defaultValue == '0') {
        this.classInactive = this.classActive;
    }


    this.object = document.getElementById(inputId);
    this.button = document.getElementById(buttonId);

    this.object.value = this.defaultValue;


    this.object.className = this.object.className + ' ' + this.classInactive;
    if(!this.object.value || this.object.value == '0' || this.object.value == '') {
        this.object.value = this.defaultValue;
        this.object.className = this.object.className + ' ' + this.classInactive;
    } else {
        this.object.className = this.object.className + ' ' + this.classActive;
    } 

}

inputController.prototype.clear = function()
{
    if ( this.object.value == this.defaultValue) {
        this.object.value = '';
    }
    //this.object.className = this.classActive;
    this.object.className = this.object.className.replace(this.classInactive, this.classActive);
}

inputController.prototype.lostFocus = function()
{
    if (this.object.value == '' ||  this.object.value == this.defaultValue) {
        this.object.value = this.defaultValue;
        //this.object.className = this.classInactive;
        this.object.className = this.object.className.replace(this.classActive, this.classInactive);
    }
}

inputController.prototype.keyPressed = function()
{
    if (this.object.value != '') {
        this.isSubmitable = true;
    } else {
        this.isSubmitable = false;
    }
}

inputController.prototype.submit = function()
{
    if (this.isSubmitable) {
        return true;
    }
    else return false;
}

////

function showImage(image, w, h, title)
{
	//var im = new Image();
	//im.src = image;

	var w = Math.min(Math.ceil(screen.availWidth * 2 / 3), w);
	var h = Math.min(Math.ceil(screen.availHeight * 2 / 3), h);
    
	var x = Math.ceil((screen.availWidth - w) / 2);
	var y = Math.ceil((screen.availHeight - h) / 2);
    	
	var newwindow = window.open('', 'mywin', 'resizable=1, menubar=0, scrollbars=1, status=0, width='+w+', height='+h+', top='+y+', left='+x);
	newwindow.document.write('<html><head><title>'+title+'</title></head>');
	newwindow.document.write('<body style="margin:0;padding:0" onclick="window.close();"><a href="javascript:void(0);"><img src="'+image+'" border="0" title="Закрыть окно"></a></body></html>');
	newwindow.document.close();
}


function initSearch()
{
}


// IE, stop flicker !
try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
