	/*eCommerce's Script*/
	function fn_ecomm_addr_copy(obj)
	{
		var f = obj.form;
		if(obj.value=='N')
		{
			f.name_first_s.value=f.name_first_b.value;
			f.name_last_s.value=f.name_last_b.value;
			f.company_s.value=f.company_b.value;
			f.address1_s.value=f.address1_b.value;
			f.address2_s.value=f.address2_b.value;
			f.city_s.value=f.city_b.value;
			f.state_s.value=f.state_b.value;
			f.zipcode_s.value=f.zipcode_b.value;
			f.country_s.value=f.country_b.value;
			f.phone_day_s.value=f.phone_day_b.value;
			f.phone_night_s.value=f.phone_night_b.value;			
		}
	}

	function fn_ecomm_prd_img_disp_reset(cnt)	/*product detail page's Left Medium Image Paging*/
	{
		if(cnt<=1)return;
		for(i=0;i<cnt;i++)
		{
			var obj = document.getElementById('ecomm_prd_disp_'+i);
			obj.style.display = 'none';
		}	
	}

	function fn_ecomm_prd_img_disp(disp_idx)	/*product detail page's Left Medium Image Paging*/
	{
		var iObj = document.getElementById('ecomm_prd_disp_'+disp_idx);
		if(!iObj)return;
		iObj.style.display = 'block';	
		
	}

	function fn_ecomm_detail(ecomm_prd_idx,ven_idx,prd_idx)
	{
		var f = document.getElementById('fcon');
		f.ecomm_prd_idx.value = ecomm_prd_idx;
		fn_post_ecomm(f,ven_idx,prd_idx);
	}
	/*
	 * Prototype		:	(void) fn_post_page_ecomm(obj,int,int)
	 * Type				:	Ajax
	 * Parameters		:	obj 	- object(this)
	 *					:	prd_idx - int,
	 *					:	ven_idx - int
	 * Author			:	Sam,Kim
	 * Comments			:	fn_post_page¿Í °ÅÀÇ À¯»çÇÏ³ª fn_post_ecomm À» ÄÝÇÑ´Ù.
	 *						fn_post_root·Î Ã³¸®ÇÏµµ·Ï ÇÏ°í, ÀÏ´Ü »èÁ¦´Â º¸·ùÇÑ´Ù.
	 */
	function fn_post_page_ecomm(obj,prd_idx,ven_idx)
	{
		if(!prd_idx || prd_idx<=0)return;
		if(!ven_idx || ven_idx<=0)return;
		//fn_get_background(ven_idx);
		var f = document.getElementById('fcon');
		fn_category_tree_reset_ecomm(f);
		fn_post_ecomm(f,ven_idx,prd_idx)
	}

	function fn_category_tree_reset_ecomm(fobj)
	{
		fobj.tree_idx.value="";
		fobj.tree_list.value="";
		fobj.tree_level.value="";
		fobj.tree_path.value="";
		fobj.ecomm_prd_idx.value="";
	}

	/*
	* Prototype			:	(void) fn_post_category_tree_ecomm(obj,int,int,int,int,int)
	* Type				:	Ajax
	* parameters		:	obj - object(this)
	*						prd_idx		- int, Root Category Index
	*						ven_idx		- int, MenuPool Index
	*						tree_idx	- int, Sub Category Index
	*						tree_list	- int, Sub Category Root Node Index
	*						tree_level	- int, Sub Category Depth
	* Comments			:	ÇÏÀ§ Ä«Å×°í¸®¸¦ È£ÃâÇÏ´Â AJAX ÇÔ¼ö.
	*						fn_post_tree·Î ´ëÄ¡
	*						¾ÕÀ¸·Î ºÒÇÊ¿äÇÒ °ÍÀ¸·Î »ç·áµÊ. ÀÏ´Ü, º¸Á¸ 2008.04.25
	*/
	function fn_post_category_tree_ecomm(obj,prd_idx,ven_idx,tree_idx,tree_list,tree_level)
	{
		var f = document.getElementById('fcon');
		if(tree_idx != '')f.tree_idx.value = tree_idx;
		if(tree_list != '')f.tree_list.value = tree_list;
		if(tree_level !='')f.tree_level.value = tree_level;
		f.tree_path.value = (f.tree_path.value=="")?obj.innerText:f.tree_path.value+" > "+obj.innerText;
		f.ecomm_prd_idx.value="";
		fn_post_ecomm(f,ven_idx,prd_idx);
	}

	function fn_ecomm_prd_cart_checkbox(bObj)
	{
		var fObj = bObj.form;
		if(!fObj)return;
		
		var chk = fObj.elements['pchk_prd_idx[]'];
		if(!chk)return;
		var chked_cnt = 0;
		if(chk.length>0)
		{
			for(i=0;i<chk.length;i++)
			{
				if(chk[i].checked)chked_cnt++;
			}
		}
		else
		{
			if(chk.checked==true)chked_cnt=1;
		}
		if(chked_cnt>0)
		{
			var f = document.getElementById('fecomm');
			fObj.action = f.action;
			fn_valid_ajaxSubmit(fObj,'fn_ecomm_prd_cart_out');
		}
		else alert('Please Check the items');
		return;
	}

	function fn_ecomm_prd_cart(ecomm_prd_idx,bObj)
	{
		var fObj = bObj.form;
		if(!fObj)return;
		var f = document.getElementById('fecomm');
		f.ecomm_prd_idx.value = ecomm_prd_idx;
		f.cnt.value=fObj.pPrdCnt.value;
		fn_valid_ajaxSubmit(f,'fn_ecomm_prd_cart_out');
	}

	function fn_ecomm_cart_form_reset()
	{
		var f = document.getElementById('fecomm');
		if(!f)return;
		f.ecomm_prd_idx.value="";
		f.cnt.value="";	
	}

	function fn_ecomm_show_cart()
	{
		var f = document.getElementById('fecomm');
		if(!f)return;
		fn_ecomm_cart_form_reset();
		ajaxSubmit(f,'fn_ecomm_prd_cart_out');
	}

	function fn_ecomm_show_cart_update(bObj)
	{
		var fObj = bObj.form;
		var f = document.getElementById('fecomm');
		fObj.action = f.action;
		ajaxSubmit(fObj,'fn_ecomm_prd_cart_update_out');		
	}

	function fn_ecomm_prd_cart_update_out(responseText)
	{
		fn_ecomm_prd_cart_out(responseText);
		fn_ecomm_cart_form_reset();
		var f = document.getElementById('fViewMyCart');
		fn_ajax_request_body(f);
	}

	function fn_ecomm_prd_cart_out(responseText)
	{
		var obj = document.getElementById('div_cart_info');
		obj.innerHTML = responseText;	
	}

	function fn_ecomm_view_my_cart_update(bObj)
	{
		if(!bObj)return;
		var f = bObj.form;
		var tarFunc = "fn_ecomm_view_my_cart_update_out";
		fn_ajax_request_body(f,tarFunc);			
	}

	function fn_ecomm_view_my_cart_update_out(responseText)
	{
		fn_response_page(responseText);
		var f = document.getElementById('fecomm');
		f.ecomm_prd_idx.value=0;
		f.cnt.value=0;
		fn_ecomm_show_cart(1);
	}

	function fn_ecomm_check_out(btnObj)		/*for check out*/
	{
		var f = btnObj.form;
		fn_ajax_request_body(f);
	}

	function fn_ecomm_submit_order(btnObj)	/*for submit order*/
	{
		var f = btnObj.form;
		fn_ajax_request_body(f);
	}

	//order ¿¡¼­ ¾²´Â shipping function
	function fn_ecomm_cal_shipping_order(btnObj,ccd_ship_method,origPostal,origState,origTaxRate)
	{
		var f			= btnObj.form;
		var weight		= f.weight.value; //document.getElementById('23_weight').value;
		var destPostal	= f.zipcode_s.value;
		var destState	= "";
		if(!f.state_s){}
		else destState = f.state_s.value;
		
		if(weight<=0)return;
		
		var af = fn_create_form("fShippingXml","post","/pages/ecommerce/ups_shipping_xml.php3");
		var objOinput = document.createElement("input");
		objOinput.setAttribute("type" ,"hidden");
		objOinput.setAttribute("name" ,"15_origPostal");
		objOinput.setAttribute("value",origPostal);

		var objDinput = document.createElement("input");
		objDinput.setAttribute("type" ,"hidden");
		objDinput.setAttribute("name" ,"19_destPostal");
		objDinput.setAttribute("value",destPostal);

		var objWinput = document.createElement("input");
		objWinput.setAttribute("type" ,"hidden");
		objWinput.setAttribute("name" ,"23_weight");
		objWinput.setAttribute("value",weight);

		if(origState == destState)
		{
			var taxRate = origTaxRate;
			var objTinput = document.createElement("input");
			objTinput.setAttribute("type","hidden");
			objTinput.setAttribute("name","taxRate");
			objTinput.setAttribute("value",taxRate);
			af.appendChild(objTinput);
		}

		af.appendChild(objOinput);
		af.appendChild(objDinput);
		af.appendChild(objWinput);

		fn_ecomm_cal_shipping(af,ccd_ship_method);
	}

	function fn_ecomm_cal_shipping(f,ccd_ship_method)
	{
		var tarFunc = "fn_ecomm_cal_shipping_out";
		
		if(ccd_ship_method==2)
			f.action = '/pages/ecommerce/ups_shipping_xml.php3';
		else if(ccd_ship_method==1)
			f.action = '/pages/ecommerce/fedex_shipping_xml.php3';
		
		//
		fn_open_progress();
		//
		fn_ajax_request_body(f,tarFunc);
	}
	
	function fn_ecomm_cal_shipping_out(responseText)
	{
		var dObj = document.getElementById('divRateSelect');
		fn_ecomm_cal_shipping_select();
	}
	/* Closing Function for Shipping Method */
	function fn_ecomm_cal_shipping_close()
	{
		fn_close_progress();
	}
	
	/*Testing Shipping XML Information	*/
	function fn_ecomm_cal_shipping_select()
	{
		fn_ecomm_cal_reset();
		
		var ship_method_node = request.responseXML.getElementsByTagName("method");
		var tax_rate_node = request.responseXML.getElementsByTagName("tax_rate");
		var subtotal = document.getElementById('pSubTotal').value;
		
		ship_method = ship_method_node[0].firstChild.nodeValue;
		tax_rate = tax_rate_node[0].firstChild.nodeValue;
		tax = eval(subtotal*(tax_rate/100));
		outTax = new Number(tax);
		
		document.getElementById('pTaxReal').value = tax;
		document.getElementById('pTaxDisp').value = fn_cal_comma(String(outTax.toFixed(2)));
		
		setShipControl(request,ship_method);
	}

	/*
	 *setShipCombo : Select¹æ½Ä
	 *setShipRadio : Radio ¹æ½Ä
	 */
	function setShipControl(request,ship_method)
	{
		var list = document.getElementById('serviceList');
		if(list != null)
			setShipCombo(request,ship_method);
		else
		{
			var rlist = document.getElementById('seviceRadio');
			if(rlist != null)setShipRadio(request,ship_method);
			else alert('There is no controls for shipping');
		}
	}
	
	function setShipRadio(request,ship_method)
	{
		var rlist = document.getElementById('seviceRadio');
		resetShipRadio(rlist);
		if(ship_method == 'UPS')setShipRadioUPS(request,rlist);
		else if(ship_method == 'FedEx')setShipRadioFedEx(request,rlist);
	}

	function resetShipRadio(rlist)
	{
		rlist.innerHTML = "";
	}
	
	function setShipRadioFedEx(request,list)
	{
		var reply = request.responseXML.getElementsByTagName("FDXRateAvailableServicesReply");
		
		if(reply.length >0)
		{
			for(var j=0;j<reply.length;j++)
			{
				var reply_node = reply[j];
				var rates = reply_node.getElementsByTagName("Entry");//request.responseXML.getElementsByTagName("Entry");
				if(rates.length > 0)
				{
					for(var i=0;i<rates.length;i++)
					{
						var node = rates[i];
						var servicecode = node.getElementsByTagName("Service")[0].firstChild.nodeValue;
						var servicename = servicecode;//getUPSSvcName(servicecode);
						/*
						*FDXG(GroundÀÇ °æ¿ì ÅÂ±×¿¡ totalCurrency¸¦ Æ÷ÇÔÇÏ°í ÀÖÁö ¾ÊÀ½.
						*/
						var totalCurrency = "USD"; //node.getElementsByTagName("EstimatedCharges")[0].getElementsByTagName("CurrencyCode")[0].firstChild.nodeValue;
						var totalCharges = node.getElementsByTagName("EstimatedCharges")[0].getElementsByTagName("DiscountedCharges")[0].getElementsByTagName("NetCharge")[0].firstChild.nodeValue;
						
						//addElementToList(list, totalCharges, servicename+" "+totalCurrency+" "+totalCharges);
						addElementToRadio(list, totalCharges, servicename+" "+totalCurrency+" "+totalCharges);//¿©±â¸¸´Ù¸£°Ô
					}
				}	
			}
		}
		fn_ecomm_cal_shipping_close();
	}
	
	function setShipRadioUPS(request,list)
	{
		var rates = request.responseXML.getElementsByTagName("RatedShipment");
		
		if(rates.length > 0)
		{
			for(var i=0;i<rates.length;i++)
			{
		
				var node = rates[i];
				var servicecode = node.getElementsByTagName("Service")[0].getElementsByTagName("Code")[0].firstChild.nodeValue;
				var servicename = getUPSSvcName(servicecode);
				var totalCurrency = node.getElementsByTagName("TotalCharges")[0].getElementsByTagName("CurrencyCode")[0].firstChild.nodeValue;
				var totalCharges = node.getElementsByTagName("TotalCharges")[0].getElementsByTagName("MonetaryValue")[0].firstChild.nodeValue;
				
				//addElementToList(list, totalCharges, servicename+" " + totalCurrency + " "+totalCharges);
				addElementToRadio(list, totalCharges, servicename+" " + totalCurrency + " "+totalCharges);
			}
		}
		fn_ecomm_cal_shipping_close();
	}
