okstr = '0123456789０１２３４５６７８９';

//パーツページ表示変更
function optionset(obj){
	dr = obj.dr.value;
	sc = obj.sc.value;
	if(obj.iv.checked){
		iv = 'y';
	}else{
		iv = 'n';
	}
	if(obj.stk.checked){
		stk = '1';
	}else{
		stk = '0';
	}

	hikisu = "";
	if(dr != ""){
		hikisu = hikisu + "&dr=" + dr;
	}
	if(sc != ""){
		hikisu = hikisu + "&sc=" + sc;
	}
	if(iv != ""){
		hikisu = hikisu + "&iv=" + iv;
	}
	if(stk != ""){
		hikisu = hikisu + "&stk=" + stk;
	}
	if(document.forms['Searchform'].elements['mt'].value != ""){
		hikisu = hikisu + "&mt=" + document.forms['Searchform'].elements['mt'].value;
	}
	if(document.forms['Searchform'].elements['slv'].value != ""){
		hikisu = hikisu + "&slv=" + document.forms['Searchform'].elements['slv'].value;
	}
	if(document.forms['Searchform'].elements['mlv'].value != ""){
		hikisu = hikisu + "&mlv=" + document.forms['Searchform'].elements['mlv'].value;
	}
	if(document.forms['Searchform'].elements['sn'].value != ""){
		hikisu = hikisu + "&sn=" + document.forms['Searchform'].elements['sn'].value;
	}
	if(document.forms['Searchform'].elements['s'].value != ""){
		hikisu = hikisu + "&s=" + document.forms['Searchform'].elements['s'].value;
	}
	if(document.forms['Searchform'].elements['c'].value != ""){
		hikisu = hikisu + "&c=" + document.forms['Searchform'].elements['c'].value;
	}
	if(document.forms['Searchform'].elements['m'].value != ""){
		hikisu = hikisu + "&m=" + document.forms['Searchform'].elements['m'].value;
	}
	if(document.forms['Searchform'].elements['sm'].value != ""){
		hikisu = hikisu + "&sm=" + document.forms['Searchform'].elements['sm'].value;
	}
	if(document.forms['Searchform'].elements['hm'].value != ""){
		hikisu = hikisu + "&hm=" + document.forms['Searchform'].elements['hm'].value;
	}
	if(document.forms['Searchform'].elements['call'].value != ""){
		hikisu = hikisu + "&call=" + document.forms['Searchform'].elements['call'].value;
	}
	if(document.forms['Searchform'].elements['b'].value != ""){
		hikisu = hikisu + "&b=" + document.forms['Searchform'].elements['b'].value;
	}
	if(document.forms['Searchform'].elements['itemcode'].value != ""){
		hikisu = hikisu + "&itemcode=" + document.forms['Searchform'].elements['itemcode'].value;
	}
	if(document.forms['Searchform'].elements['brcode'].value != ""){
		hikisu = hikisu + "&brcode=" + document.forms['Searchform'].elements['brcode'].value;
	}
	if(document.forms['Searchform'].elements['sbrcode'].value != ""){
		hikisu = hikisu + "&sbrcode=" + document.forms['Searchform'].elements['sbrcode'].value;
	}
	if(document.forms['Searchform'].elements['mkrcode'].value != ""){
		hikisu = hikisu + "&mkrcode=" + document.forms['Searchform'].elements['mkrcode'].value;
	}
	if(document.forms['Searchform'].elements['setflg'].value != ""){
		hikisu = hikisu + "&setflg=" + document.forms['Searchform'].elements['setflg'].value;
	}
	if(document.forms['Searchform'].elements['campcode'].value != ""){
		hikisu = hikisu + "&campcode=" + document.forms['Searchform'].elements['campcode'].value;
	}
	if(document.forms['Searchform'].elements['findtext'].value != ""){
		hikisu = hikisu + "&findtext=" + encodeURL(document.forms['Searchform'].elements['findtext'].value);
	}
	if(document.forms['Searchform'].elements['finduriamt1'].value != ""){
		hikisu = hikisu + "&finduriamt1=" + document.forms['Searchform'].elements['finduriamt1'].value;
	}
	if(document.forms['Searchform'].elements['finduriamt2'].value != ""){
		hikisu = hikisu + "&finduriamt2=" + document.forms['Searchform'].elements['finduriamt2'].value;
	}
	if(document.forms['Searchform'].elements['findspec'].value != ""){
		hikisu = hikisu + "&findspec=" + encodeURL(document.forms['Searchform'].elements['findspec'].value);
	}

	hikisu = hikisu.substr(1);

	var expires = new Date();
	expires.setTime(expires.getTime() + (7*24*60*60*1000));
	setCookie("dr", dr, expires.toGMTString());
	setCookie("sc", sc, expires.toGMTString());
	setCookie("iv", iv, expires.toGMTString());

	location.href="http://www.dospara.co.jp/goods_pc_parts/goods_pc_parts.php?" + hikisu;

}

