//옵션 추가정보 열 추가
var fixed_ea = 5;
var rowcount_opt = 0;
function append_opt() {
	if(rowcount_opt < fixed_ea){
		var tbl = document.getElementById("product_opt").getElementsByTagName("TBODY")[0];  
		var html1 = "<input type='hidden' id='opt_hidden_value_"+rowcount_opt+"' name='opt_hidden_value_"+rowcount_opt+"'><input type='text' id='opt_subject_"+rowcount_opt+"' name='opt_subject_"+rowcount_opt+"' style='width:100%' maxlength='250'>";  
		var html2 = "<select id='opt_contents_"+rowcount_opt+"' name='opt_contents_"+rowcount_opt+"' style='width:100%'></select>";   
		var html3 = "<input type='button' value='추가' style='width:40;color:blue' onclick='LayerShowProductOpt("+rowcount_opt+")'>  <input type='button' value='수정' style='width:40;color:green' onclick='getProductOpt("+rowcount_opt+", this.form.opt_contents_"+rowcount_opt+".selectedIndex, this.form.opt_contents_"+rowcount_opt+".value)'> <input type='button' value='삭제' style='width:40;color:red' onclick='delProductOpt("+rowcount_opt+", this.form.opt_contents_"+rowcount_opt+".selectedIndex)'>";   
		var row = document.createElement("tr"); 
		var col1 = document.createElement("td");   
		var col2 = document.createElement("td"); 
		var col3 = document.createElement("td"); 
		row.appendChild(col1);  
		row.appendChild(col2);
		row.appendChild(col3);
		col1.innerHTML = html1;  
		col2.innerHTML = html2;  
		col3.innerHTML = html3;  
		tbl.appendChild(row);  
		rowcount_opt++;
	}else{
		alert("옵션은 최대 "+fixed_ea+" 개까지 추가할 수 있습니다.");
	}
}

function remove_opt() {  
	if(rowcount_opt > 0){
		var tbl = document.getElementById("product_opt").getElementsByTagName("TBODY")[0];  
		if (tbl.hasChildNodes()) {      
			tbl.removeChild(tbl.lastChild);     // 마지막 로우   //tbl.removeChild(tbl.firstChild);  // 첫번째 로우  
		}
		rowcount_opt--;
	}
}
//옵션 추가정보 열 추가


//레이어 닫기
function LayerHideProductOpt() {
	$('layerProductOpt').hide();
}


// 세부 항목추가 레이어 보이기 =========================
function LayerShowProductOpt(o_no){
	layerPositionSet('layerProductOpt');
	$('layerProductOpt').innerHTML = "<table width='130'><tr><form name='optInsertFrm'><td>항목명</td><td><input type='text' name='newOpt' size='10'></td></tr><tr><td>추가금</td><td><input type='text' name='newOptPrice' size='10'></td></tr><tr><td colspan='2' align='center'><input type='button' value='입력' onclick='addProductOpt("+o_no+", this.form.newOpt.value, this.form.newOptPrice.value);'>&nbsp;&nbsp;&nbsp;<input type='button' value='취소' onclick='LayerHideProductOpt();'></td></tr></form></table>";
}

// 세부 항목수정 레이어 보이기 =========================
function LayerShowProductOptEdit(o_no, o_name, o_price, idx){
	if(idx=="-1"){
		alert("수정할 항목을 선택하세요.");
	}else{
		layerPositionSet('layerProductOpt');
		$('layerProductOpt').innerHTML = "<table width='130'><tr><form name='optInsertFrm'><td>항목명</td><td><input type='text' name='newOpt' size='10'  value="+o_name+"></td></tr><tr><td>추가금</td><td><input type='text' name='newOptPrice' size='10' value="+o_price+"></td></tr><tr><td colspan='2' align='center'><input type='button' value='수정' onclick='editProductOpt("+o_no+", this.form.newOpt.value, this.form.newOptPrice.value, "+idx+");'>&nbsp;&nbsp;&nbsp;<input type='button' value='취소' onclick='LayerHideProductOpt();'></td></tr></form></table>";
	}
}

