// °¢ ¿µ¿µº° ÄÝ¹é ÇÔ¼ö ¹× µ¥ÀÌÅÍ Ã¤¿ì±â
var arrItems = null;
var content = {};
content.err = {};
content.err.setMessage = function(err) {
	this.obj = Data.init.ListObj;
	this.err = err;

	this.setAddRow();
}
content.err.setMessage.prototype = {
	setAddRow : function() {
		var row = this.obj.insertRow();
		row.height	= 100;
		row.align	= "center";
		row.style['background'] = "#FFFFFF";

		var errMsg = "";
		var cell = row.insertCell();
		cell.align="center";
		switch(this.err) {
			case -1 :
				errMsg = "µ¥ÀÌÅÍ¸¦ °¡Á®¿À´Âµ¥ µµÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.";
				break;
			case -2 :
				errMsg = "°Ë»öµÈ µ¥ÀÌÅÍ°¡ ¾ø½À´Ï´Ù.";
				break;
			case -3 :
				errMsg = "µ¥ÀÌÅÍ¸¦ Ã³¸®ÇÏ´Â µµÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.";
				break;
		}

		cell.innerText = errMsg;
	}
}

content.data = {};
// Ãë¾÷¾ç½Ä, ÀÌ·Â¼­ °¡ÀÌµå, Ãë¾÷ ¸®Æ÷Æ®, ½ÅÀÔ»ç¿ø A to Z
content.data.setJobHtml = function(obj, items, count, nowcnt) {
	this.obj			= obj;
	this.items			= items;
	this.LineImg		= Data.init.LineImg;
	this.strCode		= Data.init.strCode;
	this.count			= count;
	this.nowcnt			= nowcnt;
	this.ListType		= Data.init.ListType;
	this.BoarderColor	= Data.init.BorderColor;
	this.BgColor		= Data.init.BgColor;
	
	this.setAddRow();
}
content.data.setJobHtml.prototype = {
	setAddRow : function() {
		var row1 = this.obj.insertRow();
		row1.height = 30;

		if(this.ListType == '0') {
			this.setAddCell(row1);

			if(this.nowcnt < this.count -1) {			
				var row2 = this.obj.insertRow();
				var cellLine = row2.insertCell();
				cellLine.colSpan = 3;
				cellLine.height = '1'
				cellLine.setAttribute("background", this.LineImg);
			}
		} else {										
			var row1 = this.obj.insertRow();
			row1.height = 30;
			row1.style['background'] = this.BgColor;
			var row2 = this.obj.insertRow();
			row2.style['background'] = "#FFFFFF";

			var cell1 = row1.insertCell();
			var cell2 = row2.insertCell();
			if(this.strCode == "102") cell2.valign = "top";

			cell1.className = "space1";
			cell2.className = "space2";
			
			// Àü¹®°¡ ÀÎÅÍºä html
			var tmpHtml = "<table border=0 cellpadding=0 cellspacing=0 width='100%'>";
			tmpHtml += "<tr>";
			tmpHtml += "<td width='20%' valign=top><img src='"+ this.items[7] +"' style=\"border:4pt solid #DDDDDD;\" width='100' height='69'></td>";
			tmpHtml += "<td width='80%' valign=top>";
			tmpHtml += "<a href='' onclick=\"MM_ReadOpen3('"+ this.items[2] +"', '"+ this.strCode +"', '770', '650');return false;\">";
			tmpHtml += (this.items[4].length > 100) ? this.items[4].substring(0, 100) + ".." : this.items[4];
			tmpHtml += "</a>";
			tmpHtml += "<br /><br />"+ this.items[1];
			tmpHtml += "</td>";
			tmpHtml += "</tr>";
			tmpHtml += "</table>";


			cell1.innerHTML = (this.strCode == "102")
								? "<a href='' onclick=\"MM_ReadOpen3('"+ this.items[2] +"', '"+ this.strCode +"', '770', '650');return false;\" class='b'>"+ this.items[3] +"</a>"
								: "<a href='' onclick=\"MM_ReadOpen('"+ this.items[2] +"', '"+ this.strCode +"', '760', '650');return false;\" class='b'>"+ this.items[3] +"</a>"
			cell2.innerHTML = (this.strCode == "102") 
								? tmpHtml	
								: "<a href='' onclick=\"MM_ReadOpen('"+ this.items[2] +"', '"+ this.strCode +"', '770', '650');return false;\">"+ this.items[4] +"</a>";
		}
	},
	setAddCell : function(rowObj) {
		var cell1 = rowObj.insertCell();
		var cell2 = rowObj.insertCell();
		var cell3 = rowObj.insertCell();	
		cell1.align="center";
		cell3.align="center";

		var tmpWidth	= (this.strCode == 2) ? 750 : 760;
		var tmpHeight	= (this.strCode == 2) ? 230	: 650;

		cell1.innerText = this.items[0];
		cell2.innerHTML = (this.strCode == "30") 
						? "<a href='"+ this.items[7] +"' target='_blank'>"+ this.items[3] + "</a>"
						: "<a href='' onclick=\"MM_ReadOpen4('"+ this.items[2] +"', '"+ this.strCode +"', '"+ tmpWidth +"', '"+ tmpHeight +"');return false;\">"+ this.items[3] +"</a>";
		cell3.innerText = (this.strCode == "30") ? this.items[1] : this.items[6];
	}
}

