jQuery.noConflict();

//プラグイン読込
var admin_path = '/';
for(var idx = 0; idx < jquery_plugins.length; idx++){
	var item = jquery_plugins[idx];
	var script_tag = '';
	if(item.type.toLowerCase() == 'js'){
		script_tag = '<script type="text/javascript" src="' + admin_path + item.dir + 'js/' + item.fname + '"';
		if(item.charset) script_tag += ' charset="' + item.charset + '"';
		script_tag += '></script>';
	}
	if(item.type.toLowerCase() == 'css'){
		script_tag = '<link rel="stylesheet" type="text/css" href="' + admin_path + item.dir + 'css/' + item.fname + '"';
		if(item.charset) script_tag += ' charset="' + item.charset + '"';
		script_tag += ' />';
	}
	document.write(script_tag);
}

//loadイベントへの追加
function addOnLoadEvent(handler){
	jQuery.event.add(window, "load", handler);
}

//数値カンマ付
function addFigure(target){
	var num = new String(target).replace(/,/g, '');
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, '$1,$2')));
	return num;
}

//数値に変換
function toNumeric(str){
	var num = parseInt(str, 10);
	return typeof num === 'number' && isFinite(num) ? num : 0;
}

//数値整形(cols:桁数,num:対象数値,ch:埋める文字)
function numberFormat(cols, num, ch){
	var numstr = new String(num);
	var numcnt = cols - numstr.length;
	if(numcnt > 0){
		while(numcnt-- > 0){
			numstr = ch + numstr;
		}
	}
	return numstr;
}

//端数処理
function toRoundDown(target, digits){
	var dec = Math.pow(10, digits);
	if(target < 0) dec *= -1;
	return Math.floor(target * dec) / dec;
}
function toRoundUp(target, digits){
	var dec = Math.pow(10, digits);
	if(target < 0) dec *= -1;
	return Math.ceil(target * dec) / dec;
}
function toRoundHalf(target, digits){
	var dec = Math.pow(10, digits);
	if(target > 0){
		return Math.floor((target * dec) + 0.5) / dec;
	}else{
		return Math.ceil((target * dec) - 0.5) / dec;
	}
}
function toRoundDecimal(target, digits, hasukbn){
	var dec = 0;
	switch(hasukbn){
		case 2: dec = toRoundUp(target, digits); break;
		case 1: dec = toRoundHalf(target, digits); break;
		default: dec = toRoundDown(target, digits); break;
	}
	return dec;
}

//日付チェック
function isDate(text) {
	if(text.length == 0 || text == ""){
		return false;
	}
	var arrDate = text.split("/");
	if(arrDate.length == 3){
		var date = new Date(arrDate[0] , arrDate[1] - 1 ,arrDate[2]);
		if(date.getFullYear() == arrDate[0] && 
			 (date.getMonth() == arrDate[1] - 1) && 
			   date.getDate() == arrDate[2]){
			return true;
		}
	}
	return false;
}

//日付変換
function toDateFormat(date) {
	if(!date) return '';
	var arrDate = new Array(date.getFullYear(), numberFormat(2, date.getMonth() + 1, '0'), numberFormat(2, date.getDate(), '0'));
	return arrDate.join('/');
}

/* メールアドレスチェック */
function isEmail(text){
	if(text.length == 0 || text == "") return false;
	var str = text;
	if(!str.match(/^([\w\.\-\/]+)@([\w_\-]+)\.([\w_\.\-]*)[a-z][a-z]$/i)){
		return false;
	}
	return true;
}

//印刷関連
function is_print_out() {
   /* print() が使えるブラウザかどうかを判断 */
  if(navigator.userAgent.match(/msie (\d)/i))
    v = (eval(RegExp.$1) >= 5) ? 1 : 0;
  else if (self.innerWidth)
    v = (eval(navigator.appVersion.charAt(0)) >= 4) ? 1 : 0;
  else v = 0;
  return v;
}
function print_out() {
  /* print() が使えるブラウザなら印刷を実行 */
  /* チェックの必要はなさそう
  if(is_print_out()) self.print();
  else alert("お使いのブラウザではこの機能は利用できません.\n\nファイルメニューより印刷してください.");
  */
  self.print();
}

//画像サイズ取得
function getActualDimension(image) {
	var run, mem, w, h, key = "actual";

	// for Firefox, Safari, Google Chrome
	if("naturalWidth" in image){
		return { width:  image.naturalWidth, height: image.naturalHeight };
	}

	if("src" in image){	// HTMLImageElement
		if(image[key] && image[key].src === image.src){
			return image[key];
		}
		if(document.uniqueID){	// for IE
			run = image.runtimeStyle;
			mem = { w: run.width, h: run.height };	// keep runtimeStyle
			run.width  = "auto";	// override
			run.height = "auto";
			w = image.width;
			h = image.height;
			run.width  = mem.w;		// restore
			run.height = mem.h;
		}else{	// for Opera and Other

			//function fn(){
			//	w = image.width;
			//	h = image.height;
			//}
			//mem = { w: image.width, h: image.height }; // keep current style
			//image.removeAttribute("width");
			//image.addEventListener("DOMAttrModified", fn, false);
			//image.removeAttribute("height");
			//// call fn
			//image.removeEventListener("DOMAttrModified", fn, false);
			//image.width  = mem.w; // restore
			//image.height = mem.h;

			mem = { w: image.width, h: image.height };	// keep current style
			image.removeAttribute("width");
			image.removeAttribute("height");
			w = image.width;
			h = image.height;
			image.width  = mem.w;	// restore
			image.height = mem.h;
		}
		return image[key] = { width: w, height: h, src: image.src }; // bond
	}
	// HTMLCanvasElement
	return { width: image.width, height: image.height };
}