//옵션 항목추가
function addProductOpt(o_no, o_name, o_price){
	var div_id = "opt_contents_" + o_no;
	$(div_id).options[$(div_id).length] = new Option(o_name+"|"+o_price,o_name+"|"+o_price);
	LayerHideProductOpt();
}

//옵션 항목수정
function editProductOpt(o_no, o_name, o_price, idx){
	var div_id = "opt_contents_" + o_no;
	$(div_id).options[idx] = new Option(o_name+"|"+o_price,o_name+"|"+o_price);
	LayerHideProductOpt();
}

//옵션 항목정보 가져오기
function getProductOpt(o_no, idx, val){
	var optArray = new Array();
	optArray = val.split("|");
	LayerShowProductOptEdit(o_no, optArray[0], optArray[1], idx);
}

//옵션 항목삭제
function delProductOpt(o_no, idx){
	var div_id = "opt_contents_" + o_no;
	if(idx=="-1"){
//		alert("삭제할 항목을 선택하세요.");
		alert("Please choose deletion item.");
	}else{
		$(div_id).options[idx] = null;
	}

}



// 상품분류 추가 레이어 보이기 =========================

//레이어 닫기
function LayerHideGoodCat() {
	$('layerGoodCat').hide();
}

function LayerShowGoodCat(){
	layerPositionSet('layerGoodCat');
	new Ajax.Request('/module/shop/ajax_ext_cat.php',
	{
		method:'get',
		//parameters: {idx: idx, opt_1: opt_1},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
			//var response = transport.responseText || "응답된 내역이 없습니다."; 
			var response = transport.responseText || "There is no response"; 
			//alert(transport.responseText);
			$('layerGoodCat').innerHTML = response;
		},
		
		onFailure: function(){ 
			//alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
			alert('AJAX response is failed.') 
		}   
	});
}

//상품분류 항목추가
function addGoodCat(cat_no){
	if(cat_no !=""){
		var div_id = "ext_cat";
		$(div_id).options[$(div_id).length] = new Option(arrayAllCategory[cat_no], cat_no);
		LayerHideGoodCat();
	}else{
		//alert("분류를 선택하세요.");
		alert("Please choose category.");
		$("t_ext_cat1").focus();
	}
}

//상품분류 항목삭제
function delGoodCat(idx){
	var div_id = "ext_cat";
	if(idx=="-1"){
		//alert("삭제할 항목을 선택하세요.");
		alert("Please choose deletion item.");
	}else{
		$(div_id).options[idx] = null;
	}
}



// 관련상품 추가 레이어 보이기 =========================

//레이어 닫기 - iframe 에서 부르기 때문에 parent
function LayerHideRelGood() {
	parent.$('layerRelGood').hide();
}

function LayerShowRelGood(){
	layerPositionSet('layerRelGood');
	$('iframeRelGood').src = "/backoffice/module/shop/rel_good.php";
}

//상품분류 항목삭제
function delRelGood(idx){
	var div_id = "rel_good";
	if(idx=="-1"){
		//alert("삭제할 항목을 선택하세요.");
		alert("Please choose deletion item.");
	}else{
		$(div_id).options[idx] = null;
	}
}

//체크한 아이템 주문 - iframe 에서 부르기 때문에 parent
function addRelGoodChecked(f){
	//1개이상 체크했는지 검사
	var obj = document.getElementsByName('items[]'); 
	var objlength = obj.length;
	var objchecked = 0;
	var objstring = new Array();
	var arr = new Array();
	//패런트의 관련상품이 현재 몇개있나
	var j = parent.$("rel_good").length;
	for(i=0; i<objlength; i++){
		if(obj[i].checked==true){
			objstring[objchecked] = obj[i].value;
			objchecked++;
		}
	}

	if(objchecked < 1){
		//alert("선택하신 상품이 없습니다.");
		alert("There is no item");
		return;
	}

	for(i=0;i<objstring.length;i++){
		arr = objstring[i].split("|");
		parent.$("rel_good").options[i+j] = new Option(arr[1],arr[0]);
	}

	LayerHideRelGood();
}
// 관련상품 추가 레이어 보이기 =========================