//	
	function setShipCombo(request,ship_method)
	{
		var list = document.getElementById('serviceList');
		clearList(list);
		addElementToList(list, "", "-- Select " + ship_method + " Rates --");
		if(ship_method=='UPS')setShipComboUPS(request,list);
		else if(Ship_method='FedEx')setShipComboFedEx(request,list);
	}
	
	function setShipComboFedEx(request,list)
	{
		var reply = request.responseXML.getElementsByTagName("FDXRateAvailableServicesReply");
		
		if(reply.length >0)
		{
			for(var j=0;j<reply.length;j++)
			{
				var reply_node = reply[j];
				var rates = reply_node.getElementsByTagName("Entry");//request.responseXML.getElementsByTagName("Entry");
				if(rates.length > 0)
				{
					for(var i=0;i<rates.length;i++)
					{
						var node = rates[i];
						var servicecode = node.getElementsByTagName("Service")[0].firstChild.nodeValue;
						var servicename = servicecode;//getUPSSvcName(servicecode);
						/*
						*FDXG(GroundÀÇ °æ¿ì ÅÂ±×¿¡ totalCurrency¸¦ Æ÷ÇÔÇÏ°í ÀÖÁö ¾ÊÀ½.
						*/
						var totalCurrency = "USD"; //node.getElementsByTagName("EstimatedCharges")[0].getElementsByTagName("CurrencyCode")[0].firstChild.nodeValue;
						var totalCharges = node.getElementsByTagName("EstimatedCharges")[0].getElementsByTagName("DiscountedCharges")[0].getElementsByTagName("NetCharge")[0].firstChild.nodeValue;
						
						addElementToList(list, totalCharges, servicename+" "+totalCurrency+" "+totalCharges);
					}
				}	
			}
		}
		fn_ecomm_cal_shipping_close();
	}
	
	function setShipComboUPS(request,list)
	{
		var rates = request.responseXML.getElementsByTagName("RatedShipment");
		
		if(rates.length > 0)
		{
			for(var i=0;i<rates.length;i++)
			{
		
				var node = rates[i];
				var servicecode = node.getElementsByTagName("Service")[0].getElementsByTagName("Code")[0].firstChild.nodeValue;
				var servicename = getUPSSvcName(servicecode);
				var totalCurrency = node.getElementsByTagName("TotalCharges")[0].getElementsByTagName("CurrencyCode")[0].firstChild.nodeValue;
				var totalCharges = node.getElementsByTagName("TotalCharges")[0].getElementsByTagName("MonetaryValue")[0].firstChild.nodeValue;
				
				addElementToList(list, totalCharges, servicename+" " + totalCurrency + " "+totalCharges);
			}
		}
		fn_ecomm_cal_shipping_close();
	}
	
	function getFedExSvcName(code)
	{
		var svcName = "";
		switch(code)
		{
		
		
		}
		return svcName;
	}
	function getUPSSvcName(code)
	{
		var svcName="";
		switch(code)
		{
			case "01":
				svcName="UPS Next Day Air";
			break;
			case "02":
				svcName="UPS Second Day Air";
			break;
			case "03":
				svcName="UPS Ground";
			break;
			case "07":
				svcName="UPS Worldwide Express";
			break;
			case "08":
				svcName="UPS Worldwide Expedited";
			break;
			case "11":
				svcName="UPS Standard";
			break;
			case "12":
				svcName="UPS Three-Day Select";
			break;
			case "13":
				svcName="UPS Next Day Air Saver";
			break;
			case "14":
				svcName="UPS Next Day Air Early A.M.";
			break;
			case "54":
				svcName="UPS Worldwide Express Plus";
			break;
			case "59":
				svcName="UPS Second Day Air A.M.";
			break;
			case "65":
				svcName="UPS Saver";
			break;
			default:
				return;
			break;
		}
		return svcName;
	}
	function clearList(list)
	{
		while(list.length>0)list.remove(0);
	}
	function addElementToList(list,value,label)
	{
		var option = document.createElement("option");
		option.value = value;
		var labelNode = document.createTextNode(label);
		option.appendChild(labelNode);
		list.appendChild(option);
	}
	function addElementToRadio(list,value,label)
	{
		//±¸ºÐÀÚ¿¡ À¯ÀÇ
		var rEle = "<input type='radio' name='rListEle' value=\""+value+"^"+label+"\" onClick='javascript:fn_ecomm_cal_radio(this)'>"+label;
		var tag = list.innerHTML;
		tag = tag + "<BR>" + rEle;
		list.innerHTML = tag;
	}
