/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dijit.form._FormWidget"]){
dojo._hasResource["dijit.form._FormWidget"]=true;
dojo.provide("dijit.form._FormWidget");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.declare("dijit.form._FormWidget",[dijit._Widget,dijit._Templated],{baseClass:"",name:"",alt:"",value:"",type:"text",tabIndex:"0",disabled:false,readOnly:false,intermediateChanges:false,scrollOnFocus:true,attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{value:"focusNode",disabled:"focusNode",readOnly:"focusNode",id:"focusNode",tabIndex:"focusNode",alt:"focusNode"}),_setNameAttr:function(_1){
this.name=_1;
var _2=this.valueNode||this.focusNode||this.domNode;
dojo.attr(_2,"name",_1);
},_setDisabledAttr:function(_3){
this.disabled=_3;
dojo.attr(this.focusNode,"disabled",_3);
dijit.setWaiState(this.focusNode,"disabled",_3);
if(_3){
this._hovering=false;
this._active=false;
this.focusNode.removeAttribute("tabIndex");
}else{
this.focusNode.setAttribute("tabIndex",this.tabIndex);
}
this._setStateClass();
},setDisabled:function(_4){
dojo.deprecated("setDisabled("+_4+") is deprecated. Use attr('disabled',"+_4+") instead.","","2.0");
this.attr("disabled",_4);
},_onFocus:function(e){
if(this.scrollOnFocus){
dijit.scrollIntoView(this.domNode);
}
this.inherited(arguments);
},_onMouse:function(_6){
var _7=_6.currentTarget;
if(_7&&_7.getAttribute){
this.stateModifier=_7.getAttribute("stateModifier")||"";
}
if(!this.disabled){
switch(_6.type){
case "mouseenter":
case "mouseover":
this._hovering=true;
this._active=this._mouseDown;
break;
case "mouseout":
case "mouseleave":
this._hovering=false;
this._active=false;
break;
case "mousedown":
this._active=true;
this._mouseDown=true;
var _8=this.connect(dojo.body(),"onmouseup",function(){
if(this._mouseDown&&this.isFocusable()){
this.focus();
}
this._active=false;
this._mouseDown=false;
this._setStateClass();
this.disconnect(_8);
});
break;
}
this._setStateClass();
}
},isFocusable:function(){
return !this.disabled&&!this.readOnly&&this.focusNode&&(dojo.style(this.domNode,"display")!="none");
},focus:function(){
dijit.focus(this.focusNode);
},_setStateClass:function(){
var _9=this.baseClass.split(" ");
function _a(_b){
_9=_9.concat(dojo.map(_9,function(c){
return c+_b;
}),"dijit"+_b);
};
if(this.checked){
_a("Checked");
}
if(this.state){
_a(this.state);
}
if(this.selected){
_a("Selected");
}
if(this.disabled){
_a("Disabled");
}else{
if(this.readOnly){
_a("ReadOnly");
}else{
if(this._active){
_a(this.stateModifier+"Active");
}else{
if(this._focused){
_a("Focused");
}
if(this._hovering){
_a(this.stateModifier+"Hover");
}
}
}
}
var tn=this.stateNode||this.domNode,_e={};
dojo.forEach(tn.className.split(" "),function(c){
_e[c]=true;
});
if("_stateClasses" in this){
dojo.forEach(this._stateClasses,function(c){
delete _e[c];
});
}
dojo.forEach(_9,function(c){
_e[c]=true;
});
var _12=[];
for(var c in _e){
_12.push(c);
}
tn.className=_12.join(" ");
this._stateClasses=_9;
},compare:function(_14,_15){
if((typeof _14=="number")&&(typeof _15=="number")){
return (isNaN(_14)&&isNaN(_15))?0:(_14-_15);
}else{
if(_14>_15){
return 1;
}else{
if(_14<_15){
return -1;
}else{
return 0;
}
}
}
},onChange:function(_16){
},_onChangeActive:false,_handleOnChange:function(_17,_18){
this._lastValue=_17;
if(this._lastValueReported==undefined&&(_18===null||!this._onChangeActive)){
this._resetValue=this._lastValueReported=_17;
}
if((this.intermediateChanges||_18||_18===undefined)&&((typeof _17!=typeof this._lastValueReported)||this.compare(_17,this._lastValueReported)!=0)){
this._lastValueReported=_17;
if(this._onChangeActive){
this.onChange(_17);
}
}
},create:function(){
this.inherited(arguments);
this._onChangeActive=true;
this._setStateClass();
},destroy:function(){
if(this._layoutHackHandle){
clearTimeout(this._layoutHackHandle);
}
this.inherited(arguments);
},setValue:function(_19){
dojo.deprecated("dijit.form._FormWidget:setValue("+_19+") is deprecated.  Use attr('value',"+_19+") instead.","","2.0");
this.attr("value",_19);
},getValue:function(){
dojo.deprecated(this.declaredClass+"::getValue() is deprecated. Use attr('value') instead.","","2.0");
return this.attr("value");
},_layoutHack:function(){
if(dojo.isFF==2&&!this._layoutHackHandle){
var _1a=this.domNode;
var old=_1a.style.opacity;
_1a.style.opacity="0.999";
this._layoutHackHandle=setTimeout(dojo.hitch(this,function(){
this._layoutHackHandle=null;
_1a.style.opacity=old;
}),0);
}
}});
dojo.declare("dijit.form._FormValueWidget",dijit.form._FormWidget,{attributeMap:dojo.delegate(dijit.form._FormWidget.prototype.attributeMap,{value:""}),postCreate:function(){
if(dojo.isIE||dojo.isWebKit){
this.connect(this.focusNode||this.domNode,"onkeydown",this._onKeyDown);
}
if(this._resetValue===undefined){
this._resetValue=this.value;
}
},_setValueAttr:function(_1c,_1d){
this.value=_1c;
this._handleOnChange(_1c,_1d);
},_getValueAttr:function(_1e){
return this._lastValue;
},undo:function(){
this._setValueAttr(this._lastValueReported,false);
},reset:function(){
this._hasBeenBlurred=false;
this._setValueAttr(this._resetValue,true);
},_valueChanged:function(){
var v=this.attr("value");
var lv=this._lastValueReported;
return ((v!==null&&(v!==undefined)&&v.toString)?v.toString():"")!==((lv!==null&&(lv!==undefined)&&lv.toString)?lv.toString():"");
},_onKeyDown:function(e){
if(e.keyCode==dojo.keys.ESCAPE&&!e.ctrlKey&&!e.altKey){
var te;
if(dojo.isIE){
e.preventDefault();
te=document.createEventObject();
te.keyCode=dojo.keys.ESCAPE;
te.shiftKey=e.shiftKey;
e.srcElement.fireEvent("onkeypress",te);
}else{
if(dojo.isWebKit){
te=document.createEvent("Events");
te.initEvent("keypress",true,true);
te.keyCode=dojo.keys.ESCAPE;
te.shiftKey=e.shiftKey;
e.target.dispatchEvent(te);
}
}
}
}});
}