//재고관리 설정
function checkStockManage(st){
	if(st=="1"){
		$('layerStock').hide();
		$('layerOption2').hide();
	}else if(st=="2"){
		$('layerStock').show();
		$('layerOption2').hide();
	}else if(st=="3"){
		$('layerStock').hide();
		$('layerOption2').show();
	}
}

//이미지 타입 설정
function checkImageType(st){
	if(st=="2"){
		$('layerImage1').hide();
		$('layerImage2').show();
	}else{
		$('layerImage1').show();
		$('layerImage2').hide();
	}
}

//상품 입력폼 체크
function goodCheckForm(frm){
	if (frm.cat_no.value==""){
//		alert("상품분류를 선택해 주십시요.");
		alert("Please choose category");
		frm.cat.focus();
		return false;
	}
	if (frm.g_name.value==""){
//		alert("상품명을 입력해 주십시요.");
		alert("Please enter product name");
		frm.g_name.focus();
		return false;
	}
	
	//상품 옵션정보 데이터 조합
	$("opt_hidden_count").value=0;
	for(i=0;i<fixed_ea;i++){
		try{
			var opt_subject_id = "opt_subject_" + i;
			var opt_contents_id = "opt_contents_" + i;
			var opt_value_id = "opt_hidden_value_" + i;
			for(j=0;j<$(opt_contents_id).length;j++){
				$(opt_value_id).value += $(opt_contents_id)[j].value;
				//마지막이 아니면 구분자 추가
				if(j+1 != $(opt_contents_id).length){
					$(opt_value_id).value += "|:|";
				}
			}
			$("opt_hidden_count").value++;
		}catch(e){}
	}


	//추가카테고리 조합
	try{
		for(j=0;j<$("ext_cat").length;j++){
			$("ext_cat_hidden").value += $("ext_cat")[j].value;
			//마지막이 아니면 구분자 추가
			if(j+1 != $("ext_cat").length){
				$("ext_cat_hidden").value += "|:|";
			}
		}
	}catch(e){}


	//관련상품 조합 : 상품의 idx 만 저장할 것이기 때문에 구분자를 | 하나만 함
	try{
		for(j=0;j<$("rel_good").length;j++){
			$("rel_good_hidden").value += $("rel_good")[j].value;
			//마지막이 아니면 구분자 추가
			if(j+1 != $("rel_good").length){
				$("rel_good_hidden").value += "|";
			}
		}
	}catch(e){}
}

//이미지 상세보기 레이어
function LayerShowImage(img){
	layerPositionSet('layerImageShow');
	$('layerImageShow').innerHTML = "<a href='javascript:;' onclick='LayerHideImage();'><img src='/uploaded/shop_good/"+img+"' border=0></a>";
}

//레이어 닫기
function LayerHideImage() {
	$('layerImageShow').hide();
}

//연계재고 옵션 가져오기
function getRelOpt(idx, opt_1){
	if(idx != "" || opt_1){
		new Ajax.Request('/module/shop/ajax_get_rel_opt.php',
		{
			method:'get',
			parameters: {idx: idx, opt_1: opt_1},
			asynchronous: this.asynchronous,
			encoding: 'utf-8',
			contentType: 'application/x-www-form-urlencoded',

			onSuccess: function(transport){
				//var response = transport.responseText || "응답된 내역이 없습니다."; 
				var response = transport.responseText || "There is no response"; 
				//alert(transport.responseText);
				setRelOpt(response);
			},
			
			onFailure: function(){ 
				//alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
				alert('AJAX response is failed.') 
			}   
		});
	}

}

function setRelOpt(txt){
	//alert(txt);
	var opt = new Array();
	var arr = new Array();
	var stk;
	var prc;
	opt = txt.split("||");
	//초기화	
	for(i=1; i< $("opt_rel_contents_1").length; i++){
		$("opt_rel_contents_1").options[i] = null;
	}
	for(i=0; i<opt.length; i++){
		arr = opt[i].split("**");

		if(arr[1] > "0"){
			prc = " (+"+addComma(arr[1])+")";
		}else{
			prc = "";
		}

		//재고가 없을경우 값을 -1 로 설정
		if(arr[2]=="0"){
			$("opt_rel_contents_1").options[i+1] = new Option(arr[0]+" (sold out)","-1");
		}else{
			$("opt_rel_contents_1").options[i+1] = new Option(arr[0]+prc,arr[0]+"|"+arr[1]);
		}
	}
}

