	function setComma(inin)
	{
		var temp_str = String(inin);
		for(var i = 0 , retValue = String() , stop = temp_str.length; i < stop ; i++) retValue = ((i%3) == 0) && i != 0 ? temp_str.charAt((stop - i) -1) + "," + retValue : temp_str.charAt((stop - i) -1) + retValue;
		return retValue;
	}

	function su_plus(ob)
	{
		ob.parentNode.getElementsByTagName("div")[0].innerHTML += document.getElementById('sun_ori_div').innerHTML;
		ob.parentNode.getElementsByTagName("input")[0].value = parseInt(ob.parentNode.getElementsByTagName("input")[0].value,10) + 1;
		p_exe();
	}
	
	function su_minus(ob)
	{
		var obb = ob.parentNode.getElementsByTagName("div")[0].getElementsByTagName("div");
		var cnt = obb.length;

		if(cnt==1)
		{
			alert("ÃÖ¼Ò ÇÑ°³´Â ÀÔ·ÂÇÏ¼Å¾ß ÇÕ´Ï´Ù.");
		}
		else
		{
			//alert(ob.parentNode.getElementsByTagName("div")[0].outerHTML)
			//alert(cnt);
			ob.parentNode.getElementsByTagName("div")[0].getElementsByTagName("div")[cnt-1].removeNode(true);
			ob.parentNode.getElementsByTagName("input")[0].value = parseInt(ob.parentNode.getElementsByTagName("input")[0].value,10) - 1;
		}
		
		p_exe();
	}


	var total_pcount = 0;
	
	function p_exe(ob)
	{
		
		
		try{
		if(ob.name == "s_child[]" || ob.name == "s_adult[]")
		{
			i=0;
			ss = ob.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("input");
			while (elementz = ss[i++])
			{
				if(elementz.name == "rec_cnt[]")rec_cnt = parseInt(elementz.value, 10);
			}
			
			i=0;
			sz = ob.parentNode.getElementsByTagName("input");
			while(elementx = sz[i++])
			{
				if(elementx.name == "s_adult[]")s_adult_ob = elementx;
				if(elementx.name == "s_child[]")s_child_ob = elementx;
			}
			
			if(ob.value > rec_cnt){alert(rec_cnt+"ÀÎ À» ÃÊ°úÇÏ¿© ÀÔ·ÂÇÏ¼Ì½À´Ï´Ù.");s_adult_ob.value=0;s_child_ob.value=0;p_exe(ob);return false;}
			
			
			if(ob.name == "s_adult[]")
			{
				if(rec_cnt>2)s_child_ob.value = rec_cnt - ob.value;
			}
			
			if(ob.name == "s_child[]")
			{
				if(rec_cnt>2)s_adult_ob.value = rec_cnt - ob.value;
			}
			
			if(parseInt(s_adult_ob.value,10) + parseInt(s_child_ob.value,10) > rec_cnt){alert(rec_cnt+"ÀÎ À» ÃÊ°úÇÏ¿© ÀÔ·ÂÇÏ¼Ì½À´Ï´Ù2.");s_adult_ob.value=0;s_child_ob.value=0;p_exe(ob);return false;}
			
			
		}
		}catch(e){}
		
		
		
		total_pcount = 0;
		
		var s_adult_ar = new Array();
		var s_child_ar = new Array();
		
		
		
  		var adult_price = 0;
  		var child_price = 0;
  		var ki_adult = 0;
  		var ki_child = 0;
  		
  	  	var adult_price = 0;
  	  	var child_price = 0;
  	  	var ki_adult = 0;
  	  	var ki_child = 0;
  		
  		tmp = 0;
  		
		i = 0;
		pr = 0;
		a = document.getElementsByTagName("input");
		while (element = a[i++]) 
		{
		  if (element.name == "ss_chk[]")
		  {
		  		s_price = 0;
		  		cb_price = 0;
		  		tax = 0;
		  		sm_price = 0;
		  		rec_cnt = 0;
		  		child_sale = 0;
		  		tf_sale = 0;
		  		su_su = 0;
		  		tmp = 0;
		  		
		  		j = 0;
		  		if(element.checked==true)
		  		{
		  			//alert(element.parentNode.parentNode.innerHTML);
		  			b = element.parentNode.parentNode.getElementsByTagName("input");
		  			while (element_b = b[j++])
		  			{
		  				if(element_b.name == "s_price[]")s_price = parseInt(element_b.value, 10);
		  				if(element_b.name == "cb_price[]")cb_price = parseInt(element_b.value, 10);
		  				if(element_b.name == "tax[]")tax = parseInt(element_b.value, 10);
		  				if(element_b.name == "sm_price[]")sm_price = parseInt(element_b.value, 10);
		  				if(element_b.name == "rec_cnt[]")rec_cnt = parseInt(element_b.value, 10);
		  				if(element_b.name == "child_sale[]")child_sale = parseInt(element_b.value, 10);
		  				if(element_b.name == "tf_sale[]")tf_sale = parseInt(element_b.value, 10);
		  				if(element_b.name == "su_su[]")su_su = parseInt(element_b.value, 10);

		  				if(element_b.name == "s_adult[]"){s_adult_ar[tmp] = parseInt(element_b.value, 10);}
		  				if(element_b.name == "s_child[]"){s_child_ar[tmp] = parseInt(element_b.value, 10);tmp++;}
		  			}

		  			
		  			for(h=0;h<s_adult_ar.length;h++)
		  			{
		  				
		  				//if(s_adult_ar[h]=='')s_adult_ar[h] = 0;
		  				//if(s_child_ar[h]=='')s_child_ar[h] = 0;
		  				
		  				switch(rec_cnt)
		  				{
		  					case 1:
		  						if(s_adult_ar[h] == 0 && s_child_ar[h] == 0){}
		  						else if((s_adult_ar[h] + s_child_ar[h]) == 1){pr += s_price;}  //1¸í
		  						else
		  						{
		  							//alert("Á¶°Ç¿¡ ºÎÇÕÇÏÁö ¾Ê½À´Ï´Ù.");
		  							//return false;
		  						}
		  						break;
		  					case 2:
		  						if(s_adult_ar[h] == 0 && s_child_ar[h] == 0){}
		  						else if(s_adult_ar[h] == 1 && s_child_ar[h] == 0) //¼ºÀÎ 1
		  						{
		  							pr += (2 * cb_price) + tax + sm_price;
		  						}
		  						else if(s_adult_ar[h] == 1 && s_child_ar[h] == 1) //¼ºÀÎ 1 ¾î¸°ÀÌ 1
		  						{
		  							pr += (cb_price + tax + sm_price)*2;
		  						}
		  						else if(s_adult_ar[h] == 2 && s_child_ar[h] == 0) //¼ºÀÎ 2
		  						{
		  							pr += (cb_price + tax + sm_price)*2;
		  						}
		  						else
		  						{
		  							//alert("Á¶°Ç¿¡ ºÎÇÕÇÏÁö ¾Ê½À´Ï´Ù.");
		  							//return false;
		  						}
		  						break;
		  					case 3:
		  						if(s_adult_ar[h] == 0 && s_child_ar[h] == 0){}
		  						else if(s_adult_ar[h] == 3 && s_child_ar[h] == 0)  //¼ºÀÎ 3
		  						{
		  							pr += (cb_price + tax + sm_price)*2 + (tf_sale)*1;
		  						}
		  						else if(s_adult_ar[h] == 2 && s_child_ar[h] == 1)  //¼ºÀÎ 2 ¾î¸°ÀÌ 1
		  						{
		  							pr += (cb_price + tax + sm_price)*2 + (child_sale)*1;
		  						}
		  						else if(s_adult_ar[h] == 1 && s_child_ar[h] == 2)  //¼ºÀÎ 1 ¾î¸°ÀÌ 2
		  						{
		  							pr += (cb_price + tax + sm_price)*2 + (child_sale)*1;
		  						}
		  						else
		  						{
		  							//alert("Á¶°Ç¿¡ ºÎÇÕÇÏÁö ¾Ê½À´Ï´Ù.");
		  							//return false;
		  						}
		  						break;
		  					case 4:
		  						if(s_adult_ar[h] == 0 && s_child_ar[h] == 0){}
		  						else if(s_adult_ar[h] == 4 && s_child_ar[h] == 0)  //¼ºÀÎ 4
		  						{
		  							pr += (cb_price + tax + sm_price)*2 + (tf_sale)*2;
		  						}
		  						else if(s_adult_ar[h] == 3 && s_child_ar[h] == 1)  //¼ºÀÎ 3 ¾î¸°ÀÌ 1
		  						{
		  							pr += (cb_price + tax + sm_price)*2 + (tf_sale)*1 + (child_sale)*1;
		  						}
		  						else if(s_adult_ar[h] == 2 && s_child_ar[h] == 2)  //¼ºÀÎ 2 ¾î¸°ÀÌ 2
		  						{
		  							pr += (cb_price + tax + sm_price)*2 + (child_sale)*2;
		  						}
		  						else if(s_adult_ar[h] == 1 && s_child_ar[h] == 3)  //¼ºÀÎ 1 ¾î¸°ÀÌ 3
		  						{
		  							pr += (cb_price + tax + sm_price)*2 + (child_sale)*2;
		  						}
		  						else if(s_adult_ar[h] == 0 && s_child_ar[h] == 4)  //¾î¸°ÀÌ 4
		  						{
		  							//alert("Á¶°Ç¿¡ ºÎÇÕÇÏÁö ¾Ê½À´Ï´Ù.");
		  						}
		  						else
		  						{
		  							//alert("Á¶°Ç¿¡ ºÎÇÕÇÏÁö ¾Ê½À´Ï´Ù.");
		  							//return false;
		  						}
		  						break;
		  					default:
				  				pr += ((s_adult_ar[h]+s_child_ar[h]) * cb_price) + tax + sm_price;
		  						break;
		  				}
		  				
		  				total_pcount += s_adult_ar[h];
		  				total_pcount += s_child_ar[h];
		  			}
		  		}
		    	//if(element.value != '')psum = psum + parseInt(element.value.replace(/,/gi,''), 10);
		  }
		  
		  
		  if (element.name == "ki_chk[]")
		  {
		  	  	adult_price = 0;
		  	  	child_price = 0;
		  	  	ki_adult = 0;
		  	  	ki_child = 0;
		  		j = 0;
		  		if(element.checked==true)
		  		{
		  			cc = element.parentNode.parentNode.getElementsByTagName("input");
		  			//alert(element.parentNode.parentNode.innerHTML);
		  			
		  			while (element_c = cc[j++])
		  			{
		  				//alert(element_c.value);
		  				
		  				if(element_c.name == "adult_price[]")adult_price = parseInt(element_c.value, 10);
		  				if(element_c.name == "child_price[]")child_price = parseInt(element_c.value, 10);

		  				if(element_c.name == "ki_adult[]")ki_adult = parseInt(element_c.value, 10);
		  				if(element_c.name == "ki_child[]")ki_child = parseInt(element_c.value, 10);
	
		  			}
	  						pr += ki_adult * adult_price;
	  						pr += ki_child * child_price;

		  		}
		    	//if(element.value != '')psum = psum + parseInt(element.value.replace(/,/gi,''), 10);
		  }
		  
		}
		
		//alert(pr);
		if(document.getElementById('paytype1_all').checked)
		{
			document.getElementById('paydiv').style.display = "none";
			pre_per_price = parseInt(document.getElementById('pre_per_price').value, 10);
			
			
			document.getElementById('all_total_price_span').innerHTML= setComma(pr);
			document.getElementById('all_total_price').value= pr;
			
			document.getElementById('total_pcount').innerHTML = total_pcount;
			
			document.getElementById('pre_price_span').innerHTML = setComma(pr);
			document.getElementById('pre_price').value= pr;
			
			
			document.getElementById('total_price_span').innerHTML= setComma(pr);
			document.getElementById('total_price').value= pr;
		}


		if(document.getElementById('paytype1_div').checked)
		{
			document.getElementById('paydiv').style.display = "block";
			pre_per_price = parseInt(document.getElementById('pre_per_price').value, 10);
			
			
			document.getElementById('all_total_price_span').innerHTML= setComma(pr);
			document.getElementById('all_total_price').value= pr;
			
			document.getElementById('total_pcount').innerHTML = total_pcount;
			
			document.getElementById('pre_price_span').innerHTML = setComma(pre_per_price * total_pcount);
			document.getElementById('pre_price').value= pre_per_price * total_pcount;
			
			document.getElementById('total_price_span').innerHTML= setComma(pre_per_price * total_pcount);
			document.getElementById('total_price').value= pre_per_price * total_pcount;
		}

		return true;
	}