/**/
	function fn_ecomm_cal_select(obj)
	{
		if(!obj)return;
		var shipCost = obj.value;
		var shipMethod = obj.options[obj.selectedIndex].text;
		fn_ecomm_cal_total(shipCost,shipMethod);
	}
	function fn_ecomm_cal_radio(obj)
	{
		if(!obj)return;
		var val = obj.value;
		var token   = val.split(/\^/g);
		if(token == null)return;
		var shipCost = token[0];
		var shipMethod = token[1];
		//alert(shipMethod + ":" + shipCost);
		var pShipCostDisp = document.getElementById('pShipCostDisp');
		pShipCostDisp.value = shipCost;
		fn_ecomm_cal_total(shipCost,shipMethod);
	}
	function fn_ecomm_cal_reset()
	{
		var f = document.getElementById('fShipping');
		if(!f)return;
		f.pShipCost.value	= "";
		f.pShipMethod.value	= "";
		f.pTotal.value		= "";
		f.pTax.value		= "";
	}
	/*
	* fn_ecomm_cal_select¸¦ ÅëÇØ¼­¸¸ Á¢±Ù ÇØ¾ß ÇÔ.
	*/
	function fn_ecomm_cal_total(shipCost,shipMethod)//obj
	{
		
		var f = document.getElementById('fShipping');
		if(!f)return;
		/*if(!obj.value)
		{
			fn_ecomm_cal_reset();
			return;		
		}*/
	
		var subTotal	= f.pSubTotal.value;
		var tax			= f.pTaxReal.value;
		var shipCost	= shipCost; //obj.value;
		var shipMethod	= shipMethod;//obj.options[obj.selectedIndex].text;
		
		var total = parseFloat(subTotal)+parseFloat(tax)+parseFloat(shipCost);
		var outTotal = new Number(total);
		
		total		= String(outTotal.toFixed(2));
		total		= fn_cal_comma(total);

		shipCost	= String(shipCost);
		shipCost	= fn_cal_comma(shipCost);
		
		f.pShipCost.value	= shipCost;
		f.pShipMethod.value = shipMethod;
		
		f.pTotal.value		= total;
	}