//옵션가격 설정
function setOptPrice(){
	var price;
	var point;
	var total_price;
	var opt_price;	
	var cnt;
	price = parseInt($("basicPrice").value);
	point = parseInt($("basicPoint").value);
	cnt = parseInt($("qty").value);
	if(cnt > 0){
		cnt = cnt;
	}else{
		cnt = 0;
	}
 
	//옵션가격 초기화
	var option_price1, option_price2, option_price3, option_price4, option_price5, option_price_rel1, option_price_rel2;
	option_price1 = 0;
	option_price2 = 0;
	option_price3 = 0;
	option_price4 = 0;
	option_price5 = 0;
	option_price_rel1 = 0;
	option_price_rel2 = 0;
	opt_price = option_price1 + option_price2 + option_price3 + option_price4 + option_price5 + option_price_rel1 + option_price_rel2;

	try{
		option_price1 = $("opt_contents_0").value.split("|")[1];
		if(option_price1 > 0){
			opt_price = opt_price + parseInt(option_price1);
		}
	}catch(e){}
	try{
		option_price2 = $("opt_contents_1").value.split("|")[1];
		if(option_price2 > 0){
			opt_price = opt_price + parseInt(option_price2);
		}
	}catch(e){}
	try{
		option_price3 = $("opt_contents_2").value.split("|")[1];
		if(option_price3 > 0){
			opt_price = opt_price + parseInt(option_price3);
		}
	}catch(e){}
	try{
		option_price4 = $("opt_contents_3").value.split("|")[1];
		if(option_price4 > 0){
			opt_price = opt_price + parseInt(option_price4);
		}
	}catch(e){}
	try{
		option_price5 = $("opt_contents_4").value.split("|")[1];
		if(option_price5 > 0){
			opt_price = opt_price + parseInt(option_price5);
		}
	}catch(e){}
 	try{
		option_price_rel1 = $("opt_rel_contents_1").value.split("|")[1];
		if(option_price_rel1 > 0){
			opt_price = opt_price + parseInt(option_price_rel1);
		}
	}catch(e){}
	try{
		option_price_rel2 = $("opt_rel_contents_2").value.split("|")[1];
		if(option_price_rel2 > 0){
			opt_price = opt_price + parseInt(option_price_rel2);
		}
	}catch(e){}
	total_price = (price+opt_price)*cnt;

	try{
	$("divPrice").innerHTML= addComma(total_price);
	}catch(e){}
	try{
	$("divPoint").innerHTML= addComma(point*cnt);
	}catch(e){}
}

