/*============================================================================================*/
/* ciao_minmax.js */
/* ciao OXγΐΊΐ\¦js */
/* 2008/10/06 ver 1.1.2 */
/* Copyright (c)2008 H.I.S. Co.,Ltd. e-business div.(TOKYO) All Rights Reserved */
/*============================================================================================*/

/* ------------- Numberg£ ------------- */
Number.prototype.addComma = function(){
	return this.toString().replace(/([0-9]+?)(?=(?:[0-9]{3})+$)/g, '$1,');
}

Number.prototype.addDotto = function(){
	return this / 10000;
}

/* ------------- CiaoMinmax ------------- */
var CiaoMinmax = function(course){
	this.course = course;
	this.base = document.getElementById(course.id);
	this.min;
	this.max;
}
CiaoMinmax.prototype = {
	createMinmax : function(){
		var addStr = this.course.type == 'air' ? '~`' : '~';
		this.min = this.course.min.addComma() + addStr;
		if(this.course.type == 'air_b'){
			this.min = this.course.min.addDotto() + '~`';
		}
		this.max = this.course.max ? '`' + this.course.max.addComma() + '~' : '';
	},
	show : function(){
		if(this.base){
			this.createMinmax();
			this.base.innerHTML = this.min + this.max;
		}
	}
}

/* ------------- MixMinmax ------------- */
var MixMinmax = {
	create : function(id, minmaxArray){
		var mins = [];
		var maxs = [];
		for(var i = 0; i < minmaxArray.length; i++){
			var tmp = this.searchMinmax(minmaxArray[i]);
			if(tmp){
				mins.push(tmp.min);
				tmp.max ? maxs.push(tmp.max) : false;
			}
		}
		minmax.push({
			'id' : id,
			'min' : mins.sort(function(a, b){return(a - b)})[0],
			'max' : maxs.sort(function(a, b){return(b - a)})[0],
			'type' : 'ciao'
		})
	},
	searchMinmax : function(id){
		for(var i = 0; i < minmax.length; i++){
			if(minmax[i].id == id){
				return minmax[i];
			}
		}
		return false;
	}
}

/* ------------- ΐs ------------- */
window.onload = function(){
	for(var i = 0; i < minmax.length; i++){
		new CiaoMinmax(minmax[i]).show();
	}
}
