//val : history ,, val2 : body_number
var call_sub01 = {
	getText: function(val,val2)
	{
		var req = getXMLHTTP();
	
		req.onreadystatechange = function()
		{
			if(req.readyState == 4)
			{
				
				if (req.status == 200)
				{	
					
					handleSub01Response(eval("("+req.responseText+")"),val2);
					
				}
			}					
		}
											//false ·Î ÇÒ °æ¿ì º¸¿©ÁÙ ÆäÀÌÁö¸¦ ¸ðµÎ ·ÎµùÇÑÈÄ ½½¶óÀÌµùµÈ´Ù. ·ÎµùµÇ´Âµ¿¾È ÀÎµðÄÉÀÌÅÍ¸¦ µ¿ÀÛ½ÃÅ°ÀÚ. 
											//false´Â ¿Â·¹µðÃ¼ÀÎÁö ¹Ø¿¡ÀÖ¾î¾ß ÀÛµ¿ÇÔ
		req.open('POST',"/call/call_sub01.asp?ctg="+escape(val),true);
		req.send(null);
	}
};

function handleSub01Response(result,val2)
{
		ctg_m_show(result,val2);	
		CallSetCTG(val2);

};

function ctg_m_show(result,val2)
{
	//Ã¼ÀÎÁöµÉ ¹Ùµð ¼±ÅÃ
	if (val2 == 1)
	{
		BodyTop="body_top01";
		BodyBottom = "body_bottom01";
		detail_ctg = "detail_ctg1";
		in_num=1;
	}
	else
	{
		BodyTop="body_top02";
		BodyBottom = "body_bottom02";
		detail_ctg = "detail_ctg2";
		in_num=2;
	}
	//end

	//ÀÌ¹ÌÁö °æ·Î
	var imagePath = "<img src=/img/sub/"+result.CtgImg + ">";
	var textctg = " &nbsp;<table border=0 height=30 cellpadding=0 cellspacing=0><tr><td class=payment_11 valign=top>| " + result.ctg_hangul + "</td></tr></table>";
	//end

	//select °æ·Î
	var ctgdae = "ctgdae"+in_num;
	var ctgjung = "ctgjung"+in_num;
	var textPath = 
		
		"<table><tr><td><select id='ctgdae"+in_num+"' onchange=javascript:CallCTG(document.getElementById('"+ctgdae+"').value,1,'"+in_num+"');><option></option></select></td>"
		+"<td class=subtit>></td><td><select id='ctgjung"+in_num+"' onchange=javascript:CallCTG(document.getElementById('"+ctgjung+"').value,2,'"+in_num+"');><option></option></select>"
		+"</td><td>></td>"
		+"<td><select id=ctgso"+in_num+"><option></option></select></td><td><img src='/img/sub/btn_ctgchange.gif' style=cursor:hand; onclick=javascript:DirectCTGChange('"+in_num+"');></td></tr></table>";
	//end
	
	//Áß Ä«Å×°í¸® Á¤·Ä 
	var ctgMvalue = "";
	for (i=0;i<result.ctgM.length;i++)
	{
		ctgMvalue = ctgMvalue + "<a href=javascript:body_change('" + result.CtgName+"."+result.ctgM[i].name+"."+result.ctgM[i].ctg + "P1')>"+result.ctgM[i].ctg_hangul+"</a>&nbsp;&nbsp;<img src=/img/left/division_line.gif>&nbsp;&nbsp;";
	}
	//end


	document.getElementById(BodyTop).innerHTML = 

	"<table cellpadding=0 cellspacing=0 ailgn=center border=0 width=100% height=100%>"
	+ "<tr>"
	+	"<td height=42 valign=middle>"
	+		"<table width=95% border=0><tr><td width=15></td><td align=left width=10><div id=ctgT_div"+in_num+">"+imagePath+"</div></td>"
	+		"<td align=left class=payment_11 vailgn=middle><div id=textctg"+in_num+">"+textctg+"</div></td>"
	+	"<td align=right class=subtit><div id=textPath"+in_num+">" +textPath+ "</div></td></tr></table></td>"
	+ "</tr>"
	+ "<tr>"
	+	"<td width=100% bgcolor=#535353 height=1></td>"
	+ "</tr>"
	+ "<tr>"
	+	"<td height=35 valign=middle>"
	+		"<table  border=0 cellpadding=0 cellspacing=0 width=95%>"
	+			"<tr><td height=5></td></tr><tr><td width=15></td><td align=left class=subtit><div id='"+detail_ctg+"'><img src=/img/sub/semo_dot.gif>&nbsp;&nbsp;"+ctgMvalue+"</div></td>"
	+				"<td align=right class=text><div id=totalgoodscnt"+in_num+" style='border:0px solid;'></div><!--<select><option>½Å»óÇ°¼ø</option><option>³·Àº °¡°Ý¼ø</option></select>--></td>"
	+			"</tr>"
	+		"</table>"
	+	"</td>"
	+ "</tr>"
	+ "</table>";


	document.getElementById(BodyBottom).innerHTML =
	"		 <table width=100% border=0 cellspacing=0 cellpadding=0> <tr>"
+"			 <tr><td height=20></tD></tr><tr>"
+"				<td height=1 bgcolor=#CCCCCC></td>"
+"			 </tr>"
+"			<td height=30><table border=0 cellspacing=0 cellpadding=0 align=center>"

+"			  <tr>"
+"				<td height=28><img src=/img/main/footer_01.gif width=39 height=13 border=0 onclick=javascript:CompanyIntro('show','1'); style=cursor:hand;></td>"
+"				<td><img src=/img/main/footer_00.gif width=17 height=13></td>"
+"				<td><img src=/img/main/footer_02.gif width=39 height=13 border=0 onclick=body_change('Recruit') style=cursor:hand;></td>"
+"				<td><img src=/img/main/footer_00.gif width=17 height=13></td>"
+"				<td><img src=/img/main/footer_03.gif width=85 height=13 border=0 onclick=PartnerhShip(); style=cursor:hand;></td>"
+"				<td><img src=/img/main/footer_00.gif width=17 height=13></td>"
+"				<td><img src=/img/main/footer_04.gif width=39 height=13 border=0 onclick=LargeBuy(); style=cursor:hand;></td>"
+"				<td><img src=/img/main/footer_00.gif width=17 height=13></td>"
+"				<td><img src=/img/main/footer_05.gif width=39 height=13 border=0 onclick=B2B(); style=cursor:hand;></td>"
+"				<td><img src=/img/main/footer_00.gif width=17 height=13></td>"
+"				<td><img src=/img/main/footer_06.gif width=39 height=13 border=0 onclick=body_change('UseAgreement') style=cursor:hand;></td>"
+"				<td><img src=/img/main/footer_00.gif width=17 height=13></td>"
+"				<td><img src=/img/main/footer_07.gif width=75 height=13 border=0 onclick=body_change('Privacy') style=cursor:hand;></td>"
+"				<td><p><img src=/img/main/footer_00.gif width=17 height=13></p>          </td>"
+"				<td><img src=/img/main/footer_08.gif width=102 height=13 border=0 onclick=body_change('EmailRejection') style=cursor:hand;></td>"
+"			  </tr>"
+"			</table></td>"
+"		  </tr>"
+"		  <tr>"
+"			<td height=1 bgcolor=#CCCCCC></td>"
+"		  </tr>"
+"		</table>"
+"		<table align=center border=0 cellspacing=0 cellpadding=0>"
+"		  <tr>"
+"			<td height=45 valign=bottom class=footer>»ç¾÷ÀÚµî·Ï¹øÈ£ : 212-81-41001 ¤Ó Åë½ÅÆÇ¸Å¾÷ ½Å°í¹øÈ£ : °­µ¿±¸Ã»Á¦ 25-775È£ ¤Ó ´ëÇ¥ÀÌ»ç : ±è´ëÇö<br>"
+"			  ÁÖ¼Ò : ¼­¿ï½Ã °­µ¿±¸ ÃµÈ£µ¿ 457-65¹øÁö (ÁÖ)ÆäÀÌÆÞÀ¯Åë ¤Ó TEL : 02-474-3950 ¤Ó FAX : 02-488-7022<br>°³ÀÎÁ¤º¸°ü¸®Ã¥ÀÓÀÚ : ¼­ÀºÃ¶ºÎÀå (sec@papearl.com)</td>"
+"		  </tr>"
+"		  <tr>"
+"			<td height=22 valign=bottom class=copyright>Copyright(c) 2009 Papearl, All right reserved. </td>"
+"		  </tr>"
+"		</table>";
	
};
//val2 - in_num , val3 - 1Áß 2¼Ò
function CallSetCTG(val2,val3)
{
	var req = getXMLHTTP();
	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			
			if (req.status == 200)
			{
				
				var result = eval("("+req.responseText+")");
				handleCallSetCTGresponse(result,val2,val3);
			}
		}
		
	}

	req.open('GET',"/call/call_SetCTG.asp",false);
	req.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");
	req.send(null);
}
function handleCallSetCTGresponse(result,val2,val3)
{
	var selectEl = document.getElementById("ctgdae"+val2);
	var nowctg = document.getElementById("unit_ctg");
	
	while(selectEl.firstChild)
	{
		selectEl.removeChild(selectEl.firstChild);
	}

	if (result.result == "true")
	{ 
		for (i=0;i<result.ctg.length;i++)
		{	
			var optionEl = document.createElement("option");
			optionEl.value = result.ctg[i].ctg + "/" + result.ctg[i].ctg_e;
			optionEl.appendChild(document.createTextNode(result.ctg[i].ctg_name));
			if (nowctg.value == result.ctg[i].ctg)
			{optionEl.selected = true;}
			selectEl.appendChild(optionEl);
		}
	}
	
	CallCTG(nowctg.value,1,val2,val3);
}