//장바구니에 담기
function addCart(g_idx,qty){
	var opt_1, opt_2, opt_3, opt_4, opt_5, opt_rel_1, opt_rel_2;

	if(qty < 1){
		//alert("구매수량은 1개 이상입니다.");
		//return;
		qty=1;
	}

	for(i=0;i<fixed_ea;i++){
		try{
			var opt_name_id = "opt_name_" + i;
			var opt_contents_id = "opt_contents_" + i;

			if($F(opt_contents_id)==""){
				alert($F(opt_name_id) + "(을)를 선택하세요.");
				$(opt_contents_id).focus();
				return;
			}
			if(i==0){opt_1 = $F(opt_contents_id);}
			if(i==1){opt_2 = $F(opt_contents_id);}
			if(i==2){opt_3 = $F(opt_contents_id);}
			if(i==3){opt_4 = $F(opt_contents_id);}
			if(i==4){opt_5 = $F(opt_contents_id);}

		}catch(e){}
	}

	//연계옵션 체크
	for(i=0;i<2;i++){
		try{
			var opt_name_id = "opt_rel_name_" + i;
			var opt_contents_id = "opt_rel_contents_" + i;

			if($F(opt_contents_id)==""){
				alert($F(opt_name_id) + "(을)를 선택하세요.");
				$(opt_contents_id).focus();
				return;
			}
			if(i==0){opt_rel_1 = $F(opt_contents_id);}
			if(i==1){opt_rel_2 = $F(opt_contents_id);}

		}catch(e){}
	}

	new Ajax.Request('/module/shop/ajax_cart_process.php',
	{
		method:'post',
		parameters: {evnMode: "add", g_idx: g_idx, qty: qty, opt_1: opt_1, opt_2: opt_2, opt_3: opt_3, opt_4: opt_4, opt_5: opt_5, opt_rel_1: opt_rel_1, opt_rel_2: opt_rel_2},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
			var response = transport.responseText || "응답된 내역이 없습니다."; 
			var cfm = false;
//			alert(response);
			if(response=="true"){
				cfm = confirm("장바구니에 담았습니다.\n\n지금 확인 하시겠습니까?");
				if(cfm==true){
					document.location.href="/shop.php?goPage=Cart";
				}
			}else{
				alert("장바구니에 담기 실패!");
			}
		},
		
		onFailure: function(){ 
//			alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
			alert('AJAX response is failed.') 
		}   
	});

}

//바로구매
function buyDirect(g_idx,qty){
	var opt_1, opt_2, opt_3, opt_4, opt_5, opt_rel_1, opt_rel_2;

	if(qty < 1){
		//alert("구매수량은 1개 이상입니다.");
		//return;
		qty = 1;
	}

	for(i=0;i<fixed_ea;i++){
		try{
			var opt_name_id = "opt_name_" + i;
			var opt_contents_id = "opt_contents_" + i;

			if($F(opt_contents_id)==""){
				//alert($F(opt_name_id) + "(을)를 선택하세요.");
				alert("Please choose " + $F(opt_name_id));
				$(opt_contents_id).focus();
				return;
			}
			if($F(opt_contents_id)=="-1"){
				//alert("품절된 " + $F(opt_name_id) + "입니다.");
				alert($F(opt_name_id) + " is sold out");
				$(opt_contents_id).focus();
				return;
			}
			if(i==0){opt_1 = $F(opt_contents_id);}
			if(i==1){opt_2 = $F(opt_contents_id);}
			if(i==2){opt_3 = $F(opt_contents_id);}
			if(i==3){opt_4 = $F(opt_contents_id);}
			if(i==4){opt_5 = $F(opt_contents_id);}

		}catch(e){}
	}

	//연계옵션 체크
	for(i=0;i<2;i++){
		try{
			var opt_name_id = "opt_rel_name_" + i;
			var opt_contents_id = "opt_rel_contents_" + i;

			if($F(opt_contents_id)==""){
				//alert($F(opt_name_id) + "(을)를 선택하세요.");
				alert("Please choose " + $F(opt_name_id));
				$(opt_contents_id).focus();
				return;
			}
			if(i==0){opt_rel_1 = $F(opt_contents_id);}
			if(i==1){opt_rel_2 = $F(opt_contents_id);}

		}catch(e){}
	}

	new Ajax.Request('/module/shop/ajax_cart_process.php',
	{
		method:'post',
		parameters: {evnMode: "direct", g_idx: g_idx, qty: qty, opt_1: opt_1, opt_2: opt_2, opt_3: opt_3, opt_4: opt_4, opt_5: opt_5, opt_rel_1: opt_rel_1, opt_rel_2: opt_rel_2},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
//			var response = transport.responseText || "응답된 내역이 없습니다."; 
			var response = transport.responseText || "There is no response"; 
			if(response=="true"){
				document.location.href="/shop.php?goPage=Order";
			}else{
				//alert("바로구매 진행중 실패 하였습니다.");
				alert("There happen error during order");
			}
		},
		
		onFailure: function(){ 
//			alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
			alert('AJAX response is failed.') 
		}   
	});

}


