//###################################################################
// 플래시 링크 함수
//###################################################################
function openURL(a) {
	if(a=="1"){
		targetUrl = "/news/index.daily";
	}else if(a=="2"){
		targetUrl = "/news/review/index.daily"; 
	}else if(a=="3"){
		targetUrl = "/news/report/index.daily"; 
	}else if(a=="4"){
		targetUrl = "/news/movie/list.daily?page=1&menu=40"; 
	}else if(a=="5"){
		targetUrl = "/gamedb/game_all_list.daily"; 
	}else if(a=="6"){
		targetUrl = "/free/index.daily"; 
	}

	document.location.href=targetUrl;
}


function ajaxRequest(div,actionfile,param) {
	var ajax		=	createXMLHttpRequest();
	ajax.open("POST",actionfile,false);
	ajax.setRequestHeader("content-type","application/x-www-form-urlencoded");
	ajax.send(param);

	if(ajax == null){
		alert("AJAX NOT SUPPORT.");
		history.back();
	}

	if(!div) return;
	document.getElementById(div).innerHTML	=	ajax.responseText;
	
	if(param.indexOf('cmt_recmd')!=-1){
		var textresponse = ajax.responseText;
		if(textresponse.indexOf("alreadyrecmd")!=-1){
			alert("이미 추천하셨습니다.");
		}else if(textresponse.indexOf("recmd-success")!=-1){
			alert("추천하셨습니다.");
		}
	}
	
	if(param.indexOf('cmt_accusation')!=-1){
		var textresponse = ajax.responseText;
		if(textresponse.indexOf("alreadyaccusation")!=-1){
			alert("이미 신고하셨습니다.");
		}else if(textresponse.indexOf("accusation-success")!=-1){
			alert("신고가 접수되었습니다.");
		}
	}
	
	if(param.indexOf('insert')!=-1){
		var textresponse = ajax.responseText;
		if(textresponse.indexOf("continuity")!=-1){
			alert("글을 연속으로 입력하실 수 없습니다.");
		}
	}
}

function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
		if (xmlHttp.overrideMimeType) {
			xmlHttp.overrideMimeType("text/xml");
		}
	}

	return xmlHttp;
}

/*
function startRequest(method,pURL,opendmode,sendmode,handleFunctionName) {
	try{
		xmlHttp = createXMLHttpRequest();
		xmlHttp.onreadystatechange = eval(handleFunctionName);
		xmlHttp.open(method, pURL, opendmode);
		xmlHttp.send(sendmode);
	}catch(e){
		//alert("startRequest " + e.discription);
	}
}
*/
function fn_layeropen_login(){
	window.open('/member/regist_01_agree.daily','main_login','left=100, top=100, width=550, height=550');
}
//###################################################################
// 리사이즈
// 웹2.0에 따른 if_Resize2() 업그레이드 버젼
// iframe 사이즈를 변경하는 방식이랑 외부의 margin이나 padding값에도 정확한 리사이징~
// 예) <iframe name="content" width="100%" onload="iframeResize(this)"></iframe>
//###################################################################
function iframeResize(ifrm) {
	try {
		ifrm.style.height	=	eval(ifrm.name).document.body.scrollHeight;
		document.body.scrollTop	=	0;
	} catch(ex) {
		error("아이프레임 셋팅 에러 -1");
	}
}

//###################################################################
// 플래시 뷰어 함수
//###################################################################
function  viewFlash(sDiv, sURL, sId, sCid, sWidth , sHeight, sAlign, sWmode, sBgcolor, sOrder){

	var codeBase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
	var pluginsPage = "application/x-shockwave-flash";
	var embedType = "application/x-shockwave-flash";
	var pluginsPage = "http://www.macromedia.com/go/getflashplayer";

	var flashHTML = "";
	flashHTML += "<OBJECT CLASSID=\""+ sCid +"\" CODEBASE=\""+ codeBase +"\" WIDTH=\""+ sWidth +"\" HEIGHT=\""+ sHeight +"\" ID=\"" + sId + "\" ALIGN=\"" + sAlign + "\">";
	flashHTML += "<PARAM NAME=\"movie\" VALUE=\"" + sURL + "\">";
	flashHTML += "<PARAM NAME=\"quality\" VALUE=\"high\">";
	flashHTML += "<PARAM NAME=\"allowScriptAccess\" VALUE=\"always\">";
	if(sWmode) flashHTML += "<PARAM NAME=\"wmode\" VALUE=\""+ sWmode + "\">";
	if(sBgcolor) flashHTML += "<PARAM NAME=\"bgcolor\" VALUE=\""+ sBgcolor + "\">";

	if(sOrder) {
		var arrayTemp = sOrder.split("|");
		var arrayOne;

		for (var i=0; i< arrayTemp.length ; i++)
		{
			if(arrayTemp[i]) {
				arrayOne = arrayTemp[i].split("=");


				if(arrayOne.length > 2) {
					var arrayValue = "";

					arrayValue += arrayTemp[i].replace(arrayOne[0] + "=","");
				}
				else {
					arrayValue = arrayOne[1];
				}

				flashHTML += "<PARAM NAME=\""+ arrayOne[0] + "\" VALUE=\""+ arrayValue + "\">";
			}
		}
	}
	flashHTML += "<EMBED SRC=\""+ sURL + "\" QUALITY=\"high\" WMODE=\"" + sWmode + "\" BGCOLOR=\"" + sBgcolor + "\"  WIDTH=\""+ sWidth +"\" HEIGHT=\""+ sHeight +"\" NAME=\"" + sId + "\" ALIGN=\"" + sAlign + "\"TYPE=\"" + embedType + "\" PLUGINSPAGE=\"" + pluginsPage + "\" />";
	flashHTML += "</OBJECT>";

	document.getElementById(sDiv).innerHTML = flashHTML;
}

