//모든페이지 가기 
function goPage(pageName){
	var target = "_top";
	var targetURL = "main";
	var returnPage = "/go/"+pageName+"/";
	document.location.href = returnPage;
}

function gotoMenu(pageCode){
	
	switch(pageCode){
	case '00': targetURL = "mainBegin"; break;
	case '00_2': targetURL = "newMainBegin"; break;
	case '01': targetURL = "mainPower"; break;
	case '01_1': targetURL = "announce"; break;
	case '01_2': targetURL = "event"; break;
	case '01_3': targetURL = "update"; break;
	case '01_4': targetURL = "schedule"; break;
	
	case '02_1': targetURL = "beginner01_1"; break;
	case '02_1_2': targetURL = "beginner01_2"; break;
	case '02_1_3': targetURL = "beginner01_3"; break;
	case '02_2': targetURL = "beginner02_1"; break;
	case '02_2_2': targetURL = "beginner02_2"; break;
	case '02_2_3': targetURL = "beginner02_3"; break;
	case '02_2_4': targetURL = "beginner02_4"; break;
	case '02_2_5': targetURL = "beginner02_5"; break;
	case '02_2_6': targetURL = "beginner02_6"; break;
	case '02_2_7': targetURL = "beginner02_7"; break;
	case '02_2_8': targetURL = "beginner02_8"; break;
	case '02_3': targetURL = "beginner03"; break;
	case '02_4': targetURL = "beginner04"; break;
	
		
	case '03_1': targetURL = "gamesystem01_1"; break;
	case '03_1_2': targetURL = "gamesystem01_2_1"; break;
	case '03_1_3': targetURL = "gamesystem01_3_1"; break;
	case '03_1_4': targetURL = "gamesystem01_4_1"; break;
	case '03_1_6': targetURL = "gamesystem01_6"; break;
	case '03_2': targetURL = "gamesystem02"; break;
	case '03_3': targetURL = "gamesystem03_1"; break;
	case '03_3_2': targetURL = "gamesystem03_2"; break;
	case '03_3_3': targetURL = "gamesystem03_3"; break;
	case '03_5': targetURL = "gamesystem05_1"; break;
	case '03_5_2': targetURL = "gamesystem05_2"; break;
	case '03_6': targetURL = "gamesystem06"; break;
	
	case '04_1': targetURL = "gmboard"; break;
	case '04_2': targetURL = "freeboard"; break;
	case '04_3': targetURL = "screenshot"; break;
	
	case '05_1': targetURL = "clan01"; break;
	case '05_2': targetURL = "clan02"; break;
	case '05_3': targetURL = "clan03"; break;
	case '05_4': targetURL = "clan04"; break;
	
	case '06_1': targetURL = "webshop"; break;
	case '06_2': targetURL = "webshop_gacha"; break;
	case '06_3': targetURL = "webshop_avata"; break;
	case '06_4': targetURL = "webshop_enchant"; break;
	case '06_5': targetURL = "webshop_skill"; break;
	case '06_6': targetURL = "webshop_package"; break;
	
	case '07_1': targetURL = "download"; break;
	
	}
	//플래시파일에서 불러오는 xml파일이 절대경로가 아닌 상대경로로 지정되어있어서 얘만 특별처리
	if(pageCode =="01_4"){
		document.location.href ="/go.htmls?page="+targetURL;
	}else{
		document.location.href = "/go/"+targetURL+"/";
	}
}

//공식페이지 인덱스로 가기
function goPTHome(){
	top.location.href = "/";
}

//초심자 페이지에서 멤버사이트로 가기(쿠키세팅 필요)
function goPTMemberSite(){
	document.location.replace('/go/mainPower/');
}

//클라 다운페이지로 가기
function goPTClientDown(){

//	var time = new Date().getTime();
//	var timer = $('#timer').val();
//	var downURL = document.getElementById('downURL');
//	if(timer == ""){
//		window.location= downURL.value;
//	}else{
//		if((time - timer)> 5000){
//			window.location　= downURL.value;
//		}else{
//			alert('5分ほどお時間をとってからご利用ください。');
//		}
//	}
	
	document.location.replace('/go/download/');
}

//아라리오 통합페이지로 이동
function goArarioHome(){
	window.location.href="http://www.arario.jp";
}

//엔트리 페이지로 이동!!
function goEntry(){
	window.location.href="http://pristontale.arario.jp/go/mainPower/";
}

