/* Copyright (c) 2009 Smileweb co., Ltd.  All rights reserved.  www.smileweb.co.kr */
// ywlee@
var formName = new Array(':SHOPLINK:',':IMG:',':MNAME:',':MPRICE:',':NUM:',':SV:',':BIDTYPE:',':PAYTYPE:',':BOLD:',':LOOK:',':SHIPPRICE:',':POINT:',':CPPAMT:',':MGRADE:',':CHECKID:',
						':CHECKVALUE:',':SHIPTYPE:',':ETCNUM:',':GIFT:',':EVENT:',':PUID:',':CHECKNUM:',':REGDATE:',':NPRICE:',':FIElDPRICE:',':WINMUID:',':calss_LastName:',':RESTTIME:',':EndDate:',':MinusPrice:');
var formValue = new Array();
var ieTableForm = "";
var checkIdNum = 1;
var MakeForm = {};
var tempNullData = {
	Num: "",
	Mname: "",
	CateCode: "",            
	Mgrade: "",
	Mprice: "",
	Img: "",
	Point: "",
	ShipType: "",
	PayType: "",           
	BidType: "",            
	Bold: "",
	Look: "",         
	Nprice: "",
	FieldPrice: "",
	WinMuid: "",
	RestTime: "",
	Point: "",
	RegDate: ""
}
		
MakeForm = function(data, elID, listForm, callback, callbackGubun) {
	this.data = data;
	this.elID = elID;
	this.listForm = listForm;
	this.callback = callback;
	this.callbackGubun = callbackGubun;
	this.Make();
}