//パーツ検索
function textsearch(obj){
	str1 = obj.findtext.value;
	str2 = obj.finduriamt1.value;
	str3 = obj.finduriamt2.value;

	err = 0;
	if(str2 != ""){
		for (i=0;i<str2.length;i++){
			if (okstr.indexOf(str2.charAt(i)) == -1){
				err++;
			}
		}
	}
	if(str3 != ""){
		for (i=0;i<str3.length;i++){
			if (okstr.indexOf(str3.charAt(i)) == -1){
				err++;
			}
		}
	}
	if(str1 == "" && str2 == "" && str3 == ""){
		alert('検索する文字列を入力してください。');
		return false;
	}else{
		if (err!=0){
			alert('価格検索には数字を入力してください。');
			return false;
		}else{

			hikisu = "";
			if(getCookie("dr") != ""){
				hikisu = hikisu + "&dr=" + getCookie("dr");
			}
			if(getCookie("sc") != ""){
				hikisu = hikisu + "&sc=" + getCookie("sc");
			}
			if(getCookie("iv") != ""){
				hikisu = hikisu + "&iv=" + getCookie("iv");
			}

			hikisu = hikisu + "&stk=0";

			if(str1 != ""){
				hikisu = hikisu + "&findtext=" + encodeURL(str1);
			}
			if(str2 != ""){
				hikisu = hikisu + "&finduriamt1=" + str2;
			}
			if(str3 != ""){
				hikisu = hikisu + "&finduriamt2=" + str3;
			}
			if(hikisu != ""){
				hikisu = hikisu + "&sn=y";
			}
			if(typeof(obj.s)!=typeof(undefined)){
				if(obj.s.value != ""){
					hikisu = hikisu + "&s=" + obj.s.value;
				}
			}
			if(typeof(obj.c)!=typeof(undefined)){
				if(obj.c.value != ""){
					hikisu = hikisu + "&c=" + obj.c.value;
				}
			}
			if(typeof(obj.m)!=typeof(undefined)){
				if(obj.m.value != ""){
					hikisu = hikisu + "&m=" + obj.m.value;
				}
			}
			if(typeof(obj.sm)!=typeof(undefined)){
				if(obj.sm.value != ""){
					hikisu = hikisu + "&sm=" + obj.sm.value;
				}
			}
			if(typeof(obj.hm)!=typeof(undefined)){
				if(obj.hm.value != ""){
					hikisu = hikisu + "&hm=" + obj.hm.value;

				if(typeof(obj.brcode)!=typeof(undefined)){
					if(obj.brcode.value != ""){
						hikisu = hikisu + "&brcode=" + obj.brcode.value;
					}
				}
				if(typeof(obj.sbrcode)!=typeof(undefined)){
					if(obj.sbrcode.value != ""){
						hikisu = hikisu + "&sbrcode=" + obj.sbrcode.value;
					}
				}

				}
			}
			if(typeof(obj.call)!=typeof(undefined)){
				if(obj.call.value != ""){
					hikisu = hikisu + "&call=" + obj.call.value;
				}
			}
			if(typeof(obj.b)!=typeof(undefined)){
				if(obj.b.value != ""){
					hikisu = hikisu + "&b=" + obj.b.value;
				}
			}


			hikisu = hikisu.substr(1);

			location.href="http://www.dospara.co.jp/goods_pc_parts/goods_pc_parts.php?" + hikisu;

			return false;
		}
	}
}

//パーツ単品をカートに入れる
function partcartin(itemcode){
	setflg_value = document.forms['fm' + itemcode].elements['psf'].value;
	campcode_value = document.forms['fm' + itemcode].elements['pc'].value;
	itemcode_value = itemcode;
	qty_value = document.forms['fm' + itemcode].elements['pq'].value;

	location.href="/cart/cart.php?gf=1&gs=" + setflg_value + "&gc=" + campcode_value + "&gi=" + itemcode_value + "&gq=" + qty_value;
}

//パーツセット品をカートに入れる
function partcartin2(campcode){
	setflg_value = document.forms['fm' + campcode].elements['psf'].value;
	campcode_value = campcode;
	setcode_value = document.forms['fm' + campcode].elements['psc'].value;
	qty_value = document.forms['fm' + campcode].elements['pq'].value;

	location.href="/cart/cart.php?gf=1&gs=" + setflg_value + "&gc=" + campcode_value + "&gi=" + setcode_value + "&gq=" + qty_value;
}

//カンマ入れ
function conv2Commaed(val) {
	if (val < 0) {
		return "-" + conv2Commaed(-val);
	}
	if (val >= 1000) {
		return conv2Commaed(Math.floor(val / 1000)) + "," + (1000 + val % 1000 + "").substr(1);
	}
	return val;
}