//마이페이지
function popupMypage(){
	// var myPageURL = "http://www.arario.jp/?pn=mypage";
	// window.open(myPageURL,'myPage','width=655,height=600,statusbar=no,scrollbars=yes,toolbar=no,resizable=no');
	// document.location.href = 'http://www.arario.jp/?pn=mypage';
	document.location.href = 'http://www.arario.jp/memberInfoAuth.action';
}

//비번찾기페이지로 포워딩
function findIdPass(){
	document.location.href ="http://www.arario.jp/?pn=searchInfo";
}

//회원가입페이지로가기
function goRegist(){
	document.location.href="http://www.arario.jp/?pn=regit&gn=pt";
}

//문의사항
function goQna(){
	window.open("http://www.arario.jp/support/go.htmls");
}

//자주하는 질문가기
function goFaq(){
	window.open("http://www.arario.jp/support/go.htmls");
	//window.open("http://alpha.arario.jp/support/go.htmls");
}

//riocoin Charge
function riocoinCharge(){
	window.open("http://www.arario.jp/charge/?gn=pt");
}
//회원가입 페이지 팝업으로 띄우기
function popupRegist(){
	params = 'directories=yes';
	params += ', location=yes';
	params += ', menubar=yes';
	params += ', resizable=yes';
	params += ', scrollbars=yes';
	params += ', status=yes';
	params += ', toolbar=yes';
	url = "http://www.arario.jp/?pn=regit&gn=pt";
	newwin=window.open(url,'dc_pop', params);
	 if (window.focus) {newwin.focus()}
	// return false;
}


//팝업으로 페이지 띄우기 
function popupPage(page){
	params = 'directories=yes';
	params += ', location=yes';
	params += ', menubar=yes';
	params += ', resizable=yes';
	params += ', scrollbars=yes';
	params += ', status=yes';
	params += ', toolbar=yes';
	
	url = getURL(page);
	
	newwin=window.open("/go/"+page+"/",'pt_pop', params);
	 if (window.focus) {newwin.focus()}
	// return false;
}

//팝업으로 띄울페이지 가져오기
function getURL(page){
	var url = "http://pristontale.arario.jp";
	if(page == "entryBoard"){
		url += "/entryBoard/"; 
	}
	return url;
}

//즐겨 찾기 등록하기 
function addFavorite(title){
   var url = "http://pristontale.arario.jp";
   if (window.sidebar) // firefox 
   window.sidebar.addPanel(title, url, ""); 
   else if(window.opera && window.print)

   { // opera 
      var elem = document.createElement('a'); 
      elem.setAttribute('href',url); 
      elem.setAttribute('title',title); 
      elem.setAttribute('rel','sidebar'); 
      elem.click(); 
   } 

  else if(document.all) // ie
   window.external.AddFavorite(url, title);
}


//로그인
function commonLogin(){
	  var v_user_id = trim(document.loginForm.user_id.value);
      var v_user_pass = trim(document.loginForm.user_pass.value);
      var v_rURL = document.URL;
      var v_data = "user_id="+v_user_id+"&user_pass="+v_user_pass;

      if(v_user_id.length < 1){
          alert('IDを入力してください。');
          document.loginForm.user_id.focus()
      } else if(v_user_pass.length < 1){
          alert("パスワードを入力してください。");
          document.loginForm.user_pass.focus()
      } else {
          document.loginForm.rURL.value = document.URL;

          $.ajax({
              type: "post",
              url: "/lecpt.jsp",
              data: v_data,
              success: function(msg){
                  document.loginForm.ecode.value = trim(msg);
                  document.loginForm.action = "http://www.arario.jp/commonLogin.htmls";
                  document.loginForm.submit();
              }
          })
      }
}

function extraLogin(){
	var v_user_id = trim(document.loginForm.user_id.value);
    var v_user_pass = trim(document.loginForm.user_pass.value);
    var v_rURL = trim(document.loginForm.rURL.value);
    var v_data = "user_id="+v_user_id+"&user_pass="+v_user_pass;

    if(v_user_id.length < 1){
        alert('IDを入力してください。');
        document.loginForm.user_id.focus()
    } else if(v_user_pass.length < 1){
        alert("パスワードを入力してください。");
        document.loginForm.user_pass.focus()
    } else {
        document.loginForm.rURL.value = v_rURL;

        $.ajax({
            type: "post",
            url: "/lecpt.jsp",
            data: v_data,
            success: function(msg){
                document.loginForm.ecode.value = trim(msg);
                document.loginForm.action = "http://www.arario.jp/commonLogin.htmls";
                document.loginForm.submit();
            }
        })
    }
}

