//----------------- Const------------------------>
var BOQ_GAMECARD_NAME = "ONE Game";
//----------------- Const------------------------>
function init_select(objSel,val) {          //SelectBox ÇØ´ç º§·ù¼±ÅÃ µÇ¾îÁö°Ô..
    f = objSel;    
	for(i=0;i<f.options.length;i++) {
		if( f.options[i].value== val) {						
			f.selectedIndex = i;
		}				
	}
}

function AlphaNumericField(str)
{        
    
    for(var i=0;i<str.length;i++)
    {
        if (str.charCodeAt(i) > 128)
        {           
            return false;
        }
    }

    var strChk = "`~!@#$%^&*+|=\;:'/.,<>?";
 
    for(i=0;i<str.length;i++)
    {
        if(strChk.indexOf(str.substring(i,i+1)) >= 0)
        {           
            return false;
        }
    }
    
    return;
}

function AlphaField(str)
{        
    
    for(var i=0;i<str.length;i++)
    {
        if (str.charCodeAt(i) < 65 || str.charCodeAt(i) > 122 )
        {           
            return false;
        }
    }

    var strChk = "`~!@#$%^&*+|=\;:'/.,<>?";
 
    for(i=0;i<str.length;i++)
    {
        if(strChk.indexOf(str.substring(i,i+1)) >= 0)
        {           
            return false;
        }
    }
    
    return;
}

//onKeyup event 
function OnlyNum(obj)
{
	if(!NumField(obj.value ))
	{
		alert("You should typed number");		
		obj.value = obj.value.substring( 0, obj.value.length -1 );
		return false;
	}
}

function OnlyDoubleNum(obj)
{
    if(!doubleNumField(obj.value))
    {
        alert("You should typed number");
        return false;
    }
    
    return true;
}