//スペックウインドウオープン（購入可）
function specdisplaynewwindow(itemcode){
	window.open("http://www.dospara.co.jp/goods_pc_parts/goods_pc_parts_spec.php?head=n&footer=n&m=n&s=n&ic=" + itemcode,"_blank","status=no, toolbar=no, location=no, menubar=no, scrollbars=yes, resizable=yes,width=780,height=600");
}

//スペックウインドウオープン（スペック参照用）
function specdisplaynewwindow2(itemcode){
	window.open("http://www.dospara.co.jp/goods_pc_parts/goods_pc_parts_spec.php?head=n&footer=n&m=n&s=n&b=n&k=n&ic=" + itemcode,"_blank","status=no, toolbar=no, location=no, menubar=no, scrollbars=yes, resizable=yes,width=780,height=600");
}

//汎用ウインドウオープン
function newwindow(URL,WSIZE,HSIZE,SCROLL,RESIZE){
	if(URL==""){return;}
	if(WSIZE==""){WSIZE='320';}
	if(HSIZE==""){HSIZE='300';}
	if(SCROLL==""){SCROLL='yes';}else{SCROLL='no';}
	if(RESIZE==""){RESIZE='yes';}else{RESIZE='no';}
	window.open(URL,'window','width=' + WSIZE + ',height=' + HSIZE + ', toolbar=no, directories=no, scrollbars=' + SCROLL + ', resizable=' + RESIZE + '');
}

function OpenVoteWin(URL){
	if(URL==""){ return;}
	window.open( URL,'result','width=400,height=400,toolbar=no,directories=no');
}

function jump(URL){
	if(URL==""){ return;}
	window.open(URL);
}

//クッキー取得
function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len) {
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);
		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) {
			return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
		}
		xx1 = xx2 + 1;
	}
	return("");
}

//クッキーセット
function setCookie(key, val, time) {
	tmp = key + "=" + escape(val) + "; ";
	tmp += "path=/; ";
	if(time == ""){
		tmp += "expires=Fri, 31-Dec-2030 23:59:59; ";
	}else{
		tmp += "expires=" + time + "; ";
	}
	document.cookie = tmp;
}

//クッキークリア
function clearCookie(key) {
	setCookie(key, 'XXX', '1-Jan-1997 00:00:00');
}

//税込み価格算出
function get_amt_intax (amt){
	ret = Math.ceil(amt * ((100 + 5) / 100));
	return ret;
}

//税抜き価格算出
function get_amt_notax (amt){
	ret = Math.floor(amt / (100 + 5) * 100);
	return ret;
}

//URLエンコード
function encodeURL(str){
	var s0, i, s, u;
	s0 = "";								// encoded str
	for (i = 0; i < str.length; i++){ 	// scan the source
		s = str.charAt(i);
		u = str.charCodeAt(i);					// get unicode of the char
		if (s == " "){s0 += "+";} 			// SP should be converted to "+"
		else {
			if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){ 			// check for escape
					s0 = s0 + s;						// don't escape
			}
			else {									// escape
				if ((u >= 0x0) && (u <= 0x7f)){ 		// single byte format
						s = "0"+u.toString(16);
						s0 += "%"+ s.substr(s.length-2);
				}
				else if (u > 0x1fffff){ 		// quaternary byte format (extended)
						s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
						s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
						s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
						s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
				}
				else if (u > 0x7ff){				// triple byte format
						s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
						s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
						s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
				}
				else {											// double byte format
						s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
						s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
				}
			}
		}
	}
	return s0;
}

//左メニュー
function exMenu(BRCODE){
	if(document.all){
		if (document.all['treeMenu' + BRCODE].style.display == 'none'){
			document.all['treeMenu' + BRCODE].style.display = "block";
			document.images['icon_img' + BRCODE].src = "../../img/minus.gif";
		}else{
			document.all['treeMenu' + BRCODE].style.display = "none";
			document.images['icon_img' + BRCODE].src = "../../img/plus.gif";
		}
	}
	if(document.layers){
		if (document.layers['treeMenu' + BRCODE].display == 'none'){
			document.layers['treeMenu' + BRCODE].display = "block";
			document.images['icon_img' + BRCODE].src = "../../img/minus.gif";
		}else{
			document.layers['treeMenu' + BRCODE].display = "none";
			document.images['icon_img' + BRCODE].src = "../../img/plus.gif";
		}
	}
	if(!document.all && document.getElementById){ 
		if (document.getElementById('treeMenu' + BRCODE).style.display == 'none'){
			document.getElementById('treeMenu' + BRCODE).style.display = "block";
			document.images['icon_img' + BRCODE].src = "../../img/minus.gif";
		}else{
			document.getElementById('treeMenu' + BRCODE).style.display = "none";
			document.images['icon_img' + BRCODE].src = "../../img/plus.gif";
		}
	}
}
