function pst(url)
{
	document.forms[0].action = url;
	return document.forms[0].submit();
}

function pstWName(url,frm)
{
	if (document.forms.length)
	{
		for (var i = 0; i < document.forms.length; i++)
		{
			if (document.forms[i].name == frm)
			{
				if (document.forms[i].elements['item_amount'].value == '0')
				{
					alert('ご購入数量を入力して下さい。');
					document.forms[i].elements['item_amount'].focus();
					return;
				}
				document.forms[i].action = url;
				return document.forms[i].submit();
			}
		}
	}
}

function pstWRow(url,row)
{
	if (document.forms[1].elements['item_amount' + row].value == '0')
	{
		alert('ご購入数量を入力して下さい。');
		document.forms[1].elements['item_amount' + row].focus();
		return;
	}
	document.forms[1].elements['item_id'].value = document.forms[1].elements['item_id' + row].value;
	document.forms[1].elements['item_amount'].value = document.forms[1].elements['item_amount' + row].value;
	document.forms[1].action = url;
	return document.forms[1].submit();
}

function pstWRow2(url,row)
{
	if (document.forms[1].elements['item_amount' + row].value == '0')
	{
		alert('ご購入数量を入力して下さい。');
		document.forms[1].elements['item_amount' + row].focus();
		return;
	}
	document.forms[1].elements['item_id'].value = document.forms[1].elements['item_id' + row].value;
	document.forms[1].elements['item_amount'].value = document.forms[1].elements['item_amount' + row].value;
	document.forms[1].action = url;
	return document.forms[1].submit();
}


function chkNumber(val , obj, alrt)
{
	v = new String(val);
	reg = /[^0-9]/g ;
	
	if(val.match(reg))
	{
		if(arguments[1])
		{
			obj.value = '';
			if(arguments[2])
			{
				alert('数値のみ入力してください。');
			}
		}
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function format_comma(val)
{
	var minus=val.charAt(0)=="-"?"-":""
	if(minus!=""){val=val.substring(1)}
	var tmp="",c=0
	for(i=0;i<val.length;i++){
	if(val.charAt(i)>="0"&&val.charAt(i)<="9"||val.charAt(i)=="."&&c++==0){tmp+=val.charAt(i)}
	}
	var d="",i=tmp.indexOf(".")
	if(i!=-1){
	d=tmp.substring(i)
	if(d=="."){d=""}
	tmp=tmp.substring(0,i)
	}
	while(tmp.charAt(0)=="0"&&tmp!="0"){tmp=tmp.substring(1)}
	val=tmp
	tmp=""
	for(i=val.length-1;i>=0;i--){
	tmp=val.charAt(i)+tmp
	if((val.length-i)%3==0&&i!=0){tmp=","+tmp}
	}
	if(tmp==""&&d!=""){tmp="0"}
	if(minus!=""&&tmp==""){minus=""}
	return minus+tmp+d
}


function getUrlParam(nm)
{
	var qs = new Array;
	if (location.search.length > 1)
	{
		var arr1 = location.search.substr(1).split("&"); 
		for (var x in arr1)
		{
			var arr2 = arr1[x].split("="); 
			if(arr2[0] == nm)
			{
				return arr2[1];
				break;
			}
		}
	}
	return '';
}

function replaceUrlParam(nm, v, url, flg)
{
	var qs = new Array();
	if(!arguments[2])
	{
		var arr = getURLsplit(location.href);
	}
	else
	{
		var arr = getURLsplit(url);
	}
	if(!arguments[3])
	{
		flg = false;
	}
	else
	{
		flg = true;
	}
	for(var i=0; i<arr.length; i++)
	{
		if(arr[i][0] != nm)
		{
			qs.push(new Array(arr[i][0], arr[i][1]));
		}
	}
	qs.push(new Array(nm, v))
	
  if(flg)
  {
		return qs;
  }
  else
  {
  	var tmpArr = new Array();
  	for(var i=0; i<qs.length; i++)
  	{
  		tmpArr.push(qs[i][0] + '=' + qs[i][1]);
  	}
  	return tmpArr.join('&');
  }
  
	
}

function getURLsplit(url , flg)
{

		var tmp;
	var tmp_rslt = new Array();
	var rslt = new Array();

		if(!arguments[0]){
		var str = location.search.substring( 1, location.search.length );
	}else{
		var str = url.substr(url.indexOf('?',0) + 1 , url.length - url.indexOf('?',0) - 1)
	}

		qryStr = str.split('&');

		for(i=0; i< qryStr.length; i++){

				idx = qryStr[i].indexOf('=');
  	  if(idx==-1)	continue;

	      	  tmp = new Array;
    	tmp[0] = qryStr[i].substring(0, idx);
	    tmp[1] = qryStr[i].substring(idx+1, qryStr[i].length);
    
  	 		tmp_rslt = new Array(tmp[0],tmp[1]);

      	  rslt.push(tmp_rslt);
    
	  }
	  
	  	return rslt;
  
}


function encodeURL(str)
{
	var s0, i, s, u;
	s0 = "";
	for (i = 0; i < str.length; i++)
	{
		 s = str.charAt(i);
		 u = str.charCodeAt(i);
		 if (s == " ")
		 {
		 	s0 += "+";
		 }
		 else
		 {
			  if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a)))
			  {
					s0 = s0 + s;
			  }
			  else
			  {
					if ((u >= 0x0) && (u <= 0x7f))
					{
						 s = "0"+u.toString(16);
						 s0 += "%"+ s.substr(s.length-2);
					}
					else if (u > 0x1fffff)
					{
						 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)
					{
						 s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
						 s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
						 s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
					}
					else
					{
						 s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
						 s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
					}
			  }
		 }
		 
	}
	return s0;

}
	
	
function decodeURL(str)
{
	var s0, i, j, s, ss, u, n, f;
	s0 = "";
	for (i = 0; i < str.length; i++)
	{
		 s = str.charAt(i);
		 if (s == "+")
		 {
		 		s0 += " ";
		 }
		 else
		 {
			  if (s != "%")
			  {
			  	s0 += s;
			  }
			  else
			  {
					u = 0;
					f = 1;
					while (true)
					{
						 ss = "";
							  for (j = 0; j < 2; j++ )
							  {
									sss = str.charAt(++i);
									if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f")) || ((sss >= "A") && (sss <= "F")))
									{
										 ss += sss;
									}
									else
									{
										--i;
										break;
									}
							  }
						 n = parseInt(ss, 16);
						 if (n <= 0x7f)
						 {
						 		u = n;
						 		f = 1;
						 }
						 if ((n >= 0xc0) && (n <= 0xdf))
						 {
						 		u = n & 0x1f;
						 		f = 2;
						 }
						 if ((n >= 0xe0) && (n <= 0xef))
						 {
						 		u = n & 0x0f;
						 		f = 3;
						 	}
						 if ((n >= 0xf0) && (n <= 0xf7))
						 {
						 		u = n & 0x07;
						 		f = 4;
						 }
						 if ((n >= 0x80) && (n <= 0xbf))
						 {
						 		u = (u << 6) + (n & 0x3f);
						 		--f;
						 }
						 if (f <= 1)
						 {
						 		break;
						 }
						if (str.charAt(i + 1) == "%")
						{
							i++ ;
						}
						else
						{
							break;
						}
					}
			  s0 += String.fromCharCode(u);
			  }
		 }
	}

	return s0;

}
