﻿//document.oncontextmenu=new Function("return false")


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_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_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function setTextBox()
{    
    document.getElementById('txtUserID').style.backgroundImage = document.getElementById('txtUserID').value == '' ? "url('http://img.karma2.co.kr/img/img_common/login_id.gif')" : ''
    document.getElementById('txtPasswd').style.backgroundImage = document.getElementById('txtPasswd').value == '' ? "url('http://img.karma2.co.kr/img/img_common/login_pw.gif')" : ''
}

//function trim(str) 
//{
//	var count = str.length;
//	var len = count;                
//	var st = 0;

//	while ((st < len) && (str.charAt(st) <= ' ')) 
//		st++;

//	while ((st < len) && (str.charAt(len - 1) <= ' ')) 
//		len--;

//	return ((st > 0) || (len < count)) ? str.substring(st, len) : str ;
//}
function trim(str) {
    return str.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

/**** 문자열 공백 제거 ****/
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

//자릿수체크 하여 맞으면 다음으로 포커스 이동
function len_check( val1, len, val2 )
{    
	var obj
	if ( val1.value.length == len ) 
	{      
		obj = eval(val2);
		obj.focus();
		return;
    }
}

function checkObject(object,message)
{
	if( !trim(object.value) )
	{
		alert( message );
		object.value = "";
		object.focus();
		return false;
	}
	return true;	
}

function containsChars(input,chars) 
{
    for (var inx = 0; inx < input.length; inx++) 
    {
       if (chars.indexOf(input.charAt(inx)) != -1)
           return true;
    }
    return false;
}

function containsCharsOnly(input,chars) 
{
	for (var inx = 0; inx < input.length; inx++) 
	{
		if (chars.indexOf(input.charAt(inx)) == -1)
			return false;
	}
	return true;
}

function isValidEmail(input) {
    //var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
    var format = /^[0-9a-z]([-_\.]?[0-9a-z])*@[0-9a-z]([-_\.]?[0-9a-z])*\.[a-z]{2,3}$/;
    if (input.search(format) != -1) {
        return true; //올바른 포맷 형식
    }
    return false;
}

function isNumDash(input) 
{
	var chars = "0123456789-";
	return containsCharsOnly(input,chars);
}

function isAlphabet(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);
}

function isAlphabetNum(input) {
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    return containsCharsOnly(input,chars);
}

function isNumber(input) {
    var chars = "0123456789";
    return containsCharsOnly(input,chars);
}

function isOKChar(input) {
    var chars = "<>;' ";
    return containsChars(input,chars);
}

function openPopCenter( url, wname, sizeW, sizeH )
{
	var nLeft  = screen.width/3;
	var nTop  = screen.height/3;
 
	opt = ",toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
	openobj = window.open(url, wname, "left=" + nLeft + ",top=" +  nTop + ",width=" + sizeW + ",height=" + sizeH  + opt );
	openobj.focus()
}

function openPop( url, wname, sizeW, sizeH )
{
	opt = ",toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
	openobj = window.open(url, wname, "left=10,top=10,width=" + sizeW + ",height=" + sizeH  + opt );
	openobj.focus()
}

function countString(str){
	var sum=0;
	for(i=0;i<str.length;i++){
		if(str.charCodeAt(i)<200){
			sum+=1;//영어나 숫자들일때..
		}
		else{
			sum+=2;//한글이나 특수문자 들일때..
		}
	}
	return sum;	
}

function view_photo(img_url) {
    return;
	window.open("/lib/editbox/imgViewer.asp?img=" + img_url, "photo", "toolbar=no, location=no, directories=no,status=no, menubar=no, scrollbars=no, resizable=yes");
}

function CheckLogin()
{
    if( document.getElementById('hLValue').value != "true" ){
        alert('로그인 후 이용해주세요');
		document.getElementById('txtUserID').focus();
		return false;
    }
}

// 로그인 체크후 팝업으로 오픈
function CheckLoginPop( url, locX, locY )
{	
	if( document.getElementById('hLValue').value == "true" ){
		var nLeft  = 10;
		var nTop  = 10;
		
		if( screen.width <= 1024 )
	        nTop = 10;
 
		opt = ",toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
		
		try{
		openobj = window.open(url, 'openpop', "left=" + nLeft + ",top=" +  nTop + ",width=200,height=200" + opt );
		openobj.focus()
		}
		catch(e){ alert('팝업이 차단되어 있습니다. 팝업 차단 해제 후 이용해 주세요.') }
	}
	else{
		alert('로그인 후 이용해주세요');
		try{document.getElementById('txtUserID').focus();}
		catch(e){location.href="http://www.fpscamp.com/Login/Login.aspx?retUrl=" + location.href }
		return false;
	}
}