//¼ýÀÚ ÀÚ¸´¼ö¸¦ °è»êÇÏ¿© ','¸¦ Âï¾î ÁÖ´Â ÇÔ¼ö
	function fn_cal_comma(num)
	{
		pos = Number(num.indexOf('.'));
		//alert(pos);
		headStr = num.substring(0,pos);
		tailStr = num.substring(pos);

		num = headStr+"";
		point = num.length%3
		len = num.length;
		//alert(num);

		str = num.substring(0,point);
		while( point < len){
			if( str != "" ) str += ",";
			str += num.substring( point , point+3);
			point +=3;
		}
		
		str += tailStr;
		return str;		
	}

	function fn_ecomm_order_complete(ctrlObj)//btnObj °¡ ¾Æ´Ñ Æû¿¡ Æ÷ÇÔµÈ ´Ù¸¥ ÄÜÆ®·Ñ¿¡ ÀÇÇØ È£ÃâµÉ ¼öµµ ÀÖÀ½.
	{
		var f = ctrlObj.form;

		if(!f.chkAgree.checked)
		{
			alert("Please agree to 'TERMS AND CONDITIONS OF USE'");
			f.chkAgree.focus();
			return;
		}
		if(f.fPaid.value != 1)	//2008.06.07 By Sam,Kim
		{
			alert("PAYMENT_PROCESS_IS_NOT_COMPLETED");
			return;
		}
		fn_ajax_request_body(f);
	}
