// DOM Ready 상태에서의 처리 - window.onload 보다 효율적임
/*jQuery(document).ready(function(){
	document.title = "워해머 온라인 : 심판의 시대";
	jQuery("#main_top,#container").pngFix();
	jQuery("#main_top,#container").css("visibility","visible");
	jQuery("#Journals h2:first-child").addClass("ex");
	jQuery("#RecentNews,#Journals").idTabs("!mouseover");
});*/

document.title = "워해머 온라인 : 심판의 시대";

//Active X 비활성화 대응 : 플래시
function flash(a,b,c,d) {
 var flash_tag = "";
 flash_tag = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
 flash_tag +='codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ';
 flash_tag +='WIDTH="'+a+'" HEIGHT="'+b+'"  id="'+d+'">';
 flash_tag +='<param name="movie" value="'+c+'">';
 flash_tag +='<param name="quality" value="high">';
 flash_tag +='<param name="wmode" value="transparent">';//플래시 배경 투명 설정
 flash_tag +='<param name="wmode" value="opaque">';//플래시 배경 z-index 설정
 flash_tag +='<embed src="'+c+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
 flash_tag +='type="application/x-shockwave-flash"  WIDTH="'+a+'" HEIGHT="'+b+'"></embed></object>'
 document.write(flash_tag);
}