// °ø¸ðÀü, ¸éÁ¢Á·º¸ µ¥ÀÌÅÍ Ã¤¿ì±â
content.data.setContestHtml = function(obj, items, count, nowcnt) {
	this.obj			= obj;
	this.items			= items;
	this.LineImg		= Data.init.LineImg;
	this.strCode		= Data.init.strCode;
	this.count			= count;
	this.nowcnt			= nowcnt;	
	
	this.setAddRow();
}
content.data.setContestHtml.prototype = {
	setAddRow : function() {
		var row1 = this.obj.insertRow();
		row1.height = "30";

		this.setAddCell(row1);

		if(this.nowcnt < this.count -1) {			
			var row2 = this.obj.insertRow();
			var cellLine = row2.insertCell();
			cellLine.colSpan = 4;
			cellLine.height = '1'
			cellLine.setAttribute("background", this.LineImg);
		}
	},
	setAddCell : function(rowObj) {
		var cell1 = rowObj.insertCell();		
		var cell2 = rowObj.insertCell();
		var cell3 = rowObj.insertCell();
		var cell4 = rowObj.insertCell();
		cell1.align = "center";
		cell2.align = "center";
		cell4.align = "center";

		cell1.innerText = this.items[1];
		cell2.innerText = (this.strCode == "101") ? this.items[4] : this.items[2];
		cell3.innerHTML = (this.strCode == "101") 
							? (this.items[5] == "2")
							? "<a href='"+ this.items[0] +"' target='_blank'>"+ this.items[3] +"</a>"
							: "<a href='' onclick=\"MM_ReadOpen4('"+ this.items[0] +"', '');return false;\">"+ this.items[3] +"</a>"
							: "<a href='' onclick=\"MM_ReadOpen2('"+ this.items[0] +"');return false;\">"+ this.items[3] +"</a>";
		cell4.innerText = (this.strCode == "101") ? this.items[2] : this.items[4];
	}
}
content.data.setRecruitHtml = function(obj, items, count, nowcnt) {
	this.obj			= obj;
	this.items			= items;
	this.LineImg		= Data.init.LineImg;
	this.strCode		= Data.init.strCode;
	this.count			= count;
	this.nowcnt			= nowcnt;	

	this.setAddRow();
}
content.data.setRecruitHtml.prototype = {
	setAddRow : function() {
		var row1 = this.obj.insertRow();
		row1.height = 30;

		this.setAddCell(row1);

		if(this.nowcnt < this.count -1) {
			var row2 = this.obj.insertRow();
			var cellLine = row2.insertCell();
			cellLine.colSpan = (this.strCode == "99") ? 6 : 5;
			cellLine.height = '1'
			cellLine.setAttribute("background", this.LineImg);
		}
	},
	setAddCell : function(rowObj) {
		var cell1 = rowObj.insertCell();
		var cell2 = rowObj.insertCell();
		var cell3 = rowObj.insertCell();
		var cell4 = rowObj.insertCell();
		var cell5 = rowObj.insertCell();
		cell1.align	= "center";
		cell3.align	= "center";
		cell4.align	= "center";
		cell5.align	= "center";
		cell1.width = (this.strCode == "99") ? "120"	: "100";
		cell3.width = (this.strCode == "99") ? "80"		: "120";
		cell4.width = (this.strCode == "99") ? "80"		: "100";
		cell5.width = "80";

		var tmpTitle = (this.items[2].length > 20) ? this.items[2].substring(0, 18) + ".." : this.items[2];

		cell1.innerText = this.items[1];
		cell2.innerHTML = "<a href=\"javascript:MM_ReadOpen('"+ this.items[0] +"', '"+ this.strCode +"');\">"+ tmpTitle +"</a>";
		cell3.innerText = this.items[3];	
		var arrTmpVal = this.items[4].split('/');
		// ¾Æ¸£¹ÙÀÌÆ® Ã¤¿ëÁ¤º¸ÀÏ °æ¿ì ¾ÆÀÌÄÜ Ãâ·Â
		if(parseInt(arrTmpVal[0]) > 0 && this.strCode == "98") {
			cell4.innerHTML = "<img src='http://data.recruitnet.co.kr/image/icon/payicon_0"+ arrTmpVal[0] +".gif' border='0'> "+ arrTmpVal[1];
		} else {
			cell4.innerText = arrTmpVal[0];
		}	
		cell5.innerText = this.items[5];		

		if(this.strCode == "99") {
			var cell6 = rowObj.insertCell();
			cell6.align = "center";
			cell6.width = "80";
			cell6.innerText = this.items[6];
		}
	}
}
// ¸ÞÀÎ Ãë¾÷´º½º, ±³¿ÜÃ¤¿ëÁ¤º¸, ¾Æ¸£¹ÙÀÌÆ® Á¤º¸
content.data.setMainHtml = function(obj, items, count, nowcnt) {
	this.obj			= obj;
	this.items			= items;
	this.LineImg		= Data.init.LineImg;
	this.strCode		= Data.init.strCode;
	this.count			= count;
	this.nowcnt			= nowcnt;	

	this.setAddRow();
}
content.data.setMainHtml.prototype = {
	setAddRow : function() {
		var row1 = this.obj.insertRow();
		row1.height = "20";
		this.setAddCell(row1);

		if(this.LineImg != null) {
			if(this.nowcnt < this.count -1) {
				var row2 = this.obj.insertRow();
				var cellLine = row2.insertCell();
				cellLine.colSpan	= '3';
				cellLine.height		= '1'
				cellLine.setAttribute("background", this.LineImg);
			}
		}
	},
	setAddCell : function(rowObj) {
		var cell1 = rowObj.insertCell();
		var cell2 = rowObj.insertCell();
		var cell3 = rowObj.insertCell();
		cell1.width = "10";
		cell3.width = "60";

		// ¸®Äí¸£Æ®, ¾Æ¸£¹ÙÀÌÆ® ÀÏ°æ¿ì 
		// 2¹øÂ° cell¿¡ ±â¾÷ ¸í º¸¿©ÁÖ±â
		// 4¹øÂ° cell »ý¼ºÈÄ ¸¶°¨ÀÏ º¸¿©ÁÖ±â
		if(this.strCode == "99" || this.strCode == "98") {
			cell2.width = "80";
			cell3.width = "";
			var cell4 = rowObj.insertCell();
			cell4.align = "center";
			cell4.width = "60";
		}

		var tmpComp  = (this.items[1].length > 5) ? this.items[1].substring(0, 5) + ".." : this.items[1];
		var tmpUrl = null;

		if(this.strCode == "99") {
			tmpUrl = "recruit_view.asp?strCode="+ this.items[0];
		} else if(this.strCode == "98") {
			tmpUrl = "albada_view.asp?strCode="+ this.items[0];
		}
		var strLink = (this.strCode == "30") ? "<a href='"+ this.items[0] +"' target='_blank' " : "<a href=\"javascript:MM_ReadOpen5('"+ tmpUrl +"');\" ";
		var tmpTitle= (this.items[2].length > Data.init.MaxLength) ? this.items[2].substring(0, Data.init.MaxLength) + ".." : this.items[2];

		if(Data.init.LinkClassName != null) {
			strLink += "class='"+ Data.init.LinkClassName +"'";
		}
		strLink += ">";

		cell1.innerHTML = "<img src='"+ Data.init.ListIcon +"'>";
		cell2.innerHTML = (this.strCode == "30") ? strLink + tmpTitle + "</a>" : tmpComp;
		cell3.innerHTML = (this.strCode == "30") ? this.items[1] : strLink + tmpTitle + "</a>";
		if(this.strCode == "99" || this.strCode == "98") {
			cell4.innerHTML = this.items[3];
		}
	}
}

