var attachFileSeperator = "!@!";	//÷������ ������.
var attachFileApproveSeperator = "#@#";


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { // v3.0
	var i, x, a = document.MM_sr;
	for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) {
		x.src = x.oSrc;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function open_window(TITLE,URL, WIDTH, HEIGHT) { 
	
	windowprops = "left=0,top=0,width=" + WIDTH + ",height=" + HEIGHT + ",resizable=yes,scrollbars=yes"; 
	window.open(URL, TITLE , windowprops); 
}

function open_window_popup(TITLE,URL, WIDTH, HEIGHT, TOP, LEFT) { 
	
	windowprops = "left=" + LEFT + ",top=" + TOP + ",width=" + WIDTH + ",height=" + HEIGHT + ",resizable=yes,scrollbars=yes"; 
	window.open(URL, TITLE , windowprops); 
}

function open_window_no_scroll(TITLE,URL, WIDTH, HEIGHT) { 
	
	windowprops = "left=0,top=00,width=" + WIDTH + ",height=" + HEIGHT + ",resizable=yes,scrollbars=no"; 
	window.open(URL, TITLE , windowprops); 
}

function open_window_no_scroll_no_resize(TITLE,URL, WIDTH, HEIGHT, TOP, LEFT) { 
	
	windowprops = "left=" + LEFT + ",top=" + TOP + ",width=" + WIDTH + ",height=" + HEIGHT + ",resizable=no,scrollbars=no"; 
	window.open(URL, TITLE , windowprops); 
}

function open_qna_window(TITLE,URL, WIDTH, HEIGHT) { 
	
	windowprops = "left=50%,top=50%,width=" + WIDTH + ",height=" + HEIGHT + ",resizable=yes,scrollbars=no"; 
	window.open(URL, TITLE , windowprops); 
}

function checkEmail(email) {
	
	var a = email.indexOf("@");

	email_account = email.substring(0,a);
	email_domain = email.substring(a+1);

	if(!checkEmailAccount(email_account))
	{
		return false;
	}
	if(!checkEmailDomain(email_domain))
	{
		return false;
	}

	return true;

}

function checkEmailAccount(email) {

	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.";
	var t = email;
	var ValidFlag = false
	var atCount = 0
	var SpecialFlag
	var atLoop
	var atChr
	var BadFlag
	var len = t.length;

	if ( t.length > 0 ) {
		atCount = 0
		SpecialFlag = false

		for( atLoop=1; atLoop<=t.length; atLoop++ ) {

			if(comp.indexOf(t.substring(atLoop,atLoop+1))<0)
			{
				return false;
				break;
			}
			atChr = t.substring( atLoop, atLoop+1 )

			if ( (atChr >= 32) && (atChr <= 44) ) SpecialFlag = true 
			if ( (atChr == 47) || (atChr == 96) || (atChr >= 123) ) SpecialFlag = true 
			if ( (atChr >= 58) && (atChr <= 63) ) SpecialFlag = true 
			if ( (atChr >= 91) && (atChr <= 94) ) SpecialFlag = true 
		}

		if ( SpecialFlag == false ) {
			BadFlag = false
			ValidFlag = true
		}

	}
	
	if ( BadFlag == true ) ValidFlag = false

	return ValidFlag
}

function checkEmailDomain(email) {

	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.";
	var t = email;
	var ValidFlag = false
	var atCount = 0
	var SpecialFlag
	var atLoop
	var atChr
	var BadFlag = true
	var len = t.length;
	
	if ( t.length > 0 && t.indexOf(".") > 0 ) {
		atCount = 0
		SpecialFlag = false

		for( atLoop=1; atLoop<=t.length; atLoop++ ) {

			if(comp.indexOf(t.substring(atLoop,atLoop+1))<0)
			{
				return false;
				break;
			}
			atChr = t.substring( atLoop, atLoop+1 )
			if ( atChr == "." ) atCount = atCount + 1

			if ( (atChr >= 32) && (atChr <= 44) ) SpecialFlag = true 
			if ( (atChr == 47) || (atChr == 96) || (atChr >= 123) ) SpecialFlag = true 
			if ( (atChr >= 58) && (atChr <= 63) ) SpecialFlag = true 
			if ( (atChr >= 91) && (atChr <= 94) ) SpecialFlag = true 
		}

		if ( ( atCount > 0 ) && (SpecialFlag == false ) ) {


			BadFlag = false

			if ( t.substring( 1, 2 ) == "." ) BadFlag = true
			if ( t.substring( t.length-1, t.length) == "." ) BadFlag = true
			ValidFlag = true
		}
	}
	if ( BadFlag == true ) ValidFlag = false

	return ValidFlag
}

function checkDigitAlpha(id) {

	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var t = id;
	var ValidFlag = false
	var atCount = 0
	var SpecialFlag
	var atLoop
	var atChr
	var BadFlag = true
	var len = t.length;
	
	if ( t.length > 0 ) {
		atCount = 0
		SpecialFlag = false

		for( atLoop=1; atLoop<=t.length; atLoop++ ) {

			if(comp.indexOf(t.substring(atLoop,atLoop+1))<0)
			{
				return false;
				break;
			}
			atChr = t.substring( atLoop, atLoop+1 )

			if ( (atChr >= 32) && (atChr <= 44) ) SpecialFlag = true 
			if ( (atChr == 47) || (atChr == 96) || (atChr >= 123) ) SpecialFlag = true 
			if ( (atChr >= 58) && (atChr <= 63) ) SpecialFlag = true 
			if ( (atChr >= 91) && (atChr <= 94) ) SpecialFlag = true 
		}

		if ( SpecialFlag == false ) {


			BadFlag = false
			ValidFlag = true
		}
	}
	if ( BadFlag == true ) ValidFlag = false

	return ValidFlag
}


function checkDigit(id) {
	
	var comp="0123456789";

	if ( id.length > 0 ) {
		
		for(var i=0;i<id.length;i++ ) {
			
			if(comp.indexOf(id.substring(i,i+1))<0)
			{
				return false;
			}
		}
		
		return true;

	} else {
		
		return false;
	}
}

function checkjumin(jumin)
{
	if(jumin.length != 13)
	{
		return false;
	}
	else
	{
		a = new Array(6)
		b = new Array(7)
		tot=0
		c=0
		for(i=1;i<7;i++) 
		{
				a[i]=jumin.substring(i-1,i)
				b[i]=jumin.substring(5+i,6+i)
				if(i<3) 
				{
				c=Number(b[i])*(i+7)
				}
				else if(i>=3) 
				{
				c=Number(b[i])*((i+9)%10)
				}
				tot = tot + Number(a[i])*(i+1) + c
		}
		b[7]=jumin.substring(12,13)
		if(Number(b[7]) != ((11-(tot%11))%10)) 
		{
				return false;
		}
	}
	
	return true;
}

function printNmbPage()
{
	var str = document.location.href;
	
	if(str.indexOf("?") > -1)
	{
		str = str + "&printPage=yes";

	} else
	{
		str = str + "?printPage=yes";
	}

	open_window('�������������',str,'700','500');
}

function checkNumber(field, totField)
{
  if(!checkDigit(field.value))
  {
    field.value = field.value.substring(0, field.value.length - 1);
  }
}

function num_only(){
  if((event.keyCode<48) || (event.keyCode>57)){
    event.returnValue=false;
  }
}

function checkListDeleteForm(form, text) {

	  var chk_flag = false;
	  var message = "";

	  if(text == null)
      {
		  message = "��f";
	  } else
	  {
		  message = text;
	  }
	
	  for(var i=0;i< form.elements.length;i++)
	  {
	    if(form.elements[i].type == "checkbox" && form.elements[i].checked == true)
	    {
	      chk_flag = true;
	      break;
	    }
	  }
	
	  if(chk_flag == false)
	  {
	    alert('�����׸�; ������ �ּ���');
	    return false;
	  } else {
	  	
	    if(confirm(message + " �Ͻðڽ4ϱ�?"))
	    {
	      return true;
	    }
	
	    return false;
	  } 
}




function Round(Num, Position , Base){
	//Num = �ݿø��� ��
	//Position = �ݿø��� �ڸ���(d��θ�)
	//Base = i �̸� �Ҽ�a'�� �ڸ����, f �̸� �Ҽ�a�Ʒ��� �ڸ���� �ݿø�

    if(Position == 0){ 
                //1�̸� �Ҽ�a1 �ڸ����� �ݿø�
        return Math.round(Num); 

    }else if(Position > 0){

		var cipher = '1';
		for(var i=0; i < Position; i++ ) {
			cipher = cipher + '0';
		}
		var no = Number(cipher);

		if(Base=="F"){
			//�Ҽ�a�Ʒ����� �ݿø�                        
			return Math.round(Num * no) / no;
		}else{
			//�Ҽ�a'���� �ݿø�.                        
			return Math.round(Num / no) * no;
		}

	 }else{

		alert("�ڸ���� d��θ� �����մϴ�.");
		return false;
	 }
}






function showModal(TITLE, URL, WIDTH, HEIGHT, LEFT, TOP) {

	if (window.showModalDialog) {
		return window.showModalDialog(URL,TITLE,"dialogWidth:" + WIDTH + "px;dialogHeight:" + HEIGHT + "px;dialogTop:" + TOP + "px;dialogLeft:" + LEFT + "px");
	} else {
		alert('���â ���; ������� �ʽ4ϴ�.');
	}
} 

function addFile(fieldName, fileName, fileSize, isTemp, isApproved)
{
  var file = new File();

  file.setFieldName(fieldName);
  file.setFileName(fileName);
  file.setFileSize(fileSize);

  if(isTemp != null)
	file.setIsTemp(isTemp);

  if(isApproved != null)
	file.setIsApproved(isApproved);

  fileList[fileList.length] = file;
}

function addFileLarge(fieldName, fileName, fileSize, isTemp, isApproved)
{
  var file = new File();

  file.setFieldName(fieldName);
  file.setFileName(fileName);
  file.setFileSize(fileSize);

  if(isTemp != null)
	file.setIsTemp(isTemp);

  if(isApproved != null)
	file.setIsApproved(isApproved);

  fileList[fileList.length] = file;
}

function File()
{
  this.fieldName = "";
  this.fileName = "";
  this.fileSize = "";
  this.isUse = "Y";
  this.isTemp = "Y";
  this.isApproved = "N";
  
  this.setFieldName = function(_fieldName)
  {
    this.fieldName = _fieldName;
  }

  this.setFileName = function(_fileName)
  {
    this.fileName = _fileName;
  }

  this.setFileSize = function(_fileSize)
  {
    this.fileSize = _fileSize;
  }

  this.setIsUse = function(_isUse)
  {
    this.isUse = _isUse;
  }

  this.setIsTemp = function(_isTemp)
  {
    this.isTemp = _isTemp;
  }

  this.setIsApproved = function(_isApproved)
  {
    this.isApproved = _isApproved;
  }

  this.getHtml = function(index)
  {
	  var result = "";

	  if(this.isUse == "Y")
	  {
		  if(this.isTemp == "Y")
		  {
			 methodName = "downloadTemp";
		  } else
		  {
			 methodName = "download";
		  }

		  result += "<tr><td bgcolor='#EFEFEF'>&nbsp;÷������ " + (index + 1) + "&nbsp;</td><td bgcolor='#FFFFFF'>&nbsp;<a href=\"javascript:" + methodName + "('" + this.fileName + "')\">" + this.fileName + "</a>&nbsp;</td><td bgcolor='#FFFFFF'><img src='/image/common/delete.gif' onClick='removeFile(" + index + ")' style='cursor:hand'></td></tr>";
	  }

	  return result;
  }

  this.getAdminHtml = function(index)
  {
	  var result = "";

	  if(this.isUse == "Y")
	  {
		  if(this.isTemp == "Y")
		  {
			 methodName = "downloadTemp";
		  } else
		  {
			 methodName = "download";
		  }
		  
		  if(this.isApproved == "Y")
		  {
			 checkedStr = "checked";
		  } else
		  {
			 checkedStr = "";
		  }

		  result += "<tr><td class='text_td'>÷������ " + (index + 1) + " (����: <input type='checkbox' name='fileApprove_" + index + "' value='Y' onclick=\"changeApprove(" + index + ", this.checked)\" " + checkedStr + "> )</td><td bgcolor='#FFFFFF'><a href=\"javascript:" + methodName + "('" + this.fileName + "')\">" + this.fileName + "</a></td><td bgcolor='#FFFFFF'><img src='/admin/_img/delete.gif' onClick='removeFile(" + index + ")' style='cursor:hand'></td></tr>";
	  }

	  return result;
  }

  this.getGreenHtml = function(index)
  {
	  var result = "";

	  if(this.isUse == "Y")
	  {
		  result += "<tr><td bgcolor='#FFFFFF'><img src='/board/skin/skin_green/img/file.gif'> " + this.fileName + "</td><td bgcolor='#FFFFFF'><img src='/board/skin/skin_green/img/s_delete.gif' onClick='removeFile(" + index + ")' style='cursor:hand'></td></tr>";
	  }

	  return result;
  }

  this.getBlueHtml = function(index)
  {
	  var result = "";

	  if(this.isUse == "Y")
	  {
		  result += "<tr><td bgcolor='#FFFFFF'><img src='/board/skin/skin_blue/img/file.gif'> " + this.fileName + "</td><td bgcolor='#FFFFFF'><img src='/board/skin/skin_blue/img/s_delete.gif' onClick='removeFile(" + index + ")' style='cursor:hand'></td></tr>";
	  }

	  return result;
  }

}

function downloadTemp()
{
	alert('�ش�������� �����ϼ���');
}

function download()
{
	alert('�ش�������� �����ϼ���');
}

function getCookie( name ){
        var nameOfCookie = name + "=";
        var x = 0;
        while ( x <= document.cookie.length ){

                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                                        endOfCookie = document.cookie.length;
                        return unescape( document.cookie.substring( y, endOfCookie ) );

                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 )
                        break;
        }
        return "";

}