//val1-ÇöÀçctg val2-call1Áß2¼Ò, val3- in_num, val4-set1Áß2¼Ò
function CallCTG(val,val2,val3,val4)
{
	var req = getXMLHTTP();
	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			ctgIndicator(false);
			if (req.status == 200)
			{
				
				var result = eval("("+req.responseText+")");
				handleCallCTGresponse(result,val2,val3,val4);
			}
		}
		else
		{
			ctgIndicator(true);
		}
	}

	req.open('GET',"/call/call_selectCTG.asp?ctg="+escape(val),false);
	req.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");
	req.send(null);
}

function ctgIndicator(val)
{
}
function handleCallCTGresponse(result,val2,val3,val4)
{
	var selectEl = document.getElementById("ctgjung"+val3);
	var selectEl2 = document.getElementById("ctgso"+val3);
	var nowctg = document.getElementById("unit_ctg");
	
	if (val2 == 1)
	{
		if (result.result == "true")
		{
			while(selectEl.firstChild)
			{
				selectEl.removeChild(selectEl.firstChild)
			}
			var optionEl = document.createElement("option");
			optionEl.value = "00";
			optionEl.appendChild(document.createTextNode("ÁßºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä."));
			selectEl.appendChild(optionEl);
			nowctg = Left(nowctg.value,5);
			for (i=0;i<result.ctg.length;i++)
			{	
				var optionEl = document.createElement("option");
				optionEl.value = result.ctg[i].ctg+ "/" + result.ctg[i].ctg_e;
				optionEl.appendChild(document.createTextNode(result.ctg[i].ctg_name));
				if (nowctg == result.ctg[i].ctg)
				{optionEl.selected = true;}
				selectEl.appendChild(optionEl);
			}

			while(selectEl2.firstChild)
			{
				selectEl2.removeChild(selectEl2.firstChild)
			}
			var optionEl = document.createElement("option");
			optionEl.value = "00";
			optionEl.appendChild(document.createTextNode("¼ÒºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä."));
			selectEl2.appendChild(optionEl);

			
		}
		else
		{
			var optionEl = document.createElement("option");
			optionEl.value = "00";
			optionEl.appendChild(document.createTextNode(" "));
			selectEl.appendChild(optionEl);
		}

		

	}

	if (val2 == 2 || val4 == 1 || val4 == 2)
	{
		if (result.result == "true")
		{
			while(selectEl2.firstChild)
			{
				selectEl2.removeChild(selectEl2.firstChild)
			}
			var optionEl = document.createElement("option");
			optionEl.value = "00";
			optionEl.appendChild(document.createTextNode("¼ÒºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä."));
			selectEl2.appendChild(optionEl);

			for (i=0;i<result.ctgs.length;i++)
			{	
				var optionEl = document.createElement("option");
				optionEl.value = result.ctgs[i].ctg+ "/" + result.ctgs[i].ctg_e;
				optionEl.appendChild(document.createTextNode(result.ctgs[i].ctg_name));
				if (document.getElementById("unit_ctg").value == result.ctgs[i].ctg)
				{optionEl.selected = true;}
				selectEl2.appendChild(optionEl);
			}
			
		}
		else
		{
			var optionEl = document.createElement("option");
			optionEl.value = "00";
			optionEl.appendChild(document.createTextNode(" "));
			selectEl2.appendChild(optionEl);
		}

	
	}
	else
	{
		var optionEl = document.createElement("option");
		optionEl.value = "00";
		optionEl.appendChild(document.createTextNode(" "));
		selectEl2.appendChild(optionEl);
	}
	
	selectEl.reInitializeSelectBox();
	selectEl2.reInitializeSelectBox();
	
}