// Ãë¾÷¾ç½Ä, ÀÌ·Â¼­ °¡ÀÌµå Ajax °á°ú ÇÔ¼ö
var ret = {};
ret.data = {}
ret.data.doXMLTempleteHandler = function(req) {
	if(req.readyState == 4) {
		new Data.xhr.setControlDel(Data.init.ListObj, 0);
		new Data.xhr.ToggleLoader(true);
		if(req.status == 200) {			
			try {
				var xmlDoc = req.responseXML;
				Data.init.TotalRecord = xmlDoc.getElementsByTagName("TotalRecordCount").item(0).firstChild.nodeValue;
				var pagecnt = xmlDoc.getElementsByTagName("TotalPageCount").item(0).firstChild.nodeValue;
				if(pagecnt == "error") {
					new content.err.setMessage(-1);
				} else if(parseInt(Data.init.TotalRecord) == 0) {
					new content.err.setMessage(-2);
				} else {				
					if(Data.init.RecordObj) {
						Data.init.RecordObj.innerText = "ÀüÃ¼±Û : " + Data.init.TotalRecord;
					}
					var items = eval("(" + xmlDoc.getElementsByTagName("Data").item(0).firstChild.nodeValue + ")");
					var tmpNum = parseInt(Data.init.TotalRecord) - ((Data.init.nowPage-1) * Data.init.PageSize);
					for(var i=0; i<items.length; i++) {
						arrItems = new Array();
						arrItems[arrItems.length] = tmpNum;
						arrItems[arrItems.length] = items[i].BoardCode;
						arrItems[arrItems.length] = items[i].ContentsCode;
						arrItems[arrItems.length] = items[i].Title;
						arrItems[arrItems.length] = items[i].SubTitle;
						arrItems[arrItems.length] = items[i].RegiDate;
						arrItems[arrItems.length] = items[i].ReadCount;
						arrItems[arrItems.length] = items[i].URL;

						new content.data.setJobHtml(Data.init.ListObj, arrItems, items.length, i);

						tmpNum--;
					}				
				}	

				new Data.xhr.doCreatePaging(Data.init.PageObj, pagecnt);
				new Data.xhr.setControlDel(Data.init.PageObj, 1);
			} catch(ex) {
				new content.err.setMessage(-3);
			}
		} else {
			alert("µ¥ÀÌÅÍ °¡Á®¿À±â ½ÇÆÐ!!!\n´Ù½Ã ÀÌ¿ëÇØ ÁÖ¼¼¿ä.");			
			return;
		}
	} else {
		new Data.xhr.ToggleLoader(false);
	}
}