//위시리스트에 담기
function addWish(g_idx, rt_url){
	new Ajax.Request('/module/shop/ajax_wish_process.php',
	{
		method:'post',
		parameters: {evnMode: "add", g_idx: g_idx},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
			//var response = transport.responseText || "응답된 내역이 없습니다."; 
			var response = transport.responseText || "There is no response"; 
			var cfm = false;
			if(response=="true"){
				cfm = confirm("위시리스트에 담았습니다.\n\n지금 확인 하시겠습니까?");
				if(cfm==true){
					document.location.href="/shop.php?goPage=WishList";
				}
			}else if(response=="nologin"){
				cfm = confirm("회원전용입니다.\n\n지금 로그인 하시겠습니까?");
				if(cfm==true){
					document.location.href="/member.php?goPage=Login&rt_url="+rt_url;
				}
			}else{
				alert("위시리스트에 담기 실패!");
			}
		},
		
		onFailure: function(){ 
//			alert('AJAX 데이터 응답중 오류가 발생하였습니다.')
			alert('AJAX response is failed.') 
		}   
	});

}

//장바구시 수량수정
function updateCart(c_idx,qty){
	if(qty < 1){
		alert("구매수량은 1개 이상입니다.");
		return;
	}

	new Ajax.Request('/module/shop/ajax_cart_process.php',
	{
		method:'post',
		parameters: {evnMode: "update", c_idx: c_idx, qty: qty},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
			//var response = transport.responseText || "응답된 내역이 없습니다."; 
			var response = transport.responseText || "There is no response"; 
			if(response=="true"){
				//alert("주문수량을 수정하였습니다.");
				document.location.reload();
			}else{
				alert("주문수량 수정 실패!");
			}
		},
		
		onFailure: function(){ 
//			alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
			alert('AJAX response is failed.') 
		}   
	});

}

//장바구니에서 아이템 삭제
function deleteCart(c_idx){
	new Ajax.Request('/module/shop/ajax_cart_process.php',
	{
		method:'post',
		parameters: {evnMode: "delete", c_idx: c_idx},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
			//var response = transport.responseText || "응답된 내역이 없습니다."; 
			var response = transport.responseText || "There is no response"; 
			//alert(response);
			if(response=="true"){
				document.location.reload();
			}else{
				alert("장바구니 아이템 삭제 실패!");
			}
		},
		
		onFailure: function(){ 
//			alert('AJAX 데이터 응답중 오류가 발생하였습니다.')
			alert('AJAX response is failed.') 
		}   
	});

}

//위시리스트에서 아이템 삭제
function deleteWish(c_idx){
	new Ajax.Request('/module/shop/ajax_wish_process.php',
	{
		method:'post',
		parameters: {evnMode: "delete", c_idx: c_idx},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
		//	var response = transport.responseText || "응답된 내역이 없습니다."; 
			var response = transport.responseText || "There is no response"; 
			//alert(response);
			if(response=="true"){
				document.location.reload();
			}else{
				alert("위시리스트 아이템 삭제 실패!");
			}
		},
		
		onFailure: function(){ 
//			alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
			alert('AJAX response is failed.') 
		}   
	});

}

//셀렉트 박스 전체체크
function checkboxCheckAll(status){
	var obj = document.getElementsByName('items[]'); 
	var objlength = obj.length;
	for(i=0; i<objlength; i++){
		if(status==1){
			obj[i].checked=true;
		}else{
			obj[i].checked=false;
		}
	}
}

//체크한 아이템 삭제
function deleteCartChecked(f){
	//1개이상 체크했는지 검사
	var obj = document.getElementsByName('items[]'); 
	var objlength = obj.length;
	var objchecked = 0;
	for(i=0; i<objlength; i++){
		if(obj[i].checked==true){
			objchecked++;
		}
	}

	if(objchecked < 1){
		alert("선택하신 상품이 없습니다.");
		return;
	}

	var cfm = false;
	cfm = confirm("선택하신 상품들을 장바구니에서 삭제 하시겠습니까?");
	if(cfm==true){
		f.evnMode.value = "deleteCartChecked";
		f.action = "/module/shop/cart_evn.php";
		f.submit();
	}
}

