﻿
//--------------------------------- 금액 단위 표시
function RemoveComma(val) 
{
    self.focus();
    return val.split(",").join("");
	//return val.replace(/,/gi,""); 
} 

function MakeComma(val)
{		
	var ret= "";
	var k=0;
		
	val = RemoveComma(val.toString());

	for(var i=val.length-1 ; i>=0 ; i--)
	{
		if ( k%3 ==0 && k!=0) ret="," + ret;
		ret = val.substr(i,1) + ret ; 
		k++
	}
	
	return ret.replace("-,", "-");
}

function MakeMoney(th)
{
    th.value = RemoveComma(th.value);
    
    NumberCheck(th);
    
    th.value = MakeComma(th.value);
    
    th.focus();
    th.value = th.value;
}

// 숫자만 허용함
function NumberCheck(th)
{   
	var len = th.value.length;
	
	if(isNaN(th.value))
	{  
	    self.focus();
		th.value = th.value.substr(0,len-1);
		alert('숫자 형식만 입력하십시요!');
		
		th.focus();
        th.value = th.value;
	}
	else if(parseInt(th.value, 10) < 0)
	{
	    alert('금액을 확인해 주세요!');
	    th.focus();
	    th.value = 0;	    
	}
}
//--------------------------------- 금액 단위 표시


//--------------------------------- 문자 체크
// 한글이외의 캐릭터가 있을경우 false 
function KoreanCheck(th) 
{ 
    var koreanChar = th.value;
    var len = th.value.length;
 
   if ( koreanChar == null ) return false ;
   
   for(var i=0; i < koreanChar.length; i++)
   {
     var c=koreanChar.charCodeAt(i); 

     //( 0xAC00 <= c && c <= 0xD7A3 ) 초중종성이 모인 한글자 
     //( 0x3131 <= c && c <= 0x318E ) 자음 모음 

     if( !( ( 0xAC00 <= c && c <= 0xD7A3 ) || ( 0x3131 <= c && c <= 0x318E ) || (0x30 <= c && c <= 0x39) ) ) 
     {      
        self.focus();
		th.value = th.value.substr(0,len-1);
		alert('한글과 숫자 형식만 입력하십시요!');
		
		th.focus();
        th.value = th.value;
        
        return;
     }
   }
}

// 영문 이외의 캐릭터가 있을경우 false
function EnglishCheck(th)
{   
    var englishChar = th.value;
    var len = th.value.length;
    
    if ( englishChar == null ) return false ;
       
    for( var i=0; i < englishChar.length;i++)
    {          
       var c=englishChar.charCodeAt(i);       
       if( !( (  0x61 <= c && c <= 0x7A ) || ( 0x41 <= c && c <= 0x5A ) || (0x30 <= c && c <= 0x39) ) ) 
       {         
            self.focus();
		    th.value = th.value.substr(0,len-1);
		    alert('영어와 숫자 형식만 입력하십시요!');
    		
		    th.focus();
            th.value = th.value;   
            
            return;  
       }
     }         
} 
//---------------------------------// 문자 체크


//------------------------------------- ajax
//XmlHttpRequest 객체 생성 함수
function GetXmlHttpRequest()
{
	var xmlhttp = false;
	
	if(window.XMLHttpRequest) 
		xmlhttp = new XMLHttpRequest();
	else
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

	return xmlhttp;
}

// 데이터 가져오기
function Ajax(type, strVal)
{
	var xmlhttp = GetXmlHttpRequest();
	var url = "/Ajax/Default.aspx?type=" + type + "&param=" +  strVal;
	
	xmlhttp.open("GET", url, true );
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4)
		{
			if(xmlhttp.status == 200)	//정상 처리되었을때
			{
			    var result = xmlhttp.responseText;
			    
			    if(result == "err")
			    {
			        alert("결과값이 올바르지 않습니다.");
			    }
			    else
			    {  
				    AjaxComplete(result);
				}
			}
			else						//에러 났을때
			{
				alert( "AJAX Error, (" + xmlhttp.status + " " + xmlhttp.statusText + ")" );
			}
		}
	}
	
	xmlhttp.send();
	
	return false;
}
//-------------------------------------// ajax


function LoadFlash(Url,Width,Height)
{ 
    document.writeln("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + Width + "\" height=\"" + Height + "\">"); 
    document.writeln("<param name=\"movie\" value=\"" + Url + "\">"); 
    document.writeln("<param name=\"quality\" value=\"high\" />"); 
    document.writeln("<param name=\"wmode\" value=\"transparent\">"); 
    document.writeln("<embed src=\"" + Url + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + Width + "\" height=\"" + Height + "\">"); 
    document.writeln("</object>"); 
} 

function LoadMovie(Url,Width,Height)
{ 
    document.writeln("<object classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' width='" + Width + "' height='" + Height + "'>");
    document.writeln("<param name='AutoStart' value='true'>");
    document.writeln("<param name='ClickToPlay' value='-1'>");
    document.writeln("<param name='Filename' value='" + Url + "'>");
    document.writeln("<param name='ShowControls' value='0'>");
    document.writeln("</object>");
} 

function JSDecode(str)
{
	str = str.split("＇").join("'");
	str = str.split('<br />').join('\r\n');
	//str = str.split('，').join(',');

	return str;
}