// °ø¸ðÀü, ¸éÁ¢Á·º¸ Ajax °á°ú ÇÔ¼ö
ret.data.doXMLContestHandler = function(req) {
	if(req.readyState == 4) {
		new Data.xhr.setControlDel(Data.init.ListObj, 0);
		new Data.xhr.ToggleLoader(true);
		if(req.status == 200) {		
			try {
				var xmlDoc = req.responseXML;
				Data.init.TotalRecord = xmlDoc.getElementsByTagName("TotalRecordCount").item(0).firstChild.nodeValue;
				var pagecnt = xmlDoc.getElementsByTagName("TotalPageCount").item(0).firstChild.nodeValue;
				if(pagecnt == "error") {
					new content.err.setMessage(-1);
				} else if(parseInt(Data.init.TotalRecord) == 0) {
					new content.err.setMessage(-2);
				} else {			
					if(Data.init.RecordObj) {
						Data.init.RecordObj.innerText = "ÀüÃ¼±Û : " + Data.init.TotalRecord;
					}
					var items = eval("(" + xmlDoc.getElementsByTagName("Data").item(0).firstChild.nodeValue + ")");
					for(var i=0; i<items.length; i++) {
						arrItems = new Array();
						arrItems[arrItems.length] = items[i].ContentsCode;
						arrItems[arrItems.length] = items[i].PubType;
						arrItems[arrItems.length] = items[i].PubTarget;
						arrItems[arrItems.length] = items[i].Title;
						arrItems[arrItems.length] = items[i].PubTerm;
						arrItems[arrItems.length] = items[i].RegiDate;

						new content.data.setContestHtml(Data.init.ListObj, arrItems, items.length, i);
					}				
				}	

				new Data.xhr.doCreatePaging(Data.init.PageObj, pagecnt);
				new Data.xhr.setControlDel(Data.init.PageObj, 1);
			} catch(ex) {
				new content.err.setMessage(-3);
			}
		} else {
			alert("µ¥ÀÌÅÍ °¡Á®¿À±â ½ÇÆÐ!!!\n´Ù½Ã ÀÌ¿ëÇØ ÁÖ¼¼¿ä.");			
			return;
		}
	} else {
		new Data.xhr.ToggleLoader(false);
	}
}

