/*
 * Copyright (C) 2009 Paul Uithol, SMARTposition <http://www.smartposition.nl>
 *
 * SmartPosition Common
 */
if(!window.console||!console.firebug){var names=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];
window.console={};
for(var i=0;
i<names.length;
++i){window.console[names[i]]=function(){};
}}window.SmartPosition=window.SmartPosition||{};
SmartPosition.debug=true;
if(typeof _=="undefined"){var _=function(a){return a;
};
}String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.substring(1);
};
String.prototype.startsWith=function(b,a){if(a===false){return this.indexOf(b)===0;
}else{return this.toLowerCase().indexOf(b.toLowerCase())===0;
}};
String.prototype.toPhoneString=function(){return this.replace(/[\(\)\.\-\s,]/g,"");
};
String.prototype.toNumber=function(){return parseInt(this.replace(/[^\d]/g,""));
};
String.prototype.removeWhitespace=function(){return this.replace(/\s+/g,"");
};
String.prototype.nl2br=function(){return this.replace(/\n\r?/g,"<br />");
};
String.prototype.stripTags=function(){return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi,"");
};
String.prototype.escapeHTML=function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
};
String.prototype.unescapeHTML=function(){return this.stripTags().replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");
};
Date.prototype.setISO8601=function(e){var a=/(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/;
if(e.toString().match(new RegExp(a))){var c=e.match(new RegExp(a));
var b=0;
this.setUTCDate(1);
this.setUTCFullYear(parseInt(c[1],10));
this.setUTCMonth(parseInt(c[3],10)-1);
this.setUTCDate(parseInt(c[5],10));
this.setUTCHours(parseInt(c[7],10));
this.setUTCMinutes(parseInt(c[9],10));
this.setUTCSeconds(parseInt(c[11],10));
if(c[12]){this.setUTCMilliseconds(parseFloat(c[12])*1000);
}else{this.setUTCMilliseconds(0);
}if(c[13]!="Z"){b=(c[15]*60)+parseInt(c[17],10);
b*=((c[14]=="-")?-1:1);
this.setTime(this.getTime()-b*60*1000);
}}else{this.setTime(Date.parse(e));
}return this;
};
Date.prototype.toISO8601String=function(j,c){var e=function(d){return((d<10)?"0":"")+d;
};
if(!j){var j=6;
}if(!c){var c="Z";
var a=this;
}else{if(typeof c=="string"){var g=c.match(/([-+])([0-9]{2}):([0-9]{2})/);
if(g&&g.length>=2){var k=(Number(g[2])*60)+Number(g[3]);
k*=((g[1]=="-")?-1:1);
}else{k=0;
}}else{k=-1*parseInt(c,10);
var b=c;
c=(b<0?"+":"-")+e(Math.floor(Math.abs(b)/60))+":"+e(Math.round(Math.abs(b)%60));
}var a=new Date(Number(Number(this)+(k*60000)));
}var h="";
h+=a.getUTCFullYear();
if(j>1){h+="-"+e(a.getUTCMonth()+1);
}if(j>2){h+="-"+e(a.getUTCDate());
}if(j>3){h+="T"+e(a.getUTCHours())+":"+e(a.getUTCMinutes());
}if(j>5){var f=Number(a.getUTCSeconds()+"."+((a.getUTCMilliseconds()<100)?"0":"")+e(a.getUTCMilliseconds()));
h+=":"+e(f);
}else{if(j>4){h+=":"+e(a.getUTCSeconds());
}}if(j>3){h+=c;
}return h;
};
var dateFormat=function(){var a=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,b=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,d=/[^-+\dA-Z]/g,c=function(f,e){f=String(f);
e=e||2;
while(f.length<e){f="0"+f;
}return f;
};
return function(j,w,t){var g=dateFormat;
if(arguments.length==1&&(typeof j=="string"||j instanceof String)&&!/\d/.test(j)){w=j;
j=undefined;
}j=j?new Date(j):new Date();
if(isNaN(j)){throw new SyntaxError("invalid date");
}w=String(g.masks[w]||w||g.masks["default"]);
if(w.slice(0,4)=="UTC:"){w=w.slice(4);
t=true;
}var l=t?"getUTC":"get",p=j[l+"Date"](),e=j[l+"Day"](),k=j[l+"Month"](),r=j[l+"FullYear"](),u=j[l+"Hours"](),n=j[l+"Minutes"](),v=j[l+"Seconds"](),q=j[l+"Milliseconds"](),f=t?0:j.getTimezoneOffset(),h={d:p,dd:c(p),ddd:_(g.i18n.dayNames[e]),dddd:_(g.i18n.dayNames[e+7]),m:k+1,mm:c(k+1),mmm:_(g.i18n.monthNames[k]),mmmm:_(g.i18n.monthNames[k+12]),yy:String(r).slice(2),yyyy:r,h:u%12||12,hh:c(u%12||12),H:u,HH:c(u),M:n,MM:c(n),s:v,ss:c(v),l:c(q,3),L:c(q>99?Math.round(q/10):q),t:u<12?"a":"p",tt:u<12?"am":"pm",T:u<12?"A":"P",TT:u<12?"AM":"PM",Z:t?"UTC":(String(j).match(b)||[""]).pop().replace(d,""),o:(f>0?"-":"+")+c(Math.floor(Math.abs(f)/60)*100+Math.abs(f)%60,4),S:["th","st","nd","rd"][p%10>3?0:(p%100-p%10!=10)*p%10]};
return w.replace(a,function(m){return m in h?h[m]:m.slice(1,m.length-1);
});
};
}();
dateFormat.masks={"default":"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"};
dateFormat.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]};
Date.prototype.format=function(a,b){return dateFormat(this,a,b);
};