function ResizeImage(img)
{
  //메모리에 임시 이미지 생성
  var tempImg = new Image;

  //임시 이미지 다운로드 완료시 작동할 이벤트핸들러 등록
  tempImg.onload = function()
  {
    //임시 이미지의 크기(원래 크기)가 img 태그에 지정된 크기보다 작다면
    if(tempImg.width < img.width)
    {
      //img 태그의 크기를 원래 크기로...
      img.width = tempImg.width;
    }
    
    if(tempImg.height < img.height)
    {
      //img 태그의 크기를 원래 크기로...
      img.height = tempImg.height;
    }    
  }

  //임시 이미지 다운로드 시작
  tempImg.src = img.src;
}

function SetCookie(name, value, expiredays)
{
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

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 '';
}

function TabClick(obj) {
    if(obj == null)
    {
        return;
    }
	var tabObj = obj.parentNode.parentNode;
	var tabList = tabObj.childNodes;
	var cnt = tabList.length;
	for (i = 0; i < cnt ; i++ )
	{
		if (tabList[i].className.indexOf("on") >= 0)
		{
			var imgObj = tabList[i].getElementsByTagName("IMG")[0];
			tabList[i].className = tabList[i].className.replace("on","");
			if (tabList[i].getElementsByTagName("UL")[0])
			{
				tabList[i].getElementsByTagName("UL")[0].style.display = "none";
			}
		}
	}
	obj.parentNode.insertBefore(imgObj,obj);
	obj.parentNode.className += " on";
	if (obj.parentNode.getElementsByTagName("UL")[0])
	{
		obj.parentNode.getElementsByTagName("UL")[0].style.display = "block";
	}
}

function ResizeFrmTabView(th)
{
	var ifr = th;
	
	var innerBody = ifr.contentWindow.document.body;
	var innerHeight = innerBody.scrollHeight;
	var innerWidth = innerBody.scrollWidth;
	
	if(innerHeight < 300)
	    innerHeight = 300;
	
	ifr.style.height = innerHeight;
	ifr.style.width = innerWidth;
}

function FillFrmContent(th, val)
{
    th.contentWindow.document.body.innerHTML = JSDecode(val);
    
    setTimeout(function() {ResizeFrmTabView(th)}, 200);
}

String.prototype.trim = function() 
{
    return this.replace(/(^\s*)|(\s*$)/gi, "");
}

function RemoveEmpty(val, separator)
{
    var arrTemp = val.split(separator);
    var result = "";
    
    for(var i=0 ; i<arrTemp.length ; i++)
    {
        if(arrTemp[i].trim() != "")
        {
            if(result == "")
                result = arrTemp[i];
            else
                result += "," + arrTemp[i];
        }        
    }
    
    return result;
}

function ValueInControlName(conName)
{
    var obTemp = document.getElementsByName(conName);
    var result = "";
    
    if(obTemp)
    {   
        for(var i=0 ; i<obTemp.length ; i++)
        {
            if(obTemp[i].checked)
                result += obTemp[i].value + ",";
        }
    }
    
    return RemoveEmpty(result, ",");
}

function ValueInServerControlID(conID)
{   
    var obTemp = document.getElementById(conID + "_0");
    var result = "";
    
    for(var i = 0; obTemp != null; i++)
    {  
        obTemp = document.getElementById(conID + "_" + i);
        
        if(obTemp.checked)
            result += obTemp.value + ",";
    }
    
    return RemoveEmpty(result, ",");
}

/*
function AddRow()
{
	var tableID = "tblSelectGame";
	var table = document.getElementById(tableID);
	var cellLength = table.rows[0].cells.length;	
	var row = table.insertRow(table.rows.length);
	var now = new Date();
	row.id="rowIb_" + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getMilliseconds();
	
	var cel;
	
	var temp = "<input type='file' name='file1' size='50' style='border-width:1; border-color:rgb(204,204,204); border-style:solid;'> <a href=javascript:DeleteRow('" + row.id + "');><img align='absmiddle' src='../images/x.gif' width='15' height='9' border='0'></a>";

	cel = row.insertCell(0);
	//cel.bgColor="#ffffff";
	//cel.align="left";					
	cel.innerHTML = temp;
}

function DeleteRow(rowID)
{
	var tableID = "tblSelectGame";
	var table = document.all ? document.all[tableID] : document.getElementById(tableID);
	
	for(i=0 ; i<table.rows.length ; i++)
	{
		if ( table.rows[i].id == rowID )
		{
			table.deleteRow(i);
			return;
		}
	}
}
*/

function CheckByte(val)
{
	var code_byte = 0;

	for(var i = 0; i < val.length; i++)
	{
		var oneChar = escape(val.charAt(i));

		if(oneChar.length == 1)
			code_byte++;
		else if(oneChar.indexOf("%u") != -1)
			code_byte += 2;
		else if(oneChar.indexOf("%") != -1)
			code_byte += oneChar.length/3;
	}

	return code_byte;
}

function ViewDivProcess()
{    
	var bgDiv = document.getElementById("divAlpha");
	var targetDiv = document.getElementById("divProcess");	
	
	bgDiv.style.width = document.body.scrollWidth;
	bgDiv.style.height = document.body.scrollHeight;
	targetDiv.style.top = 400;
	targetDiv.style.left = document.body.scrollWidth/2 - 100;
	
	bgDiv.style.display = "block";
	targetDiv.style.display = "block";		
}