// ¸®Äí¸£Æ®, ¾Æ¸£¹ÙÀÌÆ® Ã¤¿ë Á¤º¸
ret.data.doXMLRecruitHandler = function(req) {
	if(req.readyState == 4) {
		new Data.xhr.setControlDel(Data.init.ListObj, 0);
		new Data.xhr.ToggleLoader(true);
		if(req.status == 200) {			
			try {
				var xmlDoc = req.responseXML;
				Data.init.TotalRecord = xmlDoc.getElementsByTagName("TotalRecordCount").item(0).firstChild.nodeValue;
				var pagecnt = xmlDoc.getElementsByTagName("TotalPageCount").item(0).firstChild.nodeValue;
				if(pagecnt == "error") {
					new content.err.setMessage(-1);
				} else if(parseInt(Data.init.TotalRecord) == 0) {
					new content.err.setMessage(-2);
				} else {				
					//Data.init.RecordObj.innerText = "ÀüÃ¼±Û : " + Data.init.TotalRecord;
					var items = eval("(" + xmlDoc.getElementsByTagName("Data").item(0).firstChild.nodeValue + ")");
					for(var i=0; i<items.length; i++) {
						arrItems = new Array();
						arrItems[arrItems.length] = items[i].EmpNoticeCode;
						arrItems[arrItems.length] = (Data.init.strCode == "99") ? items[i].CompanyName.substring(0, 10)	: items[i].Area;
						arrItems[arrItems.length] = items[i].Title;
						arrItems[arrItems.length] = (Data.init.strCode == "99") ? items[i].Scholarship	: items[i].CompanyName.substring(0, 10);
						arrItems[arrItems.length] = (Data.init.strCode == "99") ? items[i].Career		: items[i].Pay;
						arrItems[arrItems.length] = (Data.init.strCode == "99") ? items[i].RegiDate		: items[i].FinishDate;
						if(Data.init.strCode == "99") arrItems[arrItems.length] = items[i].FinishDate;

						new content.data.setRecruitHtml(Data.init.ListObj, arrItems, items.length, i);
					}				
				}	

				new Data.xhr.doCreatePaging(Data.init.PageObj, pagecnt);
				new Data.xhr.setControlDel(Data.init.PageObj, 1);
			} catch(ex) {
				new content.err.setMessage(-3);
			}
		} else {
			alert("µ¥ÀÌÅÍ °¡Á®¿À±â ½ÇÆÐ!!!\n´Ù½Ã ÀÌ¿ëÇØ ÁÖ¼¼¿ä.");			
			return;
		}
	} else {
		new Data.xhr.ToggleLoader(false);
	}
}