//2010.08.24 Kyungwon.Min
function openIdLogin(p) {
	alert('プリストンテールではOpenIDはご利用いただけません。');
	//top.location.href='http://www.arario.jp/openIdAuth.htmls?pn=login&opCode='+p+'&gn=pt&loginType=araLogin';
}

//2010.08.24 Kyungwon.Min
function aboutOId() {
	alert('プリストンテールではOpenIDはご利用いただけません。');
	//top.location.href='http://www.arario.jp/openIdAuth.htmls?pn=whats&gn=pt';
}

//로그아웃
function logout(){
	if(confirm("ログアウトしますか？")){
		$.ajax({
			type:"POST",
			url:"/memberLogout.htmls",
			success:function(){document.location.reload();}
		});
	}
}

//KeyPress Cross Browser Version
function keyPress(evt){
	var ieKey = evt.keyCode || evt.which;
	if ( ieKey == 13 ){
		commonLogin();
	}
}


//PV & UV 
function addCount(sub_no){
	$.ajax({
		url  :"newAddCountAction.htmls",
		data :{"sub_no":sub_no,"referer":"null"},
		type :"POST",
		cache:false
	});
}

function addCountWithReferer(sub_no, referer){
	$.ajax({
		url  :"newAddCountAction.htmls",
		data :"sub_no="+sub_no +"&referer=null",
		type :"POST",
		cache:false
	});
}


function trim(str){
	  // str = str.replace(/^\s*/,'').replace(/\s*$/, '');
	  var re1 = /^\s+|\s+$/g;
	    var re2 = /^　+|　+$/g;
	    var trimFlag = true;
	    while(trimFlag) {
	        var length = str.length;
	        str = str.replace(re1, '');
	        str = str.replace(re2, '');
	        if(str.length == length) {
	            trimFlag = false;
	        }
	    }
	   return str; 
	}

//Line and Contents length Check!
function checkContents(id,wordsCnt, lineCnt){
	var contents = $.trim($(id).val());
	var linenum = contents.split("\n");
	var retVal = true;
	
	if(contents.length <1 || contents.length > wordsCnt || linenum.length > lineCnt){
		alert(lineCnt+"行以内、"+wordsCnt+"文字以内で入力してください。");
		retVal = false;
	}
	return retVal;
}

function checkContents2(contents,wordsCnt, lineCnt){
	var linenum = contents.split("\n");
	var retVal = true;
	
	if(contents.length <1 || contents.length > wordsCnt || linenum.length > lineCnt){
		alert(lineCnt+"行以内、"+wordsCnt+"文字以内で入力してください。");
		retVal = false;
	}
	return retVal;
}

//min textCount, max text Count, line Count 
function checkContents3(contents,min, max, lineCnt){
	var linenum = contents.split("\n");
	var retVal = true;
	
	if(contents.length <1 || contents.length < min || contents.length > max || linenum.length > lineCnt){
		alert(lineCnt+"行以内、"+min+"文字以上、"+max+"文字以内で入力してください。\n現在「"+linenum.length+"」行　「"+contents.length+"」字です。");
		retVal = false;
	}
	return retVal;
}

function MailCheck(ObjMail){
	ObjMail = $.trim(ObjMail);

	if (ObjMail.search(/(\S+)@(\S+)\.(\S+)/) == -1 ) 
	{
	    return false;    
	}
	return true;
}

function youNeedLogin(){
	alert("ログインしてからご利用ください。");
}

function alertLogin(){
	alert("ログインしてからご利用ください。");
}

function alertGetReady(){
	alert("準備中です。");
}

function txtAreaCheck(str){
	var len = str.length;
	var enter_ctn = 1;
	
	for(i = 0; i<len; i++){
		if(str.charAt(i) == '\n') ++enter_ctn;
	}
	
	return enter_ctn;
}

//티커 가져오기!
function getTicker(){
	var v_data = "tp=ticker";
	$.ajax({
		type: "post",
		url: "getTicker.htmls",
		data: v_data,
		success: function(msg){
			try{
				document.getElementById("ticker").innerHTML = trim(msg);
			} catch(e){}
		}
	})
}

function notLogin(){
	alert('ログインしてからご利用ください。');
}

