// accepts YYYY-MM-DD format
window.ymd2timestamp=function(year_month_day){
	var year_month_day_arr=String(year_month_day).split('-');
	return Date.UTC(year_month_day_arr[0],year_month_day_arr[1]-1,year_month_day_arr[2],0,0,0,0)/1000.0;
}

window.timestamp2ymd=function(timestamp){
	var myDate=new Date(timestamp*1000.0);
	return leading_zeroes(myDate.getUTCFullYear(),2)+'-'+leading_zeroes(myDate.getUTCMonth()+1,2)+'-'+leading_zeroes(myDate.getUTCDate(),2);
}
window.leading_zeroes=function(str, digits){
	while (str.toString().length<digits)
		str=0+''+str;
	return str;
}
window.timestamp2local=function(timestamp){
	var myDate=new Date(timestamp*1000.0);
	return ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][myDate.getMonth()]+' '+leading_zeroes(myDate.getDate(),2);
}

String.prototype.shrink = function (length){
	if (this.length<=length){
		return this;
	} else {
		var dots_length=(length>=9)?3:parseInt(length/3);
		var tail_length=(length>=9)?3:parseInt(length/3);
		var head_length=length-dots_length-tail_length;
		var dots='';
		while(dots_length--) {
			dots+='.';
		}
		return this.substr(0,head_length)+dots+this.substring(this.length-tail_length, this.length);
	}
}

window.ent=function(string){
	return (new String(string)).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

window.unent=function(string){
	var temp=document.createElement("textarea");
	temp.innerHTML=string;
	return temp.value;
}

window.addslashes=function(str) {
	return str.replace(/\'/g,'\\\'').replace(/\"/g,'\\"').replace(/\\/g,'\\\\').replace(/\0/g,'\\0');
}
window.stripslashes=function(str) {
	return str.replace(/\\'/g,'\'').replace(/\\"/g,'"').replace(/\\\\/g,'\\').replace(/\\0/g,'\0');
}

//class
window.Collection=function(){
	this.hash={};
	this.count=0;
	this.store=function(k,v){
		if(!(k in this.hash))
			this.count++;
		this.hash[k]=v;
	}
	this.del=function(k){
		if(k in this.hash){
			this.count--;
			delete this.hash[k];
		}
	}
}