MakeForm.prototype ={
	Make: function(){
		this.html = "";
		if (window.ActiveXObject && navigator.appVersion.indexOf("MSIE 8") < 0) {
			if (this.data.length != null && this.data.length > 0) {
				var tempCheckArray = new Array();
				tempCheckArray = this.listForm;
				
				for (var i = 0; i < this.data.length; i++) {
				
					if (this.listForm[0] != null) {
						try {
							this.html += this.Convert(this.data[i], this.listForm[i]);
						} 
						catch (e) {
							this.html += this.Convert(this.data[i], this.listForm[this.listForm.length - 1]);
						}
					}
					else {
						this.html += this.Convert(this.data[i], this.listForm);
					}
					
					
					checkIdNum++;
				}
				
				
				if (this.listForm[0] != null && this.listForm.length > this.data.length) {
					for (var i = this.listForm.length - this.data.length - 1; i < this.listForm.length; i++) {
						try {
							this.html += this.Convert(tempNullData, this.listForm[i].replaceAll('원', ''));
						} 
						catch (e) {
							this.html += this.Convert(tempNullData, this.listForm[this.listForm.length - 1].replaceAll('원', ''));
						}
					}
				}
			}
			else {
				if (this.data.num != null) {					
					
					this.html = this.Convert(this.data, this.listForm);
				} else {
					
					this.html += this.Convert(this.data, this.listForm);
				}
			} 
		}
		else {
			if (this.data.length != null && this.data.length > 0) {
				
				for (var i = 0; i < this.data.length; i++) {
				
					if ( this.listForm[0] != null && this.listForm[0].length > 5) {
						try {
							this.html += this.Convert(this.data[i], this.listForm[i]);
						} 
						catch (e) {
							this.html += this.Convert(this.data[i], this.listForm[this.listForm.length - 1]);
						}
					}
					else {
						this.html += this.Convert(this.data[i], this.listForm);
					}
					
					
					checkIdNum++;
				}
				
				
				if ( this.listForm[0] != null && this.listForm[0].length > 5 && this.listForm.length > this.data.length) {
					
					for (var i = this.listForm.length - this.data.length - 1; i < this.listForm.length; i++) {
						try {
							this.html += this.Convert(tempNullData, this.listForm[i].replaceAll('원', ''));
						} 
						catch (e) {
							this.html += this.Convert(tempNullData, this.listForm[this.listForm.length - 1].replaceAll('원', ''));
						}
					}
				}
				
			}
			else {
				if (this.data.num != null) {
					
					this.html = this.Convert(this.data, this.listForm);
				}else {
					
					this.html += this.Convert(this.data, this.listForm);
				}
			}
		}
		
		
		if (window.ActiveXObject && ($(this.elID).tagName == "TBODY" || $(this.elID).tagName == "TR" || $(this.elID).tagName == "TABLE")) {
		
			var xmlTable = $(this.elID);
			var xtableTopEl = xmlTable.parentElement;
			while(true){
				if(xtableTopEl.tagName == "TABLE"){
					xtableTopEl = xtableTopEl.parentElement;
					break;
				}else{
					xtableTopEl = xtableTopEl.parentElement;
				}
			}
			
			if(ieTableForm.length == 0) ieTableForm = xtableTopEl.innerHTML;
			
			xtableTopEl.innerHTML = ieTableForm.substr(0, ieTableForm.indexOf(this.elID) + this.elID.length + 1)+this.html+ieTableForm.substr(ieTableForm.indexOf(this.elID) + this.elID.length + 1, ieTableForm.length);
		
		}else {
			$(this.elID).innerHTML = this.html;
		}

		if(this.callbackGubun != "checkNumNotReset") checkIdNum = 1;

		if(this.callback != null && this.callbackGubun != null)	this.callback(this.callbackGubun);
	},
	Convert: function(data, listForm){

		if(data == null || data.Num == null || data.Num == "") return "";
		
		if(data.Num != null && data.Num != ""){

			if(this.elID == "soonClosingList") { formValue[0] = "javascript:shopView(\"parentWindow\" ," + data.Num + ", null )"; }
			else if(this.elID == "pshopList") { formValue[0] = "javascript:pointshopView(\"parentWindow\" ," + data.Num + ", null )"; }
			else { formValue[0] = "javascript:shopView(null," + data.Num + ", null)"; }
		}
		else
			formValue[0] = "javascript:void(0)";
		
		if (data.Img != null && data.Img != "" && data.Img.length > 10) 			
			formValue[1] = data.Img;
		else 
			formValue[1] =  '/images/common/no_img.gif';			
		
		formValue[2] = data.Mname;
		formValue[3] = data.Mprice; 
		formValue[4] = data.Num; 		
		formValue[5] = this.callbackGubun; 		
		formValue[6] = data.BidType;
		formValue[7] = data.PayType;
		if(data.Bold == 'Y') formValue[8] = 'add_bold';
		else if(this.elID == "bestSellerList") formValue[8] = 'product';
		else	formValue[8] = '';
		formValue[9] = data.Look;
		formValue[10] = data.ShipPrice;
		formValue[11] = data.Point;
		formValue[12] = data.Cppamt;
		formValue[13] = data.Mgrade;
		formValue[14] = "chkitem"+checkIdNum;
		formValue[15] = data.Num;
		formValue[16] = data.ShipType;
		formValue[17] = data.EtcNum;
		formValue[18] = data.Gift ;
		if(data.Gift != "") formValue[18] += "<br/>";
		

		formValue[20] = data.Puid;
		formValue[21] = checkIdNum;		
		formValue[22] = data.RegDate;
		formValue[23] = data.Nprice;
		formValue[24] = data.FieldPrice;
		formValue[25] = data.WinMuid;
		formValue[26] = data.calss_LastName;
		formValue[27] = data.RestTime;
		formValue[28] = data.EndDate;
		formValue[29] = data.MinusPrice;
		
          
		for(var l=0; l < formName.length; l++){
			listForm = listForm.replaceAll(formName[l], formValue[l]);
		}
		
		if ($("shopNumList") != null )
			$("shopNumList").innerHTML +=","+ data.Num ; 

		return listForm;
	}	
}

 