// 로그인 체크(부모창)후 팝업으로 오픈
function CheckPLoginPop( url, locX, locY )
{	
	if( parent.document.getElementById('hLValue').value == "true" ){
		var nLeft  = screen.width/3;
		var nTop  = screen.height/3;
		
		if( screen.width <= 1024 )
	        nTop = 10;
 
		opt = ",toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
		openobj = window.open(url, 'openpop', "left=" + nLeft + ",top=" +  nTop + ",width=0,height=0" + opt );
		openobj.focus()
	}
	else{
		alert('로그인 후 이용해주세요');
		document.getElementById('txtUserID').focus();
		return false;
	}
}

// 로그인 체크후 관련 url로
function CheckLoginURL( url, locX, locY )
{	
	if( document.getElementById('hLValue').value == "true" ){
		location.href = url;	
	}
	else{	    	    
		alert('로그인 후 이용해주세요');
		try{document.getElementById('txtUserID').focus();}
		catch(e){location.href = "http://www.fpscamp.com/Login/Login.aspx?retUrl=" + url;}
		return;
	}
}

function OpenLoginPop( locX, locY )
{
	var IE = document.all?true:false;

	try{
			if (IE) { 
				tempX = event.clientX + document.body.scrollLeft;
				tempY = event.clientY + document.body.scrollTop;
			}
			else {  
				tempX = e.pageX;
				tempY = e.pageY;
			}  
			if (tempX < 0){tempX = 0;}
			if (tempY < 0){tempY = 0;}
			
			document.getElementById('ifrmLayer').style.left = tempX;
			document.getElementById('ifrmLayer').style.top = tempY-100;
	}
	catch(e){
			var tempX  = screen.width/3;
			var tempY  = screen.height/3;
			
			document.getElementById('ifrmLayer').style.left = tempX;
			document.getElementById('ifrmLayer').style.top = tempY;
	}
	
	if( locX != 0 )	document.getElementById('ifrmLayer').style.left = locX;		// 좌표값이 존재하면 죄표값으로 셋팅
	if( locY != 0 )	document.getElementById('ifrmLayer').style.top = locY;		// 좌표값이 존재하면 죄표값으로 셋팅
	
	document.getElementById('ifrmPop').src = "/Main/Login/LoginPop.aspx";
	
	document.getElementById('ifrmLayer').style.visibility = "visible"
	
	return;
}

// 레이어 팝업( iframe ) 닫기
function ifrmLayerClose()
{
	parent.ifrmLayer.style.visibility = 'hidden'
}

// 창 크기 조절
function WinResize()
{
	var Dwidth = parseInt(document.body.scrollWidth);
	var Dheight = parseInt(document.body.scrollHeight);
	var divEl = document.createElement("div");
	divEl.style.position = "absolute";
	divEl.style.left = "0px";
	divEl.style.top = "0px";
	divEl.style.width = "100%";
	divEl.style.height = "100%";

	document.body.appendChild(divEl);
	while(1)
	{
	    try{window.resizeBy(Dwidth-divEl.offsetWidth, Dheight-divEl.offsetHeight);break;}
	    catch(e){}
	}
	//window.resizeBy(Dwidth-divEl.offsetWidth, Dheight-divEl.offsetHeight);
	document.body.removeChild(divEl);	
}

// Opener 가 존재하면 타겟이 Opener, 그렇지 않으면 새창
function CheckOpener( url )
{
	try{
		opener.location.href = url;
		opener.focus();
	}
	catch(e){
		var obj = window.open( url, '_blank', '' )
		obj.focus();	
	}	
}

// 레이어 창 닫기
function Close_layer( objLayer ){
	objLayer.style.display = 'none';
}

// 레이어 숨기기/열기
function TogleLayer( obj )
{
	if (obj.style.visibility == "hidden")
		obj.style.visibility = "visible";
	else
		obj.style.visibility = "hidden";
}


// a 링크 및 input type image 에 blur
//function allblur() {
//	//var inputs = document.getElementsByTagName("input");
//	var alinks = document.links;
//	var tmp = []; var j = 0;
//	
//    /*
//	for(i = 0; i < inputs.length; i ++) {
//		if(inputs[i].type != "image") continue;
//		tmp[j] = inputs[i];
//		j ++;
//	}
//	inputs = tmp;
//    */
//	//for(i = 0; i < inputs.length; i ++) inputs[i].onfocus = function() { this.blur(); }
//	
//	for(i = 0; i < alinks.length; i ++) alinks[i].onfocus = function() { this.blur(); }
//}
//window.onload=allblur

////////////////////////// 게 임 시 작 버 튼 //////////////////////////

var ing = 0;