//javascript chk event
function NumField(str)
{   
    if(str == "")
        str = 0; 
        
    var regExp;
    
    str = RemoveSpace( str );
    
    regExp = /[0-9]+/;

    if ( str.length > 0 )
    {
         if ( str.match(regExp) != str )
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}


function doubleNumField(str)
{
    var strChk = "0123456789.";
    
    str = encodeURI(str);

    for(i=0; i<str.length; i++)
    {
        if(strChk.indexOf(str.substring(i,i+1)) < 0)
        {          
            return false;
        }
    }
    
    return true;
}

function EmailChk(str)
{   
    var regExp;
    str = RemoveSpace( str );

    if(str.length > 0)
    {
        regExp =  /[a-zA-Z0-9.]{2,}@[a-zA-Z0-9-]{2,}\.[a-zA-Z0-9]{2,}/;

        if(str.match(regExp) == str)
        {
           return true;
        }
    }
    
    return false;
    
}

function IPchk(str)
{
    var regExp;

    regExp =  /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/

    
    if(str.match(regExp) != str)
    {
       return false;
    }
}

function showConfirm(msg)
{
    return  confirm(msg);
    
}

function OpenWindow(url, boxname, width, height , scrollbars)
{
    if ( !scrollbars ) scrollbars = "no";
    
	var winLeft = (screen.width - width) / 2;
    var winTop = (screen.height - height) / 2;
    var winProps = "width="+width+",height="+height+",top="+winTop+",left="+winLeft+",scrollbars=" + scrollbars + ",resize=yes";

    var win = window.open(url,boxname,winProps);
    win.focus();
}

function CloseWindow()
{
    if( confirm("Would you like to close the window?") ) {
        self.close();
    }
}
function ConfirmMsg(msg)
{
	//var WinAttr = "toolbar=NO;center=yes;scrollbars=NO;status=NO;dialogwidth="+width+"px;dialogheight="+height+"px";    
    /*
    if ( typeof showModalDialog == "object" ) 
        retval= window.showModalDialog("/Lib/ConfirmMsg.asp?msg="+msg,"confirmmsg", WinAttr);  
    else 
        retval = window.confirm(msg);    
    */
    retval = window.confirm(msg);    
	return retval;
}

function AlertMsg(msg)
{
    /*
	var WinAttr = "toolbar=NO;center=yes;scrollbars=NO;status=NO;dialogwidth="+width+"px;dialogheight="+height+"px";
    if ( typeof showModalDialog == "object" ) {
	    retval=window.showModalDialog("/Lib/AlertMsg.aspx?msg="+msg,"confirmmsg", WinAttr);

    	return retval;
    }
    else 
        alert(msg);
    */
    ShowAlertMessage(msg);
}


function ShowAlertMessage(msg ) 
{    
   //alert( msg );   
  
   //For ONE Only!!
   var szHTML = "<table width='100%' height='100%' style='margin-top:-10px'><tr><td align='center' valign='center' style='font:normal 12px Tahoma'>"+msg+"</td></tr></table>";
   iBox.fade_in_speed = 50;
   iBox.fade_out_speed = 50;
   iBox.show(szHTML,'',{width:300,height:50});
   //return false;
}

function ShowAlertMessage2(msg ) {    
    
    ShowAlertMessage( msg );
    
    if ( opener.goPage ) opener.goPage(1); 
    else
    {
        if ( opener ) { opener.location.reload()}
    }

    this.close();
}

function SetDate(cond, val)
{
    var f = document.forms['aspnetForm'];
    if (!f)
    {
        f = document.aspnetForm;
    }
    
    with (f)
    {
        fromymd.value = MakeDate(cond, val);
        toymd.value = MakeDate("d", "0");
    }
}

function Register( type )
{
    switch(type)
    {   
        case('Administrator'):
            OpenWindow( '/Admin/AdminUpd.aspx' , type , 560, 660, 1);
        break;
                
        default:
        
    }
}

function EditAdminInfo( adminid )
{
    OpenWindow('/Admin/AdminUpd.aspx?adminid='+adminid,'EditAdminInfo',560,660 , 1);
}

// Authority  Part ---------------------------------------->
function MenuAccess( adminid )
{
    OpenWindow('/Admin/AdminMenuAccessUpd.aspx?adminid='+adminid,'menuaccess',500,600 , 1);
}

function ChangeAuthority( objReg , objAuth)
{
    objAuth = document.getElementById( objAuth);
    
    if ( objReg.selectedIndex != 1 )
    {
        objAuth.disabled = true;
        objAuth.selectedIndex = 0;        
    }
    else 
    {
        objAuth.disabled = false;
        objAuth.selectedIndex = 1;
    }
        
}

function ShowHideGridView( Show_objID , Hide_objID )
{
    
    showObj = document.getElementById( Show_objID );
    hideObj = document.getElementById( Hide_objID );

    showObj.style.display = "block";
    hideObj.style.display = "none";
}

function EditRoleMenu( menuroleid ) 
{
    OpenWindow('/Admin/AdminMenuRoleUpd.aspx?menuroleid='+menuroleid,'menuroleupd',500,600 , 1);
}

// Authority  Part ---------------------------------------->

function RemoveSpace(str)
{
  str += '';  // ¼ýÀÚ¶óµµ ¹®ÀÚ¿­·Î º¯È¯
  return str.replace(/^\s*|\s*$/g, '');  
}

function FixedBottom() {

    var oDoc = document[document.compatMode == 'CSS1Compat' ? 'documentElement' : 'body'];
    
    if (/Opera|Safari/.test(navigator.userAgent)) oDoc = document.body;
    
    if (oDoc.scrollHeight > oDoc.clientHeight )
    {
        document.getElementById("bottom").style.top = oDoc.scrollHeight + "px";
        
    }
    else
    {
        document.getElementById("bottom").style.top =oDoc.clientHeight + "px";  
    }
    
    document.getElementById("bottom").style.display = "block";

}


function MoneyFormat(str)
{
    str = String(str);
    
	var newStr = "";
	var strLen   = str.length;
	
	var commCnt  = parseInt(((strLen - 1) / 3),10);
	var fCnt = strLen % 3;
	if (fCnt == 0 )	fCnt = 3;	
	for(var i = 0, lidx = 0; i <= commCnt; i++ )
	{
		fidx = lidx;
		lidx = fCnt + (i * 3);
		
		if (newStr.length > 0)	newStr = newStr + ",";
		newStr = newStr + str.substring(fidx, lidx);
	}
	return newStr;
}


var isResizeWin = true;

function auto_sizeup()
{
    if ( isResizeWin == false ) return;

    var elm = document.getElementById('resize_formtag');
        elm.style.width = 'auto';
        elm.style.height = 'auto';
    
    x = ( elm.offsetWidth < 426 ? 450  : elm.offsetWidth  );
    y = ( elm.offsetHeight < 320 ? 320 : elm.offsetHeight  );
        
    if(window.navigator.userAgent.indexOf("MSIE") > 0 )
    {   
        window.resizeTo(x+10,y+90);
    }
    else
    {
        window.resizeTo(x+8,y+90);
    }
}

//³¯Â¥ Ã¼Å©
function chkExpdate(str)//str : YYYYMMDD
{
    var expdate, intYear, intMonth, intDay;
    
    expdate = str;
    intYear = parseInt(expdate.substr(0,4),10);
    intMonth = parseInt(expdate.substr(4,2),10);
    intDay = parseInt(expdate.substr(6,2),10);
    
    if (intYear < 2006 || intYear > 9999)
        return false;
        
    if (intMonth > 12)
        return false;
        
    if (intMonth == 2)
    {
        if (intYear % 4 == 0  && (intYear % 100 != 0 || intYear % 400 == 0))
        {
            if (intDay > 29)
                return false;
        }
        else 
        {
            if (intDay > 28)
                return false;
        }
    }
    else if (intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12)
    {
        if (intDay > 31)
            return false;
    }
    else
    {
        if (intDay > 30)
            return false;
    }
    
    return true;
}

function RemoveAnchorDot()
{
    var obj = document.getElementsByTagName("A");
    
    for ( i=0; i < obj.length; i++)
    {
        obj[i].onfocus = function() {this.blur(); }
    }    
}

function ViewImage(srcName)
{
    var img = new Image();
    img.src = srcName;
    setTimeout( '', 100);
    w = img.width;
    h = img.height;

if (w==0) w=800

    var html = ''
    html = "<html><body style='margin:0'><img src='" + srcName+"' onclick='self.close()' style='cursot:pointer' /></body></html>";

    var objWin =  window.open( '','imgview', 'width='+w +',height=' + h + ',scrollbars=no');

    objWin.document.open();
    objWin.document.write(html);
    objWin.document.close();

    objWin.focus();

}

