/*
	Written by Bborie Park
	Copyright (c) 2008 Bborie Park
	Licensed under the GNU GPL v2 (http://www.opensource.org/licenses/gpl-license.php)

	the sprintf function is based upon jquery.printf.js by mindstep.com.  the copyright
	notice is:

	##############################################################################
	#    ____________________________________________________________________
	#   /                                                                    \
	#  |               ____  __      ___          _____  /     ___    ___     |
	#  |     ____       /  \/  \  ' /   \      / /      /__   /   \  /   \    |
	#  |    / _  \     /   /   / / /    /  ___/  \__   /     /____/ /    /    |
	#  |   / |_  /    /   /   / / /    / /   /      \ /     /      /____/     |
	#  |   \____/    /   /    \/_/    /  \__/  _____/ \__/  \___/ /           |
	#  |                                                         /            |
	#  |                                                                      |
	#  |   Copyright (c) 2007                             MindStep SCOP SARL  |
	#  |   Herve Masson                                                       |
	#  |                                                                      |
	#  |      www.mindstep.com                              www.mjslib.com    |
	#  |   info-oss@mindstep.com                           mjslib@mjslib.com  |
	#   \____________________________________________________________________/
	#
	#  Version: 1.0.0
	#
	#  (Svn version: $Id: jquery.printf.js 3434 2007-08-27 09:31:20Z herve $)
	#
	#  Redistribution and use in source and binary forms, with or without
	#  modification, are permitted provided that the following conditions
	#  are met:
	#
	#     1. Redistributions of source code must retain the above copyright
	#        notice, this list of conditions and the following disclaimer.
	#
	#     2. Redistributions in binary form must reproduce the above copyright
	#        notice, this list of conditions and the following disclaimer in
	#        the documentation and/or other materials provided with the
	#        distribution.
	#
	#  THIS SOFTWARE IS PROVIDED BY THE MINDSTEP CORP PROJECT ``AS IS'' AND
	#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
	#  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	#  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MINDSTEP CORP OR CONTRIBUTORS
	#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	#  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
	#  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
	#  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
	#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
	#  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
	#  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	#
	#  The views and conclusions contained in the software and documentation
	#  are those of the authors and should not be interpreted as representing
	#  official policies, either expressed or implied, of MindStep Corp.
	#
	################################################################################
*/
(function(h){h.extend({Util:{range:function(a,b,c){a=parseInt(a,10);b=parseInt(b,10);if(isNaN(a)||isNaN(b))return false;var d=[];if(c==null)c=1;c=parseInt(c,10);if(isNaN(c))return false;if(c===0)c=1;if(a>b&&c>0)c=-1*c;for(i=a;;i+=c){if(a>b){if(i<b)break}else if(i>b)break;d.push(i)}return d},pause:function(a){if(typeof a!="number"||isNaN(a))a=1E3;var b=new Date;for(a=b.getTime()+a;;){b=new Date;if(b.getTime()>a)return}},urlValue:function(a,b){if(typeof a!="string"&&typeof a!="number")return"";b=b||
window.location.href;a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");a=(new RegExp("[\\?&]"+a+"=([^&#]*)")).exec(b);return a!=null?a[1]:null},debug:function(a){if(typeof console!="undefined"&&typeof console.log!="undefined")console.log(a);else if(typeof opera!="undefined"&&typeof opera.postError!="undefined")opera.postError(a);else{if(!document.msgDebug)document.msgDebug=[];document.msgDebug.push(a);document.msgDebug.length>5&&document.msgDebug.shift();window.status=document.msgDebug.join(". ")}},
simpleUnique:function(a){if(!(a instanceof Array))return a;a=a.sort();for(var b=[],c=0;c<a.length;c++)h.inArray(a[c],b)<0&&b.push(a[c]);return b},id:function(a){var b=a instanceof jQuery?a:h(a);a=h(a)[0];if(!h.trim(b.attr("id")).length){var c,d=document.getElementsByTagName(a.tagName).length||100;d=Math.pow(d,2);do c=Math.floor(Math.random()*d);while(document.getElementById(a.tagName+"-"+c));b.attr("id",a.tagName+"-"+c)}return b.attr("id")},objectLength:function(a){var b=0;if(typeof a!="object")return false;
for(var c in a)b++;return b},objectSort:function(a,b){var c=[],d=[],f={};b=b||"asc";for(var g in a){c.push(g);d.push(a[g])}for(g=0;g<d.length;g++)for(a=g+1;a<d.length;a++){var n=false;switch(b){case "asc":n=d[a]<d[g];break;case "desc":n=d[a]>d[g];break;default:if(typeof b=="function")n=b.call(null,d[g],d[a]);break}if(n===true){n=d[g];d[g]=d[a];d[a]=n;n=c[g];c[g]=c[a];c[a]=n}}for(g=0;g<c.length;g++)f[c[g]]=d[g];return f},objectKeys:function(a){var b=[];for(var c in a)b.push(c);return b},objectValues:function(a){var b=
[];for(var c in a)b.push(a[c]);return b},strRight:function(a,b){a+="";b=b<=a.length?b:a.length;return a.substr(a.length-b)},strLeft:function(a,b){a+="";b=b<=a.length?b:a.length;return a.substr(0,b)},checkDate:function(a,b,c){a*=1;b*=1;c*=1;if(a<1||a>12)return false;if(b<1||b>31)return false;if((a==4||a==6||a==9||a==11)&&b==31)return false;if(a==2){if(b>29)return false;a=c/4;if(isNaN(a))return false;if(b==29&&a!=parseInt(a,10))return false}return true},daysInMonth:function(a,b){var c=[31,28,31,30,
31,30,31,31,30,31,30,31];if(a!=2)return c[a-1];if(b%4!=0)return c[1];if(b%100==0&&b%400!=0)return c[1];return c[1]+1},arrayIndexOf:function(a,b,c){if(!(a instanceof Array))return-1;c=(c||0)*1;c=!isNaN(c)&&c>=0&&c<=a.length-1?c*1:0;if(typeof Array.indexOf=="function")return a.indexOf(b,c);for(c=c;c<a.length;c++)if(a[c]==b)return c;return-1},isNull:function(a){return a===null},setElementTitle:function(a,b,c,d){b+="";if(!b.length)return false;d=d||"";a=a instanceof jQuery?a:h(a);c=h.Util.arrayIndexOf(["prepend",
"append","replace"],(c+"").toLowerCase())==-1?"append":(c+"").toLowerCase();var f=typeof a.attr("title")=="undefined"||a.attr("title").length<1?null:a.attr("title");switch(c){case "prepend":f=b+(h.Util.isNull(f)?"":d+f);break;case "append":f=(h.Util.isNull(f)?"":f+d)+b;break;case "replace":f=b;break}a.attr("title",f);return true},isAjax:function(a){return a instanceof(window.ActiveXObject?ActiveXObject:window.XDomainRequest?XDomainRequest:XMLHttpRequest)},childrenHeight:function(a){a=a instanceof
jQuery?a:h(a);var b=0;a.children().each(function(){b+=h(this).outerHeight(true)});return b==0?a.outerHeight(true):b},round:function(a,b){if(isNaN(a))return false;var c=1;a=parseFloat(a);for(b=b=isNaN(b)?1:parseInt(b,10);b>0;b--)c*=10;b=c;return Math.round(a*b)/b},strCapitalize:function(a){return a.replace(/\w+/g,function(b){return b.charAt(0).toUpperCase()+b.slice(1).toLowerCase()})},dateFormat:function(a,b){if(typeof a!="string")return false;a=a.split("");b=new Date(b);var c=[],d;for(var f in a){d=
a[f];switch(d){case "d":c.push(b.getDate());break;case "D":d=b.getDate();if(parseInt(d,10)<10)d="0"+d;c.push(d);break;case "m":c.push(b.getMonth()+1);break;case "M":d=b.getMonth()+1;if(parseInt(d,10)<10)d="0"+d;c.push(d);break;case "y":c.push(b.getYear());break;case "Y":c.push(b.getFullYear());break;default:c.push(d);break}}return c.join("")},strRepeat:function(a,b){var c=[];for(i=0;i<b;i++)c.push(a);return c.join("")},getCookie:function(a){a+="=";for(var b,c=document.cookie.split(";"),d=0;d<c.length;d++){for(b=
c[d];b.charAt(0)==" ";)b=b.substring(1,b.length);if(b.indexOf(a)==0)return b.substring(a.length,b.length)}return null},setCookie:function(a,b,c,d,f){var g=[];g.push(a+"="+b);if(c){a=new Date;a.setTime(a.getTime()+c*24*60*60*1E3);g.push("expires="+a.toGMTString())}f=typeof f=="string"?f:"/";g.push("path="+f);typeof d=="string"&&g.push("domain="+d);document.cookie=g.join("; ")},delCookie:function(a){h.Util.setCookie(a,"",-1)},arrayFill:function(a,b,c,d){if(!(a instanceof Array)||isNaN(b)||isNaN(c)||
parseInt(c,10)<1)return false;for(var f=0;f<parseInt(c,10);){a[b+f]=d;f++}},stringCounter:function(a,b){var c=[],d,f;if(typeof a=="string"){h.Util.stringCounter.charString=a;h.Util.stringCounter.charArray&&delete h.Util.stringCounter.charArray}else if(h.Util.stringCounter.charString)a=h.Util.stringCounter.charString;else{a="ABCDEFGHIJKLMNOPQRSTUVWXYZ";h.Util.stringCounter.charString=a;h.Util.stringCounter.charArray&&delete h.Util.stringCounter.charArray}f=a.length;if(b instanceof Array)h.Util.stringCounter.charArray=
b;else if(h.Util.stringCounter.charArray)b=h.Util.stringCounter.charArray;else{b=[-1];h.Util.stringCounter.charArray=b}++b[b.length-1];if(b[b.length-1]>=f)for(d=b.length;d>0;d--)if(b[d]>=f){b[d-1]++;b[d]=0}if(b[0]>=f){for(d=0;d<b.length;d++)b[d]=0;b[b.length]=0}for(d=0;d<b.length;d++)c.push(a.charAt(b[d]));return c.join("")},sprintf:function(a){function b(e){if(e===undefined||e===null)return true;return e==""?true:false}function c(e){return Math.floor(e)}function d(e,m,p,j,l){e=parseInt(e,10);if(isNaN(e))return"NaN";
aval=e<0?-e:e;var o="";if(aval==0)o="0";else for(;aval>0;){o=HDIGITS[aval%m]+o;aval=c(aval/m)}if(e<0)o="-"+o;if(j=="-")p=" ";return g(o,p,j,l,-1)}function f(e,m,p,j,l){if(l==undefined){if(parseInt(e)!=e)return""+e;l=5}m=Math.pow(10,l);e=""+Math.round(e*m);m=e.length-l;if(m==0)return"0."+e.substr(m,l);return e.substr(0,m)+"."+e.substr(m,l)}function g(e,m,p,j,l){if(e===undefined)return"(undefined)";if(e===null)return"(null)";if((j=j-e.length)>0)if(p=="-")for(;j>0;){e+=m;j--}else for(;j>0;){e=m+e;j--}if(l>
0)return e.substr(0,l);return e}function n(e,m,p){var j="",l,o,k;o=e.split("\n");for(l=0;l<o.length;l++){if(l>0)j+="\n";for(e=o[l];k=FREGEXP.exec(e);){var q="",r=" ";b(k[1])||(j+=k[1]);b(k[2])||(q=k[2]);b(k[3])||(r="0");var s=k[4],u=k[6],t=k[7];e=k[8];if(p>=m.length)j+="[missing parameter for type '"+t+"']";else{k=m[p++];switch(t){case "d":j+=d(k,10,r,q,s);break;case "o":j+=d(k,8,r,q,s);break;case "x":j+=d(k,16,r,q,s);break;case "X":j+=d(k,16,r,q,s).toUpperCase();break;case "c":j+=String.fromCharCode(parseInt(k,
10));break;case "s":j+=g(k,r,q,s,u);break;case "f":j+=f(k,r,q,s,u);break;default:j+="[unknown format '"+t+"']";break}}}j+=e}return j}FREGEXP=/^([^%]*)%([-+])?(0)?(\d+)?(\.(\d+))?([doxXcsf])(.*)$/;HDIGITS=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return n(a,arguments,1)}}})})(jQuery);