//체크한 아이템 주문
function orderCartChecked(f){
	//1개이상 체크했는지 검사
	var obj = document.getElementsByName('items[]'); 
	var objlength = obj.length;
	var objchecked = 0;
	for(i=0; i<objlength; i++){
		if(obj[i].checked==true){
			objchecked++;
		}
	}

	if(objchecked < 1){
		//alert("선택하신 상품이 없습니다.");
		alert("There is no item.");
		return;
	}

	f.evnMode.value = "orderCartChecked";
	f.action = "/module/shop/cart_evn.php";
	f.submit();
}

//전체체크후 주문
function orderCartAll(f){
	//전체체크후
	checkboxCheckAll("1");
	//주문
	orderCartChecked(f);
}

//장바구니에서 1개 상품 주문
function orderCartOne(c_idx){
	new Ajax.Request('/module/shop/ajax_cart_process.php',
	{
		method:'post',
		parameters: {evnMode: "orderOne", c_idx: c_idx},
		asynchronous: this.asynchronous,
		encoding: 'utf-8',
		contentType: 'application/x-www-form-urlencoded',

		onSuccess: function(transport){
//			var response = transport.responseText || "응답된 내역이 없습니다."; 
			var response = transport.responseText || "There is no response"; 
			if(response=="true"){
				document.location.href="/shop.php?goPage=Order";
			}else{
				alert("잠시후 다시 시도해 주세요.");
			}
		},
		
		onFailure: function(){ 
//			alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
			alert('AJAX response is failed.') 
		}   
	});

}

//위시리스트 체크한 아이템 삭제
function deleteWishChecked(f){
	//1개이상 체크했는지 검사
	var obj = document.getElementsByName('items[]'); 
	var objlength = obj.length;
	var objchecked = 0;
	for(i=0; i<objlength; i++){
		if(obj[i].checked==true){
			objchecked++;
		}
	}

	if(objchecked < 1){
		alert("선택하신 상품이 없습니다.");
		return;
	}

	var cfm = false;
	cfm = confirm("선택하신 상품들을 위시리스트에서 삭제 하시겠습니까?");
	if(cfm==true){
		f.evnMode.value = "deleteWishChecked";
		f.action = "/module/shop/wish_evn.php";
		f.submit();
	}
}

//위시리스트 체크한 아이템 카트에 담기
function addCartWishChecked(f){
	//1개이상 체크했는지 검사
	var obj = document.getElementsByName('items[]'); 
	var objlength = obj.length;
	var objchecked = 0;
	for(i=0; i<objlength; i++){
		if(obj[i].checked==true){
			objchecked++;
		}
	}

	if(objchecked < 1){
		alert("선택하신 상품이 없습니다.");
		return;
	}

	f.evnMode.value = "addCartWishChecked";
	f.action = "/module/shop/wish_evn.php";
	f.submit();
}


//주문서에서 주문자 정보와 수취인 정보가 같게 설정
function shipInfoAssign(st){
	f = document.frmOrderForm;
	if(st==true){
		f.ship_name.value = f.order_name.value;
		f.ship_zip1.value = f.order_zip1.value;
		f.ship_zip2.value = f.order_zip2.value;
		f.ship_address.value = f.order_address.value;
		f.ship_address_ext.value = f.order_address_ext.value;
		f.ship_phone1.value = f.order_phone1.value;
		f.ship_phone2.value = f.order_phone2.value;
		f.ship_phone3.value = f.order_phone3.value;
		f.ship_mobile1.value = f.order_mobile1.value;
		f.ship_mobile2.value = f.order_mobile2.value;
		f.ship_mobile3.value = f.order_mobile3.value;
	}else{
		f.ship_name.value = "";
		f.ship_zip1.value = "";
		f.ship_zip2.value = "";
		f.ship_address.value = "";
		f.ship_address_ext.value = "";
		f.ship_phone1.value = "";
		f.ship_phone2.value = "";
		f.ship_phone3.value = "";
		f.ship_mobile1.value = "";
		f.ship_mobile2.value = "";
		f.ship_mobile3.value = "";
	}
}


