function embed_flash(x,y,src) {
    var host = (("https" == document.location.protocol) ? "https://" : "http://");
    var s = "";
    s = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
    s+= ' codebase="' + host + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"';
    s+= ' width="'+x+'" height="'+y+'">';
    s+= '<param name="allowScriptAccess" value="always" />';
    s+= '<param name="allowFullScreen" value="false" />';
    s+= '<param name="movie" value="'+src+'" />';
    s+= '<param name="quality" value="high" />';
    s+= '<param name="menu" value="false" />';
    s+= '<param name="bgcolor" value="transparent" />';
    s+= '<param name="wmode" value="transparent" />';
    s+= '<embed src="'+src+'" quality="high" pluginspage="' + host + 'www.macromedia.com/go/getflashplayer"';
    s+= ' type="application/x-shockwave-flash" width="'+x+'" height="'+y+'" wmode="transparent" menu="false" bgcolor="transparent" style="margin:0px" allowScriptAccess="always"/>';
    s+= '</object>';
    document.write(s);
}

function popup_event()
{
	//document.domain = "www.callofchaos.com";
	var win = window.open('./_event_member.php','popup', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no, resizable=no,width=301,height=200'); 
	//win.focus(); 
}

function chkNumKey()
{
	if( (event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) )
		event.returnValue = true
	else if( event.keyCode == 8 || event.keyCode == 9 ) // BS, TAB
		event.returnValue = true
	else if( event.keyCode == 16 || event.keyCode == 46 ) // SHIFT, DELETE
		event.returnValue = true
	else if( event.keyCode == 39 || event.keyCode == 37 ) //arrow key
		event.returnValue = true
	else if( event.keyCode == 109 ) //subtack
		event.returnValue = true
	else
		event.returnValue = false
}

var auto_focus = true;
var prev_value = null;
function next_input( obj, next_id )
{
    if ( obj.value.length >= 6 )
    {
        if ( auto_focus == true || obj.value != prev_value)
        {
            auto_focus = false;
            prev_value = obj.value;
            document.getElementById(next_id).focus();
        }
        return;
    } 
    auto_focus = true;
}

function popup_beginner_guide()
{
    var w = 800; 
    var h = 600;
    var pos_left = (screen.width) ? (screen.width-w)/2 : 0; 
    var pos_top = (screen.height) ? (screen.height-h)/2 : 0; 
    var option = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+w+',height='+h+',top='+pos_top+',left='+pos_left; 
    
    var win = window.open('guide/index.html','popup',option); 
}

function cc_manual_download()
{
    location.href = "?m=download&a=game";
}

function cc_easy_guide()
{
    popup_beginner_guide();
}
function cc_npds()
{
    $.modal($('#modal_npds'), {
      overlayCss: {
        backgroundColor: '#000', cursor: 'wait'
      },
      containerCss: {
        height: 490, width: 510, backgroundColor: '#000', border: '1px solid #ccc'
      }
    });
}

function desc_npds( flag )
{
    if( flag ) $('#modal_desc_npds').show();
    else $('#modal_desc_npds').hide();
}

var goSearch = function() {

    if ( $.trim($("#keyword").val()) == "" )
    {
		alert('검색어를 입력해 주세요.');
		return false;
	}

    if ( $('#keyword').length > 10 )
    {
		alert('검색어를 10byte 보다 작은 길이로 입력해 주세요.');
		return false;
	}

	return true;
}

function trim(str) {
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function changebg_id( op, obj) {
    if( op )
        $("#input_id").css("background-position","0px 0px");
    else
    {
        if( trim(obj.value) == '' )
            $("#input_id").css("background-position","0px -30px");
    }
}

function changebg_pw( op, obj) {
    if( op )
        $("#input_pw").css("background-position","0px 0px");
    else
    {
        if( trim(obj.value) == '' )
            $("#input_pw").css("background-position","0px -60px");
    }
}

function logincheck() {
    if( trim( $("#input_id").val() ) === '' ) {
        alert("아이디를 입력해 주세요.");
        $("#input_id").focus();
        return false;
    }
    if( trim( $("#input_pw").val() ) === '' ) {
        alert("비밀번호를 입력해 주세요.");
        $("#input_pw").focus();
        return false;
    }
    return true;
}

jQuery(function($){
	
	// Common
	var select_root = $('div.select');
	var select_value = $('.myValue');
	var select_a = $('div.select>ul>li>a');
	var select_input = $('div.select>ul>li>input[type=radio]');
	var select_label = $('div.select>ul>li>label');
	
	// Radio Default Value
	$('div.myValue').each(function(){
		var default_value = $(this).next('.iList').find('input[checked]').next('label').text();
		$(this).append(default_value);
        $(this).addClass('selected');
		$(this).next('.iList').find('input[checked]').parents('li:first').addClass('checked');
	});
	
	// Line
	select_value.bind('focusin',function(){$(this).addClass('outLine');});
	select_value.bind('focusout',function(){$(this).removeClass('outLine');});
	select_input.bind('focusin',function(){$(this).parents('div.select').children('div.myValue').addClass('outLine');});
	select_input.bind('focusout',function(){$(this).parents('div.select').children('div.myValue').removeClass('outLine');});
	
	// Show
	function show_option(){
		$(this).parents('div.select:first').toggleClass('open');
	}
	
	// Hover
	function i_hover(){
		$(this).parents('ul:first').children('li').removeClass('hover');
		$(this).parents('li:first').toggleClass('hover');
	}
	
	// Hide
	function hide_option(){
		var t = $(this);
		setTimeout(function(){
			t.parents('div.select:first').removeClass('open');
		}, 1);
	}
	
	// Set Input
	function set_label(){
		var v = $(this).next('label').text();
		$(this).parents('ul:first').prev('.myValue').text('').append(v);
		$(this).parents('ul:first').prev('.myValue').addClass('selected');
	}
	
	// Set Anchor
	function set_anchor(){
		var v = $(this).text();
		$(this).parents('ul:first').prev('.myValue').text('').append(v);
		$(this).parents('ul:first').prev('.myValue').addClass('selected');
	}

	// Anchor Focus Out
	$('*:not("div.select a")').focus(function(){
		$('.aList').parent('.select').removeClass('open');
	});
	
	select_value.click(show_option);
	select_root.removeClass('open');
	select_root.mouseleave(function(){$(this).removeClass('open');});
	select_a.click(set_anchor).click(hide_option).focus(i_hover).hover(i_hover);
	select_input.change(set_label).focus(set_label);
	select_label.hover(i_hover).click(hide_option);
	
	// Form Reset
	$('input[type="reset"], button[type="reset"]').click(function(){
		$(this).parents('form:first').find('.myValue').each(function(){
			var origin = $(this).next('ul:first').find('li:first label').text();
			$(this).text(origin).removeClass('selected');
		});
	});
	
});