function RunGameStart(){
    
    if (ing == 1)        
        return false;       

    ing = 1;
        
    try{
        if( document.getElementById('hLValue').value != "true" ){
            ing = 0;
            alert('로그인 후 이용해주세요');
		    document.getElementById('txtUserID').focus();		    
		    return false;
        }
    }
    catch(ex){ 
        ing = 0;
        return false; 
    }    	    
    
    var gameObjectId = document.all ? "dragonfly_activex" : "npdragonfly";
    
    var Installed = false;                
    if (document.all) 
    { 
	    try 
        {
            Installed = jQuery("#" + gameObjectId)[0].ErrMsg ? true : false;
            
            if (!Installed) 
            { 
                alert("게임 실행을 위해 ActiveX Control을 설치하신 후 이용해 주세요.");  
                top.location.href = "http://www.fpscamp.com/Activex/activex_install.aspx?site=k2";  
                return false;
            }
        }
        catch(e){ 
            alert("게임 실행을 위해 ActiveX Control을 설치하신 후 이용해 주세요.");  
            top.location.href = "http://www.fpscamp.com/Activex/activex_install.aspx?site=k2";  
            return false;              
        }
    }
    else 
    { 
        try 
        {
            Installed = jQuery("#" + gameObjectId)[0].ver.constructor === Number ? true : false;
            
            if (!Installed) 
            { 
                alert("게임 실행을 위해 Plugin을 설치하신 후 이용해 주세요.");  
                return false;  
            }
        }
        catch(e){ 
            alert("게임 실행을 위해 Plugin을 설치하신 후 이용해 주세요.");  
            return false;               
        }
    }	
	
	if( Installed ){ // 설치된경우
	    try{
		    frames['ifrmTake'].location.href= "/Main/GameOn/GameStart.aspx";		 
		}
		catch(ex){
		    //alert(ex.message)
		    //location.reload();
		    ing = 0;
		    return false;
		}
	} 
	else
	{
	    top.location.href = "http://www.fpscamp.com/Activex/activex_install.aspx?site=k2";	    
	}
}


function RunGameStart2() {

//    alert('BATTLE SERVER OPEN : 05/01/2010 14:00 ~');
//    return;

    try {
        if (document.getElementById('hLValue').value != "true") {
            alert('After login use');
            document.getElementById('txtUserID').focus();
            return false;
        }
    }
    catch (ex) {
        return false;
    }

    var Installed = false;
    try {
        var xObj = new ActiveXObject("DragonflyControl.DragonflyCtrl.1");

        if (xObj)
            Installed = true;
    }
    catch (ex) {
        alert('ActiveX was not Installed');
        //location.href = '/Main/HomeMain.aspx';
        return;
    }

    if (Installed) { // 설치된경우
        try {
            frames['ifrmTake'].location.href = "/Main/GameOn/GlobalGameStart.aspx";
        }
        catch (ex) {
            //alert(ex.message)
            //location.reload();
        }
    }
    else {
        alert('ActiveX was not Installed');
        //location.href = '/Main/HomeMain.aspx';
        return;
    }
}

function RunGameStart3() {

    //    alert('BATTLE SERVER OPEN : 05/01/2010 14:00 ~');
    //    return;    
    try {
        if (document.getElementById('hLValue').value != "true") {
            alert('로그인 후 이용해주세요');
            document.getElementById('txtUserID').focus();
            return false;
        }
    }
    catch (ex) {        
        return false;
    }

    
    
    var Installed = false;
    try {
        var xObj = new ActiveXObject("DragonflyControl.DragonflyCtrl.1");
        
        if (xObj)
            Installed = true;
    }
    catch (ex) {
        alert('ActiveX가 설치되지 않았습니다.');
        //location.href = '/Main/HomeMain.aspx';
        return;
    }

    if (Installed) { // 설치된경우
        try {
            frames['ifrmTake'].location.href = "/Main/GameOn/KarmaOnlineStart.aspx";
        }
        catch (ex) {
            alert(ex.message)
            //location.reload();
        }        
    }
    else {
        alert('ActiveX가 설치되지 않았습니다.');
        //location.href = '/Main/HomeMain.aspx';
        return;
    }
}

function RunGameStart4() {
    
    try {
        if (document.getElementById('hLValue').value != "true") {
            alert('로그인 후 이용해주세요');
            document.getElementById('txtUserID').focus();
            return false;
        }
    }
    catch (ex) {
        return false;
    }

    var Installed = false;
    try {
        var xObj = new ActiveXObject("DragonflyControl.DragonflyCtrl.1");

        if (xObj)
            Installed = true;
    }
    catch (ex) {
        alert('ActiveX가 설치되지 않았습니다.');
        //location.href = '/Main/HomeMain.aspx';
        return;
    }

    if (Installed) { // 설치된경우
        try {
            frames['ifrmTake'].location.href = "/Main/GameOn/KarmaReturnsStart.aspx";
        }
        catch (ex) {
            alert(ex.message)
            //location.reload();
        }
    }
    else {
        alert('ActiveX가 설치되지 않았습니다.');
        //location.href = '/Main/HomeMain.aspx';
        return;
    }
}

document.write("<META http-equiv='Page-Enter' content='blendTrans(Duration=0.1)'>")
document.write("<META http-equiv='Page-Exit' content='blendTrans(Duration=0.1)'>")

// 쿠키 설정
function SetCookie( name, value, expiredays )
{
	var todayDate = new Date();
	todayDate.setHours( todayDate.getHours() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// 쿠키 불러오기
function GetCookie(name){
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

