
YAHOO.namespace('socialproducts.lib.util');
YAHOO.namespace('socialproducts.dic');
YAHOO.socialproducts.dic = {
strLenStatus1: 'あと全角',
strLenStatus2: '文字',
strLenStatus3: 'それ以上入力できません。入力制限をこえています。'
};
YAHOO.socialproducts.lib.util.getStringWidth = function( str ) {
if ( typeof str != 'string' || str == '' || str == null ) {
return 0;
}
var _re_pattern_narrowwidth = YAHOO.env.ua.webkit ? /[ -\}~｡-ﾟ]/g : /[\u0020-\u007D]|[\u203E]|[\uFF61-\uFF9F]/g;
var _length = 0;
for( var i=0; i<str.length; i++ ) {
var _char = str.charAt(i);
if( _char.match( _re_pattern_narrowwidth ) ) {
_length++;
} else {
if ( _char == '\r' ) { continue; }
_length += 2;
}
}
return _length;
}
YAHOO.socialproducts.lib.util.getStringLength = function( str ) {
if ( typeof str != 'string' || str == '' || str == null ) {
return 0;
}
return str.length;
}
YAHOO.socialproducts.lib.util.validateStringLength = function( args ) {
if( !args || !args.status || !args.input || !args.length ) { return false; }
var D = YAHOO.util.Dom;
var E = YAHOO.util.Event;
var status_el = D.get( args.status );
var input_el = D.get( args.input );
var _check = function(){
var __check = function() {
var d = YAHOO.socialproducts.dic;
var input_value = input_el.value;
var is_ok = true;
var length = 0;
var util = YAHOO.socialproducts.lib.util;
if( (Math.ceil(util.getStringLength(input_el.value)) / 2) > args.length ) {
is_ok = false;
}
if( is_ok ) {
length = Math.ceil( util.getStringWidth(input_el.value) / 2 );
if( length > args.length ) {
is_ok = false;
}
}
if( is_ok ) {
status_el.innerHTML = d.strLenStatus1 + ( args.length - length ) + d.strLenStatus2;
status_el.style.color = '';
status_el.style.fontWeight = 'normal';
return false;
} else {
status_el.innerHTML = d.strLenStatus3;
status_el.style.color = '#fe0000';
status_el.style.fontWeight = 'bold';
return true;
}
};
__check();
setTimeout( __check, 1000 );
}
_check();
E.addListener( args.input, 'keydown', _check );
};
(function(){
var E = YAHOO.util.Event;
var D = YAHOO.util.Dom;
E.addListener(window, 'load', function(){
if(D.inDocument('navigationSearchInput')){
var edited = false;
var elInput = D.get('navigationSearchInput');
E.addListener( elInput, 'focus', function(){
D.setStyle(elInput,'color','#404040');
if(this.value == this.title && !edited) this.value = '';
edited = true;
});
E.addListener( elInput, 'blur', function(){
if(this.value == '') {
D.setStyle(elInput,'color','#999');
this.value = this.title;
edited = false;
}
});
E.addListener('navigationSearchForm', 'submit', function(){
if(!edited) elInput.value = '';
});
if(elInput.value==''){
D.setStyle(elInput,'color','#999');
elInput.value = elInput.title;
}
}
});
})();

