function $(p){
var val = p==null||p=='null'?'':p+'';
return val.replace(/^ +| +$/g,'');
}
alert($(" adfabc|d|ad ").length);//11
alert(" adfabc|d|ad ".length);//13
String.prototype.trim=function(){
return this.replace(/(^s*)|(s*$)/g, "");
}
alert((" adfabc|d|ad ").trim().length);//11
alert((" adfabc|d|ad ").length);//13