function DirectCTGChange(val)
{
	var selectEl = document.getElementById("ctgdae"+val);
	var selectEl2 = document.getElementById("ctgjung"+val);
	var selectEl3 = document.getElementById("ctgso"+val);

	if (selectEl3.value != "00")
	{
		selectvalue =  selectEl.value; //´ëºÐ·ù
		selectvalue2 =  selectEl2.value; //ÁßºÐ·ù
		selectvalue3 = selectEl3.value; //¼ÒºÐ·ù
		
		arr_value = selectvalue.split("/");
		arr_value2 = selectvalue2.split("/");
		arr_value3 = selectvalue3.split("/");
		
		hash = arr_value[1] +"."+arr_value2[1]+"."+arr_value3[1]+"."+arr_value3[0]+"P1";
	}
	else
	{
		if (selectEl2.value != "00")
		{
			selectvalue =  selectEl.value; //´ëºÐ·ù
			selectvalue2 = selectEl2.value; //ÁßºÐ·ù
		
			arr_value = selectvalue.split("/");
			arr_value2 = selectvalue2.split("/");

			hash = arr_value[1] +"."+arr_value2[1]+"."+arr_value2[0]+"P1";
		}
		else
		{
			selectvalue = selectEl.value; //´ëºÐ·ù

			arr_value = selectvalue.split("/");

			hash = arr_value[1] +"."+arr_value[0]+"P1";
		}
	}
	//alert(hash);
	body_change(hash);
}