/*
 *	Payment Method Script
 *	2008.06.08 
 *	Author : Sam,Kim
 */
 	function fn_change_payment_method(selObj)
 	{
 		//alert(selObj.value);
 		if(fn_check_payment())
 		{
 			alert('You has already paid');
 			return;
 		}
 		var div_creditcard = document.getElementById('div_creditcard');
 		div_creditcard.style.display = "none";
 		//
 		objDiv = document.getElementById('div_'+selObj.value);
 		if(objDiv != null)objDiv.style.display = "block";
 		
 		switch(selObj.value)
 		{
 			case "creditcard":
				var cF = document.getElementById('creditcardF');
				cF.submit();
 			break;
 			case "paypal":
 				alert("Paypal is currently not available.");
 			break;
/* 			case "billmelater":
	 			alert("'Bill Me Later' is currently not available.");
 			break;*/
 		}	
 		
 		return;
 	}
/**/
	function fn_check_agreement(chkObj)
	{
		if(chkObj == null)return;
		var cf = document.getElementById('commitF');
		var obj = cf.pPaymentMethod;
		
		if(chkObj.checked == false)
		{
			if(confirm("If \"Terms and Conditions of Use\" unchecked,\n\rpayment method will be disabled.\n\r\n\rAre you sure you want to proceed?"))
			{
		 		var div_creditcard = document.getElementById('div_creditcard');
		 		var div_chkArgmMsg = document.getElementById('divCheckAgreementMsg');
		 		div_creditcard.style.display = "none";
		 		div_chkArgmMsg.style.display = "block";
				
				for(i=0;i<obj.length;i++)
				{
					obj[i].checked	= false;
					obj[i].disabled = true;
				}
			}
			else
				chkObj.checked = true;			
		}
		else
		{
			for(i=0;i<obj.length;i++)
				obj[i].disabled = false;
			
			var div_chkArgmMsg = document.getElementById('divCheckAgreementMsg');
			div_chkArgmMsg.style.display = "none";		
		}
	}
 /*
  *
  */
	function fn_ecomm_myorder(ord_idx,obj)
	{
		
		var f = document.getElementById('fpaging');
		f.action = '/pages/ecommerce/cart/viewMyOrderAction.php3';
		
		//var f = fn_create_form('fn_ecomm_myorder_form','post','/pages/ecommerce/cart/viewMyOrderAction.php3');
		if(ord_idx>0)f.action = f.action + "?ord_idx=" +ord_idx;
		fn_ajax_request_body(f);
	}
	function fn_myorder(obj)
	{
		location.href='/pages/ecommerce/cart/viewMyOrderAction.php3';	
	}
