﻿ClientAPI_AddPromptingInput = {
    Init : function(id, text){        
        var obj = DIY.helpers().g(id);
        if(obj){            
            DIY.events().register(obj, 'focus', function() { ClientAPI_AddPromptingInput.InputHelperFocus(obj, text); }, false);
            DIY.events().register(obj, 'blur', function() { ClientAPI_AddPromptingInput.InputHelperBlur(obj, text); }, false);
            // init
            ClientAPI_AddPromptingInput.InputHelperBlur(obj, text);
        }                        
    },
    InputHelperFocus : function(obj, text){        
        if(obj.value == text && !obj.ralation)
        {
            obj.value = '';
        }
        else if (obj.value == text && obj.ralation)
        {
            inpPass = DIY.helpers().g(obj.ralation);
            obj.style.display = 'none';
            inpPass.style.display = 'block';
            inpPass.value = '';
            inpPass.focus();
        }
    },
    InputHelperBlur : function(obj, text){        
        if(obj.value == '' || obj.value == text){
            if(obj.type == 'password') {
                obj.style.display = 'none';
                pass = DIY.helpers().g(obj.id + '_passInput');
                if(!pass){
                    var pass = document.createElement('input');                    
                    pass.id = obj.id + '_passInput';                    
                    pass.className = obj.className;
                    pass.value = text;
                    pass.ralation = obj.id;
                    pass.size = obj.size;
                    obj.parentNode.appendChild(pass);                    
                    ClientAPI_AddPromptingInput.Init(pass.id, text);
                }
                else
                    pass.style.display = 'block';
            }
            else {
                obj.value = text;
            }
        }        
    }
}