function activeXLoadError(){
	try{
		valueForm.luncherInstalled.value = "false";	
	}catch(e){
		
	}
}
function startGame(){
	var luncherCheck = document.valueForm.luncherInstalled.value;
	var isOpenId = document.getElementById('isOpenId').value;
	
		if(luncherCheck == "false"){		
			alert("ActiveXコントロールのインストールが必要です。\nActiveXコントロールのダウンロードを行ってください。");
		}else{
			if (isOpenId == 'Y') {
				alert('OpenIDではゲームをお楽しみいただけません。');
			} else {
				document.location.href="artp://gameid=pristontale";
			}
		}
}

function isOnWorking(){
	alert('準備中です。');
}

function beginerView(viewOK){
	//alert(viewOK);
	var cookies = getCookie("ptale_bgn_view");
	if(viewOK=="Y"){
		clearCookie("ptale_bgn_view");
		document.location.replace("/");
	} else if(viewOK=="N"){
		setCookie("ptale_bgn_view","no",365);
		document.location.replace("/go/mainPower/");
	}
}

function clearCookie(name){
	var expireDate = new Date();

    //어제 날짜를 쿠키 소멸 날짜로 설정한다.
    expireDate.setDate( expireDate.getDate() - 1 );
    document.cookie = name + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";

//    document.cookie = name + "= ''";
}

function setCookie(name,value,expiredays){	
   var todayDate = new Date();
   todayDate.setDate(todayDate.getDate()+expiredays);
   document.cookie = name + "=" + escape(value) + ";path=/;expires=" + todayDate.toGMTString()+";"	
}

function getCookie(name){
    var search = name + "=";
    
    if (document.cookie.length > 0){
        offset = document.cookie.indexOf(search);
        
        if (offset != -1){
            offset += search.length;
            end = document.cookie.indexOf(";",offset);
        
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(offset,end));
        }
        else return false;
    }
    else return false;
}

function id_focus(){
	if($('#user_id')){
		$('#user_id').val("");
	}
}

function pw_focus(){
	if($('#user_pass')){
		var obj = $('#user_pass');
		obj.style.backgroundImage='';
		obj.style.color = "#222121";
		$('#user_pass').val("");
	}
}

function viewRules(page){
	window.open('/go/'+page+'/', 'Rules', 'width=990,height=600,statusbar=no,scrollbars=yes,toolbar=no,resizable=yes,top=20,left=20;');
}

function viweHome(){
	window.location.replace('http://www.arario.jp');
}


function goTransfer(){
	params = 'directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', width=798, height=633';
	params += ', resizable=no';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	
	var url = "/go/transfer/";
	
	newwin=window.open(url,'pt_pop', params);
	 if (window.focus) {newwin.focus()}
		 //return false;
}

function closeOpenDiv(id){
	var obj = document.getElementById(id);
	if(obj.style.display != "none"){
		obj.style.display = "none";
	}else{
		obj.style.display = "block";
	}
}

function atrim(str){
	var temp_str = '';
	str = str.replace('　','');
	str = str.replace(/^\s*/,'').replace(/\s*$/, '');
	str = str.replace(/^\\s*/,'').replace(/\\s*$/, '');
	return str;
}

function goLogin(){
	//alertLogin();
	if(document.loginForm){
		var loginForm = document.loginForm; 
		loginForm.rURL.value = document.URL;
		loginForm.submit();
	}
}

function getSelectValue(obj){
	var result = "";
	for(i=0;i<obj.length;i++){
		if(obj[i].selected){
		  result = obj[i].value;
		}
	}
	return result;
}

function getSelectIndex(obj){
	var rIndex = "";
	for(i=0;i<obj.length;i++){
		if(obj[i].selected){
			rIndex =  i;
		}
	}
	return rIndex;
}

function radioSelect(obj){
	for(var i=0; i < obj.length; i++) {

		if (obj[i].checked == true){
			return obj[i].value;					
			break;		
		}
	}
	return false;
}

/** 
 * 문자의 바이트수를 세어주는 함수
 * String.bytes() 
 * aaa.bytes() 이런식으로 사용
 */
String.prototype.bytes = function() {
  var str = this;
  var l = 0;
  for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
  return l;
}


/**
 * Update date : 2009.9.16 [cause : eventForm]
 */
function viewEvent(param1,type){

	//param1 : if type is popup then pageName
	//param1 : if type is board then seq_no
	var pno = $('#pno').val();
	if(!pno){
		pno = "1";
	}
	if(type == 'popup'){
		url = "/go/"+param1+"/";
		window.open(url);
	}else{
		url = "/boardView.htmls?bn=event&sno="+ param1 + "&pno=" + pno;
		document.location.href = url;
	}
}
