function chkType(type, num) {
	if (type.value != 'Z')
		$("button" + num ).disabled = false;
	else
		$("button" + num ).disabled = true;
}

function initSpecial() {
	listSpecial();
}

function view() {
}

function addSpecial(gcode, num) {
	var type = DWRUtil.getValue("specialType" +  num); // 등록타입
	var sort = DWRUtil.getValue("sort" +  num);		   // 정렬순서
	var specialVO = {special_seq:null, special_type:type, gcode:gcode, sort_seq:sort}
	Goods.saveSpecial(specialVO, {
		callback:function(result) {
			DWRUtil.removeAllOptions("specialType" + num);
			DWRUtil.addOptions("specialType" + num, 
				 {Z:'::::: 선 택 :::::',
				  A:'이달의 추천상품',
				  B:'굿뜨래 기획 상품',
				  C:'판매 인기 상품',
				  D:'굿뜨래 신상품'});
			$("button" + num ).disabled = true;
			opener.location.reload();
			listSpecial();
		}, 	
		errorHandler:function(message) { alert("it broke" + message); }, 
       	warningHandler:function(message) { alert("it broke" + message); }
		
	});	
}

function deleteSpecial() {
	var seq = this.specialId;
	Goods.deleteSpecial(seq, listSpecial);
}

function listSpecial() {
	DWRUtil.removeAllRows("specials");
	Goods.getAllSpecialList(
		function(specialList) {
			var i = 1;
			var cellFuncs = [
				function(specialList) { return i++; },
				function(specialList) {
					var type = "";
					if (specialList.special_type == "A") type = "이달의 추천상품";
					else if (specialList.special_type == "B") type = "굿뜨래 기획상품";
					else if (specialList.special_type == "C") type = "판매 인기상품";
					else type = "굿뜨래 신상품";
					return type; 
				},
				function(specialList) { return specialList.gcode; },
				function(specialList) { return specialList.gname; },
				function(specialList) { return specialList.sort_seq; },
				function(specialList) { 
					var btn2 = document.createElement("<a href='#' style='cursor:hand'>삭제</a>");
					btn2.innerHTML = "삭제";
					btn2.specialId = specialList.special_seq;
					btn2.onclick = deleteSpecial;
					return btn2;
				}				
			];
			DWRUtil.addRows("specials", specialList, cellFuncs, {escapeHtlm:true });
			opener.location.reload();
		}
	);
}

function listSpecialType(url, type) {
	$("specialListBox").innerHTML = "";
	var rolling = new Rolling($("specialListBox"),780,200,0,1,3,1000); 
	Goods.getAllSpecialListType(type, {
		callback:function(specialList) {
			rolling.box.style.border = ""; 
			var listTag = "";
			for (var i = 0; i < specialList.length; i++) {
				listTag += "<div>";
				listTag += 		"<ul class='goods'>";
				listTag += 			"<li>";
				listTag +=				"<dl>";
				listTag +=					"<dd>";
				listTag += 						"<a href='"+ url + "?gcode=" + specialList[i].gcode + "'>";
				listTag += 							"<img src='/goodtrae" + specialList[i].file_full_path +"' width='60px' height='60px' class='photo' /></a>";
				listTag += 					"</dd>";
				listTag +=					"<dd>" + putComma(specialList[i].price) + " 원</dd>";
				listTag +=				"</dl>";
				listTag +=			"</li>";
				listTag +=		"</ul>";
				listTag += "</div>";
			}

			rolling.box.innerHTML = listTag;
			rolling.Init();
			rolling.Run();
		}
	});
}

function listGoodtraeRoom(url, type) {
	var rollingS = new Rolling($("goodtraeRoom"),780,210,0,1,3,1000); 
	Goods.getAllSpecialListType(type, {
		callback:function(specialList) {
			
			rollingS.box.style.border = ""; 
			var listTag = "";
			for (var i = 0; i < specialList.length; i++) {
				listTag += "<div>";
				listTag += 		"<ul class='goods'>";				
				listTag += 			"<li>";
				listTag += 				"<a href='"+ url + "?gcode=" + specialList[i].gcode + "'>";
				listTag += 				"<img src='/goodtrae" + specialList[i].file_full_path +"' width='100px' height='100px' class='photo' /></a>";
				listTag +=				"<dl>";
				listTag +=					"<dt>" + specialList[i].gname.substring(0,8) + "</dt>";
				listTag +=					"<dd>" + specialList[i].compose + "</dd>";
				listTag += 					"<dd class='sellPrice'>" + putComma(specialList[i].price) + " 원</dd>";
				listTag +=				"</dl>";
				listTag += 			"</li>"
				listTag += 		"</ul>";
				listTag +="</div>";
			}

			rollingS.box.innerHTML = listTag;
			rollingS.Init(); 
			rollingS.Run(); 
		}
		
	});
}

function listHighRecomArea(url, type) {
	var highRecom = new Rolling($("highRecom_Area"),700,150,2,1,2,1000); 
	Goods.getAllSpecialListType(type, {
		callback:function(specialList) {
			
			highRecom.box.style.border = ""; 
			var listTag = "";
			var count = 0;
			for (var i = 0; i < specialList.length; i++) {
				if(count % 3 == 0) listTag += "<ul class='goods'>";
				listTag +=	"<li>";
				listTag += 		"<a href='"+ url + "?gcode=" + specialList[i].gcode + "'>";
				listTag += 		"<img src='/goodtrae" + specialList[i].file_full_path +"' width='80px' height='80px' class='photo' /></a>";
				listTag +=		"<a href='"+ url + "?gcode=" + specialList[i].gcode + "'><dl>";
				listTag +=			"<dt>" + specialList[i].gname.substring(0,8) + "..</dt>";
				listTag += 			"<dd class='sellPrice'>" + putComma(specialList[i].price) + " 원</dd>";
				listTag +=		"</dl></a>";
				listTag +=	"</li>";
				count = count + 1;
				if (count % 3 == 0)	listTag +="</ul>";
			}
			highRecom.box.innerHTML = listTag;
			highRecom.Init(); 
			highRecom.Run(); 
		}
		
	});
}



