
function getScrollLeft() { 
	if ((navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1)) {
		return document.body.scrollLeft;
	} else if (window.pageXOffset) {
		return window.pageXOffset;
	} else {

		return 0;
	}
}


function getScrollTop() { 
	if (document.documentElement.scrollTop) {
		return document.documentElement.scrollTop;
	} else if (document.body.scrollTop) {
		return document.body.scrollTop;
	} else if (window.pageYOffset) {
		return window.pageYOffset;
	} else {
		return 0;
	}
}


var pageScrollTimer;

function pageScroll(toX,toY,frms,cuX,cuY) { 

	if (pageScrollTimer) clearTimeout(pageScrollTimer);
	if (!toX || toX < 0) toX = 0;
	if (!toY || toY < 0) toY = 0;
	if (!cuX) cuX = 0 + getScrollLeft();
	if (!cuY) cuY = 0 + getScrollTop();
	if (!frms) frms = 6;

	if (toY > cuY && toY > (getAnchorPosObj('end','enddiv').y) - getInnerSize().height) toY = (getAnchorPosObj('end','enddiv').y - getInnerSize().height) + 1;
	cuX += (toX - getScrollLeft()) / frms; if (cuX < 0) cuX = 0;
	cuY += (toY - getScrollTop()) / frms;  if (cuY < 0) cuY = 0;

	var posX = Math.floor(cuX);
	var posY = Math.floor(cuY);

	window.scrollTo(posX, posY);

	if (posX != toX || posY != toY) {
		pageScrollTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+cuX+","+cuY+")",16);
	}

}


function jumpToPageTop() { 

	 pageScroll(0,0,3);

}

//子ウィンドウ表示
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

//お問い合わせフォームにリンク
function opener_disp_contact(){ 
	if(!window.opener || window.opener.closed){ 
		window.alert('メインウィンドウがありません'); 
	}else{ 
		window.opener.location.href = '/contact.html'; 
	}

	window.close();
}

function move_item(form_obj, index, next){
	var next_index = index + next;

	if(!document.getElementById('stock_no[' + next_index + ']')) return false;

	var stock_no = document.getElementById('stock_no[' + next_index + ']').value;
	var color = document.getElementById('color[' + next_index + ']').value;
	var size = document.getElementById('size[' + next_index + ']').value;
	var stock_code = document.getElementById('stock_code[' + next_index + ']').value;
	var price = document.getElementById('price[' + next_index + ']').value;
	var member_price = document.getElementById('member_price[' + next_index + ']').value;
	var stock_count = document.getElementById('stock_count[' + next_index + ']').value;
	var comment = document.getElementById('comment[' + next_index + ']').value;

	document.getElementById('stock_no[' + next_index + ']').value = document.getElementById('stock_no[' + index + ']').value;
	document.getElementById('color[' + next_index + ']').value = document.getElementById('color[' + index + ']').value;
	document.getElementById('size[' + next_index + ']').value = document.getElementById('size[' + index + ']').value;
	document.getElementById('stock_code[' + next_index + ']').value = document.getElementById('stock_code[' + index + ']').value;
	document.getElementById('price[' + next_index + ']').value = document.getElementById('price[' + index + ']').value;
	document.getElementById('member_price[' + next_index + ']').value = document.getElementById('member_price[' + index + ']').value;
	document.getElementById('stock_count[' + next_index + ']').value = document.getElementById('stock_count[' + index + ']').value;
	document.getElementById('comment[' + next_index + ']').value = document.getElementById('comment[' + index + ']').value;

	document.getElementById('stock_no[' + index + ']').value = stock_no;
	document.getElementById('color[' + index + ']').value = color;
	document.getElementById('size[' + index + ']').value = size;
	document.getElementById('stock_code[' + index + ']').value = stock_code;
	document.getElementById('price[' + index + ']').value =price;
	document.getElementById('member_price[' + index + ']').value = member_price;
	document.getElementById('stock_count[' + index + ']').value = stock_count;
	document.getElementById('comment[' + index + ']').value = comment;
}

//在庫コード自動作成
function make_stock_code(tenpo_no, item_code, rows){
	var i;
	var code;
	var del_gyou = new Array();

	//削除されたコードの行数を取得
	for(i=0; i<document.getElementsByName("del_jan_code").length; i++){
		var sub_no = document.getElementsByName("del_jan_code")[i].value;
		del_gyou[i] = sub_no.substr(sub_no.length -4, 3);
	}
	

	if(document.getElementById('stock_code_0')){

		if(tenpo_no.length == 1) { tenpo_no = "0" + tenpo_no;}
		var tmp_len = item_code.length;
		for(i=0; i<(7 - tmp_len); i++) item_code = "0" + item_code;

		if(isNaN(item_code)) {
			alert("商品コードに半角数字以外が含まれています。");
			return false;
		}

		if(item_code.length > 7) {
			alert("商品コードが7桁以下で入力してください。");
			return false;
		}


		count = 0;
		if(!isNaN(rows)){
	
			for(i=0; i<rows; i++){
				sub_no = new String(count);

				
				if(sub_no.length == 1) { sub_no = "00" + sub_no;}
				if(sub_no.length == 2) { sub_no = "0" + sub_no;}

				while(!check_gyou(sub_no, del_gyou)){
					count++;
					sub_no = new String(count);

					if(sub_no.length == 1) { sub_no = "00" + sub_no;}
					if(sub_no.length == 2) { sub_no = "0" + sub_no;}
				}
				
				document.getElementById('stock_code_' + i).value = mk_code(tenpo_no + item_code + sub_no);
				count++;
			}
	
		}else{
				sub_no = new String("0");
				
				if(sub_no.length == 1) { sub_no = "00" + sub_no;}
				if(sub_no.length == 2) { sub_no = "0" + sub_no;}
	
				document.getElementById('stock_code').value = mk_code(tenpo_no + item_code + sub_no);
		}
	}

}

//削除された行が含まれるかチェック
function check_gyou(sub_no, gyou){
	var i;
	for(i=0; i<gyou.length; i++){
		if(sub_no == gyou[i]) return false;
	}

	return true;
}

//コードにチェックデジットをつける
function mk_code(tmp){

	if(isNaN(tmp)) {
		alert("半角数字で入力してください");
		return;
	}

	if(tmp.length != 12) {
		alert("12桁で入力してください(" + tmp + ")");
		return;
	}

	var kisuu = 0;
	var gusuu = 0;
	var k_str = "";
	var g_str = "";

	for(var i=11; i>=0; i--){
		if(i % 2 != 0) {
			kisuu = kisuu + parseInt(tmp.charAt(i));
			if(k_str == "") k_str = tmp.charAt(i);
			else k_str = k_str + "+" + tmp.charAt(i);
		}else{
			gusuu = gusuu +  parseInt(tmp.charAt(i));
			if(g_str == "") g_str =tmp.charAt(i);
			else g_str = g_str + "+" + tmp.charAt(i);
		}
	}

	var str = k_str + " = " + kisuu + "<br>\n";
	str = str +  g_str + " = " + gusuu + "<br>\n";

	str = str + kisuu + " x 3 = ";
	kisuu = kisuu * 3;
	str = str + kisuu + "<br>\n";

	var total = kisuu + gusuu;
	str = str +  kisuu + "+" + gusuu + "=" + total+ "<br>\n";

	//一桁目を取り出す
	var first = total - parseInt(total / 10) * 10;
	var digit = 10 - first;
	if(digit == 10) digit = 0;
	return tmp + digit;
}


