
// Ã·ºÎÆÄÀÏ ¾÷·Îµå Ã³¸®¿ë Å¸ÀÔ Å¬·¡½º
// flag (»èÁ¦¿©ºÎ): Á¤»ó N, »èÁ¦ D

function CItem(uid, type, folder, sfname, ofname, fsize, flag) { 
  
  this.uid = uid;
  this.type = type;
  this.folder = folder;
  this.sfname = sfname;
  this.ofname = ofname;
  this.fsize = fsize;
  this.flag = flag;

}


var FItem = new Array();

function Attack(type, folder, sfname, ofname, fsize) {

  var len = serial_next();

  FItem[len] = new CItem('', type, folder, sfname, ofname, fsize, 'N');

  addList(len, ofname, fsize, type);

  show_file_size();

}



function AttackUp(uid, type, folder, sfname, ofname, fsize) {   // ¼öÁ¤½Ã

  var len = serial_next();

  FItem[len] = new CItem(uid, type, folder, sfname, ofname, fsize, 'U');

  addList(len, sfname, fsize, type);

  show_file_size();

}



function serial_next () {

  var cnt = $("#sublist input:checkbox[name='chk_image[]']").length;

  return cnt;

}


function addList(cnt, filename, size, type) {

  var f = "";

  f  = "<div id=\"attchFile_"+cnt+"\" style=\"margin-left:1px; margin-top:3px; width:750px; height:20px; overflow:hidden; float:left;\">";
  f += "<div><input type=\"checkbox\" name=\"chk_image[]\" value=\""+filename+"\" alt=\""+size+"\" checked>";
  f += "<img src=\"http://image.bobaedream.co.kr/images/"+type+".gif\" border=\"0\" align=\"absmiddle\">&nbsp;"+filename;
  f += "</div>";
  f += "</div>";

  $("#sublist").append(f);

}



function subfile_delete(){

  var objs = $("input:checkbox[name='chk_image[]']:checked");

  objs.each(function(){
   	$(this).parent().parent().remove();
	FItem[$(this).parent().parent().attr("id").substring(10)].flag = "D";
  });

  show_file_size ();

}



function show_file_size () {

  var totalsize = 0;

  for (var i=0; i < FItem.length; i++) {
    if (FItem[i].flag == 'N' || FItem[i].flag == 'U') totalsize += eval(FItem[i].fsize);
  }

  $("#subfile_size").val(show_FileSize(totalsize));

}




// Ã·ºÎÆÄÀÏ °¹¼ö _ »èÁ¦´Â Á¦¿Ü

function upload_file_cnt () {

  var cnt = 0;

  if (FItem.length > 0) {
	  for (var i=0; i < FItem.length; i++) {
        if (FItem[i].flag == "N" || FItem[i].flag == "U") cnt = cnt + 1;
	  }
  }

  return cnt;

}



// ¿ë·®Ç¥½Ã

function show_FileSize (fsize) {
  
  var result = 0;

  if (eval(fsize) > 0) {
      if (eval(fsize) > 1024000) {
			 result = parseInt(Math.round((eval(fsize / 1024000) * 1000) / 1000, 2)) + " MB";
      }
		else if (eval(fsize) > 1024) {
			result = parseInt(Math.round((eval(fsize / 1024) * 10) / 10, 2)) + " KB";
      }
		else {
			result = fsize + " Byte";
      }
  }
  else {
      result = "0 Byte";
  }

  return "ÃÑ : " + result;

}



// Ã·ºÎÆÄÀÏ Á¤º¸ Àü¼ÛÀ§ÇØ ÅØ½ºÆ®¹Ú½º¿¡ ´ã¾Æ¼­ ¾×¼Ç ÆäÀÌÁö·Î Àü¼ÛÇÑ´Ù.

function get_upload_files (f) {

  if (FItem.length > 0) {

		for (var i=0; i < FItem.length; i++) {

		  var input = document.createElement('input');
		  input.type = 'hidden';
		  input.name = 'up_uid[]';
		  input.value = FItem[i].uid;
		  f.appendChild(input);

		  var input = document.createElement('input');
		  input.type = 'hidden';
		  input.name = 'up_type[]';
		  input.value = FItem[i].type;
		  f.appendChild(input);

		  var input = document.createElement('input');
		  input.type = 'hidden';
		  input.name = 'up_folder[]';
		  input.value = FItem[i].folder;
		  f.appendChild(input);

		  var input = document.createElement('input');
		  input.type = 'hidden';
		  input.name = 'up_sfname[]';
		  input.value = FItem[i].sfname;
		  f.appendChild(input);

		  var input = document.createElement('input');
		  input.type = 'hidden';
		  input.name = 'up_ofname[]';
		  input.value = FItem[i].ofname;
		  f.appendChild(input);

		  var input = document.createElement('input');
		  input.type = 'hidden';
		  input.name = 'up_fsize[]';
		  input.value = FItem[i].fsize;
		  f.appendChild(input);

		  var input = document.createElement('input');
		  input.type = 'hidden';
		  input.name = 'up_flag[]';
		  input.value = FItem[i].flag;
		  f.appendChild(input);

		}  //  for (var i=0; i

  }  //  if (FItem.length > 0) {

}