// ¸ÞÀÎ Ãë¾÷´º½º, ¸®Äí¸£Æ® Ã¤¿ëÁ¤º¸, ¾Æ¸£¹ÙÀÌÆ® 
ret.data.doXMLMainHandler = function(req) {
	if(req.readyState == 4) {
		new Data.xhr.setControlDel(Data.init.ListObj, 0);
		if(req.status == 200) {
			try {
				var xmlDoc = req.responseXML;
				Data.init.TotalRecord = xmlDoc.getElementsByTagName("TotalRecordCount").item(0).firstChild.nodeValue;
				var pagecnt = xmlDoc.getElementsByTagName("TotalPageCount").item(0).firstChild.nodeValue;
				if(pagecnt == "error") {
					new content.err.setMessage(-1);
				} else if(parseInt(Data.init.TotalRecord) == 0) {
					new content.err.setMessage(-2);
				} else {				
					var items = eval("(" + xmlDoc.getElementsByTagName("Data").item(0).firstChild.nodeValue + ")");
					for(var i=0; i<items.length; i++) {
						arrItems = new Array();
						// Ãë¾÷´º½º
						if(Data.init.strCode == "30") {
							arrItems[arrItems.length] = items[i].URL;
							arrItems[arrItems.length] = items[i].RegiDate;
							arrItems[arrItems.length] = items[i].Title;
						} 
						// ¸®Äí¸£Æ® Ã¤¿ëÁ¤º¸, ¾Æ¸£¹ÙÀÌÆ® Ã¤¿ëÁ¤º¸
						else if(Data.init.strCode == "99" || Data.init.strCode == "98") {
							arrItems[arrItems.length] = items[i].EmpNoticeCode;
							arrItems[arrItems.length] = items[i].CompanyName;
							arrItems[arrItems.length] = items[i].Title;
							arrItems[arrItems.length] = items[i].FinishDate;
						}						

						new content.data.setMainHtml(Data.init.ListObj, arrItems, items.length, i);
					}				
				}					
			} catch(e) {				
				alert("µ¥ÀÌÅÍ Ã³¸®Áß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.\n\n"+ e.message +"\n\n"+ e);
			}
		} else {
			alert("µ¥ÀÌÅÍ °¡Á®¿À±â ½ÇÆÐ!!!\n´Ù½Ã ÀÌ¿ëÇØ ÁÖ¼¼¿ä.");			
			return;
		}
	} else {
	}
}

function MM_ReadOpen(InformNoticeCode, strCode, intWidth, intHeight)
{
	var vLeft = 0 ;
	var vTop = 0 ;

	var win = window.open("http://data.recruitnet.co.kr/read.asp?InformNoticeCode="+InformNoticeCode+"&strCode="+strCode,"view","top=" + vTop + ", left=" + vLeft + ",height="+intHeight+",width="+intWidth+",scrollbars=yes");
	if(win.focus)
		win.focus();
}

function MM_ReadOpen2(PubCode)
{
	var vLeft = 0 ;
	var vTop = 0 ;

	var win = window.open("http://data.recruitnet.co.kr/read_pub.asp?PubCode="+PubCode,"view","top=" + vTop + ", left=" + vLeft + ",height=500,width=730,scrollbars=yes");
	if(win.focus)
		win.focus();
}

function MM_ReadOpen3(Code, strCode, intWidth, intHeight)
{
	var vLeft = 0 ;
	var vTop = 0 ;

	var win = window.open("http://data.recruitnet.co.kr/recruit_read_specialist.asp?Code="+ Code +"&strCode=","view","top=" + vTop + ", left=" + vLeft + ",height="+intHeight+",width="+intWidth+",scrollbars=yes");
	if(win.focus)
		win.focus();
}

function MM_ReadOpen4(Code, PubCode)
{
	var vLeft = 0 ;
	var vTop = 0 ;

	var win = window.open("http://data.recruitnet.co.kr/recruit_read_interviewtip.asp?Code="+ Code +"&strCode=="+PubCode,"view","top=" + vTop + ", left=" + vLeft + ",height=500,width=730,scrollbars=yes");
	if(win.focus)
		win.focus();
}
function MM_ReadOpen5(url)
{
	var vLeft = 0 ;
	var vTop = 0 ;

	var win = window.open("http://data.recruitnet.co.kr/"+ url,"view","top=" + vTop + ", left=" + vLeft + ",height=500,width=730,scrollbars=yes");
	if(win.focus)
		win.focus();
}