//###################################################################
// 페이드 효과 주기..  페이드인 페이드 아웃
// 
// 예) opacity("이미지아이디",시작밝기(0),끝밝기(100),걸리는시간);
//###################################################################
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart  > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


//###################################################################
// textarea 글자수 제한하기
// 
// 예) <textarea row="5" col="5" name="gametalk" onkeyup="lenString(this,500);"></textarea>
//###################################################################
//글자수 제한하기
function lenString(areaName,lenMax){
	var ls_str = areaName.value; // 이벤트가 일어난 컨트롤의 value 값
	var li_str_len = ls_str.length; // 전체길이

	var li_max = lenMax; 
	var li_byte = 0; 
	var li_len = 0; 
	var ls_one_char = ""; 
	var ls_str2 = "";

	for(var i=0; i< li_str_len; i++){
		
		ls_one_char = ls_str.charAt(i);
		
		if (escape(ls_one_char).length > 4){
		
			li_byte += 2;
		
		} else{
		
			li_byte++;
		
		}
		
		if(li_byte <= li_max){
			
			li_len = i + 1;
		}
	}
	//제한글자수가 넘어가면 삭제
	if(li_byte > li_max) {
		ls_str2 = ls_str.substr(0, li_len);
		areaName.value = ls_str2;
		
	}
}


//###################################################################
//view 페이지 넓이보다 크면 지정 사이즈대로줄임
//
// 예) viewpage 에뿌려지는 이미지에 <img src="" name="target_resize_image[]">
// window.onload = function(){resizeImages(지정사이즈)}
// ajax 경우 resizeImages(지정사이즈) 뿌려주는 곳 위에
// 
//###################################################################

function resizeImages(imageWidth) {
	var target = document.getElementsByName('target_resize_image[]');
    var imageHeight = 0;
	if (target) {
        for(i=0; i<target.length; i++) {
            // 원래 사이즈를 저장해 놓는다
            target[i].tmp_width  = target[i].width;
            target[i].tmp_height = target[i].height;
            // 이미지 폭이 테이블 폭보다 크다면 테이블폭에 맞춘다
            if(target[i].width > imageWidth) {
                imageHeight = parseFloat(target[i].width / target[i].height)
                target[i].width = imageWidth;
                target[i].height = parseInt(imageWidth / imageHeight);

                // 스타일에 적용된 이미지의 폭과 높이를 삭제한다
                target[i].style.width = '';
                target[i].style.height = '';
            }
        }
    }
}


//###################################################################
// 원본사이즈 보기
//###################################################################
function viewRealSize(img){ 
 img1= new Image(); 
 img1.src=(img); 
  call(img); 
} 
function call(img){ 
  if((img1.width!=0)&&(img1.height!=0)){ 
    viewImg(img); 
  } else{ 
    funzione="call('"+img+"')"; 
    intervallo=setTimeout(funzione,0); 
  } 
} 
function viewImg(img){ 
  WinW=img1.width+0; 
 WinH=img1.height+0; 
  LeftPosition =0;
  TopPosition =0;
  options ="height="+WinH+",width="+WinW+",top="+TopPosition+",left="+LeftPosition+",";
  imgWin=window.open("","",options);
  imgWin.document.write("<html><head><title>::: www.dailygames.co.kr :::</title></head><body leftmargin=0 topmargin=0>");
  imgWin.document.write("<img style='cursor:pointer' src="+img+" onclick='self.close()'></body>");
}


//###################################################################
// 원하는 부분만 프린트하기 
// 사용법 : onclick="printArea();" 
// 원하는 영역아이디값<div id=idPrint></div>
//###################################################################
var initBody 
function beforePrint(){ 
	initBody = document.body.innerHTML; 
	document.body.innerHTML = idPrint.innerHTML; 
}
function afterPrint(){ 
	document.body.innerHTML = initBody; 
}

function printArea() { 
	window.print(); 
}

window.onbeforeprint = beforePrint; 
window.onafterprint = afterPrint; 


//###################################################################
// 이미지팝업 레이어팝업
//###################################################################
function imgLayerPopup(mode){
	if(mode == 'view'){
		document.getElementById('viewImgLayer').style.display = "";
	} else {
		document.getElementById('viewImgLayer').style.display = "none";
	}
}


//###################################################################
// 클립보드복사
//###################################################################
function urlCopy (address) { 
	if (window.clipboardData) { 
		window.clipboardData.setData('Text', address); 
	} 
	else if (window.netscape) { 
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 
		if (!clip) return; 
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); 
		if (!trans) return; trans.addDataFlavor('text/unicode'); 
		var str = new Object(); 
		var len = new Object(); 
		var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString); 
		var copytext = address; str.data = copytext; trans.setTransferData('text/unicode',str,copytext.length*2); 
		var clipid = Components.interfaces.nsIClipboard; 
		if (!clipid) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard); 
	} 
	alert('주소가 복사되었습니다.'); 
	return false;
} 
/*
function ad_refresh-test(id, src) {
  var script = document.createElement('script');
  script.type = 'text/javascript'; 
  script.src = src;

  var div = document.getElementById(id);

  alert(div.innerHTML);

  div.innerHTML = '';
  div.appendChild(script);

//  setTimeout("ad_refresh('" + id + "', '" + src + "')", 1500);
//  document.getElementsByTagName('head')[0].appendChild(script);  
}
*/