/**
 * Å¬·¡½º¸í : MyAuction()
 * ±â    ´É : °æ¸Å¿¡ »ç¿ëµÇ´Â ÇÔ¼ö/¸Þ¼­µå
 * ÀÛ ¼º ÀÏ : 2008.01.05, ÀÌÁö¹Ìµð¾î, Á¤¿ø±¤
 *
 */
MyAuction = function () {
	this.Pages = [];
	this.Datas = [];
	this.Times = [];
	this.Flows = [];
	this.Timer = [];

	// ·Î±×ÀÎÃ¼Å©
	this.ChkLogin = function () {
		if (MyLib.Cookies("MEMBER[ID]") == "") {
			if (confirm("·Î±×ÀÎÇÏ¼Å¾ß ÀÌ¿ëÇÏ½Ç ¼ö ÀÖ´Â ÆäÀÌÁöÀÔ´Ï´Ù.\n\n·Î±×ÀÎÆäÀÌÁö·Î ÀÌµ¿ÇÏ½Ã°Ú½À´Ï±î?") == true) {
				Login();
			}
			return false;
		}
		return true;
	}
	// ·Î±×ÀÎÃ¼Å©2
	this.ChkLogin2 = function () {
		if (MyLib.Cookies("MEMBER[ID]") == "") {
		    Login();
		    return false;
		}
		return true;
	}

	// ÀÔÂû
	this.GetBidding = function (idx, cate) {
		if (this.ChkLogin2() == false) {
			return;
		}

		window.open(MyLib.TopDir + "/AUC/Bidding.aspx?n=" + idx, "BIDDING", "width=617, height=650, left=10, top=10, scrollbars=yes");
	}

	// Áï½Ã±¸¸Å
	this.GetDirect = function (idx) {
		if (this.ChkLogin2() == false) {
			return;
		}

		window.open(MyLib.TopDir + "/AUC/Direct.aspx?n=" + idx, "DIRECT", "width=617, height=650, left=10, top=10, scrollbars=yes");
	}

	// Ã¢ ´Ý±â
	this.Close = function () {
		opener.history.go(0); 
		window.close();
	}

	// Á¤·Ä ¼±ÅÃ
    this.SetOrder = function (v1, v2) {
        var frm = document.search;
        
        frm.of.value = v1;
        frm.ot.value = v2;
        frm.submit();
    }

	// ÀÔÂû ¼³Á¤
    this.SetBdrs = function () {
        for (var i = 0; i < this.Times.length; i++) {
            if (typeof this.Times[i] == "undefined" || this.Times[i] <= 0) {
                continue;
            }

			this.Flows[i] = 0;
            this.Timer[i] = setTimeout("MyAuction.SetTime(" + i + ");", 1000);
        }
    }

	// ½Ã°£ ¼³Á¤
    this.SetTime = function (cnt) {
        if (this.Times[cnt] <= 0) {
            clearTimeout(this.Timer[cnt]);
            return;
        }

		if (this.Flows[cnt] > 0 && this.Flows[cnt] % 60 == 0) {
			this.GetNowPrice(cnt);
		}

		if (this.Pages[cnt] == "V") {
			if (this.Datas[cnt][1] == "B" && this.Flows[cnt] > 0 && (this.Times[cnt] / 60) % this.Datas[cnt][2] == 0) {
				this.GetDirPrice(cnt);
			}
		}
        
        this.Times[cnt] -= 1;
        this.Flows[cnt] += 1;
        MyLib.Object("TIME" + cnt).innerHTML = this.ParseTime(this.Times[cnt]);
        this.Timer[cnt] = setTimeout("MyAuction.SetTime(" + cnt + ");", 1000);
    }

	// ÇöÀç ÀÔÂû°¡
	this.GetNowPrice = function (cnt) {
		var xml;

		xml = new XmlHttp();
		xml.Open("GET", "List.aspx?n=" + this.Datas[cnt][0] + "&m=NPC", true);
		xml.Read().onreadystatechange = function () { MyAuction.SetNowPrice(xml.Read(), cnt) };
		xml.Send();
	}
	this.SetNowPrice = function (xhr, cnt) {
		if (xhr == null || xhr.readyState != 4 || xhr.status != 200) {
			return;
		}

		try {
//			MyLib.Object("NPRC" + cnt).innerHTML = xhr.responseText;
		} catch (e) {
		}
	}

	// Áï½Ã ±¸¸Å°¡
	this.GetDirPrice = function (cnt) {
		var xml;

		xml = new XmlHttp();
		xml.Open("GET", "List.aspx?n=" + this.Datas[cnt][0] + "&m=DPC", true);
		xml.Read().onreadystatechange = function () { MyAuction.SetDirPrice(xml.Read(), cnt) };
		xml.Send();
	}
	this.SetDirPrice = function (xhr, cnt) {
		if (xhr == null || xhr.readyState != 4 || xhr.status != 200) {
			return;
		}

		try {
			MyLib.Object("DPRC" + cnt).innerHTML = xhr.responseText;
		} catch (e) {
		}
	}

	// ³¯Â¥ Â÷ÀÌ
	this.DateDiff = function (date1, date2) {
		try {
			var y1 = parseInt(date1.substr(0, 4));
			var m1 = parseInt(date1.substr(4, 1) == "0" ? date1.substr(5, 1) : date1.substr(4, 2));
			var d1 = parseInt(date1.substr(6, 1) == "0" ? date1.substr(7, 1) : date1.substr(6, 2));
			var h1 = parseInt(date1.substr(8, 1) == "0" ? date1.substr(9, 1) : date1.substr(8, 2));
			var i1 = parseInt(date1.substr(10, 1) == "0" ? date1.substr(11, 1) : date1.substr(10, 2));
			var s1 = parseInt(date1.substr(12, 1) == "0" ? date1.substr(13, 1) : date1.substr(12, 2));

			var y2 = parseInt(date2.substr(0, 4));
			var m2 = parseInt(date2.substr(4, 1) == "0" ? date2.substr(5, 1) : date2.substr(4, 2));
			var d2 = parseInt(date2.substr(6, 1) == "0" ? date2.substr(7, 1) : date2.substr(6, 2));
			var h2 = parseInt(date2.substr(8, 1) == "0" ? date2.substr(9, 1) : date2.substr(8, 2));
			var i2 = parseInt(date2.substr(10, 1) == "0" ? date2.substr(11, 1) : date2.substr(10, 2));
			var s2 = parseInt(date2.substr(12, 1) == "0" ? date2.substr(13, 1) : date2.substr(12, 2));

			var cal1 = new Date(y1, m1 - 1, d1, h1, i1, s1);
			var cal2 = new Date(y2, m2 - 1, d2, h2, i2, s2);

			return Math.ceil((cal2.getTime() - cal1.getTime()) / 1000);
		} catch (e) {
			return 0;
		}
	}

	// ³¯Â¥ º¯È¯
	this.ParseDate = function (date, type) {
		var parse = "";

		switch (type) {
			case "B" :
				parse = date.substr(0, 2) + "½Ã " + date.substr(2, 2) + "ºÐ";
				break;
			default :
				parse = date.substr(0, 4) + "-" + date.substr(4, 2) + "-" + date.substr(6, 2) + " " + date.substr(8, 2) + ":" + date.substr(10, 2) + ":" + date.substr(12, 2);
				break;
		}

		return parse;
	}

	// ½Ã°£ º¯È¯
	this.ParseTime = function (time) {
		var d;
		var h;
		var m;
		var s;

		if (time < 0) {
			s = 0;
			m = 0;
			h = 0;
		} else if (time >= 3600) {
			s = time % 60;
			m = parseInt(time / 60) % 60;
			h = parseInt(parseInt(time / 60) / 60);
		} else if (time >= 60) {
			s = time % 60;
			m = parseInt(time / 60);
			h = 0;
		} else {
			s = time;
			m = 0;
			h = 0;
		}

		if (h >= 24) {
			d = parseInt(h / 24);
			h = h % 24;
		} else {
			d = 0;
		}

		d = (d < 10) ? "0" + d : d;
		h = (h < 10) ? "0" + h : h;
		m = (m < 10) ? "0" + m : m;
		s = (s < 10) ? "0" + s : s;

		return (d == "00" ? "" : d + "ÀÏ ") + h + "½Ã°£ " + m + "ºÐ " + s + "ÃÊ";
	}
}

var MyAuction = new MyAuction();