//주문서에서 무통장입금 선택시 결제정보 선택화면 보이기
function check_pay_type(st){
	if(st=="cash"){
		$('tblPayInfo').show();
	}else{
		$('tblPayInfo').hide();
	}
}

//주문서 입력정보 체크
// onsubmit 형태로 호출하지 않고 그냥 호출해야함.
function check_order_form(f, pg){
	if(f.order_company.value==""){
		alert("Please enter your company name.");
		f.order_company.focus();
		return;
	}
	if(f.order_email.value==""){
		alert("Please enter your E-mail address.");
		f.order_email.focus();
		return ;
	}


	if(f.ship_name.value==""){
		alert("Please enter the details of consignee.");
		f.ship_name.focus();
		return ;
	}
	if(f.ship_zip.value==""){
		alert("Please enter your postal code.");
		f.ship_zip.focus();
		return ;
	}
	
	if(f.ship_address.value==""){
		alert("Please enter your address.");
		f.ship_address.focus();
		return ;
	}
	if(f.ship_address_ext.value==""){
		alert("Please enter your address.");
		f.ship_address_ext.focus();
		return ;
	}
	

//	f.target="hiddenFrame";
	f.action="/module/shop/order_evn.php";
	f.submit();
}


//하위 카테고리 html 로 가져오기 - 좌측카테고리
function getSubCatHtml(cat_no){
	if(cat_no){
		new Ajax.Request('/module/category/ajax_get_cat_html.php',
		{
			method:'get',
			parameters: {cat_no: cat_no},
			asynchronous: this.asynchronous,
			encoding: 'utf-8',
			contentType: 'application/x-www-form-urlencoded',

			onSuccess: function(transport){
				var response = transport.responseText || "하위카테고리가 없습니다."; 
				//alert(transport.responseText);
				showSubCatHtml(response);
			},
			
			onFailure: function(){ 
				alert('AJAX 데이터 응답중 오류가 발생하였습니다.') 
			}   
		});
	}else{
		hideSubCatHtml();
	}
}

function showSubCatHtml(str){
	$("divSubCategory").innerHTML = str;
	$("divSubCategory").show();
}

function hideSubCatHtml(){
	$("divSubCategory").innerHTML = "";
	$("divSubCategory").hide();
}

function getCordinatesByEvent(event){
	var cordinates = {
		x:event.pointerX(),
		y:event.pointerY()
	};
	$("divSubCategory").hide();
	$("divSubCategory").style.left = cordinates.x+10;
	$("divSubCategory").style.top = cordinates.y-5;
}
/* 카테고리 관련 */

//적립금 사용
function calUsingPoint(f, val){
	//사용하려는 적립금이 가진 적립금보다 크면 내 적립금으로 강제조정
	if(parseInt(f.using_point.value) > parseInt(f.hiddenMyPoint.value)){
		f.using_point.value = f.hiddenMyPoint.value;
	}
	//0보다 작으면 0
	if(parseInt(f.using_point.value) < 0){
		f.using_point.value = 0;
	}
	//값이 없어도 0
	if(!f.using_point.value){
		f.using_point.value = 0;
	}
	var payPrice = parseInt(f.hiddenPayAmount.value) - parseInt(f.using_point.value);
	$("showPriceTotal").innerHTML =  addComma(payPrice) + "원";
}

//상품이미지 크게보기
function viewImgPop(g_idx,seq){
	obj = window.open("/module/shop/viewImgPop.php?g_idx="+g_idx+"&seq="+seq,"viewImagePop","width=100,height=100,menubars=0, toolbars=0");
}


//상품 상세페이지에서의 리뷰보기
var review_list = '';
function reveiwClick( review) {
    if( review_list != review ) {
	    if( review_list !='' ) {
		    review_list.style.display = 'none';
		}
	    review.style.display = 'block';
		review_list = review;
    } else {
        review.style.display = 'none';
        review_list = '';
    }
}

//샵 카탈로그 다운로드
function shop_catalog_download(idx) {
	document.iframeHidden.location.href='/module/shop/catalog_download.php?idx='+idx;
}

