/*
 * libura V2.0R1.0
 * http://www.desknets.com/
 * Copyright (C)2010 NEOJAPAN,Inc. All Rights Reserved.
 * 本製品は日本国著作権法および国際条約により保護されています。 
 * 本製品の全部または一部を無断で複製したり、無断で複製物を頒 
 * 布すると著作権の侵害となりますのでご注意ください。 
 */
(function(){if(!neo.core.readyNamespace("neo.jQuery.fn.neoClearButton")){return}var a;a=function(){a.prototype.__constructor.apply(this,arguments)};a.prototype={_getDefaultOptions:function(){return $.neoClearButton.defaultOptions},_initialize:function(d,c){this._bindListener()},_bindListener:function(){var c=this;this.element.click(function(d){d.preventDefault();c._resetTargets.apply(c,arguments)})},_regulateOptions:function(c){c.elContainer=this._getElContainer(c);c.elTargets=this._getElTargets(c,c.elContainer);return c},_getElContainer:function(c){if(neo.core.exists(c,"elContainer")){return c.elContainer}else{return this._searchElContainer()}},_searchElContainer:function(){return this.element.parents("form:first")},_getElTargets:function(c,d){if(neo.core.exists(c,"elTargets")){return c.elTargets}else{return this._pickElTargets(d)}},_pickElTargets:function(c){if(!neo.core.exists(c,"find")){return[]}return c.find($.neoClearButton.SEL_TARGETS)},_resetTargets:function(){var d=this._getFuncGetData();var e=d.apply(this);var c=this;if(!neo.core.exists(this.options,"elTargets.each")){return}this.options.elTargets.each(function(){var f=$(this);var g=e[f.attr("name")];if(typeof g=="null"){return}c._setValueToFormPart.apply(c,[f,g])})},_getFuncGetData:function(){if(neo.core.exists(this.options,"getData")&&typeof this.options.getData=="function"){return this.options.getData}else{return $.neoClearButton.defaultFuncGetData}},_setValueToFormPart:function(d,f){var c="";var e="";if(neo.core.exists(d,"0.tagName.toLowerCase")){var c=d[0].tagName.toLowerCase()}else{return}if(neo.core.exists(d,"attr")){e=d.attr("type");if(neo.core.isString(e)){e=e.toLowerCase()}else{e=""}}if(c=="input"&&e=="checkbox"){this._setValueToCheckbox(d,f)}else{if(c=="input"&&e=="radio"){this._setValueToRadio(d,f)}else{if(c=="select"){this._setValueToList(d,f)}else{this._setValueToText(d,f)}}}},_setValueToCheckbox:function(c,d){if(!neo.core.exists(c,"0")){return}if(typeof d=="boolean"&&d){c[0].checked=true}else{c[0].checked=false}},_setValueToRadio:function(d,e){if(!neo.core.exists(d,"0")){return}if(neo.core.exists(e)){if(d.val()==e.toString()){d[0].checked=true}else{d[0].checked=false}}else{var c=$.grep(this.options.elTargets,function(f){f=$(f);if(f[0].tagName.toLowerCase()=="input"&&f.attr("type")=="radio"&&f.attr("name")==d.attr("name")){return true}});$.each(c,function(f){this.checked=(f==0)})}},_setValueToList:function(e,f){if(!neo.core.exists(e,"0")){return}if(neo.core.exists(f)){var d=e.find("option");var c=false;for(var g=0;g<d.length;g++){if(d[g].value==f.toString()){c=true;break}}if(c){e.val(f.toString())}else{e[0].selectedIndex=0}}else{e[0].selectedIndex=0}},_setValueToText:function(c,d){if(!neo.core.exists(c,"val")){return}if(neo.core.exists(d)){c.val(d)}else{c.val("")}}};$.fn.neoClearButton=function(c){return this.each(function(){this.neoClearButton=new a(this,c)})};var b=a.prototype;a.prototype=$.extend({},neo.jq.jQPluginBase);$.extend(a.prototype,b);$(function(){$.neoClearButton.initialize();$($.neoClearButton.SEL_TARGET).neoClearButton()});$.neoClearButton={SEL_TARGET:".neo-clearbutton",SEL_TARGETS:":text, :checkbox, :radio, select, textarea",CLS_DEFAULT:"neo-clearbutton-default",initialize:function(){return},defaultFuncGetData:function(){if(!neo.core.exists(this.options,"elTargets.each")){return{}}var c={};this.options.elTargets.each(function(){var f=$(this);var d=f[0].tagName.toLowerCase();var e=f.attr("type").toLowerCase();if(d=="input"&&e=="checkbox"){if(f.hasClass($.neoClearButton.CLS_DEFAULT)){c[f.attr("name")]=true}}else{if(d=="input"&&e=="radio"){if(f.hasClass($.neoClearButton.CLS_DEFAULT)){c[f.attr("name")]=f.val()}}else{if(d=="select"){var g=f.find("."+$.neoClearButton.CLS_DEFAULT+":first");if(g.length>0){c[f.attr("name")]=g.text()}}}}});return c},defaultOptions:{elContainer:null,elTarget:null,getData:null}}})();