function checkPattern(sType, str)	//형식 체크
{
	var	pattern	=	new	String() ;
	switch (sType){
		case "NUM" :	// 숫자만
			pattern	=/^[0-9]+$/;
			break;
		case "PHONE" :
			pattern	=/^[0-9]{2,4}-[0-9]{3,4}-[0-9]{4}$/;										 //전화번호	형식 : 033-1234-5678
			break;
		case "EMAIL" :
			pattern	=/^[_a-zA-Z\d\-\.]+@([_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+)/;						//메일
			break;
		case "DOMAIN"	:
			pattern	=/^[.a-zA-Z0-9-]+.[a-zA-Z]+$/; ///영자 숫자와	.	다음도 영자
			break;
		case "ENG" : //영자만
			pattern	=/^[a-zA-Z]+$/;
			break;
		case "ENGNUM"	:	//영자와 숫자
			pattern	=/^[a-zA-Z0-9]+$/;
			break;
		case "HAN" : //	한글만
			pattern	=/^[가-힣]*$/;
			break;
		case "USERID"	:	//첫글자는 영자	그뒤엔 영어숫자	4이상	15자리 이하
			pattern	=/^[a-zA-Z]{1}[a-zA-Z0-9_-]{4,15}$/;
			break;
		case "DATE"	:	// 날짜	:	2002-08-15
			pattern	=/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
			break;
		case "PASS"	:	// 날짜	:	2002-08-15
			pattern	=/^[;:`~!@#$%\^&*\(\)_a-zA-Z0-9-]{4,15}$/;
			break;
		default :
		  return false;
		  break;
	}

	//alert(str	+	"|"	+	pattern);

	if(!pattern.test(str)){
			return false;
	}
	return true;
}

//숫자만 눌리게	하기 , 방향키	+	Delele + BackSpace 포함
function onlynum() {
	var	iCode	=	event.keyCode;
	if(!(	((iCode	>= 48) &&	(iCode <=	57)) || ((iCode	>= 96) &&	(iCode <=	105)) || ((iCode	>= 37) &&	(iCode <=	40)) ||	(iCode ==	8	)	|| (iCode	== 46	)||	(iCode ==	9	)	)) {
		alert("숫자만 입력할 수 있습니다.");
		event.returnValue = false;
	}
}

//글자수 체크
function checkWordSize(obj, title, max){
	if (obj.value.length>max) {
		obj.blur();
		obj.value = obj.value.substring(0,max-1);
		alert(title+'(은/는) '+max+'자를 초과할 수 없습니다.');
		obj.focus();
	}
}

/* selectbox */
function selectboxLink(obj) {
	var siteLink1 = document.getElementById("selectboxLink1");
	if( obj == 'selectboxLink1' ) {
		siteLink1.style.display = 'block';
	} else if( obj == 'selectboxLink1' ) {
		document.getElementById("selectboxLink1").style.display='none';
	}
}

//라디오버튼 체크
function isNotCheckedRadio(field,	error_msg) {
	if ( field ==	null ) {
		alert(error_msg);
		return true;
	}

	if ( field.length	== null	)	{
		if ( field.checked ==	true ) {
			return false;
		}	else {
			alert(error_msg);
			return true;
		}
	}

	for(i	=	0; i < field.length; i++)	{
		if(field[i].checked	== true) {
			return false;
		}
	}
	alert(error_msg);
	return true;
}

/* registration */
function sendit(n)
{
	if(n==2) {
		form1.action="/register/simpleRegister.nhn";
	}
	else if(n==1) {
		form1.action="/register/register.nhn";
	}
	else {
		form1.action="/register/underRegister.nhn";
	}
	form1.submit();   
    return true;
}
function imgOn(imgEl) {
	imgEl.src = imgEl.src.replace("_off.gif", "_on.gif");
}
function imgOut(imgEl) {
	imgEl.src = imgEl.src.replace("_on.gif", "_off.gif");
}

//항목이 비어있는지	체크
function isEmpty(field,	error_msg)
{
	// error_msg가 ""이면	alert와	focusing을 하지	않는다
	if(error_msg ==	"")	{
		if(!CheckValid(field.value,	false))		{
			return true;
		}	else {
			return false;
		}
	}	else {
		if(!CheckValid(field.value,	false))	{
			alert(error_msg);
			//field.focus()	;
			return true;
		}	else {
			return false;
		}
	}
}

String.prototype.trim=function()
{
  var str=this.replace(/(\s+$)/g,"");
  return str.replace(/(^\s*)/g,"");
}

/*
 * input typen maxlength 프로퍼티가 있을때
 */
function MaxAlert(obj){
	if(obj.maxLength == (obj.value.length)){
		alert("최대 길이는 "+obj.maxLength+"자 입니다");
		obj.value = obj.value.substring(0,obj.maxLength-1);
	}
}

function CheckValid(String,	space)
{
	 var retvalue	=	false;
	 for (var	i=0; i<String.length;	i++)
	 {		//String이 0(""	이나 null)이면 무조건	false
			if (space	== true)
			{
				 if	(String.charAt(i)	== ' ')
				 {			//String이 0이 아닐때	space가	있어야만 true(valid)
						retvalue = true;
						break;
				 }
			}	else {
				 if	(String.charAt(i)	!= ' ')
				 {			//string이 0이 아닐때	space가	아닌 글자가	있어야만 true(valid)
						retvalue = true;
						break;
				 }
			}
	 }
	 return	retvalue;
}

//선택되어있는	라디오버튼 값
function getRadioVal(field)	{
	for(i	=	0; i < field.length; i++)	{
		if(field[i].checked	== true)
			return field[i].value;
	}
	return "";
}


function sReplace(obj, s1, s2){
    for (i=0; i< obj.value.length; i++) 
        obj.value = obj.value.replace(s1,s2);
    return;
}

function sReplace_str(str, s1, s2){
    for (i=0; i< str.length; i++) 
        str = str.replace(s1,s2);
    return str;
}


function displayResultNotice() {
	try {
		xml = parseXML("/upload/xml/indexNotice.xml");   
		xsl = parseXML("/common/indexNotice.xsl");
	}
	catch(e) {
		//alert(e.toString());
	}
	   
	// code for IE   
	if (window.ActiveXObject) {   
	    ex = xml.transformNode(xsl);
	    document.getElementById("notice").innerHTML = ex;			           
	}   
	   
	// code for Mozilla, Firefox, Opera, etc.   
	else if (document.implementation && document.implementation.createDocument) {   
		xsltProcessor = new XSLTProcessor();
	
	    xsltProcessor.importStylesheet(xsl);   
	    resultDocument = xsltProcessor.transformToFragment(xml,document);
	
	    document.getElementById("notice").appendChild(resultDocument);
	}
}

function displayResultUpdate() {
	try {
		xml = parseXML("/upload/xml/indexUpdate.xml");   
		xsl = parseXML("/common/indexUpdate.xsl");
	}
	catch(e) {
		//alert(e.toString());
	}
	   
	// code for IE   
	if (window.ActiveXObject) {   
	    ex = xml.transformNode(xsl);
	    document.getElementById("update").innerHTML = ex;			           
	}   
	   
	// code for Mozilla, Firefox, Opera, etc.   
	else if (document.implementation && document.implementation.createDocument) {   
		xsltProcessor = new XSLTProcessor();
	
	    xsltProcessor.importStylesheet(xsl);   
	    resultDocument = xsltProcessor.transformToFragment(xml,document);
	
	    document.getElementById("update").appendChild(resultDocument);
	}
}

function displayResultEvent(pCurrentDate) {
	try {
		var xml_origin = parseXML("/upload/xml/indexEvent.xml");   
		
		var text = "";
		text += "<root>\n";
		jQuery(xml_origin).find("item").each(function() {
			if(Number(jQuery("strtymd", this).text()) <= pCurrentDate && Number(jQuery("endymd", this).text()) >= pCurrentDate) {
				text += "<item>\n";
				text += "<seq>" + jQuery("seq", this).text() + "</seq>\n";
				text += "<title><![CDATA[" + jQuery("title", this).text() + "]]></title>\n";
				text += "<regdatetime>" + jQuery("regdatetime", this).text() + "</regdatetime>\n";
				text += "<urltp>" + jQuery("urltp", this).text() + "</urltp>\n";
				text += "<url><![CDATA[" + jQuery("url", this).text() + "]]></url>\n";
				text += "</item>\n";
			}
		});
		text += "</root>";
		
		xml = parseXMLString(text);		
		xsl = parseXML("/common/indexEvent.xsl");
	}
	catch(e) {
		alert(e.toString());
	}
	   
	// code for IE   
	if (window.ActiveXObject) {   
	    ex = xml.transformNode(xsl);
	    document.getElementById("event").innerHTML = ex;			           
	}   
	   
	// code for Mozilla, Firefox, Opera, etc.   
	else if (document.implementation && document.implementation.createDocument) {   
		xsltProcessor = new XSLTProcessor();
	
	    xsltProcessor.importStylesheet(xsl);   
	    resultDocument = xsltProcessor.transformToFragment(xml,document);
	
	    document.getElementById("event").appendChild(resultDocument);
	}
}

function displayResultGobbs() { 
	try {
		xml = parseXML("/upload/xml/indexGobbs.xml");   
		xsl = parseXML("/common/indexGobbs.xsl");
	}
	catch(e) {
		//alert(e.toString());
	}
	
	// code for IE   
	if (window.ActiveXObject) {   
	     ex = xml.transformNode(xsl);
	     document.getElementById("goBbsList").innerHTML = ex;
	}	   						
	// code for Mozilla, Firefox, Opera, etc.   
	else if (document.implementation && document.implementation.createDocument) {   
		xsltProcessor = new XSLTProcessor();
	
		xsltProcessor.importStylesheet(xsl);   
		resultDocument = xsltProcessor.transformToFragment(xml,document);
	
		document.getElementById("goBbsList").appendChild(resultDocument);
	}
}

function displayResultKorbbs() { 
	try {
		xml = parseXML("/upload/xml/indexKorbbs.xml");   
		xsl = parseXML("/common/indexKorbbs.xsl");
	}
	catch(e) {
		//alert(e.toString());
	}
	
	// code for IE   
	if (window.ActiveXObject) {   
	     ex = xml.transformNode(xsl);
	     document.getElementById("korBbsList").innerHTML = ex;
	}	   						
	// code for Mozilla, Firefox, Opera, etc.   
	else if (document.implementation && document.implementation.createDocument) {   
		xsltProcessor = new XSLTProcessor();
	
		xsltProcessor.importStylesheet(xsl);   
		resultDocument = xsltProcessor.transformToFragment(xml,document);
	
		document.getElementById("korBbsList").appendChild(resultDocument);
	}
}

function displayResultMidea() { 
	try {
		xml = parseXML("/upload/xml/indexMedia.xml");   
		xsl = parseXML("/common/indexMedia.xsl");
	}
	catch(e) {
		//alert(e.toString());
	}
	
	// code for IE   
	if (window.ActiveXObject) {   
	     ex = xml.transformNode(xsl);
	     document.getElementById("mideabbsList").innerHTML = ex;
	}	   						
	// code for Mozilla, Firefox, Opera, etc.   
	else if (document.implementation && document.implementation.createDocument) {   
		xsltProcessor = new XSLTProcessor();
	
		xsltProcessor.importStylesheet(xsl);   
		resultDocument = xsltProcessor.transformToFragment(xml,document);
	
		document.getElementById("mideabbsList").appendChild(resultDocument);
	}
}

function openVideo() {
	var xml = parseXML("/upload/xml/indexVideo.xml");
	var videoUrl;
	
	try {
		jQuery(xml).find("warMovie").each(function() {
			videoUrl = jQuery("flvUrl", this).text();
		});
	}
	catch(e) {		
		//alert(e.toString());
	}
	
	return videoUrl;
}

function openVideoImg() {
	var xml = parseXML("/upload/xml/indexVideo.xml");
	var videoImg;
	
	try {
		jQuery(xml).find("warMovie").each(function() {
			videoImg = jQuery("mainimg", this).text();
		});
	}
	catch(e) {		
		//alert(e.toString());
	}
	
	return videoImg;
}

function openVideoImgsub() {
	var xml = parseXML("/upload/xml/indexVideo.xml");
	var videoImgsub;
	
	try {
		jQuery(xml).find("warMovie").each(function() {
			videoImgsub = jQuery("mainimgsub", this).text();
		});
	}
	catch(e) {		
		//alert(e.toString());
	}
	
	return videoImgsub;
}

//메인 팝업
function openIndexPopup(pCurrentDate) {
	var xml = parseXML("/upload/xml/indexPopup.xml");
	
	var i = 0;
	
	try {
		jQuery(xml).find("item").each(function() {
			if(i == 3) {
				return false;
			}
			if( Number(jQuery("state", this).text()) == 0 ){
				if(Number(jQuery("strtaymdt", this).text()) <= pCurrentDate && Number(jQuery("endymdt", this).text()) >= pCurrentDate) {
					if(getCookie("popupName"+jQuery("seq", this).text()) != "check") {
						window.open('/popup/popup_index.nhn?seq=' + encodeURIComponent(jQuery("seq", this).text()), 'popup'+i+1,'width=' + jQuery("wdt", this).text() + ',height=' + (Number(jQuery("hgt", this).text()) + 40) + ',top=' + jQuery("top", this).text() + ',left=' + jQuery("left", this).text() + ',toolbar=no,menubar=no,location=no,scrollbars=no,status=no');
					}
				}
				
			}else if( Number(jQuery("state", this).text()) == 1 ){
				if(getCookie("popupName"+jQuery("seq", this).text()) != "check") {
					window.open('/popup/popup_index.nhn?seq=' + encodeURIComponent(jQuery("seq", this).text()), 'popup'+i+1,'width=' + jQuery("wdt", this).text() + ',height=' + (Number(jQuery("hgt", this).text()) + 40) + ',top=' + jQuery("top", this).text() + ',left=' + jQuery("left", this).text() + ',toolbar=no,menubar=no,location=no,scrollbars=no,status=no');
				}				
			}			
			i++;			
		});
	}
	catch(e) {
		//alert(e.toString());
	}
}

//자체점검
function callCheck(pCurrentDate) {
	var checkXml = parseXML("/upload/xml/indexCheck.xml");
	pCurrentDate = Number(pCurrentDate + "00");
	
	try {
		jQuery(checkXml).find("item").each(function() {
			if(Number(jQuery("strtchckymdt", this).text()) < pCurrentDate && Number(jQuery("endchckymdt", this).text()) > pCurrentDate) {
				if(jQuery("chckknd", this).text() == "iselfchcke") {
					//location.href="/common/under/under.nhn?msg=" + encodeURIComponent(jQuery("usernotfmsg", this).text()) + "&time=" + encodeURIComponent(jQuery("usernotfchcktm", this).text());
					location.href="/common/under/under.nhn";
				}
				//else if(jQuery("chckknd", this).text() == "ishangamechcke") {	
				//	location.href = "http://www.hangame.com/common/under/under.html";
				//}
				//return false;
			}
		});
	}
	catch(e){
		//alert(e.toString());
	}
}

//게임점검 세팅
function setCheckGame(pCurrentDate) {
	var xml = parseXML("/upload/xml/indexCheck.xml");
	pCurrentDate = Number(pCurrentDate + "00");
	var arrCheckGame = new Array();
	
	try {
		jQuery(xml).find("item").each(function() {
			if(Number(jQuery("strtchckymdt", this).text()) <= pCurrentDate && Number(jQuery("endchckymdt", this).text()) >= pCurrentDate) {
				if(jQuery("chckknd", this).text() == "mgcychcke") {
					arrCheckGame.push(jQuery("usernotfmsg", this).text());
					arrCheckGame.push(jQuery("usernotfchcktm", this).text());
				}
			}
		});
	}
	catch(e){
		//alert(e.toString());
	}
	
	return arrCheckGame;
}

/**
 * 이미지 리사이즈
 */
function resizeImgEditor(imgObj, width, height) {
	if(imgObj.width > width) {
		imgObj.width = width;
	}
	if(height != "") {
		if(imgObj.height > height) {
			imgObj.height = height;
		}
	}
}

/* 탭메뉴
function tabMenu(filename, total, n)
{
	for(var i=1;i<=total;i++){
		if(i==n){
			document.getElementById("tabBtn_"+i).src = "/img/common/tabmenu/"+filename+i+"_on.gif";
		} else {
			document.getElementById("tabBtn_"+i).src = "/img/common/tabmenu/"+filename+i+".gif";
		}
	}
}
 */
/* 준비중 */
function comingSoon(){
	alert("준비중입니다");
}

// lnb Flash메뉴 파일명 리턴
function getLeftMenuType(menuCode) {
	var leftMenuType;
	var compareMenuCode = menuCode.substr(0, 2);
	
	if(compareMenuCode == "01")
		leftMenuType = "lnb_1_news";
	else if(compareMenuCode == "02")
		leftMenuType = "lnb_2_guide";
	else if(compareMenuCode == "03")
		leftMenuType = "lnb_3_community";
	else if(compareMenuCode == "04")
		leftMenuType = "lnb_4_dataroom";	
	
	return leftMenuType;
}

// iframe 리사이즈
function resizeFrame(frm) {
	frm.style.height = "auto";
	contentHeight = frm.contentWindow.document.documentElement.scrollHeight;
	frm.style.height = contentHeight + 10 + "px";
}


function thisReload(){
	document.location.reload();
}

function eleshow(ele) {
	if(typeof ele == "string") ele = document.getElementById(ele);
	ele.style.display = 'block';
	return false;
}


//이미지원본사이즈
function ImgPopup(img2){
	poto= new Image();
	poto.src=(img2);
	Controlla(img2);
}

function Controlla(img2){
	if((poto.width!=0)&&(poto.height!=0)){
		winopen(img2,poto.width,poto.height);
	}else{
		funzione="Controlla('"+img2+"')";
		intervallo=setTimeout(funzione,20);
	}
}

//이미지 팝업
function winopen(img_view, Width, Height) {
	
	var strWidth = screen.width;
	var strHeight= screen.height-80;
	
	if ( Width > strWidth){
		per = strWidth/Width;
		Width = strWidth;
		Height = strHeight * per;
	}
	
	if ( Height > strHeight){
		per = strHeight/Height;
		Height = strHeight;
		Width = strWidth * per;
	}
	
	var winHandle = window.open("/popup/popup_image.jsp?img_view="+img_view+"&Width="+Width+"&Height="+Height ,"windowName","toolbar=no,scrollbars=no,resizable=no, top=200, left=200 ,width=" + Width + ",height=" + Height)

	winHandle.focus()
}

function survey() {
	window.open("http://surveyasp.esurvey.kr/survey/survey.aspx?pID=P06726090&gID=3", "p_survey", "");
}

function callGameStartTracking() {
	document.getElementById("gamestart_tracking").src = "/common/gamestart_tracking.html";
}


